lisai17@sina.com 2020-09-18 18:04:07 +08:00
parent 3a2651834d
commit 92f3a501ed
5 changed files with 94 additions and 43 deletions

View File

@ -5,8 +5,10 @@ import com.cowr.common.utils.DateTimeUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class OverallService {
public static OverallService me = new OverallService();
@ -118,11 +120,17 @@ public class OverallService {
}
}
*/
public Record stat(){
public Record stat(Integer supermarket_id){
long st = System.currentTimeMillis();
Record out = new Record();
Date now = new Date();
List<Object> params1 = new ArrayList<>();
List<Object> params2 = new ArrayList<>();
params1.add(OrderStateEnum.INVALID.getStateid());
params2.add(OrderStateEnum.RECEIVED.getStateid());
Calendar c = Calendar.getInstance();
c.setTime(now);
@ -137,16 +145,16 @@ public class OverallService {
String premonthtm = DateTimeUtil.sd.get().format(c.getTime()); // 前一月
out.set("ordercluster", Db.findFirst("select \n" +
String sql_ordercluster = "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()));
" where t.state < ?";
out.set("ordercluster_truck", Db.find("select\n" +
String sql_ordercluster_truck = "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" +
@ -154,9 +162,38 @@ public class OverallService {
" 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()));
" where c.state < ?";
out.set("by_supermarket", Db.find(" select \n" +
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";
String sql_by_supermarket = " select \n" +
" s.id supermarket_id,\n" +
" s.name supermarket_name,\n" +
" s.name2 supermarket_name2,\n" +
@ -201,38 +238,30 @@ public class OverallService {
" 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\n" +
" ) a on a.supermarket_id = s.id;", OrderStateEnum.RECEIVED.getStateid()));
" where t.state = ?\n";
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" +
" \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()));
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()));
}
out.set("ordercluster", Db.findFirst(sql_ordercluster, params1.toArray()));
out.set("ordercluster_truck", Db.find(sql_ordercluster_truck, params1.toArray()));
out.set("by_customer", Db.find(sql_by_customer + " group by t.customer_id", params2.toArray()));
return out;
}

View File

@ -48,7 +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.local.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;

View File

@ -0,0 +1,21 @@
package com.cowr.local.ssjygl.overall;
import com.cowr.common.view.Result;
import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService;
import com.cowr.model.Sysuser;
import com.cowr.ssjygl.overall.OverallService;
import com.jfinal.core.Controller;
public class OverallController extends Controller {
public void stat(){
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
// 是客户账户
if (tokenuser == null || tokenuser.getEntityId() == null) {
renderJson(Result.noauth());
return;
}
renderJson(Result.success(OverallService.me.stat(tokenuser.getEntityId())));
}
}

View File

@ -42,7 +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.service.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;

View File

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