|  |  |  | 
|---|
|  |  |  | import com.zy.common.properties.SlaveProperties; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.common.web.WcsController; | 
|---|
|  |  |  | import com.zy.system.entity.Config; | 
|---|
|  |  |  | import com.zy.system.service.ConfigService; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | 
|---|
|  |  |  | private OrderService orderService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrderDetlService orderDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ConfigService configService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WcsController wcsController; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | dtos.add(new OutLocDto(locNo, locDetlDto)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Config config = configService.selectConfigByCode("AutoMPArea"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<LocMast> list = locMastMapper.selectList( | 
|---|
|  |  |  | new EntityWrapper<LocMast>() | 
|---|
|  |  |  | .eq("whs_type", 5) | 
|---|
|  |  |  | .eq("loc_sts", "O") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | LocMast locMastRgv = list.isEmpty() ? null : list.get(0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer ioType = null; | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | for (OutLocDto dto : dtos) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取路径 | 
|---|
|  |  |  | StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), outSta); | 
|---|
|  |  |  | if(ioType.equals(107)){ | 
|---|
|  |  |  | staDesc = staDescService.queryCrnStnCheck(ioType, locMast.getCrnNo(), outSta); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | 
|---|
|  |  |  | wrkMast.setEmptyMk("N"); // 空板 | 
|---|
|  |  |  | wrkMast.setLinkMis("N"); | 
|---|
|  |  |  | wrkMast.setBarcode(locMast.getBarcode()); | 
|---|
|  |  |  | if(locMastRgv !=null){ | 
|---|
|  |  |  | if (Boolean.parseBoolean(config.getValue()) && locMastRgv.getLocNo() != null && ioType != 107) {  //若有空库位且配置允许则绑定其备料库位号 | 
|---|
|  |  |  | wrkMast.setLocNo(locMastRgv.getLocNo()); | 
|---|
|  |  |  | wrkMast.setTakeNone("0");  //0rgv未取,1rgv已取货 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrkMast.setAppeUser(userId); // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiUser(userId); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(locMastRgv !=null){ | 
|---|
|  |  |  | if (Boolean.parseBoolean(config.getValue()) && locMastRgv.getLocNo() != null && ioType != 107) {  //若有空库位且配置允许则绑定其备料库位号 | 
|---|
|  |  |  | //修改agv备料区状态 | 
|---|
|  |  |  | if(locMastRgv.getLocSts().equals("O") && ioType != 107){ | 
|---|
|  |  |  | locMastRgv.setLocSts("S"); | 
|---|
|  |  |  | locMastRgv.setModiUser(userId); | 
|---|
|  |  |  | locMastRgv.setModiTime(now); | 
|---|
|  |  |  | if (!locMastService.updateById(locMastRgv)) { | 
|---|
|  |  |  | throw new CoolException("预约agv备料区库位状态失败,库位号:"+locMastRgv.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 | 
|---|
|  |  |  | locMast = locMastService.selectById(dto.getLocNo()); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("F")) { | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("订单出库异常,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Config config = configService.selectConfigByCode("AutoMPArea"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取库位 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectById(taskDto.getLocNo()); | 
|---|
|  |  |  | // 判断是否是盘点单 | 
|---|
|  |  |  | 
|---|
|  |  |  | OrderPakout orderPakout = orderPakOutService.selectByNo(orderNo); | 
|---|
|  |  |  | int ioType = orderPakout.getDocType() == 8 ? 107 : (taskDto.isAll() ? 101 : 103); | 
|---|
|  |  |  | StaDesc staDesc = staDescService.queryCrnStnAuto(ioType, locMast.getCrnNo(), staNo.getDevNo()); | 
|---|
|  |  |  | List<LocMast> list = locMastMapper.selectList( | 
|---|
|  |  |  | new EntityWrapper<LocMast>() | 
|---|
|  |  |  | .eq("whs_type", 5) | 
|---|
|  |  |  | .eq("loc_sts", "O") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | LocMast locMastRgv = list.isEmpty() ? null : list.get(0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | 
|---|
|  |  |  | wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站 | 
|---|
|  |  |  | wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 | 
|---|
|  |  |  | wrkMast.setSourceLocNo(taskDto.getLocNo()); // 源库位 | 
|---|
|  |  |  | if (Boolean.parseBoolean(config.getValue()) && locMastRgv.getLocNo() != null) {  //若有空库位且配置允许则绑定其备料库位号 | 
|---|
|  |  |  | wrkMast.setLocNo(locMastRgv.getLocNo()); | 
|---|
|  |  |  | wrkMast.setTakeNone("0");  //0rgv未取,1rgv已取货 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrkMast.setFullPlt("Y"); // 满板:Y | 
|---|
|  |  |  | wrkMast.setPicking("N"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | 
|---|
|  |  |  | orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3() | 
|---|
|  |  |  | , locDto.getAnfme()); | 
|---|
|  |  |  | OrderInAndOutUtil.updateOrder(Boolean.FALSE,orderDetl.getOrderId(), 2L, userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //修改agv备料区状态 | 
|---|
|  |  |  | if(locMastRgv.getLocSts().equals("O")){ | 
|---|
|  |  |  | locMastRgv.setLocSts("S"); | 
|---|
|  |  |  | locMastRgv.setModiUser(userId); | 
|---|
|  |  |  | locMastRgv.setModiTime(now); | 
|---|
|  |  |  | if (!locMastService.updateById(locMastRgv)) { | 
|---|
|  |  |  | throw new CoolException("预约agv备料区库位状态失败,库位号:"+locMastRgv.getLocNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw new CoolException(locMastRgv.getLocNo() + "备料区不是空库位状态"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 | 
|---|
|  |  |  | locMast = locMastService.selectById(taskDto.getLocNo()); | 
|---|
|  |  |  | 
|---|
|  |  |  | //取消出库工作档时,查询单据管理表,回滚作业中数量 | 
|---|
|  |  |  | if(wrkMast.getIoType() == 101 || wrkMast.getIoType() == 103) { | 
|---|
|  |  |  | List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  | if(wrkMast.getLocNo() != null){ | 
|---|
|  |  |  | LocMast locMast = locMastService.selectById(wrkMast.getLocNo()); | 
|---|
|  |  |  | locMast.setLocSts("O"); | 
|---|
|  |  |  | locMast.setModiTime(now); | 
|---|
|  |  |  | locMast.setModiUser(userId); | 
|---|
|  |  |  | boolean locMastRes = locMastService.updateById(locMast); | 
|---|
|  |  |  | if (!locMastRes) { | 
|---|
|  |  |  | throw new CoolException("保存数据失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (WrkDetl wrkDetl : wrkDetls) { | 
|---|
|  |  |  | if (!Cools.isEmpty(wrkDetl.getOrderNo())) { | 
|---|
|  |  |  | //                    if (!orderDetlService.decrease(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) { | 
|---|