2020-09-18 17:10:33 +08:00
|
|
|
package com.cowr.ssjygl.overall;
|
|
|
|
|
|
|
|
|
|
import com.cowr.common.enums.OrderStateEnum;
|
|
|
|
|
import com.cowr.common.utils.DateTimeUtil;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
2020-09-18 18:04:07 +08:00
|
|
|
import java.util.ArrayList;
|
2020-09-18 17:10:33 +08:00
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
2020-09-18 18:04:07 +08:00
|
|
|
import java.util.List;
|
2020-09-18 17:10:33 +08:00
|
|
|
|
|
|
|
|
public class OverallService {
|
|
|
|
|
public static OverallService me = new OverallService();
|
|
|
|
|
|
2020-09-18 17:42:20 +08:00
|
|
|
/*
|
|
|
|
|
/overall/stat?token=
|
|
|
|
|
{
|
|
|
|
|
"code": 200,
|
|
|
|
|
"data": {
|
|
|
|
|
"ordercluster": {
|
|
|
|
|
"before_month_total_weight": 446.00, // 前月配额重量
|
|
|
|
|
"before_day_total_weight": 693.00, // 前日配额重量
|
|
|
|
|
"month_total_weight": 7930.00, // 当月配额重量
|
|
|
|
|
"day_total_weight": 160.00, // 当日配额重量
|
2020-09-24 19:57:38 +08:00
|
|
|
"total_weight": 8376.00, // 总配额重量
|
|
|
|
|
|
|
|
|
|
"month_truck_cnt": 49, // 当月分配车次
|
|
|
|
|
"day_truck_cnt": 0, // 当日分配车次
|
|
|
|
|
"truck_cnt": 53, // 总分配车次
|
|
|
|
|
"before_month_truck_cnt": 4, // 前月分配车次
|
|
|
|
|
"before_daytruck__cnt": 0 // 前日分配撤职
|
2020-09-18 17:42:20 +08:00
|
|
|
],
|
|
|
|
|
"by_supermarket": [
|
|
|
|
|
{
|
|
|
|
|
"supermarket_id": 1,
|
|
|
|
|
"supermarket_name": "竹瓦",
|
|
|
|
|
"supermarket_name2": "竹瓦",
|
|
|
|
|
|
|
|
|
|
"total_price": 43826.40, // 超市总销售额
|
|
|
|
|
"weight": 486.96, // 超市总销售重量
|
|
|
|
|
"truck_cnt": 18, // 超市总运输车次
|
|
|
|
|
|
|
|
|
|
"month_total_price": 43826.40, // 当月超市总销售额
|
|
|
|
|
"month_weight": 486.96, // 当月超市销售重量
|
|
|
|
|
"month_truck_cnt": 18, // 当月超市运输车次
|
|
|
|
|
"day_total_price": 0.00, // 当日超市销售总额
|
|
|
|
|
"day_weight": 0.00, // 当日超市销售重量
|
|
|
|
|
"day_truck_cnt": 0 // 当日超市运输车次
|
|
|
|
|
|
|
|
|
|
"before_month_total_price": 0.00, // 前月超市总销售额
|
|
|
|
|
"before_month_weight": 0.00, // 前月超市总销售重量
|
|
|
|
|
"before_month_truck_cnt": 0, // 前月超市运输车次
|
|
|
|
|
"before_day_total_price": 1796.40, // 前日超市销售总额
|
|
|
|
|
"before_day_weight": 19.96, // 前日超市销售重量
|
|
|
|
|
"before_day_truck_cnt": 2, // 前日超市运输车次
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
"by_customer": [
|
|
|
|
|
{
|
|
|
|
|
"total_price": 41310.00,
|
|
|
|
|
"month_total_price": 41310.00,
|
|
|
|
|
"before_day_truck_cnt": 0,
|
|
|
|
|
"month_truck_cnt": 14,
|
|
|
|
|
"truck_cnt": 14,
|
|
|
|
|
"day_total_price": 0.00,
|
|
|
|
|
"weight": 459.00,
|
|
|
|
|
"before_day_total_price": 0.00,
|
|
|
|
|
"month_weight": 459.00,
|
|
|
|
|
"before_month_total_price": 0.00,
|
|
|
|
|
"before_month_weight": 0.00,
|
|
|
|
|
"day_weight": 0.00,
|
|
|
|
|
"before_month_truck_cnt": 0,
|
|
|
|
|
"customer_name": "零散客户",
|
|
|
|
|
"before_day_weight": 0.00,
|
|
|
|
|
"day_truck_cnt": 0
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"total_price": 3330.00,
|
|
|
|
|
"month_total_price": 3330.00,
|
|
|
|
|
"before_day_truck_cnt": 0,
|
|
|
|
|
"month_truck_cnt": 1,
|
|
|
|
|
"truck_cnt": 1,
|
|
|
|
|
"day_total_price": 0.00,
|
|
|
|
|
"weight": 37.00,
|
|
|
|
|
"before_day_total_price": 0.00,
|
|
|
|
|
"month_weight": 37.00,
|
|
|
|
|
"before_month_total_price": 0.00,
|
|
|
|
|
"before_month_weight": 0.00,
|
|
|
|
|
"day_weight": 0.00,
|
|
|
|
|
"before_month_truck_cnt": 0,
|
|
|
|
|
"customer_name": "中铁十六局集团有限公司黄黄高铁项目部(一标)",
|
|
|
|
|
"customer_id": 8,
|
|
|
|
|
"before_day_weight": 0.00,
|
|
|
|
|
"day_truck_cnt": 0
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"total_price": 3690.00,
|
|
|
|
|
"month_total_price": 3690.00,
|
|
|
|
|
"before_day_truck_cnt": 0,
|
|
|
|
|
"month_truck_cnt": 3,
|
|
|
|
|
"truck_cnt": 3,
|
|
|
|
|
"day_total_price": 0.00,
|
|
|
|
|
"weight": 41.00,
|
|
|
|
|
"before_day_total_price": 0.00,
|
|
|
|
|
"month_weight": 41.00,
|
|
|
|
|
"before_month_total_price": 0.00,
|
|
|
|
|
"before_month_weight": 0.00,
|
|
|
|
|
"day_weight": 0.00,
|
|
|
|
|
"before_month_truck_cnt": 0,
|
|
|
|
|
"customer_name": "湖北碁润商砼有限公司",
|
|
|
|
|
"customer_id": 12,
|
|
|
|
|
"before_day_weight": 0.00,
|
|
|
|
|
"day_truck_cnt": 0
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-24 19:57:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
select count(t.sn) cnt, sum(t.weight) weight, sum(t.total_price) total_price, date_format(t.create_time, '%Y-%m-%d') date from order_temp t
|
|
|
|
|
where t.state = 5
|
|
|
|
|
group by date
|
|
|
|
|
|
2020-09-18 17:42:20 +08:00
|
|
|
*/
|
2020-09-18 18:04:07 +08:00
|
|
|
public Record stat(Integer supermarket_id){
|
2020-09-18 17:10:33 +08:00
|
|
|
long st = System.currentTimeMillis();
|
|
|
|
|
Record out = new Record();
|
|
|
|
|
|
2020-09-18 18:04:07 +08:00
|
|
|
Date now = new Date();
|
|
|
|
|
List<Object> params1 = new ArrayList<>();
|
|
|
|
|
List<Object> params2 = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
params1.add(OrderStateEnum.INVALID.getStateid());
|
|
|
|
|
params2.add(OrderStateEnum.RECEIVED.getStateid());
|
|
|
|
|
|
2020-09-18 17:10:33 +08:00
|
|
|
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
|
c.setTime(now);
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
|
|
|
|
|
|
|
String nowmonttm = DateTimeUtil.sd.get().format(now); // 当月
|
|
|
|
|
String nowdaytm = DateTimeUtil.sdf.get().format(now); // 当日
|
|
|
|
|
String predaytm = DateTimeUtil.sdf.get().format(c.getTime()); // 前一日
|
|
|
|
|
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
|
c.add(Calendar.MONTH, -1);
|
|
|
|
|
|
|
|
|
|
String premonthtm = DateTimeUtil.sd.get().format(c.getTime()); // 前一月
|
|
|
|
|
|
2020-09-18 18:04:07 +08:00
|
|
|
String sql_ordercluster = "select \n" +
|
2020-09-18 17:10:33 +08:00
|
|
|
" sum(t.total_weight) total_weight, \n" +
|
|
|
|
|
" sum(case when t.cutoff_time like '" + nowmonttm +"%' then t.total_weight end ) month_total_weight, \n" +
|
|
|
|
|
" sum(case when t.cutoff_time like '" + nowdaytm + "%' then t.total_weight end ) day_total_weight, \n" +
|
|
|
|
|
" sum(case when t.cutoff_time like '" + premonthtm + "%' then t.total_weight end ) before_month_total_weight, \n" +
|
|
|
|
|
" sum(case when t.cutoff_time like '" + predaytm + "%' then t.total_weight end ) before_day_total_weight \n" +
|
|
|
|
|
" from ordercluster t\n" +
|
2020-09-18 18:04:07 +08:00
|
|
|
" where t.state < ?";
|
2020-09-18 17:10:33 +08:00
|
|
|
|
2020-09-18 18:04:07 +08:00
|
|
|
String sql_ordercluster_truck = "select\n" +
|
2020-09-24 19:57:38 +08:00
|
|
|
" count(t.id) truck_cnt,\n" +
|
|
|
|
|
" sum(case when t.change_time like '" + nowmonttm +"%' then 1 else 0 end) month_truck_cnt,\n" +
|
|
|
|
|
" sum(case when t.change_time like '" + nowdaytm + "%' then 1 else 0 end) day_truck_cnt,\n" +
|
|
|
|
|
" sum(case when t.change_time like '" + premonthtm + "%' then 1 else 0 end) before_month_truck_cnt,\n" +
|
|
|
|
|
" sum(case when t.change_time like '" + predaytm + "%' then 1 else 0 end) before_day_truck_cnt\n" +
|
2020-09-18 17:10:33 +08:00
|
|
|
" from ordercluster_truck t\n" +
|
|
|
|
|
" left join ordercluster c on c.id = t.ordercluster_id\n" +
|
2020-09-18 18:04:07 +08:00
|
|
|
" where c.state < ?";
|
|
|
|
|
|
|
|
|
|
String sql_by_customer = "\n" +
|
|
|
|
|
" select\n" +
|
|
|
|
|
" t.customer_id,\n" +
|
|
|
|
|
" ifnull(max(case when t.customer_id is null then null else t.customer_name end), '零散客户') customer_name,\n" +
|
|
|
|
|
" sum(t.weight) weight,\n" +
|
|
|
|
|
" sum(t.total_price) total_price,\n" +
|
|
|
|
|
" count(*) truck_cnt,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + nowmonttm +"%' then t.weight end), 0) month_weight,\n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.weight end), 0) day_weight,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + nowmonttm +"%' then t.total_price end), 0) month_total_price,\n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.total_price end), 0) day_total_price,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" count(case when t.create_time like '" + nowmonttm +"%' then t.sn end) month_truck_cnt,\n" +
|
|
|
|
|
" count(case when t.create_time like '" + nowdaytm + "%' then t.sn end) day_truck_cnt,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + premonthtm + "%' then t.weight end), 0) before_month_weight,\n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + predaytm + "%' then t.weight end), 0) before_day_weight,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + premonthtm + "%' then t.total_price end), 0) before_month_total_price,\n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + predaytm + "%' then t.total_price end), 0) before_day_total_price,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" count(case when t.create_time like '" + premonthtm + "%' then t.sn end) before_month_truck_cnt,\n" +
|
|
|
|
|
" count(case when t.create_time like '" + predaytm + "%' then t.sn end) before_day_truck_cnt\n" +
|
|
|
|
|
" from order_temp t\n" +
|
|
|
|
|
" where t.state = ?\n";
|
|
|
|
|
|
2020-09-18 17:10:33 +08:00
|
|
|
|
2020-09-18 18:04:07 +08:00
|
|
|
String sql_by_supermarket = " select \n" +
|
2020-09-18 17:42:20 +08:00
|
|
|
" s.id supermarket_id,\n" +
|
|
|
|
|
" s.name supermarket_name,\n" +
|
|
|
|
|
" s.name2 supermarket_name2,\n" +
|
|
|
|
|
" ifnull(a.total_price, 0) total_price,\n" +
|
|
|
|
|
" ifnull(a.month_total_price, 0) month_total_price,\n" +
|
|
|
|
|
" ifnull(a.before_day_truck_cnt, 0) before_day_truck_cnt,\n" +
|
|
|
|
|
" ifnull(a.month_truck_cnt, 0) month_truck_cnt,\n" +
|
|
|
|
|
" ifnull(a.truck_cnt, 0) truck_cnt,\n" +
|
|
|
|
|
" ifnull(a.day_total_price, 0) day_total_price,\n" +
|
|
|
|
|
" ifnull(a.weight, 0) weight,\n" +
|
|
|
|
|
" ifnull(a.before_day_total_price, 0) before_day_total_price,\n" +
|
|
|
|
|
" ifnull(a.month_weight, 0) month_weight,\n" +
|
|
|
|
|
" ifnull(a.before_month_total_price, 0) before_month_total_price,\n" +
|
|
|
|
|
" ifnull(a.before_month_weight, 0) before_month_weight,\n" +
|
|
|
|
|
" ifnull(a.day_weight, 0) day_weight,\n" +
|
|
|
|
|
" ifnull(a.before_month_truck_cnt, 0) before_month_truck_cnt,\n" +
|
|
|
|
|
" ifnull(a.before_day_weight, 0) before_day_weight,\n" +
|
|
|
|
|
" ifnull(a.day_truck_cnt, 0) day_truck_cnt" +
|
|
|
|
|
" from supermarket s\n" +
|
|
|
|
|
" left join (\n" +
|
|
|
|
|
" select\n" +
|
|
|
|
|
" t.supermarket_id,\n" +
|
|
|
|
|
" sum(t.weight) weight,\n" +
|
|
|
|
|
" sum(t.total_price) total_price,\n" +
|
|
|
|
|
" count(*) truck_cnt,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + nowmonttm +"%' then t.weight end), 0) month_weight,\n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.weight end), 0) day_weight,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + nowmonttm +"%' then t.total_price end), 0) month_total_price,\n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.total_price end), 0) day_total_price,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" count(case when t.create_time like '" + nowmonttm +"%' then t.sn end) month_truck_cnt,\n" +
|
|
|
|
|
" count(case when t.create_time like '" + nowdaytm + "%' then t.sn end) day_truck_cnt,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + premonthtm + "%' then t.weight end), 0) before_month_weight,\n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + predaytm + "%' then t.weight end), 0) before_day_weight,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + premonthtm + "%' then t.total_price end), 0) before_month_total_price,\n" +
|
|
|
|
|
" ifnull(sum(case when t.create_time like '" + predaytm + "%' then t.total_price end), 0) before_day_total_price,\n" +
|
|
|
|
|
" \n" +
|
|
|
|
|
" count(case when t.create_time like '" + premonthtm + "%' then t.sn end) before_month_truck_cnt,\n" +
|
|
|
|
|
" count(case when t.create_time like '" + predaytm + "%' then t.sn end) before_day_truck_cnt\n" +
|
|
|
|
|
" from order_temp t\n" +
|
2020-09-18 18:04:07 +08:00
|
|
|
" where t.state = ?\n";
|
2020-09-18 17:10:33 +08:00
|
|
|
|
2020-09-18 18:04:07 +08:00
|
|
|
if(supermarket_id != null){
|
|
|
|
|
sql_ordercluster += " and t.supermarket_id = ? ";
|
|
|
|
|
sql_ordercluster_truck += " and c.supermarket_id = ? ";
|
|
|
|
|
sql_by_customer += " and t.supermarket_id = ? ";
|
|
|
|
|
|
|
|
|
|
params1.add(supermarket_id);
|
|
|
|
|
params2.add(supermarket_id);
|
|
|
|
|
|
|
|
|
|
out.set("by_supermarket", Db.find(sql_by_supermarket +
|
|
|
|
|
" and t.supermarket_id = ? " +
|
|
|
|
|
" group by t.supermarket_id\n" +
|
|
|
|
|
" ) a on a.supermarket_id = s.id \n" +
|
|
|
|
|
" where s.id = ? ", OrderStateEnum.RECEIVED.getStateid(), supermarket_id, supermarket_id));
|
|
|
|
|
}else{
|
|
|
|
|
out.set("by_supermarket", Db.find( sql_by_supermarket +
|
|
|
|
|
" group by t.supermarket_id\n" +
|
|
|
|
|
" ) a on a.supermarket_id = s.id", OrderStateEnum.RECEIVED.getStateid()));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 19:57:38 +08:00
|
|
|
Record ocout = Db.findFirst(sql_ordercluster, params1.toArray());
|
|
|
|
|
Record oct = Db.findFirst(sql_ordercluster_truck, params1.toArray());
|
|
|
|
|
|
|
|
|
|
ocout.setColumns(oct);
|
|
|
|
|
|
|
|
|
|
out.set("ordercluster", ocout);
|
2020-09-18 18:04:07 +08:00
|
|
|
out.set("by_customer", Db.find(sql_by_customer + " group by t.customer_id", params2.toArray()));
|
2020-09-18 17:10:33 +08:00
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
}
|