Skip to content

Commit

Permalink
refactor: 重构查询参数及字典接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jun 5, 2024
1 parent 1e73d06 commit 1d60213
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 105 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
package top.continew.admin.system.mapper;

import org.apache.ibatis.annotations.Param;
import top.continew.admin.common.model.resp.LabelValueResp;
import top.continew.admin.system.model.entity.DictItemDO;
import top.continew.starter.data.mybatis.plus.base.BaseMapper;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;

import java.io.Serializable;
import java.util.List;

/**
Expand All @@ -38,5 +37,5 @@ public interface DictItemMapper extends BaseMapper<DictItemDO> {
* @param dictCode 字典编码
* @return 字典项列表
*/
List<LabelValueResp<Serializable>> listByDictCode(@Param("dictCode") String dictCode);
List<LabelValueResp> listByDictCode(@Param("dictCode") String dictCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

package top.continew.admin.system.service;

import top.continew.admin.common.model.resp.LabelValueResp;
import top.continew.admin.system.model.entity.DictItemDO;
import top.continew.admin.system.model.query.DictItemQuery;
import top.continew.admin.system.model.req.DictItemReq;
import top.continew.admin.system.model.resp.DictItemResp;
import top.continew.starter.data.mybatis.plus.service.IService;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import top.continew.starter.extension.crud.service.BaseService;

import java.io.Serializable;
import java.util.List;

/**
Expand All @@ -41,7 +40,7 @@ public interface DictItemService extends BaseService<DictItemResp, DictItemResp,
* @param dictCode 字典编码
* @return 字典项列表
*/
List<LabelValueResp<Serializable>> listByDictCode(String dictCode);
List<LabelValueResp> listByDictCode(String dictCode);

/**
* 根据字典 ID 列表删除
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.continew.admin.common.model.resp.LabelValueResp;
import top.continew.admin.system.mapper.DictItemMapper;
import top.continew.admin.system.model.entity.DictItemDO;
import top.continew.admin.system.model.query.DictItemQuery;
import top.continew.admin.system.model.req.DictItemReq;
import top.continew.admin.system.model.resp.DictItemResp;
import top.continew.admin.system.service.DictItemService;
import top.continew.starter.core.util.validate.CheckUtils;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import top.continew.starter.extension.crud.service.impl.BaseServiceImpl;

import java.io.Serializable;
import java.util.List;

/**
Expand All @@ -54,7 +53,7 @@ protected void beforeUpdate(DictItemReq req, Long id) {
}

@Override
public List<LabelValueResp<Serializable>> listByDictCode(String dictCode) {
public List<LabelValueResp> listByDictCode(String dictCode) {
return baseMapper.listByDictCode(dictCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class OptionServiceImpl implements OptionService {
private final OptionMapper baseMapper;

@Override
@Cached(key = "#query.category", name = CacheConstants.OPTION_KEY_PREFIX)
public List<OptionResp> list(OptionQuery query) {
return BeanUtil.copyToList(baseMapper.selectList(QueryWrapperHelper.build(query)), OptionResp.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http:https://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="top.continew.admin.system.mapper.DictItemMapper">
<select id="listByDictCode" resultType="top.continew.admin.common.model.resp.LabelValueResp">
SELECT t1.label, t1.value, t1.color
<select id="listByDictCode" resultType="top.continew.starter.extension.crud.model.resp.LabelValueResp">
SELECT t1.label, t1.value, t1.color AS extend
FROM sys_dict_item AS t1
LEFT JOIN sys_dict AS t2 ON t1.dict_id = t2.id
WHERE t1.status = 1 AND t2.code = #{dictCode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil;
import com.alicp.jetcache.anno.Cached;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.x.file.storage.core.FileInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.continew.admin.common.model.resp.LabelValueResp;
import top.continew.admin.common.constant.CacheConstants;
import top.continew.admin.system.model.query.DeptQuery;
import top.continew.admin.system.model.query.MenuQuery;
import top.continew.admin.system.model.query.OptionQuery;
Expand All @@ -41,10 +43,10 @@
import top.continew.starter.core.util.validate.ValidationUtils;
import top.continew.starter.data.mybatis.plus.base.IBaseEnum;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import top.continew.starter.log.core.annotation.Log;
import top.continew.starter.web.model.R;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -95,25 +97,26 @@ public R<List<Tree<Long>>> listMenuTree(MenuQuery query, SortQuery sortQuery) {

@Operation(summary = "查询角色字典", description = "查询角色字典列表")
@GetMapping("/dict/role")
public R<List<LabelValueResp<Long>>> listRoleDict(RoleQuery query, SortQuery sortQuery) {
return R.ok(roleService.buildDict(roleService.list(query, sortQuery)));
public R<List<LabelValueResp>> listRoleDict(RoleQuery query, SortQuery sortQuery) {
return R.ok(roleService.listDict(query, sortQuery));
}

@Operation(summary = "查询字典", description = "查询字典列表")
@Parameter(name = "code", description = "字典编码", example = "notice_type", in = ParameterIn.PATH)
@GetMapping("/dict/{code}")
public R<List<LabelValueResp<Serializable>>> listDict(@PathVariable String code) {
public R<List<LabelValueResp>> listDict(@PathVariable String code) {
Optional<Class<?>> enumClassOptional = this.getEnumClassByName(code);
return R.ok(enumClassOptional.map(this::listEnumDict).orElseGet(() -> dictItemService.listByDictCode(code)));
}

@SaIgnore
@Operation(summary = "查询参数字典", description = "查询参数字典")
@GetMapping("/dict/option")
public R<List<LabelValueResp<String>>> listOptionDict(@Validated OptionQuery query) {
return R.ok(optionService.list(query)
@Cached(key = "#category", name = CacheConstants.OPTION_KEY_PREFIX)
public R<List<LabelValueResp<String>>> listOptionDict(@NotBlank(message = "类别不能为空") @RequestParam String category) {
OptionQuery optionQuery = new OptionQuery();
optionQuery.setCategory(category);
return R.ok(optionService.list(optionQuery)
.stream()
.map(option -> new LabelValueResp<>(option.getCode(), StrUtil.nullToDefault(option.getValue(), option
.getDefaultValue())))
Expand All @@ -140,11 +143,11 @@ private Optional<Class<?>> getEnumClassByName(String enumClassName) {
* @param enumClass 枚举类型
* @return 枚举字典
*/
private List<LabelValueResp<Serializable>> listEnumDict(Class<?> enumClass) {
private List<LabelValueResp> listEnumDict(Class<?> enumClass) {
Object[] enumConstants = enumClass.getEnumConstants();
return Arrays.stream(enumConstants).map(e -> {
IBaseEnum baseEnum = (IBaseEnum)e;
return new LabelValueResp<>(baseEnum.getDescription(), baseEnum.getValue(), baseEnum.getColor());
return new LabelValueResp(baseEnum.getDescription(), baseEnum.getValue(), baseEnum.getColor());
}).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public R<List<OptionResp>> list(@Validated OptionQuery query) {

@Operation(summary = "修改参数", description = "修改参数")
@SaCheckPermission("system:config:update")
@PatchMapping
@PutMapping
public R<Void> update(@Valid @RequestBody List<OptionReq> options) {
baseService.update(options);
return R.ok();
Expand Down

0 comments on commit 1d60213

Please sign in to comment.