package com.vci.server.portal.cache;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import com.vci.server.cache.redis.RedisUtil;
|
import com.vci.server.portal.entity.PLCommandParameterEntity;
|
import com.vci.server.portal.service.PLCommandParameterEntityService;
|
import com.vci.server.portal.tools.ServerTool;
|
import com.alibaba.fastjson.JSONObject;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.portal.data.PLCommandParameter;
|
|
public class ButtonParamCacheUtil extends UICacheBaseUtil<PLCommandParameter>{
|
|
private static volatile ButtonParamCacheUtil instance = null;
|
|
public static void initCache() {
|
try {
|
getInstance().initPLCommandParams();
|
} catch (Throwable e) {
|
e.printStackTrace();
|
}
|
}
|
|
private ButtonParamCacheUtil() {
|
super(UICacheNames.BUTTONPARAM, PLCommandParameter.class);
|
}
|
|
public static ButtonParamCacheUtil getInstance() {
|
if (instance == null) {
|
synchronized (ButtonParamCacheUtil.class) {
|
if (instance == null) {
|
instance = new ButtonParamCacheUtil();
|
}
|
}
|
}
|
|
return instance;
|
}
|
|
@Override
|
public void setObject(PLCommandParameter obj) {
|
if (obj == null)
|
return;
|
|
String jsonObj = JSONObject.toJSONString(obj);
|
|
RedisUtil.getInstance().hset(getName(), obj.plOId, jsonObj);
|
}
|
|
|
@Override
|
public PLCommandParameter[] getObjects() {
|
List<PLCommandParameter> list = getObjectList();
|
|
return list.toArray(new PLCommandParameter[0]);
|
}
|
|
@Override
|
public void delObject(PLCommandParameter obj) {
|
if (obj == null || StringUtils.isBlank(obj.plOId))
|
return;
|
|
RedisUtil.getInstance().hdel(getName(), obj.plOId);
|
}
|
|
private void initPLCommandParams() throws Throwable{
|
RedisUtil.getInstance().del(getName());
|
|
List<PLCommandParameterEntity> list = PLCommandParameterEntityService.getInstance().getAllPLCommandParameterEntitys();
|
|
Map<String, List<String>> mapTemp = new HashMap<String, List<String>>();
|
|
for(int i = 0; i < list.size(); i++){
|
PLCommandParameterEntity obj = list.get(i);
|
PLCommandParameter cmdParam = ServerTool.getPLCommandParameter(obj);
|
if(cmdParam != null){
|
setObject(cmdParam);
|
}
|
List<String> lstTemp = mapTemp.get(cmdParam.plCommandOId);
|
if (lstTemp == null) {
|
lstTemp = new ArrayList<String>();
|
mapTemp.put(cmdParam.plCommandOId, lstTemp);
|
}
|
lstTemp.add(cmdParam.plOId);
|
}
|
|
for (String key : mapTemp.keySet()) {
|
List<String> lstTemp = mapTemp.get(key);
|
RedisUtil.getInstance().hset(getName(), "MAP-" + key, String.join(";", lstTemp));
|
}
|
}
|
|
|
public PLCommandParameter[] getCommandParameters(String buttonId) throws VCIError {
|
|
List<PLCommandParameter> lstObj = new ArrayList<PLCommandParameter>();
|
|
String temp = RedisUtil.getInstance().hget(getName(), "MAP-" + buttonId);
|
if (StringUtils.isBlank(temp))
|
return new PLCommandParameter[0];
|
|
String oids[] = temp.split(";");
|
|
for (String oid : oids) {
|
PLCommandParameter ap = getObject(oid);
|
if (ap != null)
|
lstObj.add(ap);
|
}
|
|
return lstObj.toArray(new PLCommandParameter[0]);
|
}
|
|
}
|