perf: 优化查询写法

优化查询时使用LambdaQueryWrapper查询
部分注释补全,格式化
This commit is contained in:
胡少翔
2024-07-31 10:06:29 +08:00
parent dbf9cca78f
commit cee4651e12
6 changed files with 19 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ package com.youlai.system.common.constant;
* @since 2024-7-29 11:46:08
*/
public interface SymbolConstant {
/**
* 符号:点
*/
@@ -28,7 +29,7 @@ public interface SymbolConstant {
String COMMA = ",";
/**
* 符号:左花括号 }
* 符号:左花括号 {
*/
String LEFT_CURLY_BRACKET = "{";

View File

@@ -13,7 +13,6 @@ public interface SystemConstants {
*/
Long ROOT_NODE_ID = 0L;
/**
* 系统默认密码
*/
@@ -24,14 +23,4 @@ public interface SystemConstants {
*/
String ROOT_ROLE_CODE = "ROOT";
/**
* 未删除状态
*/
Integer NOT_DELETED_STATUS = 0;
/**
* 删除状态
*/
Integer DELETED_STATUS = 1;
}

View File

@@ -33,7 +33,7 @@ public interface SysConfigService extends IService<SysConfig> {
* 获取系统配置表单数据
*
* @param id 系统配置ID
* @return
* @return 系统配置表单数据
*/
ConfigForm getConfigFormData(Long id);
@@ -52,7 +52,6 @@ public interface SysConfigService extends IService<SysConfig> {
*/
boolean delete(Long ids);
/**
* 刷新系统配置缓存
* @return 是否刷新成功
@@ -62,7 +61,7 @@ public interface SysConfigService extends IService<SysConfig> {
/**
* 获取系统配置
* @param key 配置键
* @return 配置value
* @return 配置
*/
Object getSystemConfig(String key);

View File

@@ -1,5 +1,6 @@
package com.youlai.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -48,9 +49,9 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
@Override
public IPage<ConfigVO> page(ConfigPageQuery configPageQuery) {
Page<SysConfig> page = new Page<>(configPageQuery.getPageNum(), configPageQuery.getPageSize());
QueryWrapper<SysConfig> query = new QueryWrapper<>();
LambdaQueryWrapper<SysConfig> query = new LambdaQueryWrapper<>();
if(StringUtils.isNotBlank(configPageQuery.getKeywords())) {
query.and(q -> q.like("config_key", configPageQuery.getKeywords()).or().like("config_name", configPageQuery.getKeywords()));
query.and(q -> q.like(SysConfig::getConfigKey, configPageQuery.getKeywords()).or().like(SysConfig::getConfigName, configPageQuery.getKeywords()));
}
Page<SysConfig> pageList = this.page(page, query);
return sysConfigConverter.convertToPageVo(pageList);
@@ -63,10 +64,11 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
*/
@Override
public boolean save(ConfigForm configForm) {
Assert.isTrue(super.count(new QueryWrapper<SysConfig>().eq("config_key", configForm.getConfigKey())) == 0, "配置键已存在");
Assert.isTrue(
super.count(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getConfigKey, configForm.getConfigKey())) == 0,
"配置键已存在");
SysConfig sysConfig = sysConfigConverter.toEntity(configForm);
sysConfig.setCreateBy(SecurityUtils.getUserId());
sysConfig.setIsDeleted(SystemConstants.NOT_DELETED_STATUS);
return this.save(sysConfig);
}
@@ -74,7 +76,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
* 获取系统配置表单数据
*
* @param id 系统配置ID
* @return
* @return 系统配置表单数据
*/
@Override
public ConfigForm getConfigFormData(Long id) {
@@ -90,7 +92,9 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
*/
@Override
public boolean edit(Long id, ConfigForm configForm) {
Assert.isTrue(super.count(new QueryWrapper<SysConfig>().eq("config_key", configForm.getConfigKey()).ne("id", id)) == 0, "配置键已存在");
Assert.isTrue(
super.count(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getConfigKey, configForm.getConfigKey()).ne(SysConfig::getId, id)) == 0,
"配置键已存在");
SysConfig sysConfig = sysConfigConverter.toEntity(configForm);
sysConfig.setUpdateBy(SecurityUtils.getUserId());
return this.update(sysConfig, new QueryWrapper<SysConfig>().eq("id", id));
@@ -104,7 +108,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
@Override
public boolean delete(Long id) {
if (id != null) {
return super.remove(new QueryWrapper<SysConfig>().eq("id", id));
return super.remove(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getId, id));
}
return false;
}
@@ -128,7 +132,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
/**
* 获取系统配置
* @param key 配置键
* @return 配置value
* @return 配置
*/
@Override
public Object getSystemConfig(String key) {