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
package com.vci.server.bof.server;
 
import org.apache.commons.lang3.StringUtils;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.LinkObject;
import com.vci.server.base.exception.ExceptionLocalHandler;
import com.vci.server.cache.OMCacheProvider;
import com.vci.common.exception.VciExceptionTool;
import com.vci.corba.common.VCIError;
import com.vci.corba.common.data.UserEntityInfo;
 
/**
 * 定义工具方法
 * 添加时请注意修饰
 * @author lmh
 *
 */
public class ServiceFacadeUtil {
    
    //只用来继承,不能实例化
    protected ServiceFacadeUtil(){};
    
    private static UserEntityInfo userEntity = new UserEntityInfo();
//    private static Map<String, BtmItem> mapBtm = new HashMap<String, BtmItem>();
    
    /**
     * 日志记录
     * @param user:操作人
     * @param module:操作模块
     * @param ip:操作人所在IP地址
     * @param operation:操作类型
     * @param type:对象类型
     * @param objName:对象名称
     * @param oid:对象OID
     * @throws VCIError 
     */
//    protected void recordLog(String user, String module, String ip, String operation, String type, String objName, String oid) throws VCIError {
//        userEntity.userName = user;
//        if(module.equalsIgnoreCase(type)){
//            userEntity.modules = getBtmShowName(module);
//        }else{
//            userEntity.modules = module;
//        }
//        userEntity.ip = ip;
//
//        String con = "操作的数据是->" + getBtmShowName(type) + ":" + objName;
//        //记录日志
//        
//        ServerServiceProvider.getFrameService().savelogGeneralOperation("操作成功", con, userEntity, oid, type);
//        //LogRecordUtil.writeLog(userEntity, operation, "操作成功", "操作的数据是->" + getBtmShowName(type) + ":" + objName, LogType.GeneralOperation, oid);
//    }
    
    /**
     * 批量存储log
     * @param bos
     * @param ip
     * @param operation
     * @throws HibernateException
     * @throws SQLException
     * @throws VCIError 
     */
//    protected void batchRecordLog(BusinessObject[] bos, String ip, String operation) throws HibernateException, SQLException, VCIError {
//        //batchRecordLog(bos,ip,operation,"操作成功");
//        LogRecordUtil.batchWriteLog(userEntity, bos, operation, "操作成功");
//    }
    
//    private void batchRecordLog(BusinessObject[] bos, String ip, String operation,String result) throws HibernateException, SQLException, VCIError{
//        if (bos == null || bos.length < 1) {
//            return;
//        }
//        
//        VCIInvocationInfo invInfo = HibernateSessionFactory.getVciSessionInfo();
//        
//        if (StringUtils.isEmpty(invInfo.userName))
//            userEntity.userName = bos[0].creator;
//        else
//            userEntity.userName = invInfo.userName;
//        
//        userEntity.ip = ip;
//        
//        String type = bos[0].btName;
//        userEntity.modules = getBtmShowName(type);
//        
//        FrameworkServicePrx fService= ServerServiceProvider.getFrameService();
//
////        ArrayList<String> logList = new ArrayList<String>();
//        for (int i = 0; i < bos.length; i++) {
//            BusinessObject bo = bos[i];
//            String info = StringUtils.isNotBlank(bo.name)?bo.name:(StringUtils.isNotBlank(bo.id)?bo.id:bo.oid);
//            String btmShowName = getBtmShowName(bos[i].btName);
//            
//            try {
//                LogRecordUtil.writeLog(userEntity, result, "操作的数据为->"+ btmShowName + ":" + info, operation, (short)LogType.GeneralOperation.getIntVal(), bos[i].oid);
//                //LogRecordUtil.w (result, "操作的数据为->"+ btmShowName + ":" + info, operation, (short)LogType.GeneralOperation.getIntVal(), bos[i].oid, userEntity);
//            } catch (VCIError e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }
//            
////            logList.add(LogRecordUtil.getLogSql(userEntity, operation, result, "操作的数据为->"+ btmShowName + ":" + info, LogType.GeneralOperation, bos[i].oid, role, btmShowName));
////            if ((i + 1) % 200 == 0) {
////                LogRecordUtil.batchSaveLog(logList.toArray(new String[logList.size()]));
////                logList.clear();
////            }
//        }
////        if (bos.length % 200 != 0) {
////            LogRecordUtil.batchSaveLog(logList.toArray(new String[logList.size()]));
////            logList.clear();
////        }
//    }
    
//    protected void batchFailRecordLog(BusinessObject[] bos, String ip, String operation) throws HibernateException, SQLException, VCIError{
//        batchRecordLog(bos,ip,operation,"操作失败");
//    }
    
    
    /**
     * 获取国际化的错误提示信息,将其设置到VCIError的key中
     * @param VCIError
     * @return
     */
    protected VCIError getLocalString(String key, Throwable e) {
        VCIError error = null;
        if (e == null) {
            error = new VCIError(key, new String[0]);
        } else if (e instanceof VCIError) {
            error = (VCIError) e;
        } else {
            error = new VCIError(key, new String[]{VciExceptionTool.getExceptionStr(e), VciExceptionTool.getExceptionDetail(e)});
        }
        VCIError rsError = ExceptionLocalHandler.getInstance().getLocalString(error, "PLMBOFactory");
        return rsError;
    }
    
