1.审计管理
2.谐波检测bug修改
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.njcn.system.excel;
|
||||
|
||||
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;
|
||||
|
||||
// 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去
|
||||
public class DemoDataListener implements ReadListener<UserLogExcel> {
|
||||
|
||||
|
||||
/**
|
||||
* 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
|
||||
*/
|
||||
private static final int BATCH_COUNT = 5000;
|
||||
/**
|
||||
* 缓存的数据
|
||||
*/
|
||||
private List<UserLogExcel> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||
/**
|
||||
* 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。
|
||||
*/
|
||||
private UserLogMapper userLogMapper;
|
||||
|
||||
/**
|
||||
* 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
|
||||
*
|
||||
* @param userLogMapper
|
||||
*/
|
||||
public DemoDataListener(UserLogMapper userLogMapper) {
|
||||
this.userLogMapper = userLogMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 这个每一条数据解析都会来调用
|
||||
*
|
||||
* @param data one row value. Is is same as {@link AnalysisContext#readRowHolder()}
|
||||
* @param context
|
||||
*/
|
||||
@Override
|
||||
public void invoke(UserLogExcel data, AnalysisContext context) {
|
||||
cachedDataList.add(data);
|
||||
// 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
|
||||
if (cachedDataList.size() >= BATCH_COUNT) {
|
||||
saveData();
|
||||
// 存储完成清理 list
|
||||
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有数据解析完成了 都会来调用
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
// 这里也要保存数据,确保最后遗留的数据也存储到数据库
|
||||
saveData();
|
||||
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加上存储数据库
|
||||
*/
|
||||
public void saveData() {
|
||||
userLogMapper.insertBatch(cachedDataList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.njcn.system.excel;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: chenchao
|
||||
* @date: 2022/07/18 11:04
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
public class UserLogExcel implements Serializable {
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "id主键")
|
||||
private String id;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "登录名")
|
||||
private String loginName;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "用户名")
|
||||
private String userName;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "操作ip")
|
||||
private String ip;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "操作内容")
|
||||
private String operate;
|
||||
|
||||
@ColumnWidth(15)
|
||||
@ExcelProperty(value = "操作类型")
|
||||
private String operateType;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "操作结果")
|
||||
private Integer result;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "失败原因")
|
||||
private String failReason;
|
||||
|
||||
@ColumnWidth(30)
|
||||
@ExcelProperty(value = "时间等级(严重度)")
|
||||
private Integer level;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "事件类型")
|
||||
private Integer type;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "模块名称")
|
||||
private String serviceName="暂态";
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "告警标志")
|
||||
private Integer state;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "创建用户")
|
||||
private String createBy;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "创建时间" )
|
||||
private String createTime;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "更新用户")
|
||||
private String updateBy;
|
||||
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty(value = "更新时间" )
|
||||
private String updateTime;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user