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
package com.vci.server.base.utility;
 
import org.apache.commons.lang3.StringUtils;
 
import com.vci.common.objects.UserEntity;
import com.vci.corba.common.VCIError;
import com.vci.corba.log.LogServicePrx;
import com.vci.corba.log.data.LogType;
import com.vci.corba.log.data.RefObj;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.common.data.VCIInvocationInfo;
import com.vci.server.base.delegate.UserEntityDelegate;
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
 
public class LogRecordUtil {
 
    public static void saveLoginLog(boolean success, String content, UserEntityInfo userEnt) throws VCIError{
        
        if (userEnt == null)
            userEnt = getUserEntity();
        
        LogServicePrx logService = ServerServiceProvider.getLogService();
        
        logService.saveLoginLog(success, content, userEnt);
    }
    
    public static void saveLogoutLog(String content, UserEntityInfo userEnt) throws VCIError{
        if (userEnt == null)
            userEnt = getUserEntity();
        
        LogServicePrx logService = ServerServiceProvider.getLogService();
        
        logService.saveLogoutLog(content, userEnt);
    }
    
    /**
     * 日志记录
     * @param userEntity 用户对象
     * @param optType 操作类别
     * @param resContent 操作结构
     * @param logType 日志类型
     * @throws VCIError 
     */
    public static void writeLog(UserEntity userEnt, String optType, String result, String content, LogType logType,String dataObjId) throws VCIError{
        
        LogServicePrx logService = ServerServiceProvider.getLogService();
        
        logService.saveLog(result, content, optType, logType, dataObjId, UserEntityDelegate.changeUserEntityToInfo(userEnt));
    }
    
    /**
     * 日志记录
     * @param optType
     * @param result
     * @param content
     * @param logType
     * @param dataObjId
     * @throws VCIError
     */
    public static void writeGeneralSuccessLog(BusinessObject bo, String optType) throws VCIError{
        writeGeneralLog(bo, optType, "操作成功");
    }
    
    public static void writeGeneralFailLog(BusinessObject bo, String optType) throws VCIError{
        writeGeneralLog(bo, optType, "操作失败");
    }
    
    public static void writeGeneralLog(BusinessObject bo, String optType, String result) throws VCIError{
        
        UserEntityInfo userEnt = getUserEntity();
        
        LogServicePrx logService = ServerServiceProvider.getLogService();
        
        String logInfo = StringUtils.isNotBlank(bo.name)?bo.name:(StringUtils.isNotBlank(bo.id)?bo.id:bo.oid);
        
        logService.saveLog(result, logInfo, optType, LogType.General, bo.id, userEnt);
    }
 
    private static UserEntityInfo getUserEntity() {
        //日志记录
        VCIInvocationInfo viinfo = HibernateSessionFactory.getVciSessionInfo();
        String ip = "127.0.0.1";
        if(viinfo!=null){
            ip = viinfo.clientIPInfo == null||"".equals(viinfo.clientIPInfo) ? "127.0.0.1" : viinfo.clientIPInfo;
        }
        
        UserEntityInfo userEnt = new UserEntityInfo();
        userEnt.userName = viinfo.userName;
        userEnt.ip = ip;
        return userEnt;
    }
    
    /**
     * 日志记录
     * @param userEnt
     * @param optType
     * @param result
     * @param content
     * @param logType
     * @param dataObjId
     * @throws VCIError
     */
    public static void writeLog(UserEntityInfo userEnt, String optType, String result, String content, LogType logType,String dataObjId) throws VCIError{
        
        LogServicePrx logService = ServerServiceProvider.getLogService();
        
        logService.saveLog(result, content, optType, logType, dataObjId, userEnt);
    }
    
//    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);
//    }
 
    /**
     * 批量存储对象操作日志
     * @param userEnt
     * @param bos
     * @param operation
     * @param result
     * @throws VCIError
     */
    public static void batchWriteLog(UserEntityInfo userEnt, BusinessObject[] bos, String operation, String result) throws VCIError{
        if (bos == null || bos.length < 1) {
            return;
        }
        
        LogServicePrx logService = ServerServiceProvider.getLogService();
 
        userEnt.modules = "bo";
        
        RefObj[] ros = new RefObj[bos.length];
        for (int i = 0; i < bos.length; i++) {
            BusinessObject bo = bos[i];
            
            RefObj ro = new RefObj();
            ro.oid = bo.oid;
            ro.btName = bo.btName;
            ro.name = bo.name;
            ro.id = bo.id;
            
            ros[i] = ro;
        }
            
        try {
            logService.batchSaveObjLog(ros, operation, result, userEnt);
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
    
    /**
     * 批量保存对象操作日志
     * @param bos
     * @param operation
     * @param result
     * @throws VCIError
     */
    public static void batchWriteLog(BusinessObject[] bos, String operation) throws VCIError{
        batchWriteLog(bos, operation, "操作成功");
    }
    
    public static void batchWriteLog(BusinessObject[] bos, String operation, String result) throws VCIError{
        if (bos == null || bos.length < 1) {
            return;
        }
        
        //日志记录
        VCIInvocationInfo viinfo = HibernateSessionFactory.getVciSessionInfo();
        String ip = "127.0.0.1";
        if(viinfo!=null){
            ip = viinfo.clientIPInfo == null||"".equals(viinfo.clientIPInfo) ?"127.0.0.1":viinfo.clientIPInfo;
        }
        
        UserEntityInfo userEnt = new UserEntityInfo();
        userEnt.userName = viinfo.userName;
        userEnt.ip = ip;
        
        LogServicePrx logService = ServerServiceProvider.getLogService();
        
        userEnt.modules = "bo";
        
        RefObj[] ros = new RefObj[bos.length];
        for (int i = 0; i < bos.length; i++) {
            RefObj ro = new RefObj();
            
            BusinessObject bo = bos[i];
            
            ro.oid = bo.oid;
            ro.btName = bo.btName;
            ro.name = bo.name;
            ro.id = bo.id;
            
            ros[i] = ro;
        }
        
        try {
            logService.batchSaveObjLog(ros, operation, result, userEnt);
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
    
}