1.解决审计统计没有显示的bug
2.解决数据中心数据查询过慢和数据展示bug
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.njcn.system.excel;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.read.listener.ReadListener;
|
||||
import com.alibaba.excel.util.ListUtils;
|
||||
import com.njcn.system.mapper.UserLogMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去
|
||||
public class DataListener implements ReadListener<UserLogExcel> {
|
||||
@@ -14,7 +16,7 @@ public class DataListener implements ReadListener<UserLogExcel> {
|
||||
/**
|
||||
* 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
|
||||
*/
|
||||
private static final int BATCH_COUNT = 1000;
|
||||
private static final int BATCH_COUNT = 5000;
|
||||
/**
|
||||
* 缓存的数据
|
||||
*/
|
||||
@@ -23,14 +25,16 @@ public class DataListener implements ReadListener<UserLogExcel> {
|
||||
* 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。
|
||||
*/
|
||||
private UserLogMapper userLogMapper;
|
||||
private List<String> ids;
|
||||
|
||||
/**
|
||||
* 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
|
||||
*
|
||||
* @param userLogMapper
|
||||
*/
|
||||
public DataListener(UserLogMapper userLogMapper) {
|
||||
public DataListener(UserLogMapper userLogMapper,List<String> ids) {
|
||||
this.userLogMapper = userLogMapper;
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +70,11 @@ public class DataListener implements ReadListener<UserLogExcel> {
|
||||
* 加上存储数据库
|
||||
*/
|
||||
public void saveData() {
|
||||
userLogMapper.insertBatch(cachedDataList);
|
||||
//剔除数据库存在的数据
|
||||
List<UserLogExcel> newCachedDataList = cachedDataList.stream().filter(x -> !ids.contains(x.getId())).collect(Collectors.toList());
|
||||
System.err.println(newCachedDataList.size());
|
||||
if(CollUtil.isNotEmpty(newCachedDataList)){
|
||||
userLogMapper.insertBatch(newCachedDataList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,4 +45,10 @@ public interface AuditMapper {
|
||||
*/
|
||||
List<String> selectOperateType();
|
||||
|
||||
/**
|
||||
* 时间范围查询id集合
|
||||
* @return
|
||||
*/
|
||||
List<String> getListIDs(@Param("startTime") String startTime,
|
||||
@Param("endTime") String endTime);
|
||||
}
|
||||
|
||||
@@ -148,5 +148,18 @@
|
||||
</where>
|
||||
|
||||
</select>
|
||||
<select id="getListIDs" resultType="java.lang.String">
|
||||
SELECT
|
||||
id
|
||||
FROM sys_user_log
|
||||
<where>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
and create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -29,7 +29,6 @@ import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.enums.AuditLogEnum;
|
||||
import com.njcn.system.excel.DataListener;
|
||||
import com.njcn.system.excel.UserLogExcel;
|
||||
import com.njcn.system.mapper.AuditMapper;
|
||||
import com.njcn.system.mapper.UserLogMapper;
|
||||
@@ -267,8 +266,10 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
}
|
||||
}).sheet().doRead();
|
||||
// 执行批量插入
|
||||
saveLogsBatch(userLogs, 1500);
|
||||
if(CollUtil.isNotEmpty(userLogs)){
|
||||
// 执行批量插入
|
||||
saveLogsBatch(userLogs, 1500);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
redisUtil.delete("recoverLogFile");
|
||||
e.printStackTrace();
|
||||
@@ -317,6 +318,8 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
||||
|
||||
@Override
|
||||
public Page<AuditLogCusVO> censusAuditLog(AuditParam auditParam) {
|
||||
auditParam.setSearchBeginTime(DateUtil.beginOfDay(DateUtil.parse(auditParam.getSearchBeginTime())).toString());
|
||||
auditParam.setSearchEndTime(DateUtil.endOfDay(DateUtil.parse(auditParam.getSearchBeginTime())).toString());
|
||||
//待分页数据总量
|
||||
Page<AuditLogCusVO> page = auditMapper.selectCensusAuditLog(new Page<>(auditParam.getPageNum(), auditParam.getPageSize()), auditParam);
|
||||
return page;
|
||||
|
||||
Reference in New Issue
Block a user