|  |  |  | 
|---|
|  |  |  | 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.CombParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.LocMoveParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.MobileAdjustParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.PickParam; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.common.model.DetlDto; | 
|---|
|  |  |  | import com.zy.common.service.AgvCommonService; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | 
|---|
|  |  |  | private AgvLocDetlService agvLocDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AgvWrkMastService agvWrkMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AgvWorkService agvWorkService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AgvWrkDetlService agvWrkDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AgvLocMastService agvLocMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AgvCommonService agvCommonService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { | 
|---|
|  |  |  | throw new CoolException(BaseRes.PARAM); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | param.setContainerType(Short.valueOf(param.getBarcode().substring(0,2))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检查是否已存在相同的托盘条码,存在则抛出异常 | 
|---|
|  |  |  | if (agvWaitPakinService.selectCount(new EntityWrapper<AgvWaitPakin>().eq("supp_code", param.getBarcode())) > 0) { | 
|---|
|  |  |  | throw new CoolException(param.getBarcode() + "料想码已存在AGV入库通知档中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        //检查是否已存在相同的托盘条码,存在则抛出异常 | 
|---|
|  |  |  | //        if (agvWaitPakinService.selectCount(new EntityWrapper<AgvWaitPakin>().eq("supp_code", param.getBarcode())) > 0) { | 
|---|
|  |  |  | //            throw new CoolException(param.getBarcode() + "料想码已存在AGV入库通知档中"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检查库存是否有相同料箱,存在则抛出异常 | 
|---|
|  |  |  | if(!Cools.isEmpty(agvLocDetlService.selectOne(new EntityWrapper<AgvLocDetl>().eq("supp_code",param.getBarcode())))){ | 
|---|
|  |  |  | 
|---|
|  |  |  | if(StringUtils.isEmpty(param.getLocno())){ | 
|---|
|  |  |  | return "组托成功"; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | combBinding(param.getBarcode(),param.getLocno()); | 
|---|
|  |  |  | combBinding(param.getBarcode(),param.getLocno(),param.getContainerType()); | 
|---|
|  |  |  | return "组托成功,绑定站点成功"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 再次拣料 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public String pickAgain(PickParam pickParams, Long userId) { | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", pickParams.getLocNo())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (PickParam.Pick pick : pickParams.getPicks()) { | 
|---|
|  |  |  | if (pick.getCount().equals(0D)) continue; | 
|---|
|  |  |  | AgvWrkDetl agvWrkDetl = agvWrkDetlService.selectOne(new EntityWrapper<AgvWrkDetl>().eq("matnr", pick.getMatnr()).eq("three_code", pick.getThreeCode())); | 
|---|
|  |  |  | if (Cools.isEmpty(agvWrkDetl)) { | 
|---|
|  |  |  | AgvWrkDetl wrkDetl = 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(now); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Double anfme = agvWrkDetl.getAnfme() + pick.getCount(); | 
|---|
|  |  |  | agvWrkDetl.setAnfme(anfme); | 
|---|
|  |  |  | agvWrkDetlService.update(agvWrkDetl,new EntityWrapper<AgvWrkDetl>().eq("matnr",agvWrkDetl.getMatnr()).eq("three_code",agvWrkDetl.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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //  确认是否全部出库 | 
|---|
|  |  |  | 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++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (agvLocDetls.size() == sameNumber) { | 
|---|
|  |  |  | AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("wrk_no", pickParams.getWrkNo())); | 
|---|
|  |  |  | agvWrkMast.setIoType(101); | 
|---|
|  |  |  | agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no", pickParams.getWrkNo())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return "组托成功,绑定站点成功"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 
|---|
|  |  |  | syncWaitPakin(detlDto,"",param.getBarcode(),userId,now); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | AGV有单组托 | 
|---|
|  |  |  | 
|---|
|  |  |  | checkOrderQty(order,combMat); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(), combMat.getIsoseq(),combMat.getContainerCode()); | 
|---|
|  |  |  | DetlDto detlDto = new DetlDto(combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(), combMat.getIsoseq(),combMat.getContainerCode(),param.getLocType()); | 
|---|
|  |  |  | //同一托盘下相同物料信息和批号转为一个入库通知档 | 
|---|
|  |  |  | if (DetlDto.has(detlDtos, detlDto)) { | 
|---|
|  |  |  | DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(), detlDto.getCsocode(), detlDto.getIsoseq(),null); | 
|---|
|  |  |  | 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 { | 
|---|
|  |  |  | 
|---|
|  |  |  | //销售订单行号 | 
|---|
|  |  |  | waitPakin.setDeadTime(detlDto.getIsoseq()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | waitPakin.setLocType(detlDto.getLocType()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | waitPakin.setAppeUser(userId); | 
|---|
|  |  |  | waitPakin.setAppeTime(now); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void combBinding(String barcode, String stationCode) { | 
|---|
|  |  |  | public void combBinding(String barcode, String stationCode, Short containerType) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("dev_no", stationCode)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Cools.eq(agvBasDevp.getBarcode(),barcode)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Cools.isEmpty(agvWaitPakinService.selectByContainerCode(barcode))){ | 
|---|
|  |  |  | throw new CoolException("该料箱未组托,无法绑定站点"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AgvBasDevp agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("barcode", barcode)); | 
|---|
|  |  |  | AgvBasDevp agvBasDevp1 = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("barcode", barcode)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!Cools.isEmpty(agvBasDevp)){ | 
|---|
|  |  |  | if(!Cools.isEmpty(agvBasDevp1)){ | 
|---|
|  |  |  | throw new CoolException(barcode + "已经绑定在"+ agvBasDevp.getDevNo() +"站点"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | agvBasDevp = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("dev_no",stationCode)); | 
|---|
|  |  |  | if(agvBasDevp == null){ | 
|---|
|  |  |  | throw new CoolException(stationCode + "站点信息错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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)){ | 
|---|
|  |  |  | 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))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | }).collect(Collectors.toList()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void pakinEmpty(String devNo, boolean pakin) { | 
|---|
|  |  |  | //当前站点信息 | 
|---|
|  |  |  | AgvBasDevp agvBasDevp = agvBasDevpService.selectById(devNo); | 
|---|
|  |  |  | //寻找相同类型的库位 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //生成空盘工作档 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更改库位状态以及站点状态 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void pakoutEmpty(String devNo) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 手动移库 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public String handControlLocMove(LocMoveParam param, Long userId) { | 
|---|
|  |  |  | String fl = String.valueOf(param.getFloor()); | 
|---|
|  |  |  | short floor =(short)Integer.parseInt(fl.substring(0, 1)); | 
|---|
|  |  |  | Integer ioType = 0; | 
|---|
|  |  |  | AgvLocMast agvLocMast = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", param.getLocNo())); | 
|---|
|  |  |  | if (Cools.isEmpty(agvLocMast)) { | 
|---|
|  |  |  | throw new CoolException("当前库位为空,请检查库位!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if (agvLocMast.getLocSts() == "F") { | 
|---|
|  |  |  | //            return R.error("当前库位不为在库,或者空货架,不支持移库"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 校验楼层 | 
|---|
|  |  |  | if (agvLocMast.getLocType1() != 3) { // 不为箱壳区域 | 
|---|
|  |  |  | if (agvLocMast.getFloor() != floor) { | 
|---|
|  |  |  | throw new CoolException("当前库位不支持跨楼层转移"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | ioType = 11; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | ioType = 12; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | //查询工作档 | 
|---|
|  |  |  | AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(agvLocMast.getBarcode()); | 
|---|
|  |  |  | if(!Cools.isEmpty(agvWrkMast)){ | 
|---|
|  |  |  | throw new CoolException("当前"+agvLocMast.getBarcode()+"货架码已在工作档中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //检索库位,选择合适的库位 | 
|---|
|  |  |  | AgvLocMast locMast = agvCommonService.getLocNo(agvLocMast.getLocType1(),floor); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | throw new CoolException("当前楼层没有空库位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //生成工作档 | 
|---|
|  |  |  | AgvWrkMast mast = new AgvWrkMast(); | 
|---|
|  |  |  | //工作状态 | 
|---|
|  |  |  | mast.setWrkSts(201L); | 
|---|
|  |  |  | //入出库类型 | 
|---|
|  |  |  | mast.setIoType(ioType); | 
|---|
|  |  |  | mast.setIoTime(now); | 
|---|
|  |  |  | //优先级 | 
|---|
|  |  |  | mast.setIoPri(300.0); | 
|---|
|  |  |  | //源站点 | 
|---|
|  |  |  | mast.setSourceLocNo(agvLocMast.getLocNo()); | 
|---|
|  |  |  | //目标站点 | 
|---|
|  |  |  | mast.setLocNo(locMast.getLocNo()); | 
|---|
|  |  |  | //容器编码 | 
|---|
|  |  |  | mast.setBarcode(agvLocMast.getBarcode()); | 
|---|
|  |  |  | //容器类型 | 
|---|
|  |  |  | mast.setWhsType(30); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mast.setAppeUser(userId); | 
|---|
|  |  |  | mast.setAppeTime(now); | 
|---|
|  |  |  | mast.setModiUser(userId); | 
|---|
|  |  |  | mast.setModiTime(now); | 
|---|
|  |  |  | if (!agvWrkMastService.insertByIncrease(mast)) { | 
|---|
|  |  |  | 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())); | 
|---|
|  |  |  | //生成工作档明细 | 
|---|
|  |  |  | List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", agvLocMast.getLocNo())); | 
|---|
|  |  |  | agvLocDetls.forEach(agvLocDetl -> { | 
|---|
|  |  |  | AgvWrkDetl wrkDetl = new AgvWrkDetl(); | 
|---|
|  |  |  | wrkDetl.setWrkNo(mast1.getWrkNo()); | 
|---|
|  |  |  | wrkDetl.sync(agvLocDetl); | 
|---|
|  |  |  | wrkDetl.setSuppCode(agvLocDetl.getSuppCode()); | 
|---|
|  |  |  | wrkDetl.setIoTime(now); | 
|---|
|  |  |  | wrkDetl.setAppeUser(9527L); | 
|---|
|  |  |  | wrkDetl.setAppeTime(now); | 
|---|
|  |  |  | wrkDetl.setModiUser(9527L); | 
|---|
|  |  |  | wrkDetl.setModiTime(now); | 
|---|
|  |  |  | if (!agvWrkDetlService.insert(wrkDetl)) { | 
|---|
|  |  |  | throw new CoolException("保存工作明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新目标库位状态 | 
|---|
|  |  |  | updateAgvLocMast(agvLocMast,"P"); | 
|---|
|  |  |  | updateAgvLocMast(locMast,"Q"); | 
|---|
|  |  |  | return "ok"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 更新目标库位信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void updateAgvLocMast(AgvLocMast locMast, String locSts){ | 
|---|
|  |  |  | locMast.setLocSts(locSts); | 
|---|
|  |  |  | agvLocMastService.updateById(locMast); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|