|  |  |  | 
|---|
|  |  |  | package com.zy.common.web; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
|---|
|  |  |  | 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.EmptyPlateOutParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.result.FindLocNoAttributeVo; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.common.CodeRes; | 
|---|
|  |  |  | import com.zy.common.model.LocTypeDto; | 
|---|
|  |  |  | import com.zy.common.model.StartupDto; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Created by vincent on 2020/10/30 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WaitPakinService waitPakinService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private  LocDetlService locDetlService; | 
|---|
|  |  |  | private LocDetlService locDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RowLastnoService rowLastnoService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WorkService workService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/pakin/loc/v1") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public synchronized R getLocNo(@RequestBody SearchLocParam param) { | 
|---|
|  |  |  | log.info("收到WCS入库接口请求====>>入参:{}", param); | 
|---|
|  |  |  | if (Cools.isEmpty(param.getIoType())) { | 
|---|
|  |  |  | return R.error("入出库类型不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(param.getBarcode())) { | 
|---|
|  |  |  | return R.error("条码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | waitPakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("barcode", param.getBarcode())); | 
|---|
|  |  |  | waitPakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode())); | 
|---|
|  |  |  | if (Cools.isEmpty(waitPakins)) { | 
|---|
|  |  |  | return R.error("条码数据错误"); | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode()); | 
|---|
|  |  |  | if (wrkMast != null && wrkMast.getIoType() == 103) { | 
|---|
|  |  |  | return R.parse(CodeRes.PICK_600); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.parse(CodeRes.NO_COMB_700); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode())); | 
|---|
|  |  |  | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode())); | 
|---|
|  |  |  | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode())); | 
|---|
|  |  |  | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode())); | 
|---|
|  |  |  | if (countLoc > 0 || countWrk > 0) { | 
|---|
|  |  |  | return R.error("工作档/库存条码数据已存在"); | 
|---|
|  |  |  | return R.error(CodeRes.EXIST_500); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Cools.isEmpty(param.getLocType1())){ | 
|---|
|  |  |  | if (Cools.isEmpty(param.getLocType1())) { | 
|---|
|  |  |  | return R.error("高低检测信号不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 源站点状态检测 | 
|---|
|  |  |  | BasDevp sourceStaNo = basDevpService.checkSiteStatus(param.getSourceStaNo(), true); | 
|---|
|  |  |  | sourceStaNo.setLocType1(param.getLocType1()); | 
|---|
|  |  |  | LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo); | 
|---|
|  |  |  | if (param.getBarcode().startsWith("11")) { | 
|---|
|  |  |  | locTypeDto.setLocType2((short) 1); | 
|---|
|  |  |  | } else if (param.getBarcode().startsWith("13")) { | 
|---|
|  |  |  | locTypeDto.setLocType2((short) 2); | 
|---|
|  |  |  | } else if (param.getBarcode().startsWith("16")) { | 
|---|
|  |  |  | locTypeDto.setLocType2((short) 3); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return R.error("未知托盘码规则"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StartupDto dto = null; | 
|---|
|  |  |  | switch (param.getIoType()) { | 
|---|
|  |  |  | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info("WCS入库接口返参:{},托盘码:{}", dto, param.getBarcode()); | 
|---|
|  |  |  | return R.ok().add(dto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/auto/emptyIn/v1") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public R autoEmptyIn(@RequestBody LocTypeDto locTypeDto) { | 
|---|
|  |  |  | // 源站点状态检测 | 
|---|
|  |  |  | BasDevp sourceStaNo = basDevpService.checkSiteStatus(12, true); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 检索库位 | 
|---|
|  |  |  | FindLocNoAttributeVo findLocNoAttributeVo = new FindLocNoAttributeVo(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StartupDto dto = commonService.getLocNo(10, 12, findLocNoAttributeVo, locTypeDto, null); | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | WrkMast wrkMast = new WrkMast(); | 
|---|
|  |  |  | wrkMast.setWrkNo(dto.getWorkNo()); | 
|---|
|  |  |  | wrkMast.setIoTime(now); | 
|---|
|  |  |  | wrkMast.setWrkSts(1L); | 
|---|
|  |  |  | wrkMast.setIoPri(13D); | 
|---|
|  |  |  | wrkMast.setIoType(10); | 
|---|
|  |  |  | wrkMast.setCrnNo(dto.getCrnNo()); | 
|---|
|  |  |  | wrkMast.setSourceStaNo(dto.getSourceStaNo()); | 
|---|
|  |  |  | wrkMast.setStaNo(dto.getStaNo()); | 
|---|
|  |  |  | wrkMast.setLocNo(dto.getLocNo()); | 
|---|
|  |  |  | wrkMast.setFullPlt("N"); // 满板:N | 
|---|
|  |  |  | wrkMast.setPicking("N"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | wrkMast.setEmptyMk("Y"); // 空板 | 
|---|
|  |  |  | wrkMast.setLinkMis("Y"); | 
|---|
|  |  |  | wrkMast.setCtnType(sourceStaNo.getCtnType()); // 容器类型 | 
|---|
|  |  |  | // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | wrkMast.setMemo("自动空托入库"); | 
|---|
|  |  |  | return wrkMastService.insert(wrkMast) ? R.ok("自动空托入库成功,工作号:" + wrkMast.getWrkNo()) : R.error("生成自动空托入库失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("auto/emptyOut/v1") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public R autoEmptyOut() { | 
|---|
|  |  |  | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() | 
|---|
|  |  |  | .eq("loc_sts", "D")); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | return R.error("库存没有空板"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | EmptyPlateOutParam emptyPlateOutParam = new EmptyPlateOutParam(); | 
|---|
|  |  |  | emptyPlateOutParam.setOutSite(12); | 
|---|
|  |  |  | emptyPlateOutParam.setLocNos(new ArrayList<String>() {{ | 
|---|
|  |  |  | add(locMast.getLocNo() + ""); | 
|---|
|  |  |  | }}); | 
|---|
|  |  |  | WrkMast wrkMast = workService.emptyPlateOut(emptyPlateOutParam); | 
|---|
|  |  |  | return R.ok(!Cools.isEmpty(wrkMast) ? R.ok("自动空托出库成功,工作号:" + wrkMast.getWrkNo()) : R.error("生成自动空托出库失败")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 全板入库 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 源站点状态检测 | 
|---|
|  |  |  | BasDevp sourceStaNo = basDevpService.checkSiteStatus(devpNo, true); | 
|---|
|  |  |  | // 检索库位 | 
|---|
|  |  |  | List<String> matNos = waitPakins.stream().map(WaitPakin::getMatnr).distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | StartupDto dto = commonService.getLocNo(1, 1, devpNo, matNos, locTypeDto,0); | 
|---|
|  |  |  | //        List<String> matnrs = waitPakins.stream().map(WaitPakin::getMatnr).distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | //        List<String> batchs = waitPakins.stream().map(WaitPakin::getBatch).distinct().collect(Collectors.toList()); | 
|---|
|  |  |  | //        FindLocNoAttributeVo findLocNoAttributeVo = new FindLocNoAttributeVo(matnrs.get(0), batchs.get(0)); | 
|---|
|  |  |  | WaitPakin waitPakin1 = waitPakins.get(0); | 
|---|
|  |  |  | FindLocNoAttributeVo findLocNoAttributeVo = new FindLocNoAttributeVo(); | 
|---|
|  |  |  | findLocNoAttributeVo.setMatnr(waitPakin1.getMatnr()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //TODO 测试 | 
|---|
|  |  |  | //        StartupDto dto = new StartupDto(); | 
|---|
|  |  |  | //        dto.setCrnNo(1); | 
|---|
|  |  |  | //        dto.setSourceStaNo(devpNo); | 
|---|
|  |  |  | //        dto.setStaNo(103); | 
|---|
|  |  |  | //        LocMast locMastxx = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", "O")); | 
|---|
|  |  |  | //        dto.setLocNo(locMastxx.getLocNo()); | 
|---|
|  |  |  | //        dto.setWorkNo(Integer.parseInt((System.currentTimeMillis() + "").substring(10))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StartupDto dto = commonService.getLocNo(1, devpNo, findLocNoAttributeVo, locTypeDto, barcode); | 
|---|
|  |  |  | if (dto == null) { | 
|---|
|  |  |  | throw new CoolException("找不到空库位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int workNo = dto.getWorkNo(); | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | 
|---|
|  |  |  | wrkMast.setIoTime(new Date()); | 
|---|
|  |  |  | wrkMast.setWrkSts(2L); // 工作状态:生成入库ID | 
|---|
|  |  |  | wrkMast.setIoType(1); // 入出库状态:1.入库 | 
|---|
|  |  |  | wrkMast.setIoPri(13D); // 优先级 | 
|---|
|  |  |  | wrkMast.setIoPri(30D); // 优先级 | 
|---|
|  |  |  | wrkMast.setCrnNo(dto.getCrnNo()); | 
|---|
|  |  |  | wrkMast.setSourceStaNo(dto.getSourceStaNo()); | 
|---|
|  |  |  | wrkMast.setStaNo(dto.getStaNo()); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | wrkMast.setModiUser(waitPakin1.getModiUser()); | 
|---|
|  |  |  | wrkMast.setAppeUser(waitPakin1.getAppeUser()); | 
|---|
|  |  |  | boolean res = wrkMastService.insert(wrkMast); | 
|---|
|  |  |  | if (!res) { | 
|---|
|  |  |  | throw new CoolException("保存工作档失败"); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("保存工作明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | // 更新入库通知档 ioStatus ===>> Y | 
|---|
|  |  |  | if (!waitPakinService.updateIoStatus("Y", dto.getLocNo(), barcode)) { | 
|---|
|  |  |  | throw new CoolException("更新通知档失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 更新源站点信息 | 
|---|
|  |  |  | sourceStaNo.setWrkNo(workNo); | 
|---|
|  |  |  | sourceStaNo.setModiTime(now); | 
|---|
|  |  |  | if (!basDevpService.updateById(sourceStaNo)){ | 
|---|
|  |  |  | if (!basDevpService.updateById(sourceStaNo)) { | 
|---|
|  |  |  | throw new CoolException("更新源站失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 更新目标库位状态 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectById(dto.getLocNo()); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("O")){ | 
|---|
|  |  |  | if (locMast.getLocSts().equals("O")) { | 
|---|
|  |  |  | locMast.setLocSts("S"); // S.入库预约 | 
|---|
|  |  |  | locMast.setModiTime(now); | 
|---|
|  |  |  | if (!locMastService.updateById(locMast)){ | 
|---|
|  |  |  | if (!locMastService.updateById(locMast)) { | 
|---|
|  |  |  | throw new CoolException("改变库位状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException(dto.getLocNo()+"目标库位已被占用"); | 
|---|
|  |  |  | throw new CoolException(dto.getLocNo() + "目标库位已被占用"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | // 源站点状态检测 | 
|---|
|  |  |  | BasDevp sourceStaNo = basDevpService.checkSiteStatus(devpNo, true); | 
|---|
|  |  |  | // 检索库位 | 
|---|
|  |  |  | StartupDto dto = commonService.getLocNo(1, 10, devpNo, null, locTypeDto,0); | 
|---|
|  |  |  | FindLocNoAttributeVo findLocNoAttributeVo = new FindLocNoAttributeVo(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StartupDto dto = commonService.getLocNo(10, devpNo, findLocNoAttributeVo, locTypeDto, barcode); | 
|---|
|  |  |  | int workNo = dto.getWorkNo(); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | WrkMast wrkMast = new WrkMast(); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 更新源站点信息 | 
|---|
|  |  |  | sourceStaNo.setWrkNo(workNo); | 
|---|
|  |  |  | sourceStaNo.setModiTime(new Date()); | 
|---|
|  |  |  | if (!basDevpService.updateById(sourceStaNo)){ | 
|---|
|  |  |  | if (!basDevpService.updateById(sourceStaNo)) { | 
|---|
|  |  |  | throw new CoolException("更新源站失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 更新目标库位状态 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectById(dto.getLocNo()); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("O")){ | 
|---|
|  |  |  | if (locMast.getLocSts().equals("O")) { | 
|---|
|  |  |  | locMast.setLocSts("S"); // S.入库预约 | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | if (!locMastService.updateById(locMast)){ | 
|---|
|  |  |  | if (!locMastService.updateById(locMast)) { | 
|---|
|  |  |  | throw new CoolException("改变库位状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException(dto.getLocNo()+"目标库位已被占用"); | 
|---|
|  |  |  | throw new CoolException(dto.getLocNo() + "目标库位已被占用"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | } | 
|---|