ÎļþÃû´Ó src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncJob.java ÐÞ¸Ä |
| | |
| | | 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; |
| | |
| | | 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 ProductionOrderSyncCreationJob implements Job { |
| | | //å·¥åç¼ç (æ°ç«ç¬ 2301) |
| | | private static final String FACTORY_CODE = "2301"; |
| | | /** |
| | |
| | | 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.getLastSyncCreateDate(); |
| | | 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, lastSyncDateLow, lastSyncDateHigh, null, null); |
| | | if (productionOrderMap == null || !SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) { |
| | | log.error("æªåæ¥å°è®¢åä¿¡æ¯ï¼æ¥æï¼{}", LocalDateTime.now()); |
| | | return; |
| | |
| | | return; |
| | | } |
| | | //è°ç¨æåï¼è·åè¿åæ°æ® |
| | | result = orderBomMap.get("result"); |
| | | result = orderProcessMap.get("result"); |
| | | b = result instanceof List; |
| | | if(!b) { |
| | | log.error("è¿åç±»åéè¯¯ï¼ class:{}", result == null ? null : result.getClass()); |
| | |
| | | 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); |
| | | } |
| | | } |