| | |
| | | import com.zy.common.model.*; |
| | | import com.zy.common.model.enums.WorkNoType; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.service.wms.Result; |
| | | import com.zy.common.service.wms.WmsService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | |
| | | private WrkMastLogService wrkMastLogService; |
| | | @Autowired |
| | | private WrkDetlLogService wrkDetlLogService; |
| | | @Autowired |
| | | private WmsService wmsService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | |
| | | // 生成工作档明细 |
| | | for (LocDto locDto : taskDto.getLocDtos()) { |
| | | if (locDto.getAnfme()==null || locDto.getAnfme() <= 0.0D) { continue; } |
| | | |
| | | OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch()); |
| | | |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | wrkDetl.setIoTime(now); |
| | | wrkDetl.setWrkNo(workNo); |
| | |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | // 修改订单明细 |
| | | if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) { |
| | | throw new CoolException("修改订单明细数量失败"); |
| | | } |
| | | orderService.updateSettle(orderDetl.getOrderId(), 2L, userId); |
| | | } |
| | | // 修改库位状态: F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 |
| | | locMast = locMastService.selectById(taskDto.getLocNo()); |
| | |
| | | throw new CoolException("更新库位状态失败"); |
| | | } |
| | | } |
| | | // todo 更新站点信息(工作号) |
| | | } |
| | | } |
| | | |
| | |
| | | adjDetl.setOriQty(0.0D); |
| | | adjDetl.setAdjQty(adjust.getCount()); |
| | | adjDetlService.save(adjDetl, userId); |
| | | // 上报erp |
| | | String docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); |
| | | Integer docId = 14; // 报溢单 |
| | | List<BillDto> dtos = new ArrayList<>(); |
| | | BillDto billDto = new BillDto(); |
| | | billDto.setMatnr(adjust.getMatnr()); |
| | | billDto.setQty(Math.abs(adjust.getCount())); |
| | | dtos.add(billDto); |
| | | Result result = wmsService.erpUpload(dtos, docId, docNum); |
| | | if (result.getCode() != 200) { |
| | | throw new CoolException("库存调整失败,原因:无法上报至ERP"); |
| | | } |
| | | // 修改原库存明细 |
| | | } else { |
| | | // 如果数量修改,则更新库存明细 |
| | | if (!adjust.getCount().equals(one.getAnfme())) { |
| | | // 当数量被修改为 0 时,直接清除库存明细 |
| | | if (adjust.getCount() == 0) { |
| | | // 上报erp |
| | | String docNum = "CD-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); |
| | | Integer docId = 9; // 报损单 |
| | | List<BillDto> dtos = new ArrayList<>(); |
| | | BillDto billDto = new BillDto(); |
| | | billDto.setMatnr(adjust.getMatnr()); |
| | | billDto.setQty(Math.abs(one.getAnfme())); |
| | | dtos.add(billDto); |
| | | Result result = wmsService.erpUpload(dtos, docId, docNum); |
| | | if (result.getCode() != 200) { |
| | | throw new CoolException("库存调整失败,原因:无法上报至ERP"); |
| | | } |
| | | // 删除库存 |
| | | if (!locDetlService.delete(new EntityWrapper<>(one))) { |
| | | throw new CoolException("清除库存明细失败"); |
| | |
| | | .eq("loc_no", locMast.getLocNo()) |
| | | .eq("matnr", adjust.getMatnr()))) { |
| | | throw new CoolException("修改库存明细失败"); |
| | | } |
| | | // 上报erp |
| | | String docNum; |
| | | Integer docId; |
| | | if (one.getAnfme() > adjust.getCount()) { |
| | | // 报损 |
| | | docNum = "CD-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); |
| | | docId = 9; |
| | | } else { |
| | | // 报溢 |
| | | docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15); |
| | | docId = 14; |
| | | } |
| | | List<BillDto> dtos = new ArrayList<>(); |
| | | BillDto billDto = new BillDto(); |
| | | billDto.setMatnr(adjust.getMatnr()); |
| | | billDto.setQty(Math.abs(one.getAnfme() - adjust.getCount())); |
| | | dtos.add(billDto); |
| | | Result result = wmsService.erpUpload(dtos, docId, docNum); |
| | | if (result.getCode() != 200) { |
| | | throw new CoolException("库存调整失败,原因:无法上报至ERP"); |
| | | } |
| | | } |
| | | // 保存调整记录 |
| | |
| | | // 出库 ===>> F.在库 |
| | | if (wrkMast.getIoType() > 100 && wrkMast.getIoType() != 110) { |
| | | locSts = "F"; |
| | | // 销售单关联,则生成新的出库任务 |
| | | if (wrkMast.getPdcType().equals("Y")) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", workNo)); |
| | | for (WrkDetl wrkDetl : wrkDetls) { |
| | | Double sumAnfme = Optional.ofNullable(locDetlService.getSumAnfme(wrkDetl.getMatnr())).orElse(0.0D); |
| | | if (sumAnfme < wrkDetl.getAnfme()) { |
| | | throw new CoolException("取消失败!库存不足以重新生成出库作业"); |
| | | } |
| | | } |
| | | // 生成新的出库作业 |
| | | stockOutRe(wrkMast, wrkDetls); |
| | | } |
| | | // 空板出库 ===>> D.空桶/空栈板 |
| | | } else if (wrkMast.getIoType() == 110) { |
| | | locSts = "D"; |
| | |
| | | } else { |
| | | throw new CoolException("当前工作状态无法取消"); |
| | | } |
| | | // 订单关联 |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); |
| | | for (WrkDetl wrkDetl : wrkDetls) { |
| | | if (!Cools.isEmpty(wrkDetl.getOrderNo())) { |
| | | if (!orderDetlService.decrease(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) { |
| | | throw new CoolException("订单数据回滚失败"); |
| | | } |
| | | // 生成新的出库作业 |
| | | // stockOutRe(wrkMast, wrkDetls); |
| | | } |
| | | } |
| | | // 取消操作人员记录 |
| | | wrkMast.setManuType("手动取消"); |
| | | wrkMast.setModiUser(userId); |