|
@@ -730,7 +730,7 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 将总数随机分配到指定数量的流中,允许流的数量为0
|
|
|
+ * 将总数按顺序循环分配到指定数量的流中
|
|
|
* @param total 总数
|
|
|
* @param numStrands 流的数量
|
|
|
* @return 分配结果映射(键为流的名称,值为分配的数量)
|
|
@@ -739,24 +739,23 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
// 初始化每个流分配0个
|
|
|
List<Integer> allocation = new ArrayList<>(Collections.nCopies(numStrands, 0));
|
|
|
|
|
|
- // 随机分配所有数量
|
|
|
- Random random = ThreadLocalRandom.current();
|
|
|
+ // 按顺序循环分配所有数量
|
|
|
for (int i = 0; i < total; i++) {
|
|
|
- // 随机选择一个流增加数量
|
|
|
- int index = random.nextInt(numStrands);
|
|
|
+ // 计算当前应该分配的流索引(循环使用)
|
|
|
+ int index = i % numStrands;
|
|
|
allocation.set(index, allocation.get(index) + 1);
|
|
|
}
|
|
|
|
|
|
// 构建结果映射
|
|
|
Map<String, Integer> result = new HashMap<>();
|
|
|
- result.put("oneStrandSum", allocation.get(0));
|
|
|
- result.put("twoStrandSum", allocation.get(1));
|
|
|
- result.put("threeStrandSum", allocation.get(2));
|
|
|
- result.put("fourStrandSum", allocation.get(3));
|
|
|
- result.put("fiveStrandSum", allocation.get(4));
|
|
|
- result.put("sixStrandSum", allocation.get(5));
|
|
|
- result.put("sevenStrandSum", allocation.get(6));
|
|
|
- result.put("eightStrandSum", allocation.get(7));
|
|
|
+ result.put("oneStrandSum", numStrands > 0 ? allocation.get(0) : 0);
|
|
|
+ result.put("twoStrandSum", numStrands > 1 ? allocation.get(1) : 0);
|
|
|
+ result.put("threeStrandSum", numStrands > 2 ? allocation.get(2) : 0);
|
|
|
+ result.put("fourStrandSum", numStrands > 3 ? allocation.get(3) : 0);
|
|
|
+ result.put("fiveStrandSum", numStrands > 4 ? allocation.get(4) : 0);
|
|
|
+ result.put("sixStrandSum", numStrands > 5 ? allocation.get(5) : 0);
|
|
|
+ result.put("sevenStrandSum", numStrands > 6 ? allocation.get(6) : 0);
|
|
|
+ result.put("eightStrandSum", numStrands > 7 ? allocation.get(7) : 0);
|
|
|
|
|
|
return result;
|
|
|
}
|