update 优化通用查询参数中魔法值

This commit is contained in:
lxdy 2024-09-11 14:28:49 +08:00
parent 5e3231d59b
commit e03a62f245
11 changed files with 85 additions and 24 deletions

View File

@ -0,0 +1,31 @@
package org.dromara.common.core.constant;
/**
* 查询条件query 常量
*
* @author lxdy
*/
public interface QueryConstants {
/**
* 开始创建时间
*/
String BEGIN_CREATE_TIME = "beginCreateTime";
/**
* 结束创建时间
*/
String END_CREATE_TIME = "endCreateTime";
/**
* 开始创建时间
*/
String BEGIN_TIME = "beginTime";
/**
* 结束创建时间
*/
String END_TIME = "endTime";
}

View File

@ -20,6 +20,9 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_CREATE_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_CREATE_TIME;
/**
* 测试单表Service业务层处理
*
@ -64,8 +67,8 @@ public class TestDemoServiceImpl implements ITestDemoService {
LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery();
lqw.like(StringUtils.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey());
lqw.eq(StringUtils.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue());
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
TestDemo::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
lqw.between(params.get(BEGIN_CREATE_TIME) != null && params.get(END_CREATE_TIME) != null,
TestDemo::getCreateTime, params.get(BEGIN_CREATE_TIME), params.get(END_CREATE_TIME));
lqw.orderByAsc(TestDemo::getId);
return lqw;
}

View File

@ -2,6 +2,7 @@ package org.dromara.demo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.demo.domain.TestTree;
@ -9,13 +10,15 @@ import org.dromara.demo.domain.bo.TestTreeBo;
import org.dromara.demo.domain.vo.TestTreeVo;
import org.dromara.demo.mapper.TestTreeMapper;
import org.dromara.demo.service.ITestTreeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_CREATE_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_CREATE_TIME;
/**
* 测试树表Service业务层处理
*
@ -45,8 +48,8 @@ public class TestTreeServiceImpl implements ITestTreeService {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<TestTree> lqw = Wrappers.lambdaQuery();
lqw.like(StringUtils.isNotBlank(bo.getTreeName()), TestTree::getTreeName, bo.getTreeName());
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
TestTree::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
lqw.between(params.get(BEGIN_CREATE_TIME) != null && params.get(END_CREATE_TIME) != null,
TestTree::getCreateTime, params.get(BEGIN_CREATE_TIME), params.get(END_CREATE_TIME));
lqw.orderByAsc(TestTree::getId);
return lqw;
}

View File

@ -50,6 +50,9 @@ import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_TIME;
/**
* 业务 服务层实现
*
@ -105,8 +108,8 @@ public class GenTableServiceImpl implements IGenTableService {
.eq(StringUtils.isNotEmpty(genTable.getDataName()), "data_name", genTable.getDataName())
.like(StringUtils.isNotBlank(genTable.getTableName()), "lower(table_name)", StringUtils.lowerCase(genTable.getTableName()))
.like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(table_comment)", StringUtils.lowerCase(genTable.getTableComment()))
.between(params.get("beginTime") != null && params.get("endTime") != null,
"create_time", params.get("beginTime"), params.get("endTime"));
.between(params.get(BEGIN_TIME) != null && params.get(END_TIME) != null,
"create_time", params.get(BEGIN_TIME), params.get(END_TIME));
return wrapper;
}

View File

@ -6,6 +6,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.constant.UserConstants;
import org.dromara.common.core.exception.ServiceException;
@ -22,7 +23,6 @@ import org.dromara.system.domain.bo.SysConfigBo;
import org.dromara.system.domain.vo.SysConfigVo;
import org.dromara.system.mapper.SysConfigMapper;
import org.dromara.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@ -31,6 +31,9 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_TIME;
/**
* 参数配置 服务层实现
*
@ -113,8 +116,8 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
lqw.like(StringUtils.isNotBlank(bo.getConfigName()), SysConfig::getConfigName, bo.getConfigName());
lqw.eq(StringUtils.isNotBlank(bo.getConfigType()), SysConfig::getConfigType, bo.getConfigType());
lqw.like(StringUtils.isNotBlank(bo.getConfigKey()), SysConfig::getConfigKey, bo.getConfigKey());
lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
SysConfig::getCreateTime, params.get("beginTime"), params.get("endTime"));
lqw.between(params.get(BEGIN_TIME) != null && params.get(END_TIME) != null,
SysConfig::getCreateTime, params.get(BEGIN_TIME), params.get(END_TIME));
lqw.orderByAsc(SysConfig::getConfigId);
return lqw;
}

View File

@ -36,6 +36,9 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_TIME;
/**
* 字典 业务层处理
*
@ -72,8 +75,8 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
LambdaQueryWrapper<SysDictType> lqw = Wrappers.lambdaQuery();
lqw.like(StringUtils.isNotBlank(bo.getDictName()), SysDictType::getDictName, bo.getDictName());
lqw.like(StringUtils.isNotBlank(bo.getDictType()), SysDictType::getDictType, bo.getDictType());
lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
SysDictType::getCreateTime, params.get("beginTime"), params.get("endTime"));
lqw.between(params.get(BEGIN_TIME) != null && params.get(END_TIME) != null,
SysDictType::getCreateTime, params.get(BEGIN_TIME), params.get(END_TIME));
lqw.orderByAsc(SysDictType::getDictId);
return lqw;
}

View File

@ -33,6 +33,9 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_TIME;
/**
* 系统访问日志情况信息 服务层处理
*
@ -115,8 +118,8 @@ public class SysLogininforServiceImpl implements ISysLogininforService {
.like(StringUtils.isNotBlank(logininfor.getIpaddr()), SysLogininfor::getIpaddr, logininfor.getIpaddr())
.eq(StringUtils.isNotBlank(logininfor.getStatus()), SysLogininfor::getStatus, logininfor.getStatus())
.like(StringUtils.isNotBlank(logininfor.getUserName()), SysLogininfor::getUserName, logininfor.getUserName())
.between(params.get("beginTime") != null && params.get("endTime") != null,
SysLogininfor::getLoginTime, params.get("beginTime"), params.get("endTime"));
.between(params.get(BEGIN_TIME) != null && params.get(END_TIME) != null,
SysLogininfor::getLoginTime, params.get(BEGIN_TIME), params.get(END_TIME));
if (StringUtils.isBlank(pageQuery.getOrderByColumn())) {
pageQuery.setOrderByColumn("info_id");
pageQuery.setIsAsc("desc");
@ -150,8 +153,8 @@ public class SysLogininforServiceImpl implements ISysLogininforService {
.like(StringUtils.isNotBlank(logininfor.getIpaddr()), SysLogininfor::getIpaddr, logininfor.getIpaddr())
.eq(StringUtils.isNotBlank(logininfor.getStatus()), SysLogininfor::getStatus, logininfor.getStatus())
.like(StringUtils.isNotBlank(logininfor.getUserName()), SysLogininfor::getUserName, logininfor.getUserName())
.between(params.get("beginTime") != null && params.get("endTime") != null,
SysLogininfor::getLoginTime, params.get("beginTime"), params.get("endTime"))
.between(params.get(BEGIN_TIME) != null && params.get(END_TIME) != null,
SysLogininfor::getLoginTime, params.get(BEGIN_TIME), params.get(END_TIME))
.orderByDesc(SysLogininfor::getInfoId));
}

View File

@ -24,6 +24,9 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_TIME;
/**
* 操作日志 服务层处理
*
@ -75,8 +78,8 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
.eq(operLog.getStatus() != null,
SysOperLog::getStatus, operLog.getStatus())
.like(StringUtils.isNotBlank(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName())
.between(params.get("beginTime") != null && params.get("endTime") != null,
SysOperLog::getOperTime, params.get("beginTime"), params.get("endTime"));
.between(params.get(BEGIN_TIME) != null && params.get(END_TIME) != null,
SysOperLog::getOperTime, params.get(BEGIN_TIME), params.get(END_TIME));
}
/**

View File

@ -41,6 +41,9 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_CREATE_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_CREATE_TIME;
/**
* 文件上传 服务层实现
*
@ -141,8 +144,8 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
lqw.like(StringUtils.isNotBlank(bo.getOriginalName()), SysOss::getOriginalName, bo.getOriginalName());
lqw.eq(StringUtils.isNotBlank(bo.getFileSuffix()), SysOss::getFileSuffix, bo.getFileSuffix());
lqw.eq(StringUtils.isNotBlank(bo.getUrl()), SysOss::getUrl, bo.getUrl());
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
SysOss::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
lqw.between(params.get(BEGIN_CREATE_TIME) != null && params.get(END_CREATE_TIME) != null,
SysOss::getCreateTime, params.get(BEGIN_CREATE_TIME), params.get(END_CREATE_TIME));
lqw.eq(ObjectUtil.isNotNull(bo.getCreateBy()), SysOss::getCreateBy, bo.getCreateBy());
lqw.eq(StringUtils.isNotBlank(bo.getService()), SysOss::getService, bo.getService());
lqw.orderByAsc(SysOss::getOssId);

View File

@ -38,6 +38,9 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_TIME;
/**
* 角色 业务层处理
*
@ -77,8 +80,8 @@ public class SysRoleServiceImpl implements ISysRoleService {
.like(StringUtils.isNotBlank(bo.getRoleName()), "r.role_name", bo.getRoleName())
.eq(StringUtils.isNotBlank(bo.getStatus()), "r.status", bo.getStatus())
.like(StringUtils.isNotBlank(bo.getRoleKey()), "r.role_key", bo.getRoleKey())
.between(params.get("beginTime") != null && params.get("endTime") != null,
"r.create_time", params.get("beginTime"), params.get("endTime"))
.between(params.get(BEGIN_TIME) != null && params.get(END_TIME) != null,
"r.create_time", params.get(BEGIN_TIME), params.get(END_TIME))
.orderByAsc("r.role_sort").orderByAsc("r.create_time");
return wrapper;
}

View File

@ -44,6 +44,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.dromara.common.core.constant.QueryConstants.BEGIN_TIME;
import static org.dromara.common.core.constant.QueryConstants.END_TIME;
/**
* 用户 业务层处理
*
@ -86,8 +89,8 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
.like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName())
.eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus())
.like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.between(params.get("beginTime") != null && params.get("endTime") != null,
"u.create_time", params.get("beginTime"), params.get("endTime"))
.between(params.get(BEGIN_TIME) != null && params.get(END_TIME) != null,
"u.create_time", params.get(BEGIN_TIME), params.get(END_TIME))
.and(ObjectUtil.isNotNull(user.getDeptId()), w -> {
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId)