添加首页缓存
parent
80e19b32ad
commit
74b0e14b13
|
|
@ -0,0 +1,43 @@
|
|||
package com.cowr.service.ssjygl.jobs;
|
||||
|
||||
import com.cowr.service.ssjygl.overall.OverallCacheService;
|
||||
import com.cowr.ssjygl.overall.OverallService;
|
||||
import com.jfinal.log.Log;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.jfinal.plugin.redis.Redis;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LoadStatCacheJob implements Job {
|
||||
private static Log log = Log.getLog(LoadStatCacheJob.class);
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
String statkey = OverallCacheService.me.overallmapkey("stat");
|
||||
Record statcachedata = Redis.use().get(statkey);
|
||||
if (statcachedata == null) {
|
||||
statcachedata = OverallCacheService.me.stat(null);
|
||||
|
||||
Redis.use().setex(statkey, OverallCacheService.statExpireAt, statcachedata);
|
||||
}
|
||||
|
||||
String lastOrderkey = OverallCacheService.me.overallmapkey("lastOrder");
|
||||
List<Record> lastOrdercachedata = Redis.use().get(lastOrderkey);
|
||||
if (lastOrdercachedata == null) {
|
||||
lastOrdercachedata = OverallService.me.lastOrder(null);
|
||||
|
||||
Redis.use().setex(lastOrderkey, OverallCacheService.statExpireAt, lastOrdercachedata);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ import com.cowr.service.ssjygl.driver.DriverController;
|
|||
import com.cowr.service.ssjygl.invoice.invalidverify.InvoiceInvalidVerifyController;
|
||||
import com.cowr.service.ssjygl.invoice.log.InvoiceLogController;
|
||||
import com.cowr.service.ssjygl.invoice.receive.InvoiceReceiveController;
|
||||
import com.cowr.service.ssjygl.jobs.LoadStatCacheJob;
|
||||
import com.cowr.service.ssjygl.netty.NettyServer;
|
||||
import com.cowr.service.ssjygl.order.invalidverify.OrderInvalidVerifyController;
|
||||
import com.cowr.service.ssjygl.order.ordercluster.OrderclusterController;
|
||||
|
|
@ -318,6 +319,8 @@ public class Config extends JFinalConfig {
|
|||
}
|
||||
|
||||
SyncTaskService.me.start();
|
||||
|
||||
new LoadStatCacheJob().load();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.cowr.common.Const;
|
|||
import com.cowr.service.ssjygl.main.Config;
|
||||
|
||||
public class OverallCacheService extends com.cowr.ssjygl.overall.OverallService {
|
||||
public static final int statExpireAt = 1800; // 超时时间,单位秒
|
||||
public static OverallCacheService me = new OverallCacheService();
|
||||
public static final String tablename = "overall";
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import com.jfinal.plugin.redis.Redis;
|
|||
import java.util.List;
|
||||
|
||||
public class OverallController extends Controller {
|
||||
private static final int statExpireAt = 600; // 超时时间,单位秒
|
||||
|
||||
public void stat() {
|
||||
String key = OverallCacheService.me.overallmapkey("stat");
|
||||
|
|
@ -18,7 +17,7 @@ public class OverallController extends Controller {
|
|||
if (cachedata == null) {
|
||||
cachedata = OverallCacheService.me.stat(null);
|
||||
|
||||
Redis.use().setex(key, statExpireAt, cachedata);
|
||||
Redis.use().setex(key, OverallCacheService.statExpireAt, cachedata);
|
||||
}
|
||||
|
||||
renderJson(Result.success(cachedata));
|
||||
|
|
@ -45,14 +44,12 @@ public class OverallController extends Controller {
|
|||
}
|
||||
|
||||
public void lastOrder() {
|
||||
Integer supermarket_id = getInt("supermarket_id");
|
||||
|
||||
String key = OverallCacheService.me.overallmapkey("lastOrder_" + supermarket_id);
|
||||
String key = OverallCacheService.me.overallmapkey("lastOrder");
|
||||
List<Record> cachedata = Redis.use().get(key);
|
||||
if (cachedata == null) {
|
||||
cachedata = OverallService.me.lastOrder(supermarket_id);
|
||||
cachedata = OverallService.me.lastOrder(null);
|
||||
|
||||
Redis.use().setex(key, statExpireAt, cachedata);
|
||||
Redis.use().setex(key, OverallCacheService.statExpireAt, cachedata);
|
||||
}
|
||||
|
||||
renderJson(Result.success(cachedata));
|
||||
|
|
|
|||
|
|
@ -27,4 +27,9 @@ statsms.enable=true
|
|||
# 检查异常数据
|
||||
checkexceptiondata.job=com.cowr.service.ssjygl.jobs.CheckExceptionDataJob
|
||||
checkexceptiondata.cron= 0 3 * * * ?
|
||||
checkexceptiondata.enable=true
|
||||
checkexceptiondata.enable=true
|
||||
|
||||
# 加载首页缓存数据
|
||||
loadstat.job=com.cowr.service.ssjygl.jobs.LoadStatCacheJob
|
||||
loadstat.cron= 0 */30 * * * ?
|
||||
loadstat.enable=true
|
||||
Loading…
Reference in New Issue