lisai17@sina.com 2020-09-18 17:10:33 +08:00
parent 6701fd5e88
commit 386140b7aa
4 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,10 @@
package com.cowr.ssjygl.overall;
import com.cowr.common.view.Result;
import com.jfinal.core.Controller;
public class OverallController extends Controller {
public void stat(){
renderJson(Result.success(OverallService.me.stat()));
}
}

View File

@ -0,0 +1,113 @@
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;
}
}

View File

@ -48,6 +48,7 @@ import com.cowr.model.Supermarket;
import com.cowr.ssjygl.CacheData;
import com.cowr.ssjygl.cctv.CctvController;
import com.cowr.local.ssjygl.prepay.PrepayController;
import com.cowr.ssjygl.overall.OverallController;
import com.cowr.ssjygl.stat.purchase.OrderPurchaseStatController;
import com.cowr.local.ssjygl.stat.sale.OrderStatController;
import com.cowr.ssjygl.stat.transfer.OrderTransferStatController;
@ -163,6 +164,7 @@ public class Config extends JFinalConfig {
me.add("/cache", CacheController.class);
me.add("/camera", CameraController.class);
me.add("/supcctv", CctvController.class);
me.add("/overall", OverallController.class);
// -- 权限系统
me.add("/sysuser", SysuserController.class);

View File

@ -42,6 +42,7 @@ import com.cowr.common.Const;
import com.cowr.common.plugin.QuartzPlugin;
import com.cowr.ssjygl.cctv.CctvController;
import com.cowr.service.ssjygl.prepay.PrepayController;
import com.cowr.ssjygl.overall.OverallController;
import com.cowr.ssjygl.stat.purchase.OrderPurchaseStatController;
import com.cowr.service.ssjygl.stat.sale.OrderStatController;
import com.cowr.ssjygl.stat.transfer.OrderTransferStatController;
@ -133,6 +134,7 @@ public class Config extends JFinalConfig {
me.add("/", HomeController.class);
me.add("/cache", CacheController.class);
me.add("/supcctv", CctvController.class);
me.add("/overall", OverallController.class);
// -- 权限系统
me.add("/sysuser", SysuserController.class);