ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.vci.server.portal.cache;
 
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
 
import com.vci.server.cache.redis.RedisUtil;
import com.vci.server.portal.entity.PLActionClsEntity;
import com.vci.server.portal.service.PLActionEntityService;
import com.vci.server.portal.tools.ServerTool;
import com.alibaba.fastjson.JSONObject;
import com.vci.corba.common.VCIError;
import com.vci.corba.portal.data.PLActionCls;
/**
 * actioncls缓存
 * @author zhangxg
 *
 */
public class ActionClsCacheUtil extends UICacheBaseUtil<PLActionCls>{
    private static volatile ActionClsCacheUtil instance = null;
    
    private ActionClsCacheUtil(){
        super(UICacheNames.ACTIONCLS, PLActionCls.class);
    }
    
    public static void initCache() {
        try {
            getInstance().initActionCls();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    
    public static ActionClsCacheUtil getInstance() {
        if (instance == null) {
            synchronized (ActionClsCacheUtil.class) {
                if (instance == null) {
                    instance = new ActionClsCacheUtil();
                }
            }
        }
        
        return instance;
    }
    
    @Override
    public void setObject(PLActionCls obj)    {
        if (obj == null)
            return;
        
        String jsonObj = JSONObject.toJSONString(obj);
        
        RedisUtil.getInstance().hset(getName(), obj.name.toLowerCase(), jsonObj);
    }
    
    
    @Override
    public PLActionCls[] getObjects() {
        List<PLActionCls> list = getObjectList();
        
        return list.toArray(new PLActionCls[0]);
    }
 
    @Override
    public void delObject(PLActionCls obj) {
        if (obj == null || StringUtils.isBlank(obj.name))
            return;
        
        RedisUtil.getInstance().hdel(getName(), obj.name.toLowerCase());
    }
 
    private void initActionCls() throws VCIError{
        RedisUtil.getInstance().del(getName());
        
        List<PLActionClsEntity> clsList = PLActionEntityService.getInstance().getAllActionCls();
        for(int i = 0; i < clsList.size(); i++) {
            PLActionClsEntity entity = clsList.get(i);
            setObject(ServerTool.getPLActionCls(entity));
        }
    }
}