上传日志文件备份
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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<Page<AuditLogCusVO>> censusAuditLog(@RequestBody @Validated AuditParam auditParam){
|
||||
String methodDescribe = getMethodDescribe("censusAuditLog");
|
||||
Page<AuditLogCusVO> result = auditService.censusAuditLog(auditParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,result,methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<UserLog> {
|
||||
/**
|
||||
* 获取审计日志列表
|
||||
* 分页获取审计日志列表
|
||||
* @param auditParam
|
||||
*/
|
||||
Page<AuditLogVO> getAuditLog(AuditParam auditParam);
|
||||
|
||||
/**
|
||||
* 日志文件备份下载
|
||||
*/
|
||||
void logFileWriter();
|
||||
|
||||
/**
|
||||
* 分页获取审计日志统计列表
|
||||
* @param auditParam
|
||||
*/
|
||||
Page<AuditLogCusVO> censusAuditLog(AuditParam auditParam);
|
||||
|
||||
}
|
||||
|
||||
@@ -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<UserLogMapper, UserLog> implements AuditService {
|
||||
|
||||
private final AuditMapper auditMapper;
|
||||
|
||||
private final UserLogMapper userLogMapper;
|
||||
|
||||
@Override
|
||||
public Page<AuditLogVO> getAuditLog(AuditParam auditParam) {
|
||||
List<AuditLogVO> 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<UserLog> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.ge("sys_user_log.update_time",date);
|
||||
List<UserLog> 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<AuditLogCusVO> censusAuditLog(AuditParam auditParam) {
|
||||
List<AuditLogCusVO> auditLogVOS = new ArrayList<>();
|
||||
|
||||
Page<AuditLogCusVO> 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<UserLog> userLogs = auditMapper.selectAuditLog(auditParam);
|
||||
|
||||
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user