src/main/java/org/jeecg/common/constant/CommonConstant.java
@@ -618,4 +618,9 @@ Integer SHIFT_TYPE_1 = 1; Integer SHIFT_TYPE_2 = 2; /** * SAP请求成功编码 */ String SAP_SUCCESS_CODE = "S"; } src/main/java/org/jeecg/modules/mes/controller/MesProductionOrderController.java
@@ -111,4 +111,14 @@ }).collect(Collectors.toList()); return Result.OK(res); } @ApiOperation(value = "SAP生产订单-根据订单号同步最新信息", notes = "SAP生产订单-根据订单号同步最新信息") @GetMapping(value = "/syncSapProductionOrder") public Result<?> syncSapProductionOrder(@RequestParam(name = "id") String id) { boolean b = mesProductionOrderService.syncSapProductionOrder(id); if (!b) { return Result.error("同步失败!"); } return Result.ok("同步成功!"); } } 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.common.constant.CommonConstant; import org.jeecg.modules.lsw.service.ILswMaterialService; import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.util.ThrowableUtil; @@ -72,11 +73,6 @@ @Value("${xhj.orderStatus:REL}") private String ORDER_STATUS; /** * 请求成功编码 */ private static final String SUCCESS_CODE = "S"; @Autowired private ProductionOrderSync productionOrderSync; @Autowired @@ -125,7 +121,7 @@ try { //调用SAP接口获取生产订单 Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(request); if (productionOrderMap == null || !SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) { if (productionOrderMap == null || !CommonConstant.SAP_SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) { log.error("未同步到订单信息!日期:{}", LocalDateTime.now()); return; } @@ -141,7 +137,7 @@ 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"))) { if (orderBomMap == null || !CommonConstant.SAP_SUCCESS_CODE.equals(orderBomMap.get("ztype"))) { log.error("未同步到订单BOM信息!日期:{}", LocalDateTime.now()); return; } @@ -167,7 +163,7 @@ } //订单工序同步 Map<String, Object> orderProcessMap = orderProcessSync.syncOrderProcess(FACTORY_CODE, orderCodes); if (orderBomMap == null || !SUCCESS_CODE.equals(orderProcessMap.get("ztype"))) { if (orderBomMap == null || !CommonConstant.SAP_SUCCESS_CODE.equals(orderProcessMap.get("ztype"))) { log.error("未同步到订单工序信息!日期:{}", LocalDateTime.now()); return; } src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
@@ -1,6 +1,7 @@ package org.jeecg.modules.mes.job; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.constant.CommonConstant; import org.jeecg.modules.lsw.service.ILswMaterialService; import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.util.ThrowableUtil; @@ -72,11 +73,6 @@ @Value("${xhj.orderStatus:REL}") private String ORDER_STATUS; /** * 请求成功编码 */ private static final String SUCCESS_CODE = "S"; @Autowired private ProductionOrderSync productionOrderSync; @Autowired @@ -125,7 +121,7 @@ try { //调用SAP接口获取生产订单 Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(request); if (productionOrderMap == null || !SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) { if (productionOrderMap == null || !CommonConstant.SAP_SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) { log.error("未同步到订单信息!日期:{}", LocalDateTime.now()); return; } @@ -141,7 +137,7 @@ 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"))) { if (orderBomMap == null || !CommonConstant.SAP_SUCCESS_CODE.equals(orderBomMap.get("ztype"))) { log.error("未同步到订单BOM信息!日期:{}", LocalDateTime.now()); return; } @@ -166,7 +162,7 @@ } //订单工序同步 Map<String, Object> orderProcessMap = orderProcessSync.syncOrderProcess(FACTORY_CODE, orderCodes); if (orderBomMap == null || !SUCCESS_CODE.equals(orderProcessMap.get("ztype"))) { if (orderBomMap == null || !CommonConstant.SAP_SUCCESS_CODE.equals(orderProcessMap.get("ztype"))) { log.error("未同步到订单工序信息!日期:{}", LocalDateTime.now()); return; } src/main/java/org/jeecg/modules/mes/service/IMesProductionOrderService.java
@@ -40,4 +40,11 @@ * @return */ String getLastSyncUpdateDate(); /** * 同步SAP生产订单的最新状态 * @param id * @return */ boolean syncSapProductionOrder(String id); } src/main/java/org/jeecg/modules/mes/service/impl/MesProductionOrderServiceImpl.java
@@ -4,15 +4,21 @@ 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.common.exception.JeecgBootException; import org.jeecg.modules.mes.entity.MesProductionOrder; import org.jeecg.modules.mes.mapper.MesProductionOrderMapper; import org.jeecg.modules.mes.service.IMesProductionOrderService; import org.jeecg.modules.sap.dto.ProductionOrderDTO; import org.jeecg.modules.sap.request.ProductionOrderSyncRequest; import org.jeecg.modules.sap.service.ProductionOrderSync; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Description: SAP生产订单 @@ -22,6 +28,12 @@ */ @Service public class MesProductionOrderServiceImpl extends ServiceImpl<MesProductionOrderMapper, MesProductionOrder> implements IMesProductionOrderService { //工厂编码(新火炬 2301) @Value("${xhj.factoryCode:2301}") private String FACTORY_CODE; @Autowired private ProductionOrderSync productionOrderSync; @Override @Transactional(rollbackFor = Exception.class) @@ -57,7 +69,7 @@ @Override public String getLastSyncCreateDate() { String lastSyncDate = this.getBaseMapper().getLastSyncCreateDate(); if(lastSyncDate == null){ if (lastSyncDate == null) { return null; } return lastSyncDate.replaceAll("-", ""); @@ -66,9 +78,46 @@ @Override public String getLastSyncUpdateDate() { String lastSyncDate = this.getBaseMapper().getLastSyncUpdateDate(); if(lastSyncDate == null){ if (lastSyncDate == null) { return null; } return lastSyncDate.replaceAll("-", ""); } @Override @Transactional(rollbackFor = Exception.class) public boolean syncSapProductionOrder(String id) { MesProductionOrder entity = super.getById(id); if (entity == null) { throw new JeecgBootException("生产订单不存在,请刷新重置!"); } ProductionOrderSyncRequest request = new ProductionOrderSyncRequest(); request.setOrderCode(entity.getOrderCode()); request.setFactoryCode(FACTORY_CODE); try { Map<String, Object> resultMap = productionOrderSync.syncProductionOrder(request); if (resultMap == null) { throw new JeecgBootException("响应结果为空!"); } if (!CommonConstant.SAP_SUCCESS_CODE.equals(resultMap.get("ztype"))) { throw new JeecgBootException(resultMap.get("zmess").toString()); } //调用成功,获取返回数据 Object result = resultMap.get("result"); boolean b = result instanceof List; if (!b) { throw new JeecgBootException("返回结果格式错误!"); } List<ProductionOrderDTO> productionOrderDTOList = (List<ProductionOrderDTO>) result; if (CollectionUtil.isEmpty(productionOrderDTOList)) { throw new JeecgBootException("SAP未查询到生成订单!"); } ProductionOrderDTO dto = productionOrderDTOList.get(0); entity.updateEntity(dto); super.updateById(entity); } catch (Exception e) { throw new JeecgBootException("请求SAP失败:" + e.getMessage()); } return true; } }