    protected void dealBusinessObjectNullValue(LinkObject lo) {
        lo.oid = lo.oid == null ? "" : lo.oid;
        lo.creator = lo.creator == null ? "" : lo.creator;
        //lo.createTime = lo.createTime;
        lo.modifier = lo.modifier == null ? "" : lo.modifier;
        //lo.modifyTime = lo.modifyTime;
        lo.ltName = lo.ltName == null ? "" : lo.ltName;
        
        lo.fromOid = lo.fromOid == null ? "" : lo.fromOid;
        lo.fromRevOid = lo.fromRevOid == null ? "" : lo.fromRevOid;
        lo.fromNameOid = lo.fromNameOid == null ? "" : lo.fromNameOid;
        lo.fromBTName = lo.fromBTName == null ? "" : lo.fromBTName;
        
        lo.toOid = lo.toOid == null ? "" : lo.toOid;
        lo.toRevOid = lo.toRevOid == null ? "" : lo.toRevOid;
        lo.toNameOid = lo.toNameOid == null ? "" : lo.toNameOid;
        lo.toBTName = lo.toBTName == null ? "" : lo.toBTName;
        
        //lo.ts = lo.ts;
        lo.newAttrValList = new AttributeValue[0];
        if (lo.hisAttrValList == null) {
            lo.hisAttrValList = new AttributeValue[0];
        }
        for (int i = 0; i < lo.hisAttrValList.length; i++) {
            if (lo.hisAttrValList[i].attrVal == null) {
                lo.hisAttrValList[i].attrVal = "";
            }
        }
    }
    
 
    protected synchronized  String getBtmShowName(String btmName){
        if(StringUtils.isBlank(btmName)){
            return "";
        }
        
        BtmItem bt = OMCacheProvider.getBizType(btmName);
        
//        if (!mapBtm.containsKey(btmName)) {
//            BtmItem bt;
//            try {
//                //bt = ServerServiceProvider.getOMDService().getBTMService().getBtmItemByName(btmName);
//                bt = OMCacheProvider.getBizType(btmName);
//                mapBtm.put(btmName, bt);
//            } catch (Exception e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }
//        }
//        
//        BtmItem bt = mapBtm.get(btmName);
        if (bt == null)
            return "";
        
        return bt.label;
        
//        String sql = " select label from plbtmtype where name = ?";
//        SQLQuery query = HibernateSessionFactory.getSession().createSQLQuery(sql);
//        query.setString(0, btmName.trim());
//        
//        List<?> queryList = query.list();
//        if(queryList.size()>0){
//            Object value = queryList.get(0);
//            if(value instanceof Map){
//                return ((Map)value).get("label").toString();
//            }else{
//                return value.toString();
//            }
//        }
//        
//        return btmName;
    }
}