| | |
| | | import com.zy.common.model.OutLocDto; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.service.erp.ErpSqlServer; |
| | | 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.text.MessageFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | |
| | | private WrkMastLogService wrkMastLogService; |
| | | @Autowired |
| | | private WrkDetlLogService wrkDetlLogService; |
| | | @Autowired |
| | | private ErpSqlServer erpSqlServer; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | matDtos.add(new MatCodeCountDto(elem.getMatNo(), elem.getCount(), elem.getMatStatus(), elem.getStr5(), elem.getStr6())); |
| | | }); |
| | | wrkDetlService.createWorkDetail(workNo, matDtos, param.getBarcode(), userId); |
| | | // 成品物料 |
| | | // 成品物料 |
| | | } else { |
| | | // 保持工作档明细 |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | |
| | | sourceStaNo.setWrkNo(workNo); |
| | | sourceStaNo.setModiUser(userId); |
| | | sourceStaNo.setModiTime(new Date()); |
| | | if (!basDevpService.updateById(sourceStaNo)){ |
| | | if (!basDevpService.updateById(sourceStaNo)) { |
| | | throw new CoolException("更新源站失败"); |
| | | } |
| | | // 更新目标库位状态 |
| | | LocMast locMast = locMastService.selectById(dto.getLocNo()); |
| | | if (locMast.getLocSts().equals("O")){ |
| | | if (locMast.getLocSts().equals("O")) { |
| | | locMast.setLocSts("S"); // S.入库预约 |
| | | locMast.setModiUser(userId); |
| | | locMast.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast)){ |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("改变库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException(dto.getLocNo()+"目标库位已被占用"); |
| | | throw new CoolException(dto.getLocNo() + "目标库位已被占用"); |
| | | } |
| | | // 判断无通知单号supplier的入库数据,CPICMO插入数据 |
| | | List<FullStoreParam.MatCodeStore> erpMatList = param.getList(); |
| | | for (FullStoreParam.MatCodeStore es : erpMatList) { |
| | | if (Cools.isEmpty(es.getStr6())) { |
| | | String maxKeySql = "select max(FInterID) as num from CPICMO"; |
| | | List<ERPselectParam> maxKeyList = erpSqlServer.select(maxKeySql, ERPselectParam.class); |
| | | Integer maxKey = maxKeyList.get(0).getNum(); |
| | | String ErpSql = "insert into CPICMO(FBrNo, FSourceBillNo, FBillNo, FTranType, FStatus, FMRP, FItemID, FQty, FCommitQty, FSourceEntryID, FClosed, FUnitID, FAuxCommitQty, FCancellation, FQtyFinish, FQtyScrap, FQtyLost, FAuxQtyFinish, FAuxQtyScrap, FAuxQtyLost, FMrpClosed, FBomInterID, FQtyPass, FAuxQtyPass, FQtyBack, FAuxQtyBack, FFinishTime, FReadyTIme, FPowerCutTime, FFixTime, FWaitItemTime, FWaitToolTime, FTaskID, FWorkTypeID, FCostObjID, FStockQty, FAuxStockQty, FSuspend, FReleasedQty, FReleasedAuxQty, FUnScheduledQty, FUnScheduledAuxQty, FSubEntryID, FScheduleID, FPlanOrderInterID, FProcessPrice, FProcessFee, FGMPBatchNo, FGMPCollectRate, FGMPItemBalance, FGMPBulkQty, FCustID, FMRPLockFlag, FHandworkClose, FInHighLimit, FInHighLimitQty, FInLowLimit, FInLowLimitQty, FChangeTimes, FCheckCommitQty, FAuxCheckCommitQty, FPlanConfirmed, FPlanMode, FMTONo, FPrintCount, FFinClosed, FStockFlag, FStartFlag, FVchBillNo, FVchInterID, FCardClosed, FHRReadyTime, FSourceTranType, FSourceInterId, FInterID, FAuxQty, FAuxInHighLimitQty, FAuxInLowLimitQty, Fnumber, FWorkShop) values (0, 0, '0', 85, 0, 1052, 0, 0, 0, 0, 0, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14036, '0', 0, 0, 14215, 0, '0', 0, 1059, 0, 0, 0, 0, {0,number,#}, {1,number,#}, {2,number,#}, {3,number,#}, ''{4}'' 11378)"; |
| | | ErpSql = MessageFormat.format(ErpSql, maxKey + 1, es.getCount(), es.getCount(), es.getCount(), es.getMatNo()); |
| | | erpSqlServer.update(ErpSql); |
| | | } |
| | | } |
| | | return dto.getLocNo(); |
| | | } |
| | |
| | | wrkMast.setModiUser(userId); |
| | | wrkMast.setModiTime(new Date()); |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | throw new CoolException("保存工作档失败,出库库位号:"+dto.getLocNo()); |
| | | throw new CoolException("保存工作档失败,出库库位号:" + dto.getLocNo()); |
| | | } |
| | | // 生成工作档明细 |
| | | for (LocDetlDto detlDto : dto.getLocDetlDtos()) { |
| | | // 出库时,数量为0的直接忽略 |
| | | if (detlDto.getCount()==null || detlDto.getCount() <= 0.0D) {continue;} |
| | | if (detlDto.getCount() == null || detlDto.getCount() <= 0.0D) { |
| | | continue; |
| | | } |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | wrkDetl.setWrkNo(workNo); |
| | | wrkDetl.setIoTime(new Date()); |
| | | Double anfme = ioType==101?detlDto.getLocDetl().getAnfme():detlDto.getCount(); |
| | | Double anfme = ioType == 101 ? detlDto.getLocDetl().getAnfme() : detlDto.getCount(); |
| | | wrkDetl.setAnfme(anfme); // 数量 |
| | | VersionUtils.setWrkDetl(wrkDetl, detlDto.getLocDetl()); // 版本控制 |
| | | wrkDetl.setAppeTime(new Date()); |
| | |
| | | // 修改库位状态: F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 |
| | | locMast = locMastService.selectById(dto.getLocNo()); |
| | | if (locMast.getLocSts().equals("F")) { |
| | | locMast.setLocSts(ioType==101?"R":"P"); |
| | | locMast.setLocSts(ioType == 101 ? "R" : "P"); |
| | | locMast.setModiUser(userId); |
| | | locMast.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("预约库位状态失败,库位号:"+dto.getLocNo()); |
| | | throw new CoolException("预约库位状态失败,库位号:" + dto.getLocNo()); |
| | | } |
| | | } else { |
| | | throw new CoolException(dto.getLocNo() + "库位不是在库状态"); |
| | |
| | | sourceStaNo.setWrkNo(workNo); |
| | | sourceStaNo.setModiUser(userId); |
| | | sourceStaNo.setModiTime(new Date()); |
| | | if (!basDevpService.updateById(sourceStaNo)){ |
| | | if (!basDevpService.updateById(sourceStaNo)) { |
| | | throw new CoolException("更新源站失败"); |
| | | } |
| | | // 更新目标库位状态 |
| | | LocMast locMast = locMastService.selectById(dto.getLocNo()); |
| | | if (locMast.getLocSts().equals("O")){ |
| | | if (locMast.getLocSts().equals("O")) { |
| | | locMast.setLocSts("S"); // S.入库预约 |
| | | locMast.setModiUser(userId); |
| | | locMast.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast)){ |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("改变库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException(dto.getLocNo()+"目标库位已被占用"); |
| | | throw new CoolException(dto.getLocNo() + "目标库位已被占用"); |
| | | } |
| | | return dto.getLocNo(); |
| | | } |
| | |
| | | // 获取库位 |
| | | LocMast locMast = locMastService.selectById(locNo); |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException(locNo+"库位不存在"); |
| | | throw new CoolException(locNo + "库位不存在"); |
| | | } |
| | | // 获取源站 |
| | | Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() |
| | |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 更新库位状态 D.空板 -> R.出库预约 |
| | | if (locMast.getLocSts().equals("D")){ |
| | | if (locMast.getLocSts().equals("D")) { |
| | | locMast.setLocSts("R"); |
| | | locMast.setModiUser(userId); |
| | | locMast.setModiTime(new Date()); |
| | |
| | | if (null != one) locDetlDtos.add(new LocDetlDto(one, one.getAnfme())); |
| | | } |
| | | } |
| | | for (LocDetlDto e: locDetlDtos) { |
| | | for (LocDetlDto e : locDetlDtos) { |
| | | if (Cools.isEmpty(e.getLocDetl().getZpallet())) { |
| | | throw new CoolException("托盘码为空不允许盘点,库位号" + e.getLocDetl().getLocNo()); |
| | | } |
| | |
| | | @Transactional |
| | | public void locMove(String sourceLocNo, String locNo, Long userId) { |
| | | LocMast sourceLoc = locMastService.selectById(sourceLocNo); |
| | | if (Cools.isEmpty(sourceLoc)){ |
| | | if (Cools.isEmpty(sourceLoc)) { |
| | | throw new CoolException("未找到库位"); |
| | | } |
| | | LocMast loc = locMastService.selectById(locNo); |
| | | if (Cools.isEmpty(loc)){ |
| | | if (Cools.isEmpty(loc)) { |
| | | throw new CoolException("未找到库位"); |
| | | } |
| | | if (!sourceLoc.getCrnNo().equals(loc.getCrnNo())) { |
| | |
| | | wrkMast.setFullPlt("N"); // 满板:Y |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 空板 |
| | | wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板 |
| | | wrkMast.setBarcode(sourceLoc.getBarcode()); // 托盘码 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setAppeUser(userId); |
| | |
| | | sourceLoc.setLocSts("R"); // R.出库预约 |
| | | sourceLoc.setModiUser(userId); |
| | | sourceLoc.setModiTime(new Date()); |
| | | if (!locMastService.updateById(sourceLoc)){ |
| | | if (!locMastService.updateById(sourceLoc)) { |
| | | throw new CoolException("更新源库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("源库位出库失败,状态:"+sourceLoc.getLocSts$()); |
| | | throw new CoolException("源库位出库失败,状态:" + sourceLoc.getLocSts$()); |
| | | } |
| | | // 修改目标库位状态 |
| | | if (loc.getLocSts().equals("O")) { |
| | |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败,目标库位状态:"+loc.getLocSts$()); |
| | | throw new CoolException("移转失败,目标库位状态:" + loc.getLocSts$()); |
| | | } |
| | | } |
| | | |
| | |
| | | @Transactional |
| | | public void completeWrkMast(String workNo, Long userId) { |
| | | WrkMast wrkMast = wrkMastService.selectById(workNo); |
| | | if (Cools.isEmpty(wrkMast)){ |
| | | throw new CoolException(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)) { |
| | | if (wrkMast.getWrkSts() < 4 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType() == 11)) { |
| | | wrkMast.setWrkSts(4L); |
| | | // 出库 |
| | | // 出库 |
| | | } else if (wrkMast.getWrkSts() > 10) { |
| | | wrkMast.setWrkSts(14L); |
| | | } |
| | |
| | | LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam)); |
| | | // 保存新库存明细 |
| | | if (Cools.isEmpty(one)) { |
| | | if (adjust.getCount() == 0){ |
| | | if (adjust.getCount() == 0) { |
| | | continue; |
| | | } |
| | | MatCode matCode = matCodeService.selectById(adjust.getMatnr()); |
| | |
| | | adjDetl.setOriQty(0.0D); |
| | | adjDetl.setAdjQty(adjust.getCount()); |
| | | adjDetlService.save(adjDetl, userId); |
| | | // 修改原库存明细 |
| | | // 调整库存,新增,StockCheckRecord插入盘盈数据 |
| | | String ErpSql = "insert into StockCheckRecord(Fnumber, CheckQty, Fflag_rw, Fflag_finish) values (''{0}'', {1,number,#}, 0, 0)"; |
| | | ErpSql = MessageFormat.format(ErpSql, adjust.getMatnr(), adjust.getCount()); |
| | | erpSqlServer.update(ErpSql); |
| | | // 修改原库存明细 |
| | | } else { |
| | | // 库存原数量 |
| | | Double oldCount = one.getAnfme(); |
| | | // 如果数量修改,则更新库存明细 |
| | | if (!adjust.getCount().equals(one.getAnfme())) { |
| | | // 当数量被修改为 0 时,直接清除库存明细 |
| | |
| | | adjDetl.setOriQty(one.getAnfme()); |
| | | adjDetl.setAdjQty(adjust.getCount()); |
| | | adjDetlService.save(adjDetl, userId); |
| | | // 调整库存,修改,StockCheckRecord插入盘盈、盘亏数据 |
| | | Double erpCount = 0D; |
| | | if (adjust.getCount() == 0) { |
| | | erpCount = 0 - oldCount; |
| | | } else { |
| | | erpCount = adjust.getCount() - oldCount; |
| | | } |
| | | String ErpSql = "insert into StockCheckRecord(Fnumber, CheckQty, Fflag_rw, Fflag_finish) values (''{0}'', {1,number,#}, 0, 0)"; |
| | | ErpSql = MessageFormat.format(ErpSql, adjust.getMatnr(), erpCount); |
| | | erpSqlServer.update(ErpSql); |
| | | } |
| | | } |
| | | } |
| | |
| | | @Transactional |
| | | public void cancelWrkMast(String workNo, Long userId) { |
| | | WrkMast wrkMast = wrkMastService.selectById(workNo); |
| | | if (Cools.isEmpty(wrkMast)){ |
| | | throw new CoolException(workNo+"工作档不存在"); |
| | | if (Cools.isEmpty(wrkMast)) { |
| | | throw new CoolException(workNo + "工作档不存在"); |
| | | } |
| | | String locNo = ""; // 待修改目标库位 |
| | | String locSts = ""; // 待修改目标库位状态 |
| | |
| | | // 库位转移:源库位 |
| | | LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo()); |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException("取消库位转移失败,源库位不存在:"+ wrkMast.getSourceLocNo()); |
| | | throw new CoolException("取消库位转移失败,源库位不存在:" + wrkMast.getSourceLocNo()); |
| | | } |
| | | locMast.setLocSts(wrkMast.getEmptyMk().equals("Y")?"D":"F"); |
| | | locMast.setLocSts(wrkMast.getEmptyMk().equals("Y") ? "D" : "F"); |
| | | locMast.setModiTime(new Date()); |
| | | 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.空桶/空栈板 |
| | | // 空板出库 ===>> D.空桶/空栈板 |
| | | } else if (wrkMast.getIoType() == 110) { |
| | | locSts = "D"; |
| | | // 库位转移 ===>> D.空桶/空栈板 |
| | | // 库位转移 ===>> D.空桶/空栈板 |
| | | } else if (wrkMast.getIoType() == 11) { |
| | | locSts = wrkMast.getEmptyMk().equals("Y")?"D":"F"; |
| | | locSts = wrkMast.getEmptyMk().equals("Y") ? "D" : "F"; |
| | | // 库位转移:目标库位 |
| | | LocMast locMast = locMastService.selectById(wrkMast.getLocNo()); |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException("取消库位转移失败,目标库位不存在:"+ wrkMast.getSourceLocNo()); |
| | | throw new CoolException("取消库位转移失败,目标库位不存在:" + wrkMast.getSourceLocNo()); |
| | | } |
| | | locMast.setLocSts("O"); |
| | | locMast.setModiTime(new Date()); |
| | |
| | | // 修改库位状态 |
| | | LocMast locMast = locMastService.selectById(locNo); |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException("取消工作档失败,库位不存在:"+ locNo); |
| | | throw new CoolException("取消工作档失败,库位不存在:" + locNo); |
| | | } |
| | | locMast.setLocSts(locSts); |
| | | locMast.setModiTime(new Date()); |
| | |
| | | @Transactional |
| | | public void pickWrkMast(String workNo, Long userId) { |
| | | WrkMast wrkMast = wrkMastService.selectById(workNo); |
| | | if (Cools.isEmpty(wrkMast)){ |
| | | throw new CoolException(workNo+"工作档不存在"); |
| | | if (Cools.isEmpty(wrkMast)) { |
| | | throw new CoolException(workNo + "工作档不存在"); |
| | | } |
| | | // 入出库类型判断 |
| | | if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107) { |
| | |
| | | } |
| | | locMast.setModiTime(now); |
| | | locMast.setModiUser(useId); |
| | | if (!locMastService.updateById(locMast)){ |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("修改库位状态失败"); |
| | | } |
| | | } |