优化基础数据放入redis缓存。
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
package com.gzzn.omms.msgexchangeapi.basicdata.manager;
|
package com.gzzn.omms.msgexchangeapi.basicdata.manager;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.gzzn.omms.msgexchangeapi.basicdata.entity.OrmsStand;
|
import com.gzzn.omms.msgexchangeapi.basicdata.entity.OrmsStand;
|
||||||
import com.gzzn.omms.msgexchangeapi.basicdata.service.IOrmsStandService;
|
import com.gzzn.omms.msgexchangeapi.basicdata.service.IOrmsStandService;
|
||||||
|
import com.gzzn.omms.msgexchangeapi.redis.RedisService;
|
||||||
import com.gzzn.omms.msgexchangeapi.utils.SpringUtil;
|
import com.gzzn.omms.msgexchangeapi.utils.SpringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,8 +16,7 @@ import com.gzzn.omms.msgexchangeapi.utils.SpringUtil;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class OrmsStandManager {
|
public class OrmsStandManager {
|
||||||
private static Hashtable dataCache = null;
|
private static final String KEY_ORMSSTAND = "orms_stand";
|
||||||
|
|
||||||
private static OrmsStandManager instance = new OrmsStandManager();
|
private static OrmsStandManager instance = new OrmsStandManager();
|
||||||
|
|
||||||
private OrmsStandManager()
|
private OrmsStandManager()
|
||||||
@@ -32,23 +33,28 @@ public class OrmsStandManager {
|
|||||||
{
|
{
|
||||||
OrmsStand ormsStand = null;
|
OrmsStand ormsStand = null;
|
||||||
synchronized (OrmsStandManager.class) {
|
synchronized (OrmsStandManager.class) {
|
||||||
if(null == dataCache)
|
//缓存获取
|
||||||
|
RedisService redisService = (RedisService) SpringUtil
|
||||||
|
.getBean("redisService");
|
||||||
|
Boolean keyExists = redisService.hasKey(KEY_ORMSSTAND);
|
||||||
|
|
||||||
|
|
||||||
|
if(!keyExists)
|
||||||
{
|
{
|
||||||
//远程获取
|
//远程获取
|
||||||
IOrmsStandService ormsStandService = (IOrmsStandService) SpringUtil
|
IOrmsStandService ormsStandService = (IOrmsStandService) SpringUtil
|
||||||
.getBean("ormsStandService");
|
.getBean("ormsStandService");
|
||||||
List<OrmsStand> lsOrmsStand = ormsStandService.findAll();
|
List<OrmsStand> lsOrmsStand = ormsStandService.findAll();
|
||||||
|
Map mapOrmsStand = new HashMap<String, OrmsStand>();
|
||||||
|
|
||||||
dataCache = new Hashtable<>();
|
|
||||||
for(OrmsStand node: lsOrmsStand)
|
for(OrmsStand node: lsOrmsStand)
|
||||||
{
|
{
|
||||||
dataCache.put(node.getStandCode(), node);
|
mapOrmsStand.put(node.getStandCode(), node);
|
||||||
}
|
}
|
||||||
|
redisService.hmset(KEY_ORMSSTAND, mapOrmsStand, 3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
//本地获取
|
//本地获取
|
||||||
ormsStand = (OrmsStand) dataCache.get(standCode);
|
ormsStand = (OrmsStand) redisService.hget(KEY_ORMSSTAND, standCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ormsStand;
|
return ormsStand;
|
||||||
|
|||||||
Reference in New Issue
Block a user