|  |  |  | 
|---|
|  |  |  | import com.core.common.*; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.CombParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.MobileAdjustParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.NodePakoutParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.OpenOrderPakinParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.*; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.task.core.ReturnT; | 
|---|
|  |  |  | import com.zy.asrs.task.handler.WorkLogHandler; | 
|---|
|  |  |  | 
|---|
|  |  |  | private NodeService nodeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ManPakOutService manPakOutService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlService locDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void comb(CombParam param, Long userId) { | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { | 
|---|
|  |  |  | throw new CoolException(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { | 
|---|
|  |  |  | //            throw new CoolException(BaseRes.PARAM); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // 判断是否有相同条码的数据 | 
|---|
|  |  |  | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). | 
|---|
|  |  |  | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "数据正在进行入库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断托盘是否已经在库 | 
|---|
|  |  |  | if (locDetlService.selectCount(new EntityWrapper<LocDetl>() | 
|---|
|  |  |  | .eq("zpallet", param.getBarcode())) > 0) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "数据已经在库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断托盘是否已经在工作档 | 
|---|
|  |  |  | if (wrkMastService.selectCount(new EntityWrapper<WrkMast>() | 
|---|
|  |  |  | .eq("barcode", param.getBarcode())) > 0) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "数据已经在任务档中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断是否存在料箱码 => 存在料箱码则要求提交上来的物料list必须全部都有料箱码 | 
|---|
|  |  |  | boolean hasContainerCode = false; | 
|---|
|  |  |  | int containerCodeCount = 0;//料箱码数量 | 
|---|
|  |  |  | for (CombParam.CombMat combMat : param.getCombMats()) { | 
|---|
|  |  |  | if(!Cools.isEmpty(combMat.getContainerCode())){ | 
|---|
|  |  |  | //if (combMat.getContainerCode() != null) { | 
|---|
|  |  |  | hasContainerCode = true; | 
|---|
|  |  |  | containerCodeCount++; | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断料箱是否已经出现在入库通知档、库存中 | 
|---|
|  |  |  | if (hasContainerCode) { | 
|---|
|  |  |  | if (containerCodeCount != param.getCombMats().size()) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "托盘有" + (param.getCombMats().size()-containerCodeCount) + "个未扫描的料箱"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (CombParam.CombMat combMat : param.getCombMats()) { | 
|---|
|  |  |  | //判断料箱是否正在入库 | 
|---|
|  |  |  | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). | 
|---|
|  |  |  | eq("supp_code", combMat.getContainerCode()).eq("io_status", "N")) > 0) { | 
|---|
|  |  |  | throw new CoolException(combMat.getContainerCode() + "料箱正在进行入库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断料箱是否已经在库 | 
|---|
|  |  |  | if (locDetlService.selectCount(new EntityWrapper<LocDetl>() | 
|---|
|  |  |  | .eq("supp_code", combMat.getContainerCode())) > 0) { | 
|---|
|  |  |  | throw new CoolException(combMat.getContainerCode() + "料箱已经在库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // todo: 不下线重新入库 | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode()); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 生成入库通知档 | 
|---|
|  |  |  | List<DetlDto> detlDtos = new ArrayList<>(); | 
|---|
|  |  |  | param.getCombMats().forEach(elem -> { | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme(), elem.getCsocode(), elem.getIsoseq()); | 
|---|
|  |  |  | detlDto.setContainerCode(elem.getContainerCode()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme(), elem.getCsocode(), elem.getIsoseq(),elem.getContainerCode()); | 
|---|
|  |  |  | if (DetlDto.has(detlDtos, detlDto)) { | 
|---|
|  |  |  | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(),detlDto.getCsocode(),detlDto.getIsoseq(),detlDto.getContainerCode()); | 
|---|
|  |  |  | assert one != null; | 
|---|
|  |  |  | 
|---|
|  |  |  | param.getCombMats().forEach(elem -> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 订单明细数量校验 | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch()); | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch(),elem.getCsocode(),elem.getIsoseq()); | 
|---|
|  |  |  | if (elem.getAnfme() > orderDetl.getEnableQty()) { | 
|---|
|  |  |  | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单明细数量 | 
|---|
|  |  |  | if (!orderDetlService.increase(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { | 
|---|
|  |  |  | if (!orderDetlService.increase(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme(),elem.getCsocode(),elem.getIsoseq())) { | 
|---|
|  |  |  | throw new CoolException("修改单据明细数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme(),elem.getCsocode(),elem.getIsoseq()); | 
|---|
|  |  |  | detlDto.setContainerCode(elem.getContainerCode()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme(),elem.getCsocode(),elem.getIsoseq(),elem.getContainerCode()); | 
|---|
|  |  |  | if (DetlDto.has(detlDtos, detlDto)) { | 
|---|
|  |  |  | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(),detlDto.getCsocode(),detlDto.getIsoseq(),detlDto.getContainerCode()); | 
|---|
|  |  |  | assert one != null; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改作业数量 ---------------------------------------- | 
|---|
|  |  |  | // 订单明细数量校验 | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch()); | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch(),detlDto.getCsocode(),detlDto.getIsoseq()); | 
|---|
|  |  |  | if (detlDto.getAnfme() > orderDetl.getEnableQty()) { | 
|---|
|  |  |  | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单明细数量 | 
|---|
|  |  |  | if (!orderDetlService.increase(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { | 
|---|
|  |  |  | if (!orderDetlService.increase(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme(),detlDto.getCsocode(),detlDto.getIsoseq())) { | 
|---|
|  |  |  | throw new CoolException("修改单据明细数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | waitPakinList.forEach(waitPakin -> { | 
|---|
|  |  |  | //料想码 | 
|---|
|  |  |  | String containerCode = waitPakin.getSuppCode(); | 
|---|
|  |  |  | //如果当前料想码已存在,则修改该料想的物料数量 | 
|---|
|  |  |  | ManLocDetl manLocDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>().eq("container_code", containerCode)); | 
|---|
|  |  |  | //如果当前库位已存在货物 | 
|---|
|  |  |  | Wrapper<ManLocDetl> wrapper = new EntityWrapper<ManLocDetl>().eq("loc_no", locNo).eq("matnr",waitPakin.getMatnr()); | 
|---|
|  |  |  | Utils.wapperSetCondition(wrapper,"container_code",containerCode); | 
|---|
|  |  |  | Utils.wapperSetCondition(wrapper,"batch",waitPakin.getBatch()); | 
|---|
|  |  |  | Utils.wapperSetCondition(wrapper,"csocode",waitPakin.getThreeCode()); | 
|---|
|  |  |  | Utils.wapperSetCondition(wrapper,"isoseq",waitPakin.getDeadTime()); | 
|---|
|  |  |  | ManLocDetl manLocDetl = manLocDetlService.selectOne(wrapper); | 
|---|
|  |  |  | if(Cools.isEmpty(manLocDetl)){ | 
|---|
|  |  |  | saveManlocDetl(waitPakin,now,locNo); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if(Cools.eq(manLocDetl.getMatnr(),waitPakin.getMatnr()) | 
|---|
|  |  |  | && Cools.eq(manLocDetl.getCsocode(),waitPakin.getThreeCode()) | 
|---|
|  |  |  | && Cools.eq(manLocDetl.getIsoseq(),waitPakin.getDeadTime())){ | 
|---|
|  |  |  | manLocDetl.setAnfme(manLocDetl.getAnfme() + waitPakin.getAnfme()); | 
|---|
|  |  |  | manLocDetlService.update(manLocDetl,new EntityWrapper<ManLocDetl>() | 
|---|
|  |  |  | .eq("loc_no",manLocDetl.getLocNo()) | 
|---|
|  |  |  | .eq("container_code",manLocDetl.getContainerCode())); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | saveManlocDetl(waitPakin,now,locNo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | manLocDetl.setAnfme(manLocDetl.getAnfme() + waitPakin.getAnfme()); | 
|---|
|  |  |  | manLocDetlService.update(manLocDetl,wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //生成平库入出库日志 | 
|---|
|  |  |  | SaasUtils.insertLog(0,locNo,waitPakin.getMatnr(), waitPakin.getAnfme(),user.getUsername()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | Node node = nodeService.selectByUuid(locNo); | 
|---|
|  |  |  | node.setStatus(0); | 
|---|
|  |  |  | nodeService.updateById(node); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //生成入库通知历史档 | 
|---|
|  |  |  | waitPakinLogService.save(zpallet); | 
|---|
|  |  |  | //删除入库通知档 | 
|---|
|  |  |  | 
|---|
|  |  |  | //修改库存 | 
|---|
|  |  |  | manLocDetl.setAnfme(manLocDetl.getAnfme()-manPakOut.getCount()); | 
|---|
|  |  |  | if (manLocDetl.getAnfme() == 0 ){ | 
|---|
|  |  |  | checkNodeStatus(manLocDetl.getLocNo()); | 
|---|
|  |  |  | manLocDetlService.delete(manLocDetlWrapper); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | manLocDetl.setStatus(1); | 
|---|
|  |  |  | 
|---|
|  |  |  | //检测订单是否完成 | 
|---|
|  |  |  | orderService.checkComplete(param.getOrderNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void modifyWrkDetl(List<WrkDetl> wrkDetls, List<ModifyPakoutParam.CA> params, Long userId) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no",wrkDetls.get(0).getWrkNo())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | params.forEach(param ->{ | 
|---|
|  |  |  | WrkDetl wrkDetl = new WrkDetl(); | 
|---|
|  |  |  | LocDetl locDetl = locDetlService.selectByContainerCode(param.getContainerCode()); | 
|---|
|  |  |  | BeanUtils.copyProperties(locDetl,wrkDetl); | 
|---|
|  |  |  | wrkDetl.setWrkNo(wrkDetls.get(0).getWrkNo()); | 
|---|
|  |  |  | if(wrkDetl.getAnfme() < param.getAnfme()){ | 
|---|
|  |  |  | throw new CoolException("料箱"+param.getContainerCode()+"的物料数量小于拣料数量,请重新核对"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrkDetl.setAnfme(param.getAnfme()); | 
|---|
|  |  |  | wrkDetl.setModiTime(new Date()); | 
|---|
|  |  |  | wrkDetl.setAppeTime(new Date()); | 
|---|
|  |  |  | wrkDetl.setModiUser(userId); | 
|---|
|  |  |  | wrkDetlService.insert(wrkDetl); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void nodePakinNoComb(CombParam param) { | 
|---|
|  |  |  | if(Cools.isEmpty(param.getLocno())){ | 
|---|
|  |  |  | throw new CoolException("库位号未填写,无法入库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | param.getCombMats().forEach(combMat -> { | 
|---|
|  |  |  | Wrapper<ManLocDetl> wrapper = new EntityWrapper<ManLocDetl>().eq("loc_no", param.getLocno()).eq("matnr",combMat.getMatnr()); | 
|---|
|  |  |  | Utils.wapperSetCondition(wrapper,"container_code",combMat.getContainerCode()); | 
|---|
|  |  |  | Utils.wapperSetCondition(wrapper,"batch",combMat.getBatch()); | 
|---|
|  |  |  | Utils.wapperSetCondition(wrapper,"csocode",combMat.getCsocode()); | 
|---|
|  |  |  | Utils.wapperSetCondition(wrapper,"isoseq",combMat.getIsoseq()); | 
|---|
|  |  |  | ManLocDetl manLocDetl = manLocDetlService.selectOne(wrapper); | 
|---|
|  |  |  | if(Cools.isEmpty(manLocDetl)){ | 
|---|
|  |  |  | saveManlocDetl(combMat,param.getLocno()); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | manLocDetl.setAnfme(manLocDetl.getAnfme() + combMat.getAnfme()); | 
|---|
|  |  |  | manLocDetlService.update(manLocDetl,wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //生成平库入出库日志 | 
|---|
|  |  |  | SaasUtils.insertLog(0,param.getLocno(),combMat.getMatnr(), combMat.getAnfme(),""); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private boolean saveManlocDetl(CombParam.CombMat combMat, String locNo){ | 
|---|
|  |  |  | Node node = nodeService.selectOne(new EntityWrapper<Node>() | 
|---|
|  |  |  | .eq("name", locNo)); | 
|---|
|  |  |  | Mat mat = matService.selectByMatnr(combMat.getMatnr()); | 
|---|
|  |  |  | ManLocDetl manLocDetl = new ManLocDetl(); | 
|---|
|  |  |  | BeanUtils.copyProperties(mat,manLocDetl); | 
|---|
|  |  |  | manLocDetl.setAnfme(combMat.getAnfme()); | 
|---|
|  |  |  | manLocDetl.setNodeId(node.getId()); | 
|---|
|  |  |  | manLocDetl.setContainerCode(combMat.getContainerCode()); | 
|---|
|  |  |  | manLocDetl.setCsocode(combMat.getCsocode()); | 
|---|
|  |  |  | manLocDetl.setIsoseq(combMat.getIsoseq()); | 
|---|
|  |  |  | manLocDetl.setCreateTime(new Date()); | 
|---|
|  |  |  | manLocDetl.setModiTime(new Date()); | 
|---|
|  |  |  | manLocDetl.setLocNo(locNo); | 
|---|
|  |  |  | manLocDetl.setStatus(1); | 
|---|
|  |  |  | return manLocDetlService.insert(manLocDetl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void saveManlocDetl(WaitPakin waitPakin, Date now, String locNo){ | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return status; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  | ManPakOut m = new ManPakOut(); | 
|---|
|  |  |  | m.setAnfme(1.0); | 
|---|
|  |  |  | NodePakoutParam n = new NodePakoutParam(); | 
|---|
|  |  |  | n.setAnfme(1.0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | double a = 1.0; | 
|---|
|  |  |  | double b = 1.0; | 
|---|
|  |  |  | System.out.println(m.getAnfme() == n.getAnfme()); | 
|---|
|  |  |  | System.out.println(a == b); | 
|---|
|  |  |  | System.out.println(Double.doubleToLongBits(m.getAnfme()) == Double.doubleToLongBits(n.getAnfme())); | 
|---|
|  |  |  | private void checkNodeStatus(String locNo){ | 
|---|
|  |  |  | ManLocDetl manLocDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>().eq("loc_no", locNo)); | 
|---|
|  |  |  | //如果库存信息中没有改库位,则修改库位状态为1 | 
|---|
|  |  |  | if(Cools.isEmpty(manLocDetl)){ | 
|---|
|  |  |  | Node node = nodeService.selectByUuid(locNo); | 
|---|
|  |  |  | node.setStatus(1); | 
|---|
|  |  |  | nodeService.updateById(node); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|