| | |
| | | import com.zy.common.model.ExistDto; |
| | | import com.zy.common.model.LocDto; |
| | | import com.zy.common.model.TaskDto; |
| | | import com.zy.common.utils.OutStockInterceptUtil; |
| | | import com.zy.common.utils.RoleUtils; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | /** 处理订单出库货位分配 |
| | | /** |
| | | * 处理订单出库货位分配 |
| | | * |
| | | * @param jsonObject 请求参数(包含订单明细ID列表和出库数量) |
| | | */ |
| | | @PostMapping("/out/pakout/OrderOutGetLoc.number/auth") |
| | |
| | | |
| | | /** |
| | | * 处理单个订单明细的货位分配 |
| | | * @param orderDetl 订单明细 |
| | | * |
| | | * @param orderDetl 订单明细 |
| | | * @param requiredAmount 需求出库量 |
| | | * @param processedLocs 已处理的货位集合(用于去重) |
| | | * @param processedLocs 已处理的货位集合(用于去重) |
| | | * @param processedStock 已处理的库存记录集合(用于去重) |
| | | */ |
| | | private List<LocDto> processOrderDetl(OrderDetl orderDetl, Double requiredAmount, |
| | | Set<String> processedLocs, Set<ExistDto> processedStock) { |
| | | Set<String> processedLocs, Set<ExistDto> processedStock) { |
| | | List<LocDto> result = new ArrayList<>(); |
| | | double remaining = Optional.ofNullable(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | |
| | |
| | | throw new CoolException("出库数量必须大于0"); |
| | | } |
| | | if (requiredAmount > remaining) { |
| | | throw new CoolException("订单"+orderDetl.getOrderNo()+"请求数量超过可出库数量,剩余可出:" + remaining); |
| | | throw new CoolException("订单" + orderDetl.getOrderNo() + "请求数量超过可出库数量,剩余可出:" + remaining); |
| | | } |
| | | // 当指定数量时,使用指定数量覆盖剩余量 |
| | | remaining = Math.min(requiredAmount, remaining); |
| | |
| | | |
| | | // 获取可用库存记录 |
| | | List<LocDetl> stocks = locDetlService.queryStock( |
| | | orderDetl.getMatnr(), orderDetl.getBatch(), null, |
| | | processedLocs, orderDetl.getSupp(), |
| | | orderDetl.getTemp1(), orderDetl.getTemp2() |
| | | orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getSuppCode(), |
| | | processedLocs, orderDetl.getSupp(), |
| | | orderDetl.getTemp1(), orderDetl.getTemp2() |
| | | ); |
| | | |
| | | // 遍历处理每个库存记录 |
| | |
| | | if (remaining <= 0) break; |
| | | |
| | | LocMast locMast = locMastService.selectOne( |
| | | new EntityWrapper<LocMast>().eq("loc_no", stock.getLocNo())); |
| | | new EntityWrapper<LocMast>().eq("loc_no", stock.getLocNo())); |
| | | |
| | | // 非7号堆垛机处理逻辑 |
| | | if (locMast.getCrnNo() != 7) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** 创建缺量DTO */ |
| | | /** |
| | | * 创建缺量DTO |
| | | */ |
| | | private LocDto createShortageDto(OrderDetl orderDetl, double qty) { |
| | | LocDto dto = new LocDto(null, orderDetl.getMatnr(), |
| | | orderDetl.getMaktx(), orderDetl.getBatch(), |
| | | orderDetl.getOrderNo(), qty); |
| | | orderDetl.getMaktx(), orderDetl.getBatch(), |
| | | orderDetl.getOrderNo(), qty); |
| | | dto.setLack(true); |
| | | return dto; |
| | | } |
| | | |
| | | /** 处理普通货位 */ |
| | | /** |
| | | * 处理普通货位 |
| | | */ |
| | | private void processNormalLocation(LocDetl stock, OrderDetl orderDetl, double remaining, |
| | | Set<ExistDto> processedStock, List<LocDto> result) { |
| | | Set<ExistDto> processedStock, List<LocDto> result) { |
| | | ExistDto exist = new ExistDto() |
| | | .setLocNo(stock.getLocNo()) |
| | | .setMatnr(stock.getMatnr()) |
| | | .setBatch(stock.getBatch()); |
| | | .setLocNo(stock.getLocNo()) |
| | | .setMatnr(stock.getMatnr()) |
| | | .setBatch(stock.getBatch()); |
| | | |
| | | if (processedStock.add(exist)) { |
| | | double allocateQty = Math.min(remaining, stock.getAnfme()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** 处理7号堆垛机货位 */ |
| | | /** |
| | | * 处理7号堆垛机货位 |
| | | */ |
| | | private void processCrn7Location(LocMast baseLoc, LocDetl stock, OrderDetl orderDetl, |
| | | double remaining, Set<ExistDto> processedStock, |
| | | List<LocDto> result) { |
| | | double remaining, Set<ExistDto> processedStock, |
| | | List<LocDto> result) { |
| | | // 构建查询条件 |
| | | EntityWrapper<LocMast> wrapper = (EntityWrapper<LocMast>) new EntityWrapper<LocMast>() |
| | | .eq("gro1", baseLoc.getGro1()) |
| | | .eq("crn_no", 7) |
| | | .eq("loc_type1", baseLoc.getLocType1()) |
| | | .orderBy("bay1", (baseLoc.getBay1() == 6 || baseLoc.getBay1() == 5)); |
| | | .eq("gro1", baseLoc.getGro1()) |
| | | .eq("crn_no", 7) |
| | | .eq("loc_type1", baseLoc.getLocType1()) |
| | | .orderBy("bay1", (baseLoc.getBay1() == 6 || baseLoc.getBay1() == 5)); |
| | | |
| | | // 获取同组货位并处理 |
| | | locMastService.selectList(wrapper).stream() |
| | | .filter(loc -> "F".equals(loc.getLocSts())) |
| | | .forEach(loc -> processCrn7SubLocation(loc, stock, orderDetl, remaining, processedStock, result)); |
| | | .filter(loc -> "F".equals(loc.getLocSts())) |
| | | .forEach(loc -> processCrn7SubLocation(loc, stock, orderDetl, remaining, processedStock, result)); |
| | | } |
| | | |
| | | /** 处理7号堆垛机子货位 */ |
| | | /** |
| | | * 处理7号堆垛机子货位 |
| | | */ |
| | | private void processCrn7SubLocation(LocMast loc, LocDetl stock, OrderDetl orderDetl, |
| | | double remaining, Set<ExistDto> processedStock, |
| | | List<LocDto> result) { |
| | | double remaining, Set<ExistDto> processedStock, |
| | | List<LocDto> result) { |
| | | LocDetl subStock = locDetlService.selectOne( |
| | | new EntityWrapper<LocDetl>() |
| | | .eq("loc_No", loc.getLocNo()) |
| | | .eq("matnr", stock.getMatnr()) |
| | | .eq("batch", stock.getBatch())); |
| | | new EntityWrapper<LocDetl>() |
| | | .eq("loc_No", loc.getLocNo()) |
| | | .eq("matnr", stock.getMatnr()) |
| | | .eq("batch", stock.getBatch())); |
| | | |
| | | if (!Cools.isEmpty(subStock)) { |
| | | ExistDto exist = new ExistDto() |
| | | .setLocNo(subStock.getLocNo()) |
| | | .setMatnr(subStock.getMatnr()) |
| | | .setBatch(subStock.getBatch()); |
| | | .setLocNo(subStock.getLocNo()) |
| | | .setMatnr(subStock.getMatnr()) |
| | | .setBatch(subStock.getBatch()); |
| | | |
| | | if (processedStock.add(exist) && remaining > 0) { |
| | | double allocateQty = Math.min(remaining, subStock.getAnfme()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** 构建货位DTO通用方法 */ |
| | | /** |
| | | * 构建货位DTO通用方法 |
| | | */ |
| | | private LocDto buildLocDto(LocDetl stock, OrderDetl orderDetl, double qty) { |
| | | LocDto dto = new LocDto( |
| | | stock.getLocNo(), stock.getMatnr(), stock.getMaktx(), |
| | | stock.getBatch(), orderDetl.getOrderNo(), qty |
| | | stock.getLocNo(), stock.getMatnr(), stock.getMaktx(), |
| | | stock.getBatch(), orderDetl.getOrderNo(), qty |
| | | ); |
| | | |
| | | // 获取工作站并转换 |
| | | List<Integer> staNos = staDescService.queryOutStaNosByLocNo( |
| | | stock.getLocNo(), qty >= stock.getAnfme() ? 101 : 103); |
| | | stock.getLocNo(), qty >= stock.getAnfme() ? 101 : 103); |
| | | |
| | | List<LocDto.staListDto> staList = staNos.stream() |
| | | .map(staNo -> new LocDto.staListDto() |
| | | .setStaNo(staNo) |
| | | .setStaName(Utils.getStaName(staNo))) |
| | | .collect(Collectors.toList()); |
| | | .map(staNo -> new LocDto.staListDto() |
| | | .setStaNo(staNo) |
| | | .setStaName(Utils.getStaName(staNo))) |
| | | .collect(Collectors.toList()); |
| | | |
| | | dto.setStaNos(staList); |
| | | return dto; |
| | |
| | | // } |
| | | |
| | | |
| | | /** 四向库订单出库 **/ |
| | | /** |
| | | * 四向库订单出库 |
| | | **/ |
| | | @PostMapping("/out/pakout/previewCustomQuantity/auth/sxk") |
| | | @ManagerAuth |
| | | public R pakoutPreviewCustomQuantitySXK(@RequestBody JSONObject jsonObject) { |
| | |
| | | } |
| | | issued = amount; |
| | | } |
| | | if (issued <= 0.0D) { continue; } |
| | | if (issued <= 0.0D) { |
| | | continue; |
| | | } |
| | | List<LocDetl> locDetls = new ArrayList<>(); |
| | | locDetls = locDetlService.queryStockFour(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist,orderDetl.getSupp(),orderDetl.getTemp1(),orderDetl.getTemp2()); |
| | | locDetls = locDetlService.queryStockFour(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist, orderDetl.getSupp(), orderDetl.getTemp1(), orderDetl.getTemp2()); |
| | | for (LocDetl locDetl : locDetls) { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetl.getLocNo())); |
| | | if (locMast.getLocSts().equals("F")){ |
| | | if (locMast.getLocSts().equals("F")) { |
| | | LocDetl locDetl1 = locDetlService.selectOne(new EntityWrapper<LocDetl>() |
| | | .eq("loc_No", locMast.getLocNo()) |
| | | .eq("matnr", locDetl.getMatnr()).eq("batch", locDetl.getBatch())); |
| | |
| | | existDto.setLocNo(locDetl1.getLocNo()); |
| | | existDto.setMatnr(locDetl1.getMatnr()); |
| | | existDto.setBatch(locDetl1.getBatch()); |
| | | if (existDtos.add(existDto)){ |
| | | if (existDtos.add(existDto)) { |
| | | if (issued > 0) { |
| | | LocDto locDto = new LocDto(locDetl1.getLocNo(), locDetl1.getMatnr(), locDetl1.getMaktx(), locDetl1.getBatch(), orderDetl.getOrderNo(), |
| | | issued >= locDetl1.getAnfme() ? locDetl1.getAnfme() : issued); |
| | |
| | | locDtos.add(locDto); |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | }else { |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | |
| | | |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | if (issued <= 0.0D) { continue; } |
| | | if (issued <= 0.0D) { |
| | | continue; |
| | | } |
| | | List<LocDetl> locDetls = new ArrayList<>(); |
| | | locDetls = locDetlService.queryStockFour(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist,orderDetl.getSupp(),orderDetl.getTemp1(),orderDetl.getTemp2()); |
| | | locDetls = locDetlService.queryStockFour(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist, orderDetl.getSupp(), orderDetl.getTemp1(), orderDetl.getTemp2()); |
| | | for (LocDetl locDetl : locDetls) { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetl.getLocNo())); |
| | | if (locMast.getLocSts().equals("F")){ |
| | | if (locMast.getLocSts().equals("F")) { |
| | | LocDetl locDetl1 = locDetlService.selectOne(new EntityWrapper<LocDetl>() |
| | | .eq("loc_No", locMast.getLocNo()) |
| | | .eq("matnr", locDetl.getMatnr()).eq("batch", locDetl.getBatch())); |
| | |
| | | existDto.setLocNo(locDetl1.getLocNo()); |
| | | existDto.setMatnr(locDetl1.getMatnr()); |
| | | existDto.setBatch(locDetl1.getBatch()); |
| | | if (existDtos.add(existDto)){ |
| | | if (existDtos.add(existDto)) { |
| | | if (issued > 0) { |
| | | LocDto locDto = new LocDto(locDetl1.getLocNo(), locDetl1.getMatnr(), locDetl1.getMaktx(), locDetl1.getBatch(), orderDetl.getOrderNo(), |
| | | issued >= locDetl1.getAnfme() ? locDetl1.getAnfme() : issued); |
| | |
| | | locDtos.add(locDto); |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | }else { |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | |
| | | return R.ok().add(locDtos); |
| | | } |
| | | |
| | | /** ctu订单出库 **/ |
| | | /** |
| | | * ctu订单出库 |
| | | **/ |
| | | @PostMapping("/out/pakout/previewCustomQuantity/auth/ctu") |
| | | @ManagerAuth |
| | | public R pakoutPreviewCustomQuantityCTU(@RequestBody JSONObject jsonObject) { |
| | |
| | | } |
| | | issued = amount; |
| | | } |
| | | if (issued <= 0.0D) { continue; } |
| | | if (issued <= 0.0D) { |
| | | continue; |
| | | } |
| | | List<LocDetl> locDetls = new ArrayList<>(); |
| | | locDetls = locDetlService.queryStockMinAnfme(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist,orderDetl.getSupp(),orderDetl.getTemp1(),orderDetl.getTemp2()); |
| | | locDetls = locDetlService.queryStockMinAnfme(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist, orderDetl.getSupp(), orderDetl.getTemp1(), orderDetl.getTemp2()); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | ExistDto existDto = new ExistDto(); |
| | |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | } |
| | | }else { |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | |
| | | |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | if (issued <= 0.0D) { continue; } |
| | | if (issued <= 0.0D) { |
| | | continue; |
| | | } |
| | | List<LocDetl> locDetls = new ArrayList<>(); |
| | | locDetls = locDetlService.queryStockMinAnfme(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist,orderDetl.getSupp(),orderDetl.getTemp1(),orderDetl.getTemp2()); |
| | | locDetls = locDetlService.queryStockMinAnfme(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist, orderDetl.getSupp(), orderDetl.getTemp1(), orderDetl.getTemp2()); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | ExistDto existDto = new ExistDto(); |
| | |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | } |
| | | }else { |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | |
| | | return R.ok().add(locDtos); |
| | | } |
| | | |
| | | /** crn订单出库 **/ |
| | | /** |
| | | * crn订单出库 |
| | | **/ |
| | | @PostMapping("/out/pakout/previewCustomQuantity/auth/crn") |
| | | @ManagerAuth |
| | | public R pakoutPreviewCustomQuantityCRN(@RequestBody JSONObject jsonObject) { |
| | |
| | | } |
| | | issued = amount; |
| | | } |
| | | if (issued <= 0.0D) { continue; } |
| | | if (issued <= 0.0D) { |
| | | continue; |
| | | } |
| | | List<LocDetl> locDetls = new ArrayList<>(); |
| | | locDetls = locDetlService.queryStockCrn(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist,orderDetl.getSupp(),orderDetl.getTemp1(),orderDetl.getTemp2()); |
| | | locDetls = locDetlService.queryStockCrn(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist, orderDetl.getSupp(), orderDetl.getTemp1(), orderDetl.getTemp2()); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | ExistDto existDto = new ExistDto(); |
| | |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | } |
| | | }else { |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | |
| | | |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | if (issued <= 0.0D) { continue; } |
| | | if (issued <= 0.0D) { |
| | | continue; |
| | | } |
| | | List<LocDetl> locDetls = new ArrayList<>(); |
| | | locDetls = locDetlService.queryStockCrn(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist,orderDetl.getSupp(),orderDetl.getTemp1(),orderDetl.getTemp2()); |
| | | locDetls = locDetlService.queryStockCrn(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist, orderDetl.getSupp(), orderDetl.getTemp1(), orderDetl.getTemp2()); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | ExistDto existDto = new ExistDto(); |
| | |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | } |
| | | }else { |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @PostMapping("/out/pakout/auth") |
| | | @ManagerAuth(memo = "订单出库") |
| | | public synchronized R pakout(@RequestBody List<LocDto> locDtos) throws InterruptedException { |
| | |
| | | boolean lack = true; |
| | | for (LocDto locDto : locDtos) { |
| | | // 判断入库模式 |
| | | OutStockInterceptUtil.outStockIntercept(locDto.getStaNo()); |
| | | //OutStockInterceptUtil.outStockIntercept(locDto.getStaNo()); |
| | | if (!locDto.isLack()) { |
| | | lack = false; |
| | | break; |
| | |
| | | List<TaskDto> taskDtos = new ArrayList<>(); |
| | | // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务 |
| | | for (LocDto locDto : locDtos) { |
| | | if (locDto.isLack()) { continue; } |
| | | if (locDto.isLack()) { |
| | | continue; |
| | | } |
| | | TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getStaNo(), locDto); |
| | | if (TaskDto.has(taskDtos, taskDto)) { |
| | | TaskDto dto = TaskDto.find(taskDtos, taskDto); |
| | |
| | | boolean lack = true; |
| | | for (LocDto locDto : locDtos) { |
| | | // 判断入库模式 |
| | | OutStockInterceptUtil.outStockIntercept(locDto.getStaNo()); |
| | | //OutStockInterceptUtil.outStockIntercept(locDto.getStaNo()); |
| | | if (!locDto.isLack()) { |
| | | lack = false; |
| | | break; |
| | |
| | | List<TaskDto> taskDtos = new ArrayList<>(); |
| | | // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务 |
| | | for (LocDto locDto : locDtos) { |
| | | if (locDto.isLack()) { continue; } |
| | | if (locDto.isLack()) { |
| | | continue; |
| | | } |
| | | TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getStaNo(), locDto); |
| | | if (TaskDto.has(taskDtos, taskDto)) { |
| | | TaskDto dto = TaskDto.find(taskDtos, taskDto); |