114 lines
6.9 KiB
Java
114 lines
6.9 KiB
Java
|
|
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;
|
||
|
|
|
||
|
|
import java.util.Calendar;
|
||
|
|
import java.util.Date;
|
||
|
|
|
||
|
|
public class OverallService {
|
||
|
|
public static OverallService me = new OverallService();
|
||
|
|
|
||
|
|
public Record stat(){
|
||
|
|
long st = System.currentTimeMillis();
|
||
|
|
Record out = new Record();
|
||
|
|
|
||
|
|
Date now = new Date();
|
||
|
|
|
||
|
|
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()); // 前一月
|
||
|
|
|
||
|
|
out.set("ordercluster", Db.findFirst("select \n" +
|
||
|
|
" 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" +
|
||
|
|
" where t.state < ?", OrderStateEnum.INVALID.getStateid()));
|
||
|
|
|
||
|
|
out.set("ordercluster_truck", Db.find("select\n" +
|
||
|
|
" count(t.id) cnt,\n" +
|
||
|
|
" sum(case when t.change_time like '" + nowmonttm +"%' then 1 else 0 end) month_cnt,\n" +
|
||
|
|
" sum(case when t.change_time like '" + nowdaytm + "%' then 1 else 0 end) day_cnt,\n" +
|
||
|
|
" sum(case when t.change_time like '" + premonthtm + "%' then 1 else 0 end) before_month_cnt,\n" +
|
||
|
|
" sum(case when t.change_time like '" + predaytm + "%' then 1 else 0 end) before_day_cnt\n" +
|
||
|
|
" from ordercluster_truck t\n" +
|
||
|
|
" left join ordercluster c on c.id = t.ordercluster_id\n" +
|
||
|
|
" where c.state < ?", OrderStateEnum.INVALID.getStateid()));
|
||
|
|
|
||
|
|
out.set("by_supermarket", Db.find("\n" +
|
||
|
|
"select\n" +
|
||
|
|
" t.supermarket_id,\n" +
|
||
|
|
" sum(t.weight) weight,\n" +
|
||
|
|
" sum(t.total_price) total_price,\n" +
|
||
|
|
" count(*) truck_cnt,\n" +
|
||
|
|
" count(distinct t.truck_license) truck_cnt_only,\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" +
|
||
|
|
" group by t.supermarket_id", OrderStateEnum.RECEIVED.getStateid()));
|
||
|
|
|
||
|
|
out.set("by_customer", Db.find("\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" +
|
||
|
|
" count(distinct t.truck_license) truck_cnt_only,\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" +
|
||
|
|
"group by t.customer_id", OrderStateEnum.RECEIVED.getStateid()));
|
||
|
|
|
||
|
|
return out;
|
||
|
|
}
|
||
|
|
}
|