|
|
|
|
@ -652,6 +652,141 @@ public class WorkOrderRunServiceImpl extends BaseServiceImpl<WorkOrderRunMapper, |
|
|
|
|
workOrder.setRunStatus(WorkOrder.RUN_STATUS_RECEIVE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R oemOrderOut() { |
|
|
|
|
// 扫描待外协下达的车间订单:oem_out=0 且未完工
|
|
|
|
|
List<WorkOrder> workOrders = workOrderMapper.selectList(new LambdaQueryWrapper<WorkOrder>() |
|
|
|
|
.eq(WorkOrder::getOemOut, "0") |
|
|
|
|
.lt(WorkOrder::getRunStatus, WorkOrder.RUN_STATUS_COMPLETED) |
|
|
|
|
.isNotNull(WorkOrder::getWorId)); |
|
|
|
|
|
|
|
|
|
List<String> errors = new ArrayList<>(); |
|
|
|
|
for (WorkOrder wo : workOrders) { |
|
|
|
|
try { |
|
|
|
|
// 运行记录
|
|
|
|
|
WorkOrderRun workOrderRun = workOrderRunMapper.selectById(wo.getWorId()); |
|
|
|
|
if (workOrderRun == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
// 运行记录中无外协商则跳过
|
|
|
|
|
if (workOrderRun.getInCustomer() == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
// 生产订单
|
|
|
|
|
YieldOrder yo = yieldOrderMapper.selectById(wo.getYoId()); |
|
|
|
|
if (yo == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
// 当前工序
|
|
|
|
|
WorkPlan wp = workPlanMapper.selectById(wo.getWpId()); |
|
|
|
|
if (wp == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
// 首道工序 → 生产订单状态设为加工中
|
|
|
|
|
if (wp.getFrontWpId() == null) { |
|
|
|
|
yo.setStatus(5); |
|
|
|
|
yieldOrderMapper.updateById(yo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Oem oem = oemMapper.selectById(workOrderRun.getInCustomer()); |
|
|
|
|
User planner = UserCache.getUser(wo.getPlanner()); |
|
|
|
|
String wxWoCode; |
|
|
|
|
|
|
|
|
|
if (workOrderRun.getCollaborate() != null && workOrderRun.getCollaborate().equalsIgnoreCase("1")) { |
|
|
|
|
// 协作外协:组装工序名称
|
|
|
|
|
List<WorkPlan> wpList = workPlanMapper.selectList(new LambdaQueryWrapper<WorkPlan>() |
|
|
|
|
.eq(WorkPlan::getWoId, wo.getId())); |
|
|
|
|
List<BsProcessSetEntity> processSets = processSetMapper.selectByIds( |
|
|
|
|
wpList.stream().filter(workPlan -> oem.getId().equals(workPlan.getOcId())) |
|
|
|
|
.map(WorkPlan::getPpsId).collect(Collectors.toList())); |
|
|
|
|
String ppsName = processSets.stream().map(BsProcessSetEntity::getName).collect(Collectors.joining(",")); |
|
|
|
|
// 最大计划结束时间
|
|
|
|
|
LocalDateTime maxPlanEndTime = wpList.stream().map(WorkPlan::getPlanEndTime) |
|
|
|
|
.max(LocalDateTime::compareTo).orElse(null); |
|
|
|
|
if (maxPlanEndTime == null) { |
|
|
|
|
maxPlanEndTime = LocalDateTime.now(); |
|
|
|
|
} |
|
|
|
|
wxWoCode = erpDataOemClient.fullOrderOutsourcing( |
|
|
|
|
yo.getPartCode(), yo.getProductIdent(), wo.getBatchNo(), |
|
|
|
|
oem != null ? oem.getCode() : "", ppsName, yo.getYoCode(), |
|
|
|
|
planner != null ? planner.getName() : "", |
|
|
|
|
maxPlanEndTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), |
|
|
|
|
wo.getMakeQty(), "").getData(); |
|
|
|
|
} else { |
|
|
|
|
// 整体外协:获取B号C号
|
|
|
|
|
User user = UserCache.getUser(workOrderRun.getCreateUser()); |
|
|
|
|
User dispatcher = UserCache.getUser(wo.getDispatcher()); |
|
|
|
|
String roamNo = null; |
|
|
|
|
String craftNo = null; |
|
|
|
|
Long craftId = yo.getCraftId(); |
|
|
|
|
if (craftId != null && wo.getReworkCode() == null) { |
|
|
|
|
Map<String, String> craftInfo = baseMapper.selectRoamAndCraftNoByCraftId(craftId); |
|
|
|
|
roamNo = craftInfo.get("ROAMNO"); |
|
|
|
|
craftNo = craftInfo.get("CRAFTNO"); |
|
|
|
|
if (roamNo == null) { |
|
|
|
|
craftInfo = baseMapper.selectRoamAndCraftNoByPartCode(yo.getPartCode()); |
|
|
|
|
roamNo = craftInfo.get("ROAMNO"); |
|
|
|
|
craftNo = craftInfo.get("CRAFTNO"); |
|
|
|
|
} |
|
|
|
|
} else if (StringUtils.isNotBlank(wo.getReworkCode())) { |
|
|
|
|
roamNo = wo.getReworkCode(); |
|
|
|
|
craftNo = "返修"; |
|
|
|
|
craftId = Long.valueOf(wo.getReworkNo()); |
|
|
|
|
} |
|
|
|
|
String demandDateStr = ""; |
|
|
|
|
if (yo.getDemandDate() != null) { |
|
|
|
|
demandDateStr = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") |
|
|
|
|
.withZone(ZoneId.systemDefault()).format(yo.getDemandDate().toInstant()); |
|
|
|
|
} |
|
|
|
|
wxWoCode = erpDataOemClient.collaborativeOutsourcing( |
|
|
|
|
yo.getPartCode(), yo.getProductIdent(), demandDateStr, wo.getMakeQty(), |
|
|
|
|
yo.getUseDeptCode(), yo.getUseDept(), wo.getBatchNo(), |
|
|
|
|
oem != null ? oem.getCode() : "", yo.getPlate(), yo.getYpCode(), yo.getYoCode(), |
|
|
|
|
user != null ? user.getName() : "", |
|
|
|
|
planner != null ? planner.getName() : "", |
|
|
|
|
dispatcher != null ? dispatcher.getName() : "", |
|
|
|
|
roamNo, craftNo, craftId).getData(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ERP返回成功,回写工序状态和车间订单
|
|
|
|
|
if (StringUtils.isNotBlank(wxWoCode)) { |
|
|
|
|
workOrderRun.setWoCode(wxWoCode); |
|
|
|
|
workOrderRunMapper.updateById(workOrderRun); |
|
|
|
|
updateWorkPlanAndOrderStatus(wo, wxWoCode); |
|
|
|
|
workOrderMapper.updateById(wo); |
|
|
|
|
|
|
|
|
|
// 协作外协:生成镀前出库记录
|
|
|
|
|
// if (wo.getOemType() != null && wo.getOemType() == WorkOrder.OEM_TYPE_SINGLE) {
|
|
|
|
|
// Long count = plateAroundMapper.selectCount(new LambdaQueryWrapper<PlateAround>()
|
|
|
|
|
// .eq(PlateAround::getWpId, wo.getWpId())
|
|
|
|
|
// .eq(PlateAround::getPaType, PlateAround.BEFORE_PLAT_IN));
|
|
|
|
|
// if (count > 0) {
|
|
|
|
|
// WorkPlan nextPlan = workPlanMapper.selectOne(new LambdaQueryWrapper<WorkPlan>()
|
|
|
|
|
// .eq(WorkPlan::getId, wp.getNextWpId()));
|
|
|
|
|
// PlateAround plateAround = new PlateAround();
|
|
|
|
|
// plateAround.setPaCode(generatePaCode());
|
|
|
|
|
// plateAround.setWpId(wo.getWpId());
|
|
|
|
|
// plateAround.setOcId(nextPlan != null ? nextPlan.getOcId() : null);
|
|
|
|
|
// plateAround.setPaType((short) 2);
|
|
|
|
|
// plateAround.setQuantity(wo.getMakeQty());
|
|
|
|
|
// plateAround.setCurStatus((short) 2);
|
|
|
|
|
// plateAround.setCreateUser(wo.getDispatcher());
|
|
|
|
|
// plateAround.setCreateTime(new Date());
|
|
|
|
|
// plateAroundMapper.insert(plateAround);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
errors.add("车间订单" + wo.getWoCode() + "外协下达失败:" + e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!errors.isEmpty()) { |
|
|
|
|
return R.fail(String.join(";", errors)); |
|
|
|
|
} |
|
|
|
|
return R.success("外协订单下达完成"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
@Override |
|
|
|
|
public R changeOemManufacturer(Long worId, Long ocId) { |
|
|
|
|
|