package com.zy.asrs.service.impl; import com.core.common.Cools; import com.core.common.DateUtils; import com.core.exception.CoolException; import com.zy.asrs.entity.LocMast; import com.zy.asrs.entity.WrkMast; import com.zy.asrs.service.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.HashMap; import java.util.concurrent.TimeUnit; @Slf4j @Service public class WorkServiceImpl implements WorkService { @Autowired private WrkMastService wrkMastService; @Autowired private LocMastService locMastService; @Autowired private WrkMastLogService wrkMastLogService; @Autowired private ToWmsService toWmsService; @Override @Transactional public void completeWrkMast(String workNo, Long userId) { WrkMast wrkMast = wrkMastService.selectById(workNo); if (Cools.isEmpty(wrkMast)) { throw new CoolException(workNo + "工作档不存在"); } if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 14) { throw new CoolException("当前工作档已完成"); } // 入库 + 库位转移 if (wrkMast.getWrkSts() < 4 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType() == 11)) { wrkMast.setWrkSts(4L); // 出库 } else if (wrkMast.getWrkSts() > 10) { wrkMast.setWrkSts(14L); } Date now = new Date(); wrkMast.setCrnStrTime(DateUtils.calculate(now, 1L, TimeUnit.SECONDS, true)); wrkMast.setCrnEndTime(now); wrkMast.setModiTime(now); wrkMast.setModiUser(userId); // 完成操作人员记录 wrkMast.setManuType("手动完成"); if (!wrkMastService.updateById(wrkMast)) { throw new CoolException("修改工作档失败"); } HashMap headParam = new HashMap<>(); headParam.put("TaskNo", wrkMast.getTaskNo()); headParam.put("Result", 0);//完成 toWmsService.addReportLog(wrkMast); } @Override @Transactional public void cancelWrkMast(String workNo, Long userId) { Date now = new Date(); WrkMast wrkMast = wrkMastService.selectById(workNo); String locNo = ""; // 待修改目标库位 String locSts = ""; // 待修改目标库位状态 // 入库取消(修改目标库位) if (wrkMast.getWrkSts() < 4) { locNo = wrkMast.getLocNo(); locSts = "O"; // 库位转移 if (wrkMast.getIoType() == 11) { // 库位转移:源库位 LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo()); if (Cools.isEmpty(locMast)) { throw new CoolException("取消库位转移失败,源库位不存在:" + wrkMast.getSourceLocNo()); } locMast.setLocSts(wrkMast.getFullPlt().equalsIgnoreCase("N") ? "D" : "F"); locMast.setModiTime(now); locMast.setModiUser(userId); locMastService.updateById(locMast); } // 出库取消(修改源库位) } else if (wrkMast.getWrkSts() > 10 && wrkMast.getWrkSts() != 14) { locNo = wrkMast.getSourceLocNo(); // 出库 ===>> F.在库 if (wrkMast.getIoType() > 100 && wrkMast.getIoType() != 110) { locSts = "F"; // 空板出库 ===>> D.空桶/空栈板 } else if (wrkMast.getIoType() == 110) { locSts = "D"; // 库位转移 ===>> D.空桶/空栈板 } else if (wrkMast.getIoType() == 11) { locSts = wrkMast.getFullPlt().equalsIgnoreCase("N") ? "D" : "F"; // 库位转移:目标库位 LocMast locMast = locMastService.selectById(wrkMast.getLocNo()); if (Cools.isEmpty(locMast)) { throw new CoolException("取消库位转移失败,目标库位不存在:" + wrkMast.getSourceLocNo()); } locMast.setLocSts("O"); locMast.setModiTime(now); locMast.setModiUser(userId); locMastService.updateById(locMast); } } else { throw new CoolException("当前工作状态无法取消"); } // 取消操作人员记录 wrkMast.setManuType("手动取消"); wrkMast.setModiUser(userId); wrkMast.setModiTime(now); if (!wrkMastService.updateById(wrkMast)) { throw new CoolException("取消任务失败"); } // 保存工作主档历史档 if (!wrkMastLogService.save(wrkMast.getWrkNo())) { throw new CoolException("保存任务历史档失败, workNo = " + wrkMast.getWrkNo()); } // 删除工作主档 boolean wrkMastRes = wrkMastService.deleteById(wrkMast); // 修改库位状态 LocMast locMast = locMastService.selectById(locNo); if (Cools.isEmpty(locMast)) { throw new CoolException("取消任务失败,库位不存在:" + locNo); } locMast.setLocSts(locSts); locMast.setModiTime(now); locMast.setModiUser(userId); boolean locMastRes = locMastService.updateById(locMast); if (!wrkMastRes || !locMastRes) { throw new CoolException("保存数据失败"); } HashMap headParam = new HashMap<>(); headParam.put("TaskNo", wrkMast.getTaskNo()); headParam.put("Result", 1);//取消 toWmsService.addReportLog(wrkMast); } }