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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package com.vci.server.omd.attribpool.cache;
 
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
import org.dom4j.DocumentException;
 
import com.alibaba.fastjson.JSONObject;
import com.vci.common.log.ServerWithLog4j;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.server.cache.CacheNames;
import com.vci.server.cache.OMCacheProvider;
import com.vci.server.cache.redis.RedisUtil;
import com.vci.server.omd.attribpool.service.AttrPoolService;
 
public class APServerCacheUtil {//extends BaseCacheTimer{
    //private AttribItem[] attributes = null;
    //private Map<String, AttribItem> attrNameMap = null;
//    private static volatile APServerCacheUtil instance = null;
//    private static String CACHENAME = "attributepool";
 
//    private APServerCacheUtil() {
//        super(CACHENAME);
//        try {
//            attrNameMap = new HashMap<String, AttribItem>();
//            this.setCurrentTime(this.getDataBaseCurrtenttime());
//            initAttribute();
//        } catch (Throwable e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//        }
//    }
//    
//    public static APServerCacheUtil getInstance() {
//        if (instance == null) {
//            synchronized (APServerCacheUtil.class) {
//                if (instance == null) {
//                    instance = new APServerCacheUtil();
//                }
//            }
//        }
//        
//        return instance;
//    }
    
    public static void initCache() {
        try {
            clearCache();
            initAttribute();
        } catch (Exception e) {
            ServerWithLog4j.logger.error(e);
        }
    }
    
    public static void clearCache() {
        RedisUtil.getInstance().del(CacheNames.ATTRITEMS);
    }
 
    private static void initAttribute() throws VCIError, SQLException, IOException, DocumentException {
        RedisUtil.getInstance().del(CacheNames.ATTRITEMS);
        
        AttribItem[] attrs = AttrPoolService.getInstance().getAttribItems("", 1, 1);
        for (int i = 0; i < attrs.length; i++) {
            if (attrs[i] == null)
                return;
            
            String jsonObj = JSONObject.toJSONString(attrs[i]);
            
            RedisUtil.getInstance().hset(CacheNames.ATTRITEMS, attrs[i].name.toLowerCase(), jsonObj);
        }
    }
    
 
    public static void delAttribute(String name) {
        if (StringUtils.isBlank(name))
            return;
        
        RedisUtil.getInstance().hdel(CacheNames.ATTRITEMS, name.toLowerCase());
    }
    
    public static void setAttribute(AttribItem item) {
        if (item == null)
            return;
        
        String jsonObj = JSONObject.toJSONString(item);
        
        RedisUtil.getInstance().hset(CacheNames.ATTRITEMS, item.name.toLowerCase(), jsonObj);
    }
    
    
//    public static void setAttribute(AttribItem item) {
//        if (item == null)
//            return;
//        
//        String jsonObj = JSONObject.toJSONString(item);
//        
//        RedisUtil.getInstance().hset(CacheNames.ATTRITEMS, item.name.toLowerCase(), jsonObj);
//    }
 
//    
//    public void reloadCache() throws VCIError {
//        try {
//            initAttribute();
//        }catch (Throwable e) {
//            e.printStackTrace();
//            throw getLocalVciError("P0010PLMAP-00012", e);
//        }
//    }
//
//    
//    public void arraySort() {
//        List<AttribItem> list = Arrays.asList(attributes);
//        Collections.sort(list, new Comparator<AttribItem>(){
//            @Override
//            public int compare(AttribItem a1, AttribItem a2) {
//                return new String(a1.name).compareTo(new String(a2.name));
//            }
//        });
//        attributes = list.toArray(new AttribItem[list.size()]);
//    }
    
    /**
     * 根据条件获取符合条件的属性定义
     * 
     * @param filter,条件,只有name其左右
     * @param start,暂不起作用
     * @param rows,暂不起作用
     * @return
     * @throws VCIError
     */
//    public static AttribItem[] getAttribItems(String filter, int start, int rows) throws VCIError {
//
//        List<AttribItem> attrList = new ArrayList<AttribItem>();
//        AttribItem[] cAttributes = OMCacheProvider.getAttributes();
//        if(filter != null && !filter.equals("")){
//            for (AttribItem attr : cAttributes) {
//                if (attr.name.indexOf(filter) >= 0) {
//                    attrList.add(attr);
//                }
//            }
//            cAttributes = attrList.toArray(new AttribItem[attrList.size()]);
//        }
//        
//        return cAttributes;
//    }
//    
    /**
     * 判断当前名称的属性是否存在
     * 
     * @param name
     * @return
     * @throws VCIError
     */
//    public boolean checkRowIsExists(String name) throws VCIError {
//        refreshCache();
//        if (attrNameMap.containsKey(name)) {
//            return true;
//        }
//        
//        return false;
//    }
    
    /**
     * 根据属性的名称集合获取详细的属性定义
     * @param attNames
     * @return
     * @throws VCIError
     */
//    public AttribItem[] getAttribItemsByNames(String[] attNames)
//            throws VCIError {
//        refreshCache();
//        List<AttribItem> attrList = new ArrayList<AttribItem>();
//        for (String attrName : attNames) {
//            if (attrNameMap.containsKey(attrName)) {
//                attrList.add(attrNameMap.get(attrName));
//            }
//        }
//        
//        return attrList.toArray(new AttribItem[attrList.size()]);
//    }
    
