mirror of https://github.com/jeecgboot/jeecg-boot
Replace old algo by new algo
parent
0c57d68a12
commit
140997994a
|
@ -154,63 +154,7 @@ public class AddPortraitTubeJob implements Job {
|
|||
* @param orderItems List of order items
|
||||
* @return Set of pairs
|
||||
*/
|
||||
private static Pair<HashSet<Pair<String, Integer>>, HashSet<Pair<String, Integer>>> findCurrentAndAdequateTubes(List<OrderItem> orderItems) {
|
||||
int canvas40Count = 0;
|
||||
int canvas50Count = 0;
|
||||
HashSet<Pair<String, Integer>> currentTubes = new HashSet<>();
|
||||
HashSet<Pair<String, Integer>> adequateTubes = new HashSet<>();
|
||||
for (OrderItem orderItem : orderItems) {
|
||||
String sku = orderItem.getErpCode();
|
||||
int quantity = orderItem.getQuantity();
|
||||
if (TUBE_SKUS.contains(sku)) {
|
||||
currentTubes.add(Pair.of(sku, quantity));
|
||||
} else if (sku.startsWith(PREFIX_50_CANVAS)) {
|
||||
canvas50Count += quantity;
|
||||
} else if (sku.startsWith(PREFIX_40_CANVAS)) {
|
||||
canvas40Count += quantity;
|
||||
} else if (sku.startsWith(PREFIX_30_CANVAS)) {
|
||||
canvas40Count += quantity;
|
||||
}
|
||||
}
|
||||
|
||||
int canvas40RemainderCount = canvas40Count % MAXIMUM_CANVAS_IN_TUBE.intValue();
|
||||
int canvas50RemainderCount = canvas50Count % MAXIMUM_CANVAS_IN_TUBE.intValue();
|
||||
int tube50SingleCount = 0;
|
||||
int tube50MultipleCount = (int) Math.floor(canvas50Count / MAXIMUM_CANVAS_IN_TUBE);
|
||||
int tube40SingleCount = 0;
|
||||
int tube40MultipleCount = (int) Math.floor(canvas40Count / MAXIMUM_CANVAS_IN_TUBE);
|
||||
if (canvas50RemainderCount > 0 && canvas40RemainderCount > 0) {
|
||||
tube50MultipleCount++;
|
||||
if (canvas50RemainderCount == 2 && canvas40RemainderCount == 2) {
|
||||
tube50SingleCount++;
|
||||
}
|
||||
} else {
|
||||
if (canvas40RemainderCount == 1) {
|
||||
tube40SingleCount++;
|
||||
} else if (canvas40RemainderCount == 2) {
|
||||
tube40MultipleCount++;
|
||||
} else if (canvas50RemainderCount == 1) {
|
||||
tube50SingleCount++;
|
||||
} else if (canvas50RemainderCount == 2) {
|
||||
tube50MultipleCount++;
|
||||
}
|
||||
}
|
||||
if (tube50SingleCount > 0) {
|
||||
adequateTubes.add(Pair.of(TUBE_50_SKU_SINGLE, tube50SingleCount));
|
||||
}
|
||||
if (tube50MultipleCount > 0) {
|
||||
adequateTubes.add(Pair.of(TUBE_50_SKU_MULTIPLE, tube50MultipleCount));
|
||||
}
|
||||
if (tube40SingleCount > 0) {
|
||||
adequateTubes.add(Pair.of(TUBE_40_SKU_SINGLE, tube40SingleCount));
|
||||
}
|
||||
if (tube40MultipleCount > 0) {
|
||||
adequateTubes.add(Pair.of(TUBE_40_SKU_MULTIPLE, tube40MultipleCount));
|
||||
}
|
||||
return Pair.of(currentTubes, adequateTubes);
|
||||
}
|
||||
|
||||
private static Pair<HashSet<Pair<String, Integer>>, HashSet<Pair<String, Integer>>> newFindCurrentAndAdequateTubes(List<OrderItem> orderItems) {
|
||||
private Pair<HashSet<Pair<String, Integer>>, HashSet<Pair<String, Integer>>> findCurrentAndAdequateTubes(List<OrderItem> orderItems) {
|
||||
int canvas30Count = 0;
|
||||
int canvas40Count = 0;
|
||||
int canvas50Count = 0;
|
||||
|
@ -311,118 +255,4 @@ public class AddPortraitTubeJob implements Job {
|
|||
}
|
||||
return Pair.of(currentTubes, adequateTubes);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<OrderItem> orderItems = buildOrderItems(0,0,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(0,0,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(0,0,2);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(0,1,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(0,1,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(0,1,2);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(0,2,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(0,2,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(0,2,2);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,0,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,0,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,0,2);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,1,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,1,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,1,2);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,2,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,2,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(1,2,2);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,0,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,0,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,0,2);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,1,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,1,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,1,2);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,2,0);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,2,1);
|
||||
compare(orderItems);
|
||||
|
||||
orderItems = buildOrderItems(2,2,2);
|
||||
compare(orderItems);
|
||||
}
|
||||
|
||||
private static void compare(List<OrderItem> orderItems) {
|
||||
HashSet<Pair<String, Integer>> tubesOldWay = findCurrentAndAdequateTubes(orderItems).getRight();
|
||||
HashSet<Pair<String, Integer>> tubesNewWay = newFindCurrentAndAdequateTubes(orderItems).getRight();
|
||||
System.out.println("old way : " + tubesOldWay);
|
||||
System.out.println("new way : " + tubesNewWay);
|
||||
System.out.println(tubesOldWay.containsAll(tubesNewWay) && tubesNewWay.containsAll(tubesOldWay) ? "we're good" : "shit");
|
||||
}
|
||||
|
||||
private static List<OrderItem> buildOrderItems(Integer canvas30q, Integer canvas40q, Integer canvas50q) {
|
||||
List<OrderItem> orderItems = new ArrayList<>();
|
||||
if (canvas30q != null) {
|
||||
orderItems.add(buildOrderItem(PREFIX_30_CANVAS, canvas30q));
|
||||
}
|
||||
if (canvas40q != null) {
|
||||
orderItems.add(buildOrderItem(PREFIX_40_CANVAS, canvas40q));
|
||||
}
|
||||
if (canvas50q != null) {
|
||||
orderItems.add(buildOrderItem(PREFIX_50_CANVAS, canvas50q));
|
||||
}
|
||||
System.out.println(canvas30q + " x 30cm " + canvas40q + " x 40cm " + canvas50q + " x 50cm");
|
||||
return orderItems;
|
||||
}
|
||||
|
||||
private static OrderItem buildOrderItem(String erpCode, Integer quantity) {
|
||||
OrderItem orderItem = new OrderItem();
|
||||
orderItem.setErpCode(erpCode);
|
||||
orderItem.setQuantity(quantity);
|
||||
return orderItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue