| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.BaseRes; |
| | |
| | | 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 WrkDetlLogService wrkDetlLogService; |
| | | @Autowired |
| | | private WmsService wmsService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private OrderService orderService; |
| | |
| | | if (Cools.isEmpty(param.getDevpNo(), param.getList())) { |
| | | throw new CoolException(BaseRes.PARAM); |
| | | } |
| | | Date now = new Date(); |
| | | // 源站点状态检测 |
| | | BasDevp sourceStaNo = basDevpService.checkSiteStatus(param.getDevpNo(), true); |
| | | // 检索库位 |
| | | LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo); |
| | | log.info(JSON.toJSONString(locTypeDto)); |
| | | log.info("{}入库口尺寸检测:{}", param.getDevpNo(), locTypeDto.getLocType1()==1?"低规格库位":"高规格库位"); |
| | | List<String> matNos = param.getList().stream().map(FullStoreParam.MatCodeStore::getMatNo).distinct().collect(Collectors.toList()); |
| | | StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 1, param.getDevpNo(), matNos, locTypeDto, 0); |
| | | // 生成工作号 |
| | |
| | | wrkMast.setIoTime(new Date()); |
| | | wrkMast.setWrkSts(1L); // 工作状态:生成入库ID |
| | | wrkMast.setIoType(1); // 入出库状态:1.入库 |
| | | wrkMast.setIoPri(13D); // 优先级:10 |
| | | wrkMast.setIoPri(13D); // 优先级:13 |
| | | wrkMast.setCrnNo(dto.getCrnNo()); |
| | | wrkMast.setSourceStaNo(dto.getSourceStaNo()); |
| | | wrkMast.setStaNo(dto.getStaNo()); |
| | |
| | | wrkMast.setEmptyMk("N"); // 空板 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setCtnType(sourceStaNo.getCtnType()); // 容器类型 |
| | | // 操作人员数据 |
| | | wrkMast.setAppeUser(userId); |
| | | wrkMast.setAppeTime(new Date()); |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiUser(userId); |
| | | wrkMast.setModiTime(new Date()); |
| | | boolean res = wrkMastService.insert(wrkMast); |
| | | if (!res) { |
| | | wrkMast.setModiTime(now); |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 生成工作档明细 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getList().forEach(elem -> { |
| | | detlDtos.add(new DetlDto(elem.getMatNo(), elem.getCount())); |
| | | DetlDto detlDto = new DetlDto(elem.getMatNo(), elem.getBatch(), elem.getAnfme()); |
| | | if (DetlDto.has(detlDtos, detlDto)) { |
| | | DetlDto detlDto1 = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); |
| | | assert detlDto1 != null; |
| | | detlDto1.setAnfme(detlDto1.getAnfme() + detlDto.getAnfme()); |
| | | } else { |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | wrkDetlService.createWorkDetail(workNo, detlDtos, param.getBarcode(), userId); |
| | | // 更新源站点信息 |
| | | sourceStaNo.setWrkNo(workNo); |
| | | sourceStaNo.setModiUser(userId); |
| | | sourceStaNo.setModiTime(new Date()); |
| | | sourceStaNo.setModiTime(now); |
| | | if (!basDevpService.updateById(sourceStaNo)){ |
| | | throw new CoolException("更新源站失败"); |
| | | } |
| | |
| | | if (locMast.getLocSts().equals("O")){ |
| | | locMast.setLocSts("S"); // S.入库预约 |
| | | locMast.setModiUser(userId); |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiTime(now); |
| | | if (!locMastService.updateById(locMast)){ |
| | | throw new CoolException("改变库位状态失败"); |
| | | } |
| | |
| | | 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"); |
| | | } |
| | | } |
| | | // 保存调整记录 |