各取土场运输量统计

dev
wany 2025-03-25 16:45:26 +08:00
parent 4e79a6fbc0
commit ca995fd7de
2 changed files with 50 additions and 119 deletions

View File

@ -3237,47 +3237,51 @@ public class OrderStatService {
List<Record> sups = Db.find("select t.* from supermarket t \n" +
" where t.type = 1"); //取土场
if(sups == null || sups.isEmpty()){
return null;
}
String dynamicSql = "";
for (int s = 0; s < sups.size(); s++) {
Integer id = sups.get(s).getInt("id");
dynamicSql += "ifnull( sum( CASE WHEN g.sandfarm_id = " + id+ " THEN g.count END ), 0 ) xsc_"+ id +",\n" +
" ifnull( sum( CASE WHEN g.sandfarm_id = " + id+ " THEN g.source_weight END ), 0 ) xss_"+ id +",\n" +
" ifnull( sum( CASE WHEN g.sandfarm_id = " + id+ " THEN g.weight END ), 0 ) xsw_"+ id +",\n" +
" ifnull( sum( CASE WHEN g.sandfarm_id = " + id+ " THEN g.trans_price END ), 0 ) xst_"+ id +",\n";
}
String sql = "SELECT\n" +
" g.trans_co_id,\n" +
" g.license,\n" +
" ifnull( sum( g.count ), 0 ) count,\n" +
" ifnull( sum( g.source_weight ), 0 ) source_weight,\n" +
" ifnull( sum( g.weight ), 0 ) weight,\n" +
" ifnull( sum( g.trans_price ), 0 ) total_price,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 2 THEN g.count END ), 0 ) xsc_2,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 2 THEN g.source_weight END ), 0 ) xss_2,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 2 THEN g.weight END ), 0 ) xsw_2,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 2 THEN g.trans_price END ), 0 ) xst_2\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 3 THEN g.count END ), 0 ) xsc_3,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 3 THEN g.source_weight END ), 0 ) xss_3,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 3 THEN g.weight END ), 0 ) xsw_3,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 3 THEN g.trans_price END ), 0 ) xst_3,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 4 THEN g.count END ), 0 ) xsc_4,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 4 THEN g.source_weight END ), 0 ) xss_4,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 4 THEN g.weight END ), 0 ) xsw_4,\n" +
" ifnull( sum( CASE WHEN g.supermarket_id = 4 THEN g.trans_price END ), 0 ) xst_4\n" +
dynamicSql +
" ifnull( sum( g.trans_price ), 0 ) trans_price\n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" ifnull( t.trans_co_id, ifnull( ot.trans_co_id, 0 ) ) trans_co_id,\n" +
" t.supermarket_id,\n" +
" t.truck_license license,\n" +
" ifnull( ot.trans_co_id, ifnull( ot.trans_co_id, 0 ) ) trans_co_id,\n" +
" ot.sandfarm_id,\n" +
" ot.truck_license license,\n" +
" ifnull( count( ot.sn ), 0 ) count,\n" +
" ifnull( sum( t.weight ), 0 ) weight,\n" +
" ifnull( sum( ot.weight ), 0 ) source_weight,\n" +
" ifnull( sum( ot.trans_price ), 0 ) trans_price \n" +
" FROM\n" +
" order_temp t \n" +
" LEFT JOIN order_transfer ot ON ot.old_sn = t.sn " +
" order_transfer ot \n" +
" LEFT JOIN order_temp t ON ot.old_sn = t.sn " +
" WHERE\n" +
" t.create_time >= ? \n" +
" AND t.create_time <= ? \n" +
" AND t.state = 5 " +
" ot.create_time >= ? \n" +
" AND ot.create_time <= ? \n" +
" AND ot.state = 5 " +
" GROUP BY\n" +
" t.trans_co_id,\n" +
" t.truck_license,\n" +
" t.supermarket_id\n" +
" ) g LEFT JOIN supermarket s ON s.id = g.supermarket_id \n" +
" ot.trans_co_id,\n" +
" ot.truck_license,\n" +
" ot.sandfarm_id\n" +
" ) g LEFT JOIN supermarket s ON s.id = g.sandfarm_id \n" +
" WHERE s.type = 1 \n" +
"GROUP BY\n" +
" g.trans_co_id," +
@ -3335,22 +3339,6 @@ public class OrderStatService {
List<Record> typelist = Db.find("select id trans_co_id, name trans_name from transport_company ORDER BY ID ");
double all_count = 0.0;
double all_weight = 0.0;
double all_trans_price = 0.0;
double all_xst_2 = 0.0;
double all_xsc_2 = 0.0;
double all_xss_2 = 0.0;
double all_xsw_2 = 0.0;
double all_xst_3 = 0.0;
double all_xsc_3 = 0.0;
double all_xss_3 = 0.0;
double all_xsw_3 = 0.0;
double all_xst_4 = 0.0;
double all_xsc_4 = 0.0;
double all_xss_4 = 0.0;
double all_xsw_4 = 0.0;
typelist.add(new Record().set("trans_co_id", 0).set("trans_name", "未分类"));
for (Record record : typelist) {
@ -3360,71 +3348,17 @@ public class OrderStatService {
List<Record> list = typemap.get(trans_co_id);
record.set("children", list);
double count = 0.0;
double weight = 0.0;
double trans_price = 0.0;
double xst_2 = 0.0; // 运输费(元)
double xsc_2 = 0.0; // 车次
double xss_2 = 0.0; // 总进场(吨)
double xsw_2 = 0.0; // 总出场(吨)
double xst_3 = 0.0;
double xsc_3 = 0.0;
double xss_3 = 0.0;
double xsw_3 = 0.0;
double xst_4 = 0.0;
double xsc_4 = 0.0;
double xss_4 = 0.0;
double xsw_4 = 0.0;
for (Record r : list) {
count += DataUtil.getDefaultByRecord(r, "count");
weight += DataUtil.getDefaultByRecord(r, "weight");
trans_price += DataUtil.getDefaultByRecord(r, "trans_price");
xsc_2 += DataUtil.getDefaultByRecord(r, "xsc_2");
xst_2 += DataUtil.getDefaultByRecord(r, "xst_2");
xss_2 += DataUtil.getDefaultByRecord(r, "xss_2");
xsw_2 += DataUtil.getDefaultByRecord(r, "xsw_2");
xsc_3 += DataUtil.getDefaultByRecord(r, "xsc_3");
xst_3 += DataUtil.getDefaultByRecord(r, "xst_3");
xss_3 += DataUtil.getDefaultByRecord(r, "xss_3");
xsw_3 += DataUtil.getDefaultByRecord(r, "xse_3");
xsc_4 += DataUtil.getDefaultByRecord(r, "xsc_4");
xst_4 += DataUtil.getDefaultByRecord(r, "xst_4");
xss_4 += DataUtil.getDefaultByRecord(r, "xss_4");
xsw_4 += DataUtil.getDefaultByRecord(r, "xse_4");
all_count += DataUtil.getDefaultByRecord(r, "count");
all_weight += DataUtil.getDefaultByRecord(r, "weight");
all_trans_price += DataUtil.getDefaultByRecord(r, "trans_price");
all_xsc_2 += DataUtil.getDefaultByRecord(r, "xsc_2");
all_xst_2 += DataUtil.getDefaultByRecord(r, "xst_2");
all_xss_2 += DataUtil.getDefaultByRecord(r, "xss_2");
all_xsw_2 += DataUtil.getDefaultByRecord(r, "xsw_2");
all_xsc_3 += DataUtil.getDefaultByRecord(r, "xsc_3");
all_xst_3 += DataUtil.getDefaultByRecord(r, "xst_3");
all_xss_3 += DataUtil.getDefaultByRecord(r, "xss_3");
all_xsw_3 += DataUtil.getDefaultByRecord(r, "xse_3");
all_xsc_4 += DataUtil.getDefaultByRecord(r, "xsc_4");
all_xst_4 += DataUtil.getDefaultByRecord(r, "xst_4");
all_xss_4 += DataUtil.getDefaultByRecord(r, "xss_4");
all_xsw_4 += DataUtil.getDefaultByRecord(r, "xse_4");
record.set("count", list.stream().map(o->o.getBigDecimal("count")).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("source_weight", list.stream().map(o->o.getBigDecimal("source_weight")).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("trans_price", list.stream().map(o->o.getBigDecimal("trans_price")).reduce(BigDecimal.ZERO, BigDecimal::add));
for (Record sup : sups) {
Integer id = sup.getInt("id");
record.set("xsc_"+id, list.stream().map(o->o.getBigDecimal("xsc_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("xst_"+id, list.stream().map(o->o.getBigDecimal("xst_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("xss_"+id, list.stream().map(o->o.getBigDecimal("xss_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("xsw_"+id, list.stream().map(o->o.getBigDecimal("xsw_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
}
record.set("count", count);
record.set("weight", weight);
record.set("trans_price", trans_price);
record.set("xsc_2", xsc_2);
record.set("xst_2", xst_2);
record.set("xss_2", xss_2);
record.set("xsw_2", xsw_2);
record.set("xst_3", xst_3);
record.set("xsc_3", xsc_3);
record.set("xss_3", xss_3);
record.set("xsw_3", xsw_3);
record.set("xst_4", xst_4);
record.set("xsc_4", xsc_4);
record.set("xss_4", xss_4);
record.set("xsw_4", xsw_4);
}
}
@ -3436,21 +3370,16 @@ public class OrderStatService {
record.set("trans_co_id", -1);
record.set("trans_name", "合计");
record.set("count", all_count);
record.set("weight", all_weight);
record.set("trans_price", all_trans_price);
record.set("xst_2", all_xst_2);
record.set("xsc_2", all_xsc_2);
record.set("xss_2", all_xss_2);
record.set("xsw_2", all_xsw_2);
record.set("xsc_3", all_xsc_3);
record.set("xst_3", all_xst_3);
record.set("xss_3", all_xss_3);
record.set("xsw_3", all_xsw_3);
record.set("xsc_4", all_xsc_4);
record.set("xst_4", all_xst_4);
record.set("xss_4", all_xss_4);
record.set("xsw_4", all_xsw_4);
record.set("count", trans_co_list.stream().map(o->o.getBigDecimal("count")).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("source_weight", trans_co_list.stream().map(o->o.getBigDecimal("source_weight")).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("trans_price", trans_co_list.stream().map(o->o.getBigDecimal("trans_price")).reduce(BigDecimal.ZERO, BigDecimal::add));
for (Record sup : sups) {
Integer id = sup.getInt("id");
record.set("xsc_"+id, trans_co_list.stream().map(o->o.getBigDecimal("xsc_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("xst_"+id, trans_co_list.stream().map(o->o.getBigDecimal("xst_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("xss_"+id, trans_co_list.stream().map(o->o.getBigDecimal("xss_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("xsw_"+id, trans_co_list.stream().map(o->o.getBigDecimal("xsw_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
}
typelist.add(record);
@ -5199,3 +5128,4 @@ public class OrderStatService {
}
}
}

View File

@ -556,6 +556,7 @@ public class OrderStatController extends BaseController {
}
}
/**
*
*/