ÎļþÃû´Ó 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); |
| | | } |
| | | } |
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 ¸´ÖÆ |
| | |
| | | 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 ProductionOrderSyncUpdateJob 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.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; |
| | |
| | | //è°ç¨æåï¼è·åè¿åæ°æ® |
| | | Object result = productionOrderMap.get("result"); |
| | | boolean b = result instanceof List; |
| | | if(!b) { |
| | | if (!b) { |
| | | log.error("è¿åç±»åéè¯¯ï¼ class:{}", result == null ? null : result.getClass()); |
| | | return; |
| | | } |
| | |
| | | //è°ç¨æåï¼è·åè¿åæ°æ® |
| | | 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; |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.jeecg.modules.mes.entity.MesProductionOrder; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @Description: SAPç产订å |
| | | * @Author: jeecg-boot |
| | |
| | | */ |
| | | public interface MesProductionOrderMapper extends BaseMapper<MesProductionOrder> { |
| | | |
| | | /** |
| | | * è·åææ°çåå»ºåæ¥æ¥æ |
| | | * @return |
| | | */ |
| | | String getLastSyncCreateDate(); |
| | | |
| | | /** |
| | | * è·åææ°çåå»ºåæ¥æ¥æ |
| | | * @return |
| | | */ |
| | | String getLastSyncUpdateDate(); |
| | | } |
| | |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="org.jeecg.modules.mes.mapper.MesProductionOrderMapper"> |
| | | |
| | | <select id="getLastSyncCreateDate" resultType="java.lang.String"> |
| | | select MAX(order_create_date) from mes_production_order |
| | | </select> |
| | | |
| | | <select id="getLastSyncUpdateDate" resultType="java.lang.String"> |
| | | select MAX(order_update_date) from mes_production_order |
| | | </select> |
| | | </mapper> |
| | |
| | | * @return |
| | | */ |
| | | MesProductionOrder getByOrderCode(String orderCode); |
| | | |
| | | /** |
| | | * è·å䏿¬¡åæ¥åå»ºæ¥æææ°çæ¥æ |
| | | * @return |
| | | */ |
| | | String getLastSyncCreateDate(); |
| | | |
| | | /** |
| | | *è·å䏿¬¡åæ¥æ´æ°æ¥æææ°çæ¥æ |
| | | * @return |
| | | */ |
| | | String getLastSyncUpdateDate(); |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mes.entity.MesProductionOrder; |
| | | import org.jeecg.modules.mes.mapper.MesProductionOrderMapper; |
| | | import org.jeecg.modules.mes.service.IMesProductionOrderService; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map<String, MesProductionOrder> saveOrUpdateProductionOrder(List<ProductionOrderDTO> productionOrderDTOList) { |
| | | List<MesProductionOrder> addList = new ArrayList<>(); |
| | | List<MesProductionOrder> updateList = new ArrayList<>(); |
| | | Map<String, MesProductionOrder> resultMap = new HashMap<>(); |
| | | for (ProductionOrderDTO productionOrderDTO : productionOrderDTOList) { |
| | | MesProductionOrder updated = getByOrderCode(productionOrderDTO.getAUFNR()); |
| | | if (updated == null) { |
| | | updated = new MesProductionOrder(productionOrderDTO); |
| | | addList.add(updated); |
| | | resultMap.put(updated.getOrderCode(), updated); |
| | | this.getBaseMapper().insert(updated); |
| | | } else { |
| | | updated.updateEntity(productionOrderDTO); |
| | | updateList.add(updated); |
| | | resultMap.put(updated.getOrderCode(), updated); |
| | | this.getBaseMapper().updateById(updated); |
| | | } |
| | | } |
| | | if(CollectionUtil.isEmpty(addList)){ |
| | | super.saveBatch(addList); |
| | | } |
| | | if(CollectionUtil.isEmpty(updateList)){ |
| | | super.updateBatchById(updateList); |
| | | } |
| | | return resultMap; |
| | | } |
| | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public String getLastSyncCreateDate() { |
| | | String lastSyncDate = this.getBaseMapper().getLastSyncCreateDate(); |
| | | if(lastSyncDate == null){ |
| | | return null; |
| | | } |
| | | return lastSyncDate.replaceAll("-", ""); |
| | | } |
| | | |
| | | @Override |
| | | public String getLastSyncUpdateDate() { |
| | | String lastSyncDate = this.getBaseMapper().getLastSyncUpdateDate(); |
| | | if(lastSyncDate == null){ |
| | | return null; |
| | | } |
| | | return lastSyncDate.replaceAll("-", ""); |
| | | } |
| | | } |
| | |
| | | //éæ°æ°å¢å·¥åºä¿¡æ¯ |
| | | List<OrderProcessDTO> collect = orderProcessDTOList.stream().filter(orderProcessDTO -> entry.getKey().equals(orderProcessDTO.getAUFNR())).collect(Collectors.toList()); |
| | | if (CollectionUtil.isNotEmpty(collect)) { |
| | | List<PmsMaterialProcess> list = collect.stream().map(orderBomDTO -> new PmsMaterialProcess(entry.getKey(), order.getMaterialName(), orderBomDTO)).collect(Collectors.toList()); |
| | | List<PmsMaterialProcess> list = collect.stream().map(orderBomDTO -> new PmsMaterialProcess(order.getId(), order.getMaterialName(), orderBomDTO)).collect(Collectors.toList()); |
| | | super.saveBatch(list); |
| | | } |
| | | } |
| | |
| | | @ApiOperation(value = "SAPéææµè¯-ç产订å忥æ¥å£", notes = "SAPéææµè¯-ç产订å忥æ¥å£") |
| | | @GetMapping("/syncProductionOrder") |
| | | public Result<?> syncProductionOrder() throws Exception { |
| | | Map<String, Object> resultMap = productionOrderSync.syncProductionOrder(factoryCode, orderTypeCode1, productionManager, orderStatus, createTime, null); |
| | | Map<String, Object> resultMap = productionOrderSync.syncProductionOrder(factoryCode, orderTypeCode1, productionManager, orderStatus, null, null, null, null); |
| | | return Result.ok(resultMap); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 忥çæè®¢å |
| | | */ |
| | | Map<String, Object> syncProductionOrder(String factoryCode, String orderTypeCode, String productionManager, String orderStatus, String createTime, String updateTime) throws Exception; |
| | | Map<String, Object> syncProductionOrder(String factoryCode, String orderTypeCode, String productionManager, String orderStatus, String createTimeLow, String createTimeHigh, String updateTimeLow, String updateTimeHigh) throws Exception; |
| | | } |
| | |
| | | |
| | | @Override |
| | | @ApiLog(apiName = "ç产订å忥(ZPPF_033_1)", apiCategory = ApiLogCategoryEnum.SAP) |
| | | public Map<String, Object> syncProductionOrder(String factoryCode, String orderTypeCode, String productionManager, String orderStatus, String createTime, String updateTime) throws Exception { |
| | | public Map<String, Object> syncProductionOrder(String factoryCode, String orderTypeCode, String productionManager, String orderStatus, String createTimeLow, String createTimeHigh, String updateTimeLow, String updateTimeHigh) throws Exception { |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | JCoDestination destination = connectionManager.getDestination(); |
| | | JCoRepository repository = destination.getRepository(); |
| | |
| | | item.put("TXT04", orderStatus); |
| | | items.add(item); |
| | | } |
| | | if(StringUtils.isNotBlank(createTime)){ |
| | | if(StringUtils.isNotBlank(createTimeLow)){ |
| | | JCoTable UDATETable = function.getTableParameterList().getTable("ZTAB_UDATE"); |
| | | UDATETable.appendRow(); |
| | | UDATETable.setValue("LOW", createTime); |
| | | UDATETable.setValue("LOW", createTimeLow); |
| | | //ç»è£
请æ±åæ° |
| | | JSONObject item = new JSONObject(); |
| | | item.put("ZTAB_UDATE_LOW", createTime); |
| | | item.put("ZTAB_UDATE_LOW", createTimeLow); |
| | | items.add(item); |
| | | } |
| | | if(StringUtils.isNotBlank(updateTime)){ |
| | | JCoTable LAEDATable = function.getTableParameterList().getTable("ZTAB_LAEDA"); |
| | | LAEDATable.appendRow(); |
| | | LAEDATable.setValue("LOW", updateTime); |
| | | if(StringUtils.isNotBlank(createTimeHigh)){ |
| | | JCoTable UDATETable = function.getTableParameterList().getTable("ZTAB_UDATE"); |
| | | UDATETable.appendRow(); |
| | | UDATETable.setValue("HIGH", createTimeHigh); |
| | | //ç»è£
请æ±åæ° |
| | | JSONObject item = new JSONObject(); |
| | | item.put("ZTAB_LAEDA_LOW", updateTime); |
| | | item.put("ZTAB_UDATE_HIGH", createTimeHigh); |
| | | items.add(item); |
| | | } |
| | | if(StringUtils.isNotBlank(updateTimeLow)){ |
| | | JCoTable LAEDATable = function.getTableParameterList().getTable("ZTAB_LAEDA"); |
| | | LAEDATable.appendRow(); |
| | | LAEDATable.setValue("LOW", updateTimeLow); |
| | | //ç»è£
请æ±åæ° |
| | | JSONObject item = new JSONObject(); |
| | | item.put("ZTAB_LAEDA_LOW", updateTimeLow); |
| | | items.add(item); |
| | | } |
| | | if(StringUtils.isNotBlank(updateTimeHigh)){ |
| | | JCoTable LAEDATable = function.getTableParameterList().getTable("ZTAB_LAEDA"); |
| | | LAEDATable.appendRow(); |
| | | LAEDATable.setValue("HIGH", updateTimeLow); |
| | | //ç»è£
请æ±åæ° |
| | | JSONObject item = new JSONObject(); |
| | | item.put("ZTAB_LAEDA_HIGH", updateTimeLow); |
| | | items.add(item); |
| | | } |
| | | // æ§è¡è°ç¨ |