| | |
| | | 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.BasDevp; |
| | | import com.zy.asrs.entity.LocDetl; |
| | | import com.zy.asrs.entity.LocMast; |
| | |
| | | return R.ok().add(orderDetlService.selectByOrderId(orderId).stream().map(OrderDetl::getId).distinct().collect(Collectors.toList())); |
| | | } |
| | | |
| | | @PostMapping("/out/pakout/OrderOutGetLoc/auth") |
| | | @ManagerAuth |
| | | public R OrderOutGetLoc(@RequestBody List<Long> ids) { |
| | | if (Cools.isEmpty(ids)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | // 获取订单明细并处理 |
| | | List<OrderDetl> orderDetls = orderDetlService.selectBatchIds(ids); |
| | | Set<String> processedLocs = new HashSet<>(); // 已处理货位缓存 |
| | | Set<ExistDto> processedStock = new HashSet<>(); // 已处理库存缓存 |
| | | List<LocDto> result = new ArrayList<>(); |
| | | |
| | | for (OrderDetl detl : orderDetls) { |
| | | result.addAll(processOrderDetl(detl, null, processedLocs, processedStock)); |
| | | } |
| | | |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | /** 处理订单出库货位分配 |
| | | * @param jsonObject 请求参数(包含订单明细ID列表和出库数量) |
| | | */ |
| | | @PostMapping("/out/pakout/OrderOutGetLoc.number/auth") |
| | | @ManagerAuth |
| | | public R OrderOutGetLocNumber(@RequestBody JSONObject jsonObject) { |
| | | // 参数校验 |
| | | if (!jsonObject.containsKey("ids") || !jsonObject.containsKey("amount")) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | |
| | | // 提取并转换参数 |
| | | List<Long> ids = jsonObject.getJSONArray("ids").toJavaList(Long.class); |
| | | Double amount = jsonObject.getDouble("amount"); |
| | | |
| | | |
| | | // 获取订单明细并处理 |
| | | List<OrderDetl> orderDetls = orderDetlService.selectBatchIds(ids); |
| | | Set<String> processedLocs = new HashSet<>(); // 已处理货位缓存 |
| | | Set<ExistDto> processedStock = new HashSet<>(); // 已处理库存缓存 |
| | | List<LocDto> result = new ArrayList<>(); |
| | | |
| | | for (OrderDetl detl : orderDetls) { |
| | | result.addAll(processOrderDetl(detl, amount, processedLocs, processedStock)); |
| | | } |
| | | |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | /** |
| | | * 处理单个订单明细的货位分配 |
| | | * @param orderDetl 订单明细 |
| | | * @param requiredAmount 需求出库量 |
| | | * @param processedLocs 已处理的货位集合(用于去重) |
| | | * @param processedStock 已处理的库存记录集合(用于去重) |
| | | */ |
| | | private List<LocDto> processOrderDetl(OrderDetl orderDetl, Double requiredAmount, |
| | | Set<String> processedLocs, Set<ExistDto> processedStock) { |
| | | List<LocDto> result = new ArrayList<>(); |
| | | double remaining = Optional.ofNullable(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | |
| | | // 调整校验逻辑:当requiredAmount不为null时才校验 |
| | | if (requiredAmount != null) { |
| | | if (requiredAmount <= 0) { |
| | | throw new CoolException("出库数量必须大于0"); |
| | | } |
| | | if (requiredAmount > 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() |
| | | ); |
| | | |
| | | // 遍历处理每个库存记录 |
| | | for (LocDetl stock : stocks) { |
| | | if (remaining <= 0) break; |
| | | |
| | | LocMast locMast = locMastService.selectOne( |
| | | new EntityWrapper<LocMast>().eq("loc_no", stock.getLocNo())); |
| | | |
| | | // 非7号堆垛机处理逻辑 |
| | | if (locMast.getCrnNo() != 7) { |
| | | processNormalLocation(stock, orderDetl, remaining, processedStock, result); |
| | | } |
| | | // 7号堆垛机特殊处理 |
| | | else { |
| | | processCrn7Location(locMast, stock, orderDetl, remaining, processedStock, result); |
| | | } |
| | | |
| | | remaining -= stock.getAnfme(); |
| | | } |
| | | |
| | | // 处理缺量情况 |
| | | if (remaining > 0) { |
| | | result.add(createShortageDto(orderDetl, remaining)); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** 创建缺量DTO */ |
| | | private LocDto createShortageDto(OrderDetl orderDetl, double qty) { |
| | | LocDto dto = new LocDto(null, orderDetl.getMatnr(), |
| | | 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) { |
| | | ExistDto exist = new ExistDto() |
| | | .setLocNo(stock.getLocNo()) |
| | | .setMatnr(stock.getMatnr()) |
| | | .setBatch(stock.getBatch()); |
| | | |
| | | if (processedStock.add(exist)) { |
| | | double allocateQty = Math.min(remaining, stock.getAnfme()); |
| | | result.add(buildLocDto(stock, orderDetl, allocateQty)); |
| | | } |
| | | } |
| | | |
| | | /** 处理7号堆垛机货位 */ |
| | | private void processCrn7Location(LocMast baseLoc, LocDetl stock, OrderDetl orderDetl, |
| | | 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)); |
| | | |
| | | // 获取同组货位并处理 |
| | | locMastService.selectList(wrapper).stream() |
| | | .filter(loc -> "F".equals(loc.getLocSts())) |
| | | .forEach(loc -> processCrn7SubLocation(loc, stock, orderDetl, remaining, processedStock, result)); |
| | | } |
| | | |
| | | /** 处理7号堆垛机子货位 */ |
| | | private void processCrn7SubLocation(LocMast loc, LocDetl stock, OrderDetl orderDetl, |
| | | 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())); |
| | | |
| | | if (!Cools.isEmpty(subStock)) { |
| | | ExistDto exist = new ExistDto() |
| | | .setLocNo(subStock.getLocNo()) |
| | | .setMatnr(subStock.getMatnr()) |
| | | .setBatch(subStock.getBatch()); |
| | | |
| | | if (processedStock.add(exist) && remaining > 0) { |
| | | double allocateQty = Math.min(remaining, subStock.getAnfme()); |
| | | result.add(buildLocDto(subStock, orderDetl, allocateQty)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** 构建货位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 |
| | | ); |
| | | |
| | | // 获取工作站并转换 |
| | | List<Integer> staNos = staDescService.queryOutStaNosByLocNo( |
| | | 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()); |
| | | |
| | | dto.setStaNos(staList); |
| | | return dto; |
| | | } |
| | | |
| | | // 新增方法 |
| | | // private List<LocDto> processOrderDetl(OrderDetl orderDetl, Double amount, Set<String> exist, Set<ExistDto> existDtos) { |
| | | // List<LocDto> result = new ArrayList<>(); |
| | | // double issued = Optional.ofNullable(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | // |
| | | // if (amount != null && amount > issued) { |
| | | // throw new CoolException("数量高于可出库数量"); |
| | | // } |
| | | // |
| | | // List<LocDetl> locDetls = locDetlService.queryStockCrn(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist, orderDetl.getSupp(), orderDetl.getTemp1(), orderDetl.getTemp2()); |
| | | // for (LocDetl locDetl : locDetls) { |
| | | // if (issued <= 0) break; |
| | | // LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetl.getLocNo())); |
| | | // if (locMast.getCrnNo() != 7) { |
| | | // ExistDto existDto = new ExistDto(); |
| | | // existDto.setLocNo(locDetl.getLocNo()); |
| | | // existDto.setMatnr(locDetl.getMatnr()); |
| | | // existDto.setBatch(locDetl.getBatch()); |
| | | // if (existDtos.add(existDto)) { |
| | | // LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), |
| | | // issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued); |
| | | // List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), issued >= locDetl.getAnfme() ? 101 : 103); |
| | | // List<LocDto.staListDto> maps = new ArrayList<>(); |
| | | // for (Integer staNo : staNos) { |
| | | // LocDto.staListDto staListDto = new LocDto.staListDto(); |
| | | // staListDto.setStaNo(staNo); |
| | | // staListDto.setStaName(Utils.getStaName(staNo)); |
| | | // maps.add(staListDto); |
| | | // } |
| | | // locDto.setStaNos(maps); |
| | | // result.add(locDto); |
| | | // // 剩余待出数量递减 |
| | | // issued = issued - locDetl.getAnfme(); |
| | | // } |
| | | // }else { |
| | | // List<LocMast> locMasts = new ArrayList<>(); |
| | | // if (locMast.getBay1() ==6 || locMast.getBay1()==5){ |
| | | // locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | // .eq("gro1", locMast.getGro1()) |
| | | // .eq("crn_no", 7) |
| | | // .eq("loc_type1",locMast.getLocType1()) |
| | | // .orderBy("bay1", true)); |
| | | // }else{ |
| | | // locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | // .eq("gro1", locMast.getGro1()) |
| | | // .eq("crn_no", 7) |
| | | // .eq("loc_type1",locMast.getLocType1()) |
| | | // .orderBy("bay1", false)); |
| | | // } |
| | | // for (LocMast locMast1 : locMasts){ |
| | | // if (locMast1.getLocSts().equals("F")){ |
| | | // LocDetl locDetl1 = locDetlService.selectOne(new EntityWrapper<LocDetl>() |
| | | // .eq("loc_No", locMast1.getLocNo()) |
| | | // .eq("matnr", locDetl.getMatnr()).eq("batch", locDetl.getBatch())); |
| | | // if (!Cools.isEmpty(locDetl1)) { |
| | | // ExistDto existDto = new ExistDto(); |
| | | // existDto.setLocNo(locDetl1.getLocNo()); |
| | | // existDto.setMatnr(locDetl1.getMatnr()); |
| | | // existDto.setBatch(locDetl1.getBatch()); |
| | | // if (existDtos.add(existDto)){ |
| | | // if (issued <= 0) break; |
| | | // LocDto locDto = new LocDto(locDetl1.getLocNo(), locDetl1.getMatnr(), locDetl1.getMaktx(), locDetl1.getBatch(), orderDetl.getOrderNo(), |
| | | // issued >= locDetl1.getAnfme() ? locDetl1.getAnfme() : issued); |
| | | // List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl1.getLocNo(), issued >= locDetl1.getAnfme() ? 101 : 103); |
| | | // List<LocDto.staListDto> maps = new ArrayList<>(); |
| | | // for (Integer staNo : staNos) { |
| | | // LocDto.staListDto staListDto = new LocDto.staListDto(); |
| | | // staListDto.setStaNo(staNo); |
| | | // staListDto.setStaName(Utils.getStaName(staNo)); |
| | | // maps.add(staListDto); |
| | | // } |
| | | // locDto.setStaNos(maps); |
| | | // result.add(locDto); |
| | | // // 剩余待出数量递减 |
| | | // issued = issued - locDetl.getAnfme(); |
| | | // |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // if (issued > 0) { |
| | | // LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | // locDto.setLack(Boolean.TRUE); |
| | | // result.add(locDto); |
| | | // } |
| | | // return result; |
| | | // } |
| | | |
| | | |
| | | /** 四向库订单出库 **/ |
| | | @PostMapping("/out/pakout/previewCustomQuantity/auth/sxk") |