package org.jeecg.modules.mes.job;
|
|
import lombok.extern.slf4j.Slf4j;
|
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.sap.dto.OrderBomDTO;
|
import org.jeecg.modules.sap.dto.OrderProcessDTO;
|
import org.jeecg.modules.sap.dto.ProductionOrderDTO;
|
import org.jeecg.modules.sap.service.OrderBomSync;
|
import org.jeecg.modules.sap.service.OrderProcessSync;
|
import org.jeecg.modules.sap.service.ProductionOrderSync;
|
import org.quartz.Job;
|
import org.quartz.JobExecutionContext;
|
import org.quartz.JobExecutionException;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.time.LocalDateTime;
|
import java.util.List;
|
import java.util.Map;
|
|
@Component
|
@Slf4j
|
public class ProductionOrderSyncJob implements Job {
|
//工厂编码(新火炬 2301)
|
private static final String FACTORY_CODE = "2301";
|
/**
|
* 订单类型
|
* 标准生产订单 Z001
|
* 客退返工生产订单 Z002
|
* 呆滞处理返工生产订单 Z003
|
* 试制生产订单(新火炬) Z011
|
* 拆零生产订单(新火炬) 2012
|
*/
|
private static final String ORDER_TYPE_CODE = "Z001";
|
/**
|
* 生产调度员
|
* 001 一分厂调度员
|
* 002 二分厂调度员
|
* 003 三分厂调度员
|
* 004 四分厂调度员
|
* 005 ABS调度员
|
* 006 调质调度员
|
* 007 五分厂调度员
|
* 008 试制车间调度员
|
* 009 外采调度员
|
* 010 六厂调度员
|
* 012 八分厂调度员
|
*/
|
private static final String PRODUCTION_MANAGER = "010";
|
/**
|
* 生产订单状态,实际上,只有REL状态的工单才可以进行操作
|
* CRTD 新建
|
* REL 下达
|
* TECO 关闭
|
*/
|
private static final String ORDER_STATUS = "REL";
|
|
/**
|
* 请求成功编码
|
*/
|
private static final String SUCCESS_CODE = "S";
|
|
@Autowired
|
private ProductionOrderSync productionOrderSync;
|
@Autowired
|
private OrderBomSync orderBomSync;
|
@Autowired
|
private OrderProcessSync orderProcessSync;
|
@Autowired
|
private IMesProductionOrderService productionOrderService;
|
@Autowired
|
private IPmsProcessBillMaterialsService processBillMaterialsService;
|
@Autowired
|
private IPmsMaterialProcessService materialProcessService;
|
|
@Override
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
//获取上次同步时间
|
try {
|
//调用SAP接口获取生产订单
|
Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(FACTORY_CODE, ORDER_TYPE_CODE, PRODUCTION_MANAGER, ORDER_STATUS, null, null);
|
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) {
|
log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
|
return;
|
}
|
List<ProductionOrderDTO> productionOrderDTOList = (List<ProductionOrderDTO>) result;
|
Map<String, MesProductionOrder> orderMap = productionOrderService.saveOrUpdateProductionOrder(productionOrderDTOList);
|
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"))) {
|
log.error("未同步到订单BOM信息!日期:{}", LocalDateTime.now());
|
return;
|
}
|
//调用成功,获取返回数据
|
result = orderBomMap.get("result");
|
b = result instanceof List;
|
if(!b) {
|
log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
|
return;
|
}
|
List<OrderBomDTO> orderBomDTOList = (List<OrderBomDTO>) result;
|
b = processBillMaterialsService.saveOrUpdateOrderBom(orderMap, orderBomDTOList);
|
if(!b) {
|
log.error("保存订单BOM失败,日期:{}", LocalDateTime.now());
|
return;
|
}
|
//订单工序同步
|
Map<String, Object> orderProcessMap = orderProcessSync.syncOrderProcess(FACTORY_CODE, orderCodes);
|
if (orderBomMap == null || !SUCCESS_CODE.equals(orderProcessMap.get("ztype"))) {
|
log.error("未同步到订单工序信息!日期:{}", LocalDateTime.now());
|
return;
|
}
|
//调用成功,获取返回数据
|
result = orderBomMap.get("result");
|
b = result instanceof List;
|
if(!b) {
|
log.error("返回类型错误, class:{}", result == null ? null : result.getClass());
|
return;
|
}
|
List<OrderProcessDTO> orderProcessDTOList = (List<OrderProcessDTO>) result;
|
b = materialProcessService.saveOrUpdateOrderProcess(orderMap, orderProcessDTOList);
|
if(!b) {
|
log.error("保存订单工序失败,日期:{}", LocalDateTime.now());
|
}
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
|
}
|
}
|