diff --git a/continew-admin-common/src/main/java/top/continew/admin/common/model/resp/LabelValueResp.java b/continew-admin-common/src/main/java/top/continew/admin/common/model/resp/LabelValueResp.java deleted file mode 100644 index f2afb83a..00000000 --- a/continew-admin-common/src/main/java/top/continew/admin/common/model/resp/LabelValueResp.java +++ /dev/null @@ -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 - * @author Charles7c - * @since 2023/2/24 22:02 - */ -@Data -@NoArgsConstructor -@Schema(description = "键值对信息") -public class LabelValueResp 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; - } -} diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/mapper/DictItemMapper.java b/continew-admin-system/src/main/java/top/continew/admin/system/mapper/DictItemMapper.java index 02cfd175..437714ff 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/mapper/DictItemMapper.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/mapper/DictItemMapper.java @@ -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; /** @@ -38,5 +37,5 @@ public interface DictItemMapper extends BaseMapper { * @param dictCode 字典编码 * @return 字典项列表 */ - List> listByDictCode(@Param("dictCode") String dictCode); + List listByDictCode(@Param("dictCode") String dictCode); } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/DictItemService.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/DictItemService.java index c22b45ec..38bb9137 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/DictItemService.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/DictItemService.java @@ -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; /** @@ -41,7 +40,7 @@ public interface DictItemService extends BaseService> listByDictCode(String dictCode); + List listByDictCode(String dictCode); /** * 根据字典 ID 列表删除 diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/DictItemServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/DictItemServiceImpl.java index 609119d5..0bd54ddb 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/DictItemServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/DictItemServiceImpl.java @@ -18,7 +18,6 @@ package top.continew.admin.system.service.impl; 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; @@ -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.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; /** @@ -54,7 +53,7 @@ public class DictItemServiceImpl extends BaseServiceImpl> listByDictCode(String dictCode) { + public List listByDictCode(String dictCode) { return baseMapper.listByDictCode(dictCode); } diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java index 00a56834..d719cf50 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java @@ -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 list(OptionQuery query) { return BeanUtil.copyToList(baseMapper.selectList(QueryWrapperHelper.build(query)), OptionResp.class); } diff --git a/continew-admin-system/src/main/resources/mapper/DictItemMapper.xml b/continew-admin-system/src/main/resources/mapper/DictItemMapper.xml index 96e5aa5a..d6d51aab 100644 --- a/continew-admin-system/src/main/resources/mapper/DictItemMapper.xml +++ b/continew-admin-system/src/main/resources/mapper/DictItemMapper.xml @@ -1,8 +1,8 @@ - + 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} diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/common/CommonController.java b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/common/CommonController.java index 9e8f9955..66818646 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/common/CommonController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/common/CommonController.java @@ -20,17 +20,19 @@ import cn.dev33.satoken.annotation.SaIgnore; 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; @@ -41,10 +43,10 @@ import top.continew.starter.core.autoconfigure.project.ProjectProperties; 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; @@ -95,8 +97,6 @@ public class CommonController { @Operation(summary = "查询角色字典", description = "查询角色字典列表") @GetMapping("/dict/role") - public R>> listRoleDict(RoleQuery query, SortQuery sortQuery) { - return R.ok(roleService.buildDict(roleService.list(query, sortQuery))); public R> listRoleDict(RoleQuery query, SortQuery sortQuery) { return R.ok(roleService.listDict(query, sortQuery)); } @@ -104,7 +104,7 @@ public class CommonController { @Operation(summary = "查询字典", description = "查询字典列表") @Parameter(name = "code", description = "字典编码", example = "notice_type", in = ParameterIn.PATH) @GetMapping("/dict/{code}") - public R>> listDict(@PathVariable String code) { + public R> listDict(@PathVariable String code) { Optional> enumClassOptional = this.getEnumClassByName(code); return R.ok(enumClassOptional.map(this::listEnumDict).orElseGet(() -> dictItemService.listByDictCode(code))); } @@ -112,8 +112,11 @@ public class CommonController { @SaIgnore @Operation(summary = "查询参数字典", description = "查询参数字典") @GetMapping("/dict/option") - public R>> listOptionDict(@Validated OptionQuery query) { - return R.ok(optionService.list(query) + @Cached(key = "#category", name = CacheConstants.OPTION_KEY_PREFIX) + public R>> 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()))) @@ -140,11 +143,11 @@ public class CommonController { * @param enumClass 枚举类型 * @return 枚举字典 */ - private List> listEnumDict(Class enumClass) { + private List 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(); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/OptionController.java b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/OptionController.java index 23623d5c..1961c0f7 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/OptionController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/OptionController.java @@ -56,7 +56,7 @@ public class OptionController { @Operation(summary = "修改参数", description = "修改参数") @SaCheckPermission("system:config:update") - @PatchMapping + @PutMapping public R update(@Valid @RequestBody List options) { baseService.update(options); return R.ok();