各砂站运输量统计表优化

dev
xiaocui 2021-05-21 12:54:55 +08:00
parent 0387562ee8
commit 86ac3c6f0f
1 changed files with 72 additions and 290 deletions

View File

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