    /**
     * 获取单一属性名对应的属性详细信息
     * @param abName
     * @return
     * @throws VCIError
     */
//    public AttribItem getAttribItemByName(String abName) throws VCIError {
//        refreshCache();
//        if (attrNameMap.containsKey(abName)) {
//            return attrNameMap.get(abName);
//        }
//        
//        return new AttribItem();
//    }
    
    /**
     * 获取属性的数据类型
     * @param abName
     * @return
     * @throws VCIError
     */
//    public String getAttribItemDataType(String abName) throws VCIError {
//        refreshCache();
//        if (attrNameMap.containsKey(abName)) {
//            return attrNameMap.get(abName).vtDataType;
//        }
//        
//        return "";
//    }
    
    /**
     * 获取引用枚举的所有属性名称
     * @param emName
     * @return
     * @throws VCIError
     */
//    public static String[] getAPNamesByEMName(String emName) throws VCIError {
//        List<String> attrNameList = new ArrayList<String>();
//        
//        AttribItem[] items = OMCacheProvider.getAttributes();
//        for (AttribItem attr : items) {
//            if (attr.other.indexOf(emName) >= 0) {
//                attrNameList.add(attr.name); 
//            }
//        }
//        
//        return attrNameList.toArray(new String[attrNameList.size()]);
//    }
    
    /**
     * 获取名称包含text,名称不在abNameArray数组中的属性详细信息
     * @param abNameArray
     * @param text
     * @return
     * @throws VCIError
     */
    public static AttribItem[] getAttribItemsOutNames(String[] abNameArray, String text)
            throws VCIError {
 
        List<String> abNameList = new ArrayList<String>();
        for (String ab : abNameArray) {
            abNameList.add(ab);
        }
        AttribItem[] items = OMCacheProvider.getAttributes();
        
        List<AttribItem> attrList = new ArrayList<AttribItem>();
        for (AttribItem attr : items) {
            if (attr.name.indexOf(text) >= 0 && !abNameList.contains(attr.name)) {
                attrList.add(attr);
            }
        }
        
        return attrList.toArray(new AttribItem[attrList.size()]);
    }
    
//    private synchronized void refreshCache() throws VCIError {
//        long cTime = this.getDataBaseCurrtenttime();
//        //List<PLCacheTempEntity> list = needUpdateCache(objType);
//        PLCacheRecordEnt[] list = getUpdatedCacheData(CACHENAME);
//        if (list != null) {
//            if (list.length > 0){
//                updateCache(CACHENAME, list);
//            }
//            this.setCurrentTime(cTime);
//        }
//    }
 
//    private boolean updateCache(String objType, PLCacheRecordEnt[] cacheTempList) throws VCIError {
//        boolean flag = false;
//        try {
//            List<AttribItem> list = new ArrayList<AttribItem>();
//            for (int i = 0 ; i < attributes.length ; i++) {
//                list.add(attributes[i]);
//            }
//            List<String> idList = new ArrayList<String>();
//            for (PLCacheRecordEnt cache : cacheTempList) {
//                idList.add(cache.getId());
//                AttribItem ab = AttrPoolService.getInstance().getAttribItemByOid(cache.getObjId());
//                if ("creat".equals(cache.getOperateType())) {
//                    list.add(ab);
//                    attrNameMap.put(ab.name, ab);
//                } else if ("edit".equals(cache.getOperateType())) {
//                    list = removeListItemByOid(cache.getObjId(), list);
//                    attrNameMap = removeMapItemByOid(cache.getObjId(), attrNameMap);
//                    list.add(ab);
//                    attrNameMap.put(ab.name, ab);
//                } else if ("delete".equals(cache.getOperateType())) {
//                    attrNameMap = removeMapItemByOid(cache.getObjId(), attrNameMap);
//                    list = removeListItemByOid(cache.getObjId(), list);
//                }
//            }
//            attributes = list.toArray(new AttribItem[list.size()]);
//            arraySort();
//        } catch (Throwable e) {
//            e.printStackTrace();
//            throw getLocalVciError("P0010PLMAP-00012", e);
//        }
//        flag = true;
//        return flag;
//    }
//    
//    protected VCIError getLocalVciError(String key, Throwable e) {
//        VCIError error = new VCIError(key, new String[]{VciExceptionTool.getExceptionStr(e), VciExceptionTool.getExceptionDetail(e)});
//        VCIError rsError = ExceptionLocalHandler.getInstance().getLocalString(error, "PLMAP");
//        return rsError;
//    }
//    
//    private Map<String, AttribItem> removeMapItemByOid(String oid, Map<String, AttribItem> map) {
//        for (Iterator<String> it = map.keySet().iterator();it.hasNext();) {
//            AttribItem ab = map.get(it.next());
//            if (oid.equals(ab.oid)) {
//                map.remove(ab);
//            }
//        }
//        
//        resetCache();
//        return map;
//    }
//    
//    private List<AttribItem> removeListItemByOid(String oid, List<AttribItem> list) {
//        Iterator<AttribItem> it = list.iterator();
//        for (;it.hasNext();) {
//            AttribItem ab = it.next();
//            if (oid.equals(ab.oid)) {
//                it.remove();
//            }
//        }
//        
//        resetCache();
//        return list;
//    }
//    
//    private void resetCache() {
//        this.resetCache(CACHENAME);
//    }
}