refactor: 优化部分代码

This commit is contained in:
Charles7c 2024-05-01 22:06:47 +08:00
parent 42ac82e7ce
commit 0a0353f1f6
7 changed files with 31 additions and 42 deletions

View File

@ -31,12 +31,11 @@ import java.util.List;
*/
public interface FileMapper extends BaseMapper<FileDO> {
/**
* 查询文件资源统计
* 查询文件资源统计信息
*
* @return 文件资源统计结果
* @return 文件资源统计信息
*/
@Select("SELECT type,COUNT(1) number,SUM(size) size FROM sys_file GROUP BY type")
@Select("SELECT type, COUNT(1) number, SUM(size) size FROM sys_file GROUP BY type")
List<FileStatisticsResp> statistics();
}

View File

@ -18,6 +18,7 @@ package top.continew.admin.system.model.query;
import cn.hutool.core.date.DatePattern;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -68,6 +69,7 @@ public class LogQuery implements Serializable {
*/
@Schema(description = "操作时间", example = "2023-08-08 00:00:00,2023-08-08 23:59:59")
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
@Size(max = 2, message = "操作时间必须是一个范围")
private List<Date> createTime;
/**

View File

@ -16,6 +16,7 @@
package top.continew.admin.system.model.resp;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.system.enums.FileTypeEnum;
@ -25,13 +26,14 @@ import java.io.Serializable;
import java.util.List;
/**
* 文件资源统计
* 文件资源统计信息
*
* @author Kils
* @since 2024/04/30 14:30
* @since 2024/4/30 14:30
*/
@Data
@Schema(description = "文件资源统计")
@Schema(description = "文件资源统计信息")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FileStatisticsResp implements Serializable {
@Serial
@ -40,7 +42,8 @@ public class FileStatisticsResp implements Serializable {
/**
* 文件类型
*/
@Schema(description = "文件类型", example = "")
@Schema(description = "类型1其他2图片3文档4视频5音频", type = "Integer", allowableValues = {"1", "2", "3", "4",
"5"}, example = "2")
private FileTypeEnum type;
/**

View File

@ -64,9 +64,9 @@ public interface FileService extends BaseService<FileResp, FileResp, FileQuery,
Long countByStorageIds(List<Long> storageIds);
/**
* 查询文件资源统计
* 查询文件资源统计信息
*
* @return 资源统计结果
* @return 资源统计信息
*/
FileStatisticsResp statistics();
}

View File

@ -17,12 +17,8 @@
package top.continew.admin.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.unit.DataSizeUtil;
import cn.hutool.core.io.unit.DataUnit;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -41,7 +41,6 @@ import top.continew.admin.system.model.resp.log.LoginLogExportResp;
import top.continew.admin.system.model.resp.log.OperationLogExportResp;
import top.continew.admin.system.service.LogService;
import top.continew.starter.core.util.validate.CheckUtils;
import top.continew.starter.core.util.validate.ValidationUtils;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
@ -66,7 +65,7 @@ public class LogServiceImpl implements LogService {
@Override
public PageResp<LogResp> page(LogQuery query, PageQuery pageQuery) {
QueryWrapper<LogDO> queryWrapper = this.handleQueryWrapper(query);
QueryWrapper<LogDO> queryWrapper = this.buildQueryWrapper(query);
IPage<LogResp> page = baseMapper.selectLogPage(pageQuery.toPage(), queryWrapper);
return PageResp.build(page);
}
@ -120,7 +119,7 @@ public class LogServiceImpl implements LogService {
* @return 列表信息
*/
private List<LogResp> list(LogQuery query, SortQuery sortQuery) {
QueryWrapper<LogDO> queryWrapper = this.handleQueryWrapper(query);
QueryWrapper<LogDO> queryWrapper = this.buildQueryWrapper(query);
this.sort(queryWrapper, sortQuery);
return baseMapper.selectLogList(queryWrapper);
}
@ -142,39 +141,28 @@ public class LogServiceImpl implements LogService {
}
/**
* 处理查询条件
* 构建 QueryWrapper
*
* @param query 查询条件
* @return QueryWrapper
*/
private QueryWrapper<LogDO> handleQueryWrapper(LogQuery query) {
QueryWrapper<LogDO> queryWrapper = new QueryWrapper<>();
// 构建条件
private QueryWrapper<LogDO> buildQueryWrapper(LogQuery query) {
String description = query.getDescription();
if (StrUtil.isNotBlank(description)) {
queryWrapper.and(q -> q.like("t1.description", description).or().like("t1.module", description));
}
String module = query.getModule();
if (StrUtil.isNotBlank(module)) {
queryWrapper.eq("t1.module", module);
}
String ip = query.getIp();
if (StrUtil.isNotBlank(ip)) {
queryWrapper.and(q -> q.like("t1.ip", ip).or().like("t1.address", ip));
}
String createUserString = query.getCreateUserString();
if (StrUtil.isNotBlank(createUserString)) {
queryWrapper.and(q -> q.like("t2.username", createUserString).or().like("t2.nickname", createUserString));
}
List<Date> createTimeList = query.getCreateTime();
if (CollUtil.isNotEmpty(createTimeList)) {
ValidationUtils.throwIf(createTimeList.size() != 2, "[{}] 必须是一个范围", "createTime");
queryWrapper.between("t1.create_time", createTimeList.get(0), createTimeList.get(1));
}
Integer status = query.getStatus();
if (null != status) {
queryWrapper.eq("t1.status", status);
}
return queryWrapper;
List<Date> createTimeList = query.getCreateTime();
return new QueryWrapper<LogDO>().and(StrUtil.isNotBlank(description), q -> q.like("t1.description", description)
.or()
.like("t1.module", description))
.eq(StrUtil.isNotBlank(module), "t1.module", module)
.and(StrUtil.isNotBlank(ip), q -> q.like("t1.ip", ip).or().like("t1.address", ip))
.and(StrUtil.isNotBlank(createUserString), q -> q.like("t2.username", createUserString)
.or()
.like("t2.nickname", createUserString))
.eq(null != status, "t1.status", status)
.between(CollUtil.isNotEmpty(createTimeList), "t1.create_time", CollUtil.getFirst(createTimeList), CollUtil
.getLast(createTimeList));
}
}

View File

@ -15,6 +15,7 @@
*/
package top.continew.admin.webapi.system;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;