From ac3585d0c943ea50572e05632fd7dda2109bdcb3 Mon Sep 17 00:00:00 2001 From: "lisai17@sina.com" Date: Sun, 11 Oct 2020 22:50:32 +0800 Subject: [PATCH] . --- .../cowr/ssjygl/overall/OverallService.java | 190 ++++++++++++++---- .../com/cowr/local/ssjygl/main/Config.java | 2 +- .../ssjygl/overall/OverallController.java | 54 ++++- .../ordercluster/OrderclusterSyncService.java | 18 +- .../ssjygl/overall/OverallController.java | 20 ++ 5 files changed, 237 insertions(+), 47 deletions(-) diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/overall/OverallService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/overall/OverallService.java index b7514ba..4bdf42b 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/overall/OverallService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/overall/OverallService.java @@ -37,23 +37,25 @@ public class OverallService { "supermarket_name": "竹瓦", "supermarket_name2": "竹瓦", - "total_price": 43826.40, // 超市总销售额 - "weight": 486.96, // 超市总销售重量 - "truck_cnt": 18, // 超市总运输车次 + "total_price": 43826.40, // 砂站总销售额 + "weight": 486.96, // 砂站总销售重量 + "truck_cnt": 18, // 砂站总运输车次 - "month_total_price": 43826.40, // 当月超市总销售额 - "month_weight": 486.96, // 当月超市销售重量 - "month_truck_cnt": 18, // 当月超市运输车次 - "day_total_price": 0.00, // 当日超市销售总额 - "day_weight": 0.00, // 当日超市销售重量 - "day_truck_cnt": 0 // 当日超市运输车次 + "month_total_price": 43826.40, // 当月砂站总销售额 + "month_weight": 486.96, // 当月砂站销售重量 + "month_truck_cnt": 18, // 当月砂站运输车次 + "day_total_price": 0.00, // 当日砂站销售总额 + "day_weight": 0.00, // 当日砂站销售重量 + "day_truck_cnt": 0 // 当日砂站运输车次 - "before_month_total_price": 0.00, // 前月超市总销售额 - "before_month_weight": 0.00, // 前月超市总销售重量 - "before_month_truck_cnt": 0, // 前月超市运输车次 - "before_day_total_price": 1796.40, // 前日超市销售总额 - "before_day_weight": 19.96, // 前日超市销售重量 - "before_day_truck_cnt": 2, // 前日超市运输车次 + "before_month_total_price": 0.00, // 前月砂站总销售额 + "before_month_weight": 0.00, // 前月砂站总销售重量 + "before_month_truck_cnt": 0, // 前月砂站运输车次 + "before_day_total_price": 1796.40, // 前日砂站销售总额 + "before_day_weight": 19.96, // 前日砂站销售重量 + "before_day_truck_cnt": 2, // 前日砂站运输车次 + + "day_quota_total_price": 253.00, // 当日砂站配额重量 }, ], "by_customer": [ @@ -123,11 +125,11 @@ where t.state = 5 group by date */ - public Record stat(Integer supermarket_id){ - long st = System.currentTimeMillis(); + public Record stat(Integer supermarket_id) { + long st = System.currentTimeMillis(); Record out = new Record(); - Date now = new Date(); + Date now = new Date(); List params1 = new ArrayList<>(); List params2 = new ArrayList<>(); @@ -140,8 +142,8 @@ group by date 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()); // 前一日 + 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); @@ -150,7 +152,7 @@ group by date 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 '" + 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" + @@ -159,7 +161,7 @@ group by date String sql_ordercluster_truck = "select\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 '" + 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" + @@ -175,13 +177,13 @@ group by date " 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 '" + 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 '" + 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 '" + 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" + @@ -223,13 +225,13 @@ group by date " 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 '" + 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 '" + 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 '" + 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" + @@ -243,7 +245,10 @@ group by date " from order_temp t\n" + " where t.state = ?\n"; - if(supermarket_id != null){ + + List by_supermarket_list; + + if (supermarket_id != null) { sql_ordercluster += " and t.supermarket_id = ? "; sql_ordercluster_truck += " and c.supermarket_id = ? "; sql_by_customer += " and t.supermarket_id = ? "; @@ -251,25 +256,140 @@ group by date params1.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 = ? " + " 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 + + " where s.id = ? ", OrderStateEnum.RECEIVED.getStateid(), supermarket_id, supermarket_id); + } else { + by_supermarket_list = Db.find(sql_by_supermarket + " 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 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 oct = Db.findFirst(sql_ordercluster_truck, params1.toArray()); + Record oct = Db.findFirst(sql_ordercluster_truck, params1.toArray()); ocout.setColumns(oct); out.set("ordercluster", ocout); 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; } + + /** + * 近 31 日总销售列表 + * @return + */ + public List 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 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 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 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())); + } } diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java index 8c8e2c6..1f646dd 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java @@ -90,7 +90,7 @@ public class Config extends JFinalConfig { public static DeviceThread deviceThread = new DeviceThread(); public static SocketIOService socketio = null; private static boolean client_run = true; - public static final String CLINET_VERSION = "20201009"; + public static final String CLINET_VERSION = "20201011"; public static String getRootPath() { return PathKit.getWebRootPath() diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/overall/OverallController.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/overall/OverallController.java index 47f1843..cc28f25 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/overall/OverallController.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/overall/OverallController.java @@ -7,7 +7,7 @@ import com.cowr.ssjygl.overall.OverallService; import com.jfinal.core.Controller; public class OverallController extends Controller { - public void stat(){ + public void stat() { Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token")); // 是客户账户 @@ -18,4 +18,56 @@ public class OverallController extends Controller { 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())); + } } \ No newline at end of file diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java index 702183e..3a0424b 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java @@ -73,7 +73,6 @@ public class OrderclusterSyncService extends BaseSyncService { } List newlist = new ArrayList<>(); - List uuids = new ArrayList<>(); Map syncmap = new HashMap<>(); List chksup = new ArrayList<>(); @@ -162,10 +161,7 @@ public class OrderclusterSyncService extends BaseSyncService { model.setPayType(2); model.setUuid(StrKit.getRandomUUID()); - uuids.add(model.getUuid()); - newlist.add(model); - syncmap.get(supermarket_id).addSaveData(model); } catch (Exception e) { log.error(e.getMessage(), e); return Result.failed("数据解析错误"); @@ -180,13 +176,15 @@ public class OrderclusterSyncService extends BaseSyncService { @Override public boolean run() { try { - int[] ret = Db.batchSave(newlist, newlist.size()); + // 单个对象调用 save 可以获取返回的自增id + for(Ordercluster model : newlist){ + boolean ret = model.save(); - for (int i : ret) { - // 必须是每条 sql 修改一条记录 - if (i != 1) { + if(!ret){ return false; } + + syncmap.get(model.getSupermarketId()).addSaveData(model); } // 将订单同步到不同的超市 @@ -204,9 +202,9 @@ public class OrderclusterSyncService extends BaseSyncService { } }); + // 保存成功后,发送配额提醒短信 if (ret) { - List orderclusters = Ordercluster.dao.find("select * from ordercluster t where t.uuid in ('" + StrKit.join(uuids, "', '") + "')"); - for (Ordercluster cluster : orderclusters) { + for (Ordercluster cluster : newlist) { SmsService.me.sendPeiE(cluster); } } diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/overall/OverallController.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/overall/OverallController.java index 2a5f89b..a0473e2 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/overall/OverallController.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/overall/OverallController.java @@ -8,4 +8,24 @@ public class OverallController extends Controller { public void stat(){ 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())); + } } \ No newline at end of file