新火炬后端单体项目初始化代码
zhangherong
昨天 a27f1b573fc5cf9a3b78e2eacb56e44310f83456
src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncCreationJob.java
@@ -1,6 +1,7 @@
package org.jeecg.modules.mes.job;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.lsw.service.ILswMaterialService;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.ThrowableUtil;
import org.jeecg.modules.mes.entity.MesProductionOrder;
@@ -14,6 +15,7 @@
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.request.ProductionOrderSyncRequest;
import org.jeecg.modules.sap.service.OrderBomSync;
import org.jeecg.modules.sap.service.OrderProcessSync;
import org.jeecg.modules.sap.service.ProductionOrderSync;
@@ -21,6 +23,7 @@
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@@ -32,7 +35,8 @@
@Slf4j
public class ProductionOrderSyncCreationJob implements Job {
    //工厂编码(新火炬 2301)
    private static final String FACTORY_CODE = "2301";
    @Value("${xhj.factoryCode:2301}")
    private String FACTORY_CODE;
    /**
     * 订单类型
     * 标准生产订单 Z001
@@ -41,7 +45,8 @@
     * 试制生产订单(新火炬)  Z011
     * 拆零生产订单(新火炬)  2012
     */
    private static final String ORDER_TYPE_CODE = "Z001";
    @Value("${xhj.orderType:Z001}")
    private String ORDER_TYPE_CODE;
    /**
     * 生产调度员
     * 001 一分厂调度员
@@ -56,14 +61,16 @@
     * 010 六厂调度员
     * 012 八分厂调度员
     */
    private static final String PRODUCTION_MANAGER = "010";
    @Value("${xhj.productionManager:012}")
    private String PRODUCTION_MANAGER;
    /**
     * 生产订单状态,实际上,只有REL状态的工单才可以进行操作
     * CRTD 新建
     * REL 下达
     * TECO 关闭
     */
    private static final String ORDER_STATUS = "REL";
    @Value("${xhj.orderStatus:REL}")
    private String ORDER_STATUS;
    /**
     * 请求成功编码
@@ -86,6 +93,8 @@
    private ISysQuartzLogService sysQuartzLogService;
    @Autowired
    private IQuartzJobService quartzJobService;
    @Autowired
    private ILswMaterialService lswMaterialService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
@@ -100,15 +109,22 @@
        //获取上次同步时间
        String lastSyncDateLow = productionOrderService.getLastSyncCreateDate();
        String lastSyncDateHigh = null;
        if(lastSyncDateLow != null) {
        if (lastSyncDateLow != null) {
            lastSyncDateHigh = DateUtils.format(new Date(), "yyyyMMdd");
            if(lastSyncDateLow.equals(lastSyncDateHigh)) {
            if (lastSyncDateLow.equals(lastSyncDateHigh)) {
                lastSyncDateHigh = null;
            }
        }
        ProductionOrderSyncRequest request = new ProductionOrderSyncRequest();
        request.setFactoryCode(FACTORY_CODE);
        request.setOrderTypeCode(ORDER_TYPE_CODE);
        request.setProductionManager(PRODUCTION_MANAGER);
        request.setOrderStatus(ORDER_STATUS);
        request.setCreateTimeLow(lastSyncDateLow);
        request.setCreateTimeHigh(lastSyncDateHigh);
        try {
            //调用SAP接口获取生产订单
            Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(FACTORY_CODE, ORDER_TYPE_CODE, PRODUCTION_MANAGER, ORDER_STATUS, lastSyncDateLow, lastSyncDateHigh, null, null);
            Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(request);
            if (productionOrderMap == null || !SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) {
                log.error("未同步到订单信息!日期:{}", LocalDateTime.now());
                return;
@@ -116,7 +132,7 @@
            //调用成功,获取返回数据
            Object result = productionOrderMap.get("result");
            boolean b = result instanceof List;
            if(!b) {
            if (!b) {
                log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
                return;
            }
@@ -132,14 +148,21 @@
            //调用成功,获取返回数据
            result = orderBomMap.get("result");
            b = result instanceof List;
            if(!b) {
            if (!b) {
                log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
                return;
            }
            //订单BOM数据处理
            List<OrderBomDTO> orderBomDTOList = (List<OrderBomDTO>) result;
            b = processBillMaterialsService.saveOrUpdateOrderBom(orderMap, orderBomDTOList);
            if(!b) {
            if (!b) {
                log.error("保存订单BOM失败,日期:{}", LocalDateTime.now());
                return;
            }
            //物料数据处理
            b = lswMaterialService.saveOrUpdateMaterial(orderMap, orderBomDTOList);
            if (!b) {
                log.error("保存物料失败,日期:{}", LocalDateTime.now());
                return;
            }
            //订单工序同步
@@ -151,13 +174,13 @@
            //调用成功,获取返回数据
            result = orderProcessMap.get("result");
            b = result instanceof List;
            if(!b) {
            if (!b) {
                log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
                return;
            }
            List<OrderProcessDTO> orderProcessDTOList = (List<OrderProcessDTO>) result;
            b = materialProcessService.saveOrUpdateOrderProcess(orderMap, orderProcessDTOList);
            if(!b) {
            if (!b) {
                log.error("保存订单工序失败,日期:{}", LocalDateTime.now());
            }
            quartzLog.setIsSuccess(0);