优化首页缓存

dev
lisai17@sina.com 2021-09-24 00:28:20 +08:00
parent 59107fee73
commit 9f2e87265a
5 changed files with 54 additions and 10 deletions

View File

@ -11,7 +11,7 @@ import java.math.BigDecimal;
import java.util.*;
public class OverallService {
public static OverallService me = new OverallService();
public static OverallService me = new OverallService();
/*
/overall/stat?token=

View File

@ -2225,12 +2225,12 @@ public class OrderStatService {
" and t.verify_time > ? \n" +
" group by t.customer_id \n" +
" ) a on c.id = a.customer_id \n\n" +
" left join (\n" +
" select t.customer_id, sum(t.amount) total_amount from refund_detail t \n" +
" where t.state = 3 \n" +
" and t.verify_time > ? \n" +
" group by t.customer_id\n" +
" ) b on c.id = b.customer_id " +
" left join (\n" +
" select t.customer_id, sum(t.amount) total_amount from refund_detail t \n" +
" where t.state = 3 \n" +
" and t.verify_time > ? \n" +
" group by t.customer_id\n" +
" ) b on c.id = b.customer_id " +
" left join customer_type tp on tp.id = c.customer_type_id\n" +
" left join prepay_customer p on p.customer_id = c.id\n" +
" where " + cidsql + " a.customer_id is not null \n" + // 查询时间段内有购砂、起始时间年内有充值的

View File

@ -103,7 +103,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 = "20210415";
public static final String CLINET_VERSION = "20210923";
public static String getRootPath() {
return PathKit.getWebRootPath()

View File

@ -0,0 +1,22 @@
package com.cowr.service.ssjygl.overall;
import com.cowr.common.Const;
import com.cowr.service.ssjygl.main.Config;
public class OverallCacheService extends com.cowr.ssjygl.overall.OverallService {
public static OverallCacheService me = new OverallCacheService();
public static final String tablename = "overall";
public String redisbasekey() {
return Config.dbprop.get("database.basekey") + Const.REDIS_SEPARATE + tablename + Const.REDIS_SEPARATE;
}
public String rediskey(Object key) {
return redisbasekey() + key;
}
public String overallmapkey(Object key) {
return rediskey("overallmapkey" + Const.REDIS_SEPARATE + key);
}
}

View File

@ -4,10 +4,24 @@ import com.cowr.common.view.Result;
import com.cowr.model.Sysuser;
import com.cowr.ssjygl.overall.OverallService;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.redis.Redis;
import java.util.List;
public class OverallController extends Controller {
private static final int statExpireAt = 600; // 超时时间,单位秒
public void stat() {
renderJson(Result.success(OverallService.me.stat(null)));
String key = OverallCacheService.me.overallmapkey("stat");
Record cachedata = Redis.use().get(key);
if (cachedata == null) {
cachedata = OverallCacheService.me.stat(null);
Redis.use().setex(key, statExpireAt, cachedata);
}
renderJson(Result.success(cachedata));
}
public void lastStat() {
@ -33,7 +47,15 @@ public class OverallController extends Controller {
public void lastOrder() {
Integer supermarket_id = getInt("supermarket_id");
renderJson(Result.success(OverallService.me.lastOrder(supermarket_id)));
String key = OverallCacheService.me.overallmapkey("lastOrder_" + supermarket_id);
List<Record> cachedata = Redis.use().get(key);
if (cachedata == null) {
cachedata = OverallService.me.lastOrder(supermarket_id);
Redis.use().setex(key, statExpireAt, cachedata);
}
renderJson(Result.success(cachedata));
}
public void customerQuota() {