lisai17@sina.com 2020-10-11 22:50:32 +08:00
parent f404297a8b
commit ac3585d0c9
5 changed files with 237 additions and 47 deletions

View File

@ -37,23 +37,25 @@ public class OverallService {
"supermarket_name": "竹瓦", "supermarket_name": "竹瓦",
"supermarket_name2": "竹瓦", "supermarket_name2": "竹瓦",
"total_price": 43826.40, // 超市总销售额 "total_price": 43826.40, // 砂站总销售额
"weight": 486.96, // 超市总销售重量 "weight": 486.96, // 砂站总销售重量
"truck_cnt": 18, // 超市总运输车次 "truck_cnt": 18, // 砂站总运输车次
"month_total_price": 43826.40, // 当月超市总销售额 "month_total_price": 43826.40, // 当月砂站总销售额
"month_weight": 486.96, // 当月超市销售重量 "month_weight": 486.96, // 当月砂站销售重量
"month_truck_cnt": 18, // 当月超市运输车次 "month_truck_cnt": 18, // 当月砂站运输车次
"day_total_price": 0.00, // 当日超市销售总额 "day_total_price": 0.00, // 当日砂站销售总额
"day_weight": 0.00, // 当日超市销售重量 "day_weight": 0.00, // 当日砂站销售重量
"day_truck_cnt": 0 // 当日超市运输车次 "day_truck_cnt": 0 // 当日砂站运输车次
"before_month_total_price": 0.00, // 前月超市总销售额 "before_month_total_price": 0.00, // 前月砂站总销售额
"before_month_weight": 0.00, // 前月超市总销售重量 "before_month_weight": 0.00, // 前月砂站总销售重量
"before_month_truck_cnt": 0, // 前月超市运输车次 "before_month_truck_cnt": 0, // 前月砂站运输车次
"before_day_total_price": 1796.40, // 前日超市销售总额 "before_day_total_price": 1796.40, // 前日砂站销售总额
"before_day_weight": 19.96, // 前日超市销售重量 "before_day_weight": 19.96, // 前日砂站销售重量
"before_day_truck_cnt": 2, // 前日超市运输车次 "before_day_truck_cnt": 2, // 前日砂站运输车次
"day_quota_total_price": 253.00, // 当日砂站配额重量
}, },
], ],
"by_customer": [ "by_customer": [
@ -123,11 +125,11 @@ where t.state = 5
group by date group by date
*/ */
public Record stat(Integer supermarket_id){ public Record stat(Integer supermarket_id) {
long st = System.currentTimeMillis(); long st = System.currentTimeMillis();
Record out = new Record(); Record out = new Record();
Date now = new Date(); Date now = new Date();
List<Object> params1 = new ArrayList<>(); List<Object> params1 = new ArrayList<>();
List<Object> params2 = new ArrayList<>(); List<Object> params2 = new ArrayList<>();
@ -140,8 +142,8 @@ group by date
c.add(Calendar.DAY_OF_MONTH, -1); c.add(Calendar.DAY_OF_MONTH, -1);
String nowmonttm = DateTimeUtil.sd.get().format(now); // 当月 String nowmonttm = DateTimeUtil.sd.get().format(now); // 当月
String nowdaytm = DateTimeUtil.sdf.get().format(now); // 当日 String nowdaytm = DateTimeUtil.sdf.get().format(now); // 当日
String predaytm = DateTimeUtil.sdf.get().format(c.getTime()); // 前一日 String predaytm = DateTimeUtil.sdf.get().format(c.getTime()); // 前一日
c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.DAY_OF_MONTH, 1);
c.add(Calendar.MONTH, -1); c.add(Calendar.MONTH, -1);
@ -150,7 +152,7 @@ group by date
String sql_ordercluster = "select \n" + String sql_ordercluster = "select \n" +
" sum(t.total_weight) total_weight, \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 '" + 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 '" + 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 '" + 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" + " sum(case when t.cutoff_time like '" + predaytm + "%' then t.total_weight end ) before_day_total_weight \n" +
@ -159,7 +161,7 @@ group by date
String sql_ordercluster_truck = "select\n" + String sql_ordercluster_truck = "select\n" +
" count(t.id) truck_cnt,\n" + " 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 '" + 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 '" + 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 '" + 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" + " sum(case when t.change_time like '" + predaytm + "%' then 1 else 0 end) before_day_truck_cnt\n" +
@ -175,13 +177,13 @@ group by date
" sum(t.total_price) total_price,\n" + " sum(t.total_price) total_price,\n" +
" count(*) truck_cnt,\n" + " count(*) truck_cnt,\n" +
" \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 '" + 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" + " ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.weight end), 0) day_weight,\n" +
" \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 '" + 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" + " ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.total_price end), 0) day_total_price,\n" +
" \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 '" + 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" + " count(case when t.create_time like '" + nowdaytm + "%' then t.sn end) day_truck_cnt,\n" +
" \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 '" + premonthtm + "%' then t.weight end), 0) before_month_weight,\n" +
@ -223,13 +225,13 @@ group by date
" sum(t.total_price) total_price,\n" + " sum(t.total_price) total_price,\n" +
" count(*) truck_cnt,\n" + " count(*) truck_cnt,\n" +
" \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 '" + 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" + " ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.weight end), 0) day_weight,\n" +
" \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 '" + 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" + " ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.total_price end), 0) day_total_price,\n" +
" \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 '" + 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" + " count(case when t.create_time like '" + nowdaytm + "%' then t.sn end) day_truck_cnt,\n" +
" \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 '" + premonthtm + "%' then t.weight end), 0) before_month_weight,\n" +
@ -243,7 +245,10 @@ group by date
" from order_temp t\n" + " from order_temp t\n" +
" where t.state = ?\n"; " where t.state = ?\n";
if(supermarket_id != null){
List<Record> by_supermarket_list;
if (supermarket_id != null) {
sql_ordercluster += " and t.supermarket_id = ? "; sql_ordercluster += " and t.supermarket_id = ? ";
sql_ordercluster_truck += " and c.supermarket_id = ? "; sql_ordercluster_truck += " and c.supermarket_id = ? ";
sql_by_customer += " and t.supermarket_id = ? "; sql_by_customer += " and t.supermarket_id = ? ";
@ -251,25 +256,140 @@ group by date
params1.add(supermarket_id); params1.add(supermarket_id);
params2.add(supermarket_id); params2.add(supermarket_id);
out.set("by_supermarket", Db.find(sql_by_supermarket + by_supermarket_list = Db.find(sql_by_supermarket +
" and t.supermarket_id = ? " + " and t.supermarket_id = ? " +
" group by t.supermarket_id\n" + " group by t.supermarket_id\n" +
" ) a on a.supermarket_id = s.id \n" + " ) a on a.supermarket_id = s.id \n" +
" where s.id = ? ", OrderStateEnum.RECEIVED.getStateid(), supermarket_id, supermarket_id)); " where s.id = ? ", OrderStateEnum.RECEIVED.getStateid(), supermarket_id, supermarket_id);
}else{ } else {
out.set("by_supermarket", Db.find( sql_by_supermarket + by_supermarket_list = Db.find(sql_by_supermarket +
" group by t.supermarket_id\n" + " group by t.supermarket_id\n" +
" ) a on a.supermarket_id = s.id", OrderStateEnum.RECEIVED.getStateid())); " ) a on a.supermarket_id = s.id", OrderStateEnum.RECEIVED.getStateid());
}
List<Record> suppeie = Db.find("select t.supermarket_id, sum(t.total_weight) total_weight from ordercluster t\n" +
"where t.cutoff_time like ? \n" +
"and t.state < ? \n" +
"group by t.supermarket_id", nowdaytm + "%", OrderStateEnum.RECEIVED.getStateid());
for(Record record : by_supermarket_list){
for(Record r : suppeie){
if(r.getInt("supermarket_id") != null && r.getInt("supermarket_id").equals(record.getInt("supermarket_id"))){
record.set("day_quota_total_price", r.get("total_weight"));
}
}
} }
Record ocout = Db.findFirst(sql_ordercluster, params1.toArray()); Record ocout = Db.findFirst(sql_ordercluster, params1.toArray());
Record oct = Db.findFirst(sql_ordercluster_truck, params1.toArray()); Record oct = Db.findFirst(sql_ordercluster_truck, params1.toArray());
ocout.setColumns(oct); ocout.setColumns(oct);
out.set("ordercluster", ocout); out.set("ordercluster", ocout);
out.set("by_customer", Db.find(sql_by_customer + " group by t.customer_id", params2.toArray())); out.set("by_customer", Db.find(sql_by_customer + " group by t.customer_id", params2.toArray()));
out.set("by_supermarket", by_supermarket_list);
return out; return out;
} }
/**
* 31
* @return
*/
public List<Record> lastStat() {
Date now = new Date();
Calendar c = Calendar.getInstance();
c.setTime(now);
c.add(Calendar.DAY_OF_MONTH, -31);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return Db.find("\n" +
"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\n" +
"where t.state = ?\n" +
"and t.create_time >= ?\n" +
"group by date",
OrderStateEnum.RECEIVED.getStateid(),
DateTimeUtil.sdfhms.get().format(c.getTime()));
}
/**
* 31
* @return
*/
public List<Record> lastSupermarketStat(int supermarket_id) {
Date now = new Date();
Calendar c = Calendar.getInstance();
c.setTime(now);
c.add(Calendar.DAY_OF_MONTH, -31);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return Db.find("\n" +
"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\n" +
"where t.state = ?\n" +
"and t.supermarket_id = ?\n" +
"and t.create_time >= ?\n" +
"group by date",
OrderStateEnum.RECEIVED.getStateid(),
supermarket_id,
DateTimeUtil.sdfhms.get().format(c.getTime()));
}
/**
* 31
* @return
*/
public List<Record> lastCustomerStat(int customer_id) {
Date now = new Date();
Calendar c = Calendar.getInstance();
c.setTime(now);
c.add(Calendar.DAY_OF_MONTH, -31);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return Db.find("\n" +
"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\n" +
"where t.state = ?\n" +
"and t.customer_id = ?\n" +
"and t.create_time >= ?\n" +
"group by date",
OrderStateEnum.RECEIVED.getStateid(),
customer_id,
DateTimeUtil.sdfhms.get().format(c.getTime()));
}
/**
* 31
* @return
*/
public List<Record> lastTempStat() {
Date now = new Date();
Calendar c = Calendar.getInstance();
c.setTime(now);
c.add(Calendar.DAY_OF_MONTH, -31);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return Db.find("\n" +
"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\n" +
"where t.state = ?\n" +
"and t.customer_id is null \n" +
"and t.create_time >= ?\n" +
"group by date",
OrderStateEnum.RECEIVED.getStateid(),
DateTimeUtil.sdfhms.get().format(c.getTime()));
}
} }

