| | |
| | | package com.zy.asrs.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.entity.param.StockOutParam; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | import java.util.*; |
| | | |
| | | public class OutboundAllocationUtil { |
| | | // public static void main(String[] args) { |
| | | // List<Integer> STA_WORK_CU = new ArrayList<Integer>() {{ |
| | | // add(101);add(102);add(104);add(105);add(107);add(108); |
| | | // add(111);add(1202);add(1104);add(33105);add(1307);add(108); |
| | | // }}; |
| | | // List<Integer> integersStaArr = new ArrayList<>(); |
| | | // List<int[]> stalistArr = new ArrayList<>(); |
| | | // for(Integer staNo : STA_WORK_CU){ |
| | | // int selectCount = staNo*2; |
| | | // if (staNo == 111){ |
| | | // selectCount = 9999999; |
| | | // } |
| | | // stalistArr.add(new int[]{staNo, selectCount}); |
| | | // } |
| | | // |
| | | //// 按selectCount降序排序(最大的排第一位) |
| | | // Collections.sort(stalistArr, (a, b) -> b[1] - a[1]); // 降序排列 |
| | | //// 如果您需要转为数组(可选) |
| | | // for (int[] staNowArr : stalistArr){ |
| | | // integersStaArr.add(staNowArr[0]); |
| | | // } |
| | | // System.out.println(JSON.toJSONString(integersStaArr)); |
| | | // } |
| | | public static void main(String[] args) { |
| | | int numLanes = 3; |
| | | int numWarehouses = 2; |
| | | List<Integer> goods = new ArrayList<>(); |
| | | |
| | | // Generate random goods// 生成随机货物数量 |
| | | Random random = new Random(); |
| | | for (int i = 0; i < numLanes; i++) { |
| | | int goodsCount = random.nextInt(10) + 1; // Randomly generate goods count (1-10)// 随机生成货物数量 (1-10) |
| | | goods.add(goodsCount); |
| | | int[] staNos =new int[]{118,120,121}; |
| | | List<Integer> integersStaArr = new ArrayList<>(); |
| | | List<Long[]> stalistArr = new ArrayList<>(); |
| | | for(Integer staNo : staNos){ |
| | | Date modiTime = new Date(); |
| | | stalistArr.add(new Long[]{staNo.longValue(), modiTime.getTime()-staNo.longValue()}); |
| | | } |
| | | int[] warehouses = distributeGoods(numLanes, numWarehouses,goods); |
| | | System.out.println(JSON.toJSONString(stalistArr)); |
| | | |
| | | if (!stalistArr.isEmpty() && stalistArr.size()>1){ |
| | | // Collections.sort(stalistArr, (a, b) -> a[1] - b[1]); // 降序排列 |
| | | |
| | | System.out.println("Goods distribution:");//货物分配情况 |
| | | for (int i = 0; i < numWarehouses; i++) { |
| | | System.out.println("Warehouse " + (i + 1) + ": " + warehouses[i] + " goods"); |
| | | Collections.sort(stalistArr, Comparator.comparingLong(arr -> arr[1])); |
| | | for (Long[] staNowArr : stalistArr){ |
| | | integersStaArr.add(staNowArr[0].intValue()); |
| | | } |
| | | } |
| | | System.out.println(JSON.toJSONString(integersStaArr)); |
| | | |
| | | int[] warehouses2 = distributeGoods2(numLanes, numWarehouses,goods); |
| | | |
| | | System.out.println("Goods distribution2:");//货物分配情况 |
| | | for (int i = 0; i < numWarehouses; i++) { |
| | | System.out.println("Warehouse " + (i + 1) + ": " + warehouses2[i] + " goods"); |
| | | } |
| | | |
| | | int totalItems = 1000; // 替换为实际的出库箱子数量 |
| | | distributeItemsToTrucks(totalItems); |
| | | } |
| | | // public static void main(String[] args) { |
| | | // int numLanes = 3; |
| | | // int numWarehouses = 2; |
| | | // List<Integer> goods = new ArrayList<>(); |
| | | // |
| | | // // Generate random goods// 生成随机货物数量 |
| | | // Random random = new Random(); |
| | | // for (int i = 0; i < numLanes; i++) { |
| | | // int goodsCount = random.nextInt(10) + 1; // Randomly generate goods count (1-10)// 随机生成货物数量 (1-10) |
| | | // goods.add(goodsCount); |
| | | // } |
| | | // int[] warehouses = distributeGoods(numLanes, numWarehouses,goods); |
| | | // |
| | | // |
| | | // System.out.println("Goods distribution:");//货物分配情况 |
| | | // for (int i = 0; i < numWarehouses; i++) { |
| | | // System.out.println("Warehouse " + (i + 1) + ": " + warehouses[i] + " goods"); |
| | | // } |
| | | // |
| | | // int[] warehouses2 = distributeGoods2(numLanes, numWarehouses,goods); |
| | | // |
| | | // System.out.println("Goods distribution2:");//货物分配情况 |
| | | // for (int i = 0; i < numWarehouses; i++) { |
| | | // System.out.println("Warehouse " + (i + 1) + ": " + warehouses2[i] + " goods"); |
| | | // } |
| | | // |
| | | // int totalItems = 1000; // 替换为实际的出库箱子数量 |
| | | // distributeItemsToTrucks(totalItems); |
| | | // } |
| | | |
| | | public static int[] distributeGoods(int numLanes, int numWarehouses,List<Integer> goods) { |
| | | int[] warehouses = new int[numWarehouses]; |
| | |
| | | List<StockOutParam.LocDetl> locDetls = param.getLocDetls(); |
| | | List<String> brands = new ArrayList<>(); |
| | | for (StockOutParam.LocDetl locDetl:locDetls){ |
| | | if (Cools.isEmpty(locDetl.getBrand())){ |
| | | locDetl.setBrand(""); |
| | | } |
| | | if (!brands.contains(locDetl.getBrand())){ |
| | | brands.add(locDetl.getBrand()); |
| | | } |
| | |
| | | List<StockOutParam.LocDetl> locDetls5 = new ArrayList<>(); |
| | | List<StockOutParam.LocDetl> locDetls6 = new ArrayList<>(); |
| | | for (StockOutParam.LocDetl locDetl:locDetls){ |
| | | if (Cools.isEmpty(locDetl.getBrand())){ |
| | | locDetl.setBrand(""); |
| | | } |
| | | if (locDetl.getBrand().equals(brand)){ |
| | | switch (Utils.getRow(locDetl.getLocNo())){ |
| | | case 1: case 2: case 3: case 4: |
| | |
| | | |
| | | int sign = 0; |
| | | int staA=118; |
| | | int staB=119; |
| | | int staB=118; |
| | | for (List<StockOutParam.LocDetl> locDetlList:lists){ |
| | | sign++; |
| | | if (locDetlList.size()==0){ |
| | | continue; |
| | | } |
| | | if (sign>lists.size()/2) { |
| | | //120、121 |
| | | staA=120; |
| | | staB=121; |
| | | } |
| | | List<StockOutParam.LocDetl> locDetlsA = new ArrayList<>(); |
| | | List<StockOutParam.LocDetl> locDetlsB = new ArrayList<>(); |
| | | List<String> locNos = new ArrayList<>(); |
| | | for (StockOutParam.LocDetl locDetl:locDetlList){ |
| | | if (locDetlsA.size()<locDetlList.size()/2){ |
| | | locDetlsA.add(locDetl); |
| | | if (!locNos.contains(locDetl.getLocNo())){ |
| | | locNos.add(locDetl.getLocNo()); |
| | | } |
| | | }else { |
| | | if (locNos.contains(locDetl.getLocNo())){ |
| | | locDetlsA.add(locDetl); |
| | | }else { |
| | | locDetlsB.add(locDetl); |
| | | } |
| | | } |
| | | } |
| | | if (locDetlsA.size()!=0){ |
| | | StockOutParam stockOutParamA = new StockOutParam(); |
| | | stockOutParamA.setOutSite(staA); |
| | | stockOutParamA.setOrderNo(param.getOrderNo()); |
| | | stockOutParamA.setLocDetls(locDetlsA); |
| | | stockOutParams.add(stockOutParamA); |
| | | } |
| | | if (locDetlsB.size()!=0){ |
| | | StockOutParam stockOutParamB = new StockOutParam(); |
| | | stockOutParamB.setOutSite(staB); |
| | | stockOutParamB.setOrderNo(param.getOrderNo()); |
| | | stockOutParamB.setLocDetls(locDetlsB); |
| | | stockOutParams.add(stockOutParamB); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return stockOutParams; |
| | | } |
| | | |
| | | public static List<StockOutParam> OutboundClassificationNew(StockOutParam param){ |
| | | List<StockOutParam> stockOutParams = new ArrayList<>(); |
| | | |
| | | List<StockOutParam.LocDetl> locDetls = param.getLocDetls(); |
| | | List<String> brands = new ArrayList<>(); |
| | | for (StockOutParam.LocDetl locDetl:locDetls){ |
| | | if (Cools.isEmpty(locDetl.getBrand())){ |
| | | locDetl.setBrand(""); |
| | | } |
| | | if (!brands.contains(locDetl.getBrand())){ |
| | | brands.add(locDetl.getBrand()); |
| | | } |
| | | } |
| | | |
| | | for (String brand : brands){ |
| | | List<StockOutParam.LocDetl> locDetls1 = new ArrayList<>(); |
| | | List<StockOutParam.LocDetl> locDetls2 = new ArrayList<>(); |
| | | List<StockOutParam.LocDetl> locDetls3 = new ArrayList<>(); |
| | | List<StockOutParam.LocDetl> locDetls4 = new ArrayList<>(); |
| | | List<StockOutParam.LocDetl> locDetls5 = new ArrayList<>(); |
| | | List<StockOutParam.LocDetl> locDetls6 = new ArrayList<>(); |
| | | for (StockOutParam.LocDetl locDetl:locDetls){ |
| | | if (Cools.isEmpty(locDetl.getBrand())){ |
| | | locDetl.setBrand(""); |
| | | } |
| | | if (locDetl.getBrand().equals(brand)){ |
| | | switch (Utils.getRow(locDetl.getLocNo())){ |
| | | case 1: case 2: case 3: case 4: |
| | | locDetls1.add(locDetl); |
| | | break; |
| | | case 5: case 6: case 7: case 8: |
| | | locDetls2.add(locDetl); |
| | | break; |
| | | case 9: case 10: case 11: case 12: |
| | | locDetls3.add(locDetl); |
| | | break; |
| | | case 13: case 14: case 15: case 16: |
| | | locDetls4.add(locDetl); |
| | | break; |
| | | case 17: case 18: case 19: case 20: |
| | | locDetls5.add(locDetl); |
| | | break; |
| | | case 21: case 22: case 23: case 24: |
| | | locDetls6.add(locDetl); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | } |
| | | ArrayList<List<StockOutParam.LocDetl>> lists = new ArrayList<>(); |
| | | lists.add(locDetls1); |
| | | lists.add(locDetls2); |
| | | lists.add(locDetls3); |
| | | lists.add(locDetls4); |
| | | lists.add(locDetls5); |
| | | lists.add(locDetls6); |
| | | |
| | | int sign = 0; |
| | | int staA=118; |
| | | int staB=118; |
| | | for (List<StockOutParam.LocDetl> locDetlList:lists){ |
| | | sign++; |
| | | if (locDetlList.size()==0){ |