package com.zy.asrs.task;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.common.Cools;
|
import com.zy.asrs.entity.*;
|
import com.zy.asrs.service.*;
|
import com.zy.asrs.task.core.ReturnT;
|
import com.zy.asrs.task.handler.OrderSyncHandler;
|
import com.zy.common.entity.Parameter;
|
import com.zy.common.utils.Synchro;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.util.List;
|
|
/**
|
* Created by vincent on 2020/7/7
|
*/
|
@Slf4j
|
@Component
|
public class OrderSyncScheduler {
|
|
@Autowired
|
private OrderSyncHandler orderSyncHandler;
|
@Autowired
|
private OrderPakinService orderPakinService;
|
@Autowired
|
private OrderPakoutService orderPakoutService;
|
@Autowired
|
private ApiLogService apiLogService;
|
@Autowired
|
private OrderDetlReportService orderDetlReportService;
|
@Autowired
|
private OrderDetlReportLogService orderDetlReportLogService;
|
@Autowired
|
private OrderReportService orderReportService;
|
@Autowired
|
private OrderReportLogService orderReportLogService;
|
|
@Scheduled(cron = "0 0 1 * * ? ")
|
public void clearApiLog() {
|
try {
|
apiLogService.clearWeekBefore();
|
} catch (Exception e) {
|
log.error("第三方接口日志自动清除失败(范围:一周之前", e);
|
}
|
}
|
|
|
/**
|
* 订单状态4至6,并且写入上报表
|
*/
|
@Scheduled(cron = "0/5 * * * * ? ")
|
@Async("orderThreadPool")
|
public void completeOrderPakin() {
|
String erpReport = Parameter.get().getErpReport();
|
if (!Cools.isEmpty(erpReport) && erpReport.equals("true")) {
|
List<OrderPakin> orders = orderPakinService.selectComplete();
|
for (OrderPakin order : orders) {
|
ReturnT<String> result = orderSyncHandler.start(order);
|
if (!result.isSuccess()) {
|
log.error("单据[orderNo={}]上报erp失败", order.getOrderNo());
|
}
|
}
|
}
|
}
|
|
/**
|
* 订单状态4至6,并且写入上报表
|
*/
|
@Scheduled(cron = "0/5 * * * * ? ")
|
@Async("orderThreadPool")
|
public void completeOrderPakout() {
|
String erpReport = Parameter.get().getErpReport();
|
if (!Cools.isEmpty(erpReport) && erpReport.equals("true")) {
|
List<OrderPakout> orders = orderPakoutService.selectComplete();
|
for (OrderPakout order : orders) {
|
ReturnT<String> result = orderSyncHandler.start(order);
|
if (!result.isSuccess()) {
|
log.error("单据[orderNo={}]上报erp失败", order.getOrderNo());
|
}
|
}
|
}
|
}
|
|
|
//@Scheduled(cron = "0 0 3 * * ? ")
|
@Scheduled(cron = "0/5 * * * * ? ")
|
public void clearReportLog() {
|
try {
|
List<OrderReport> orderReports = orderReportService.selectList(new EntityWrapper<OrderReport>().eq("status", 1).eq("settle", 4));
|
for (OrderReport orderReport : orderReports) {
|
List<OrderDetlReportLog> orderId = orderDetlReportLogService.selectList(new EntityWrapper<OrderDetlReportLog>().eq("order_id", orderReport.getId()));
|
for (OrderDetlReportLog orderDetl : orderId) {
|
OrderDetlReportLog orderDetlReportLog = new OrderDetlReportLog();
|
orderDetlReportLog.sync(orderDetl);
|
orderDetlReportLog.setId(null);
|
orderDetlReportLogService.insert(orderDetlReportLog);
|
orderDetlReportService.deleteById(orderDetl.getId());
|
}
|
OrderReportLog reportLog = new OrderReportLog();
|
Synchro.Copy(orderReport, reportLog);
|
orderReportLogService.insert(reportLog);
|
orderReportService.deleteById(orderReport.getId());
|
}
|
} catch (Exception e) {
|
log.error("上报日志删除", e);
|
}
|
}
|
}
|