View File

@ -90,7 +90,7 @@ public class Config extends JFinalConfig {
public static DeviceThread deviceThread = new DeviceThread(); public static DeviceThread deviceThread = new DeviceThread();
public static SocketIOService socketio = null; public static SocketIOService socketio = null;
private static boolean client_run = true; private static boolean client_run = true;
public static final String CLINET_VERSION = "20201009"; public static final String CLINET_VERSION = "20201011";
public static String getRootPath() { public static String getRootPath() {
return PathKit.getWebRootPath() return PathKit.getWebRootPath()

View File

@ -7,7 +7,7 @@ import com.cowr.ssjygl.overall.OverallService;
import com.jfinal.core.Controller; import com.jfinal.core.Controller;
public class OverallController extends Controller { public class OverallController extends Controller {
public void stat(){ public void stat() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token")); Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
// 是客户账户 // 是客户账户
@ -18,4 +18,56 @@ public class OverallController extends Controller {
renderJson(Result.success(OverallService.me.stat(tokenuser.getEntityId()))); renderJson(Result.success(OverallService.me.stat(tokenuser.getEntityId())));
} }
public void lastStat() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
// 是客户账户
if (tokenuser == null || tokenuser.getEntityId() == null) {
renderJson(Result.noauth());
return;
}
renderJson(Result.success(OverallService.me.lastStat()));
}
public void lastSupermarketStat() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
// 是客户账户
if (tokenuser == null || tokenuser.getEntityId() == null) {
renderJson(Result.noauth());
return;
}
Integer supermarket_id = getInt("supermarket_id", 0);
renderJson(Result.success(OverallService.me.lastSupermarketStat(supermarket_id)));
}
public void lastCustomerStat() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
// 是客户账户
if (tokenuser == null || tokenuser.getEntityId() == null) {
renderJson(Result.noauth());
return;
}
Integer customer_id = getInt("customer_id", 0);
renderJson(Result.success(OverallService.me.lastCustomerStat(customer_id)));
}
public void lastTempStat() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
// 是客户账户
if (tokenuser == null || tokenuser.getEntityId() == null) {
renderJson(Result.noauth());
return;
}
renderJson(Result.success(OverallService.me.lastTempStat()));
}
} }

