新火炬后端单体项目初始化代码
zhangherong
6 天以前 0bbd986930e4b41e0741fd07c4287208da398330
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package org.jeecg.modules.mes.job;
 
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.mes.entity.MesProductionOrder;
import org.jeecg.modules.mes.service.IMesProductionOrderService;
import org.jeecg.modules.pms.service.IPmsMaterialProcessService;
import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsService;
import org.jeecg.modules.sap.dto.OrderBomDTO;
import org.jeecg.modules.sap.dto.OrderProcessDTO;
import org.jeecg.modules.sap.dto.ProductionOrderDTO;
import org.jeecg.modules.sap.service.OrderBomSync;
import org.jeecg.modules.sap.service.OrderProcessSync;
import org.jeecg.modules.sap.service.ProductionOrderSync;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
 
@Component
@Slf4j
public class ProductionOrderSyncJob implements Job {
    //工厂编码(新火炬 2301)
    private static final String FACTORY_CODE = "2301";
    /**
     * 订单类型
     * 标准生产订单 Z001
     * 客退返工生产订单 Z002
     * 呆滞处理返工生产订单 Z003
     * 试制生产订单(新火炬)  Z011
     * 拆零生产订单(新火炬)  2012
     */
    private static final String ORDER_TYPE_CODE = "Z001";
    /**
     * 生产调度员
     * 001 一分厂调度员
     * 002 二分厂调度员
     * 003 三分厂调度员
     * 004 四分厂调度员
     * 005 ABS调度员
     * 006 调质调度员
     * 007 五分厂调度员
     * 008 试制车间调度员
     * 009 外采调度员
     * 010 六厂调度员
     * 012 八分厂调度员
     */
    private static final String PRODUCTION_MANAGER = "010";
    /**
     * 生产订单状态,实际上,只有REL状态的工单才可以进行操作
     * CRTD 新建
     * REL 下达
     * TECO 关闭
     */
    private static final String ORDER_STATUS = "REL";
 
    /**
     * 请求成功编码
     */
    private static final String SUCCESS_CODE = "S";
 
    @Autowired
    private ProductionOrderSync productionOrderSync;
    @Autowired
    private OrderBomSync orderBomSync;
    @Autowired
    private OrderProcessSync orderProcessSync;
    @Autowired
    private IMesProductionOrderService productionOrderService;
    @Autowired
    private IPmsProcessBillMaterialsService processBillMaterialsService;
    @Autowired
    private IPmsMaterialProcessService materialProcessService;
 
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //获取上次同步时间
        try {
            //调用SAP接口获取生产订单
            Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(FACTORY_CODE, ORDER_TYPE_CODE, PRODUCTION_MANAGER, ORDER_STATUS, null, null);
            if (productionOrderMap == null || !SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) {
                log.error("未同步到订单信息!日期:{}", LocalDateTime.now());
                return;
            }
            //调用成功,获取返回数据
            Object result = productionOrderMap.get("result");
            boolean b = result instanceof List;
            if(!b) {
                log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
                return;
            }
            List<ProductionOrderDTO> productionOrderDTOList = (List<ProductionOrderDTO>) result;
            Map<String, MesProductionOrder> orderMap = productionOrderService.saveOrUpdateProductionOrder(productionOrderDTOList);
            String orderCodes = String.join(",", orderMap.keySet());
            //订单BOM同步
            Map<String, Object> orderBomMap = orderBomSync.syncOrderBom(FACTORY_CODE, orderCodes);
            if (orderBomMap == null || !SUCCESS_CODE.equals(orderBomMap.get("ztype"))) {
                log.error("未同步到订单BOM信息!日期:{}", LocalDateTime.now());
                return;
            }
            //调用成功,获取返回数据
            result = orderBomMap.get("result");
            b = result instanceof List;
            if(!b) {
                log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
                return;
            }
            List<OrderBomDTO> orderBomDTOList = (List<OrderBomDTO>) result;
            b = processBillMaterialsService.saveOrUpdateOrderBom(orderMap, orderBomDTOList);
            if(!b) {
                log.error("保存订单BOM失败,日期:{}", LocalDateTime.now());
                return;
            }
            //订单工序同步
            Map<String, Object> orderProcessMap = orderProcessSync.syncOrderProcess(FACTORY_CODE, orderCodes);
            if (orderBomMap == null || !SUCCESS_CODE.equals(orderProcessMap.get("ztype"))) {
                log.error("未同步到订单工序信息!日期:{}", LocalDateTime.now());
                return;
            }
            //调用成功,获取返回数据
            result = orderBomMap.get("result");
            b = result instanceof List;
            if(!b) {
                log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
                return;
            }
            List<OrderProcessDTO> orderProcessDTOList = (List<OrderProcessDTO>) result;
            b = materialProcessService.saveOrUpdateOrderProcess(orderMap, orderProcessDTOList);
            if(!b) {
                log.error("保存订单工序失败,日期:{}", LocalDateTime.now());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
 
    }
}