mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 00:57:13 +08:00 
			
		
		
		
	refactor: 重构查询参数及字典接口
This commit is contained in:
		| @@ -1,83 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. |  | ||||||
|  * |  | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  | ||||||
|  * you may not use this file except in compliance with the License. |  | ||||||
|  * You may obtain a copy of the License at |  | ||||||
|  * |  | ||||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
|  * |  | ||||||
|  * Unless required by applicable law or agreed to in writing, software |  | ||||||
|  * distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|  * See the License for the specific language governing permissions and |  | ||||||
|  * limitations under the License. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| package top.continew.admin.common.model.resp; |  | ||||||
|  |  | ||||||
| import com.fasterxml.jackson.annotation.JsonInclude; |  | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; |  | ||||||
| import lombok.Data; |  | ||||||
| import lombok.NoArgsConstructor; |  | ||||||
|  |  | ||||||
| import java.io.Serial; |  | ||||||
| import java.io.Serializable; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * 键值对信息 |  | ||||||
|  * |  | ||||||
|  * @param <T> |  | ||||||
|  * @author Charles7c |  | ||||||
|  * @since 2023/2/24 22:02 |  | ||||||
|  */ |  | ||||||
| @Data |  | ||||||
| @NoArgsConstructor |  | ||||||
| @Schema(description = "键值对信息") |  | ||||||
| public class LabelValueResp<T> implements Serializable { |  | ||||||
|  |  | ||||||
|     @Serial |  | ||||||
|     private static final long serialVersionUID = 1L; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 标签 |  | ||||||
|      */ |  | ||||||
|     @Schema(description = "标签", example = "男") |  | ||||||
|     private String label; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 值 |  | ||||||
|      */ |  | ||||||
|     @Schema(description = "值", example = "1") |  | ||||||
|     private T value; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 是否禁用 |  | ||||||
|      */ |  | ||||||
|     @Schema(description = "是否禁用", example = "false") |  | ||||||
|     private Boolean disabled; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 颜色 |  | ||||||
|      */ |  | ||||||
|     @Schema(description = "颜色", example = "#165DFF") |  | ||||||
|     @JsonInclude(JsonInclude.Include.NON_NULL) |  | ||||||
|     private String color; |  | ||||||
|  |  | ||||||
|     public LabelValueResp(String label, T value) { |  | ||||||
|         this.label = label; |  | ||||||
|         this.value = value; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public LabelValueResp(String label, T value, String color) { |  | ||||||
|         this.label = label; |  | ||||||
|         this.value = value; |  | ||||||
|         this.color = color; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public LabelValueResp(String label, T value, Boolean disabled) { |  | ||||||
|         this.label = label; |  | ||||||
|         this.value = value; |  | ||||||
|         this.disabled = disabled; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -17,11 +17,10 @@ | |||||||
| package top.continew.admin.system.mapper; | package top.continew.admin.system.mapper; | ||||||
|  |  | ||||||
| import org.apache.ibatis.annotations.Param; | 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.admin.system.model.entity.DictItemDO; | ||||||
| import top.continew.starter.data.mybatis.plus.base.BaseMapper; | 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; | import java.util.List; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -38,5 +37,5 @@ public interface DictItemMapper extends BaseMapper<DictItemDO> { | |||||||
|      * @param dictCode 字典编码 |      * @param dictCode 字典编码 | ||||||
|      * @return 字典项列表 |      * @return 字典项列表 | ||||||
|      */ |      */ | ||||||
|     List<LabelValueResp<Serializable>> listByDictCode(@Param("dictCode") String dictCode); |     List<LabelValueResp> listByDictCode(@Param("dictCode") String dictCode); | ||||||
| } | } | ||||||
| @@ -16,15 +16,14 @@ | |||||||
|  |  | ||||||
| package top.continew.admin.system.service; | 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.entity.DictItemDO; | ||||||
| import top.continew.admin.system.model.query.DictItemQuery; | import top.continew.admin.system.model.query.DictItemQuery; | ||||||
| import top.continew.admin.system.model.req.DictItemReq; | import top.continew.admin.system.model.req.DictItemReq; | ||||||
| import top.continew.admin.system.model.resp.DictItemResp; | import top.continew.admin.system.model.resp.DictItemResp; | ||||||
| import top.continew.starter.data.mybatis.plus.service.IService; | 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 top.continew.starter.extension.crud.service.BaseService; | ||||||
|  |  | ||||||
| import java.io.Serializable; |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -41,7 +40,7 @@ public interface DictItemService extends BaseService<DictItemResp, DictItemResp, | |||||||
|      * @param dictCode 字典编码 |      * @param dictCode 字典编码 | ||||||
|      * @return 字典项列表 |      * @return 字典项列表 | ||||||
|      */ |      */ | ||||||
|     List<LabelValueResp<Serializable>> listByDictCode(String dictCode); |     List<LabelValueResp> listByDictCode(String dictCode); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 根据字典 ID 列表删除 |      * 根据字典 ID 列表删除 | ||||||
|   | |||||||
| @@ -18,7 +18,6 @@ package top.continew.admin.system.service.impl; | |||||||
|  |  | ||||||
| import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||||
| import org.springframework.stereotype.Service; | 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.mapper.DictItemMapper; | ||||||
| import top.continew.admin.system.model.entity.DictItemDO; | import top.continew.admin.system.model.entity.DictItemDO; | ||||||
| import top.continew.admin.system.model.query.DictItemQuery; | import top.continew.admin.system.model.query.DictItemQuery; | ||||||
| @@ -26,9 +25,9 @@ import top.continew.admin.system.model.req.DictItemReq; | |||||||
| import top.continew.admin.system.model.resp.DictItemResp; | import top.continew.admin.system.model.resp.DictItemResp; | ||||||
| import top.continew.admin.system.service.DictItemService; | import top.continew.admin.system.service.DictItemService; | ||||||
| import top.continew.starter.core.util.validate.CheckUtils; | 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 top.continew.starter.extension.crud.service.impl.BaseServiceImpl; | ||||||
|  |  | ||||||
| import java.io.Serializable; |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -54,7 +53,7 @@ public class DictItemServiceImpl extends BaseServiceImpl<DictItemMapper, DictIte | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public List<LabelValueResp<Serializable>> listByDictCode(String dictCode) { |     public List<LabelValueResp> listByDictCode(String dictCode) { | ||||||
|         return baseMapper.listByDictCode(dictCode); |         return baseMapper.listByDictCode(dictCode); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -58,7 +58,6 @@ public class OptionServiceImpl implements OptionService { | |||||||
|     private final OptionMapper baseMapper; |     private final OptionMapper baseMapper; | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Cached(key = "#query.category", name = CacheConstants.OPTION_KEY_PREFIX) |  | ||||||
|     public List<OptionResp> list(OptionQuery query) { |     public List<OptionResp> list(OptionQuery query) { | ||||||
|         return BeanUtil.copyToList(baseMapper.selectList(QueryWrapperHelper.build(query)), OptionResp.class); |         return BeanUtil.copyToList(baseMapper.selectList(QueryWrapperHelper.build(query)), OptionResp.class); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,8 +1,8 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8" ?> | <?xml version="1.0" encoding="UTF-8" ?> | ||||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||||||
| <mapper namespace="top.continew.admin.system.mapper.DictItemMapper"> | <mapper namespace="top.continew.admin.system.mapper.DictItemMapper"> | ||||||
|     <select id="listByDictCode" resultType="top.continew.admin.common.model.resp.LabelValueResp"> |     <select id="listByDictCode" resultType="top.continew.starter.extension.crud.model.resp.LabelValueResp"> | ||||||
|         SELECT t1.label, t1.value, t1.color |         SELECT t1.label, t1.value, t1.color AS extend | ||||||
|         FROM sys_dict_item AS t1 |         FROM sys_dict_item AS t1 | ||||||
|         LEFT JOIN sys_dict AS t2 ON t1.dict_id = t2.id |         LEFT JOIN sys_dict AS t2 ON t1.dict_id = t2.id | ||||||
|         WHERE t1.status = 1 AND t2.code = #{dictCode} |         WHERE t1.status = 1 AND t2.code = #{dictCode} | ||||||
|   | |||||||
| @@ -20,17 +20,19 @@ import cn.dev33.satoken.annotation.SaIgnore; | |||||||
| import cn.hutool.core.lang.tree.Tree; | import cn.hutool.core.lang.tree.Tree; | ||||||
| import cn.hutool.core.util.ClassUtil; | import cn.hutool.core.util.ClassUtil; | ||||||
| import cn.hutool.core.util.StrUtil; | 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.Operation; | ||||||
| import io.swagger.v3.oas.annotations.Parameter; | import io.swagger.v3.oas.annotations.Parameter; | ||||||
| import io.swagger.v3.oas.annotations.enums.ParameterIn; | import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||||||
| import io.swagger.v3.oas.annotations.tags.Tag; | import io.swagger.v3.oas.annotations.tags.Tag; | ||||||
|  | import jakarta.validation.constraints.NotBlank; | ||||||
| import jakarta.validation.constraints.NotNull; | import jakarta.validation.constraints.NotNull; | ||||||
| import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||||
| import org.dromara.x.file.storage.core.FileInfo; | import org.dromara.x.file.storage.core.FileInfo; | ||||||
| import org.springframework.validation.annotation.Validated; | import org.springframework.validation.annotation.Validated; | ||||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||||
| import org.springframework.web.multipart.MultipartFile; | 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.DeptQuery; | ||||||
| import top.continew.admin.system.model.query.MenuQuery; | import top.continew.admin.system.model.query.MenuQuery; | ||||||
| import top.continew.admin.system.model.query.OptionQuery; | import top.continew.admin.system.model.query.OptionQuery; | ||||||
| @@ -41,10 +43,10 @@ import top.continew.starter.core.autoconfigure.project.ProjectProperties; | |||||||
| import top.continew.starter.core.util.validate.ValidationUtils; | import top.continew.starter.core.util.validate.ValidationUtils; | ||||||
| import top.continew.starter.data.mybatis.plus.base.IBaseEnum; | 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.query.SortQuery; | ||||||
|  | import top.continew.starter.extension.crud.model.resp.LabelValueResp; | ||||||
| import top.continew.starter.log.core.annotation.Log; | import top.continew.starter.log.core.annotation.Log; | ||||||
| import top.continew.starter.web.model.R; | import top.continew.starter.web.model.R; | ||||||
|  |  | ||||||
| import java.io.Serializable; |  | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Optional; | import java.util.Optional; | ||||||
| @@ -95,8 +97,6 @@ public class CommonController { | |||||||
|  |  | ||||||
|     @Operation(summary = "查询角色字典", description = "查询角色字典列表") |     @Operation(summary = "查询角色字典", description = "查询角色字典列表") | ||||||
|     @GetMapping("/dict/role") |     @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) { |     public R<List<LabelValueResp>> listRoleDict(RoleQuery query, SortQuery sortQuery) { | ||||||
|         return R.ok(roleService.listDict(query, sortQuery)); |         return R.ok(roleService.listDict(query, sortQuery)); | ||||||
|     } |     } | ||||||
| @@ -104,7 +104,7 @@ public class CommonController { | |||||||
|     @Operation(summary = "查询字典", description = "查询字典列表") |     @Operation(summary = "查询字典", description = "查询字典列表") | ||||||
|     @Parameter(name = "code", description = "字典编码", example = "notice_type", in = ParameterIn.PATH) |     @Parameter(name = "code", description = "字典编码", example = "notice_type", in = ParameterIn.PATH) | ||||||
|     @GetMapping("/dict/{code}") |     @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); |         Optional<Class<?>> enumClassOptional = this.getEnumClassByName(code); | ||||||
|         return R.ok(enumClassOptional.map(this::listEnumDict).orElseGet(() -> dictItemService.listByDictCode(code))); |         return R.ok(enumClassOptional.map(this::listEnumDict).orElseGet(() -> dictItemService.listByDictCode(code))); | ||||||
|     } |     } | ||||||
| @@ -112,8 +112,11 @@ public class CommonController { | |||||||
|     @SaIgnore |     @SaIgnore | ||||||
|     @Operation(summary = "查询参数字典", description = "查询参数字典") |     @Operation(summary = "查询参数字典", description = "查询参数字典") | ||||||
|     @GetMapping("/dict/option") |     @GetMapping("/dict/option") | ||||||
|     public R<List<LabelValueResp<String>>> listOptionDict(@Validated OptionQuery query) { |     @Cached(key = "#category", name = CacheConstants.OPTION_KEY_PREFIX) | ||||||
|         return R.ok(optionService.list(query) |     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() |             .stream() | ||||||
|             .map(option -> new LabelValueResp<>(option.getCode(), StrUtil.nullToDefault(option.getValue(), option |             .map(option -> new LabelValueResp<>(option.getCode(), StrUtil.nullToDefault(option.getValue(), option | ||||||
|                 .getDefaultValue()))) |                 .getDefaultValue()))) | ||||||
| @@ -140,11 +143,11 @@ public class CommonController { | |||||||
|      * @param enumClass 枚举类型 |      * @param enumClass 枚举类型 | ||||||
|      * @return 枚举字典 |      * @return 枚举字典 | ||||||
|      */ |      */ | ||||||
|     private List<LabelValueResp<Serializable>> listEnumDict(Class<?> enumClass) { |     private List<LabelValueResp> listEnumDict(Class<?> enumClass) { | ||||||
|         Object[] enumConstants = enumClass.getEnumConstants(); |         Object[] enumConstants = enumClass.getEnumConstants(); | ||||||
|         return Arrays.stream(enumConstants).map(e -> { |         return Arrays.stream(enumConstants).map(e -> { | ||||||
|             IBaseEnum baseEnum = (IBaseEnum)e; |             IBaseEnum baseEnum = (IBaseEnum)e; | ||||||
|             return new LabelValueResp<>(baseEnum.getDescription(), baseEnum.getValue(), baseEnum.getColor()); |             return new LabelValueResp(baseEnum.getDescription(), baseEnum.getValue(), baseEnum.getColor()); | ||||||
|         }).toList(); |         }).toList(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -56,7 +56,7 @@ public class OptionController { | |||||||
|  |  | ||||||
|     @Operation(summary = "修改参数", description = "修改参数") |     @Operation(summary = "修改参数", description = "修改参数") | ||||||
|     @SaCheckPermission("system:config:update") |     @SaCheckPermission("system:config:update") | ||||||
|     @PatchMapping |     @PutMapping | ||||||
|     public R<Void> update(@Valid @RequestBody List<OptionReq> options) { |     public R<Void> update(@Valid @RequestBody List<OptionReq> options) { | ||||||
|         baseService.update(options); |         baseService.update(options); | ||||||
|         return R.ok(); |         return R.ok(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user