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();
|
}
|
}
|
|
}
|