| | |
| | | package com.zy.common.web; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.mapper.WrkMastMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.common.model.AgvBasDevpDto; |
| | | import com.zy.common.model.LocTypeDto; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.service.CommonService; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @RestController |
| | | @RequestMapping("/rpc") |
| | | public class WcsController { |
| | | |
| | | private static HashMap<String,String> currentContainerMap; |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | |
| | | private AgvWrkMastService agvWrkMastService; |
| | | @Autowired |
| | | private WrkMastMapper wrkMastMapper; |
| | | @Autowired |
| | | private WrkMastLogService wrkMastLogService; |
| | | @Autowired |
| | | private AgvWrkDetlService agvWrkDetlService; |
| | | @Autowired |
| | | private AgvLocDetlService agvLocDetlService; |
| | | // @Autowired |
| | | // private ErpService erpService; |
| | | |
| | |
| | | throw new CoolException(dto.getLocNo() + "目标库位已被占用"); |
| | | } |
| | | |
| | | // 保存工作主档历史档 |
| | | if (!wrkMastLogService.save(wrkMast.getWrkNo())) { |
| | | throw new CoolException(wrkMast.getWrkNo() + "保存工作主档历史档失败"); |
| | | } |
| | | |
| | | //获取回库提升机目标站 |
| | | Integer staNo = liftNo * 100 + locMast.getLev1(); |
| | | // 更新工作档数据状态 |
| | |
| | | wrkMast.setShuttleNo(null); // 穿梭车清空 |
| | | wrkMast.setLiftNo(null);// 提升机清空 |
| | | wrkMast.setModiTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) > 0) { |
| | | if (!wrkMastService.updateById(wrkMast)) { |
| | | throw new CoolException(wrkMast.getWrkNo() + "更新工作档数据状态失败"); |
| | | } |
| | | |
| | |
| | | if (!locMastService.updateById(locMast)) { |
| | | throw new CoolException("改变库位状态失败"); |
| | | } |
| | | |
| | | List<LocDetl> locDetls1 = locDetlService.selectByLocNo(locMast.getLocNo()); |
| | | log.info("工作号:" + wrkMast.getWrkNo() + ",托盘码:" + wrkMast.getBarcode() + ",修改库位状态O=>Q成功,库存明细:" + JSON.toJSONString(locDetls1)); |
| | | } else { |
| | | throw new CoolException(dto.getLocNo() + "目标库位已被占用"); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | //清空源库位数据 |
| | | //检查目标库位,库存明细是否添加成功 |
| | | List<LocDetl> checkLocDetls = locDetlService.selectByLocNo(dto.getLocNo()); |
| | | if (checkLocDetls.isEmpty()) { |
| | | throw new CoolException("库存明细迁移失败"); |
| | | } |
| | | |
| | | // //清空源库位数据 |
| | | LocMast locMast1 = locMastService.selectByLoc(wrkMast.getSourceLocNo()); |
| | | if (locMast1.getLocSts().equals("P")) { |
| | | locMast1.setLocSts("O"); // 清空库位 |
| | | locMast1.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMast1)) { |
| | | throw new CoolException("改变库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("源库位状态异常"); |
| | | // if (locMast1.getLocSts().equals("P")) { |
| | | // locMast1.setLocSts("O"); // 清空库位 |
| | | // locMast1.setModiTime(new Date()); |
| | | // if (!locMastService.updateById(locMast1)) { |
| | | // throw new CoolException("改变库位状态失败"); |
| | | // } |
| | | // } else { |
| | | // throw new CoolException("源库位状态异常"); |
| | | // } |
| | | |
| | | // 保存工作主档历史档 |
| | | if (!wrkMastLogService.save(wrkMast.getWrkNo())) { |
| | | throw new CoolException(wrkMast.getWrkNo() + "保存工作主档历史档失败"); |
| | | } |
| | | |
| | | //获取回库提升机目标站 |
| | |
| | | wrkMast.setShuttleNo(null); // 穿梭车清空 |
| | | wrkMast.setLiftNo(null);// 提升机清空 |
| | | wrkMast.setModiTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) > 0) { |
| | | if (!wrkMastService.updateById(wrkMast)) { |
| | | throw new CoolException(wrkMast.getWrkNo() + "更新工作档数据状态失败"); |
| | | } |
| | | |
| | |
| | | if(Cools.isEmpty(agvBasDevp) || !"O".equals(agvBasDevp.getLocSts())){ |
| | | throw new CoolException("当前站点不存在或者站点不为空"); |
| | | } |
| | | if(Cools.isEmpty(agvWaitPakinService.selectByContainerCode(containerCode))){ |
| | | throw new CoolException("该料箱位组托"); |
| | | AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode", containerCode)); |
| | | |
| | | //拣料、盘点完成任务 |
| | | if(!Cools.isEmpty(agvWrkMast) && (agvWrkMast.getIoType() == 103 || agvWrkMast.getIoType() == 107) && agvWrkMast.getWrkSts() == 205){ |
| | | //绑定站点 |
| | | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode,agvWrkMast.getWhsType().shortValue()); |
| | | |
| | | //生成拣料、盘点再入库任务 |
| | | List<AgvWrkMast> agvWrkMastList = new ArrayList<>(); |
| | | agvWrkMast.setMk("Y"); |
| | | agvWrkMast.setLocNo(agvBasDevp.getDevNo()); |
| | | agvWrkMastList.add(agvWrkMast); |
| | | agvWorkService.pickIn(agvWrkMastList); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | //去找agv工作档任务 |
| | | if(!Cools.isEmpty(agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode",containerCode)))){ |
| | | throw new CoolException("该料箱正在入库中"); |
| | | //入库任务 |
| | | if (!Cools.isEmpty(agvWaitPakinService.selectByContainerCode(containerCode))){ |
| | | //绑定站点 |
| | | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode,agvWrkMast.getWhsType().shortValue()); |
| | | //生成工作档 |
| | | List<AgvBasDevp> agvBasDevpList = agvBasDevpService.selectList(new EntityWrapper<AgvBasDevp>().eq("dev_no", param.getDevNo())); |
| | | agvWorkService.createWaitPainWrkMastStart(agvBasDevpList, null, true); |
| | | |
| | | return R.ok(); |
| | | } |
| | | //绑定站点 |
| | | agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",containerCode); |
| | | |
| | | //生成工作档 |
| | | List<AgvBasDevp> agvBasDevpList = agvBasDevpService.selectList(new EntityWrapper<AgvBasDevp>().eq("dev_no", param.getDevNo())); |
| | | agvWorkService.createWaitPainWrkMastStart(agvBasDevpList, null, true); |
| | | return R.error("没有查询到该料箱信息"); |
| | | |
| | | } |
| | | |
| | | @PostMapping("/current/containerCode") |
| | | @ResponseBody |
| | | public R move(@RequestBody ReplenishmentParam param){ |
| | | |
| | | if(Cools.isEmpty(currentContainerMap)){ |
| | | currentContainerMap = new HashMap<>(); |
| | | } |
| | | |
| | | String containerCode = param.getContainerCode().split(";")[0]; |
| | | |
| | | if(Cools.isEmpty(containerCode)){ |
| | | throw new CoolException("料箱码为空"); |
| | | } |
| | | |
| | | if(!Character.isDigit(containerCode.charAt(0))){ |
| | | containerCode = containerCode.substring(3,containerCode.length()); |
| | | } |
| | | |
| | | |
| | | String devNo = param.getDevNo(); |
| | | String currentContainerCode = currentContainerMap.get(devNo); |
| | | |
| | | //判断容器是否发生变化 |
| | | if(!Cools.isEmpty(currentContainerCode) && !Cools.eq(containerCode,currentContainerCode)){ |
| | | //查询旧容器的工作档 |
| | | AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(currentContainerCode); |
| | | if(!Cools.isEmpty(agvWrkMast) && agvWrkMast.getIoType() == 101){ |
| | | //将工作党状态改为容器离场 |
| | | agvWrkMast.setWrkSts(206L); |
| | | agvWrkMastService.updateById(agvWrkMast); |
| | | // //发送容器立场请求,完成工作档 |
| | | // List<AgvWrkMast> agvWrkMastList = new ArrayList<>(); |
| | | // agvWrkMastList.add(agvWrkMast); |
| | | // try { |
| | | // int code = agvWrkMastService.containerMoveOut(agvWrkMastList); |
| | | // if(code == 0){ |
| | | // //将工作党状态改为容器离场 |
| | | // agvWrkMast.setWrkSts(206L); |
| | | // agvWrkMastService.updateById(agvWrkMast); |
| | | // } |
| | | // } catch (IOException e) { |
| | | // log.error(e.getMessage()); |
| | | // } |
| | | } |
| | | } |
| | | |
| | | currentContainerMap.put(devNo,containerCode); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /* |
| | | 显示AGV输送线拣料、盘点、入库信息 |
| | | */ |
| | | @PostMapping("/info") |
| | | @ResponseBody |
| | | public R containerMove(@RequestBody ReplenishmentParam param){ |
| | | |
| | | String devNo = param.getDevNo(); |
| | | String containerCode = currentContainerMap.get(devNo); |
| | | |
| | | AgvBasDevpDto agvBasDevpDto = new AgvBasDevpDto(); |
| | | |
| | | //查找该容器的工作档 |
| | | AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(containerCode); |
| | | if(!Cools.isEmpty(agvWrkMast)){ |
| | | List<AgvWrkDetl> agvWrkDetlList = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", agvWrkMast.getWrkNo())); |
| | | |
| | | for (AgvWrkDetl agvWrkDetl : agvWrkDetlList){ |
| | | agvWrkDetl.setVolume(agvWrkDetl.getAnfme()); |
| | | if(agvWrkMast.getIoType() == 103){ |
| | | //寻找是否有相同物料的工作档明细,并返回数量之和 |
| | | double anfme = getAllAnfmeInAgvWrkDetlList(agvWrkDetlList,agvWrkDetl); |
| | | AgvLocDetl agvLocDetl = agvLocDetlService.selectByMatnrAndBatchAndCsocodeAndisoCode(agvWrkMast.getSourceLocNo(), agvWrkDetl.getMatnr(), agvWrkDetl.getBatch(), agvWrkDetl.getThreeCode(), agvWrkDetl.getDeadTime()); |
| | | //用于结余数量显示 |
| | | agvWrkDetl.setVolume(agvLocDetl.getAnfme() - anfme); |
| | | } |
| | | if(agvWrkMast.getIoType() == 53){ |
| | | AgvLocDetl agvLocDetl = agvLocDetlService.selectByMatnrAndBatchAndCsocodeAndisoCode(agvWrkMast.getLocNo(), agvWrkDetl.getMatnr(), agvWrkDetl.getBatch(), agvWrkDetl.getThreeCode(), agvWrkDetl.getDeadTime()); |
| | | if(Cools.isEmpty(agvLocDetl)){ |
| | | agvWrkDetl.setVolume(0.0); |
| | | }else { |
| | | agvWrkDetl.setVolume(agvLocDetl.getAnfme()); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | agvBasDevpDto.setAgvWrkDetls(agvWrkDetlList); |
| | | agvBasDevpDto.setAgvWrkMast(agvWrkMast); |
| | | } |
| | | //查找该容器的入库通知档 |
| | | List<AgvWaitPakin> agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper<AgvWaitPakin>().eq("supp_code", containerCode)); |
| | | if(!Cools.isEmpty(agvWaitPakinList)){ |
| | | agvBasDevpDto.setAgvWaitPakins(agvWaitPakinList); |
| | | } |
| | | |
| | | System.out.println("currentContainerMap: " + currentContainerMap); |
| | | |
| | | |
| | | System.out.println("agvBasDevpDto: " + agvBasDevpDto); |
| | | |
| | | return R.ok(agvBasDevpDto); |
| | | } |
| | | |
| | | private double getAllAnfmeInAgvWrkDetlList(List<AgvWrkDetl> agvWrkDetlList, AgvWrkDetl wd0) { |
| | | double allAnfme = 0; |
| | | for (AgvWrkDetl wd1 : agvWrkDetlList){ |
| | | if(Cools.eq(wd0.getMatnr(),wd1.getMatnr()) |
| | | && Cools.eq(wd0.getBatch(),wd1.getBatch()) |
| | | && Cools.eq(wd0.getThreeCode(),wd1.getThreeCode()) |
| | | && Cools.eq(wd0.getDeadTime(),wd1.getDeadTime())){ |
| | | allAnfme += wd1.getAnfme(); |
| | | } |
| | | } |
| | | return allAnfme; |
| | | } |
| | | |
| | | |
| | | } |