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 new file mode 100644 index 000000000..640f0d2d9 --- /dev/null +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/AuditLogCusVO.java @@ -0,0 +1,34 @@ +package com.njcn.system.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/07/13 21:02 + */ +@Data +public class AuditLogCusVO implements Serializable { + + /** + * 操作人员 + */ + @ApiModelProperty("操作人员") + private String userName; + + /** + * 操作类型 + */ + @ApiModelProperty("操作类型") + private String operate; + + /** + * 事件总数 + */ + @ApiModelProperty("事件总数") + private Integer count; + +} diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/config/SystemBaseConfig.java b/pqs-system/system-boot/src/main/java/com/njcn/system/config/SystemBaseConfig.java new file mode 100644 index 000000000..cdc3d8984 --- /dev/null +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/config/SystemBaseConfig.java @@ -0,0 +1,22 @@ +package com.njcn.system.config; + +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * @version 1.0.0 + * @author: chenchao + * @date: 2022/07/15 14:31 + */ +@Data +@Component +public class SystemBaseConfig { + + @Value("${business.wavePath}") + private String wavePath; + + @Value("${business.tempPath}") + private String tempPath; + +} 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 f63191d0f..ff53a5635 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,6 +7,7 @@ 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.service.AuditService; import com.njcn.web.controller.BaseController; @@ -46,6 +47,25 @@ public class AuditController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,result,methodDescribe); } + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/logFileWriter") + @ApiOperation("日志文件备份") + public HttpResult logFileWriter() { + String methodDescribe = getMethodDescribe("logFileWriter"); + auditService.logFileWriter(); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,null,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); + } + } 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 226239e9a..da93995a4 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 @@ -1,7 +1,10 @@ package com.njcn.system.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; 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; /** @@ -9,11 +12,22 @@ import com.njcn.system.pojo.vo.AuditLogVO; * @author: chenchao * @date: 2022/07/11 19:59 */ -public interface AuditService { +public interface AuditService extends IService { /** - * 获取审计日志列表 + * 分页获取审计日志列表 * @param auditParam */ Page getAuditLog(AuditParam auditParam); + /** + * 日志文件备份下载 + */ + void logFileWriter(); + + /** + * 分页获取审计日志统计列表 + * @param auditParam + */ + Page censusAuditLog(AuditParam auditParam); + } 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 f174fc8e2..b9783cc4f 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 @@ -1,16 +1,25 @@ package com.njcn.system.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.system.config.SystemBaseConfig; import com.njcn.system.mapper.AuditMapper; +import com.njcn.system.mapper.UserLogMapper; 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.service.AuditService; import lombok.AllArgsConstructor; +import org.apache.commons.io.FileUtils; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import java.io.File; +import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.List; @@ -21,11 +30,12 @@ import java.util.List; */ @Service @AllArgsConstructor -public class AuditServiceImpl implements AuditService { - +public class AuditServiceImpl extends ServiceImpl implements AuditService { private final AuditMapper auditMapper; + private final UserLogMapper userLogMapper; + @Override public Page getAuditLog(AuditParam auditParam) { List auditLogVOS = new ArrayList<>(); @@ -77,6 +87,53 @@ public class AuditServiceImpl implements AuditService { return page; } + @Override + public void logFileWriter() { + SystemBaseConfig SystemBaseConfig = null; + LocalDate nowDate = LocalDate.now(); + LocalDate agoDate = nowDate.minusMonths(6).with(TemporalAdjusters.firstDayOfMonth()); + 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"); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.ge("sys_user_log.update_time",date); + List userLogs = userLogMapper.selectList(queryWrapper); + 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(); + } + + } + + + @Override + public Page censusAuditLog(AuditParam auditParam) { + List auditLogVOS = new ArrayList<>(); + + Page page = new Page<>(); + page.setSize(auditParam.getPageSize()); + page.setCurrent(auditParam.getPageNum()); + //待分页数据总量 + int count = auditMapper.getCount(auditParam); + page.setTotal(count); + //分页总页数 + int pages = (int)Math.ceil(count*1.0/auditParam.getPageSize()); + page.setPages(pages); + + auditParam.setPageNum(auditParam.getPageSize()*(auditParam.getPageNum()-1)); + List userLogs = auditMapper.selectAuditLog(auditParam); + + + + return page; + } }