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.PLTabButtonEntity;
|
import com.vci.server.portal.service.PLTabButtonEntityService;
|
import com.vci.server.portal.tools.ServerTool;
|
import com.alibaba.fastjson.JSONObject;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.portal.data.PLTabButton;
|
|
public class ComponentBtnCacheUtil extends UICacheBaseUtil<PLTabButton>{
|
|
private static volatile ComponentBtnCacheUtil instance = null;
|
|
public static void initCache() {
|
try {
|
getInstance().initPLTabButton();
|
} catch (Throwable e) {
|
e.printStackTrace();
|
}
|
}
|
|
private ComponentBtnCacheUtil() {
|
super(UICacheNames.BUTTON, PLTabButton.class);
|
}
|
|
public static ComponentBtnCacheUtil getInstance() {
|
if (instance == null) {
|
synchronized (ComponentBtnCacheUtil.class) {
|
if (instance == null) {
|
instance = new ComponentBtnCacheUtil();
|
}
|
}
|
}
|
|
return instance;
|
}
|
|
|
@Override
|
public void setObject(PLTabButton obj) {
|
if (obj == null)
|
return;
|
|
String jsonObj = JSONObject.toJSONString(obj);
|
|
RedisUtil.getInstance().hset(getName(), obj.plOId, jsonObj);
|
}
|
|
public void setObject(PLTabButtonEntity obj) {
|
if (obj == null)
|
return;
|
|
PLTabButton btn = ServerTool.getPLTabButton(obj);
|
|
setObject(btn);
|
}
|
|
@Override
|
public PLTabButton[] getObjects() {
|
List<PLTabButton> list = getObjectList();
|
|
return list.toArray(new PLTabButton[0]);
|
}
|
|
|
@Override
|
public void delObject(PLTabButton obj) {
|
if (obj == null || StringUtils.isBlank(obj.plOId))
|
return;
|
|
RedisUtil.getInstance().hdel(getName(), obj.plOId);
|
}
|
|
private void initPLTabButton() throws Throwable{
|
RedisUtil.getInstance().del(getName());
|
|
List<PLTabButtonEntity> listEnt = PLTabButtonEntityService.getInstance().getAllPLTabButtonEntitys();
|
|
Map<String, List<String>> mapTemp = new HashMap<String, List<String>>();
|
|
for(PLTabButtonEntity btn : listEnt){
|
PLTabButton plBtn = ServerTool.getPLTabButton(btn);
|
if(plBtn != null){
|
setObject(plBtn);
|
}
|
List<String> lstTemp = mapTemp.get(plBtn.plTableOId);
|
if (lstTemp == null) {
|
lstTemp = new ArrayList<String>();
|
mapTemp.put(plBtn.plTableOId, lstTemp);
|
}
|
lstTemp.add(plBtn.plOId);
|
}
|
|
for (String key : mapTemp.keySet()) {
|
List<String> lstTemp = mapTemp.get(key);
|
RedisUtil.getInstance().hset(getName(), "MAP-" + key, String.join(";", lstTemp));
|
}
|
}
|
|
public PLTabButton[] getButtons(String componentId) throws VCIError {
|
List<PLTabButton> lstObj = new ArrayList<PLTabButton>();
|
|
String temp = RedisUtil.getInstance().hget(getName(), "MAP-" + componentId);
|
if (StringUtils.isBlank(temp))
|
return new PLTabButton[0];
|
|
String oids[] = temp.split(";");
|
|
for (String oid : oids) {
|
PLTabButton ap = getObject(oid);
|
if (ap != null)
|
lstObj.add(ap);
|
}
|
|
return lstObj.toArray(new PLTabButton[0]);
|
}
|
}
|