|
|
|
|
@@ -5,6 +5,7 @@ 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.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
|
|
@@ -15,11 +16,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
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.google.common.collect.Lists;
|
|
|
|
|
import com.njcn.common.config.GeneralInfo;
|
|
|
|
|
import com.njcn.common.pojo.exception.BusinessException;
|
|
|
|
|
import com.njcn.redis.utils.RedisUtil;
|
|
|
|
|
import com.njcn.system.enums.AuditLogEnum;
|
|
|
|
|
import com.njcn.system.excel.DemoDataListener;
|
|
|
|
|
import com.njcn.system.excel.DataListener;
|
|
|
|
|
import com.njcn.system.excel.UserLogExcel;
|
|
|
|
|
import com.njcn.system.mapper.AuditMapper;
|
|
|
|
|
import com.njcn.system.mapper.UserLogMapper;
|
|
|
|
|
@@ -37,7 +38,6 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
|
|
|
|
@@ -64,14 +64,15 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|
|
|
|
private String urls;
|
|
|
|
|
private final GeneralInfo generalInfo;
|
|
|
|
|
|
|
|
|
|
private final RedisUtil redisUtil;
|
|
|
|
|
@Override
|
|
|
|
|
public Page<AuditLogVO> getAuditLog(AuditParam auditParam) {
|
|
|
|
|
List<AuditLogVO> auditLogVOS = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
Page<UserLog> info = this.page(new Page<>(auditParam.getPageNum(), auditParam.getPageSize()), new LambdaQueryWrapper<UserLog>()
|
|
|
|
|
.eq(StrUtil.isNotBlank(auditParam.getLoginName()), UserLog::getLoginName, auditParam.getLoginName())
|
|
|
|
|
.eq(auditParam.getType() != null, UserLog::getLoginName, auditParam.getType())
|
|
|
|
|
.eq(StrUtil.isNotBlank(auditParam.getOperateType()), UserLog::getLoginName, auditParam.getLoginName())
|
|
|
|
|
.eq(auditParam.getType() != null, UserLog::getType, auditParam.getType())
|
|
|
|
|
.eq(StrUtil.isNotBlank(auditParam.getOperateType()), UserLog::getOperateType, auditParam.getOperateType())
|
|
|
|
|
.ge(StrUtil.isNotBlank(auditParam.getSearchBeginTime()), UserLog::getCreateTime, DateUtil.beginOfDay(DateUtil.parse(auditParam.getSearchBeginTime())))
|
|
|
|
|
.le(StrUtil.isNotBlank(auditParam.getSearchEndTime()), UserLog::getCreateTime, DateUtil.endOfDay(DateUtil.parse(auditParam.getSearchEndTime())))
|
|
|
|
|
);
|
|
|
|
|
@@ -118,6 +119,12 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void logFileWriter() {
|
|
|
|
|
//限制多次点击
|
|
|
|
|
String logFileWriter = redisUtil.getStringByKey("logFileWriter");
|
|
|
|
|
if(StrUtil.isNotBlank(logFileWriter)|| ObjectUtil.equals(logFileWriter,"1")){
|
|
|
|
|
throw new BusinessException(AuditLogEnum.MULTIPLE_CLICKS_LOGFILEWRITER);
|
|
|
|
|
}
|
|
|
|
|
redisUtil.saveByKey("logFileWriter","1");
|
|
|
|
|
LocalDateTime nowDate = LocalDateTime.now();
|
|
|
|
|
LocalDateTime agoDate = nowDate.minusMonths(6).with(TemporalAdjusters.firstDayOfMonth());
|
|
|
|
|
String date = agoDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
|
|
|
|
@@ -125,6 +132,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|
|
|
|
String endTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH_mm_ss").format(nowDate);
|
|
|
|
|
//文件名
|
|
|
|
|
QueryWrapper<UserLog> aa = new QueryWrapper<>();
|
|
|
|
|
aa.select("id");
|
|
|
|
|
aa.ge("sys_user_log.update_time", date);
|
|
|
|
|
aa.le("sys_user_log.update_time", endTime);
|
|
|
|
|
String nowTime = date + "至" + endTime;
|
|
|
|
|
@@ -169,10 +177,12 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
redisUtil.delete("recoverLogFile");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
excelWriter.finish();
|
|
|
|
|
}
|
|
|
|
|
redisUtil.delete("logFileWriter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -193,8 +203,13 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void recoverLogFile() {
|
|
|
|
|
String logFileWriter = redisUtil.getStringByKey("recoverLogFile");
|
|
|
|
|
if(StrUtil.isNotBlank(logFileWriter)|| ObjectUtil.equals(logFileWriter,"1")){
|
|
|
|
|
throw new BusinessException(AuditLogEnum.MULTIPLE_CLICKS_LOGFILEWRITER);
|
|
|
|
|
}
|
|
|
|
|
redisUtil.saveByKey("recoverLogFile","1");
|
|
|
|
|
File newFile = getLastFile();
|
|
|
|
|
if (!newFile.exists()) {
|
|
|
|
|
if (FileUtil.isEmpty(newFile)) {
|
|
|
|
|
throw new BusinessException(AuditLogEnum.NOT_FIND_FILE);
|
|
|
|
|
}
|
|
|
|
|
FileInputStream in = null;
|
|
|
|
|
@@ -211,38 +226,24 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|
|
|
|
.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()))
|
|
|
|
|
EasyExcel.read(newFile, UserLogExcel.class, new DataListener(this.getBaseMapper()))
|
|
|
|
|
.excelType(ExcelTypeEnum.XLSX).doReadAll();
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
redisUtil.delete("recoverLogFile");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
throw new ExcelImportException(e.getMessage(), e);
|
|
|
|
|
} finally {
|
|
|
|
|
IOUtils.closeQuietly(in);
|
|
|
|
|
}
|
|
|
|
|
redisUtil.delete("recoverLogFile");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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());
|
|
|
|
|
//待分页数据总量
|
|
|
|
|
List<AuditLogCusVO> auditLogCusVOS = auditMapper.selectCensusAuditLog(auditParam);
|
|
|
|
|
page.setTotal(auditLogCusVOS.size());
|
|
|
|
|
//分页总页数
|
|
|
|
|
int pages = (int) Math.ceil(page.getTotal() * 1.0 / auditParam.getPageSize());
|
|
|
|
|
page.setPages(pages);
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(auditLogCusVOS)) {
|
|
|
|
|
List<List<AuditLogCusVO>> pageList = Lists.partition(auditLogCusVOS, auditParam.getPageSize());
|
|
|
|
|
auditLogVOS = pageList.get(auditParam.getPageNum() - 1);
|
|
|
|
|
}
|
|
|
|
|
page.setRecords(auditLogVOS);
|
|
|
|
|
|
|
|
|
|
Page<AuditLogCusVO> page = auditMapper.selectCensusAuditLog(new Page<>(auditParam.getPageNum(), auditParam.getPageSize()), auditParam);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -259,7 +260,7 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Float getMemoInfo() {
|
|
|
|
|
String schema = urls.substring(urls.lastIndexOf("/")+1,urls.lastIndexOf("?"));
|
|
|
|
|
String schema = urls.substring(urls.lastIndexOf("/") + 1, urls.lastIndexOf("?"));
|
|
|
|
|
return this.baseMapper.getMemoInfo(schema);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -292,8 +293,6 @@ public class AuditServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implem
|
|
|
|
|
*/
|
|
|
|
|
public File getLastFile() {
|
|
|
|
|
File parentFile = new File(generalInfo.getBusinessTempPath());
|
|
|
|
|
// Date date = FileUtil.lastModifiedTime(parentFile);
|
|
|
|
|
// System.out.println(">>>>>>>>>>当前文件夹最后修改时间>>>>>>>>>" + date);
|
|
|
|
|
|
|
|
|
|
//文件夹下的所有子文件数组
|
|
|
|
|
File[] files = parentFile.listFiles();
|
|
|
|
|
|