lisai17@sina.com 2020-11-05 10:45:53 +08:00
parent cc6db32ede
commit 3347b7ed65
2 changed files with 100 additions and 5 deletions

View File

@ -3,14 +3,12 @@ package com.cowr.ssjygl.overall;
import com.cowr.common.Const; import com.cowr.common.Const;
import com.cowr.common.enums.OrderStateEnum; import com.cowr.common.enums.OrderStateEnum;
import com.cowr.common.utils.DateTimeUtil; import com.cowr.common.utils.DateTimeUtil;
import com.cowr.model.Supermarket;
import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class OverallService { public class OverallService {
public static OverallService me = new OverallService(); public static OverallService me = new OverallService();
@ -496,7 +494,7 @@ group by date
return outlist; return outlist;
} }
public List<Record> customerQuotaStat(){ public List<Record> customerQuotaStat() {
Date now = new Date(); Date now = new Date();
String nowdaytm = DateTimeUtil.sdf.get().format(now); // 当日 String nowdaytm = DateTimeUtil.sdf.get().format(now); // 当日
@ -525,4 +523,96 @@ group by date
" where t.state < 5\n" + " where t.state < 5\n" +
" and t.cutoff_time like ? ", nowdaytm + "%", nowdaytm + "%"); " and t.cutoff_time like ? ", nowdaytm + "%", nowdaytm + "%");
} }
/**
*
*
* @return
*/
public Record supermarketQoQ() {
Date now = new Date();
Calendar c = Calendar.getInstance();
c.setTime(now);
c.add(Calendar.DAY_OF_YEAR, -1);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
String start = DateTimeUtil.sdf.get().format(c.getTime());
c.add(Calendar.DAY_OF_YEAR, -8);
String end = DateTimeUtil.sdf.get().format(c.getTime());
String[] ds = new String[]{start, end};
List<Supermarket> ss = Supermarket.dao.findAll();
List<Record> list = Db.find("select date_format(t.create_time, '%Y-%m-%d') date, count(t.sn) total_cnt, sum(t.weight) total_weight, sum(t.total_price) total_price, t.supermarket_id id\n" +
" from order_temp t\n" +
" where t.create_time like ?\n" +
" or t.create_time like ?\n" +
" group by t.supermarket_id, date", start + "%", end + "%");
Map<String, Record> map = new HashMap<>();
for (Record record : list) {
String date = record.getStr("date");
String sid = record.getStr("id");
map.put(date + "_" + sid, record);
}
for (Supermarket supermarket : ss) {
for (String t : ds) {
String key = t + "_" + supermarket.getId();
if (!map.containsKey(key)) {
Record newobj = new Record()
.set("id", supermarket.getId())
.set("name", supermarket.getName())
.set("date", t)
.set("total_cnt", 0)
.set("total_weight", 0)
.set("total_price", 0);
list.add(newobj);
map.put(key, newobj);
} else {
map.get(key).set("name", supermarket.getName());
}
}
}
Record out = new Record();
List<Record> slist = new ArrayList<>();
for (Supermarket supermarket : ss) {
String skey = ds[0] + "_" + supermarket.getId();
String ekey = ds[1] + "_" + supermarket.getId();
Record sval = map.get(skey);
Record eval = map.get(ekey);
BigDecimal s_total_cnt = sval.getBigDecimal("total_cnt");
BigDecimal e_total_cnt = eval.getBigDecimal("total_cnt");
BigDecimal s_total_weight = sval.getBigDecimal("total_weight");
BigDecimal e_total_weight = eval.getBigDecimal("total_weight");
BigDecimal s_total_price = sval.getBigDecimal("total_price");
BigDecimal e_total_price = eval.getBigDecimal("total_price");
slist.add(
new Record()
.set("id", supermarket.getId())
.set("name", supermarket.getName())
.set("total_cnt_ratio", e_total_cnt.doubleValue() == 0 ? 0 : s_total_cnt.subtract(e_total_cnt).divide(e_total_cnt, 4, BigDecimal.ROUND_HALF_UP))
.set("total_weight_ratio", e_total_weight.doubleValue() == 0 ? 0 : s_total_weight.subtract(e_total_weight).divide(e_total_weight, 4, BigDecimal.ROUND_HALF_UP))
.set("total_price_ratio", e_total_price.doubleValue() == 0 ? 0 : s_total_price.subtract(e_total_price).divide(e_total_price, 4, BigDecimal.ROUND_HALF_UP))
);
}
out.set("list", slist);
out.set("date", ds);
return out;
}
} }

View File

@ -39,7 +39,12 @@ public class OverallController extends Controller {
public void customerQuota() { public void customerQuota() {
renderJson(Result.success(OverallService.me.customerQuota())); renderJson(Result.success(OverallService.me.customerQuota()));
} }
public void customerQuotaStat() { public void customerQuotaStat() {
renderJson(Result.success(OverallService.me.customerQuotaStat())); renderJson(Result.success(OverallService.me.customerQuotaStat()));
} }
public void supermarketQoQ() {
renderJson(Result.success(OverallService.me.supermarketQoQ()));
}
} }