2023-12-25 09:36:23 +08:00
package com.engine.salary.elog.service.impl ;
import cn.hutool.core.date.DateUtil ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
2023-12-26 16:12:44 +08:00
import com.cloudstore.eccom.pc.table.WeaTable ;
import com.cloudstore.eccom.pc.table.WeaTableColumn ;
import com.engine.core.impl.Service ;
import com.engine.salary.constant.SalaryDefaultTenantConstant ;
import com.engine.salary.elog.annotation.OperateType ;
import com.engine.salary.elog.entity.dto.ElogBean ;
import com.engine.salary.elog.entity.dto.FilterConditionDto ;
import com.engine.salary.elog.entity.dto.LoggerContext ;
import com.engine.salary.elog.entity.dto.ShowColumsDto ;
import com.engine.salary.elog.entity.param.ELogGetLogParam ;
2023-12-26 17:49:50 +08:00
import com.engine.salary.elog.entity.param.GetDetailChangesParam ;
2023-12-26 16:12:44 +08:00
import com.engine.salary.elog.enums.ElogConsts ;
2023-12-25 09:36:23 +08:00
import com.engine.salary.elog.service.ILoggerTableService ;
import com.engine.salary.elog.util.ElogServiceUtils ;
2023-12-26 16:12:44 +08:00
import com.engine.salary.elog.util.ElogSeviceSwitchUtils ;
2023-12-25 09:36:23 +08:00
import com.engine.salary.elog.util.ElogSeviceUtils ;
2023-12-26 16:12:44 +08:00
import com.engine.salary.elog.util.FieldNameMap ;
2023-12-25 09:36:23 +08:00
import com.engine.salary.mapper.elog.LocalElogDaoMapper ;
2023-12-26 16:12:44 +08:00
import com.engine.salary.util.SalaryI18nUtil ;
import com.engine.salary.util.db.MapperProxyFactory ;
import com.engine.salary.util.page.Column ;
import com.engine.salary.util.page.PageInfo ;
import com.engine.salary.util.page.SalaryPageUtil ;
import com.github.pagehelper.Page ;
import org.apache.commons.collections4.CollectionUtils ;
2023-12-25 09:36:23 +08:00
import org.apache.commons.lang3.StringUtils ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2023-12-26 16:12:44 +08:00
import weaver.conn.RecordSet ;
import weaver.general.Util ;
2023-12-25 09:36:23 +08:00
import javax.servlet.http.HttpServletRequest ;
import java.util.* ;
import java.util.stream.Collectors ;
2023-12-26 16:12:44 +08:00
public class LoggerTableService extends Service implements ILoggerTableService {
2023-12-25 09:36:23 +08:00
private static final Logger logger = LoggerFactory . getLogger ( LoggerTableService . class ) ;
2023-12-26 16:12:44 +08:00
private LocalElogDaoMapper getLocalElogDaoMapper ( ) {
return MapperProxyFactory . getProxy ( LocalElogDaoMapper . class ) ;
}
2023-12-25 09:36:23 +08:00
2023-12-26 16:12:44 +08:00
//
// private ComInfoCache comInfoCache;
//
//
// private HrmCommonUtil hrmCommonUtil;
//
//
// private QueryCommonTabeMapper queryCommonTabeMapper;
//
//
// private RestHighLevelClient restHighLevelClient;
//
// @Resource
// private BatchExportSender batchExportSender;
//
//
// @Resource
// private DateRangeTransformer dateRangeTransformer;
//
//
// private HrmCommonEmployeeService hrmCommonEmployeeService;
//
//
private final String databaseId = new RecordSet ( ) . getDBType ( ) ;
2023-12-25 09:36:23 +08:00
@Override
2023-12-26 16:12:44 +08:00
public PageInfo queryLogs ( String data ) {
2023-12-25 09:36:23 +08:00
//解析数据
ElogBean elogBean = ElogServiceUtils . getElogBean ( data ) ;
// columIndex统一转为小写
Optional . ofNullable ( elogBean . getShowColumns ( ) )
. ifPresent ( list - > {
list . forEach ( x - > {
if ( StringUtils . isNotBlank ( x . getColumIndex ( ) ) ) {
x . setColumIndex ( x . getColumIndex ( ) . toLowerCase ( ) ) ;
}
} ) ;
} ) ;
List < ShowColumsDto > showColums = elogBean . getShowColumns ( ) ;
String module = elogBean . getModule ( ) ;
String function = elogBean . getFunction ( ) ;
String searchMap = elogBean . getSearchMap ( ) ;
String pageSize = elogBean . getPageSize ( ) ;
2024-01-29 16:21:17 +08:00
String pageNum = elogBean . getCurrent ( ) ;
2023-12-25 09:36:23 +08:00
String downloadSize = elogBean . getDownloadSize ( ) ;
List < FilterConditionDto > filterConditionDtos = elogBean . getFilterConditionDtos ( ) ;
String transMethod = elogBean . getTransMethod ( ) ;
Map authParamsJson = elogBean . getAuthParamsJson ( ) ;
//获取 context 数据
LoggerContext context = new LoggerContext ( ) ;
context . setModuleName ( module ) ;
context . setFunctionName ( function ) ;
context . setTenant_key ( getTenantKey ( ) ) ;
// context.setOperator(getEmployeeId());
//获取主表
String tableName = ElogSeviceUtils . getTableName ( module , function ) ;
//获取weaTable
2023-12-26 16:12:44 +08:00
List < Column > columns = getWeaColumns ( data , showColums , module , function ) ;
2023-12-25 09:36:23 +08:00
//获取条件sql
2023-12-26 16:12:44 +08:00
String searchMapsql = getSearchMapSql ( searchMap , module , function , elogBean . getShowColumns ( ) ) ;
2023-12-25 09:36:23 +08:00
String sb = getQueryCondition ( filterConditionDtos ) ;
sb = searchMapsql . concat ( sb ) ;
String customSql = getCustomSql ( transMethod , sb , " before " ) ;
// 分页
Page page = null ;
if ( StringUtils . isEmpty ( downloadSize ) ) {
page = new Page ( ElogSeviceUtils . getIntValue ( pageNum , 1 ) , ElogSeviceUtils . getIntValue ( pageSize , 10 ) ) ;
} else {
int pagesize = ElogSeviceUtils . getIntValue ( downloadSize , 5000 ) ;
page = new Page ( 1 , pagesize ) ;
}
2023-12-26 16:12:44 +08:00
List < Map > list = getLocalElogDaoMapper ( ) . queryElogList ( page , context , null , tableName , customSql , " * " ) ;
Map < String , Object > countMap = getLocalElogDaoMapper ( ) . elogCount ( context , tableName , customSql ) ;
2023-12-25 09:36:23 +08:00
if ( " st " . equals ( databaseId ) ) {
//st数据库 date类型特殊处理
list . forEach ( map - > {
map . forEach ( ( k , v ) - > {
if ( v instanceof Date ) {
map . put ( k , DateUtil . format ( ( Date ) v , " yyyy-MM-dd HH:mm:ss " ) ) ;
}
} ) ;
} ) ;
}
//处理转换其他数据库类型值
list = ElogSeviceSwitchUtils . getSwitchDatabaseData ( list ) ;
//处理用户信息Data
// 大小写转换
ElogSeviceSwitchUtils . changKey2Lower ( list ) ;
// 存放结果集
2023-12-26 16:12:44 +08:00
PageInfo pageInfo = SalaryPageUtil . buildPage ( page . getPageNum ( ) , page . getPageSize ( ) , switchString ( list ) ) ;
pageInfo . setTotal ( ElogSeviceUtils . getLongValue ( countMap . get ( " counts " ) + " " , 0 ) ) ;
pageInfo . setColumns ( columns ) ;
return pageInfo ;
2023-12-25 09:36:23 +08:00
}
@Override
public WeaTable queryLogsPapi ( String data , HttpServletRequest request ) {
return null ;
}
@Override
public List getDetailChangesPapi ( String module , String function , String mainid , String transMethod , HttpServletRequest request ) {
return null ;
}
private String getshowColumsStr ( List < ShowColumsDto > showColums ) {
StringBuffer sb = new StringBuffer ( ) ;
sb . append ( " id,uuid,targetid,params,operatetype,link_id,link_type, " ) ;
for ( ShowColumsDto showColum : showColums ) {
String columIndex = showColum . getColumIndex ( ) ;
2023-12-26 16:12:44 +08:00
if ( " date " . equalsIgnoreCase ( columIndex ) | | " createdate " . equalsIgnoreCase ( columIndex ) ) {
2023-12-25 09:36:23 +08:00
columIndex = " log_date " ;
2023-12-26 16:12:44 +08:00
} else if ( " operator " . equalsIgnoreCase ( columIndex ) ) {
2023-12-25 09:36:23 +08:00
columIndex = " log_operator " ;
2023-12-26 16:12:44 +08:00
} else if ( " modulenamespan " . equalsIgnoreCase ( columIndex ) ) {
2023-12-25 09:36:23 +08:00
columIndex = " modulename " ;
2023-12-26 16:12:44 +08:00
} else if ( " functionnameespan " . equalsIgnoreCase ( columIndex ) ) {
2023-12-25 09:36:23 +08:00
columIndex = " functionname " ;
} else if ( " avatar " . equals ( columIndex ) ) {
continue ;
}
sb . append ( columIndex ) . append ( " , " ) ;
}
String substring = sb . toString ( ) . substring ( 0 , sb . toString ( ) . length ( ) - 1 ) ;
return substring ;
}
2023-12-26 16:12:44 +08:00
// private PermissionParams getPermissionParams(Map hashMap) {
// PermissionParams permissionParams = new PermissionParams();
// String permissionId = getPermissionStr(hashMap, "permissionId");
// String permissionType = getPermissionStr(hashMap, "permissionType");
// String mainDataTableAlias = getPermissionStr(hashMap, "mainDataTableAlias");
// String mainDataTable = getPermissionStr(hashMap, "mainDataTable");
// String primaryKey = getPermissionStr(hashMap, "primaryKey");
// String permissionTargetId = getPermissionStr(hashMap, "permissionTargetId");
// String permissionConfigSourceId = getPermissionStr(hashMap, "permissionConfigSourceId");
//
// permissionParams.setPermissionId(permissionId);
// permissionParams.setPermissionType(permissionType);
// permissionParams.setMainDataTableAlias(mainDataTableAlias);
// permissionParams.setMainDataTable(mainDataTable);
// permissionParams.setPrimaryKey(primaryKey);
// permissionParams.setPermissionTargetId(permissionTargetId);
// permissionParams.setPermissionConfigSourceId(permissionConfigSourceId);
//
// return permissionParams;
//
// }
2023-12-25 09:36:23 +08:00
2023-12-26 16:12:44 +08:00
private List < Column > getWeaColumns ( String data , List < ShowColumsDto > showColums , String module , String function ) {
List < Column > columns = new ArrayList < > ( ) ;
2023-12-25 09:36:23 +08:00
if ( showColums ! = null & & showColums . size ( ) > 0 ) {
for ( ShowColumsDto showColum : showColums ) {
if ( StringUtils . isNotBlank ( showColum . getAliasColumName ( ) ) ) {
2023-12-26 16:12:44 +08:00
columns . add ( new Column ( showColum . getAliasColumName ( ) , showColum . getColumIndex ( ) , showColum . getColumIndex ( ) ) ) ;
2023-12-25 09:36:23 +08:00
} else if ( StringUtils . isNotBlank ( showColum . getColumName ( ) ) ) {
2023-12-26 16:12:44 +08:00
columns . add ( new Column ( FieldNameMap . getMainFieldNameMap ( data , function , showColum . getColumName ( ) ) , showColum . getColumIndex ( ) , showColum . getColumIndex ( ) ) ) ;
2023-12-25 09:36:23 +08:00
}
}
} else {
2023-12-26 16:12:44 +08:00
columns . add ( new Column ( FieldNameMap . getMainFieldNameMap ( module , function , " moduleName " ) , " modulenamespan " , " modulenamespan " ) ) ;
columns . add ( new Column ( FieldNameMap . getMainFieldNameMap ( module , function , " functionName " ) , " functionnamespan " , " functionnamespan " ) ) ;
columns . add ( new Column ( FieldNameMap . getMainFieldNameMap ( module , function , " clientIp " ) , " clientip " , " clientip " ) ) ;
columns . add ( new Column ( FieldNameMap . getMainFieldNameMap ( module , function , " operateTypeName " ) , " operatetypename " , " operatetypename " ) ) ;
columns . add ( new Column ( FieldNameMap . getMainFieldNameMap ( module , function , " targetName " ) , " targetname " , " targetname " ) ) ;
columns . add ( new Column ( FieldNameMap . getMainFieldNameMap ( module , function , " date " ) , " createdate " , " createdate " ) ) ;
columns . add ( new Column ( FieldNameMap . getMainFieldNameMap ( module , function , " operatorName " ) , " operatorname " , " operatorname " ) ) ;
2023-12-25 09:36:23 +08:00
}
2023-12-26 16:12:44 +08:00
return columns ;
2023-12-25 09:36:23 +08:00
}
private String getTargetid ( List < FilterConditionDto > filterConditionDtos ) {
if ( ! filterConditionDtos . isEmpty ( ) ) {
for ( FilterConditionDto filterConditionDto : filterConditionDtos ) {
if ( " targetid " . equalsIgnoreCase ( filterConditionDto . getColumIndex ( ) ) ) {
return filterConditionDto . getValue ( ) ;
}
}
}
return " " ;
}
private String getPermissionStr ( Map hashMap , String str ) {
if ( hashMap ! = null & & hashMap . size ( ) > 0 ) {
Object obj = hashMap . get ( str ) ;
if ( obj ! = null ) {
return obj . toString ( ) ;
}
}
return " " ;
}
2023-12-26 16:12:44 +08:00
// private Map getCustomAuthSql(String transMethod, Map params, String prefix) {
// MethodHandler beforeMethodHandler = ElogMethodHandler.loadMethodHandler(prefix + transMethod);
// Map<String, Object> hashMap = new HashMap<>();
// if (beforeMethodHandler != null) {
// try {
// hashMap.put("flag", true);
// hashMap.put("msg", "");
// hashMap.putAll(params);
// Object execute = beforeMethodHandler.execute(hashMap);
// if (execute != null && execute instanceof Map) {
// Map map = (Map) execute;
// return map;
// }
// } catch (Exception e) {
// logger.error("转换出错:" + e);
// throw new RuntimeException(e.getMessage());
// }
// }
// return hashMap;
// }
2023-12-25 09:36:23 +08:00
private String getCustomSql ( String transMethod , String sql , String prefix ) {
2023-12-26 16:12:44 +08:00
// MethodHandler beforeMethodHandler = ElogMethodHandler.loadMethodHandler(prefix + transMethod);
// boolean flag = false;
// if (beforeMethodHandler != null) {
// try {
// String subSql = "";
// if (sql.length() > 5) {
// flag = true;
// subSql = sql.substring(5, sql.length());
// }
// Object execute = beforeMethodHandler.execute(subSql);
// if (execute != null) {
// if (execute instanceof String) {
// StringBuffer sb = null;
// if(execute.toString().length()==0){
// sb = new StringBuffer();
// } else if (flag || execute.toString().length() > 0) {
// sb = new StringBuffer(" and ");
// } else {
// sb = new StringBuffer();
// }
//
// sb.append(execute.toString());
// return sb.toString();
// }
// }
// } catch (Exception e) {
// logger.error("转换出错:" + e);
// throw new RuntimeException(e.getMessage());
// }
// }
2023-12-25 09:36:23 +08:00
return sql ;
}
private void transUserInfo ( List < Map > list ) {
2023-12-26 16:12:44 +08:00
// List<Object> operators = new ArrayList<>();
// if (list != null && list.size() > 0) {
// for (Map map : list) {
// //避免暴露内网地址
// map.remove("requesturl");
//
// Object operator = map.get("operator");
// if (operator != null && StringUtils.isNotBlank(operator.toString())) {
// operators.add(ElogSeviceUtils.getLongValue(operator.toString()));
// }
// }
// }
// List<HrmEmployeeComInfo> cacheList = comInfoCache.getCacheList(HrmEmployeeComInfo.class, operators);
// Map<Long, ElogHrmSimpleEmployeeInfo> infoHashMap = new HashMap<>();
// if (cacheList != null && cacheList.size() > 0) {
// for (HrmEmployeeComInfo hrmEmployeeComInfo : cacheList) {
// HrmAvatarComInfo hrmAvatarComInfo = (HrmAvatarComInfo) comInfoCache.getCacheById(HrmAvatarComInfo.class, hrmEmployeeComInfo.getAvatar());
// ElogHrmSimpleEmployeeInfo info = new ElogHrmSimpleEmployeeInfo();
// if (hrmAvatarComInfo != null) {
// info.setAvatarP3Id(hrmAvatarComInfo.getP3());
// }
// info.setId(hrmEmployeeComInfo.getId());
// info.setUserName(hrmEmployeeComInfo.getUsername());
// infoHashMap.put(hrmEmployeeComInfo.getId(), info);
// }
// }
// if (list != null && list.size() > 0) {
// for (Map map : list) {
// Object operator = map.get("operator");
// if (map.get("params") != null && map.get("params").toString().startsWith("H4s")) {
// map.put("params", ElogSeviceUtils.uncompress(map.get("params").toString()));
// }
// map.put("dboperatorname", Util.null2String(map.get("operatorname")));
// if (operator != null && StringUtils.isNotBlank(operator.toString())) {
// Map<Long, String> i18nOperatorMap = new HashMap<>();
// ElogHrmSimpleEmployeeInfo hrmEmployeeComInfo = infoHashMap.get(Long.parseLong(operator.toString()));
// if (hrmEmployeeComInfo != null) {
// //获取最新的人员名称并进行多语言转换
// i18nOperatorMap.put(Long.parseLong(operator.toString()), hrmEmployeeComInfo.getUserName());
// Map<Long, String> parseI18nOperator = HrmI18nUtil.batchCovertEmployee(i18nOperatorMap, map.get("tenant_key").toString());
// map.put("operatorname", parseI18nOperator.get(Long.parseLong(operator.toString())));
//
//// if (StringUtils.isNotEmpty(hrmEmployeeComInfo.getUserName())) {
//// map.put("operatorname", hrmEmployeeComInfo.getUserName());
//// }
// if (hrmEmployeeComInfo.getAvatarP3Id() != null) {
// map.put("avatar", hrmEmployeeComInfo.getAvatarP3Id());
2023-12-25 09:36:23 +08:00
// }
2023-12-26 16:12:44 +08:00
// }
// }
2023-12-25 09:36:23 +08:00
// }
// }
2023-12-26 16:12:44 +08:00
}
2023-12-25 09:36:23 +08:00
/ * *
* 获取宽度
*
* @param showColum
* @return
* /
private String getColumnsWidth ( ShowColumsDto showColum ) {
if ( StringUtils . isBlank ( showColum . getWidth ( ) ) ) {
return " 5% " ;
} else {
return showColum . getWidth ( ) ;
}
}
private String getTenantKey ( ) {
2023-12-26 16:12:44 +08:00
// User currentUser = UserContext.getCurrentUser();
// if (currentUser != null) {
// return currentUser.getTenantKey();
// } else {
// String tenantKey = TenantRpcContext.getTenantKey();
// if (StringUtils.isNotBlank(tenantKey)) {
// return tenantKey;
// }
// }
return SalaryDefaultTenantConstant . DEFAULT_TENANT_KEY ;
2023-12-25 09:36:23 +08:00
}
2023-12-26 16:12:44 +08:00
// private String getEmployeeId() {
//
// User currentUser = UserContext.getCurrentUser();
// if (currentUser != null && !currentUser.isAdmin()) {
// String employeeId = TenantRpcContext.getEmployeeId();
// return StringUtils.isNotBlank(employeeId) ? employeeId : "";
// }
// return "";
// }
//
// private String getUserId() {
// User currentUser = UserContext.getCurrentUser();
// if (currentUser != null) {
// return currentUser.getEmployeeId().toString();
// }
// String employeeId = TenantRpcContext.getEmployeeId();
// return StringUtils.isNotBlank(employeeId) ? employeeId : "";
// }
2023-12-25 09:36:23 +08:00
/ * *
* 拼接搜索条件
*
* @param searchMap
* @param module
* @param function
* @return
* /
private String getSearchMapSql ( String searchMap , String module , String function , List < ShowColumsDto > showColumns ) {
StringBuffer sb = new StringBuffer ( ) ;
Map map = JSON . parseObject ( searchMap ) ;
if ( map = = null ) return sb . toString ( ) ;
Iterator < Map . Entry < String , Object > > iterators = map . entrySet ( ) . iterator ( ) ;
while ( iterators . hasNext ( ) ) {
Map . Entry < String , Object > next = iterators . next ( ) ;
String key = next . getKey ( ) ;
2023-12-26 16:12:44 +08:00
// SecurityUtil.sqlCheck(key);
2023-12-25 09:36:23 +08:00
if ( " date " . equals ( key ) | | " createdate " . equals ( key ) ) {
Object date = next . getValue ( ) ;
if ( date ! = null ) {
if ( StringUtils . isNotBlank ( date . toString ( ) ) ) {
List dates = ( List ) date ;
2023-12-26 16:12:44 +08:00
// if (dates != null && dates.size() == 2) {
// Object startDate = dates.get(0);
// Object endDate = dates.get(1);
// startDate = ElogSeviceUtils.checkValSql(startDate.toString());
// endDate = ElogSeviceUtils.checkValSql(endDate.toString());
// if (StringUtils.isNotBlank(startDate.toString()) && StringUtils.isNotBlank(endDate.toString())) {
// startDate = startDate.toString().replaceAll("'", "''");
// endDate = endDate.toString().replaceAll("'", "''");
// String dateRangeAfter = dateRangeTransformer.getDateRangeAfter(startDate.toString());
// String dateRangeBefore = dateRangeTransformer.getDateRangeBefore(endDate.toString());
// sb.append(" and log_date ").append(" between ").append(getSwithDatabaseDate(dateRangeAfter)).append(" and ").append(getSwithDatabaseDate(dateRangeBefore)).append(" ");
// } else if (StringUtils.isNotBlank(startDate.toString())) {
// String dateRangeAfter = dateRangeTransformer.getDateRangeAfter(startDate.toString());
// sb.append(" and log_date ").append(" >= ").append(getSwithDatabaseDate(dateRangeAfter)).append(" ");
// } else if (StringUtils.isNotBlank(endDate.toString())) {
// String dateRangeBefore = dateRangeTransformer.getDateRangeBefore(endDate.toString());
// sb.append(" and log_date ").append(" <= ").append(getSwithDatabaseDate(dateRangeBefore)).append(" ");
// }
// }
2023-12-25 09:36:23 +08:00
}
}
} else if ( " operator " . equals ( next . getKey ( ) ) ) {
Object operator = next . getValue ( ) ;
if ( operator ! = null ) {
if ( StringUtils . isNotBlank ( operator . toString ( ) ) ) {
operator = ElogSeviceUtils . checkValSql ( operator . toString ( ) ) ;
operator = operator . toString ( ) . replaceAll ( " ' " , " '' " ) ;
2023-12-26 16:12:44 +08:00
if ( StringUtils . isNumeric ( operator . toString ( ) ) & & operator . toString ( ) . length ( ) > 15 ) {
2023-12-25 09:36:23 +08:00
sb . append ( " and log_operator = " ) . append ( operator . toString ( ) ) . append ( " " ) ;
}
2023-12-26 16:12:44 +08:00
// else {
// List<HrmEmployee> likeNameHrmEmployeeList = hrmCommonEmployeeService.queryEmpsByCondidtion(
// new HrmOrgEmpCondition().setNameLikeList(Arrays.asList(operator.toString())).setTenantKey(getTenantKey()),
// HrmConditionResultType.BEAN.name());
// if (likeNameHrmEmployeeList != null && likeNameHrmEmployeeList.size() > 0) {
// List<Long> ids = likeNameHrmEmployeeList.stream().map(HrmEmployee::getId).collect(Collectors.toList());
// if (ids != null && ids.size() > 0) {
// sb.append(" and ( operatorname like '%").append(operator.toString()).append("%' ")
// .append(" or log_operator in (").append(StringUtils.join(ids, ",")).append(")) ");
// }
// } else {
// sb.append(" and operatorname like '%").append(operator.toString()).append("%' ");
// }
// }
2023-12-25 09:36:23 +08:00
}
}
} else if ( " modulename " . equals ( next . getKey ( ) ) ) {
Object moduleName = next . getValue ( ) ;
if ( moduleName ! = null ) {
moduleName = moduleName . toString ( ) . replaceAll ( " ' " , " '' " ) ;
if ( StringUtils . isNotBlank ( moduleName . toString ( ) ) ) {
moduleName = ElogSeviceUtils . checkValSql ( moduleName . toString ( ) ) ;
//sb.append(" and modulename = '").append(moduleName.toString()).append("' ");
StringBuffer stringBuffer = new StringBuffer ( ) ;
if ( isEnglish ( moduleName . toString ( ) ) ) {
Map < String , Integer > moduleMap = ElogSeviceSwitchUtils . moduleMap ;
Iterator < Map . Entry < String , Integer > > iterator = moduleMap . entrySet ( ) . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
Map . Entry < String , Integer > nextObj = iterator . next ( ) ;
if ( nextObj . getKey ( ) . contains ( moduleName . toString ( ) ) ) {
stringBuffer . append ( " ' " ) . append ( nextObj . getKey ( ) ) . append ( " ', " ) ;
}
}
} else {
Map < String , Integer > moduleMap = ElogSeviceSwitchUtils . moduleMap ;
Iterator < Map . Entry < String , Integer > > iterator = moduleMap . entrySet ( ) . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
Map . Entry < String , Integer > nextObj = iterator . next ( ) ;
String val = ElogSeviceSwitchUtils . getModuleName ( nextObj . getValue ( ) + " " ) ;
if ( val . contains ( moduleName . toString ( ) ) ) {
stringBuffer . append ( " ' " ) . append ( nextObj . getKey ( ) ) . append ( " ', " ) ;
}
}
}
String str = " " ;
if ( stringBuffer . toString ( ) . length ( ) > 0 ) {
str = stringBuffer . substring ( 0 , stringBuffer . length ( ) - 1 ) ;
String inVals = str . toString ( ) . replaceAll ( " '' " , " ' " ) ;
sb . append ( " and modulename in ( " ) . append ( inVals ) . append ( " ) " ) ;
} else {
sb . append ( " and modulename = ' " ) . append ( moduleName . toString ( ) ) . append ( " ' " ) ;
}
}
}
2023-12-26 16:12:44 +08:00
} else if ( databaseId . equalsIgnoreCase ( ElogConsts . POSTGRESQL ) & & " targetid " . equalsIgnoreCase ( next . getKey ( ) ) ) {
2023-12-25 09:36:23 +08:00
//兼容PG环境int类型不支持模糊搜索的问题
String value = next . getValue ( ) . toString ( ) . replaceAll ( " ' " , " '' " ) ;
value = ElogSeviceUtils . checkValSql ( value . toString ( ) ) ;
if ( value . startsWith ( " _ " ) ) {
value = value . replace ( " _ " , " \\ _ " ) ;
}
//将类型转为varchar再进行查询
sb . append ( " and " ) . append ( " cast( " ) . append ( key ) . append ( " as VARCHAR(255) ) " ) . append ( " like '% " ) . append ( value ) . append ( " %' " ) ;
} else {
if ( next . getValue ( ) ! = null & & StringUtils . isNotBlank ( key ) & & StringUtils . isNotBlank ( next . getValue ( ) . toString ( ) ) ) {
String value = next . getValue ( ) . toString ( ) . replaceAll ( " ' " , " '' " ) ;
value = ElogSeviceUtils . checkValSql ( value . toString ( ) ) ;
StringBuilder stringBuffer = new StringBuilder ( ) ;
2023-12-26 16:12:44 +08:00
// if (isLikeSearch(showColumns, key)) {
// String logSearchSql = I18nUtil.getLogSearchSql(ElogSeviceUtils.getTableName(module, function), key, value);
// String sql = logSearchSql.replaceAll("%_", "%\\\\_");
// try {
// List<Map> maps = queryCommonTabeMapper.queryLabelIds(sql);
// if (maps != null && maps.size() > 0) {
// for (Map map1 : maps) {
// Object indexid = map1.get(key);
// if (indexid == null || StringUtils.isEmpty(indexid.toString())) {
// indexid = map1.get(key.toLowerCase());
// }
// if (indexid != null && StringUtils.isNotEmpty(indexid.toString())) {
// String val = indexid.toString().replace("'", "''");
// if (ElogSeviceUtils.checkIsNumber(map.get(key))) {
// val = "-" + val;
// value = "-" + value;
// }
// stringBuffer.append("'").append(val).append("',");
// }
// }
// }
// } catch (Exception e) {
// logger.error("i18查询sql报错: {}", e.getMessage(), e);
// }
//
// }
2023-12-25 09:36:23 +08:00
String str = " " ;
if ( stringBuffer . toString ( ) . length ( ) > 0 ) {
str = stringBuffer . substring ( 0 , stringBuffer . length ( ) - 1 ) ;
if ( value . startsWith ( " _ " ) ) {
value = value . replace ( " _ " , " \\ _ " ) ;
}
sb . append ( " and ( " ) . append ( key ) . append ( " like '% " ) . append ( value ) . append ( " %' " ) ;
//String inVals = str.toString().replaceAll("''", "'");
if ( str . startsWith ( " _ " ) ) {
str = str . replace ( " _ " , " \\ _ " ) ;
}
if ( " operatetypename " . equals ( key ) ) {
String s = ElogSeviceUtils . checkValSql ( next . getValue ( ) . toString ( ) ) ;
sb . append ( matchOperatetype ( s ) ) ;
}
sb . append ( " or " ) . append ( key ) . append ( " in ( " ) . append ( str ) . append ( " )) " ) ;
} else {
if ( " operatetypename " . equals ( key ) ) {
sb . append ( " and ( " ) . append ( key ) . append ( " like '% " ) . append ( value ) . append ( " %' " ) ;
String s = ElogSeviceUtils . checkValSql ( next . getValue ( ) . toString ( ) ) ;
sb . append ( matchOperatetype ( s ) ) . append ( " ) " ) ;
} else {
if ( value . startsWith ( " _ " ) ) {
value = value . replace ( " _ " , " \\ _ " ) ;
}
sb . append ( " and " ) . append ( key ) . append ( " like '% " ) . append ( value ) . append ( " %' " ) ;
}
}
}
}
}
return sb . toString ( ) ;
}
2023-12-26 16:12:44 +08:00
// /**
// * 是否模糊搜索
// *
// * @param showColumns
// * @param key
// * @return
// */
// private boolean isLikeSearch(List<ShowColumsDto> showColumns, String key) {
// for (ShowColumsDto showColumn : showColumns) {
// if (key.equalsIgnoreCase(showColumn.getColumIndex()) && showColumn.isTransfLanguage()) {
// return true;
// }
// }
// return false;
// }
2023-12-25 09:36:23 +08:00
2023-12-26 16:12:44 +08:00
// private String getSwithDatabaseDate(String date) {
// if (ElogConsts.ORACLE.equals(DatabaseUtil.getDatabaseId())) {
// return " to_date('" + date + "','yyyy-mm-dd hh24:mi:ss') ";
// } else if (ElogConsts.POSTGRESQL.equals(DatabaseUtil.getDatabaseId())) {
// return " to_timestamp('" + date + "', 'YYYY-MM-DD HH24:MI:SS') ";
// } else if (ElogConsts.SQLSERVER.equals(DatabaseUtil.getDatabaseId())) {
// return " convert(nvarchar(19),'" + date + "',120) ";
// } else {
// return " DATE_FORMAT('" + date + "','%Y-%m-%d %H:%i:%s') ";
// }
// }
2023-12-25 09:36:23 +08:00
public String matchOperatetype ( String str ) {
2023-12-26 16:12:44 +08:00
// if (ElogSeviceUtils.currentLanguage() != 8) {
// return "";
// }
2023-12-25 09:36:23 +08:00
List < String > list = new ArrayList ( ) ;
list . add ( OperateType . add ) ;
list . add ( OperateType . update ) ;
list . add ( OperateType . view ) ;
list . add ( OperateType . delete ) ;
StringBuffer sb = new StringBuffer ( ) ;
for ( String o : list ) {
if ( o . toLowerCase ( ) . contains ( str . toLowerCase ( ) ) ) {
sb . append ( " ' " ) . append ( o ) . append ( " ', " ) ;
}
}
if ( " new " . toLowerCase ( ) . contains ( str . toLowerCase ( ) ) ) {
sb . append ( " 'add', " ) ;
}
String sql = " " ;
if ( sb . length ( ) > 0 ) {
sql = sb . toString ( ) . substring ( 0 , sb . length ( ) - 1 ) ;
sql = " or operatetype in ( " + sql + " ) " ;
}
return sql ;
}
public static boolean isEnglish ( String charaString ) {
return charaString . matches ( " ^[a-zA-Z]* " ) ;
}
/ * *
* 获取搜索条件
*
* @param filterConditionDtos
* @return
* /
private String getQueryCondition ( List < FilterConditionDto > filterConditionDtos ) {
StringBuffer sb = new StringBuffer ( ) ;
if ( filterConditionDtos ! = null & & filterConditionDtos . size ( ) > 0 ) {
for ( FilterConditionDto filterConditionDto : filterConditionDtos ) {
if ( StringUtils . isNotBlank ( filterConditionDto . getColumIndex ( ) ) ) {
sb . append ( getsql ( filterConditionDto ) ) ;
}
}
}
return sb . toString ( ) ;
}
/ * *
* 拼接sql
*
* @param filterConditionDto
* @return
* /
private String getsql ( FilterConditionDto filterConditionDto ) {
StringBuffer sb = new StringBuffer ( ) ;
filterConditionDto . setConnectCondition ( ElogSeviceUtils . checkConditionSql ( filterConditionDto . getConnectCondition ( ) ) ) ;
filterConditionDto . setType ( ElogSeviceUtils . checkTypeSql ( filterConditionDto . getType ( ) ) ) ;
filterConditionDto . setValue ( ElogSeviceUtils . checkValSql ( filterConditionDto . getValue ( ) ) ) ;
switchDatabaseFieldIndex ( filterConditionDto ) ;
if ( " LIKE " . equalsIgnoreCase ( filterConditionDto . getType ( ) ) ) {
if ( filterConditionDto . getLike ( ) ! = null ) {
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( " ' " ) .
append ( filterConditionDto . getLike ( ) . getPrefix ( ) ! = null ? filterConditionDto . getLike ( ) . getPrefix ( ) : " " ) .
append ( filterConditionDto . getValue ( ) ) .
append ( filterConditionDto . getLike ( ) . getSuffix ( ) ! = null ? filterConditionDto . getLike ( ) . getSuffix ( ) : " " ) .
append ( " ' " ) ;
}
} else if ( " IN " . equalsIgnoreCase ( filterConditionDto . getType ( ) ) ) {
String [ ] split = filterConditionDto . getValue ( ) . split ( " \" , \" " ) ;
if ( split . length > 0 ) {
StringBuffer str = new StringBuffer ( " ( " ) ;
String value = " " ;
if ( " targetid " . equals ( filterConditionDto . getColumIndex ( ) ) | | " log_operator " . equals ( filterConditionDto . getColumIndex ( ) ) ) {
List < String > list = JSONArray . parseArray ( filterConditionDto . getValue ( ) , String . class ) ;
for ( String s : list ) {
str . append ( s ) . append ( " , " ) ;
}
} else {
List < String > list = JSONArray . parseArray ( filterConditionDto . getValue ( ) , String . class ) ;
for ( String s : list ) {
str . append ( " ' " ) . append ( s ) . append ( " ', " ) ;
}
}
value = str . toString ( ) . substring ( 0 , str . length ( ) - 1 ) ;
value + = " ) " ;
switchDatabaseFieldIndex ( filterConditionDto ) ;
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( value ) .
append ( " " ) ;
} else if ( split . length = = 0 ) {
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( " (' " ) .
append ( filterConditionDto . getValue ( ) ) .
append ( " ') " ) ;
}
} else if ( " IS NULL " . equalsIgnoreCase ( filterConditionDto . getType ( ) ) | | " IS NOT NULL " . equalsIgnoreCase ( filterConditionDto . getType ( ) ) ) {
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( " " ) ;
} else if ( " BETWEEN " . equalsIgnoreCase ( filterConditionDto . getType ( ) ) ) {
String [ ] split = filterConditionDto . getValue ( ) . split ( " \" , \" " ) ;
StringBuffer stringBuffer = new StringBuffer ( ) ;
if ( split . length > 0 ) {
List < String > list = JSONArray . parseArray ( filterConditionDto . getValue ( ) , String . class ) ;
String str = " " ;
for ( String s : list ) {
stringBuffer . append ( " ' " ) . append ( s ) . append ( " ' AND " ) ;
}
str = stringBuffer . toString ( ) . substring ( 0 , stringBuffer . length ( ) - 3 ) ;
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( str ) .
append ( " " ) ;
} else if ( split . length = = 0 ) {
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( " ' " ) .
append ( filterConditionDto . getValue ( ) ) .
append ( " ' " ) ;
}
} else {
if ( " targetid " . equals ( filterConditionDto . getColumIndex ( ) ) | | " log_operator " . equals ( filterConditionDto . getColumIndex ( ) ) ) {
if ( StringUtils . isNotBlank ( filterConditionDto . getValue ( ) ) ) {
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getValue ( ) ) .
append ( " " ) ;
} else {
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( " " ) .
append ( - 1 ) .
append ( " " ) ;
}
} else {
sb . append ( " " ) .
append ( getConnectCondition ( filterConditionDto . getConnectCondition ( ) ) ) .
append ( " " ) .
append ( filterConditionDto . getColumIndex ( ) ) .
append ( " " ) .
append ( getQueryType ( filterConditionDto . getType ( ) ) ) .
append ( " ' " ) .
append ( filterConditionDto . getValue ( ) ) .
append ( " ' " ) ;
}
}
return sb . toString ( ) ;
}
private void switchDatabaseFieldIndex ( FilterConditionDto filterConditionDto ) {
if ( " operator " . equalsIgnoreCase ( filterConditionDto . getColumIndex ( ) ) ) {
filterConditionDto . setColumIndex ( " log_operator " ) ;
} else if ( " date " . equalsIgnoreCase ( filterConditionDto . getColumIndex ( ) ) ) {
filterConditionDto . setColumIndex ( " log_date " ) ;
} else if ( " result " . equalsIgnoreCase ( filterConditionDto . getColumIndex ( ) ) ) {
filterConditionDto . setColumIndex ( " log_result " ) ;
}
}
/ * *
* 获取查询类型
*
* @param type
* @return
* /
private String getQueryType ( String type ) {
//如果不填默认是=
if ( StringUtils . isBlank ( type ) ) {
return " = " ;
}
return type ;
}
/ * *
* 获取连接条件
*
* @param connectCondition
* @return
* /
private String getConnectCondition ( String connectCondition ) {
//如果不填默认是AND
if ( StringUtils . isBlank ( connectCondition ) ) {
return " AND " ;
}
return connectCondition ;
}
@Override
2023-12-26 17:49:50 +08:00
public List < Map < String , Object > > getDetailChanges ( GetDetailChangesParam param ) {
return getDetailChangesMethod ( param . getModule ( ) , param . getFunction ( ) , param . getMainid ( ) , param . getDetailTransMethod ( ) , null ) ;
2023-12-25 09:36:23 +08:00
}
/ * *
* 明细分页查询
2023-12-26 16:12:44 +08:00
*
2023-12-25 09:36:23 +08:00
* @param module
* @param function
* @param mainid
* @param detailTransMethod
* @param current
* @param pageSize
* @return
* /
@Override
public WeaTable getDetailChangePages ( String module , String function , String mainid , String detailTransMethod , String current , String pageSize ) {
Integer pageNum = Util . getIntValue ( current , 1 ) ;
Integer size = Util . getIntValue ( pageSize , 10 ) ;
2023-12-26 16:12:44 +08:00
Page page = new Page ( pageNum , size ) ;
2023-12-25 09:36:23 +08:00
List < Map < String , Object > > list = getDetailChangesMethod ( module , function , mainid , null , page ) ;
//查询分页总数
String tableName = ElogSeviceUtils . getTableName ( module , function , true ) ;
2023-12-26 16:12:44 +08:00
Integer total = getLocalElogDaoMapper ( ) . queryAllChangesPageCounts ( tableName , mainid ) ;
WeaTable weaTable = new WeaTable ( ) ;
2023-12-25 09:36:23 +08:00
weaTable . setColumns ( getDetailColumns ( list ) ) ;
2023-12-26 16:12:44 +08:00
PageInfo pageInfo = SalaryPageUtil . buildPage ( pageNum , size , list ) ;
pageInfo . setTotal ( total ) ;
2023-12-25 09:36:23 +08:00
return weaTable ;
}
private List < WeaTableColumn > getDetailColumns ( List < Map < String , Object > > list ) {
List < WeaTableColumn > columns = new ArrayList < > ( ) ;
2023-12-26 16:12:44 +08:00
if ( CollectionUtils . isNotEmpty ( list ) ) {
List < Map > detailcontexts = ( List < Map > ) list . get ( 0 ) . get ( " detailcontexts " ) ;
if ( CollectionUtils . isNotEmpty ( detailcontexts ) ) {
2023-12-25 09:36:23 +08:00
for ( Map map : detailcontexts ) {
WeaTableColumn weaTableColumn = new WeaTableColumn ( ) ;
// 列表属性名
2023-12-26 16:12:44 +08:00
weaTableColumn . setColumn ( ( String ) map . get ( " fieldname " ) ) ;
2023-12-25 09:36:23 +08:00
//显示名称 多语言转换 fieldnamelabelid
2023-12-26 16:12:44 +08:00
weaTableColumn . setText ( ( String ) map . get ( " fieldname " ) ) ;
2023-12-25 09:36:23 +08:00
columns . add ( weaTableColumn ) ;
}
}
}
return columns ;
}
2023-12-26 16:12:44 +08:00
public List < Map < String , Object > > getDetailChangesMethod ( String module , String function , String mainid , String detailTransMethod , Page page ) {
2023-12-25 09:36:23 +08:00
List list = new ArrayList < > ( ) ;
String tableName = ElogSeviceUtils . getTableName ( module , function , true ) ;
String maintableName = ElogSeviceUtils . getTableName ( module , function , false ) ;
2023-12-26 16:12:44 +08:00
List < Map > maps = getLocalElogDaoMapper ( ) . queryAllMainData ( maintableName , mainid ) ;
2023-12-25 09:36:23 +08:00
maps = ElogSeviceSwitchUtils . getSwitchDatabaseData ( maps ) ;
ElogSeviceSwitchUtils . changKey2Lower ( maps ) ;
List < Map > allChangesData = new ArrayList < > ( ) ;
//如果有分页数据则走分页方法
2023-12-26 16:12:44 +08:00
if ( Objects . nonNull ( page ) ) {
2023-12-25 09:36:23 +08:00
// Integer offset = (pageNum - 1) * size;
//分页查询明细数据
2023-12-26 16:12:44 +08:00
allChangesData = getLocalElogDaoMapper ( ) . queryAllChangesDataPages ( tableName , mainid , page ) ;
2023-12-25 09:36:23 +08:00
} else {
//没有被则不分页
2023-12-26 16:12:44 +08:00
allChangesData = getLocalElogDaoMapper ( ) . queryAllChangesData ( tableName , mainid ) ;
2023-12-25 09:36:23 +08:00
}
ElogSeviceSwitchUtils . changKey2Lower ( allChangesData ) ;
allChangesData = ElogSeviceSwitchUtils . getSwitchDatabaseData ( allChangesData ) ;
List < Map > mainlist = new ArrayList < > ( ) ;
List < Map > detaillist = new ArrayList < > ( ) ;
if ( allChangesData ! = null & & allChangesData . size ( ) > 0 ) {
for ( Map allChangesDatum : allChangesData ) {
Object o = allChangesDatum . get ( " isdetail " ) ;
if ( o ! = null ) {
if ( " 0 " . equals ( o . toString ( ) ) ) {
mainlist . add ( allChangesDatum ) ;
} else {
detaillist . add ( allChangesDatum ) ;
}
}
}
}
2023-12-26 16:12:44 +08:00
// List<Map> mainlist = getLocalElogDaoMapper().queryAllMainChanges(tableName, mainid);
// List<Map> detaillist = getLocalElogDaoMapper().queryAllDetailChanges(tableName, mainid);
2023-12-25 09:36:23 +08:00
//List<Map> moduleInfo = queryCommonTabeMapper.queryModuleNameInfo(module);
List < Map > moduleInfo = new ArrayList < > ( ) ;
processDetailInfo ( mainlist , detaillist , moduleInfo ) ;
Map < String , Object > map = ElogSeviceSwitchUtils . switchChangeValue ( mainlist , maps ) ;
Map < String , Object > detailMap = ElogSeviceSwitchUtils . switchDetailChangeValue ( detaillist ) ;
map . putAll ( detailMap ) ;
if ( maps ! = null & & maps . size ( ) > 0 ) {
Map maininfoMap = maps . get ( 0 ) ;
2023-12-26 16:12:44 +08:00
String operatetypename = ( String ) maininfoMap . get ( " operatetypename " ) ;
String targetname = ( String ) maininfoMap . get ( " targetname " ) ;
2023-12-25 09:36:23 +08:00
//长度大于1避免部分模块为1, 2, 3这类的操作类型
if ( StringUtils . isNumeric ( operatetypename ) & & operatetypename . length ( ) > 1 & & operatetypename . length ( ) < 10 ) {
String transfOperatetypename = ElogSeviceSwitchUtils . transfLanguageLableid ( Long . parseLong ( operatetypename ) , operatetypename ) ;
2023-12-26 16:12:44 +08:00
maininfoMap . put ( " operatetypename " , transfOperatetypename ) ;
2023-12-25 09:36:23 +08:00
}
if ( StringUtils . isNumeric ( targetname ) & & targetname . length ( ) > 1 & & targetname . length ( ) < 10 ) {
String transfTargetname = ElogSeviceSwitchUtils . transfLanguageLableid ( Long . parseLong ( targetname ) , targetname ) ;
2023-12-26 16:12:44 +08:00
maininfoMap . put ( " targetname " , transfTargetname ) ;
2023-12-25 09:36:23 +08:00
}
2023-12-26 16:12:44 +08:00
map . put ( " maininfo " , maininfoMap ) ;
2023-12-25 09:36:23 +08:00
map . put ( " detailtitle " , " " ) ;
}
list . add ( map ) ;
//List transfLanguageData = ElogSeviceSwitchUtils.transfLanguageData(list);
return list ;
}
/ * *
* 处理修改详情转多语言 ( 主表和明细表 )
*
* @param mainlist
* @param detaillist
* @param commonTableInfo
* @return
* /
private void processDetailInfo ( List < Map > mainlist , List < Map > detaillist , List < Map > commonTableInfo ) {
Map < String , Object > tablenameMap = new HashMap < > ( ) ;
Map < String , Object > fieldnameMap = new HashMap < > ( ) ;
Map < String , Object > valueMap = new HashMap < > ( ) ;
if ( commonTableInfo ! = null & & commonTableInfo . size ( ) > 0 ) {
for ( Map commonTableInfoMap : commonTableInfo ) {
JSONObject commonTableInfoMapJs = JSONObject . parseObject ( JSONObject . toJSONString ( commonTableInfoMap ) ) ;
String tablename = commonTableInfoMapJs . getString ( " table_name " ) ;
String tablename_labelid = commonTableInfoMapJs . getString ( " tablename_labelid " ) ;
String fieldname = commonTableInfoMapJs . getString ( " field_name " ) ;
String fieldname_labelid = commonTableInfoMapJs . getString ( " fieldname_labelid " ) ;
String values_kvpairs = commonTableInfoMapJs . getString ( " values_kvpairs " ) ;
fieldnameMap . put ( fieldname , fieldname_labelid ) ;
if ( StringUtils . isNotBlank ( fieldname ) & & StringUtils . isNotBlank ( values_kvpairs ) ) {
JSONObject jsonObject = JSONObject . parseObject ( values_kvpairs ) ;
valueMap . put ( fieldname , jsonObject ) ;
}
Object tablenameObj = tablenameMap . get ( tablename ) ;
if ( tablenameObj = = null ) {
tablenameMap . put ( tablename , tablename_labelid ) ;
}
}
}
if ( mainlist ! = null & & mainlist . size ( ) > 0 & & fieldnameMap . size ( ) > 0 & & valueMap . size ( ) > 0 ) {
for ( Map mainlistMap : mainlist ) {
JSONObject mainMapJs = JSONObject . parseObject ( JSONObject . toJSONString ( mainlistMap ) ) ;
String fielddesc = mainMapJs . getString ( " fielddesc " ) ;
String oldvalue = mainMapJs . getString ( " oldvalue " ) ;
String newvalue = mainMapJs . getString ( " newvalue " ) ;
if ( fieldnameMap . get ( fielddesc ) ! = null ) {
mainlistMap . put ( " fielddesc " , ElogSeviceSwitchUtils . transfLanguageLableid ( ElogSeviceUtils . getLongValue ( fieldnameMap . get ( fielddesc ) . toString ( ) ) , fieldnameMap . get ( fielddesc ) . toString ( ) ) ) ;
}
if ( valueMap . get ( fielddesc ) ! = null ) {
JSONObject jsonObject = JSONObject . parseObject ( valueMap . get ( fielddesc ) . toString ( ) ) ;
String oldvalueStr = jsonObject . getString ( oldvalue ) ;
String newvalueStr = jsonObject . getString ( newvalue ) ;
if ( StringUtils . isNotBlank ( oldvalueStr ) ) {
mainlistMap . put ( " oldvalue " , ElogSeviceSwitchUtils . transfLanguageLableid ( ElogSeviceUtils . getLongValue ( oldvalueStr ) , oldvalue ) ) ;
}
if ( StringUtils . isNotBlank ( newvalueStr ) ) {
mainlistMap . put ( " newvalue " , ElogSeviceSwitchUtils . transfLanguageLableid ( ElogSeviceUtils . getLongValue ( newvalueStr ) , newvalue ) ) ;
}
}
}
}
if ( detaillist ! = null & & detaillist . size ( ) > 0 & & fieldnameMap . size ( ) > 0 & & valueMap . size ( ) > 0 ) {
for ( Map detaillistMap : detaillist ) {
JSONObject mainMapJs = JSONObject . parseObject ( JSONObject . toJSONString ( detaillistMap ) ) ;
String tablename = mainMapJs . getString ( " tablename " ) ;
String fielddesc = mainMapJs . getString ( " fielddesc " ) ;
String oldvalue = mainMapJs . getString ( " oldvalue " ) ;
String newvalue = mainMapJs . getString ( " newvalue " ) ;
if ( tablenameMap . get ( tablename ) ! = null ) {
detaillistMap . put ( " tablename " , ElogSeviceSwitchUtils . transfLanguageLableid ( ElogSeviceUtils . getLongValue ( tablenameMap . get ( tablename ) . toString ( ) ) , tablenameMap . get ( tablename ) . toString ( ) ) ) ;
}
if ( fieldnameMap . get ( fielddesc ) ! = null ) {
detaillistMap . put ( " fielddesc " , ElogSeviceSwitchUtils . transfLanguageLableid ( ElogSeviceUtils . getLongValue ( fieldnameMap . get ( fielddesc ) . toString ( ) ) , fieldnameMap . get ( fielddesc ) . toString ( ) ) ) ;
}
if ( valueMap . get ( fielddesc ) ! = null ) {
JSONObject jsonObject = JSONObject . parseObject ( valueMap . get ( fielddesc ) . toString ( ) ) ;
String oldvalueStr = jsonObject . getString ( oldvalue ) ;
String newvalueStr = jsonObject . getString ( newvalue ) ;
if ( StringUtils . isNotBlank ( oldvalueStr ) ) {
detaillistMap . put ( " oldvalue " , ElogSeviceSwitchUtils . transfLanguageLableid ( ElogSeviceUtils . getLongValue ( oldvalueStr ) , oldvalue ) ) ;
}
if ( StringUtils . isNotBlank ( newvalueStr ) ) {
detaillistMap . put ( " newvalue " , ElogSeviceSwitchUtils . transfLanguageLableid ( ElogSeviceUtils . getLongValue ( newvalueStr ) , newvalue ) ) ;
}
}
}
}
}
@Override
2023-12-26 16:12:44 +08:00
public List queryLogList ( ELogGetLogParam param ) {
2023-12-25 09:36:23 +08:00
LoggerContext context = new LoggerContext ( ) ;
2023-12-26 16:12:44 +08:00
context . setModuleName ( param . getModule ( ) ) ;
context . setFunctionName ( param . getFunction ( ) ) ;
int pagenum = Util . getIntValue ( param . getCurrent ( ) , 1 ) - 1 ;
int size = Util . getIntValue ( param . getPageSize ( ) , 10 ) ;
2023-12-25 09:36:23 +08:00
int start = pagenum * size ;
int end = start + size ;
Page < Map > page = new Page ( pagenum , size ) ;
String limit = " limit " + start + " , " + ( end - start ) ;
2023-12-26 16:12:44 +08:00
String tableName = ElogSeviceUtils . getTableName ( param . getModule ( ) , param . getFunction ( ) ) ;
List < Map > list = getLocalElogDaoMapper ( ) . queryElogList ( page , context , null , tableName , null , " * " ) ;
2023-12-25 09:36:23 +08:00
list = ElogSeviceSwitchUtils . getSwitchDatabaseData ( list ) ;
return switchString ( list ) ;
}
@Override
public List queryCardLogList ( String data ) {
JSONObject map = JSONObject . parseObject ( data ) ;
String module = " " ;
String function = " " ;
String pageNum = " " ;
String pageSize = " " ;
String dataset = " " ;
String searchMap = " " ;
String sColum = " " ;
String fColum = " " ;
String transMethod = null ;
List < ShowColumsDto > showColums = new ArrayList < > ( ) ;
List < FilterConditionDto > filterConditionDtos = new ArrayList < > ( ) ;
String authParams = " " ;
Map jsonObject = new HashMap ( ) ;
if ( map ! = null ) {
module = map . getString ( " module " ) ;
function = map . getString ( " function " ) ;
pageNum = map . getString ( " pageNum " ) ;
pageSize = map . getString ( " pageSize " ) ;
//dataset = map.get("dataset").toString();
searchMap = map . getString ( " searchMap " ) ;
sColum = map . getString ( " showColums " ) ;
showColums = JSONArray . parseArray ( sColum , ShowColumsDto . class ) ;
fColum = map . getString ( " filterConditions " ) ;
transMethod = map . getString ( " transMethod " ) ;
filterConditionDtos = JSONArray . parseArray ( fColum , FilterConditionDto . class ) ;
authParams = map . getString ( " authParams " ) ;
jsonObject = JSONObject . parseObject ( authParams ) ;
}
LoggerContext context = new LoggerContext ( ) ;
context . setModuleName ( module ) ;
context . setFunctionName ( function ) ;
context . setTenant_key ( getTenantKey ( ) . toLowerCase ( ) ) ;
// 分页
//Page<Map> pages = ElogSeviceUtils.getPage();
String sb = getQueryCondition ( filterConditionDtos ) ;
logger . info ( " elog查询条件拼接sql: {} " , sb ) ;
// 消费到消息,通过MethodHandler调用对应的方法
String customSql = getCustomSql ( transMethod , sb , " before " ) ;
Page pages = new Page ( ElogSeviceUtils . getIntValue ( pageNum , 1 ) , ElogSeviceUtils . getIntValue ( pageSize , 10 ) ) ;
2023-12-26 16:12:44 +08:00
int page = Util . getIntValue ( pages . getPageNum ( ) + " " , 1 ) - 1 ;
int size = Util . getIntValue ( pages . getPageSize ( ) + " " , 10 ) ;
2023-12-25 09:36:23 +08:00
int start = page * size ;
int end = start + size ;
String limit = " limit " + start + " , " + ( end - start ) ;
String tableName = ElogSeviceUtils . getTableName ( module , function ) ;
//String columns = getshowColumsStr(showColums);
List < Map > list = new ArrayList < > ( ) ;
Map < String , Object > countMap = new HashMap < > ( ) ;
2023-12-26 16:12:44 +08:00
list = getLocalElogDaoMapper ( ) . queryElogList ( pages , context , null , tableName , customSql , " * " ) ;
countMap = getLocalElogDaoMapper ( ) . elogCount ( context , tableName , customSql ) ;
2023-12-25 09:36:23 +08:00
list = ElogSeviceSwitchUtils . getSwitchDatabaseData ( list ) ;
if ( list ! = null & & list . size ( ) > 0 ) {
//if ("1".equals(pageNum)){
list . get ( 0 ) . put ( " total " , ElogSeviceUtils . getLongValue ( countMap . get ( " counts " ) + " " , 0 ) ) ;
//}
}
transUserInfo ( list ) ;
//System.out.println("elog查询名称和头像耗时: {}"+ (l3-l2));
transfLanguageData ( list , showColums ) ;
List res = switchString ( list ) ;
return res ;
}
/ * *
* 转换数据成多语言 , 结合前端转
*
* @param lists
* @param showColums
* /
public static List transfLanguageData ( List < Map > lists , List < ShowColumsDto > showColums ) {
if ( lists ! = null & & lists . size ( ) > 0 ) {
for ( Map map : lists ) {
if ( map ! = null ) {
Iterator < Map . Entry < String , Object > > iterator = map . entrySet ( ) . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
Map . Entry < String , Object > entry = iterator . next ( ) ;
for ( ShowColumsDto showColum : showColums ) {
if ( StringUtils . isNotBlank ( showColum . getColumIndex ( ) ) & & showColum . isTransfLanguage ( ) & & entry . getKey ( ) . equals ( showColum . getColumIndex ( ) ) & & ! Objects . isNull ( entry . getValue ( ) ) & & StringUtils . isNumeric ( entry . getValue ( ) . toString ( ) ) ) {
if ( entry . getValue ( ) instanceof Integer | | entry . getValue ( ) instanceof Long | | entry . getValue ( ) instanceof String ) {
map . put ( entry . getKey ( ) , ElogSeviceSwitchUtils . transfLanguageLableid ( ElogSeviceUtils . getLongValue ( entry . getValue ( ) . toString ( ) ) , entry . getValue ( ) . toString ( ) ) ) ;
} else {
//map.put(entry.getKey(), ElogSeviceSwitchUtils.handlerBaseDataMethod(entry.getValue().toString()));
map . put ( entry . getKey ( ) , entry . getValue ( ) ) ;
}
} else if ( StringUtils . isNotBlank ( showColum . getColumIndex ( ) ) & & showColum . isTransfLanguage ( ) & & entry . getKey ( ) . equals ( showColum . getColumIndex ( ) ) & & ! Objects . isNull ( entry . getValue ( ) ) ) {
//read view add edit update delete
if ( " add " . equals ( entry . getValue ( ) . toString ( ) ) | | " 创建 " . equals ( entry . getValue ( ) . toString ( ) ) ) {
2023-12-26 16:12:44 +08:00
map . put ( entry . getKey ( ) , SalaryI18nUtil . getI18nLabel ( 1111111 , " 新增 " ) ) ;
2023-12-25 09:36:23 +08:00
} else if ( " read " . equals ( entry . getValue ( ) . toString ( ) ) | | " view " . equals ( entry . getValue ( ) . toString ( ) ) | | " 查看 " . equals ( entry . getValue ( ) . toString ( ) ) ) {
2023-12-26 16:12:44 +08:00
map . put ( entry . getKey ( ) , SalaryI18nUtil . getI18nLabel ( 1111111 , " 查看 " ) ) ;
2023-12-25 09:36:23 +08:00
} else if ( " edit " . equals ( entry . getValue ( ) . toString ( ) ) | | " update " . equals ( entry . getValue ( ) . toString ( ) ) | | " 更新 " . equals ( entry . getValue ( ) . toString ( ) ) ) {
2023-12-26 16:12:44 +08:00
map . put ( entry . getKey ( ) , SalaryI18nUtil . getI18nLabel ( 1111111 , " 修改 " ) ) ;
} else if ( " delete " . equals ( entry . getValue ( ) . toString ( ) ) | | " 删除 " . equals ( entry . getValue ( ) . toString ( ) ) ) {
map . put ( entry . getKey ( ) , SalaryI18nUtil . getI18nLabel ( 63254 , " 删除 " ) ) ;
2023-12-25 09:36:23 +08:00
} else if ( entry . getValue ( ) . toString ( ) . contains ( " 取消关联标签 " ) ) {
2023-12-26 16:12:44 +08:00
String val = entry . getValue ( ) . toString ( ) . replace ( " 取消关联标签 " , SalaryI18nUtil . getI18nLabel ( 1111111 , " 取消关联标签 " ) + " " ) ;
2023-12-25 09:36:23 +08:00
map . put ( entry . getKey ( ) , val ) ;
} else if ( entry . getValue ( ) . toString ( ) . contains ( " 关联标签 " ) ) {
2023-12-26 16:12:44 +08:00
String val = entry . getValue ( ) . toString ( ) . replace ( " 关联标签 " , SalaryI18nUtil . getI18nLabel ( 1111111 , " 关联标签 " ) + " " ) ;
2023-12-25 09:36:23 +08:00
map . put ( entry . getKey ( ) , val ) ;
}
}
}
}
}
}
}
return lists ;
}
@Override
public Map countLog ( String module , String function ) {
LoggerContext context = new LoggerContext ( ) ;
context . setModuleName ( module ) ;
context . setFunctionName ( function ) ;
context . setTenant_key ( getTenantKey ( ) ) ;
String tableName = ElogSeviceUtils . getTableName ( module , function ) ;
2023-12-26 16:12:44 +08:00
return getLocalElogDaoMapper ( ) . elogCount ( context , tableName , null ) ;
2023-12-25 09:36:23 +08:00
}
@Override
public List queryDetailLogList ( String module , String function , String current , String pageSize , String condition , String mainId ) {
LoggerContext context = new LoggerContext ( ) ;
context . setModuleName ( module ) ;
context . setFunctionName ( function ) ;
context . setTenant_key ( getTenantKey ( ) ) ;
context . setUuid ( mainId ) ;
int page = Util . getIntValue ( current , 1 ) - 1 ;
int size = Util . getIntValue ( pageSize , 10 ) ;
int start = page * size ;
int end = start + size ;
String limit = " limit " + start + " , " + ( end - start ) ;
// 还需要支持下查询
String tableName = ElogSeviceUtils . getTableName ( module , function , true ) ;
2023-12-26 16:12:44 +08:00
List < Map > list = getLocalElogDaoMapper ( ) . queryDetailElogList ( context , limit , tableName , null ) ;
2023-12-25 09:36:23 +08:00
list = ElogSeviceSwitchUtils . getSwitchDatabaseData ( list ) ;
return switchString ( list ) ;
}
@Override
public Map countDestailLog ( String module , String function , String mainId ) {
LoggerContext context = new LoggerContext ( ) ;
context . setModuleName ( module ) ;
context . setFunctionName ( function ) ;
context . setTenant_key ( getTenantKey ( ) ) ;
context . setUuid ( mainId ) ;
String tableName = ElogSeviceUtils . getTableName ( module , function , true ) ;
2023-12-26 16:12:44 +08:00
return getLocalElogDaoMapper ( ) . elogDetailCount ( context , tableName , null ) ;
2023-12-25 09:36:23 +08:00
}
@Override
public WeaTable queryElogTraceInfo ( String traceId , String module , String function , Integer currentPage , Integer pageSize , String traceTransMethod ) {
WeaTable weaTable = new WeaTable ( ) ;
if ( StringUtils . isNotEmpty ( traceId ) ) {
String tableName = ElogSeviceUtils . getTableName ( module , function ) ;
Integer offset = ( currentPage - 1 ) * pageSize ;
2023-12-26 16:12:44 +08:00
List < Map > list = getLocalElogDaoMapper ( ) . queryElogTraceInfo ( traceId , tableName , offset , pageSize ) ;
2023-12-25 09:36:23 +08:00
for ( Map map : list ) {
if ( map . get ( " modulename " ) ! = null ) {
map . put ( " modulenamespan " , ElogSeviceSwitchUtils . getModuleName ( map . get ( " modulename " ) . toString ( ) ) ) ;
}
}
//list = ElogSeviceSwitchUtils.getSwitchDatabaseData(list);
2023-12-26 16:12:44 +08:00
int count = getLocalElogDaoMapper ( ) . queryElogTraceInfoCount ( traceId , tableName ) ;
PageInfo pageInfo = SalaryPageUtil . buildPage ( currentPage , pageSize , list ) ;
// pageInfo.setColumns();
pageInfo . setTotal ( count ) ;
2023-12-25 09:36:23 +08:00
}
return weaTable ;
}
@Override
public List queryLogInfoByCustom ( String module , String function , String field , String value , boolean isDetail ) {
List list = new ArrayList ( ) ;
String tableName = ElogSeviceUtils . getTableName ( module , function , isDetail ) ;
if ( StringUtils . isNotBlank ( field ) & & StringUtils . isNotBlank ( value ) ) {
StringBuffer sql = new StringBuffer ( ) ;
sql . append ( field ) . append ( " = ' " ) . append ( value ) . append ( " ' " ) ;
2023-12-26 16:12:44 +08:00
list = getLocalElogDaoMapper ( ) . queryLogInfoByCustom ( tableName , sql . toString ( ) ) ;
2023-12-25 09:36:23 +08:00
}
return list ;
}
@Override
public List queryLogInfoByCustom ( String module , String function , String field , String value ) {
return queryLogInfoByCustom ( module , function , field , value , false ) ;
}
public List switchString ( List < Map > list ) {
if ( list ! = null ) {
return list . stream ( ) . map ( m - > {
Set < Map . Entry > en = m . entrySet ( ) ;
for ( Map . Entry entry : en ) {
if ( entry . getValue ( ) ! = null ) {
entry . setValue ( String . valueOf ( entry . getValue ( ) ) ) ;
}
}
return m ;
} ) . collect ( Collectors . toList ( ) ) ;
} else {
return list ;
}
}
2023-12-26 16:12:44 +08:00
// @Override
// public BatchDocumentMessage downloadLog(String data) {
// JSONObject jsonObject = JSONObject.parseObject(data);
// String module = jsonObject.getString("downloadmodule");
// String function = jsonObject.getString("function");
// String serviceName = jsonObject.getString("serviceName");
// String fileName = jsonObject.getString("fileName");
// String passWord = jsonObject.getString("passWord");
//
// if (StringUtils.isEmpty(fileName)) {
// fileName = SalaryI18nUtil.getI18nLabel(191432, "日志记录");
// }
//
// BatchDocumentMessage batchDocumentMessage = new BatchDocumentMessage();
// WeaTable weaTable = queryLogs(data);
// List<WeaTableColumn> columns = weaTable.getColumns();
// List<Map> headers = new ArrayList<>();
// if (columns != null && !columns.isEmpty()) {
// for (WeaTableColumn column : columns) {
// Map<String, String> header = new HashMap<>();
// header.put("key", column.getDataIndex());
// header.put("name", column.getTitle());
// headers.add(header);
// }
// }
// List<Map<String, Object>> dataList = weaTable.getData();
// List<Map<String, Object>> maps = new ArrayList<>();
// if (dataList != null && !dataList.isEmpty()) {
// dataList.stream().forEach(m -> {
// Map<String, Object> map = new HashMap<>();
// headers.stream().forEach(h -> {
// map.put(h.get("key").toString(), m.get(h.get("key")));
// });
// maps.add(map);
// });
// }
//
// //必传--业务id
// batchDocumentMessage.setBizId(IdGenerator.generate() + "");
// //必传-处理名称
// batchDocumentMessage.setHandlerName("ebatchdemo");
// //必传-服务名称
// batchDocumentMessage.setServiceName(serviceName);
// //必传-数据类型
// batchDocumentMessage.setDataType(fileName);
// //任务id
// batchDocumentMessage.setBatchTaskId(IdGenerator.generate());
// //必传-模块
// batchDocumentMessage.setModule(module); //com.weaver.teams.domain.EntityType 中的module( 没有的话需要找温明刚维护下)
// //必传-功能
// batchDocumentMessage.setFunction(function);
// //必传-eteamsid
// batchDocumentMessage.setEteamsId(TenantRpcContext.getEteamsId());
//
// //非必传
// if (StringUtils.isNotBlank(passWord)) {
// batchDocumentMessage.setPassword(passWord);
// }
//
// //必传
// BatchFile batchFile = new BatchFile();
// batchFile.setName(fileName);
// //必传
// batchFile.setFileType(FileType.EXCEL);
// //必传
// batchFile.setHandlerFileMethod(HandlerFileMethod.HANDLER_EXCEL_WITH_DATA);
// batchFile.setTemplateId(1l);
// List<ExcelSheet> excelSheets = new ArrayList<>();
// ExcelSheet excelSheet = new ExcelSheet();
//
// excelSheet.setHeader(headers);
// excelSheet.setData(maps);
// excelSheet.setName(fileName);
// excelSheets.add(excelSheet);
// batchFile.setExcelSheets(excelSheets);
// batchDocumentMessage.setBatchFile(batchFile);
// batchDocumentMessage.setChunk(false);//不分片
// batchExportSender.sendBatchExport(batchDocumentMessage);
//
// return batchDocumentMessage;
// }
//
2023-12-25 09:36:23 +08:00
private String [ ] getESfields ( String value ) {
String [ ] split = value . split ( " , " ) ;
List < String > list = new ArrayList < > ( ) ;
for ( String s : split ) {
switch ( s . toLowerCase ( ) ) {
case " interfacename " :
list . add ( " interfacename " ) ;
break ;
case " operatetype " :
list . add ( " operatetype " ) ;
break ;
case " operatedesc " :
list . add ( " operatedesc " ) ;
break ;
case " params " :
list . add ( " params " ) ;
break ;
case " clientip " :
list . add ( " clientip " ) ;
break ;
case " groupnamelabel " :
list . add ( " groupnamelabel " ) ;
break ;
case " redoservice " :
list . add ( " redoservice " ) ;
break ;
case " redocontext " :
list . add ( " redocontext " ) ;
break ;
case " cancelservice " :
list . add ( " cancelservice " ) ;
break ;
case " cancelcontext " :
list . add ( " cancelcontext " ) ;
break ;
case " device " :
list . add ( " device " ) ;
break ;
case " groupid " :
list . add ( " groupid " ) ;
break ;
case " belongmainid " :
list . add ( " belongmainid " ) ;
break ;
case " requesturl " :
list . add ( " requesturl " ) ;
break ;
case " requesturi " :
list . add ( " requesturi " ) ;
break ;
case " log_result " :
list . add ( " logResult " ) ;
break ;
case " fromterminal " :
list . add ( " fromterminal " ) ;
break ;
case " resultdesc " :
list . add ( " resultdesc " ) ;
break ;
case " old_content " :
list . add ( " oldContent " ) ;
break ;
case " link_type " :
list . add ( " linkType " ) ;
break ;
}
}
//list转为数组
if ( list . size ( ) > 0 ) {
String [ ] strings = list . toArray ( new String [ list . size ( ) ] ) ;
return strings ;
}
return null ;
}
}