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 6e4f4b6..61106bd 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 @@ -1859,7 +1859,7 @@ public class OrderStatService { Sheet sheet = wb.createSheet(stm.substring(0, 10) + " ~ " + etm.substring(0, 10) + "各砂站运输量统计表"); sheet.setColumnWidth(1,40*256); - for(int i=2;i<28;i++){ + for(int i=2;i<30;i++){ sheet.setColumnWidth(i,15*256); } @@ -1870,15 +1870,13 @@ public class OrderStatService { sheet.addMergedRegion(new CellRangeAddress(0,1,2,2)); sheet.addMergedRegion(new CellRangeAddress(0,1,3,3)); int num = 4; - for(int i=0;i<12;i++){ + for(int i=0;i<13;i++){ sheet.addMergedRegion(new CellRangeAddress(0,0,num,num+1)); num=num+2; } // 通用单元格格式 Font font = wb.createFont(); CellStyle cellStyle = wb.createCellStyle(); -// font.setFontHeight((short) (10 * 20)); -// font.setFontName("宋体"); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); @@ -1903,11 +1901,12 @@ public class OrderStatService { row.createCell(20).setCellValue("融嘉合计"); row.createCell(22).setCellValue("盐港"); row.createCell(24).setCellValue("永安"); - row.createCell(26).setCellValue("盐港合计"); + row.createCell(26).setCellValue("河东湾"); + row.createCell(28).setCellValue("盐港合计"); row = sheet.createRow(1); num = 4; - for(int i=0;i<12;i++){ + for(int i=0;i<13;i++){ row.createCell(num++).setCellValue("总销售量(吨)"); row.createCell(num++).setCellValue("总销售额(元)"); } @@ -1942,6 +1941,8 @@ public class OrderStatService { row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "yg_xse")); row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "ya_xsl")); row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "ya_xse")); + row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "dhw_xsl")); + row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "dhw_xse")); row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "yghj_xsl")); row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "yghj_xse")); } @@ -1951,7 +1952,7 @@ public class OrderStatService { if (row == null) { row = sheet.createRow(r); } - for (int c = 0; c < 28; c++) { + for (int c = 0; c < 30; c++) { Cell cell = row.getCell(c); if (cell == null) { @@ -1967,302 +1968,82 @@ public class OrderStatService { * 各砂站运输量统计表 */ public List trafficStatisticsOfEachSandStation( String stm, String etm,Integer invoice_type){ - List dataList = new ArrayList<>(); - //零散用户统计 - Record scattered=scatteredUsersAreNotClassified(stm,etm,invoice_type); - if(scattered.getBigDecimal("weight").compareTo(new BigDecimal("0"))>0||scattered.getBigDecimal("total_price").compareTo(new BigDecimal("0"))>0){ - Record scatteredSandStation=scatteredUsersClassificationStatistics(stm,etm,invoice_type); - scattered.setColumns(scatteredSandStation); - dataList.add(scattered); - } - //固定用户统计 - List recordList = fixedUserUnclassified(stm,etm,invoice_type); - if(recordList!=null&&!recordList.isEmpty()){ - for (Record record : recordList) { - if(record.getBigDecimal("weight").compareTo(new BigDecimal("0"))>0||record.getBigDecimal("total_price").compareTo(new BigDecimal("0"))>0){ - Integer customer_id=record.getInt("customer_id"); - Record sandStation=fixedUserClassificationStatistics(stm, etm,customer_id,invoice_type); - record.setColumns(sandStation); - } + List dataList = trafficStatistics(stm,etm,invoice_type); + if (dataList!=null&&!dataList.isEmpty()) { + for (Record oldRecord : dataList) { + Record newRecord =total(oldRecord); + oldRecord=newRecord; } } - dataList.addAll(recordList); return dataList; } - /** - * 零散用户 - */ - /** - * 固定用户不分类统计:统计各个固定用户在所有砂站的销量和销售额 - */ - public List fixedUserUnclassified(String stm, String etm,Integer invoice_type){ + + public List trafficStatistics(String stm, String etm,Integer invoice_type){ String paramsSql=""; if(invoice_type!=null){ paramsSql="and t.invoice_type=?\n"; } - String sql="SELECT\n" + - "a.customer_name,\n" + - " a.customer_id,\n" + - "ifnull(sum( a.weight ),0) weight,\n" + - "ifnull(sum( a.total_price ),0) total_price\n" + - "FROM\n" + - "(\n" + - "SELECT\n" + - "t.sn,t.customer_id,\n" + - "t.customer_name,\n" + - "t.weight,\n" + - "t.total_price,\n" + - "t.product_id,\n" + - "t.product_name \n" + - "FROM\n" + - "order_sale t \n" + - "WHERE\n" + - "t.state = 5 \n" + - "AND t.create_time >=? \n" + - "AND t.create_time <=? \n" + + String sql="select\n" + + "\tg.customer_id,\n" + + "\tifnull(c.name, '零散用户') customer_name,\n" + + "\tifnull(sum(g.weight), 0) weight,\n" + + "\tifnull(sum(g.total_price), 0) total_price,\n" + + "\tifnull(sum(case g.supermarket_id when 1 then g.weight end), 0) zw_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 2 then g.weight end), 0) tp_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 3 then g.weight end), 0) sc_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 4 then g.weight end), 0) sb_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 5 then g.weight end), 0) jr_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 6 then g.weight end), 0) yg_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 7 then g.weight end), 0) zwsc_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 8 then g.weight end), 0) ya_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 9 then g.weight end), 0) sl_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 10 then g.weight end), 0) hdw_xsl,\n" + + "\tifnull(sum(case g.supermarket_id when 1 then g.total_price end), 0) zw_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 2 then g.total_price end), 0) tp_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 3 then g.total_price end), 0) sc_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 4 then g.total_price end), 0) sb_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 5 then g.total_price end), 0) jr_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 6 then g.total_price end), 0) yg_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 7 then g.total_price end), 0) zwsc_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 8 then g.total_price end), 0) ya_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 9 then g.total_price end), 0) sl_xse,\n" + + "\tifnull(sum(case g.supermarket_id when 10 then g.total_price end), 0) hdw_xse\n" + + "from (\n" + + "\n" + + "\tselect\n" + + "\t\tifnull(t.customer_id, 0) customer_id,\n" + + "\t\tt.supermarket_id,\n" + + "\t\tifnull(sum(t.weight), 0) weight,\n" + + "\t\tifnull(sum(t.total_price), 0) total_price\n" + + "\tfrom order_sale t\n" + + "\twhere t.state = 5\n" + + "\tand t.create_time>= ?\n" + + "\tand t.create_time<= ?\n" + paramsSql+ - "AND t.isprepaid = 1 UNION\n" + - "SELECT\n" + - "t.sn,t.customer_id,\n" + - "t.customer_name,\n" + - "t.weight,\n" + - "t.total_price,\n" + - "t.product_id,\n" + - "t.product_name \n" + - "FROM\n" + - "order_temp t \n" + - "WHERE\n" + - "t.state = 5 \n" + - "AND t.create_time >=? \n" + - "AND t.create_time <=? \n" + + "\tgroup by t.customer_id, t.supermarket_id\n" + + "\tunion all\n" + + "\tselect\n" + + "\t\tifnull(t.customer_id, 0) customer_id,\n" + + "\t\tt.supermarket_id,\n" + + "\t\tifnull(sum(t.weight), 0) weight,\n" + + "\t\tifnull(sum(t.total_price), 0) total_price\n" + + "\tfrom order_temp t\n" + + "\twhere t.state = 5\n" + + "\tand t.create_time>= ?\n" + + "\tand t.create_time<= ?\n" + paramsSql+ - "AND t.isprepaid = 1 \n" + - ") a\n" + - " JOIN customer c ON c.id = a.customer_id \n" + - "GROUP BY\n" + - "a.customer_id,a.customer_name"; - + "\tgroup by t.customer_id, t.supermarket_id\n" + + ") g\n" + + "left join customer c on c.id = g.customer_id\n" + + "group by g.customer_id"; List recordList; - if(invoice_type!=null){ - recordList = Db.find(sql, stm, etm,invoice_type, stm, etm,invoice_type); + if(invoice_type!=null) { + recordList = Db.find(sql, stm,etm,invoice_type, stm,etm,invoice_type); }else { - recordList = Db.find(sql, stm, etm, stm, etm); + recordList = Db.find(sql, stm,etm, stm,etm); } - return recordList; } - - /** - * 固定用户分类统计:统计各个固定用户在不同砂站的销量以及销售额 - * @return - */ - public Record fixedUserClassificationStatistics(String stm, String etm,Integer customer_id,Integer invoice_type){ - String paramsSql=""; - if(invoice_type!=null){ - paramsSql="and t.invoice_type=?\n"; - } - String sql="SELECT\n" + - "ifnull( sum( CASE g.id WHEN 1 THEN g.weight END ), 0.00 ) zw_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 1 THEN g.total_price END ), 0.00 ) zw_xse,\n" + - "ifnull( sum( CASE g.id WHEN 2 THEN g.weight END ), 0.00 ) tp_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 2 THEN g.total_price END ), 0.00 ) tp_xse,\n" + - "ifnull( sum( CASE g.id WHEN 3 THEN g.weight END ), 0.00 ) sc_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 3 THEN g.total_price END ), 0.00 ) sc_xse,\n" + - "ifnull( sum( CASE g.id WHEN 4 THEN g.weight END ), 0.00 ) sb_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 4 THEN g.total_price END ), 0.00 ) sb_xse,\n" + - "ifnull( sum( CASE g.id WHEN 5 THEN g.weight END ), 0.00 ) jr_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 5 THEN g.total_price END ), 0.00 ) jr_xse,\n" + - "ifnull( sum( CASE g.id WHEN 6 THEN g.weight END ), 0.00 ) yg_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 6 THEN g.total_price END ), 0.00 ) yg_xse,\n" + - "ifnull( sum( CASE g.id WHEN 7 THEN g.weight END ), 0.00 ) zwsc_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 7 THEN g.total_price END ), 0.00 ) zwsc_xse,\n" + - "ifnull( sum( CASE g.id WHEN 8 THEN g.weight END ), 0.00 ) ya_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 8 THEN g.total_price END ), 0.00 ) ya_xse,\n" + - "ifnull( sum( CASE g.id WHEN 9 THEN g.weight END ), 0.00 ) sl_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 9 THEN g.total_price END ), 0.00 ) sl_xse \n" + - "FROM\n" + - "(\n" + - "SELECT\n" + - "m.id,\n" + - "n.customer_id,\n" + - "IFNULL( n.weight, 0.00 ) weight,\n" + - "IFNULL( n.total_price, 0.00 ) total_price \n" + - "FROM\n" + - "( SELECT id, NAME FROM supermarket ) m\n" + - "JOIN (\n" + - "SELECT\n" + - "a.id,\n" + - "sum( a.weight ) weight,\n" + - "sum( a.total_price ) total_price,\n" + - "a.customer_id \n" + - "FROM\n" + - "(\n" + - "SELECT\n" + - "t.sn,t.supermarket_id AS id,\n" + - "t.customer_id,\n" + - "t.customer_name,\n" + - "t.weight,\n" + - "t.total_price,\n" + - "t.product_id,\n" + - "t.product_name \n" + - "FROM\n" + - "order_sale t \n" + - "WHERE\n" + - "t.state = 5 \n" + - "AND t.create_time >=? \n" + - "AND t.create_time <=? \n" + - paramsSql+ - "AND t.isprepaid = 1 UNION\n" + - "SELECT\n" + - "t.sn,t.supermarket_id AS id,\n" + - "t.customer_id,\n" + - "t.customer_name,\n" + - "t.weight,\n" + - "t.total_price,\n" + - "t.product_id,\n" + - "t.product_name \n" + - "FROM\n" + - "order_temp t \n" + - "WHERE\n" + - "t.state = 5 \n" + - "AND t.create_time >=? \n" + - "AND t.create_time <=? \n" + - paramsSql+ - "AND t.isprepaid = 1 \n" + - ") a\n" + - "JOIN customer c ON c.id = a.customer_id \n" + - "WHERE\n" + - "a.customer_id = ? \n" + - "GROUP BY\n" + - "a.id \n" + - ") n ON m.id = n.id \n" + - ") g \n" + - "GROUP BY\n" + - "g.customer_id"; - Record record; - if(invoice_type!=null){ - record = Db.findFirst(sql, stm,etm,invoice_type, stm,etm,invoice_type, customer_id); - }else { - record = Db.findFirst(sql, stm,etm, stm,etm, customer_id); - } - return total(record); - } - /** - * 零散用户不分类统计:统计所有零散用户在所有砂站的销量和销售额 - */ - public Record scatteredUsersAreNotClassified(String stm, String etm,Integer invoice_type){ - String paramsSql=""; - if(invoice_type!=null){ - paramsSql="and t.invoice_type=?\n"; - } - String sql="SELECT '零散用户' customer_name, 0 customer_id,\n" + - "ifnull(sum( a.weight ),0) weight,\n" + - "ifnull(sum( a.total_price ),0) total_price\n" + - "FROM\n" + - "(\n" + - "SELECT\n" + - "t.sn,t.weight,\n" + - "t.total_price,\n" + - "t.product_id\n" + - "FROM\n" + - "order_sale t \n" + - "WHERE\n" + - "t.state = 5 \n" + - "AND t.create_time >=?\n" + - "AND t.create_time <=?\n" + - paramsSql+ - "AND t.isprepaid = 0 UNION\n" + - "SELECT\n" + - "t.sn,t.weight,\n" + - "t.total_price,\n" + - "t.product_id\n" + - "FROM\n" + - "order_temp t \n" + - "WHERE\n" + - "t.state = 5 \n" + - "AND t.create_time >=?\n" + - "AND t.create_time <=?\n" + - paramsSql+ - "AND t.isprepaid = 0 \n" + - ") a"; - Record record; - if(invoice_type!=null){ - record = Db.findFirst(sql, stm, etm,invoice_type, stm, etm,invoice_type); - }else { - record = Db.findFirst(sql, stm, etm, stm, etm); - } - - return record; - } - - /** - * 零散用户分类统计:统计所有零散用户在各个沙场的销量和销售额 - * @param stm - * @param etm - * @return - */ - public Record scatteredUsersClassificationStatistics(String stm, String etm,Integer invoice_type){ - String paramsSql=""; - if(invoice_type!=null){ - paramsSql="and t.invoice_type=?\n"; - } - String sql="select \n" + - "ifnull( sum( CASE g.id WHEN 1 THEN IFNULL( g.weight, 0 ) END ), 0 ) zw_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 1 THEN IFNULL( g.total_price, 0 ) END ), 0 ) zw_xse,\n" + - "ifnull( sum( CASE g.id WHEN 2 THEN IFNULL( g.weight, 0 ) END ), 0 ) tp_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 2 THEN IFNULL( g.total_price, 0 ) END ), 0 ) tp_xse,\n" + - "ifnull( sum( CASE g.id WHEN 3 THEN IFNULL( g.weight, 0 ) END ), 0 ) sc_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 3 THEN IFNULL( g.total_price, 0 ) END ), 0 ) sc_xse,\n" + - "ifnull( sum( CASE g.id WHEN 4 THEN IFNULL( g.weight, 0 ) END ), 0 ) sb_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 4 THEN IFNULL( g.total_price, 0 ) END ), 0 ) sb_xse,\n" + - "ifnull( sum( CASE g.id WHEN 5 THEN IFNULL( g.weight, 0 ) END ), 0 ) jr_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 5 THEN IFNULL( g.total_price, 0 ) END ), 0 ) jr_xse,\n" + - "ifnull( sum( CASE g.id WHEN 6 THEN IFNULL( g.weight, 0 ) END ), 0 ) yg_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 6 THEN IFNULL( g.total_price, 0 ) END ), 0 ) yg_xse,\n" + - "ifnull( sum( CASE g.id WHEN 7 THEN IFNULL( g.weight, 0 ) END ), 0 ) zwsc_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 7 THEN IFNULL( g.total_price, 0 ) END ), 0 ) zwsc_xse,\n" + - "ifnull( sum( CASE g.id WHEN 8 THEN IFNULL( g.weight, 0 ) END ), 0 ) ya_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 8 THEN IFNULL( g.total_price, 0 ) END ), 0 ) ya_xse,\n" + - "ifnull( sum( CASE g.id WHEN 9 THEN IFNULL( g.weight, 0 ) END ), 0 ) sl_xsl,\n" + - "ifnull( sum( CASE g.id WHEN 9 THEN IFNULL( g.total_price, 0 ) END ), 0 ) sl_xse \n" + - " from (\n" + - "select m.id,n.weight,n.total_price from \n" + - "( SELECT id, NAME FROM supermarket ) m join \n" + - "(\n" + - "SELECT\n" + - "t.sn,t.supermarket_id AS id,\n" + - "t.weight,\n" + - "t.total_price FROM\n" + - "order_sale t \n" + - "WHERE\n" + - "t.state = 5 \n" + - "AND t.create_time >=? \n" + - "AND t.create_time <=? \n" + - paramsSql+ - "AND t.isprepaid = 0 UNION\n" + - "SELECT\n" + - "t.sn,t.supermarket_id AS id,\n" + - "t.weight,\n" + - "t.total_price\n" + - "FROM\n" + - "order_temp t \n" + - "WHERE\n" + - "t.state = 5 \n" + - "AND t.create_time >=? \n" + - "AND t.create_time <=? \n" + - paramsSql+ - "AND t.isprepaid = 0 ) n on m.id=n.id\n" + - ") g"; - - Record record; - if(invoice_type!=null) { - record = Db.findFirst(sql, stm,etm,invoice_type, stm,etm,invoice_type); - }else { - record = Db.findFirst(sql, stm,etm, stm,etm); - } - return total(record); - } - /** * 合计 * @param record @@ -2280,8 +2061,9 @@ public class OrderStatService { record.set("jrhj_xsl",jrhj_xsl); record.set("jrhj_xse",jrhj_xse); //盐港合计 - BigDecimal yghj_xsl=new BigDecimal(record.getStr("yg_xsl")).add(new BigDecimal(record.getStr("ya_xsl"))); - BigDecimal yghj_xse=new BigDecimal(record.getStr("yg_xse")).add(new BigDecimal(record.getStr("ya_xse"))); + BigDecimal yghj_xsl=new BigDecimal(record.getStr("yg_xsl")).add(new BigDecimal(record.getStr("ya_xsl"))).add(new BigDecimal(record.getStr("hdw_xsl"))); + BigDecimal yghj_xse=new BigDecimal(record.getStr("yg_xse")).add(new BigDecimal(record.getStr("ya_xse"))).add(new BigDecimal(record.getStr("hdw_xse"))); + record.set("yghj_xsl",yghj_xsl); record.set("yghj_xse",yghj_xse); return record;