1.审计管理
2.谐波检测bug修改
This commit is contained in:
12
pom.xml
12
pom.xml
@@ -48,8 +48,14 @@
|
|||||||
<!--nacos的ip:port-->
|
<!--nacos的ip:port-->
|
||||||
<nacos.url>${middle.server.url}:18848</nacos.url>
|
<nacos.url>${middle.server.url}:18848</nacos.url>
|
||||||
<!--服务器发布内容为空-->
|
<!--服务器发布内容为空-->
|
||||||
<!-- <nacos.namespace></nacos.namespace>-->
|
<nacos.namespace></nacos.namespace>
|
||||||
<nacos.namespace>fd74182b-1fce-4dba-afa7-2623b0376205</nacos.namespace>
|
<!-- <nacos.namespace>fd74182b-1fce-4dba-afa7-2623b0376205</nacos.namespace>-->
|
||||||
|
<!-- 13-->
|
||||||
|
<!-- <nacos.namespace>2974723d-4032-4d63-a0fa-80921894b9c3</nacos.namespace>-->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!--sentinel:port-->
|
<!--sentinel:port-->
|
||||||
<sentinel.url>${middle.server.url}:8080</sentinel.url>
|
<sentinel.url>${middle.server.url}:8080</sentinel.url>
|
||||||
<!--网关地址,主要用于配置swagger中认证token-->
|
<!--网关地址,主要用于配置swagger中认证token-->
|
||||||
@@ -97,7 +103,7 @@
|
|||||||
<commons-codec.version>1.15</commons-codec.version>
|
<commons-codec.version>1.15</commons-codec.version>
|
||||||
<sentinel.datasource.nacos.version>1.8.1</sentinel.datasource.nacos.version>
|
<sentinel.datasource.nacos.version>1.8.1</sentinel.datasource.nacos.version>
|
||||||
<jackson>2.12.4</jackson>
|
<jackson>2.12.4</jackson>
|
||||||
<easyexcel>2.2.6</easyexcel>
|
<easyexcel>3.0.5</easyexcel>
|
||||||
<influxdb-java.version>2.18</influxdb-java.version>
|
<influxdb-java.version>2.18</influxdb-java.version>
|
||||||
<echarts.version>3.0.0.6</echarts.version>
|
<echarts.version>3.0.0.6</echarts.version>
|
||||||
<gson.version>2.8.9</gson.version>
|
<gson.version>2.8.9</gson.version>
|
||||||
|
|||||||
@@ -143,11 +143,19 @@ public class HistoryResultServiceImpl implements HistoryResultService {
|
|||||||
Date d = formatter.parse(objectList.get(0).toString());
|
Date d = formatter.parse(objectList.get(0).toString());
|
||||||
time.add(d);
|
time.add(d);
|
||||||
fValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
|
fValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
|
||||||
|
if (Integer.parseInt(contion) == 14) {
|
||||||
|
bValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(2).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
|
||||||
|
cValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(3).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < time.size(); i++) {
|
for (int i = 0; i < time.size(); i++) {
|
||||||
List<Object> objects = new ArrayList<>();
|
List<Object> objects = new ArrayList<>();
|
||||||
objects.add(time.get(i));
|
objects.add(time.get(i));
|
||||||
objects.add(fValue.get(i));
|
objects.add(fValue.get(i));
|
||||||
|
if (Integer.parseInt(contion) == 14) {
|
||||||
|
objects.add(bValue.get(i));
|
||||||
|
objects.add(cValue.get(i));
|
||||||
|
}
|
||||||
objectListData.add(objects);
|
objectListData.add(objects);
|
||||||
}
|
}
|
||||||
historyDataResultVO.setTopLimit(queryResultLimitVO.getTopLimit());
|
historyDataResultVO.setTopLimit(queryResultLimitVO.getTopLimit());
|
||||||
@@ -291,7 +299,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
|
|||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
//电压不平衡
|
//电压不平衡
|
||||||
sql = "SELECT time as time, v_zero as aValue FROM data_v WHERE " + stringBuilder.toString() +
|
sql = "SELECT time as time, v_zero as aValue, v_pos as bValue, v_neg as cValue FROM data_v WHERE " + stringBuilder.toString() +
|
||||||
" and (phasic_type ='T') group by phasic_type order by time asc tz('Asia/Shanghai');";
|
" and (phasic_type ='T') group by phasic_type order by time asc tz('Asia/Shanghai');";
|
||||||
phasicType.add("零序电压");
|
phasicType.add("零序电压");
|
||||||
phasicType.add("正序电压");
|
phasicType.add("正序电压");
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.njcn.executor.handler;
|
||||||
|
|
||||||
|
import com.njcn.system.api.AuditFeignClient;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wr
|
||||||
|
* @description
|
||||||
|
* @date 2023/5/17 19:48
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AuditJob {
|
||||||
|
private final AuditFeignClient auditFeignClient;
|
||||||
|
|
||||||
|
@XxlJob("clearHistoryLogJob")
|
||||||
|
public void clearHistoryLogJob() {
|
||||||
|
try {
|
||||||
|
String time = LocalDateTime.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||||
|
log.info("执行日期deviceAbnormalStatisticsJob===============>"+time);
|
||||||
|
auditFeignClient.clearHistoryLog();
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.njcn.system.api;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.constant.ServerInfo;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.system.api.fallback.AuditFeignClientFallbackFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author denghuajun
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2022年01月05日 15:11
|
||||||
|
*/
|
||||||
|
@FeignClient(value = ServerInfo.SYSTEM, path = "/audit", fallbackFactory = AuditFeignClientFallbackFactory.class, contextId = "area")
|
||||||
|
public interface AuditFeignClient {
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/clearHistoryLog")
|
||||||
|
HttpResult clearHistoryLog();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.njcn.system.api.fallback;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.system.api.AuditFeignClient;
|
||||||
|
import com.njcn.system.utils.SystemEnumUtil;
|
||||||
|
import feign.hystrix.FallbackFactory;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author denghuajun
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2022年01月05日 15:08
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class AuditFeignClientFallbackFactory implements FallbackFactory<AuditFeignClient> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuditFeignClient create(Throwable cause) {
|
||||||
|
//判断抛出异常是否为解码器抛出的业务异常
|
||||||
|
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||||
|
if(cause.getCause() instanceof BusinessException){
|
||||||
|
BusinessException businessException = (BusinessException) cause.getCause();
|
||||||
|
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||||
|
}
|
||||||
|
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||||
|
return new AuditFeignClient() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpResult clearHistoryLog() {
|
||||||
|
log.error("{}异常,降级处理,异常为:{}","清空历史日志",cause.toString());
|
||||||
|
throw new BusinessException(finalExceptionEnum);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,9 @@ public enum AuditLogEnum {
|
|||||||
* 审计日志模块异常响应码
|
* 审计日志模块异常响应码
|
||||||
*/
|
*/
|
||||||
NOT_FIND_FILE("A0300", "文件未备份,请先备份文件"),
|
NOT_FIND_FILE("A0300", "文件未备份,请先备份文件"),
|
||||||
LOG_EXCEPTION("A0301", "导入旧日志文件异常")
|
LOG_EXCEPTION("A0301", "导入旧日志文件异常"),
|
||||||
|
LOG_EXCEPTIONTIME("A0302", "导入旧日志文件异常:缺少时间范围"),
|
||||||
|
DELETE_DATA("A0303", "导入旧日志文件异常:删除数据失败")
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,11 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>easyexcel</artifactId>
|
||||||
|
<version>${easyexcel}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class AuditController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/logFileWriter")
|
@PostMapping("/logFileWriter")
|
||||||
@ApiOperation("日志文件备份")
|
@ApiOperation("日志文件备份")
|
||||||
public HttpResult logFileWriter() {
|
public HttpResult logFileWriter(){
|
||||||
String methodDescribe = getMethodDescribe("logFileWriter");
|
String methodDescribe = getMethodDescribe("logFileWriter");
|
||||||
auditService.logFileWriter();
|
auditService.logFileWriter();
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,null,methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,null,methodDescribe);
|
||||||
@@ -94,6 +94,13 @@ public class AuditController extends BaseController {
|
|||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@PostMapping("/getMemoInfo")
|
||||||
|
@ApiOperation("获取表空间大小")
|
||||||
|
public HttpResult<Float> getMemoInfo() {
|
||||||
|
String methodDescribe = getMethodDescribe("getMemoInfo");
|
||||||
|
Float memoInfo = auditService.getMemoInfo();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, memoInfo, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.njcn.system.controller;
|
package com.njcn.system.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
import com.njcn.common.pojo.constant.OperateType;
|
import com.njcn.common.pojo.constant.OperateType;
|
||||||
@@ -11,6 +12,7 @@ import com.njcn.common.pojo.exception.BusinessException;
|
|||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.HttpResultUtil;
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
import com.njcn.common.utils.LogUtil;
|
import com.njcn.common.utils.LogUtil;
|
||||||
|
import com.njcn.system.enums.SystemResponseEnum;
|
||||||
import com.njcn.system.pojo.param.ConfigParam;
|
import com.njcn.system.pojo.param.ConfigParam;
|
||||||
import com.njcn.system.pojo.po.Config;
|
import com.njcn.system.pojo.po.Config;
|
||||||
import com.njcn.system.service.IConfigService;
|
import com.njcn.system.service.IConfigService;
|
||||||
@@ -122,6 +124,13 @@ public class ConfigController extends BaseController {
|
|||||||
public HttpResult<Config> removeSysConfigById(@RequestParam("id") String id) {
|
public HttpResult<Config> removeSysConfigById(@RequestParam("id") String id) {
|
||||||
String methodDescribe = getMethodDescribe("removeSysConfigById");
|
String methodDescribe = getMethodDescribe("removeSysConfigById");
|
||||||
LogUtil.njcnDebug(log, "{}", methodDescribe, id);
|
LogUtil.njcnDebug(log, "{}", methodDescribe, id);
|
||||||
|
int count = iConfigService.count(new LambdaQueryWrapper<Config>()
|
||||||
|
.eq(Config::getState, DataStateEnum.ENABLE.getCode())
|
||||||
|
.ne(Config::getId, id));
|
||||||
|
if(count==0){
|
||||||
|
//不可更改当前激活状态,必须保留一个激活系统
|
||||||
|
throw new BusinessException(SystemResponseEnum.ACTIVATED_STATE);
|
||||||
|
}
|
||||||
boolean res = iConfigService.removeById(id);
|
boolean res = iConfigService.removeById(id);
|
||||||
if (res) {
|
if (res) {
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.njcn.system.mapper;
|
package com.njcn.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.njcn.system.pojo.dto.excel.UserLogExcel;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.njcn.system.excel.UserLogExcel;
|
||||||
import com.njcn.system.pojo.param.AuditParam;
|
import com.njcn.system.pojo.param.AuditParam;
|
||||||
import com.njcn.system.pojo.po.UserLog;
|
import com.njcn.system.pojo.po.UserLog;
|
||||||
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
||||||
@@ -25,6 +26,8 @@ public interface AuditMapper {
|
|||||||
* 查询需要备份的审计日志
|
* 查询需要备份的审计日志
|
||||||
*/
|
*/
|
||||||
List<UserLogExcel> queryExportUser(@Param("ew") QueryWrapper<UserLogExcel> queryWrapper);
|
List<UserLogExcel> queryExportUser(@Param("ew") QueryWrapper<UserLogExcel> queryWrapper);
|
||||||
|
|
||||||
|
Page<UserLogExcel> queryExportLimit(Page<UserLogExcel> page, @Param("startTime")String time,@Param("endTime")String endTime);
|
||||||
/**
|
/**
|
||||||
* 获取审计日志统计列表
|
* 获取审计日志统计列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package com.njcn.system.mapper;
|
package com.njcn.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.njcn.system.pojo.dto.AreaTreeDTO;
|
import com.njcn.system.excel.UserLogExcel;
|
||||||
import com.njcn.system.pojo.po.Area;
|
|
||||||
import com.njcn.system.pojo.po.UserLog;
|
import com.njcn.system.pojo.po.UserLog;
|
||||||
import com.njcn.system.pojo.vo.AreaTreeVO;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,5 +17,23 @@ import java.util.List;
|
|||||||
public interface UserLogMapper extends BaseMapper<UserLog> {
|
public interface UserLogMapper extends BaseMapper<UserLog> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志批量插入
|
||||||
|
* @param userLogs
|
||||||
|
*/
|
||||||
|
void insertBatch(@Param("list") List<UserLogExcel> userLogs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询数据库是否存在
|
||||||
|
* @param idList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> ids(@Param("ids")List<String> idList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询表空间大小
|
||||||
|
* @param schema
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Float getMemoInfo(@Param("schema") String schema);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,13 +91,13 @@
|
|||||||
AND operate != "unknown operate"
|
AND operate != "unknown operate"
|
||||||
AND update_time >= #{auditParam.searchBeginTime}
|
AND update_time >= #{auditParam.searchBeginTime}
|
||||||
AND #{auditParam.searchEndTime} >= update_time
|
AND #{auditParam.searchEndTime} >= update_time
|
||||||
<if test="auditParam.loginName!=null">
|
<if test="auditParam.loginName!=null and auditParam.loginName!=''">
|
||||||
and login_name = #{auditParam.loginName}
|
and login_name = #{auditParam.loginName}
|
||||||
</if>
|
</if>
|
||||||
<if test="auditParam.type!=null">
|
<if test="auditParam.type!=null and auditParam.type!=''">
|
||||||
and type = #{auditParam.type}
|
and type = #{auditParam.type}
|
||||||
</if>
|
</if>
|
||||||
<if test="auditParam.operateType!=null">
|
<if test="auditParam.operateType!=null and auditParam.operateType!=''">
|
||||||
and operate_type = #{auditParam.operateType}
|
and operate_type = #{auditParam.operateType}
|
||||||
</if>
|
</if>
|
||||||
GROUP BY login_name, operate_type
|
GROUP BY login_name, operate_type
|
||||||
@@ -118,5 +118,35 @@
|
|||||||
FROM sys_user_log
|
FROM sys_user_log
|
||||||
GROUP BY operate_type
|
GROUP BY operate_type
|
||||||
</select>
|
</select>
|
||||||
|
<select id="queryExportLimit" resultType="com.njcn.system.excel.UserLogExcel">
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
login_name loginName,
|
||||||
|
user_name userName,
|
||||||
|
ip,
|
||||||
|
operate,
|
||||||
|
operate_type operateType,
|
||||||
|
result,
|
||||||
|
fail_reason failReason,
|
||||||
|
level,
|
||||||
|
type,
|
||||||
|
service_name serviceName,
|
||||||
|
state,
|
||||||
|
create_by createBy,
|
||||||
|
create_time createTime,
|
||||||
|
update_by updateBy,
|
||||||
|
update_time updateTime
|
||||||
|
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>
|
</mapper>
|
||||||
@@ -2,4 +2,59 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.njcn.system.mapper.UserLogMapper">
|
<mapper namespace="com.njcn.system.mapper.UserLogMapper">
|
||||||
|
|
||||||
|
<insert id="insertBatch">
|
||||||
|
INSERT INTO sys_user_log (
|
||||||
|
id,
|
||||||
|
login_name,
|
||||||
|
user_name,
|
||||||
|
ip,
|
||||||
|
operate,
|
||||||
|
operate_type,
|
||||||
|
result,
|
||||||
|
fail_reason,
|
||||||
|
LEVEL,
|
||||||
|
type,
|
||||||
|
service_name,
|
||||||
|
state,
|
||||||
|
create_by,
|
||||||
|
create_time,
|
||||||
|
update_by,
|
||||||
|
update_time
|
||||||
|
)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="item" separator="," index="index">
|
||||||
|
( #{item.id},
|
||||||
|
#{item.loginName},
|
||||||
|
#{item.userName},
|
||||||
|
#{item.ip},
|
||||||
|
#{item.operate},
|
||||||
|
#{item.operateType},
|
||||||
|
#{item.result},
|
||||||
|
#{item.failReason},
|
||||||
|
#{item.level},
|
||||||
|
#{item.type},
|
||||||
|
#{item.serviceName},
|
||||||
|
#{item.state},
|
||||||
|
#{item.createBy},
|
||||||
|
#{item.createTime},
|
||||||
|
#{item.updateBy},
|
||||||
|
#{item.updateTime} )
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
</insert>
|
||||||
|
<select id="ids" resultType="java.lang.String">
|
||||||
|
select id from sys_user_log
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
<select id="getMemoInfo" resultType="java.lang.Float">
|
||||||
|
SELECT
|
||||||
|
TRUNCATE (data_length / 1024 / 1024, 2) AS '数据容量(MB)'
|
||||||
|
FROM
|
||||||
|
information_schema.tables
|
||||||
|
where table_schema = #{schema} and table_name="sys_user_log"
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -45,4 +45,10 @@ public interface AuditService extends IService<UserLog> {
|
|||||||
* 清空6个月前的历史日志
|
* 清空6个月前的历史日志
|
||||||
*/
|
*/
|
||||||
void clearHistoryLog();
|
void clearHistoryLog();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表空间大小
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Float getMemoInfo();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
package com.njcn.system.service.impl;
|
package com.njcn.system.service.impl;
|
||||||
|
|
||||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
||||||
import cn.afterturn.easypoi.excel.imports.ExcelImportService;
|
|
||||||
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
|
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.excel.EasyExcel;
|
||||||
|
import com.alibaba.excel.ExcelWriter;
|
||||||
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||||
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||||
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@@ -13,9 +19,10 @@ import com.google.common.collect.Lists;
|
|||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.system.enums.AuditLogEnum;
|
import com.njcn.system.enums.AuditLogEnum;
|
||||||
|
import com.njcn.system.excel.DemoDataListener;
|
||||||
|
import com.njcn.system.excel.UserLogExcel;
|
||||||
import com.njcn.system.mapper.AuditMapper;
|
import com.njcn.system.mapper.AuditMapper;
|
||||||
import com.njcn.system.mapper.UserLogMapper;
|
import com.njcn.system.mapper.UserLogMapper;
|
||||||
import com.njcn.system.pojo.dto.excel.UserLogExcel;
|
|
||||||
import com.njcn.system.pojo.param.AuditParam;
|
import com.njcn.system.pojo.param.AuditParam;
|
||||||
import com.njcn.system.pojo.po.UserLog;
|
import com.njcn.system.pojo.po.UserLog;
|
||||||
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
import com.njcn.system.pojo.vo.AuditLogCusVO;
|
||||||
@@ -23,20 +30,18 @@ import com.njcn.system.pojo.vo.AuditLogVO;
|
|||||||
import com.njcn.system.pojo.vo.LogParamVO;
|
import com.njcn.system.pojo.vo.LogParamVO;
|
||||||
import com.njcn.system.pojo.vo.ValuePO;
|
import com.njcn.system.pojo.vo.ValuePO;
|
||||||
import com.njcn.system.service.AuditService;
|
import com.njcn.system.service.AuditService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.commons.compress.utils.IOUtils;
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
import org.apache.commons.fileupload.FileItem;
|
import org.apache.commons.fileupload.FileItem;
|
||||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
@@ -50,40 +55,33 @@ import java.util.stream.Collectors;
|
|||||||
* @date: 2022/07/11 20:56
|
* @date: 2022/07/11 20:56
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements AuditService {
|
public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements AuditService {
|
||||||
|
|
||||||
private final AuditMapper auditMapper;
|
private final AuditMapper auditMapper;
|
||||||
|
|
||||||
private final UserLogMapper userLogMapper;
|
@Value("${spring.datasource.druid.url}")
|
||||||
|
private String urls;
|
||||||
private final GeneralInfo generalInfo;
|
private final GeneralInfo generalInfo;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<AuditLogVO> getAuditLog(AuditParam auditParam) {
|
public Page<AuditLogVO> getAuditLog(AuditParam auditParam) {
|
||||||
auditParam.setSearchBeginTime(auditParam.getSearchBeginTime() + StrUtil.SPACE + "00:00:00");
|
|
||||||
auditParam.setSearchEndTime(auditParam.getSearchEndTime() + StrUtil.SPACE + "23:59:59");
|
|
||||||
List<AuditLogVO> auditLogVOS = new ArrayList<>();
|
List<AuditLogVO> auditLogVOS = new ArrayList<>();
|
||||||
|
|
||||||
Page<AuditLogVO> page = new Page<>();
|
Page<UserLog> info = this.page(new Page<>(auditParam.getPageNum(), auditParam.getPageSize()), new LambdaQueryWrapper<UserLog>()
|
||||||
page.setSize(auditParam.getPageSize());
|
.eq(StrUtil.isNotBlank(auditParam.getLoginName()), UserLog::getLoginName, auditParam.getLoginName())
|
||||||
page.setCurrent(auditParam.getPageNum());
|
.eq(auditParam.getType() != null, UserLog::getLoginName, auditParam.getType())
|
||||||
|
.eq(StrUtil.isNotBlank(auditParam.getOperateType()), UserLog::getLoginName, auditParam.getLoginName())
|
||||||
//待分页数据总量
|
.ge(StrUtil.isNotBlank(auditParam.getSearchBeginTime()), UserLog::getCreateTime, DateUtil.beginOfDay(DateUtil.parse(auditParam.getSearchBeginTime())))
|
||||||
int count = auditMapper.getCount(auditParam);
|
.le(StrUtil.isNotBlank(auditParam.getSearchEndTime()), UserLog::getCreateTime, DateUtil.endOfDay(DateUtil.parse(auditParam.getSearchEndTime())))
|
||||||
page.setTotal(count);
|
);
|
||||||
//分页总页数
|
Page<AuditLogVO> page = BeanUtil.copyProperties(info, Page.class);
|
||||||
int pages = (int)Math.ceil(count*1.0/auditParam.getPageSize());
|
if (CollUtil.isNotEmpty(info.getRecords())) {
|
||||||
page.setPages(pages);
|
for (UserLog userLog : info.getRecords()) {
|
||||||
|
|
||||||
auditParam.setPageNum(auditParam.getPageSize()*(auditParam.getPageNum()-1));
|
|
||||||
List<UserLog> userLogs = auditMapper.selectAuditLog(auditParam);
|
|
||||||
if (!CollectionUtils.isEmpty(userLogs)) {
|
|
||||||
for (UserLog userLog: userLogs) {
|
|
||||||
AuditLogVO auditLogVO = new AuditLogVO();
|
AuditLogVO auditLogVO = new AuditLogVO();
|
||||||
String updateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(userLog.getUpdateTime());
|
String updateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(userLog.getUpdateTime());
|
||||||
auditLogVO.setTime(updateTime);
|
auditLogVO.setTime(updateTime);
|
||||||
if (userLog.getUserName()==null || userLog.getUserName().equals("")) {
|
if (userLog.getUserName() == null || userLog.getUserName().equals("")) {
|
||||||
auditLogVO.setUserName(userLog.getLoginName());
|
auditLogVO.setUserName(userLog.getLoginName());
|
||||||
} else {
|
} else {
|
||||||
auditLogVO.setUserName(userLog.getUserName());
|
auditLogVO.setUserName(userLog.getUserName());
|
||||||
@@ -91,21 +89,23 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
auditLogVO.setOperate(userLog.getOperate());
|
auditLogVO.setOperate(userLog.getOperate());
|
||||||
StringBuilder describe = new StringBuilder();
|
StringBuilder describe = new StringBuilder();
|
||||||
describe.append(auditLogVO.getUserName()).append("在").append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(userLog.getUpdateTime())).append("在").append(userLog.getIp()).append("执行了").append(userLog.getOperate()).append(",结果为");
|
describe.append(auditLogVO.getUserName()).append("在").append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(userLog.getUpdateTime())).append("在").append(userLog.getIp()).append("执行了").append(userLog.getOperate()).append(",结果为");
|
||||||
if (userLog.getResult()==1) {
|
if (userLog.getResult() == 1) {
|
||||||
describe.append("成功");
|
describe.append("成功");
|
||||||
}
|
}
|
||||||
if (userLog.getResult()==0) {
|
if (userLog.getResult() == 0) {
|
||||||
describe.append("失败").append(",失败原因为").append(userLog.getFailReason());
|
describe.append("失败").append(",失败原因为").append(userLog.getFailReason());
|
||||||
}
|
}
|
||||||
auditLogVO.setDescribe(describe.toString());
|
auditLogVO.setDescribe(describe.toString());
|
||||||
auditLogVO.setType(userLog.getType() == 0 ? "业务事件" : "系统事件");
|
auditLogVO.setType(userLog.getType() == 0 ? "业务事件" : "系统事件");
|
||||||
auditLogVO.setResult(userLog.getResult() == 0 ? "失败" : "成功");
|
auditLogVO.setResult(userLog.getResult() == 0 ? "失败" : "成功");
|
||||||
auditLogVO.setIp(userLog.getIp());
|
auditLogVO.setIp(userLog.getIp());
|
||||||
if (userLog.getLevel()==0) {
|
if (userLog.getLevel() == 0) {
|
||||||
auditLogVO.setLevel("普通");
|
auditLogVO.setLevel("普通");
|
||||||
}if (userLog.getLevel()==1) {
|
}
|
||||||
|
if (userLog.getLevel() == 1) {
|
||||||
auditLogVO.setLevel("中等");
|
auditLogVO.setLevel("中等");
|
||||||
}if (userLog.getLevel()==2) {
|
}
|
||||||
|
if (userLog.getLevel() == 2) {
|
||||||
auditLogVO.setLevel("严重");
|
auditLogVO.setLevel("严重");
|
||||||
}
|
}
|
||||||
auditLogVOS.add(auditLogVO);
|
auditLogVOS.add(auditLogVO);
|
||||||
@@ -118,37 +118,61 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logFileWriter() {
|
public void logFileWriter() {
|
||||||
LocalDate nowDate = LocalDate.now();
|
LocalDateTime nowDate = LocalDateTime.now();
|
||||||
LocalDate agoDate = nowDate.minusMonths(6).with(TemporalAdjusters.firstDayOfMonth());
|
LocalDateTime agoDate = nowDate.minusMonths(6).with(TemporalAdjusters.firstDayOfMonth());
|
||||||
String date = agoDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
String date = agoDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||||
// String time = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(agoDate);
|
//结束时间
|
||||||
// queryWrapper.between("sys_user_log.update_time","2022-02-01","2022-07-31");
|
String endTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH_mm_ss").format(nowDate);
|
||||||
|
//文件名
|
||||||
|
QueryWrapper<UserLog> aa = new QueryWrapper<>();
|
||||||
|
aa.ge("sys_user_log.update_time", date);
|
||||||
|
aa.le("sys_user_log.update_time", endTime);
|
||||||
|
String nowTime = date + "至" + endTime;
|
||||||
|
//必须放到循环外,否则会刷新流
|
||||||
|
ExcelWriter excelWriter = EasyExcel.write(generalInfo.getBusinessTempPath() + "//" + nowTime + ExcelTypeEnum.CSV.getValue(), UserLogExcel.class)
|
||||||
|
.excelType(ExcelTypeEnum.CSV)
|
||||||
|
.build();
|
||||||
|
|
||||||
QueryWrapper<UserLogExcel> queryWrapper = new QueryWrapper<>();
|
try {
|
||||||
queryWrapper.ge("sys_user_log.update_time",date);
|
//记录总数:实际中需要根据查询条件进行统计即可:一共多少条
|
||||||
List<UserLogExcel> excelList = auditMapper.queryExportUser(queryWrapper);
|
int totalCount = this.count(aa);
|
||||||
|
//每一个Sheet存放100w条数据
|
||||||
|
Integer sheetDataRows = 1000000;
|
||||||
|
//每次写入的数据量20w,每页查询20W
|
||||||
|
Integer writeDataRows = 200000;
|
||||||
|
//计算需要的Sheet总数量
|
||||||
|
Integer sheetNum = totalCount % sheetDataRows == 0 ? (totalCount / sheetDataRows) : (totalCount / sheetDataRows + 1);
|
||||||
|
//计算一般情况下每一个Sheet需要写入的次数(一般情况不包含最后一个sheet,因为最后一个sheet不确定会写入多少条数据)
|
||||||
|
Integer oneSheetWriteCount = sheetDataRows / writeDataRows;
|
||||||
|
//计算最后一个sheet需要写入的次数
|
||||||
|
Integer lastSheetWriteCount = 0;
|
||||||
|
if (totalCount > sheetDataRows) {
|
||||||
|
lastSheetWriteCount = totalCount % sheetDataRows == 0 ? oneSheetWriteCount : (totalCount % sheetDataRows % writeDataRows == 0 ? (totalCount / sheetDataRows / writeDataRows) : (totalCount / sheetDataRows / writeDataRows + 1));
|
||||||
|
} else {
|
||||||
|
lastSheetWriteCount = totalCount % sheetDataRows == 0 ? oneSheetWriteCount : oneSheetWriteCount + 1;
|
||||||
|
}
|
||||||
|
|
||||||
LocalDateTime nowDateTime = LocalDateTime.now();
|
//开始分批查询分次写入
|
||||||
String nowTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss").format(nowDateTime);
|
for (int i = 0; i < sheetNum; i++) {
|
||||||
|
|
||||||
File filePath = new File(generalInfo.getBusinessTempPath());
|
//循环写入次数: j的自增条件是当不是最后一个Sheet的时候写入次数为正常的每个Sheet写入的次数,如果是最后一个就需要使用计算的次数lastSheetWriteCount
|
||||||
filePath.mkdirs();
|
for (int j = 0; j < (i != sheetNum - 1 ? oneSheetWriteCount : lastSheetWriteCount); j++) {
|
||||||
File file = new File(filePath.getPath() + File.separator + nowTime +" sys_user_log.xlsx");
|
//分页查询一次20w
|
||||||
// ExcelUtil.exportExcelWithTargetFile(file, UserLogExcel.class, excelList);
|
//查询分页列表---按照自己的业务查列表,分页这个一定要使用这个:page1.getPageNum(),page1.getPageSize()!!!
|
||||||
|
Page<UserLogExcel> userLogExcelPage = auditMapper.queryExportLimit(new Page<>(j + 1 + oneSheetWriteCount * i, writeDataRows), date, endTime);
|
||||||
|
List<UserLogExcel> list = userLogExcelPage.getRecords();
|
||||||
|
//写入到excel:
|
||||||
|
WriteSheet writeSheet = EasyExcel.writerSheet(i, "Sheet" + (i + 1)).head(UserLogExcel.class)
|
||||||
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
|
||||||
|
excelWriter.write(list, writeSheet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//备份为txt
|
} catch (Exception e) {
|
||||||
// QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
|
e.printStackTrace();
|
||||||
// queryWrapper.ge("sys_user_log.update_time",date);
|
} finally {
|
||||||
// List<UserLog> userLogs = userLogMapper.selectList(queryWrapper);
|
excelWriter.finish();
|
||||||
// try {
|
}
|
||||||
// File file = new File(SystemBaseConfig.getTempPath()+ File.separator + nowDate +" sys_user_log.txt");
|
|
||||||
// //将list写入文件并生成路径
|
|
||||||
// FileUtils.writeLines(file, userLogs, true);
|
|
||||||
// //读取文件大小
|
|
||||||
// long sizeOf = FileUtils.sizeOf(new File(file.getPath()));
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -173,48 +197,22 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
if (!newFile.exists()) {
|
if (!newFile.exists()) {
|
||||||
throw new BusinessException(AuditLogEnum.NOT_FIND_FILE);
|
throw new BusinessException(AuditLogEnum.NOT_FIND_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportParams params = new ImportParams();
|
|
||||||
params.setHeadRows(1);//表头
|
|
||||||
params.setTitleRows(0);//标题行数
|
|
||||||
params.setNeedVerify(false);
|
|
||||||
//第一个sheet为台账信息
|
|
||||||
params.setStartSheetIndex(0);
|
|
||||||
params.setSheetNum(1);
|
|
||||||
|
|
||||||
FileInputStream in = null;
|
FileInputStream in = null;
|
||||||
try {
|
try {
|
||||||
in = new FileInputStream(newFile);
|
in = new FileInputStream(newFile);
|
||||||
//将Excel文件转成对象集合
|
String name = newFile.getName();
|
||||||
List<UserLogExcel> excelList = new ExcelImportService().importExcelByIs(in, UserLogExcel.class, params, false).getList();
|
String[] split = name.split(ExcelTypeEnum.CSV.getValue());
|
||||||
if (excelList.get(0).getId().isEmpty()) {
|
|
||||||
throw new BusinessException(AuditLogEnum.LOG_EXCEPTION);
|
String[] splitTime = split[0].split("至");
|
||||||
}
|
if (StrUtil.isBlank(splitTime[0]) || StrUtil.isBlank(splitTime[1])) {
|
||||||
List<String> oldIds = excelList.stream().map(UserLogExcel::getId).collect(Collectors.toList());
|
throw new BusinessException(AuditLogEnum.LOG_EXCEPTIONTIME);
|
||||||
//查找该备份文件是否已存在
|
|
||||||
List<UserLog> logList = userLogMapper.selectBatchIds(oldIds);
|
|
||||||
if (CollectionUtils.isEmpty(logList)) {
|
|
||||||
List<UserLog> userLogs = new ArrayList<>();
|
|
||||||
for (UserLogExcel excel: excelList) {
|
|
||||||
UserLog userLog = new UserLog();
|
|
||||||
BeanUtil.copyProperties(excel,userLog);
|
|
||||||
userLogs.add(userLog);
|
|
||||||
}
|
|
||||||
this.saveBatch(userLogs);
|
|
||||||
} else {
|
|
||||||
List<String> isIds = logList.stream().map(UserLog::getId).collect(Collectors.toList());
|
|
||||||
List<UserLogExcel> needSaveUserLogData = excelList.stream().filter(userLogExcelTemp -> !isIds.contains(userLogExcelTemp.getId())).collect(Collectors.toList());
|
|
||||||
if (!CollectionUtils.isEmpty(needSaveUserLogData)) {
|
|
||||||
List<UserLog> userLogs = new ArrayList<>();
|
|
||||||
for (UserLogExcel needSave: needSaveUserLogData) {
|
|
||||||
UserLog userLog = new UserLog();
|
|
||||||
BeanUtil.copyProperties(needSave,userLog);
|
|
||||||
userLogs.add(userLog);
|
|
||||||
}
|
|
||||||
this.saveBatch(userLogs);
|
|
||||||
// this.saveOrUpdateBatch(userLogs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
LambdaQueryWrapper<UserLog> le = new LambdaQueryWrapper<UserLog>()
|
||||||
|
.ge(UserLog::getCreateTime, DateUtil.beginOfDay(DateUtil.parse(splitTime[0])))
|
||||||
|
.le(UserLog::getCreateTime, splitTime[1].replace("_", ":"));
|
||||||
|
this.remove(le);
|
||||||
|
EasyExcel.read(newFile, UserLogExcel.class, new DemoDataListener(this.getBaseMapper()))
|
||||||
|
.excelType(ExcelTypeEnum.CSV).doReadAll();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -222,19 +220,6 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(in);
|
IOUtils.closeQuietly(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
|
||||||
// // FileInputStream in = new FileInputStream(file);
|
|
||||||
// MultipartFile multipartFile = getMultipartFile(file);
|
|
||||||
//
|
|
||||||
// List<Object> list = ExcelImportUtil.importExcelMore(multipartFile.getInputStream(), UserLogExcel.class, params).getList();
|
|
||||||
//
|
|
||||||
// System.out.println(list);
|
|
||||||
//
|
|
||||||
// // this.saveOrUpdate(excelList.get(0));
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// throw new BusinessException(AuditLogEnum.LOG_EXCEPTION);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,7 +234,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
List<AuditLogCusVO> auditLogCusVOS = auditMapper.selectCensusAuditLog(auditParam);
|
List<AuditLogCusVO> auditLogCusVOS = auditMapper.selectCensusAuditLog(auditParam);
|
||||||
page.setTotal(auditLogCusVOS.size());
|
page.setTotal(auditLogCusVOS.size());
|
||||||
//分页总页数
|
//分页总页数
|
||||||
int pages = (int)Math.ceil(page.getTotal()*1.0/auditParam.getPageSize());
|
int pages = (int) Math.ceil(page.getTotal() * 1.0 / auditParam.getPageSize());
|
||||||
page.setPages(pages);
|
page.setPages(pages);
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(auditLogCusVOS)) {
|
if (!CollectionUtils.isEmpty(auditLogCusVOS)) {
|
||||||
@@ -268,10 +253,16 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
String date = agoDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
String date = agoDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||||
|
|
||||||
QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.lt("sys_user_log.update_time",date);
|
queryWrapper.lt("sys_user_log.create_time", date);
|
||||||
auditMapper.deleteByTime(queryWrapper);
|
auditMapper.deleteByTime(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Float getMemoInfo() {
|
||||||
|
String schema = urls.substring(urls.lastIndexOf("/")+1,urls.lastIndexOf("?"));
|
||||||
|
return this.baseMapper.getMemoInfo(schema);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LogParamVO saveLogParam() {
|
public LogParamVO saveLogParam() {
|
||||||
LogParamVO logParamVO = new LogParamVO();
|
LogParamVO logParamVO = new LogParamVO();
|
||||||
@@ -279,15 +270,15 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
List<String> operateType = auditMapper.selectOperateType();
|
List<String> operateType = auditMapper.selectOperateType();
|
||||||
List<ValuePO> loginNameList = new ArrayList<>();
|
List<ValuePO> loginNameList = new ArrayList<>();
|
||||||
List<ValuePO> operateTypeList = new ArrayList<>();
|
List<ValuePO> operateTypeList = new ArrayList<>();
|
||||||
for (int i = 0; i<loginName.size(); i++) {
|
for (int i = 0; i < loginName.size(); i++) {
|
||||||
ValuePO valuePO = new ValuePO();
|
ValuePO valuePO = new ValuePO();
|
||||||
valuePO.setName("选项"+(i+1));
|
valuePO.setName("选项" + (i + 1));
|
||||||
valuePO.setValue(loginName.get(i));
|
valuePO.setValue(loginName.get(i));
|
||||||
loginNameList.add(valuePO);
|
loginNameList.add(valuePO);
|
||||||
}
|
}
|
||||||
for (int i = 0; i<operateType.size(); i++) {
|
for (int i = 0; i < operateType.size(); i++) {
|
||||||
ValuePO valuePO = new ValuePO();
|
ValuePO valuePO = new ValuePO();
|
||||||
valuePO.setName("选项"+(i+1));
|
valuePO.setName("选项" + (i + 1));
|
||||||
valuePO.setValue(operateType.get(i));
|
valuePO.setValue(operateType.get(i));
|
||||||
operateTypeList.add(valuePO);
|
operateTypeList.add(valuePO);
|
||||||
}
|
}
|
||||||
@@ -296,28 +287,22 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|||||||
return logParamVO;
|
return logParamVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**返回一个最新修改日期的文件*/
|
/**
|
||||||
|
* 返回一个最新修改日期的文件
|
||||||
|
*/
|
||||||
public File getLastFile() {
|
public File getLastFile() {
|
||||||
File parentFile = new File(generalInfo.getBusinessTempPath());
|
File parentFile = new File(generalInfo.getBusinessTempPath());
|
||||||
Date date = FileUtil.lastModifiedTime(parentFile);
|
// Date date = FileUtil.lastModifiedTime(parentFile);
|
||||||
System.out.println(">>>>>>>>>>当前文件夹最后修改时间>>>>>>>>>"+date);
|
// System.out.println(">>>>>>>>>>当前文件夹最后修改时间>>>>>>>>>" + date);
|
||||||
|
|
||||||
//文件夹下的所有子文件数组
|
//文件夹下的所有子文件数组
|
||||||
File[] files = parentFile.listFiles();
|
File[] files = parentFile.listFiles();
|
||||||
List<Date> list = Arrays.stream(files).map(tempFile -> FileUtil.lastModifiedTime(tempFile)).collect(Collectors.toList());
|
List<Date> list = Arrays.stream(files).map(tempFile -> FileUtil.lastModifiedTime(tempFile)).collect(Collectors.toList());
|
||||||
//Date集合排序
|
//Date集合排序
|
||||||
Collections.sort(list, new Comparator<Date>() {
|
Collections.sort(list, Comparator.reverseOrder());
|
||||||
@Override
|
|
||||||
public int compare(Date o1, Date o2) {
|
|
||||||
return o2.compareTo(o1);//倒序排序
|
|
||||||
// return o1.compareTo(o2);//正序排序
|
|
||||||
}
|
|
||||||
});
|
|
||||||
File newFile = Arrays.stream(files).filter(tempFile -> FileUtil.lastModifiedTime(tempFile).equals(list.get(0))).collect(Collectors.toList()).get(0);
|
File newFile = Arrays.stream(files).filter(tempFile -> FileUtil.lastModifiedTime(tempFile).equals(list.get(0))).collect(Collectors.toList()).get(0);
|
||||||
|
|
||||||
return newFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,9 @@ import org.springframework.beans.BeanUtils;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -85,8 +83,7 @@ public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> impleme
|
|||||||
@Override
|
@Override
|
||||||
public List<Config> getList() {
|
public List<Config> getList() {
|
||||||
List<Config> list = this.baseMapper.getList();
|
List<Config> list = this.baseMapper.getList();
|
||||||
List<Config> filterList = list.stream().filter(t -> t.getLogTime() > 0 && t.getLogSize().compareTo(new BigDecimal(0))==1).collect(Collectors.toList());
|
return list;
|
||||||
return filterList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user