提交 342136fc authored 作者: douxy's avatar douxy

增加定时任务执行旺店通其他出入库库存数据获取

上级 141925c3
package com.sfa.job.controller.order;
import com.sfa.job.service.stock.IWdtOtherStockSyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* @Author: DouXinYu
* @Date: 2026-04-18 14:26
* @Description:
*/
@RestController
public class TestController {
@Autowired
private IWdtOtherStockSyncService wdtOtherStockSyncService;
@PostMapping("/test")
public void get(@RequestBody Map<String,String> params){
wdtOtherStockSyncService.syncLastDayOtherStockOut(params.get("startTime"),params.get("endTime"));
}
@PostMapping("/testIn")
public void getIn(@RequestBody Map<String,String> params){
wdtOtherStockSyncService.syncLastDayOtherStockIn(params.get("startTime"),params.get("endTime"));
}
}
package com.sfa.job.jobhandler;
import com.sfa.job.service.stock.IWdtOtherStockSyncService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 旺店通其他出入库单同步 XXL-Job 任务
*
* @Author: DouXinYu
* @Date: 2026-04-23
*/
@Slf4j
@Component
public class WdtOtherStockSyncJobHandler {
@Autowired
private IWdtOtherStockSyncService wdtOtherStockSyncService;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/**
* 同步昨日其他出库单(XXL-Job 任务)
* 任务调度建议:0 0 1 * * ? 每天凌晨1点
*/
@XxlJob("wdtSyncLastDayOtherStockOutJob")
public void syncLastDayOtherStockOutJob() {
log.info("===== XXL-Job 开始执行:同步昨日旺店通其他出库单 =====");
XxlJobHelper.log("XXL-Job 开始执行:同步昨日旺店通其他出库单");
LocalDateTime now = LocalDateTime.now();
LocalDateTime yesterdayStart = now.minusDays(1).withHour(0).withMinute(0).withSecond(0);
LocalDateTime yesterdayEnd = now.minusDays(1).withHour(23).withMinute(59).withSecond(59);
String startTime = yesterdayStart.format(FORMATTER);
String endTime = yesterdayEnd.format(FORMATTER);
log.info("同步时间范围:{} ~ {}", startTime, endTime);
XxlJobHelper.log("同步时间范围:{} ~ {}", startTime, endTime);
long start = System.currentTimeMillis();
try {
wdtOtherStockSyncService.syncLastDayOtherStockOut(startTime, endTime);
log.info("===== XXL-Job 同步昨日其他出库单完成,耗时:{}ms =====", System.currentTimeMillis() - start);
XxlJobHelper.log("同步完成,耗时:{}ms", System.currentTimeMillis() - start);
XxlJobHelper.handleSuccess("同步昨日其他出库单成功");
} catch (Exception e) {
log.error("===== XXL-Job 同步昨日其他出库单异常 =====", e);
XxlJobHelper.log("同步异常:%s", e.getMessage());
XxlJobHelper.handleFail("同步昨日其他出库单失败:" + e.getMessage());
}
}
/**
* 同步昨日其他入库单(XXL-Job 任务)
* 任务调度建议:0 10 1 * * ? 每天凌晨1点10分
*/
@XxlJob("wdtSyncLastDayOtherStockInJob")
public void syncLastDayOtherStockInJob() {
log.info("===== XXL-Job 开始执行:同步昨日旺店通其他入库单 =====");
XxlJobHelper.log("XXL-Job 开始执行:同步昨日旺店通其他入库单");
LocalDateTime now = LocalDateTime.now();
LocalDateTime yesterdayStart = now.minusDays(1).withHour(0).withMinute(0).withSecond(0);
LocalDateTime yesterdayEnd = now.minusDays(1).withHour(23).withMinute(59).withSecond(59);
String startTime = yesterdayStart.format(FORMATTER);
String endTime = yesterdayEnd.format(FORMATTER);
log.info("同步时间范围:{} ~ {}", startTime, endTime);
XxlJobHelper.log("同步时间范围:{} ~ {}", startTime, endTime);
long start = System.currentTimeMillis();
try {
wdtOtherStockSyncService.syncLastDayOtherStockIn(startTime, endTime);
log.info("===== XXL-Job 同步昨日其他入库单完成,耗时:{}ms =====", System.currentTimeMillis() - start);
XxlJobHelper.log("同步完成,耗时:{}ms", System.currentTimeMillis() - start);
XxlJobHelper.handleSuccess("同步昨日其他入库单成功");
} catch (Exception e) {
log.error("===== XXL-Job 同步昨日其他入库单异常 =====", e);
XxlJobHelper.log("同步异常:%s", e.getMessage());
XxlJobHelper.handleFail("同步昨日其他入库单失败:" + e.getMessage());
}
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论