package com.vci.server.framework.delegate;
|
|
import java.text.SimpleDateFormat;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
|
import com.vci.common.utility.ObjectUtility;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.framework.data.LogInfo;
|
import com.vci.corba.framework.data.LogPeriodInfo;
|
import com.vci.corba.framework.data.SystemCfgInfo;
|
import com.vci.corba.common.data.UserEntityInfo;
|
import com.vci.corba.framework.data.UserInfo;
|
import com.vci.server.base.delegate.UserEntityDelegate;
|
import com.vci.server.framework.systemConfig.SystemCfg;
|
import com.vci.server.framework.systemConfig.log.Log;
|
import com.vci.server.framework.systemConfig.log.LogPeriod;
|
import com.vci.server.framework.systemConfig.log.LogService;
|
|
public class LogManagementDelegate {
|
|
/**
|
* 在初始化日志模块时,检查是否配置了自动删除
|
* @return true表示设置了自动删除
|
* @throws VCIError
|
*/
|
public boolean getIsAutoDelete() throws VCIError {
|
boolean res = false;
|
try {
|
LogService logSrv = new LogService();
|
res = logSrv.getIsAutoDelete();
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140101", new String[]{});//获取日志删除配置出错,请重试!
|
}
|
return res ;
|
}
|
|
/**
|
* 初始化日志模块时,获取保存期限和备份期限下拉框列表
|
* @return 配置好的期限值的集合
|
* @throws VCIError
|
*/
|
public LogPeriodInfo[] getPeriods() throws VCIError {
|
LogPeriod[] periods = null;
|
LogPeriodInfo[] infos = null;
|
try {
|
LogService logSrv = new LogService();
|
periods = logSrv.getPeriods();
|
if(periods!=null) {
|
infos = new LogPeriodInfo[periods.length];
|
for(int i=0;i<periods.length;i++) {
|
infos[i] = changePeriodObjToInfo(periods[i]);
|
}
|
} else {
|
infos = new LogPeriodInfo[0];
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140102", new String[]{});//获取日志配置期限出错,请重试!
|
}
|
return infos;
|
}
|
|
/**
|
* 获取日志页面显示条数
|
* @return
|
* @throws VCIError
|
*/
|
public int getPageSize() throws VCIError {
|
int pageSize = 0;
|
try {
|
LogService logSrv = new LogService();
|
pageSize = logSrv.getPageSize();
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140103", new String[]{});//获取日志页面显示条数出错,请重试!
|
}
|
return pageSize;
|
}
|
|
/**
|
* 获取当前查询日志总数
|
* @param sql 带条件的查询语句
|
* @return
|
* @throws VCIError
|
*/
|
public long getSumLogRows(String sql) throws VCIError {
|
long sumRows = 0;
|
try {
|
LogService logSrv = new LogService();
|
sumRows = logSrv.getSumLogRows(sql);
|
}catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140104", new String[]{});//获取本次查询日志总数出错,请重试!
|
}
|
return sumRows ;
|
}
|
|
/**
|
* 获取全部日志信息
|
* @return
|
*/
|
public LogInfo[] fetchLogInfo(int pageNo,int pageSize,String sql) throws VCIError{
|
LogInfo[] logInfos = null;
|
try {
|
LogService logSrv = new LogService();
|
List<Log> list = logSrv.getLogList(pageNo, pageSize,sql);
|
logInfos = new LogInfo[list.size()];
|
Set<String> userIds = new HashSet<String>();
|
for(int i = 0;i < list.size();i++){
|
logInfos[i] = this.changeLogToLogInfo(list.get(i));
|
|
if (!userIds.contains(logInfos[i].username))
|
userIds.add(logInfos[i].username);
|
}
|
|
if(userIds.size()>0){
|
UserInfo[] userInfos = new RightManagementDelegate().fetchUserInfoByNames(userIds.toArray(new String[0]));
|
Map<String,String> userInfoMap = new HashMap<String,String>();
|
if(userInfos.length > 0 ){
|
for(int i = 0 ; i < userInfos.length; i ++){
|
UserInfo user = userInfos[i];
|
userInfoMap.put(user.userName, user.trueName);
|
}
|
}
|
for(int i = 0 ; i < logInfos.length ; i ++){
|
String userId = logInfos[i].username;
|
if(userInfoMap.containsKey(userId)){
|
logInfos[i].truename = userInfoMap.get(userId);
|
}
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140105", new String[]{});//查询日志出错,请重试!
|
}
|
return logInfos;
|
}
|
|
/**
|
* 根据查询条件获取日志信息
|
* <p>Description: </p>
|
*
|
* @author Administrator
|
* @time 2013-1-2
|
* @param pageNo
|
* @param pageSize
|
* @param sql
|
* @return
|
* @throws VCIError
|
*/
|
public LogInfo[] getLogListByContion(int pageNo,int pageSize,String sql) throws VCIError{
|
LogInfo[] logInfos = null;
|
try {
|
LogService logSrv = new LogService();
|
List<Log> list = logSrv.getLogListByContion(pageNo, pageSize,sql);
|
logInfos = new LogInfo[list.size()];
|
Set<String> userIds = new HashSet<String>();
|
for(int i = 0;i < list.size();i++){
|
logInfos[i] = this.changeLogToLogInfo(list.get(i));
|
userIds.add(logInfos[i].username);
|
}
|
if(userIds.size()>0){
|
UserInfo[] userInfos = new RightManagementDelegate().fetchUserInfoByNames(userIds.toArray(new String[0]));
|
Map<String,String> userInfoMap = new HashMap<String,String>();
|
if(userInfos.length > 0 ){
|
for(int i = 0 ; i < userInfos.length; i ++){
|
UserInfo user = userInfos[i];
|
userInfoMap.put(user.userName, user.trueName);
|
}
|
}
|
for(int i = 0 ; i < logInfos.length ; i ++){
|
String userId = logInfos[i].username;
|
if(userInfoMap.containsKey(userId)){
|
logInfos[i].truename = userInfoMap.get(userId);
|
}
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140105", new String[]{});//查询日志出错,请重试!
|
}
|
return logInfos;
|
}
|
|
/**
|
* 保存日志保存/备份期限
|
* @param info 系统配置表的对象
|
* @return
|
*/
|
public boolean savePeriod(SystemCfgInfo info,UserEntityInfo userEntityInfo) throws VCIError{
|
boolean res = false;
|
String id = ObjectUtility.getNewObjectID36();
|
try {
|
LogService logSrv = new LogService();
|
info.id = id;
|
UserEntityDelegate.setUserEntityToService(logSrv, userEntityInfo);
|
res = logSrv.savePeriod(changeSysCfgInfoToObj(info));
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140106", new String[]{});//保存期限出错,请重试!
|
}
|
return res ;
|
}
|
|
/**
|
* 获取保存/备份期限值
|
* @param type
|
* @return
|
* @throws VCIError
|
*/
|
public int getCurPeriod(String type) throws VCIError{
|
int period = 0;
|
try {
|
LogService logSrv = new LogService();
|
period = logSrv.getCurPeriod(type);
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140107", new String[]{});//获取期限数值出错,请重试!
|
}
|
return period;
|
}
|
|
public boolean deleteLog(String deleteDate) throws VCIError {
|
boolean res = false;
|
try {
|
LogService logSrv = new LogService();
|
res = logSrv.deleteLog(deleteDate);
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError("140108", new String[]{});//删除日志出错,请重试!
|
}
|
return res;
|
}
|
|
|
|
|
/**
|
* period
|
* 服务器端对象转成CORBA对象
|
* @param obj
|
* @return
|
*/
|
private LogPeriodInfo changePeriodObjToInfo(LogPeriod obj) {
|
LogPeriodInfo info = new LogPeriodInfo();
|
info.code = obj.getCode()==null?"":obj.getCode();
|
info.value = obj.getValue()==null?"":obj.getValue();
|
return info;
|
}
|
|
/**
|
* 系统配置
|
* CORBA对象转成服务器端对象
|
* @param info
|
* @return
|
*/
|
private SystemCfg changeSysCfgInfoToObj(SystemCfgInfo info) {
|
SystemCfg sys = new SystemCfg();
|
sys.setId(info.id);
|
sys.setName(info.name);
|
sys.setValue(info.value);
|
return sys;
|
}
|
|
/**
|
* Log
|
* 服务器端对象转成CORBA对象
|
* @param obj
|
* @return
|
*/
|
public LogInfo changeLogToLogInfo(Log obj){
|
LogInfo info = new LogInfo();
|
info.puid = obj.getId() == null?"":obj.getId();
|
info.type = obj.getType() == null?"":obj.getType();
|
info.date = obj.getDate() == null?"":new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(obj.getDate());
|
info.username = obj.getUsername() == null?"":obj.getUsername();
|
info.userIp = obj.getUserIp() == null?"":obj.getUserIp();
|
info.entityDesc = obj.getEntityDesc() == null?"":obj.getEntityDesc();
|
info.property = obj.getProperty() == null?"":obj.getProperty();
|
info.previousVal = obj.getPreviousVal() == null?"":obj.getPreviousVal();
|
info.newVal = obj.getNewVal() == null?"":obj.getNewVal();
|
info.result = obj.getResult() == null?"":obj.getResult();
|
info.moduleName = obj.getModule() == null?"":obj.getModule();
|
info.logType = obj.getLogType() == null ? "" : obj.getLogType();
|
return info;
|
}
|
}
|