新火炬后端单体项目初始化代码
zhangherong
2025-08-02 a5aa9503efd20103df066219c512b47b7f65e363
src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
copy from src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncJob.java copy to src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
Îļþ´Ó src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncJob.java ¸´ÖÆ
@@ -1,10 +1,16 @@
package org.jeecg.modules.mes.job;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.ThrowableUtil;
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.quartz.entity.QuartzJob;
import org.jeecg.modules.quartz.entity.SysQuartzLog;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.jeecg.modules.quartz.service.ISysQuartzLogService;
import org.jeecg.modules.sap.dto.OrderBomDTO;
import org.jeecg.modules.sap.dto.OrderProcessDTO;
import org.jeecg.modules.sap.dto.ProductionOrderDTO;
@@ -18,12 +24,13 @@
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Component
@Slf4j
public class ProductionOrderSyncJob implements Job {
public class ProductionOrderSyncUpdateJob implements Job {
    //工厂编码(新火炬 2301)
    private static final String FACTORY_CODE = "2301";
    /**
@@ -75,13 +82,33 @@
    private IPmsProcessBillMaterialsService processBillMaterialsService;
    @Autowired
    private IPmsMaterialProcessService materialProcessService;
    @Autowired
    private ISysQuartzLogService sysQuartzLogService;
    @Autowired
    private IQuartzJobService quartzJobService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //任务日志
        SysQuartzLog quartzLog = new SysQuartzLog();
        quartzLog.setCreateTime(new Date());
        List<QuartzJob> byJobClassName = quartzJobService.findByJobClassName(this.getClass().getName());
        if (byJobClassName != null && !byJobClassName.isEmpty()) {
            quartzLog.setJobId(byJobClassName.get(0).getId());
        }
        long startTime = System.currentTimeMillis();
        //获取上次同步时间
        String lastSyncDateLow = productionOrderService.getLastSyncUpdateDate();
        String lastSyncDateHigh = null;
        if (lastSyncDateLow != null) {
            lastSyncDateHigh = DateUtils.format(new Date(), "yyyyMMdd");
            if (lastSyncDateLow.equals(lastSyncDateHigh)) {
                lastSyncDateHigh = null;
            }
        }
        try {
            //调用SAP接口获取生产订单
            Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(FACTORY_CODE, ORDER_TYPE_CODE, PRODUCTION_MANAGER, ORDER_STATUS, null, null);
            Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(FACTORY_CODE, ORDER_TYPE_CODE, PRODUCTION_MANAGER, ORDER_STATUS, null, null, lastSyncDateLow, lastSyncDateHigh);
            if (productionOrderMap == null || !SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) {
                log.error("未同步到订单信息!日期:{}", LocalDateTime.now());
                return;
@@ -89,7 +116,7 @@
            //调用成功,获取返回数据
            Object result = productionOrderMap.get("result");
            boolean b = result instanceof List;
            if(!b) {
            if (!b) {
                log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
                return;
            }
@@ -105,13 +132,13 @@
            //调用成功,获取返回数据
            result = orderBomMap.get("result");
            b = result instanceof List;
            if(!b) {
            if (!b) {
                log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
                return;
            }
            List<OrderBomDTO> orderBomDTOList = (List<OrderBomDTO>) result;
            b = processBillMaterialsService.saveOrUpdateOrderBom(orderMap, orderBomDTOList);
            if(!b) {
            if (!b) {
                log.error("保存订单BOM失败,日期:{}", LocalDateTime.now());
                return;
            }
@@ -122,20 +149,25 @@
                return;
            }
            //调用成功,获取返回数据
            result = orderBomMap.get("result");
            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);
        } catch (Exception e) {
            throw new RuntimeException(e);
            log.error("定时任务失败,{}", e.getMessage(), e);
            quartzLog.setIsSuccess(-1);
            quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
        }
        long endTime = System.currentTimeMillis();
        quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
        sysQuartzLogService.save(quartzLog);
    }
}