From 2a619ec2358a3a06bb76697ba982f20914a52026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=B6=85?= <973677575@qq.com> Date: Tue, 19 Jul 2022 20:09:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E8=AE=A1=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../njcn/system/pojo/param/AuditParam.java | 10 ++-- .../njcn/system/pojo/vo/AuditLogCusVO.java | 4 +- .../com/njcn/system/pojo/vo/AuditLogVO.java | 2 +- .../com/njcn/system/pojo/vo/LogParamVO.java | 28 ++++++++++ .../system/controller/AuditController.java | 29 +++++++--- .../com/njcn/system/mapper/AuditMapper.java | 14 ++++- .../system/mapper/mapping/AuditMapper.xml | 55 +++++++++++++++++-- .../com/njcn/system/service/AuditService.java | 5 ++ .../system/service/impl/AuditServiceImpl.java | 33 +++++++---- 9 files changed, 146 insertions(+), 34 deletions(-) create mode 100644 pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/LogParamVO.java diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/param/AuditParam.java b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/param/AuditParam.java index d411446c8..f3f13ab3b 100644 --- a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/param/AuditParam.java +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/param/AuditParam.java @@ -24,14 +24,14 @@ public class AuditParam { @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误") private String searchEndTime; - @ApiModelProperty("用户名") - private String userName; + @ApiModelProperty("登录名") + private String loginName; - @ApiModelProperty("事件类型") - private String type; + @ApiModelProperty("事件类型(0.业务事件 1.系统事件)") + private Integer type; @ApiModelProperty("操作类型") - private String operate; + private String operateType; @ApiModelProperty("页码") @NotNull(message = "页码不可为空") diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogCusVO.java b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogCusVO.java index 640f0d2d9..64f74d4a5 100644 --- a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogCusVO.java +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogCusVO.java @@ -17,13 +17,13 @@ public class AuditLogCusVO implements Serializable { * 操作人员 */ @ApiModelProperty("操作人员") - private String userName; + private String LoginName; /** * 操作类型 */ @ApiModelProperty("操作类型") - private String operate; + private String operateType; /** * 事件总数 diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogVO.java b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogVO.java index 508c47e9e..669c08e82 100644 --- a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogVO.java +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogVO.java @@ -35,7 +35,7 @@ public class AuditLogVO { * 事件类型 */ @ApiModelProperty("事件类型") - private String operateType; + private String type; /** * 操作结果 */ diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/LogParamVO.java b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/LogParamVO.java new file mode 100644 index 000000000..5382979e3 --- /dev/null +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/LogParamVO.java @@ -0,0 +1,28 @@ +package com.njcn.system.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/07/19 19:06 + */ +@Data +public class LogParamVO { + + /** + * 登录名 + */ + @ApiModelProperty("登录名") + private List loginName; + + /** + * 操作类型 + */ + @ApiModelProperty("操作类型") + private List operateType; + +} diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/controller/AuditController.java b/pqs-system/system-boot/src/main/java/com/njcn/system/controller/AuditController.java index 7670d435c..ff9349470 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/controller/AuditController.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/controller/AuditController.java @@ -7,7 +7,9 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; import com.njcn.system.pojo.param.AuditParam; +import com.njcn.system.pojo.vo.AuditLogCusVO; import com.njcn.system.pojo.vo.AuditLogVO; +import com.njcn.system.pojo.vo.LogParamVO; import com.njcn.system.service.AuditService; import com.njcn.web.controller.BaseController; import io.swagger.annotations.Api; @@ -64,15 +66,24 @@ public class AuditController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,res,methodDescribe); } - // @OperateInfo(info = LogEnum.BUSINESS_COMMON) - // @PostMapping("/censusAuditLog") - // @ApiOperation("审计日志统计") - // @ApiImplicitParam(name = "auditParam", value = "审计日志参数", required = true) - // public HttpResult> censusAuditLog(@RequestBody @Validated AuditParam auditParam){ - // String methodDescribe = getMethodDescribe("censusAuditLog"); - // Page result = auditService.censusAuditLog(auditParam); - // return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,result,methodDescribe); - // } + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/censusAuditLog") + @ApiOperation("审计日志统计") + @ApiImplicitParam(name = "auditParam", value = "审计日志参数", required = true) + public HttpResult> censusAuditLog(@RequestBody @Validated AuditParam auditParam){ + String methodDescribe = getMethodDescribe("censusAuditLog"); + Page result = auditService.censusAuditLog(auditParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,result,methodDescribe); + } + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @PostMapping("/saveLogParam") + @ApiOperation("筛选下拉列表参数") + public HttpResult saveLogParam() { + String methodDescribe = getMethodDescribe("saveLogParam"); + LogParamVO result = auditService.saveLogParam(); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/AuditMapper.java b/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/AuditMapper.java index 70aa80913..3750f7583 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/AuditMapper.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/AuditMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.njcn.system.pojo.dto.excel.UserLogExcel; import com.njcn.system.pojo.param.AuditParam; import com.njcn.system.pojo.po.UserLog; +import com.njcn.system.pojo.vo.AuditLogCusVO; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -24,5 +25,16 @@ public interface AuditMapper { * 查询需要备份的审计日志 */ List queryExportUser(@Param("ew") QueryWrapper queryWrapper); - + /** + * 获取审计日志统计列表 + */ + List selectCensusAuditLog(@Param("auditParam") AuditParam auditParam); + /** + * 查询所有登录名 + */ + List selectLoginName(); + /** + * 查询所有操作类型 + */ + List selectOperateType(); } diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/mapping/AuditMapper.xml b/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/mapping/AuditMapper.xml index 840e54371..635ce721c 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/mapping/AuditMapper.xml +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/mapping/AuditMapper.xml @@ -8,6 +8,15 @@ FROM sys_user_log WHERE update_time >= #{auditParam.searchBeginTime} AND #{auditParam.searchEndTime} >= update_time + + and login_name = #{auditParam.loginName} + + + and type = #{auditParam.type} + + + and operate_type = #{auditParam.operateType} + @@ -66,5 +75,43 @@ Where ${ew.sqlSegment} + + + + + \ No newline at end of file diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/service/AuditService.java b/pqs-system/system-boot/src/main/java/com/njcn/system/service/AuditService.java index 7da549a11..09bd27b9e 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/service/AuditService.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/service/AuditService.java @@ -6,6 +6,7 @@ import com.njcn.system.pojo.param.AuditParam; import com.njcn.system.pojo.po.UserLog; import com.njcn.system.pojo.vo.AuditLogCusVO; import com.njcn.system.pojo.vo.AuditLogVO; +import com.njcn.system.pojo.vo.LogParamVO; /** * @version 1.0.0 @@ -35,4 +36,8 @@ public interface AuditService extends IService { */ Page censusAuditLog(AuditParam auditParam); + /** + * 获取筛选下拉列表参数 + */ + LogParamVO saveLogParam(); } diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/AuditServiceImpl.java b/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/AuditServiceImpl.java index 0fe1293fd..0111d3ef1 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/AuditServiceImpl.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/AuditServiceImpl.java @@ -4,6 +4,7 @@ import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.afterturn.easypoi.excel.imports.ExcelImportService; import cn.afterturn.easypoi.exception.excel.ExcelImportException; import cn.hutool.core.bean.BeanUtil; +import com.alibaba.nacos.shaded.com.google.common.collect.Lists; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -18,6 +19,7 @@ import com.njcn.system.pojo.param.AuditParam; import com.njcn.system.pojo.po.UserLog; import com.njcn.system.pojo.vo.AuditLogCusVO; import com.njcn.system.pojo.vo.AuditLogVO; +import com.njcn.system.pojo.vo.LogParamVO; import com.njcn.system.service.AuditService; import lombok.AllArgsConstructor; import org.apache.commons.compress.utils.IOUtils; @@ -76,7 +78,7 @@ public class AuditServiceImpl extends ServiceImpl implem AuditLogVO auditLogVO = new AuditLogVO(); String updateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(userLog.getUpdateTime()); auditLogVO.setTime(updateTime); - if (userLog.getUserName().isEmpty()) { + if (userLog.getUserName()==null || userLog.getUserName().equals("")) { auditLogVO.setUserName(userLog.getLoginName()); } else { auditLogVO.setUserName(userLog.getUserName()); @@ -91,7 +93,7 @@ public class AuditServiceImpl extends ServiceImpl implem describe.append("失败").append(",失败原因为").append(userLog.getFailReason()); } auditLogVO.setDescribe(describe.toString()); - auditLogVO.setOperateType(userLog.getType() == 0 ? "业务事件" : "系统事件"); + auditLogVO.setType(userLog.getType() == 0 ? "业务事件" : "系统事件"); auditLogVO.setResult(userLog.getResult() == 0 ? "失败" : "成功"); auditLogVO.setIp(userLog.getIp()); if (userLog.getLevel()==0) { @@ -126,6 +128,7 @@ public class AuditServiceImpl extends ServiceImpl implem File file = new File(filePath.getPath() + File.separator + nowDate +" sys_user_log.xlsx"); ExcelUtil.exportExcelWithTargetFile(file, UserLogExcel.class, excelList); + //备份为txt // QueryWrapper queryWrapper = new QueryWrapper<>(); // queryWrapper.ge("sys_user_log.update_time",date); // List userLogs = userLogMapper.selectList(queryWrapper); @@ -163,7 +166,6 @@ public class AuditServiceImpl extends ServiceImpl implem if (!file.exists()) { throw new BusinessException(AuditLogEnum.NOT_FIND_FILE); } - ImportParams params = new ImportParams(); params.setHeadRows(1);//表头 params.setTitleRows(0);//标题行数 @@ -173,7 +175,6 @@ public class AuditServiceImpl extends ServiceImpl implem params.setSheetNum(1); FileInputStream in = null; - try { in = new FileInputStream(file); List excelList = new ExcelImportService().importExcelByIs(in, UserLogExcel.class, params, false).getList(); @@ -192,7 +193,6 @@ public class AuditServiceImpl extends ServiceImpl implem IOUtils.closeQuietly(in); } - // try { // // FileInputStream in = new FileInputStream(file); // MultipartFile multipartFile = getMultipartFile(file); @@ -217,19 +217,28 @@ public class AuditServiceImpl extends ServiceImpl implem page.setSize(auditParam.getPageSize()); page.setCurrent(auditParam.getPageNum()); //待分页数据总量 - int count = auditMapper.getCount(auditParam); - page.setTotal(count); + List auditLogCusVOS = auditMapper.selectCensusAuditLog(auditParam); + page.setTotal(auditLogCusVOS.size()); //分页总页数 - int pages = (int)Math.ceil(count*1.0/auditParam.getPageSize()); + int pages = (int)Math.ceil(page.getTotal()*1.0/auditParam.getPageSize()); page.setPages(pages); - auditParam.setPageNum(auditParam.getPageSize()*(auditParam.getPageNum()-1)); - List userLogs = auditMapper.selectAuditLog(auditParam); - - + if (!CollectionUtils.isEmpty(auditLogCusVOS)) { + List> pageList = Lists.partition(auditLogCusVOS, auditParam.getPageSize()); + auditLogVOS = pageList.get(auditParam.getPageNum() - 1); + } + page.setRecords(auditLogVOS); return page; } + @Override + public LogParamVO saveLogParam() { + LogParamVO logParamVO = new LogParamVO(); + logParamVO.setLoginName(auditMapper.selectLoginName()); + logParamVO.setOperateType(auditMapper.selectOperateType()); + return logParamVO; + } + }