View File

@ -73,7 +73,6 @@ public class OrderclusterSyncService extends BaseSyncService {
} }
List<Ordercluster> newlist = new ArrayList<>(); List<Ordercluster> newlist = new ArrayList<>();
List<String> uuids = new ArrayList<>();
Map<Integer, SyncTask> syncmap = new HashMap<>(); Map<Integer, SyncTask> syncmap = new HashMap<>();
List<Integer> chksup = new ArrayList<>(); List<Integer> chksup = new ArrayList<>();
@ -162,10 +161,7 @@ public class OrderclusterSyncService extends BaseSyncService {
model.setPayType(2); model.setPayType(2);
model.setUuid(StrKit.getRandomUUID()); model.setUuid(StrKit.getRandomUUID());
uuids.add(model.getUuid());
newlist.add(model); newlist.add(model);
syncmap.get(supermarket_id).addSaveData(model);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return Result.failed("数据解析错误"); return Result.failed("数据解析错误");
@ -180,13 +176,15 @@ public class OrderclusterSyncService extends BaseSyncService {
@Override @Override
public boolean run() { public boolean run() {
try { try {
int[] ret = Db.batchSave(newlist, newlist.size()); // 单个对象调用 save 可以获取返回的自增id
for(Ordercluster model : newlist){
boolean ret = model.save();
for (int i : ret) { if(!ret){
// 必须是每条 sql 修改一条记录
if (i != 1) {
return false; return false;
} }
syncmap.get(model.getSupermarketId()).addSaveData(model);
} }
// 将订单同步到不同的超市 // 将订单同步到不同的超市
@ -204,9 +202,9 @@ public class OrderclusterSyncService extends BaseSyncService {
} }
}); });
// 保存成功后,发送配额提醒短信
if (ret) { if (ret) {
List<Ordercluster> orderclusters = Ordercluster.dao.find("select * from ordercluster t where t.uuid in ('" + StrKit.join(uuids, "', '") + "')"); for (Ordercluster cluster : newlist) {
for (Ordercluster cluster : orderclusters) {
SmsService.me.sendPeiE(cluster); SmsService.me.sendPeiE(cluster);
} }
} }

View File

@ -8,4 +8,24 @@ public class OverallController extends Controller {
public void stat(){ public void stat(){
renderJson(Result.success(OverallService.me.stat(null))); renderJson(Result.success(OverallService.me.stat(null)));
} }
public void lastStat() {
renderJson(Result.success(OverallService.me.lastStat()));
}
public void lastSupermarketStat() {
Integer supermarket_id = getInt("supermarket_id", 0);
renderJson(Result.success(OverallService.me.lastSupermarketStat(supermarket_id)));
}
public void lastCustomerStat() {
Integer customer_id = getInt("customer_id", 0);
renderJson(Result.success(OverallService.me.lastCustomerStat(customer_id)));
}
public void lastTempStat() {
renderJson(Result.success(OverallService.me.lastTempStat()));
}
} }