|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.BaseRes; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Optional; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { | 
|---|
|  |  |  | throw new CoolException(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!CodeDetectionUtil.barcodeDetection(param.getBarcode())){ | 
|---|
|  |  |  | if (!CodeDetectionUtil.barcodeDetection(param.getBarcode())) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "货架码有误,请正确扫码!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | param.setContainerType(Short.valueOf(param.getBarcode().substring(0,2))); | 
|---|
|  |  |  | param.setContainerType(Short.valueOf(param.getBarcode().substring(0, 2))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        //检查是否已存在相同的货架条码,存在则抛出异常 | 
|---|
|  |  |  | //        if (agvWaitPakinService.selectCount(new EntityWrapper<AgvWaitPakin>().eq("supp_code", param.getBarcode())) > 0) { | 
|---|
|  |  |  | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检查库存是否有相同货架,存在则抛出异常 | 
|---|
|  |  |  | if(!Cools.isEmpty(agvLocDetlService.selectOne(new EntityWrapper<AgvLocDetl>().eq("supp_code",param.getBarcode())))){ | 
|---|
|  |  |  | if (!Cools.isEmpty(agvLocDetlService.selectOne(new EntityWrapper<AgvLocDetl>().eq("supp_code", param.getBarcode())))) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "货架码已存在AGV库存明细中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检查库存是否有相同货架,存在则抛出异常 | 
|---|
|  |  |  | if(!Cools.isEmpty(agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("barcode",param.getBarcode())))){ | 
|---|
|  |  |  | if (!Cools.isEmpty(agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("barcode", param.getBarcode())))) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "货架码已存在AGV库存主档中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查看工作档是否有相同货架,存在则抛出异常 | 
|---|
|  |  |  | if(!Cools.isEmpty(agvWrkMastService.selectByContainerCode(param.getBarcode()))){ | 
|---|
|  |  |  | if (!Cools.isEmpty(agvWrkMastService.selectByContainerCode(param.getBarcode()))) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "货架码已存在AGV工作档中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(param.getOrderNo())) { | 
|---|
|  |  |  | //无单组托 | 
|---|
|  |  |  | NoOrderComb(param,userId); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | NoOrderComb(param, userId); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //有单组托 | 
|---|
|  |  |  | OrderComb(param,userId); | 
|---|
|  |  |  | OrderComb(param, userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isEmpty(param.getLocno())){ | 
|---|
|  |  |  | if (StringUtils.isEmpty(param.getLocno())) { | 
|---|
|  |  |  | return "组托成功"; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | combBinding(param.getBarcode(),param.getLocno(),param.getContainerType()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | combBinding(param.getBarcode(), param.getLocno(), param.getContainerType()); | 
|---|
|  |  |  | return "组托成功,绑定站点成功"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public String pickAgain(PickParam pickParams, Long userId) { | 
|---|
|  |  |  | public synchronized String pickAgain(PickParam pickParams, Long userId) { | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", pickParams.getLocNo())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("wrk_no", pickParams.getWrkNo())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(agvWrkMast)){ | 
|---|
|  |  |  | return "失败,未查到工作主档,工作号:"+pickParams.getWrkNo(); | 
|---|
|  |  |  | if (Cools.isEmpty(agvWrkMast)) { | 
|---|
|  |  |  | return "失败,未查到工作主档,工作号:" + pickParams.getWrkNo(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (PickParam.Pick pick : pickParams.getPicks()) { | 
|---|
|  |  |  | if (pick.getCount().equals(0D)) continue; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Double count = 0.0D; | 
|---|
|  |  |  | AgvWrkDetl agvWrkDetl = agvWrkDetlService.selectOne(new EntityWrapper<AgvWrkDetl>().eq("matnr", pick.getMatnr()).eq("three_code", pick.getThreeCode()).eq("supp_code",pick.getSuppCode())); | 
|---|
|  |  |  | AgvWrkDetl agvWrkDetl = agvWrkDetlService.selectOne(new EntityWrapper<AgvWrkDetl>().eq("matnr", pick.getMatnr()).eq("three_code", pick.getThreeCode()).eq("supp_code", pick.getSuppCode())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(agvWrkDetl)) { | 
|---|
|  |  |  | AgvWrkDetl wrkDetl = new AgvWrkDetl(); | 
|---|
|  |  |  | agvWrkDetl = new AgvWrkDetl(); | 
|---|
|  |  |  | Mat mat = matService.selectByMatnr(pick.getMatnr()); | 
|---|
|  |  |  | if (Cools.isEmpty(mat)) { | 
|---|
|  |  |  | throw new CoolException(pick.getMatnr() + "商品不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrkDetl.sync(mat); | 
|---|
|  |  |  | wrkDetl.setWrkNo(pickParams.getWrkNo()); | 
|---|
|  |  |  | wrkDetl.setOrderNo(pick.getOrderNo()); | 
|---|
|  |  |  | wrkDetl.setIoTime(agvWrkMast.getIoTime()); | 
|---|
|  |  |  | wrkDetl.setAnfme(pick.getCount()); // 数量 | 
|---|
|  |  |  | wrkDetl.setSuppCode(pick.getSuppCode()); // 货架条码 | 
|---|
|  |  |  | wrkDetl.setAppeUser(userId); | 
|---|
|  |  |  | wrkDetl.setAppeTime(now); | 
|---|
|  |  |  | wrkDetl.setModiUser(userId); | 
|---|
|  |  |  | wrkDetl.setModiTime(now); | 
|---|
|  |  |  | wrkDetl.setThreeCode(pick.getThreeCode()); | 
|---|
|  |  |  | agvWrkDetlService.insert(wrkDetl); | 
|---|
|  |  |  | agvWrkDetl.sync(mat); | 
|---|
|  |  |  | agvWrkDetl.setWrkNo(pickParams.getWrkNo()); | 
|---|
|  |  |  | agvWrkDetl.setOrderNo(pick.getOrderNo()); | 
|---|
|  |  |  | agvWrkDetl.setIoTime(agvWrkMast.getIoTime()); | 
|---|
|  |  |  | agvWrkDetl.setAnfme(pick.getCount()); // 数量 | 
|---|
|  |  |  | agvWrkDetl.setSuppCode(pick.getSuppCode()); // 货架条码 | 
|---|
|  |  |  | agvWrkDetl.setAppeUser(userId); | 
|---|
|  |  |  | agvWrkDetl.setAppeTime(now); | 
|---|
|  |  |  | agvWrkDetl.setModiUser(userId); | 
|---|
|  |  |  | agvWrkDetl.setModiTime(now); | 
|---|
|  |  |  | agvWrkDetl.setThreeCode(pick.getThreeCode()); | 
|---|
|  |  |  | agvWrkDetlService.insert(agvWrkDetl); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Double anfme = agvWrkDetl.getAnfme() + pick.getCount(); | 
|---|
|  |  |  | agvWrkDetl.setIoTime(agvWrkMast.getIoTime()); | 
|---|
|  |  |  | agvWrkDetl.setAnfme(anfme); | 
|---|
|  |  |  | agvWrkDetl.setModiTime(new Date()); | 
|---|
|  |  |  | agvWrkDetlService.update(agvWrkDetl,new EntityWrapper<AgvWrkDetl>().eq("matnr",agvWrkDetl.getMatnr()).eq("three_code",agvWrkDetl.getThreeCode()).eq("supp_code",pick.getSuppCode())); | 
|---|
|  |  |  | agvWrkDetl.setModiTime(now); | 
|---|
|  |  |  | agvWrkDetlService.update(agvWrkDetl, new EntityWrapper<AgvWrkDetl>().eq("matnr", agvWrkDetl.getMatnr()).eq("three_code", agvWrkDetl.getThreeCode()).eq("supp_code", pick.getSuppCode())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 库存校验 | 
|---|
|  |  |  | Optional<AgvLocDetl> first = agvLocDetls.stream().filter(agvLocDetl -> agvLocDetl.getThreeCode().equals(pick.getThreeCode())) | 
|---|
|  |  |  | .filter(agvLocDetl -> agvLocDetl.getMatnr().equals(pick.getMatnr())).findFirst(); | 
|---|
|  |  |  | if (first.isPresent()) { | 
|---|
|  |  |  | AgvLocDetl agvLocDetl = first.get(); | 
|---|
|  |  |  | if (agvLocDetl.getAnfme() < agvWrkDetl.getAnfme()) { | 
|---|
|  |  |  | throw new CoolException("拣料数量不能大于库存数量"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("拣料数量不能大于库存数量,存库不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 更新订单 | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("order_no", pick.getOrderNo()).eq("matnr", pick.getMatnr()).eq("three_code",pick.getThreeCode())); | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("order_no", pick.getOrderNo()).eq("matnr", pick.getMatnr()).eq("three_code", pick.getThreeCode())); | 
|---|
|  |  |  | orderDetl.setQty(orderDetl.getQty() + pick.getCount()); | 
|---|
|  |  |  | if (!orderDetlService.update(orderDetl,new EntityWrapper<OrderDetl>().eq("order_no", pick.getOrderNo()).eq("matnr", pick.getMatnr()).eq("three_code",pick.getThreeCode()))){ | 
|---|
|  |  |  | throw new CoolException("修改订单明细失败,请联系管理员"+pick.getOrderNo()+pick.getMatnr()); | 
|---|
|  |  |  | if (!orderDetlService.update(orderDetl, new EntityWrapper<OrderDetl>().eq("order_no", pick.getOrderNo()).eq("matnr", pick.getMatnr()).eq("three_code", pick.getThreeCode()))) { | 
|---|
|  |  |  | throw new CoolException("修改订单明细失败,请联系管理员" + pick.getOrderNo() + pick.getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //  确认是否全部出库 | 
|---|
|  |  |  | int sameNumber = 0; | 
|---|
|  |  |  | List<AgvWrkDetl> agvWrkDetls = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", pickParams.getWrkNo())); | 
|---|
|  |  |  | for (AgvLocDetl agvLocDetl : agvLocDetls) { | 
|---|
|  |  |  | for (AgvWrkDetl agvWrkDetl : agvWrkDetls) { | 
|---|
|  |  |  | if (agvLocDetl.getMatnr().equals(agvWrkDetl.getMatnr()) | 
|---|
|  |  |  | && agvLocDetl.getThreeCode().equals(agvWrkDetl.getThreeCode()) | 
|---|
|  |  |  | && agvLocDetl.getSuppCode().equals(agvWrkDetl.getSuppCode()) | 
|---|
|  |  |  | && agvLocDetl.getAnfme().equals(agvWrkDetl.getAnfme())) { | 
|---|
|  |  |  | sameNumber++; | 
|---|
|  |  |  | Order order = orderService.selectByNo(orderDetl.getOrderNo()); | 
|---|
|  |  |  | if (order.getSettle() == 1) { | 
|---|
|  |  |  | if (!orderService.updateSettle(order.getId(), 2L, userId)) { | 
|---|
|  |  |  | throw new CoolException("再次拣料:更新订单状态失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (agvLocDetls.size() == sameNumber) { | 
|---|
|  |  |  | agvWrkMast.setIoType(101); | 
|---|
|  |  |  | agvWrkMast.setModiTime(new Date()); | 
|---|
|  |  |  | agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no", pickParams.getWrkNo())); | 
|---|
|  |  |  | //  确认是否全部出库 | 
|---|
|  |  |  | double totleWrkdetl = 0.0; | 
|---|
|  |  |  | double totleLocdetl = 0.0; | 
|---|
|  |  |  | List<AgvWrkDetl> agvWrkDetls = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", pickParams.getWrkNo())); | 
|---|
|  |  |  | for (AgvLocDetl agvLocDetl : agvLocDetls) { | 
|---|
|  |  |  | totleLocdetl = totleLocdetl + agvLocDetl.getAnfme(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (AgvWrkDetl agvWrkDetl : agvWrkDetls) { | 
|---|
|  |  |  | totleWrkdetl = totleWrkdetl + agvWrkDetl.getAnfme(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (totleWrkdetl >= totleLocdetl) { | 
|---|
|  |  |  | agvWrkMast.setIoType(101); | 
|---|
|  |  |  | agvWrkMastService.update(agvWrkMast, new EntityWrapper<AgvWrkMast>().eq("wrk_no", pickParams.getWrkNo())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        agvLocDetls.size() == 1 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return "组托成功,绑定站点成功"; | 
|---|
|  |  |  | return "拣料成功"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | AGV无单组托 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void NoOrderComb(CombParam param, Long userId){ | 
|---|
|  |  |  | List<DetlDto> detlDtos = mappingDetlDtoByCombMat(param,null); | 
|---|
|  |  |  | private void NoOrderComb(CombParam param, Long userId) { | 
|---|
|  |  |  | List<DetlDto> detlDtos = mappingDetlDtoByCombMat(param, null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //用于统一一个货架下的入库通知档的生成时间 | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | detlDtos.forEach(detlDto -> { | 
|---|
|  |  |  | syncWaitPakin(detlDto,"",param.getBarcode(),userId,now); | 
|---|
|  |  |  | syncWaitPakin(detlDto, "", param.getBarcode(), userId, now); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | AGV有单组托 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void OrderComb(CombParam param, Long userId){ | 
|---|
|  |  |  | private void OrderComb(CombParam param, Long userId) { | 
|---|
|  |  |  | //关联组托 | 
|---|
|  |  |  | Order order = orderService.selectByNo(param.getOrderNo()); | 
|---|
|  |  |  | if(Cools.isEmpty(order)){ | 
|---|
|  |  |  | if (Cools.isEmpty(order)) { | 
|---|
|  |  |  | throw new CoolException("单据编号不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //订单状态2以上为完成或者取消的订单 | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("单据编号已过期"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 用于生成入库通知档所需参数 | 
|---|
|  |  |  | List<DetlDto> detlDtos = mappingDetlDtoByCombMat(param,order); | 
|---|
|  |  |  | List<DetlDto> detlDtos = mappingDetlDtoByCombMat(param, order); | 
|---|
|  |  |  | //用于统一一个货架下的入库通知档的生成时间 | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | for (DetlDto detlDto : detlDtos) { | 
|---|
|  |  |  | //同步生成入库通知档 | 
|---|
|  |  |  | syncWaitPakin(detlDto,order.getOrderNo(),param.getBarcode(),userId,now); | 
|---|
|  |  |  | syncWaitPakin(detlDto, order.getOrderNo(), param.getBarcode(), userId, now); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //修改单据状态为2.作业中 | 
|---|
|  |  |  | orderService.updateSettle(order.getId(), 2L, userId); | 
|---|
|  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 根据PDA扫码所传的物料信息参数映射为DetlDto | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private List<DetlDto> mappingDetlDtoByCombMat(CombParam param, Order order){ | 
|---|
|  |  |  | private List<DetlDto> mappingDetlDtoByCombMat(CombParam param, Order order) { | 
|---|
|  |  |  | List<DetlDto> detlDtos = new ArrayList<>(); | 
|---|
|  |  |  | param.getCombMats().forEach(combMat -> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!Cools.isEmpty(order)){ | 
|---|
|  |  |  | if (!Cools.isEmpty(order)) { | 
|---|
|  |  |  | //检查入库数量 | 
|---|
|  |  |  | checkOrderQty(order,combMat); | 
|---|
|  |  |  | checkOrderQty(order, combMat); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(), combMat.getIsoseq(),combMat.getContainerCode(),param.getLocType(),combMat.getProcessSts()); | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(), combMat.getIsoseq(), combMat.getContainerCode(), param.getLocType(), combMat.getProcessSts()); | 
|---|
|  |  |  | //同一货架下相同物料信息和批号转为一个入库通知档 | 
|---|
|  |  |  | if (DetlDto.has(detlDtos, detlDto)) { | 
|---|
|  |  |  | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(), detlDto.getCsocode(), detlDto.getIsoseq(),detlDto.getContainerCode()); | 
|---|
|  |  |  | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(), detlDto.getCsocode(), detlDto.getIsoseq(), detlDto.getContainerCode()); | 
|---|
|  |  |  | assert one != null; | 
|---|
|  |  |  | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 检查入库数量是否小于等于单据数量,合理则修改OrderDetl作业数量信息,否则抛出异常 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void checkOrderQty(Order order, CombParam.CombMat combMat){ | 
|---|
|  |  |  | private void checkOrderQty(Order order, CombParam.CombMat combMat) { | 
|---|
|  |  |  | // 订单明细数量校验,如果作业数量大于单据数量则抛出异常 | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getCsocode(),combMat.getIsoseq()); | 
|---|
|  |  |  | if(Cools.isEmpty(orderDetl)){ | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getCsocode(), combMat.getIsoseq()); | 
|---|
|  |  |  | if (Cools.isEmpty(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("未匹配到该单据下的物料"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (combMat.getAnfme() > orderDetl.getEnableQty()) { | 
|---|
|  |  |  | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单明细数量 | 
|---|
|  |  |  | if (!orderDetlService.increase(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(),combMat.getIsoseq())) { | 
|---|
|  |  |  | if (!orderDetlService.increase(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(), combMat.getIsoseq())) { | 
|---|
|  |  |  | throw new CoolException("修改单据明细数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 同步生成AGV入库通知档数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void syncWaitPakin(DetlDto detlDto, String orderNo, String zpallet, Long userId, Date now ){ | 
|---|
|  |  |  | private void syncWaitPakin(DetlDto detlDto, String orderNo, String zpallet, Long userId, Date now) { | 
|---|
|  |  |  | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); | 
|---|
|  |  |  | if (Cools.isEmpty(mat)) { | 
|---|
|  |  |  | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectItem(orderNo, mat.getMatnr(), detlDto.getBatch(), detlDto.getCsocode()); | 
|---|
|  |  |  | AgvWaitPakin waitPakin = new AgvWaitPakin(); | 
|---|
|  |  |  | waitPakin.sync(mat); | 
|---|
|  |  |  | if (orderDetl != null) { | 
|---|
|  |  |  | waitPakin.setWeight(orderDetl.getWeight()); | 
|---|
|  |  |  | waitPakin.setVolume(orderDetl.getVolume()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | waitPakin.setOrderNo(orderNo);   // 单据编号 | 
|---|
|  |  |  | waitPakin.setBatch(detlDto.getBatch());     // 序列码 | 
|---|
|  |  |  | //waitPakin.setZpallet(zpallet);   // 货架码 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("dev_no", stationCode)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Cools.eq(agvBasDevp.getBarcode(),barcode)){ | 
|---|
|  |  |  | if (Cools.eq(agvBasDevp.getBarcode(), barcode)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Cools.isEmpty(agvWaitPakinService.selectByContainerCode(barcode))){ | 
|---|
|  |  |  | if (Cools.isEmpty(agvWaitPakinService.selectByContainerCode(barcode))) { | 
|---|
|  |  |  | throw new CoolException("该货架未组托,无法绑定站点"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AgvBasDevp agvBasDevp1 = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("barcode", barcode)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!Cools.isEmpty(agvBasDevp1)){ | 
|---|
|  |  |  | throw new CoolException(barcode + "已经绑定在"+ agvBasDevp.getDevNo() +"站点"); | 
|---|
|  |  |  | if (!Cools.isEmpty(agvBasDevp1)) { | 
|---|
|  |  |  | throw new CoolException(barcode + "已经绑定在" + agvBasDevp.getDevNo() + "站点"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(agvBasDevp == null){ | 
|---|
|  |  |  | if (agvBasDevp == null) { | 
|---|
|  |  |  | throw new CoolException(stationCode + "站点信息错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!"O".equals(agvBasDevp.getLocSts())){ | 
|---|
|  |  |  | if (!"O".equals(agvBasDevp.getLocSts())) { | 
|---|
|  |  |  | throw new CoolException(stationCode + "该站点货位状态非空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", agvBasDevp.getDevNo())); | 
|---|
|  |  |  | if(!Cools.isEmpty(agvWrkMast)){ | 
|---|
|  |  |  | if (!Cools.isEmpty(agvWrkMast)) { | 
|---|
|  |  |  | throw new CoolException(stationCode + "该站点已被工作号为" + agvWrkMast.getWrkNo() + "占用,无法绑定"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | agvBasDevp.setBarcode(barcode); | 
|---|
|  |  |  | agvBasDevp.setLocSts("F"); | 
|---|
|  |  |  | agvBasDevp.setLocType2(containerType); | 
|---|
|  |  |  | agvBasDevpService.update(agvBasDevp,(new EntityWrapper<AgvBasDevp>().eq("dev_no",stationCode))); | 
|---|
|  |  |  | agvBasDevpService.update(agvBasDevp, (new EntityWrapper<AgvBasDevp>().eq("dev_no", stationCode))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<AgvBasDevp> getAgvBasDevpByFloor(int floor) { | 
|---|
|  |  |  | EntityWrapper<AgvBasDevp> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("floor",floor).eq("cache_shelves","Y").eq("loc_sts","F"); | 
|---|
|  |  |  | wrapper.eq("floor", floor).eq("cache_shelves", "Y").eq("loc_sts", "F"); | 
|---|
|  |  |  | List<AgvBasDevp> agvBasDevpList = agvBasDevpService.selectList(wrapper); | 
|---|
|  |  |  | return agvBasDevpList.stream().filter(agvBasDevp -> { | 
|---|
|  |  |  | return !Cools.isEmpty(agvWaitPakinService.selectByContainerCode(agvBasDevp.getBarcode())); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public String handControlLocMove(LocMoveParam param, Long userId) { | 
|---|
|  |  |  | String fl = String.valueOf(param.getFloor()); | 
|---|
|  |  |  | short floor =(short)Integer.parseInt(fl.substring(0, 1)); | 
|---|
|  |  |  | short floor = (short) Integer.parseInt(fl.substring(0, 1)); | 
|---|
|  |  |  | switch (param.getFloor()) { | 
|---|
|  |  |  | case "1F01": | 
|---|
|  |  |  | floor = 1; | 
|---|
|  |  |  | 
|---|
|  |  |  | if (agvLocMast.getFloor() != floor) { | 
|---|
|  |  |  | if (agvLocMast.getFloor() == 1 && (floor == 2 || floor == 3)) { | 
|---|
|  |  |  | throw new CoolException("当前库位请选择调拨单调拨!"); | 
|---|
|  |  |  | } else if ((agvLocMast.getFloor() == 2 || agvLocMast.getFloor() == 3) && (floor == 1 || floor == 4)) { | 
|---|
|  |  |  | throw new CoolException("当前库位请选择调拨回流单回退!"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | ioType = 12; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | //查询工作档 | 
|---|
|  |  |  | AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(agvLocMast.getBarcode()); | 
|---|
|  |  |  | if(!Cools.isEmpty(agvWrkMast)){ | 
|---|
|  |  |  | throw new CoolException("当前"+agvLocMast.getBarcode()+"货架码已在工作档中"); | 
|---|
|  |  |  | if (!Cools.isEmpty(agvWrkMast)) { | 
|---|
|  |  |  | throw new CoolException("当前" + agvLocMast.getBarcode() + "货架码已在工作档中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //检索库位,选择合适的库位 | 
|---|
|  |  |  | AgvLocMast locMast = null; | 
|---|
|  |  |  | if (floor == 1) { | 
|---|
|  |  |  | locMast = agvCommonService.getLocNo(agvLocMast.getLocType1(),floor,true,false); | 
|---|
|  |  |  | locMast = agvCommonService.getLocNo(agvLocMast.getLocType1(), floor, true, false); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | locMast = agvCommonService.getLocNo(agvLocMast.getLocType1(),floor,false,false); | 
|---|
|  |  |  | locMast = agvCommonService.getLocNo(agvLocMast.getLocType1(), floor, false, false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 目标楼层去 吸塑2楼 | 
|---|
|  |  |  | 
|---|
|  |  |  | //生成工作档 | 
|---|
|  |  |  | AgvWrkMast mast = new AgvWrkMast(); | 
|---|
|  |  |  | //工作状态 | 
|---|
|  |  |  | if (ioType==121) { | 
|---|
|  |  |  | if (ioType == 121) { | 
|---|
|  |  |  | mast.setWrkSts(11L); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | mast.setWrkSts(201L); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //入出库类型 | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("保存工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (agvLocMast.getLocSts().equals("F")) { | 
|---|
|  |  |  | AgvWrkMast mast1 = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", locMast.getLocNo()).eq("source_loc_no",agvLocMast.getLocNo())); | 
|---|
|  |  |  | AgvWrkMast mast1 = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", locMast.getLocNo()).eq("source_loc_no", agvLocMast.getLocNo())); | 
|---|
|  |  |  | //生成工作档明细 | 
|---|
|  |  |  | List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", agvLocMast.getLocNo())); | 
|---|
|  |  |  | agvLocDetls.forEach(agvLocDetl -> { | 
|---|
|  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果当前任务是箱壳二三楼回退一楼的 回滚调拨单 | 
|---|
|  |  |  | if (ioType == 12 && locMast.getFloor() == 1 && floor != 4 && agvLocMast.getFloor() != 1) { | 
|---|
|  |  |  | List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", agvLocMast.getLocNo())); | 
|---|
|  |  |  | for (AgvLocDetl agvLocDetl : agvLocDetls) { | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("three_code", agvLocDetl.getThreeCode()).eq("matnr", agvLocDetl.getMatnr()).eq("order_no", "DB" + agvLocDetl.getOrderNo())); | 
|---|
|  |  |  | orderDetl.setQty(orderDetl.getQty() - agvLocDetl.getAnfme()); | 
|---|
|  |  |  | if (!orderDetlService.updateById(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        // 如果当前任务是箱壳二三楼回退一楼的 回滚调拨单 | 
|---|
|  |  |  | //        if (ioType == 12 && locMast.getFloor() == 1 && floor != 4 && agvLocMast.getFloor() != 1) { | 
|---|
|  |  |  | //            List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", agvLocMast.getLocNo())); | 
|---|
|  |  |  | //            for (AgvLocDetl agvLocDetl : agvLocDetls) { | 
|---|
|  |  |  | //                OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("three_code", agvLocDetl.getThreeCode()).eq("matnr", agvLocDetl.getMatnr()).eq("source", 33)); | 
|---|
|  |  |  | //                if (Cools.isEmpty(orderDetl)) { | 
|---|
|  |  |  | //                    throw new CoolException("当前物料的调拨单不存在!"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                Order order = orderService.selectByNo(orderDetl.getOrderNo()); | 
|---|
|  |  |  | //                if (Cools.isEmpty(order)) { | 
|---|
|  |  |  | //                    throw new CoolException("当前物料的调拨单不存在!"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                if (order.getSettle() == 4L) { | 
|---|
|  |  |  | //                    if (!orderService.updateSettle(order.getId(),2L,userId)) { | 
|---|
|  |  |  | //                        throw new CoolException("调拨单回滚异常!"); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                orderDetl.setQty(orderDetl.getQty() - agvLocDetl.getAnfme()); | 
|---|
|  |  |  | //                if (!orderDetlService.updateById(orderDetl)) { | 
|---|
|  |  |  | //                    throw new CoolException("保存工作明细失败"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //更新目标库位状态 | 
|---|
|  |  |  | updateAgvLocMast(agvLocMast,"P"); | 
|---|
|  |  |  | updateAgvLocMast(locMast,"Q"); | 
|---|
|  |  |  | updateAgvLocMast(agvLocMast, "P"); | 
|---|
|  |  |  | updateAgvLocMast(locMast, "Q"); | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Synchronized | 
|---|
|  |  |  | public String allocationOut(AgvMobileStartPakin param, Long userId) { | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | if(Cools.isEmpty(param.getBarcode())) { | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode())) { | 
|---|
|  |  |  | throw new CoolException("请输入货架码"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", param.getDevNo())); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("当前货架码与任务不匹配"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!agvWrkMast.getWrkSts().equals(207L) && !agvWrkMast.getWrkSts().equals(205L)) { | 
|---|
|  |  |  | throw new CoolException("当前工作状态:" + agvWrkMast.getWrkSts$() +"不符合离场条件"); | 
|---|
|  |  |  | throw new CoolException("当前工作状态:" + agvWrkMast.getWrkSts$() + "不符合离场条件"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (agvWrkMast.getWrkSts().equals(205L)) { | 
|---|
|  |  |  | // 库位 -- 接驳位 / 库位 | 
|---|
|  |  |  | if (agvWrkMast.getLocNo().substring(0,2).equals("DB")) { | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"F",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | if (agvWrkMast.getLocNo().substring(0, 2).equals("DB")) { | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(), "F", agvWrkMast.getBarcode(), agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | // 接驳位 -- 库位 | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(),"D",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(agvWrkMast.getLocNo(), "D", agvWrkMast.getBarcode(), agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 接驳位 -- 库位 | 
|---|
|  |  |  | if (agvWrkMast.getSourceLocNo().substring(0,2).equals("DB")) { | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getSourceLocNo(),"O","",(short)0); | 
|---|
|  |  |  | if (agvWrkMast.getSourceLocNo().substring(0, 2).equals("DB")) { | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getSourceLocNo(), "O", "", (short) 0); | 
|---|
|  |  |  | // 库位 -- 接驳位 / 库位 | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //修改源库位状态为O | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O","",agvWrkMast.getWhsType().shortValue(),"",(short)0); | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(), "O", "", agvWrkMast.getWhsType().shortValue(), "", (short) 0); | 
|---|
|  |  |  | //更新目标库位明细 101.出库 删除源库位库存明细 | 
|---|
|  |  |  | agvLocDetlService.delete(new EntityWrapper<AgvLocDetl>().eq("loc_no",agvWrkMast.getSourceLocNo())); | 
|---|
|  |  |  | agvLocDetlService.delete(new EntityWrapper<AgvLocDetl>().eq("loc_no", agvWrkMast.getSourceLocNo())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | agvWrkMast.setSourceLocNo(""); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //生成AGV工作历史档 + 生成AGV工作明细历史档 | 
|---|
|  |  |  | 
|---|
|  |  |  | agvWrkDetl.setWrkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  | agvWrkDetl.setModiUser(userId); | 
|---|
|  |  |  | agvWrkDetl.setModiTime(now); | 
|---|
|  |  |  | agvWrkDetl.setIoTime(now); | 
|---|
|  |  |  | if (!agvWrkDetlService.insert(agvWrkDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 更新站点状态 | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O","",null); | 
|---|
|  |  |  | //        agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O","",null); | 
|---|
|  |  |  | // 更新源库位状态 | 
|---|
|  |  |  | //        agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"O","",agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(), "O", "", agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除AGV工作明细档 | 
|---|
|  |  |  | agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no",oldWrkNo)); | 
|---|
|  |  |  | agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", oldWrkNo)); | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 调拨进场 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | if (agvWrkMast.getCrnNo() != agvBasDevp.getFloor()) { | 
|---|
|  |  |  | throw new CoolException("请移动到->" + agvWrkMast.getCrnNo() + "楼入库点入库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AgvLocMast locNo = agvCommonService.getLocNo(3, 1,false,true); | 
|---|
|  |  |  | AgvLocMast locNo = agvCommonService.getLocNo(3, 1, false, true); | 
|---|
|  |  |  | //工作状态 | 
|---|
|  |  |  | agvWrkMast.setWrkSts(211L); | 
|---|
|  |  |  | //入出库类型 | 
|---|
|  |  |  | 
|---|
|  |  |  | agvWrkMast.setSourceLocNo(param.getDevNo()); | 
|---|
|  |  |  | agvWrkMast.setModiUser(userId); | 
|---|
|  |  |  | agvWrkMast.setModiTime(now); | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast, new EntityWrapper<AgvWrkMast>().eq("wrk_no", agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | throw new CoolException("更新工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(locNo.getLocNo(),"S",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(locNo.getLocNo(), "S", agvWrkMast.getBarcode(), agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | // 更新源库位状态 | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"R",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(), "R", agvWrkMast.getBarcode(), agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | //删除AGV工作档 | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 空架离场 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | agvWrkMast.setModiTime(new Date()); | 
|---|
|  |  |  | agvWrkMast.setWrkSts(213L); | 
|---|
|  |  |  | agvWrkMast.setSourceLocNo(""); | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast, new EntityWrapper<AgvWrkMast>().eq("wrk_no", agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | throw new CoolException("更新工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 更新源库位状态 | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"O","",agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(), "O", "", agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 空架进场 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | agvWrkMast.setWrkSts(214L); | 
|---|
|  |  |  | agvWrkMast.setModiTime(new Date()); | 
|---|
|  |  |  | agvWrkMast.setSourceLocNo(param.getDevNo()); | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast, new EntityWrapper<AgvWrkMast>().eq("wrk_no", agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | throw new CoolException("更新工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 更新源库位状态 | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",param.getBarcode(),agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(), "F", param.getBarcode(), agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 转手动回流 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public String handBack(AgvMobileStartPakin param, Long userId) { | 
|---|
|  |  |  | 
|---|
|  |  |  | agvWrkMast.setIoType(113); | 
|---|
|  |  |  | agvWrkMast.setModiUser(userId); | 
|---|
|  |  |  | agvWrkMast.setModiTime(now); | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast, new EntityWrapper<AgvWrkMast>().eq("wrk_no", agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | throw new CoolException("更新工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | 
|---|
|  |  |  | agvWrkMastLogService.save(agvWrkMast); | 
|---|
|  |  |  | agvWrkDetlLogService.save(agvWrkMast.getWrkNo()); | 
|---|
|  |  |  | String sourceLocNo = agvWrkMast.getSourceLocNo(); | 
|---|
|  |  |  | AgvLocMast newLocMast = agvCommonService.getLocNo(3, 1,false,false); | 
|---|
|  |  |  | AgvLocMast newLocMast = agvCommonService.getLocNo(3, 1, false, false); | 
|---|
|  |  |  | agvWrkMast.setSourceLocNo(agvWrkMast.getLocNo()); | 
|---|
|  |  |  | agvWrkMast.setLocNo(newLocMast.getLocNo()); | 
|---|
|  |  |  | agvWrkMast.setIoType(57); | 
|---|
|  |  |  | agvWrkMast.setWrkSts(201L); | 
|---|
|  |  |  | agvWrkMast.setModiUser(userId); | 
|---|
|  |  |  | agvWrkMast.setModiTime(now); | 
|---|
|  |  |  | agvWrkMast.setIoTime(now); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | if (!agvWrkMastService.update(agvWrkMast, new EntityWrapper<AgvWrkMast>().eq("wrk_no", agvWrkMast.getWrkNo()))) { | 
|---|
|  |  |  | throw new CoolException("更新工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 更新源站点 + 目标库位状态 + 历史源库位 | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"R",param.getBarcode(),agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(newLocMast.getLocNo(),"S",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(sourceLocNo,"O","",(short)30); | 
|---|
|  |  |  | agvLocDetlService.delete(new EntityWrapper<AgvLocDetl>().eq("loc_no",sourceLocNo)); | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(), "R", param.getBarcode(), agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(newLocMast.getLocNo(), "S", agvWrkMast.getBarcode(), agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(sourceLocNo, "O", "", (short) 30); | 
|---|
|  |  |  | agvLocDetlService.delete(new EntityWrapper<AgvLocDetl>().eq("loc_no", sourceLocNo)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<AgvWrkDetl> agvWrkDetls = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("supp_code",param.getBarcode())); | 
|---|
|  |  |  | List<AgvWrkDetl> agvWrkDetls = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("supp_code", param.getBarcode())); | 
|---|
|  |  |  | agvWrkDetls.forEach(agvWrkDetl -> { | 
|---|
|  |  |  | for (AgvWrkDetl wrkDetl : param.getWrkDetls()) { | 
|---|
|  |  |  | if (wrkDetl.getMatnr().equals(agvWrkDetl.getMatnr()) && wrkDetl.getThreeCode().equals(agvWrkDetl.getThreeCode())) { | 
|---|
|  |  |  | 
|---|
|  |  |  | agvWrkDetl.setOrderNo(agvWrkDetl.getOrderNo().substring(2)); | 
|---|
|  |  |  | agvWrkDetl.setModiUser(userId); | 
|---|
|  |  |  | agvWrkDetl.setModiTime(now); | 
|---|
|  |  |  | if (!agvWrkDetlService.update(agvWrkDetl,new EntityWrapper<AgvWrkDetl>() | 
|---|
|  |  |  | .eq("matnr",agvWrkDetl.getMatnr()) | 
|---|
|  |  |  | .eq("three_code",agvWrkDetl.getThreeCode()) | 
|---|
|  |  |  | .eq("supp_code",param.getBarcode()))) { | 
|---|
|  |  |  | agvWrkDetl.setIoTime(now); | 
|---|
|  |  |  | if (!agvWrkDetlService.update(agvWrkDetl, new EntityWrapper<AgvWrkDetl>() | 
|---|
|  |  |  | .eq("matnr", agvWrkDetl.getMatnr()) | 
|---|
|  |  |  | .eq("three_code", agvWrkDetl.getThreeCode()) | 
|---|
|  |  |  | .eq("supp_code", param.getBarcode()))) { | 
|---|
|  |  |  | throw new CoolException("更新工作明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public String doBack(AgvMobileStartPakin param, Long userId) { | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode()) || !CodeDetectionUtil.barcodeDetection(param.getBarcode())){ | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode()) || !CodeDetectionUtil.barcodeDetection(param.getBarcode())) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "货架码有误,请正确扫码!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Cools.isEmpty(param.getDevNo()) || !CodeDetectionUtil.carCodeDetection(param.getDevNo())){ | 
|---|
|  |  |  | if (Cools.isEmpty(param.getDevNo()) || !CodeDetectionUtil.carCodeDetection(param.getDevNo())) { | 
|---|
|  |  |  | throw new CoolException(param.getDevNo() + "小车地码有误,请正确扫码!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 新建回退工作档 | 
|---|
|  |  |  | AgvWrkMast wrkMast = createWrkMast(58, 201L, agvWrkMast.getLocNo(), agvWrkMast.getSourceLocNo(), agvWrkMast.getBarcode(), now, userId, agvWrkMast.getWhsType(), 0); | 
|---|
|  |  |  | // 更新接驳位,更新库位状态 | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(wrkMast.getLocNo(),"S",wrkMast.getBarcode(),wrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(wrkMast.getSourceLocNo(),"R",wrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvLocMastService.updateLocStsByLocNo(wrkMast.getLocNo(), "S", wrkMast.getBarcode(), wrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | agvBasDevpService.updateLocStsAndBarcodeByDevNo(wrkMast.getSourceLocNo(), "R", wrkMast.getBarcode(), agvWrkMast.getWhsType().shortValue()); | 
|---|
|  |  |  | // 更新工作明细 | 
|---|
|  |  |  | List<AgvWrkDetl> agvWrkDetls = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("supp_code", agvWrkMast.getBarcode())); | 
|---|
|  |  |  | for (AgvWrkDetl agvWrkDetl : agvWrkDetls) { | 
|---|
|  |  |  | agvWrkDetl.setWrkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  | // 保持工作档明细 | 
|---|
|  |  |  | agvWrkDetl.setWrkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  | agvWrkDetl.setIoTime(now); | 
|---|
|  |  |  | agvWrkDetl.setModiUser(userId); | 
|---|
|  |  |  | agvWrkDetl.setModiTime(now); | 
|---|
|  |  |  | if (!agvWrkDetlService.insert(agvWrkDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 同步订单数量 | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("matnr", agvWrkDetl.getMatnr()).eq("three_code",agvWrkDetl.getThreeCode()).in("source",18,31,34)); | 
|---|
|  |  |  | //OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("matnr", agvWrkDetl.getMatnr()).eq("three_code", agvWrkDetl.getThreeCode()).eq("order_no", agvWrkDetl.getOrderNo()).in("source", 18, 31, 34)); | 
|---|
|  |  |  | List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("matnr", agvWrkDetl.getMatnr()).eq("three_code", agvWrkDetl.getThreeCode()).eq("order_no", agvWrkDetl.getOrderNo())); | 
|---|
|  |  |  | OrderDetl orderDetl = null; | 
|---|
|  |  |  | if (orderDetls.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("订单明细不存在"); | 
|---|
|  |  |  | } else if (orderDetls.size() > 1) { | 
|---|
|  |  |  | for (OrderDetl detl : orderDetls) { | 
|---|
|  |  |  | if (Cools.isEmpty(agvWrkDetl.getBatch()) && Cools.isEmpty(detl.getBatch())) { | 
|---|
|  |  |  | orderDetl = detl; | 
|---|
|  |  |  | } else if (!Cools.isEmpty(agvWrkDetl.getBatch()) && !Cools.isEmpty(detl.getBatch()) && agvWrkDetl.getBatch().equals(detl.getBatch())) { | 
|---|
|  |  |  | orderDetl = detl; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (orderDetl == null) { | 
|---|
|  |  |  | throw new CoolException("订单明细不匹配"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | orderDetl = orderDetls.get(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderDetl.setQty(orderDetl.getQty() - agvWrkDetl.getAnfme()); | 
|---|
|  |  |  | if (!orderDetlService.update(orderDetl,new EntityWrapper<OrderDetl>().eq("order_no",orderDetl.getOrderNo()).eq("matnr", orderDetl.getMatnr()).eq("three_code",orderDetl.getThreeCode()))){ | 
|---|
|  |  |  | throw new CoolException("修改订单明细失败,请联系管理员"+orderDetl.getOrderNo()+orderDetl.getMatnr()); | 
|---|
|  |  |  | if (!orderDetlService.updateById(orderDetl)) { | 
|---|
|  |  |  | throw new CoolException("修改订单明细失败,请联系管理员" + orderDetl.getOrderNo() + orderDetl.getMatnr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //删除AGV工作档 | 
|---|
|  |  |  | agvWrkMastService.deleteById(agvWrkMast); | 
|---|
|  |  |  | //删除AGV工作明细档 | 
|---|
|  |  |  | agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no",oldWrkNo)); | 
|---|
|  |  |  | agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", oldWrkNo)); | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 更新目标库位信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void updateAgvLocMast(AgvLocMast locMast, String locSts){ | 
|---|
|  |  |  | private void updateAgvLocMast(AgvLocMast locMast, String locSts) { | 
|---|
|  |  |  | locMast.setLocSts(locSts); | 
|---|
|  |  |  | agvLocMastService.updateById(locMast); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 生成工作档 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private AgvWrkMast createWrkMast(int ioType, long wrkSts, String sourceLocNo, String locNo, String barcode,  Date now, Long userId, int containerType,int floor){ | 
|---|
|  |  |  | private AgvWrkMast createWrkMast(int ioType, long wrkSts, String sourceLocNo, String locNo, String barcode, Date now, Long userId, int containerType, int floor) { | 
|---|
|  |  |  | AgvWrkMast wrkMast = new AgvWrkMast(); | 
|---|
|  |  |  | //工作状态 | 
|---|
|  |  |  | wrkMast.setWrkSts(wrkSts); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("保存工作档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | wrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", locNo).eq("source_loc_no",sourceLocNo).eq("barcode",barcode).orderBy("modi_time",false)); | 
|---|
|  |  |  | wrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", locNo).eq("source_loc_no", sourceLocNo).eq("barcode", barcode).orderBy("modi_time", false)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return wrkMast; | 
|---|
|  |  |  | } | 
|---|