From 1e6ff6923e5475f95044540c1702d70c53e40479 Mon Sep 17 00:00:00 2001 From: xjm Date: Wed, 3 Jan 2024 14:23:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B6=88=E8=B4=B9=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cowr/ssjygl/prepay/PrepayService.java | 3 +- .../ssjygl/stat/sale/OrderStatService.java | 1383 +++++++++-------- 2 files changed, 713 insertions(+), 673 deletions(-) diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/prepay/PrepayService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/prepay/PrepayService.java index 1416648..580ef74 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/prepay/PrepayService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/prepay/PrepayService.java @@ -210,7 +210,8 @@ public class PrepayService { " ,p.order_sn \n" + " ,p.arrive_time \n" + " ,p.type \n" + - " ,a.supermarket_id \n" + + " ,p.second_weight - p.first_weight net_weight\n" + + " ,a.supermarket_id \n" + " ,s.`name` supermarket_name \n" + " ,a.truck_license \n" + " ,a.weight \n" + 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 8a3263f..2b8e096 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 @@ -29,8 +29,8 @@ import java.util.concurrent.Executors; import static com.cowr.common.utils.DateTimeUtil.*; public class OrderStatService { - private static Log log = Log.getLog(OrderStatService.class); - public static OrderStatService me = new OrderStatService(); + private static Log log = Log.getLog(OrderStatService.class); + public static OrderStatService me = new OrderStatService(); /** * 销售日明细 @@ -214,8 +214,8 @@ public class OrderStatService { } }); - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet("销售汇总表"); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet("销售汇总表"); // 副标题 start String subtitle = ""; @@ -241,7 +241,7 @@ public class OrderStatService { // 表头 start Row row = sheet.createRow(2); - int a = 0; + int a = 0; row.createCell(a++).setCellValue("序号"); row.createCell(a++).setCellValue("入场时间"); row.createCell(a++).setCellValue("销售单编号"); @@ -259,11 +259,11 @@ public class OrderStatService { row.createCell(a++).setCellValue("预付费"); // 表头 end - double sum_weight = 0.0; - double sum_price = 0.0; + double sum_weight = 0.0; + double sum_price = 0.0; double isprepaid_sum_price = 0.0; - int datalen = list.size(); - int end_col = sup_name == null ? 11 : 10; + int datalen = list.size(); + int end_col = sup_name == null ? 11 : 10; for (int i = 0; i < datalen; i++) { Record order = list.get(i); @@ -276,7 +276,7 @@ public class OrderStatService { } row = sheet.createRow(i + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue(i + 1); if (order.get("in_time") == null) { @@ -300,7 +300,7 @@ public class OrderStatService { // 合计 start row = sheet.createRow(datalen + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue("合计"); row.createCell(a++).setCellValue(""); row.createCell(a++).setCellValue(""); @@ -351,9 +351,9 @@ public class OrderStatService { * @return */ public Record monthgrid(String tm, Integer supermarket_id, Integer customer_id, Boolean stat_product, Integer product_id) { - String sql; - String paramsSql = ""; - List paraList = new ArrayList<>(); + String sql; + String paramsSql = ""; + List paraList = new ArrayList<>(); paraList.add(OrderStateEnum.RECEIVED.getStateid()); // paraList.add(tm + "%"); @@ -403,14 +403,14 @@ public class OrderStatService { } - List dblist = Db.find(sql, paraList.toArray()); + List dblist = Db.find(sql, paraList.toArray()); Map spkeys = new HashMap<>(); // supermarket_id <-> supermarket_name - Map cumaps = new HashMap<>(); // customer_id <-> out record + Map cumaps = new HashMap<>(); // customer_id <-> out record for (Record record : dblist) { String supermarket_id_str = record.getStr("supermarket_id"); - int sql_supermarket_id = record.getInt("supermarket_id"); - String supermarket_name = record.getStr("supermarket_name"); + int sql_supermarket_id = record.getInt("supermarket_id"); + String supermarket_name = record.getStr("supermarket_name"); String sql_customer_id; if (record.get("customer_id") == null) { @@ -471,9 +471,9 @@ public class OrderStatService { * @return */ public Workbook monthgridExport(String tm, Integer supermarket_id, Integer customer_id, Boolean stat_product, Integer product_id) { - Record grid = monthgrid(tm, supermarket_id, customer_id, stat_product, product_id); - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet("销售月汇总"); + Record grid = monthgrid(tm, supermarket_id, customer_id, stat_product, product_id); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet("销售月汇总"); // 副标题 start String subtitle = ""; @@ -491,7 +491,7 @@ public class OrderStatService { List rows = grid.get("rows"); int end_col = cols.size() + 1; - int a = 0; + int a = 0; Row row = sheet.createRow(2); row.createCell(a++).setCellValue("序号"); @@ -506,7 +506,7 @@ public class OrderStatService { for (int i = 0; i < datalen; i++) { Record rowobj = rows.get(i); row = sheet.createRow(i + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue(i + 1); row.createCell(a++).setCellValue(rowobj.getStr("name")); @@ -556,7 +556,7 @@ public class OrderStatService { " where t.state = 5 \n" + // " and t.create_time like ? \n" + " and t.create_time between ? and ? \n" + - saleParams + + saleParams + " ) t\n" + " group by t.id, t.product_id\n" + " ) a on a.id = t.supermarket_id and a.product_id = t.product_id\n" + @@ -595,7 +595,7 @@ public class OrderStatService { String saleParams = ""; List paraList = new ArrayList<>(); paraList.add(OrderStateEnum.RECEIVED.getStateid()); - + addTm(tm, paraList); // paraList.add(tm + "%"); @@ -714,7 +714,7 @@ public class OrderStatService { List dblist = Db.find(sql, paraList.toArray()); if (dblist.size() > 0) { - Record total = new Record(); + Record total = new Record(); total.set("id", 0); total.set("name", "合计"); total.set("orderCount", 0); @@ -797,9 +797,9 @@ public class OrderStatService { * @return */ public Workbook salestatExport(String tm, String title, String subtitle, Integer sale_type) { - List list = salestat(tm, sale_type); - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet(title); + List list = salestat(tm, sale_type); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet(title); // 表头 start Row row = sheet.createRow(2); @@ -822,10 +822,10 @@ public class OrderStatService { row.setHeight((short) (30 * 20)); a = 0; - String strweight = ""; + String strweight = ""; String strtotalPrice = ""; - Double weight = DataUtil.getDoubleByRecord(record, "weight"); + Double weight = DataUtil.getDoubleByRecord(record, "weight"); Double totalPrice = DataUtil.getDoubleByRecord(record, "totalPrice"); if (weight != null) { @@ -859,9 +859,9 @@ public class OrderStatService { * @return */ public Workbook salestatCustomerExport(String tm, String title, String subtitle, Integer invoice_type, Boolean stat_product, Integer customer_id, Integer customer_type_id, Integer sale_type) { - List list = salestatCustomer(tm, invoice_type, stat_product, customer_id, customer_type_id, sale_type); - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet(title); + List list = salestatCustomer(tm, invoice_type, stat_product, customer_id, customer_type_id, sale_type); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet(title); // 表头 start Row row = sheet.createRow(2); @@ -884,10 +884,10 @@ public class OrderStatService { row.setHeight((short) (30 * 20)); a = 0; - String strweight = ""; + String strweight = ""; String strtotalPrice = ""; - Double weight = DataUtil.getDoubleByRecord(record, "weight"); + Double weight = DataUtil.getDoubleByRecord(record, "weight"); Double totalPrice = DataUtil.getDoubleByRecord(record, "totalPrice"); if (weight != null) { @@ -957,8 +957,8 @@ public class OrderStatService { * @return */ public List mdstat(String stm, String etm, Integer supermarket_id, Boolean stat_product, Integer product_id, Integer sale_type) { - String sql; - String saleParam = ""; + String sql; + String saleParam = ""; List paramsArray = new ArrayList<>(); paramsArray.add(OrderStateEnum.RECEIVED.getStateid()); if (sale_type != null && (sale_type == 0 || sale_type == 1)) { @@ -1017,7 +1017,7 @@ public class OrderStatService { for (int i = 0; i < dblist.size(); i++) { Record record = dblist.get(i); record.set("id", i + 1); - double weight = record.getDouble("weight"); + double weight = record.getDouble("weight"); double totalPrice = record.getDouble("totalPrice"); if (i > 0) { @@ -1047,9 +1047,9 @@ public class OrderStatService { * @return */ public Workbook mdstatExport(String stm, String etm, Integer supermarket_id, Boolean stat_product, Integer product_id, Integer sale_type) { - List list = mdstat(stm, etm, supermarket_id, stat_product, product_id, sale_type); - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet("销售月逐日统计"); + List list = mdstat(stm, etm, supermarket_id, stat_product, product_id, sale_type); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet("销售月逐日统计"); // 副标题 start String subtitle = ""; @@ -1064,7 +1064,7 @@ public class OrderStatService { // 表头 start Row row = sheet.createRow(2); - int a = 0; + int a = 0; row.createCell(a++).setCellValue("日期"); row.createCell(a++).setCellValue("销量"); // row.createCell(a++).setCellValue("销售量截止累计"); @@ -1078,7 +1078,7 @@ public class OrderStatService { for (int i = 0; i < datalen; i++) { Record record = list.get(i); row = sheet.createRow(i + 3); - a = 0; + a = 0; String date = record.get("date"); @@ -1125,7 +1125,7 @@ public class OrderStatService { * @return */ public List statTrans(String tm, String stm, String etm, Integer supermarket_id, boolean stat_product, Integer product_id, Integer isprepaid) { - String temp_sql; + String temp_sql; List paraTemp = new ArrayList<>(); if (stat_product) { @@ -1195,7 +1195,8 @@ public class OrderStatService { // paraTemp.add(tm + "%"); temp_sql += " and t.create_time between ? and ? \n"; - addTm(tm, paraTemp); } + addTm(tm, paraTemp); + } if (isprepaid != null) { temp_sql += " and t.isprepaid = ? \n"; @@ -1224,13 +1225,13 @@ public class OrderStatService { } public Workbook statTransExport(String name, String tm, String stm, String etm, Integer supermarket_id, boolean stat_product, Integer product_id, Integer isprepaid) { - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet(name); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet(name); List list = statTrans(tm, stm, etm, supermarket_id, stat_product, product_id, isprepaid); - int datalen = list.size(); - int end_col = stat_product ? 8 : 7; // 数据共有几列 + int datalen = list.size(); + int end_col = stat_product ? 8 : 7; // 数据共有几列 String subtitle = ""; Supermarket supermarket = Supermarket.dao.findById(supermarket_id); @@ -1257,7 +1258,7 @@ public class OrderStatService { // 表头 start Row row = sheet.createRow(2); - int a = 0; + int a = 0; row.createCell(a++).setCellValue("序号"); if (stat_product) { row.createCell(a++).setCellValue("品类"); @@ -1271,11 +1272,11 @@ public class OrderStatService { row.createCell(a++).setCellValue("备注"); // 表头 end - double sum_weight = 0.0; - double sum_price = 0.0; - double sum_distance = 0.0; + double sum_weight = 0.0; + double sum_price = 0.0; + double sum_distance = 0.0; double sum_trans_price = 0.0; - int sum_cnt = 0; + int sum_cnt = 0; for (int i = 0; i < datalen; i++) { Record order = list.get(i); @@ -1287,7 +1288,7 @@ public class OrderStatService { sum_cnt += order.getInt("orderCount"); row = sheet.createRow(i + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue(i + 1); if (stat_product) { row.createCell(a++).setCellValue(order.getStr("product_name")); @@ -1303,7 +1304,7 @@ public class OrderStatService { // 合计 start row = sheet.createRow(datalen + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue("合计"); if (stat_product) { row.createCell(a++).setCellValue(""); @@ -1396,7 +1397,7 @@ public class OrderStatService { // paraList.add(tm + "%"); temp_sql += " and t.create_time between ? and ? \n"; - addTm(tm,paraList); + addTm(tm, paraList); } @@ -1456,13 +1457,13 @@ public class OrderStatService { } public Workbook statCustomerExport(String name, String tm, String stm, String etm, Integer supermarket_id, Integer customer_id, String customer_ids, Integer customer_type_id, boolean stat_product, Integer product_id, Integer isprepaid, Integer sale_type) { - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet(name); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet(name); List list = statCustomer(tm, stm, etm, supermarket_id, customer_id, customer_ids, customer_type_id, stat_product, product_id, isprepaid, sale_type); - int datalen = list.size(); - int end_col = stat_product ? 6 : 5; // 数据共有几列 + int datalen = list.size(); + int end_col = stat_product ? 6 : 5; // 数据共有几列 String subtitle = ""; Supermarket supermarket = Supermarket.dao.findById(supermarket_id); @@ -1489,7 +1490,7 @@ public class OrderStatService { // 表头 start Row row = sheet.createRow(2); - int a = 0; + int a = 0; row.createCell(a++).setCellValue("序号"); if (stat_product) { row.createCell(a++).setCellValue("品类"); @@ -1502,8 +1503,8 @@ public class OrderStatService { // 表头 end double sum_weight = 0.0; - double sum_price = 0.0; - int sum_cnt = 0; + double sum_price = 0.0; + int sum_cnt = 0; for (int i = 0; i < datalen; i++) { Record order = list.get(i); @@ -1513,7 +1514,7 @@ public class OrderStatService { sum_cnt += order.getInt("orderCount"); row = sheet.createRow(i + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue(i + 1); if (stat_product) { row.createCell(a++).setCellValue(order.getStr("product_name")); @@ -1527,7 +1528,7 @@ public class OrderStatService { // 合计 start row = sheet.createRow(datalen + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue("合计"); if (stat_product) { row.createCell(a++).setCellValue(""); @@ -1553,7 +1554,7 @@ public class OrderStatService { " where t.state = 5\n" + " and t.create_time between ? and ? \n" + " group by t.supermarket_id,t.product_id,t.product_name\n" + - ") a on s.id = a.id order by s.id", year + "-01-01 00:00:00",year + "-12-31 23:59:59"); + ") a on s.id = a.id order by s.id", year + "-01-01 00:00:00", year + "-12-31 23:59:59"); } else { list = Db.find("select s.id, s.name, a.cnt, a.total_price, a.total_weight from supermarket s\n" + "left join (\n" + @@ -1561,7 +1562,7 @@ public class OrderStatService { " where t.state = 5\n" + " and t.create_time between ? and ? \n" + " group by t.supermarket_id\n" + - ") a on s.id = a.id order by s.id", year + "-01-01 00:00:00",year + "-12-31 23:59:59"); + ") a on s.id = a.id order by s.id", year + "-01-01 00:00:00", year + "-12-31 23:59:59"); } } else { @@ -1609,8 +1610,8 @@ public class OrderStatService { public Workbook yearStatBySupExport(String year, Boolean stat_product) { List list = yearStatBySup(year, stat_product); - Workbook wb = new XSSFWorkbook(); - Sheet sheet; + Workbook wb = new XSSFWorkbook(); + Sheet sheet; if (StrKit.notBlank(year)) { sheet = wb.createSheet(year + "年销售汇总"); @@ -1621,7 +1622,7 @@ public class OrderStatService { // 表头 start Row row = sheet.createRow(0); - int a = 0; + int a = 0; row.createCell(a++).setCellValue("名称"); row.createCell(a++).setCellValue("订单量"); row.createCell(a++).setCellValue("总销售吨数"); @@ -1633,7 +1634,7 @@ public class OrderStatService { Record order = list.get(i); row = sheet.createRow(i + 1); - a = 0; + a = 0; row.createCell(a++).setCellValue(order.getStr("name")); if (order.get("cnt") != null) { row.createCell(a++).setCellValue(order.getInt("cnt")); @@ -1651,8 +1652,8 @@ public class OrderStatService { public List yearStatBySup(String stm, String etm, Boolean stat_product, Integer product_id, Integer sale_type) { List list; - String paramsSql = ""; - String saleParam = ""; + String paramsSql = ""; + String saleParam = ""; List paramsArray = new ArrayList<>(); if (sale_type != null && (sale_type == 0 || sale_type == 1)) { saleParam += " and t.sale_type = ? \n"; @@ -1714,13 +1715,13 @@ public class OrderStatService { } public Workbook yearStatBySupExport(String stm, String etm, Boolean stat_product, Integer product_id, Integer sale_type) { - List list = yearStatBySup(stm, etm, stat_product, product_id, sale_type); - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet(stm.substring(0, 10) + " ~ " + etm.substring(0, 10) + "年销售汇总"); + List list = yearStatBySup(stm, etm, stat_product, product_id, sale_type); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet(stm.substring(0, 10) + " ~ " + etm.substring(0, 10) + "年销售汇总"); // 表头 start Row row = sheet.createRow(0); - int a = 0; + int a = 0; row.createCell(a++).setCellValue("名称"); row.createCell(a++).setCellValue("订单量"); row.createCell(a++).setCellValue("总销售吨数"); @@ -1732,7 +1733,7 @@ public class OrderStatService { Record order = list.get(i); row = sheet.createRow(i + 1); - a = 0; + a = 0; row.createCell(a++).setCellValue(order.getStr("name")); if (order.get("cnt") != null) { row.createCell(a++).setCellValue(order.getInt("cnt")); @@ -1901,8 +1902,8 @@ public class OrderStatService { public Workbook yearStatByCustomerExport(String year, Boolean stat_product, Integer customer_id, Integer customer_type_id, Integer sale_type) { List list = yearStatByCustomer(year, stat_product, customer_id, customer_type_id, sale_type); - Workbook wb = new XSSFWorkbook(); - Sheet sheet; + Workbook wb = new XSSFWorkbook(); + Sheet sheet; if (StrKit.notBlank(year)) { sheet = wb.createSheet(year + "年销售汇总"); @@ -1913,22 +1914,22 @@ public class OrderStatService { // 表头 start Row row = sheet.createRow(0); - int a = 0; + int a = 0; row.createCell(a++).setCellValue("名称"); row.createCell(a++).setCellValue("订单量"); row.createCell(a++).setCellValue("总销售吨数"); row.createCell(a++).setCellValue("总销售额"); row.createCell(a++).setCellValue("客户总余额"); - int end_col = 5; - int datalen = list.size(); - Record hj = null; + int end_col = 5; + int datalen = list.size(); + Record hj = null; for (int i = 0; i < datalen; i++) { Record order = list.get(i); row = sheet.createRow(i + 1); - a = 0; + a = 0; if (order.getInt("id") == 0) { hj = order; @@ -1943,7 +1944,7 @@ public class OrderStatService { if (hj != null) { row = sheet.createRow(datalen + 1); - a = 0; + a = 0; row.createCell(a++).setCellValue("账户总余额"); row.createCell(a++).setCellValue(""); @@ -1961,8 +1962,8 @@ public class OrderStatService { public List yearStatByCustomer(String stm, String etm, Boolean stat_product, Integer product_id, Integer customer_id, Integer customer_type_id, Integer sale_type) { List list; - String paramsSql = ""; - String saleParam = ""; + String paramsSql = ""; + String saleParam = ""; List paramsArray = new ArrayList<>(); if (sale_type != null && (sale_type == 0 || sale_type == 1)) { saleParam += " and t.sale_type = ? \n"; @@ -2065,28 +2066,28 @@ public class OrderStatService { public Workbook yearStatByCustomerExport(String stm, String etm, Boolean stat_product, Integer product_id, Integer customer_id, Integer customer_type_id, Integer sale_type) { - List list = yearStatByCustomer(stm, etm, stat_product, product_id, customer_id, customer_type_id, sale_type); - Workbook wb = new XSSFWorkbook(); - Sheet sheet = wb.createSheet(stm.substring(0, 10) + " ~ " + stm.substring(0, 10) + "时段销售汇总"); + List list = yearStatByCustomer(stm, etm, stat_product, product_id, customer_id, customer_type_id, sale_type); + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet(stm.substring(0, 10) + " ~ " + stm.substring(0, 10) + "时段销售汇总"); // 表头 start Row row = sheet.createRow(0); - int a = 0; + int a = 0; row.createCell(a++).setCellValue("名称"); row.createCell(a++).setCellValue("订单量"); row.createCell(a++).setCellValue("总销售吨数"); row.createCell(a++).setCellValue("总销售额"); row.createCell(a++).setCellValue("客户总余额"); - int end_col = 5; - int datalen = list.size(); - Record hj = null; + int end_col = 5; + int datalen = list.size(); + Record hj = null; for (int i = 0; i < datalen; i++) { Record order = list.get(i); row = sheet.createRow(i + 1); - a = 0; + a = 0; if (order.getInt("id") == 0) { hj = order; @@ -2101,7 +2102,7 @@ public class OrderStatService { if (hj != null) { row = sheet.createRow(datalen + 1); - a = 0; + a = 0; row.createCell(a++).setCellValue("账户总余额"); row.createCell(a++).setCellValue(""); @@ -2117,13 +2118,13 @@ public class OrderStatService { } public Workbook trafficStatisticsOfEachSandStationExport(String stm, String etm, String tm, Integer invoice_type, Integer sale_type) { - Record data = trafficStatisticsOfEachSandStation(stm, etm, tm, invoice_type, sale_type); + Record data = trafficStatisticsOfEachSandStation(stm, etm, tm, invoice_type, sale_type); List list = data.get("data"); List hj_children = new ArrayList<>(); hj_children.add(list.get(list.size() - 1).set("customer_type_name", "合计")); list.get(list.size() - 1).set("children", hj_children); List sups = data.get("supermarket"); - Workbook wb = new XSSFWorkbook(); + Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet(stm.substring(0, 10) + " ~ " + etm.substring(0, 10) + "各砂站运输量统计表"); @@ -2142,10 +2143,10 @@ public class OrderStatService { Row row2 = sheet.createRow(1); Row row3 = sheet.createRow(2); - int a2 = 8; + int a2 = 8; for (int i = 0; i < sups.size(); i++) { - Record s = sups.get(i); + Record s = sups.get(i); Double yield = DataUtil.getDoubleByRecord(s, "yield"); row.createCell(a).setCellValue(s.getStr("name")); @@ -2169,11 +2170,11 @@ public class OrderStatService { sheet.addMergedRegion(new CellRangeAddress(0, 2, 7, 7)); int datalen = list.size(); - int colcnt = a; - int rowcnt = 3; + int colcnt = a; + int rowcnt = 3; for (int i = 0; i < datalen; i++) { - int startrow = rowcnt; - Record sales = list.get(i); + int startrow = rowcnt; + Record sales = list.get(i); row = sheet.createRow(rowcnt++); List children = sales.get("children"); @@ -2213,7 +2214,7 @@ public class OrderStatService { } } // 通用单元格格式 - Font font = wb.createFont(); + Font font = wb.createFont(); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); @@ -2276,24 +2277,86 @@ public class OrderStatService { saleParam += " and t.sale_type = ? \n"; } - String union_4 = "union select\n" + - " ifnull(t.customer_id, 0) customer_id,\n" + - " t.supermarket_id,\n" + - " ifnull(sum(t.weight), 0) weight,\n" + - " ifnull(sum(t.total_price), 0) total_price\n" + - " from order_temp t\n" + - " where t.state = 5\n" + + String union_4 = ""; + String union_99 = ""; + String today = ""; + String endDay = etm.split(" ")[0]; + if (LocalDate.now().toString().equals(endDay)) { + + union_4 = "union select\n" + + " ifnull(t.customer_id, 0) customer_id,\n" + + " t.supermarket_id,\n" + + " ifnull(sum(t.weight), 0) weight,\n" + + " ifnull(sum(t.total_price), 0) total_price\n" + + " from order_temp t\n" + + " where t.state = 5\n"; // " and t.product_id != 4\n" + - saleParam + - " and t.supermarket_id = 4\n" + - " and (t.create_time < '2021-09-08 00:00:00'\n" + - " or t.create_time > '2021-10-15 23:59:59')\n" + - " AND t.create_time >= CONCAT( CURDATE(), ' 00:00:00' )" + + + if (invoice_type != null) { + union_4 += "and t.invoice_type = " + invoice_type + " \n"; + } + + if (sale_type != null && (sale_type == 0 || sale_type == 1)) { + union_4 += " and t.sale_type = " + sale_type + " \n"; + } + + union_4 += " and t.supermarket_id = 4\n" + + " and (t.create_time < '2021-09-08 00:00:00'\n" + + " or t.create_time > '2021-10-15 23:59:59')\n" + + " AND t.create_time >= CONCAT( CURDATE(), ' 00:00:00' )" + // " and t.create_time >= ? \n" + // " and t.create_time <= ?\n" + - " and (t.create_time < '2021-10-20 00:00:00' or t.create_time > '2021-10-20 23:59:59')\n" + - paramsSql + - " group by t.customer_id\n"; + " and (t.create_time < '2021-10-20 00:00:00' or t.create_time > '2021-10-20 23:59:59')\n" + + " group by t.customer_id\n"; + + union_99 = " union select\n" + + " ifnull(t.customer_id, 0) customer_id,\n" + + " 99 supermarket_id,\n" + + " ifnull(sum(t.weight), 0) weight,\n" + + " ifnull(sum(t.total_price), 0) total_price\n" + + " from order_temp t\n" + + " where t.state = 5\n" ; +// " and t.product_id != 4\n" + + if (invoice_type != null) { + union_99 += "and t.invoice_type = " + invoice_type + " \n"; + } + + if (sale_type != null && (sale_type == 0 || sale_type == 1)) { + union_99 += " and t.sale_type = " + sale_type + " \n"; + } + union_99 += " and t.supermarket_id = 4\n" + + " and ((t.create_time >= '2021-09-08 00:00:00' and t.create_time <= '2021-10-15 23:59:59') \n" + + " or (t.create_time >= '2021-10-20 00:00:00' and t.create_time <= '2021-10-20 23:59:59'))\n" + + " AND t.create_time >= CONCAT( CURDATE(), ' 00:00:00' ) \n" + +// " and t.create_time >= ? \n" + +// " and t.create_time <= ?\n" + + " group by t.customer_id\n"; + + today = " select\n" + + " ifnull(t.customer_id, 0) customer_id,\n" + + " t.supermarket_id,\n" + + " ifnull(sum(t.weight), 0) weight,\n" + + " ifnull(sum(t.total_price), 0) total_price\n" + + " from order_temp t\n" + + " where t.state = 5\n" ; +// " and t.product_id != 4\n" + + if (invoice_type != null) { + today += "and t.invoice_type = " + invoice_type + " \n"; + } + + if (sale_type != null && (sale_type == 0 || sale_type == 1)) { + today += " and t.sale_type = " + sale_type + " \n"; + } + today += " and t.supermarket_id != 4\n" + + " AND t.create_time >= CONCAT( CURDATE(), ' 00:00:00' ) \n" + +// " and t.create_time>= ? \n" + +// " and t.create_time<= ?\n" + +// paramsSql + + " group by t.customer_id, t.supermarket_id \n " + + " union \n "; + } + + union_4 += " UNION\n" + " SELECT\n" + " ifnull( t.customer_id, 0 ) customer_id,\n" + @@ -2306,28 +2369,14 @@ public class OrderStatService { " t.supermarket_id != 4 \n" + " AND t.date >= ? \n" + " AND t.date <= ? \n" + + " and (t.date < '2021-09-08'\n" + + " or t.date > '2021-10-15')\n" + + " and (t.date < '2021-10-20' or t.date > '2021-10-20')\n" + saleParam + " GROUP BY\n" + " t.customer_id,\n" + " t.supermarket_id"; - String union_99 = " union select\n" + - " ifnull(t.customer_id, 0) customer_id,\n" + - " 99 supermarket_id,\n" + - " ifnull(sum(t.weight), 0) weight,\n" + - " ifnull(sum(t.total_price), 0) total_price\n" + - " from order_temp t\n" + - " where t.state = 5\n" + -// " and t.product_id != 4\n" + - saleParam + - " and t.supermarket_id = 4\n" + - " and ((t.create_time >= '2021-09-08 00:00:00' and t.create_time <= '2021-10-15 23:59:59') \n" + - " or (t.create_time >= '2021-10-20 00:00:00' and t.create_time <= '2021-10-20 23:59:59'))\n" + - " AND t.create_time >= CONCAT( CURDATE(), ' 00:00:00' ) \n" + -// " and t.create_time >= ? \n" + -// " and t.create_time <= ?\n" + - paramsSql + - " group by t.customer_id\n"; union_99 += " union SELECT\n" + " ifnull( t.customer_id, 0 ) customer_id,\n" + @@ -2346,7 +2395,7 @@ public class OrderStatService { " GROUP BY\n" + " t.customer_id "; - String order_sql = ""; + String order_sql = ""; String sql = "select\n" + " g.customer_id,\n" + @@ -2371,22 +2420,8 @@ public class OrderStatService { " ifnull(sum(case when g.supermarket_id = 12 then g.total_price end), 0) xse_12,\n" + " ifnull(sum(case when g.supermarket_id = 99 then g.total_price end), 0) xse_99\n" + " from (\n" + - " select\n" + - " ifnull(t.customer_id, 0) customer_id,\n" + - " t.supermarket_id,\n" + - " ifnull(sum(t.weight), 0) weight,\n" + - " ifnull(sum(t.total_price), 0) total_price\n" + - " from order_temp t\n" + - " where t.state = 5\n" + -// " and t.product_id != 4\n" + - saleParam + - " and t.supermarket_id != 4\n" + - " AND t.create_time >= CONCAT( CURDATE(), ' 00:00:00' ) \n" + -// " and t.create_time>= ? \n" + -// " and t.create_time<= ?\n" + - paramsSql + - " group by t.customer_id, t.supermarket_id\n" + - " union select\n" + + today + + " select\n" + " ifnull(t.customer_id, 0) customer_id,\n" + " t.supermarket_id,\n" + " ifnull(sum(t.weight), 0) weight,\n" + @@ -2406,20 +2441,21 @@ public class OrderStatService { if (invoice_type != null) { if (sale_type != null && (sale_type == 0 || sale_type == 1)) { - customer_sale_list = Db.find(sql, sale_type, invoice_type,stm, etm,sale_type, sale_type,invoice_type, stm, etm, sale_type, sale_type,invoice_type, stm, etm, sale_type); + customer_sale_list = Db.find(sql, stm, etm, sale_type, stm, etm, sale_type, stm, etm, sale_type); } else { - customer_sale_list = Db.find(sql, stm, etm, invoice_type, stm, etm, invoice_type, stm, etm, invoice_type); +// customer_sale_list = Db.find(sql, stm, etm, invoice_type, stm, etm, invoice_type, stm, etm, invoice_type); + customer_sale_list = Db.find(sql, stm, etm, stm, etm, stm, etm); } } else { if (sale_type != null && (sale_type == 0 || sale_type == 1)) { - customer_sale_list = Db.find(sql, sale_type, stm, etm, sale_type, sale_type, stm, etm, sale_type,sale_type, stm, etm, sale_type); + customer_sale_list = Db.find(sql,stm, etm, sale_type, stm, etm, sale_type, stm, etm, sale_type); } else { customer_sale_list = Db.find(sql, stm, etm, stm, etm, stm, etm); } } - List ids = new ArrayList<>(); - String cidsql = ""; + List ids = new ArrayList<>(); + String cidsql = ""; for (Record r : customer_sale_list) { ids.add(r.getStr("customer_id")); } @@ -2434,24 +2470,24 @@ public class OrderStatService { String tempSql = " select t.customer_id, sum(t.total_price) total_price\n" + - " from order_end t\n" + - " where t.customer_id > -1\n" + + " from order_end t\n" + + " where t.customer_id > -1\n" + // "and t.product_id != 4\n" + - " and t.date <= ?\n" + - " and t.sale_type = 0\n" + - " group by t.customer_id\n" ; + " and t.date <= ?\n" + + " and t.sale_type = 0\n" + + " group by t.customer_id\n"; // 如果是当天的就加上销售订单数据 - if (LocalDate.now().toString().equals(tm)){ + if (LocalDate.now().toString().equals(tm)) { tempSql += "UNION select t.customer_id, sum(t.total_price) total_price\n" + - " from order_temp t\n" + - " where t.customer_id is not null\n" + + " from order_temp t\n" + + " where t.customer_id is not null\n" + // "and t.product_id != 4\n" + - " and t.create_time >= ?\n" + - " and t.create_time <= ?\n" + - " and t.state = 5\n" + - " and t.sale_type = 0\n" + - " group by t.customer_id\n" ; + " and t.create_time >= ?\n" + + " and t.create_time <= ?\n" + + " and t.state = 5\n" + + " and t.sale_type = 0\n" + + " group by t.customer_id\n"; customer_pre_list_params.add(tm + STM_SUFFIX); customer_pre_list_params.add(tm + ETM_SUFFIX); @@ -2474,7 +2510,7 @@ public class OrderStatService { " from prepay_customer t\n" + " left join customer c on c.id = t.customer_id\n" + " left join (\n" + - tempSql + + tempSql + " ) a on a.customer_id = t.customer_id\n" + " left join(\n" + " select a.customer_id, a.amount, ifnull(b.amount, 0) refund_amount\n" + @@ -2558,10 +2594,10 @@ public class OrderStatService { // }); customer_pre_list.sort(Comparator.comparing(o -> - Objects.nonNull(o.getInt("customer_type_id"))? CustomerTypeEnum.getSortById(String.valueOf(o.getInt("customer_type_id"))) : Integer.valueOf(-1))); + Objects.nonNull(o.getInt("customer_type_id")) ? CustomerTypeEnum.getSortById(String.valueOf(o.getInt("customer_type_id"))) : Integer.valueOf(-1))); - Map salemap = new HashMap<>(); + Map salemap = new HashMap<>(); Map> typemap = new HashMap<>(); for (Record record : customer_sale_list) { @@ -2569,7 +2605,7 @@ public class OrderStatService { } for (Record record : customer_pre_list) { - Integer customer_id = record.getInt("customer_id"); + Integer customer_id = record.getInt("customer_id"); Integer customer_type_id = record.getInt("customer_type_id"); if (salemap.containsKey(customer_id)) { @@ -2589,27 +2625,27 @@ public class OrderStatService { double all_prepay_total_amount = 0.0; double all_refund_total_amount = 0.0; - double all_prepay_surplus = 0.0; - double all_weight = 0.0; - double all_total_price = 0.0; - double all_xsl_1 = 0.0; - double all_xsl_2 = 0.0; - double all_xsl_3 = 0.0; - double all_xsl_4 = 0.0; - double all_xsl_5 = 0.0; - double all_xsl_6 = 0.0; - double all_xsl_11 = 0.0; - double all_xsl_12 = 0.0; - double all_xsl_99 = 0.0; - double all_xse_1 = 0.0; - double all_xse_2 = 0.0; - double all_xse_3 = 0.0; - double all_xse_4 = 0.0; - double all_xse_5 = 0.0; - double all_xse_6 = 0.0; - double all_xse_11 = 0.0; - double all_xse_12 = 0.0; - double all_xse_99 = 0.0; + double all_prepay_surplus = 0.0; + double all_weight = 0.0; + double all_total_price = 0.0; + double all_xsl_1 = 0.0; + double all_xsl_2 = 0.0; + double all_xsl_3 = 0.0; + double all_xsl_4 = 0.0; + double all_xsl_5 = 0.0; + double all_xsl_6 = 0.0; + double all_xsl_11 = 0.0; + double all_xsl_12 = 0.0; + double all_xsl_99 = 0.0; + double all_xse_1 = 0.0; + double all_xse_2 = 0.0; + double all_xse_3 = 0.0; + double all_xse_4 = 0.0; + double all_xse_5 = 0.0; + double all_xse_6 = 0.0; + double all_xse_11 = 0.0; + double all_xse_12 = 0.0; + double all_xse_99 = 0.0; for (Record record : typelist) { Integer customer_type_id = record.getInt("customer_type_id"); @@ -2620,27 +2656,27 @@ public class OrderStatService { double prepay_total_amount = 0.0; double refund_total_amount = 0.0; - double prepay_surplus = 0.0; - double weight = 0.0; - double total_price = 0.0; - double xsl_1 = 0.0; - double xsl_2 = 0.0; - double xsl_3 = 0.0; - double xsl_4 = 0.0; - double xsl_5 = 0.0; - double xsl_6 = 0.0; - double xsl_11 = 0.0; - double xsl_12 = 0.0; - double xsl_99 = 0.0; - double xse_1 = 0.0; - double xse_2 = 0.0; - double xse_3 = 0.0; - double xse_4 = 0.0; - double xse_5 = 0.0; - double xse_6 = 0.0; - double xse_11 = 0.0; - double xse_12 = 0.0; - double xse_99 = 0.0; + double prepay_surplus = 0.0; + double weight = 0.0; + double total_price = 0.0; + double xsl_1 = 0.0; + double xsl_2 = 0.0; + double xsl_3 = 0.0; + double xsl_4 = 0.0; + double xsl_5 = 0.0; + double xsl_6 = 0.0; + double xsl_11 = 0.0; + double xsl_12 = 0.0; + double xsl_99 = 0.0; + double xse_1 = 0.0; + double xse_2 = 0.0; + double xse_3 = 0.0; + double xse_4 = 0.0; + double xse_5 = 0.0; + double xse_6 = 0.0; + double xse_11 = 0.0; + double xse_12 = 0.0; + double xse_99 = 0.0; for (Record r : list) { prepay_total_amount += DataUtil.getDefaultByRecord(r, "prepay_total_amount"); @@ -2736,7 +2772,7 @@ public class OrderStatService { // }); typelist.sort(Comparator.comparing(o -> - Objects.nonNull(o.getInt("customer_type_id"))? CustomerTypeEnum.getSortById(String.valueOf(o.getInt("customer_type_id"))) : Integer.valueOf(-1))); + Objects.nonNull(o.getInt("customer_type_id")) ? CustomerTypeEnum.getSortById(String.valueOf(o.getInt("customer_type_id"))) : Integer.valueOf(-1))); Record record = new Record(); @@ -2890,10 +2926,10 @@ public class OrderStatService { } public Workbook presellOrderStatisticsExport(String stm, String etm) { - Record data = presellOrderStatistics(stm, etm); + Record data = presellOrderStatistics(stm, etm); List list = data.get("data"); List sups = data.get("supermarket"); - Workbook wb = new XSSFWorkbook(); + Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet(stm.substring(0, 10) + " ~ " + etm.substring(0, 10) + "各砂站预售额及已提货额统计表"); @@ -2909,10 +2945,10 @@ public class OrderStatService { row.createCell(a++).setCellValue("总提货量(吨)"); Row row2 = sheet.createRow(1); - int a2 = 6; + int a2 = 6; for (int i = 0; i < sups.size(); i++) { - Record s = sups.get(i); + Record s = sups.get(i); row.createCell(a).setCellValue(s.getStr("name")); sheet.addMergedRegion(new CellRangeAddress(0, 0, a, a + 2)); @@ -2931,10 +2967,10 @@ public class OrderStatService { sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5)); int datalen = list.size(); - int colcnt = a; - int rowcnt = 2; + int colcnt = a; + int rowcnt = 2; for (int i = 0; i < datalen; i++) { - Record rec = list.get(i); + Record rec = list.get(i); row = sheet.createRow(rowcnt++); row.createCell(0).setCellValue(i + 1); @@ -2954,7 +2990,7 @@ public class OrderStatService { } // 通用单元格格式 - Font font = wb.createFont(); + Font font = wb.createFont(); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); @@ -2990,6 +3026,7 @@ public class OrderStatService { /** * 各砂站预售金额、提货额统计 + * * @param stm * @param etm * @return @@ -3005,7 +3042,7 @@ public class OrderStatService { " id <= 6\n" + "OR id = 11 or id = 12 "); - // 预售金额统计 + // 预售金额统计 List paraList1 = new ArrayList<>(); List paraList2 = new ArrayList<>(); String paramsSql = ""; @@ -3074,42 +3111,42 @@ public class OrderStatService { " ) g group by g.customer_id \n" + " ) t LEFT JOIN customer c ON c.id = t.customer_id"; - List list = Db.find(sql, paraList1.toArray()); - List ret = new ArrayList<>(); - double all_total_presell_amount = 0.0; - double all_total_presell_pug = 0.0; - double all_total_weight = 0.0; - double all_xsl_1 = 0.0; - double all_xsl_2 = 0.0; - double all_xsl_3 = 0.0; - double all_xsl_4 = 0.0; - double all_xsl_5 = 0.0; - double all_xsl_6 = 0.0; - double all_xsl_11 = 0.0; - double all_xsl_12 = 0.0; - double all_xse_1 = 0.0; - double all_xse_2 = 0.0; - double all_xse_3 = 0.0; - double all_xse_4 = 0.0; - double all_xse_5 = 0.0; - double all_xse_6 = 0.0; - double all_xse_11 = 0.0; - double all_xse_12 = 0.0; - double all_xsw_1 = 0.0; - double all_xsw_2 = 0.0; - double all_xsw_3 = 0.0; - double all_xsw_4 = 0.0; - double all_xsw_5 = 0.0; - double all_xsw_6 = 0.0; - double all_xsw_11 = 0.0; - double all_xsw_12 = 0.0; + List list = Db.find(sql, paraList1.toArray()); + List ret = new ArrayList<>(); + double all_total_presell_amount = 0.0; + double all_total_presell_pug = 0.0; + double all_total_weight = 0.0; + double all_xsl_1 = 0.0; + double all_xsl_2 = 0.0; + double all_xsl_3 = 0.0; + double all_xsl_4 = 0.0; + double all_xsl_5 = 0.0; + double all_xsl_6 = 0.0; + double all_xsl_11 = 0.0; + double all_xsl_12 = 0.0; + double all_xse_1 = 0.0; + double all_xse_2 = 0.0; + double all_xse_3 = 0.0; + double all_xse_4 = 0.0; + double all_xse_5 = 0.0; + double all_xse_6 = 0.0; + double all_xse_11 = 0.0; + double all_xse_12 = 0.0; + double all_xsw_1 = 0.0; + double all_xsw_2 = 0.0; + double all_xsw_3 = 0.0; + double all_xsw_4 = 0.0; + double all_xsw_5 = 0.0; + double all_xsw_6 = 0.0; + double all_xsw_11 = 0.0; + double all_xsw_12 = 0.0; for (int i = 0; i < list.size(); i++) { Record r = list.get(i); String name = r.getStr("name"); double total_presell_amount = DataUtil.getDefaultByRecord(r, "total_presell_amount"); - double total_presell_pug = DataUtil.getDefaultByRecord(r, "total_presell_pug"); - double total_weight = DataUtil.getDefaultByRecord(r, "total_weight"); + double total_presell_pug = DataUtil.getDefaultByRecord(r, "total_presell_pug"); + double total_weight = DataUtil.getDefaultByRecord(r, "total_weight"); double xsl_1 = DataUtil.getDefaultByRecord(r, "xsl_1"); double xsl_2 = DataUtil.getDefaultByRecord(r, "xsl_2"); double xsl_3 = DataUtil.getDefaultByRecord(r, "xsl_3"); @@ -3287,23 +3324,24 @@ public class OrderStatService { /** * [{ - * name: '竹瓦', key: '1' - * children: [ - * {name: '实售', key: '1_sh' , - * children: [ - * {name: '黄砂', key: '1_sh_1', order_num: 45, weight: 171.11, total_price: 14855.9}, - * {name: '鹅卵石', key: '1_sh_2', order_num: 3, weight: 36, total_price: 2376}, - * {name: '机制砂', key: '1_sh_3', order_num: 0, weight: 0, total_price: 0} - * ] - * }, - * {name: '预售', key: '1_yh' , - * children: [ - * {name: '-', key: '1_yh_1', order_num: '-', weight: '-', total_price: 380}] - * } - * ] + * name: '竹瓦', key: '1' + * children: [ + * {name: '实售', key: '1_sh' , + * children: [ + * {name: '黄砂', key: '1_sh_1', order_num: 45, weight: 171.11, total_price: 14855.9}, + * {name: '鹅卵石', key: '1_sh_2', order_num: 3, weight: 36, total_price: 2376}, + * {name: '机制砂', key: '1_sh_3', order_num: 0, weight: 0, total_price: 0} + * ] + * }, + * {name: '预售', key: '1_yh' , + * children: [ + * {name: '-', key: '1_yh_1', order_num: '-', weight: '-', total_price: 380}] + * } + * ] * } * ] * 砂站年统计 + * * @param tm * @return */ @@ -3332,440 +3370,441 @@ public class OrderStatService { addTm(tm, shParamsList); addTm(tm, yhParamsList); } - // 实售 - List shList = Db.find( - "select s.id, s.name, p.id product_id, p.`name` product_name, ifnull(a.orderCount, 0) as order_num, ifnull(a.totalPrice, 0) as total_price, ifnull(a.weight, 0) as weight\n" + - " from supermarket_product t\n" + - " left join (\n" + - " select t.id, t.product_id, count(*) as orderCount, sum(t.total_price) as totalPrice, sum(t.weight) as weight\n" + - " from (\n" + - " select t.supermarket_id as id, t.total_price, t.weight, t.product_id\n" + - " from order_temp t \n" + - " where t.sale_type = 0 \n" + - " and t.state = 5 \n" + - shParams + - " ) t\n" + - " group by t.id, t.product_id\n" + - " ) a on a.id = t.supermarket_id and a.product_id = t.product_id\n" + - " left join supermarket s on s.id = t.supermarket_id\n" + - " left join product p on p.id = t.product_id order BY s.id, p.id ASC", shParamsList.toArray()); - // 预售 - List yhList = Db.find( - "SELECT\n" + - " t.supermarket_id id,\n" + - " ifnull(count(*), 0) as order_num,\n" + - " ifnull(sum(t.weight), 0) as weight,\n" + - " ifnull(sum(t.total_price), 0) as total_price\n" + - "FROM\n" + - " order_temp t\n" + - "LEFT JOIN ordercluster c ON c.id = t.ordercluster_id\n" + - "LEFT JOIN presell_order p ON p.id = c.presell_order_id\n" + - "WHERE\n" + - " t.sale_type = 1\n" + - " AND t.state = 5\n" + - " AND p.del = 0\n" + - yhParams + - "GROUP BY\n" + - " t.supermarket_id", yhParamsList.toArray()); + // 实售 + List shList = Db.find( + "select s.id, s.name, p.id product_id, p.`name` product_name, ifnull(a.orderCount, 0) as order_num, ifnull(a.totalPrice, 0) as total_price, ifnull(a.weight, 0) as weight\n" + + " from supermarket_product t\n" + + " left join (\n" + + " select t.id, t.product_id, count(*) as orderCount, sum(t.total_price) as totalPrice, sum(t.weight) as weight\n" + + " from (\n" + + " select t.supermarket_id as id, t.total_price, t.weight, t.product_id\n" + + " from order_temp t \n" + + " where t.sale_type = 0 \n" + + " and t.state = 5 \n" + + shParams + + " ) t\n" + + " group by t.id, t.product_id\n" + + " ) a on a.id = t.supermarket_id and a.product_id = t.product_id\n" + + " left join supermarket s on s.id = t.supermarket_id\n" + + " left join product p on p.id = t.product_id order BY s.id, p.id ASC", shParamsList.toArray()); + // 预售 + List yhList = Db.find( + "SELECT\n" + + " t.supermarket_id id,\n" + + " ifnull(count(*), 0) as order_num,\n" + + " ifnull(sum(t.weight), 0) as weight,\n" + + " ifnull(sum(t.total_price), 0) as total_price\n" + + "FROM\n" + + " order_temp t\n" + + "LEFT JOIN ordercluster c ON c.id = t.ordercluster_id\n" + + "LEFT JOIN presell_order p ON p.id = c.presell_order_id\n" + + "WHERE\n" + + " t.sale_type = 1\n" + + " AND t.state = 5\n" + + " AND p.del = 0\n" + + yhParams + + "GROUP BY\n" + + " t.supermarket_id", yhParamsList.toArray()); - List retChildren = new ArrayList<>(); - List retList = new ArrayList<>(); - List shList1 = new ArrayList<>(); - List yhList1 = new ArrayList<>(); + List retChildren = new ArrayList<>(); + List retList = new ArrayList<>(); + List shList1 = new ArrayList<>(); + List yhList1 = new ArrayList<>(); - int hj_hs_sh_order_num = 0; - double hj_hs_sh_weight = 0.0; - double hj_hs_sh_total_price = 0.0; + int hj_hs_sh_order_num = 0; + double hj_hs_sh_weight = 0.0; + double hj_hs_sh_total_price = 0.0; - int hj_els_sh_order_num = 0; - double hj_els_sh_weight = 0.0; - double hj_els_sh_total_price = 0.0; + int hj_els_sh_order_num = 0; + double hj_els_sh_weight = 0.0; + double hj_els_sh_total_price = 0.0; - int hj_jzs_sh_order_num = 0; - double hj_jzs_sh_weight = 0.0; - double hj_jzs_sh_total_price = 0.0; + int hj_jzs_sh_order_num = 0; + double hj_jzs_sh_weight = 0.0; + double hj_jzs_sh_total_price = 0.0; - int hj_yh_order_num = 0; - double hj_yh_weight = 0.0; - double hj_yh_total_price = 0.0; + int hj_yh_order_num = 0; + double hj_yh_weight = 0.0; + double hj_yh_total_price = 0.0; - // 实售合并 - if (shList != null && !shList.isEmpty()) { - 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 || id == 10) && product_id == 1) { - shMap.put(id, s); - } else { - shList1.add(s); - } - } - 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); - } - 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) { - Record p = new Record(); - p.set("id", s.getInt("id")); - p.set("name", s.getStr("name")); - p.set("product_id", 1); - p.set("product_name", "黄砂"); - p.set("order_num", 0); - p.set("weight", new BigDecimal(0)); - p.set("total_price", new BigDecimal(0)); - shList1.add(p); - } - } - // 预售合并 - if (yhList != null && !yhList.isEmpty()) { - 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 || id == 10) { - yhMap.put(id, s); - } else { - yhList1.add(s); - } - } - 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); - } - 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) { - Record p = new Record(); - p.set("id", s.getInt("id")); - p.set("order_num", 0); - p.set("weight", new BigDecimal(0)); - p.set("total_price", new BigDecimal(0)); - yhList1.add(p); - } - } - if (sups.size() > 0) { - for (Record s : sups) { - Record p = new Record(); - int s_id = s.getInt("id"); - String name = s.getStr("name"); - p.set("key", s_id); - p.set("name", name); - Record sh = new Record(); - sh.set("key", s_id + "_sh"); - sh.set("item_name", "实售"); - List shChildren = new ArrayList<>(); - if (shList1.size() > 0) { - boolean flag = true; - for (Record sl : shList1) { - int sl_id = sl.getInt("id"); - int product_id = sl.getInt("product_id"); - if (s_id == sl_id) { - flag = false; - Record r = new Record(); - int order_num = sl.getInt("order_num") == null ? 0 : sl.getInt("order_num"); - BigDecimal weight = sl.getBigDecimal("weight") == null ? new BigDecimal(0) : sl.getBigDecimal("weight"); - BigDecimal total_price = sl.getBigDecimal("total_price") == null ? new BigDecimal(0) : sl.getBigDecimal("total_price"); - - if (product_id == 1) { - hj_hs_sh_order_num += order_num; - hj_hs_sh_weight += weight.doubleValue(); - hj_hs_sh_total_price += total_price.doubleValue(); - } else if (product_id == 2) { - hj_els_sh_order_num += order_num; - hj_els_sh_weight += weight.doubleValue(); - hj_els_sh_total_price += total_price.doubleValue(); - } else if (product_id == 3) { - hj_jzs_sh_order_num += order_num; - hj_jzs_sh_weight += weight.doubleValue(); - hj_jzs_sh_total_price += total_price.doubleValue(); - } - - r.set("key", s_id + "_sh_" + product_id); - r.set("id", s_id); - r.set("name", name); - r.set("item_name", "实售"); - r.set("product_id", product_id); - r.set("product_name", sl.getStr("product_name")); - r.set("order_num", order_num); - r.set("weight", weight); - r.set("total_price", total_price); - retList.add(r); - shChildren.add(new Record().setColumns(r).remove("name").remove("item_name")); - } - } - if (flag) { - Record r = new Record(); - r.set("key", s_id + "_sh_1"); - r.set("id", s_id); - r.set("name", name); - r.set("item_name", "实售"); - r.set("product_id", 1); - r.set("product_name", "-"); - r.set("order_num", "-"); - r.set("weight", "-"); - r.set("total_price", "-"); - retList.add(r); - shChildren.add(new Record().setColumns(r).remove("name").remove("item_name")); - } - } - - shChildren.sort(new Comparator() { - @Override - public int compare(Record o1, Record o2) { - return o1.getInt("product_id") - o2.getInt("product_id"); - } - }); - sh.set("children", shChildren); - - Record yh = new Record(); - yh.set("key", s.getInt("id") + "_yh"); - yh.set("item_name", "预售"); - List yhChildren = new ArrayList<>(); - if (yhList1.size() > 0) { - boolean flag = true; - for (Record yl : yhList1) { - int yl_id = yl.getInt("id"); - if (s_id == yl_id) { - flag = false; - Record r = new Record(); - - int order_num = yl.getInt("order_num") == null ? 0 : yl.getInt("order_num"); - BigDecimal weight = yl.getBigDecimal("weight") == null ? new BigDecimal(0) : yl.getBigDecimal("weight"); - BigDecimal total_price = yl.getBigDecimal("total_price") == null ? new BigDecimal(0) : yl.getBigDecimal("total_price"); - hj_yh_order_num += order_num; - hj_yh_weight += weight.doubleValue(); - hj_yh_total_price += total_price.doubleValue(); - - r.set("key", yl_id + "_yh_1"); - r.set("id", s_id); - r.set("name", name); - r.set("item_name", "预售"); - r.set("product_name", "-"); - r.set("order_num", order_num); - r.set("weight", weight); - r.set("total_price", total_price); - retList.add(r); - yhChildren.add(new Record().setColumns(r).remove("name").remove("item_name")); - } + // 实售合并 + if (shList != null && !shList.isEmpty()) { + 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 || id == 10) && product_id == 1) { + shMap.put(id, s); + } else { + shList1.add(s); } - if (flag) { - Record r2 = new Record(); - r2.set("key", s_id + "_yh_1"); - r2.set("id", s_id); - r2.set("name", name); - r2.set("item_name", "预售"); - r2.set("product_name", "-"); - r2.set("order_num", "-"); - r2.set("weight", "-"); - r2.set("total_price", "-"); - retList.add(r2); - yhChildren.add(new Record().setColumns(r2).remove("name").remove("item_name")); + } + 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); } - } - yh.set("children", yhChildren); - List children = new ArrayList<>(); + 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) { + Record p = new Record(); + p.set("id", s.getInt("id")); + p.set("name", s.getStr("name")); + p.set("product_id", 1); + p.set("product_name", "黄砂"); + p.set("order_num", 0); + p.set("weight", new BigDecimal(0)); + p.set("total_price", new BigDecimal(0)); + shList1.add(p); + } + } + // 预售合并 + if (yhList != null && !yhList.isEmpty()) { + 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 || id == 10) { + yhMap.put(id, s); + } else { + yhList1.add(s); + } + } + 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); + } + 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) { + Record p = new Record(); + p.set("id", s.getInt("id")); + p.set("order_num", 0); + p.set("weight", new BigDecimal(0)); + p.set("total_price", new BigDecimal(0)); + yhList1.add(p); + } + } + if (sups.size() > 0) { + for (Record s : sups) { + Record p = new Record(); + int s_id = s.getInt("id"); + String name = s.getStr("name"); + p.set("key", s_id); + p.set("name", name); + Record sh = new Record(); + sh.set("key", s_id + "_sh"); + sh.set("item_name", "实售"); + List shChildren = new ArrayList<>(); + if (shList1.size() > 0) { + boolean flag = true; + for (Record sl : shList1) { + int sl_id = sl.getInt("id"); + int product_id = sl.getInt("product_id"); + if (s_id == sl_id) { + flag = false; + Record r = new Record(); + int order_num = sl.getInt("order_num") == null ? 0 : sl.getInt("order_num"); + BigDecimal weight = sl.getBigDecimal("weight") == null ? new BigDecimal(0) : sl.getBigDecimal("weight"); + BigDecimal total_price = sl.getBigDecimal("total_price") == null ? new BigDecimal(0) : sl.getBigDecimal("total_price"); - children.add(sh); - children.add(yh); - p.set("children", children); + if (product_id == 1) { + hj_hs_sh_order_num += order_num; + hj_hs_sh_weight += weight.doubleValue(); + hj_hs_sh_total_price += total_price.doubleValue(); + } else if (product_id == 2) { + hj_els_sh_order_num += order_num; + hj_els_sh_weight += weight.doubleValue(); + hj_els_sh_total_price += total_price.doubleValue(); + } else if (product_id == 3) { + hj_jzs_sh_order_num += order_num; + hj_jzs_sh_weight += weight.doubleValue(); + hj_jzs_sh_total_price += total_price.doubleValue(); + } - retChildren.add(p); - } + r.set("key", s_id + "_sh_" + product_id); + r.set("id", s_id); + r.set("name", name); + r.set("item_name", "实售"); + r.set("product_id", product_id); + r.set("product_name", sl.getStr("product_name")); + r.set("order_num", order_num); + r.set("weight", weight); + r.set("total_price", total_price); + retList.add(r); + shChildren.add(new Record().setColumns(r).remove("name").remove("item_name")); + } + } + if (flag) { + Record r = new Record(); + r.set("key", s_id + "_sh_1"); + r.set("id", s_id); + r.set("name", name); + r.set("item_name", "实售"); + r.set("product_id", 1); + r.set("product_name", "-"); + r.set("order_num", "-"); + r.set("weight", "-"); + r.set("total_price", "-"); + retList.add(r); + shChildren.add(new Record().setColumns(r).remove("name").remove("item_name")); + } + } - retList.sort(new Comparator() { - @Override - public int compare(Record o1, Record o2) { - if (o1.getInt("product_id") != null && o2.getInt("product_id") != null - && o1.getInt("id") == o2.getInt("id")) { - return o1.getInt("product_id") - o2.getInt("product_id"); - } else if (o1.getInt("id") != null && o2.getInt("id") != null) { - return o1.getInt("id") - o2.getInt("id"); - } - return 1; - } - }); + shChildren.sort(new Comparator() { + @Override + public int compare(Record o1, Record o2) { + return o1.getInt("product_id") - o2.getInt("product_id"); + } + }); + sh.set("children", shChildren); - // 合计 - Record hj = new Record(); - List hj_sh_children = new ArrayList<>(); - List hj_yh_children = new ArrayList<>(); + Record yh = new Record(); + yh.set("key", s.getInt("id") + "_yh"); + yh.set("item_name", "预售"); + List yhChildren = new ArrayList<>(); + if (yhList1.size() > 0) { + boolean flag = true; + for (Record yl : yhList1) { + int yl_id = yl.getInt("id"); + if (s_id == yl_id) { + flag = false; + Record r = new Record(); - Record hj_sh_hs = new Record(); - hj_sh_hs.set("key", "hj_sh_1"); - hj_sh_hs.set("name", "合计"); - hj_sh_hs.set("item_name", "实售"); - hj_sh_hs.set("product_name", "黄砂"); - hj_sh_hs.set("order_num", hj_hs_sh_order_num); - hj_sh_hs.set("weight", hj_hs_sh_weight); - hj_sh_hs.set("total_price", hj_hs_sh_total_price); - retList.add(hj_sh_hs); - hj_sh_children.add(new Record().setColumns(hj_sh_hs).remove("name").remove("item_name")); + int order_num = yl.getInt("order_num") == null ? 0 : yl.getInt("order_num"); + BigDecimal weight = yl.getBigDecimal("weight") == null ? new BigDecimal(0) : yl.getBigDecimal("weight"); + BigDecimal total_price = yl.getBigDecimal("total_price") == null ? new BigDecimal(0) : yl.getBigDecimal("total_price"); + hj_yh_order_num += order_num; + hj_yh_weight += weight.doubleValue(); + hj_yh_total_price += total_price.doubleValue(); - Record hj_sh_els = new Record(); - hj_sh_els.set("key", "hj_sh_2"); - hj_sh_els.set("name", "合计"); - hj_sh_els.set("item_name", "实售"); - hj_sh_els.set("product_name", "鹅卵石"); - hj_sh_els.set("order_num", hj_els_sh_order_num); - hj_sh_els.set("weight", hj_els_sh_weight); - hj_sh_els.set("total_price", hj_els_sh_total_price); - retList.add(hj_sh_els); - hj_sh_children.add(new Record().setColumns(hj_sh_els).remove("name").remove("item_name")); + r.set("key", yl_id + "_yh_1"); + r.set("id", s_id); + r.set("name", name); + r.set("item_name", "预售"); + r.set("product_name", "-"); + r.set("order_num", order_num); + r.set("weight", weight); + r.set("total_price", total_price); + retList.add(r); + yhChildren.add(new Record().setColumns(r).remove("name").remove("item_name")); + } + } + if (flag) { + Record r2 = new Record(); + r2.set("key", s_id + "_yh_1"); + r2.set("id", s_id); + r2.set("name", name); + r2.set("item_name", "预售"); + r2.set("product_name", "-"); + r2.set("order_num", "-"); + r2.set("weight", "-"); + r2.set("total_price", "-"); + retList.add(r2); + yhChildren.add(new Record().setColumns(r2).remove("name").remove("item_name")); + } + } + yh.set("children", yhChildren); + List children = new ArrayList<>(); - Record hj_sh_jzs = new Record(); - hj_sh_jzs.set("key", "hj_sh_3"); - hj_sh_jzs.set("name", "合计"); - hj_sh_jzs.set("item_name", "实售"); - hj_sh_jzs.set("product_name", "机制砂"); - hj_sh_jzs.set("order_num", hj_jzs_sh_order_num); - hj_sh_jzs.set("weight", hj_jzs_sh_weight); - hj_sh_jzs.set("total_price", hj_jzs_sh_total_price); - retList.add(hj_sh_jzs); - hj_sh_children.add(hj_sh_jzs); + children.add(sh); + children.add(yh); + p.set("children", children); - Record hj_yh_1 = new Record(); - hj_yh_1.set("key", "hj_yh_1"); - hj_yh_1.set("name", "合计"); - hj_yh_1.set("item_name", "预售"); - hj_yh_1.set("product_name", "-"); - hj_yh_1.set("order_num", hj_yh_order_num); - hj_yh_1.set("weight", hj_yh_weight); - hj_yh_1.set("total_price", hj_yh_total_price); - retList.add(hj_yh_1); - hj_yh_children.add(hj_yh_1); + retChildren.add(p); + } - Record hj_sh = new Record(); - hj_sh.set("key", "hj_sh"); - hj_sh.set("item_name", "实售"); - hj_sh.set("children", hj_sh_children); + retList.sort(new Comparator() { + @Override + public int compare(Record o1, Record o2) { + if (o1.getInt("product_id") != null && o2.getInt("product_id") != null + && o1.getInt("id") == o2.getInt("id")) { + return o1.getInt("product_id") - o2.getInt("product_id"); + } else if (o1.getInt("id") != null && o2.getInt("id") != null) { + return o1.getInt("id") - o2.getInt("id"); + } + return 1; + } + }); - Record hj_yh = new Record(); - hj_yh.set("key", "hj_yh"); - hj_yh.set("item_name", "预售"); - hj_yh.set("children", hj_yh_children); + // 合计 + Record hj = new Record(); + List hj_sh_children = new ArrayList<>(); + List hj_yh_children = new ArrayList<>(); - List hj_children = new ArrayList<>(); - hj_children.add(hj_sh); - hj_children.add(hj_yh); + Record hj_sh_hs = new Record(); + hj_sh_hs.set("key", "hj_sh_1"); + hj_sh_hs.set("name", "合计"); + hj_sh_hs.set("item_name", "实售"); + hj_sh_hs.set("product_name", "黄砂"); + hj_sh_hs.set("order_num", hj_hs_sh_order_num); + hj_sh_hs.set("weight", hj_hs_sh_weight); + hj_sh_hs.set("total_price", hj_hs_sh_total_price); + retList.add(hj_sh_hs); + hj_sh_children.add(new Record().setColumns(hj_sh_hs).remove("name").remove("item_name")); - hj.set("key", "hj").set("name", "合计").set("children", hj_children); - retChildren.add(hj); + Record hj_sh_els = new Record(); + hj_sh_els.set("key", "hj_sh_2"); + hj_sh_els.set("name", "合计"); + hj_sh_els.set("item_name", "实售"); + hj_sh_els.set("product_name", "鹅卵石"); + hj_sh_els.set("order_num", hj_els_sh_order_num); + hj_sh_els.set("weight", hj_els_sh_weight); + hj_sh_els.set("total_price", hj_els_sh_total_price); + retList.add(hj_sh_els); + hj_sh_children.add(new Record().setColumns(hj_sh_els).remove("name").remove("item_name")); - // 总合计 - Record total = new Record(); - total.set("key", "total").set("name", "总合计").set("item_name", "-").set("product_name", "-") - .set("order_num", hj_hs_sh_order_num + hj_els_sh_order_num + hj_jzs_sh_order_num + hj_yh_order_num) - .set("weight", hj_hs_sh_weight + hj_els_sh_weight + hj_jzs_sh_weight + hj_yh_weight) - .set("total_price", hj_hs_sh_total_price + hj_els_sh_total_price + hj_jzs_sh_total_price + hj_yh_total_price); + Record hj_sh_jzs = new Record(); + hj_sh_jzs.set("key", "hj_sh_3"); + hj_sh_jzs.set("name", "合计"); + hj_sh_jzs.set("item_name", "实售"); + hj_sh_jzs.set("product_name", "机制砂"); + hj_sh_jzs.set("order_num", hj_jzs_sh_order_num); + hj_sh_jzs.set("weight", hj_jzs_sh_weight); + hj_sh_jzs.set("total_price", hj_jzs_sh_total_price); + retList.add(hj_sh_jzs); + hj_sh_children.add(hj_sh_jzs); - retList.add(total); + Record hj_yh_1 = new Record(); + hj_yh_1.set("key", "hj_yh_1"); + hj_yh_1.set("name", "合计"); + hj_yh_1.set("item_name", "预售"); + hj_yh_1.set("product_name", "-"); + hj_yh_1.set("order_num", hj_yh_order_num); + hj_yh_1.set("weight", hj_yh_weight); + hj_yh_1.set("total_price", hj_yh_total_price); + retList.add(hj_yh_1); + hj_yh_children.add(hj_yh_1); - retChildren.add(total); - } + Record hj_sh = new Record(); + hj_sh.set("key", "hj_sh"); + hj_sh.set("item_name", "实售"); + hj_sh.set("children", hj_sh_children); - return type == 1 ? retChildren : retList; + Record hj_yh = new Record(); + hj_yh.set("key", "hj_yh"); + hj_yh.set("item_name", "预售"); + hj_yh.set("children", hj_yh_children); + + List hj_children = new ArrayList<>(); + hj_children.add(hj_sh); + hj_children.add(hj_yh); + + hj.set("key", "hj").set("name", "合计").set("children", hj_children); + retChildren.add(hj); + + // 总合计 + Record total = new Record(); + total.set("key", "total").set("name", "总合计").set("item_name", "-").set("product_name", "-") + .set("order_num", hj_hs_sh_order_num + hj_els_sh_order_num + hj_jzs_sh_order_num + hj_yh_order_num) + .set("weight", hj_hs_sh_weight + hj_els_sh_weight + hj_jzs_sh_weight + hj_yh_weight) + .set("total_price", hj_hs_sh_total_price + hj_els_sh_total_price + hj_jzs_sh_total_price + hj_yh_total_price); + + retList.add(total); + + retChildren.add(total); + } + + return type == 1 ? retChildren : retList; } - private void addTm(String tm, List list){ + private void addTm(String tm, List list) { switch (tm.length()) { - case 4:{ // 年 + case 4: { // 年 list.add(tm + "-01-01 00:00:00"); list.add(tm + "-12-31 23:59:59"); break; - }case 7:{ // 月 + } + case 7: { // 月 list.add(tm + "-01 00:00:00"); list.add(tm + "-31 23:59:59"); break; } - case 10:{ // 日 + case 10: { // 日 list.add(tm + " 00:00:00"); list.add(tm + " 23:59:59");