dev
parent
bbb63db569
commit
f627babeb3
|
|
@ -11,7 +11,9 @@ import com.jfinal.aop.Clear;
|
||||||
import com.jfinal.core.Controller;
|
import com.jfinal.core.Controller;
|
||||||
import com.jfinal.plugin.activerecord.Record;
|
import com.jfinal.plugin.activerecord.Record;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Clear(AuthInterceptor.class)
|
@Clear(AuthInterceptor.class)
|
||||||
|
|
@ -19,7 +21,7 @@ public class CacheController extends Controller {
|
||||||
/**
|
/**
|
||||||
* 重新加载本地数据库缓存到内存
|
* 重新加载本地数据库缓存到内存
|
||||||
*/
|
*/
|
||||||
public void reload(){
|
public void reload() {
|
||||||
SupermarketSyncService.me.initSupCache();
|
SupermarketSyncService.me.initSupCache();
|
||||||
|
|
||||||
TransportCompanyService.me.initTransCoPriceModulus(); // 初始化物流公司价格系数配置
|
TransportCompanyService.me.initTransCoPriceModulus(); // 初始化物流公司价格系数配置
|
||||||
|
|
@ -30,11 +32,20 @@ public class CacheController extends Controller {
|
||||||
renderJson(Result.success("重新加载完成"));
|
renderJson(Result.success("重新加载完成"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void last(){
|
public void last() {
|
||||||
|
Map<Integer, Record> map = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<Integer, Record> entry : SvrCacheData.SUP_HEARTBEAT.entrySet()) {
|
||||||
|
Record c = entry.getValue();
|
||||||
Record out = new Record();
|
Record out = new Record();
|
||||||
for(Map.Entry<Integer, Long> entry : SvrCacheData.SUP_HEARTBEAT.entrySet()){
|
out.set("version", c.get("version"));
|
||||||
out.set(String.valueOf(entry.getKey()), DateTimeUtil.sdfhms.get().format(new Date(entry.getValue())));
|
|
||||||
|
if (c.get("tm") != null) {
|
||||||
|
out.set("tm", DateTimeUtil.sdfhms.get().format(new Date(c.getLong("tm"))));
|
||||||
}
|
}
|
||||||
renderJson(out);
|
|
||||||
|
map.put(entry.getKey(), out);
|
||||||
|
}
|
||||||
|
renderJson(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
package com.cowr.service.ssjygl.main;
|
package com.cowr.service.ssjygl.main;
|
||||||
|
|
||||||
import com.cowr.model.Supermarket;
|
import com.cowr.model.Supermarket;
|
||||||
|
import com.jfinal.plugin.activerecord.Record;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class SvrCacheData {
|
public class SvrCacheData {
|
||||||
public static Map<Integer, Supermarket> SUP_CACHE = new HashMap<>(); // 砂站基础信息缓存,常用配置数据,避免重复请求数据库
|
public static Map<Integer, Supermarket> SUP_CACHE = new HashMap<>(); // 砂站基础信息缓存,常用配置数据,避免重复请求数据库
|
||||||
public static Map<Integer, Long> SUP_HEARTBEAT = new HashMap<>(); // 砂站客户端心跳时间戳
|
public static Map<Integer, Record> SUP_HEARTBEAT = new HashMap<>(); // 砂站客户端心跳时间戳
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import com.cowr.model.Supermarket;
|
||||||
import com.cowr.service.ssjygl.main.SvrCacheData;
|
import com.cowr.service.ssjygl.main.SvrCacheData;
|
||||||
import com.cowr.service.ssjygl.synctask.SyncTaskService;
|
import com.cowr.service.ssjygl.synctask.SyncTaskService;
|
||||||
import com.jfinal.log.Log;
|
import com.jfinal.log.Log;
|
||||||
|
import com.jfinal.plugin.activerecord.Record;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
|
@ -185,18 +186,29 @@ public class NettyServer {
|
||||||
.toJSONString()
|
.toJSONString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 只保存有效 supermarket_id
|
||||||
|
if (SvrCacheData.SUP_CACHE.containsKey(supermarket_id)) {
|
||||||
|
if (!SvrCacheData.SUP_HEARTBEAT.containsKey(supermarket_id)) {
|
||||||
|
SvrCacheData.SUP_HEARTBEAT.put(supermarket_id, new Record());
|
||||||
|
}
|
||||||
|
|
||||||
|
SvrCacheData.SUP_HEARTBEAT.get(supermarket_id).set("version", json.get("clinet_version"));
|
||||||
|
}
|
||||||
|
|
||||||
log.debug("supermarket_id %s 注册成功, client version %s", supermarket_id, json.get("clinet_version"));
|
log.debug("supermarket_id %s 注册成功, client version %s", supermarket_id, json.get("clinet_version"));
|
||||||
} else if (Enums.MsgTarget.HEARTBEAT.name().equals(target)) {
|
} else if (Enums.MsgTarget.HEARTBEAT.name().equals(target)) {
|
||||||
printlog("收到心跳 supermarket " + map.get(ctx.channel()) + ", 已连接客户端总数: " + map.size());
|
printlog("收到心跳 supermarket " + map.get(ctx.channel()) + ", 已连接客户端总数: " + map.size());
|
||||||
|
|
||||||
if(map.containsKey(ctx.channel())){
|
if (map.containsKey(ctx.channel())) {
|
||||||
Integer supermarket_id = map.get(ctx.channel());
|
Integer supermarket_id = map.get(ctx.channel());
|
||||||
|
|
||||||
if(SvrCacheData.SUP_CACHE.containsKey(supermarket_id)){
|
|
||||||
Supermarket supermarket = SvrCacheData.SUP_CACHE.get(supermarket_id);
|
|
||||||
|
|
||||||
// 只保存有效 supermarket_id
|
// 只保存有效 supermarket_id
|
||||||
SvrCacheData.SUP_HEARTBEAT.put(supermarket.getId(), System.currentTimeMillis());
|
if (SvrCacheData.SUP_CACHE.containsKey(supermarket_id)) {
|
||||||
|
if (!SvrCacheData.SUP_HEARTBEAT.containsKey(supermarket_id)) {
|
||||||
|
SvrCacheData.SUP_HEARTBEAT.put(supermarket_id, new Record());
|
||||||
|
}
|
||||||
|
|
||||||
|
SvrCacheData.SUP_HEARTBEAT.get(supermarket_id).set("tm", System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (Enums.MsgTarget.SYNCTASK.name().equals(target)) {
|
} else if (Enums.MsgTarget.SYNCTASK.name().equals(target)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue