自动化立体仓库 - WMS系统
13
zhang
2 天以前 d7c7cbbe2ba964b92e31e36d15c6941b4328b9b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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);
        }
    }
}