diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java index 20bd002..0ecdc89 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java @@ -2976,6 +2976,38 @@ public class OrderStatService { return PoiDynamicMarge.createExcel(headers, title, listMap, regions, titleMap); } + private Record margeRecord(Record s1, Record s2, Integer type) { + Record s3 = new Record(); + + int order_num; + int s1_order_num = s1.getInt("order_num") == null ? 0 : s1.getInt("order_num"); + int s2_order_num = s2.getInt("order_num") == null ? 0 : s2.getInt("order_num"); + order_num = s1_order_num + s2_order_num; + + BigDecimal total_price; + BigDecimal s1_total_price = s1.getBigDecimal("total_price") == null ? new BigDecimal(0) : s1.getBigDecimal("total_price"); + BigDecimal s2_total_price = s2.getBigDecimal("total_price") == null ? new BigDecimal(0) : s2.getBigDecimal("total_price"); + total_price = s1_total_price.add(s2_total_price); + + BigDecimal weight; + BigDecimal s1_weight = s1.getBigDecimal("weight") == null ? new BigDecimal(0) : s1.getBigDecimal("weight"); + BigDecimal s2_weight = s2.getBigDecimal("weight") == null ? new BigDecimal(0) : s2.getBigDecimal("weight"); + weight = s1_weight.add(s2_weight); + + s3.set("id", s1.getInt("id")); + if (type != null && type == 1) { + s3.set("name", s1.getStr("name")); + s3.set("product_id", s1.getInt("product_id")); + s3.set("product_name", s1.getStr("product_name")); + } + s3.set("order_num", order_num); + s3.set("total_price", total_price); + s3.set("weight", weight); + + return s3; + } + + /** * [{ * name: '竹瓦', key: '1' @@ -3078,58 +3110,61 @@ public class OrderStatService { // 实售合并 if (shList != null && !shList.isEmpty()) { - List shList2 = new ArrayList<>(); + Map shMap = new HashMap<>(); for (Record s : shList) { int id = s.getInt("id"); int product_id = s.getInt("product_id"); - if ((id == 1 || id == 5 || id == 6 || id == 7 || id == 8 || id == 9) && product_id == 1) { - shList2.add(s); + if ((id == 1 || id == 5 || id == 6 || id == 7 || id == 8 || id == 9 || id == 10) && product_id == 1) { + shMap.put(id, s); } else { shList1.add(s); } } - if (shList2.size() > 1) { - for (Record s1 : shList2) { - boolean flag = false; - for (Record s2 : shList2) { - int s1_id = s1.getInt("id"); - int s2_id = s2.getInt("id"); - if ((s1_id == 1 && s2_id == 7) || (s1_id == 5 && s2_id == 9) ||s1_id == 6 && s2_id == 8) { - flag = true; - Record s3 = new Record(); - - int order_num; - int s1_order_num = s1.getInt("order_num") == null ? 0 : s1.getInt("order_num"); - int s2_order_num = s2.getInt("order_num") == null ? 0 : s2.getInt("order_num"); - order_num = s1_order_num + s2_order_num; - - BigDecimal total_price; - BigDecimal s1_total_price = s1.getBigDecimal("total_price") == null ? new BigDecimal(0) : s1.getBigDecimal("total_price"); - BigDecimal s2_total_price = s2.getBigDecimal("total_price") == null ? new BigDecimal(0) : s2.getBigDecimal("total_price"); - total_price = s1_total_price.add(s2_total_price); - - BigDecimal weight = s1.getBigDecimal("weight").add(s2.getBigDecimal("weight")); - if (weight.compareTo(new BigDecimal(0)) == 0) { - weight = new BigDecimal(0); - } - - s3.set("id", s1_id); - s3.set("name", s1.getStr("name")); - s3.set("product_id", s1.getInt("product_id")); - s3.set("product_name", s1.getStr("product_name")); - s3.set("order_num", order_num); - s3.set("total_price", total_price); - s3.set("weight", weight); - shList1.add(s3); - break; - } - } - if (!flag) { - shList1.add(s1); - } + if (shMap.size() > 1) { + Record s_1 = shMap.get(1); + Record s_5 = shMap.get(5); + Record s_6 = shMap.get(6); + Record s_7 = shMap.get(7); + Record s_8 = shMap.get(8); + Record s_9 = shMap.get(9); + Record s_10 = shMap.get(10); + if (s_1 != null && s_7 != null) { + Record s_1_7 = margeRecord(s_1, s_7, 1); + shList1.add(s_1_7); + shMap.remove(1); + shMap.remove(7); } - } else if (shList2.size() == 1) { - shList1.addAll(shList2); + if (s_5 != null && s_9 != null) { + Record s_5_9 = margeRecord(s_5, s_9, 1); + shList1.add(s_5_9); + shMap.remove(5); + shMap.remove(9); + } + if (s_6 != null && s_8 != null && s_10 == null) { + Record s_6_8 = margeRecord(s_6, s_8, 1); + shList1.add(s_6_8); + shMap.remove(6); + shMap.remove(8); + } + if (s_6 != null && s_8 == null && s_10 != null) { + Record s_6_10 = margeRecord(s_6, s_10, 1); + shList1.add(s_6_10); + shMap.remove(6); + shMap.remove(10); + } + if (s_6 != null && s_8 != null && s_10 != null) { + Record s_8_10 = margeRecord(s_8, s_10, 1); + Record s_6_8_10 = margeRecord(s_6, s_8_10, 1); + shList1.add(s_6_8_10); + shMap.remove(6); + shMap.remove(8); + shMap.remove(10); + } + if (shMap.size() > 0) { + shList1.addAll(shMap.values()); + } + } else if (shMap.size() == 1) { + shList1.addAll(shMap.values()); } } else { for (Record s : sups) { @@ -3146,54 +3181,60 @@ public class OrderStatService { } // 预售合并 if (yhList != null && !yhList.isEmpty()) { - List yhList2 = new ArrayList<>(); + Map yhMap = new HashMap<>(); for (Record s : yhList) { int id = s.getInt("id"); - if (id == 1 || id == 5 || id == 6 || id == 7 || id == 8 || id == 9) { - yhList2.add(s); + if (id == 1 || id == 5 || id == 6 || id == 7 || id == 8 || id == 9 || id == 10) { + yhMap.put(id, s); } else { yhList1.add(s); } } - if (yhList2.size() > 1) { - for (Record s1 : yhList2) { - boolean flag = false; - for (Record s2 : yhList2) { - int s1_id = s1.getInt("id"); - int s2_id = s2.getInt("id"); - if ((s1_id == 1 && s2_id == 7) || (s1_id == 5 && s2_id == 9) || s1_id == 6 && s2_id == 8) { - flag = true; - Record s3 = new Record(); - - int order_num; - int s1_order_num = s1.getInt("order_num") == null ? 0 : s1.getInt("order_num"); - int s2_order_num = s2.getInt("order_num") == null ? 0 : s2.getInt("order_num"); - order_num = s1_order_num + s2_order_num; - - BigDecimal total_price; - BigDecimal s1_total_price = s1.getBigDecimal("total_price") == null ? new BigDecimal(0) : s1.getBigDecimal("total_price"); - BigDecimal s2_total_price = s2.getBigDecimal("total_price") == null ? new BigDecimal(0) : s2.getBigDecimal("total_price"); - total_price = s1_total_price.add(s2_total_price); - - BigDecimal weight = s1.getBigDecimal("weight").add(s2.getBigDecimal("weight")); - if (weight.compareTo(new BigDecimal(0)) == 0) { - weight = new BigDecimal(0); - } - - s3.set("id", s1_id); - s3.set("order_num", order_num); - s3.set("total_price", total_price); - s3.set("weight", weight); - yhList1.add(s3); - break; - } - } - if (!flag) { - yhList1.add(s1); - } + if (yhMap.size() > 1) { + Record s_1 = yhMap.get(1); + Record s_5 = yhMap.get(5); + Record s_6 = yhMap.get(6); + Record s_7 = yhMap.get(7); + Record s_8 = yhMap.get(8); + Record s_9 = yhMap.get(9); + Record s_10 = yhMap.get(10); + if (s_1 != null && s_7 != null) { + Record s_1_7 = margeRecord(s_1, s_7, null); + yhList1.add(s_1_7); + yhMap.remove(1); + yhMap.remove(7); } - } else if(yhList2.size() == 1) { - yhList1.addAll(yhList2); + if (s_5 != null && s_9 != null) { + Record s_5_9 = margeRecord(s_5, s_9, null); + yhList1.add(s_5_9); + yhMap.remove(5); + yhMap.remove(9); + } + if (s_6 != null && s_8 != null && s_10 == null) { + Record s_6_8 = margeRecord(s_6, s_8, null); + yhList1.add(s_6_8); + yhMap.remove(6); + yhMap.remove(8); + } + if (s_6 != null && s_8 == null && s_10 != null) { + Record s_6_10 = margeRecord(s_6, s_10, null); + yhList1.add(s_6_10); + yhMap.remove(6); + yhMap.remove(10); + } + if (s_6 != null && s_8 != null && s_10 != null) { + Record s_8_10 = margeRecord(s_8, s_10, null); + Record s_6_8_10 = margeRecord(s_6, s_8_10, null); + yhList1.add(s_6_8_10); + yhMap.remove(6); + yhMap.remove(8); + yhMap.remove(10); + } + if (yhMap.size() > 0) { + yhList1.addAll(yhMap.values()); + } + } else if(yhMap.size() == 1) { + yhList1.addAll(yhMap.values()); } } else { for (Record s : sups) {