mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-12 06:57:13 +08:00
refactor: 优化字典管理相关 API
1.合并 DictResp 及 DictDetailResp 2.合并 DictItemResp 及 DictItemDetailResp 3.字典项增加状态 status 字段
This commit is contained in:
@@ -16,14 +16,13 @@
|
||||
|
||||
package top.charles7c.continew.admin.system.model.entity;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import lombok.Data;
|
||||
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.model.entity.BaseDO;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 字典项实体
|
||||
*
|
||||
@@ -62,6 +61,11 @@ public class DictItemDO extends BaseDO {
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private DisEnableStatusEnum status;
|
||||
|
||||
/**
|
||||
* 字典ID
|
||||
*/
|
||||
|
@@ -18,6 +18,8 @@ package top.charles7c.continew.admin.system.model.query;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.charles7c.continew.starter.data.core.annotation.Query;
|
||||
import top.charles7c.continew.starter.data.core.enums.QueryType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -35,6 +37,19 @@ public class DictItemQuery implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 关键词
|
||||
*/
|
||||
@Schema(description = "关键词")
|
||||
@Query(columns = {"label", "description"}, type = QueryType.LIKE)
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态(1:启用;2:禁用)", example = "1")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 字典 ID
|
||||
*/
|
||||
|
@@ -38,10 +38,9 @@ public class DictQuery implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
* 关键词
|
||||
*/
|
||||
@Schema(description = "名称")
|
||||
@Schema(description = "关键词")
|
||||
@Query(columns = {"name", "code", "description"}, type = QueryType.LIKE)
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
}
|
@@ -16,18 +16,17 @@
|
||||
|
||||
package top.charles7c.continew.admin.system.model.req;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.model.req.BaseReq;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 创建或修改字典项信息
|
||||
*
|
||||
@@ -78,6 +77,12 @@ public class DictItemReq extends BaseReq {
|
||||
@Length(max = 200, message = "描述长度不能超过 {max} 个字符")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
||||
private DisEnableStatusEnum status;
|
||||
|
||||
/**
|
||||
* 所属字典
|
||||
*/
|
||||
|
@@ -1,63 +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.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||
|
||||
/**
|
||||
* 字典详情信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/9/11 21:29
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "字典详情信息")
|
||||
public class DictDetailResp extends BaseDetailResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@Schema(description = "名称", example = "公告类型")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@Schema(description = "编码", example = "announcement_type")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", example = "公告类型描述信息")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 是否为系统内置数据
|
||||
*/
|
||||
@Schema(description = "是否为系统内置数据", example = "true")
|
||||
private Boolean isSystem;
|
||||
}
|
@@ -1,98 +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.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||
|
||||
/**
|
||||
* 字典项详情信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/9/11 21:29
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@Schema(description = "字典项详情信息")
|
||||
public class DictItemDetailResp extends BaseDetailResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
@Schema(description = "标签", example = "通知")
|
||||
@ExcelProperty(value = "标签", order = 2)
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
@Schema(description = "值", example = "1")
|
||||
@ExcelProperty(value = "值", order = 3)
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 标签颜色
|
||||
*/
|
||||
@Schema(description = "标签颜色", example = "blue")
|
||||
@ExcelProperty(value = "标签颜色", order = 4)
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
@ExcelProperty(value = "排序", order = 5)
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", example = "通知描述信息")
|
||||
@ExcelProperty(value = "描述", order = 6)
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 字典 ID
|
||||
*/
|
||||
@Schema(description = "字典 ID", example = "1")
|
||||
private Long dictId;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
@Schema(hidden = true)
|
||||
@ExcelProperty(value = "字典名称", order = 7)
|
||||
private String dictName;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
@Schema(hidden = true)
|
||||
@ExcelProperty(value = "字典编码", order = 8)
|
||||
private String dictCode;
|
||||
}
|
@@ -16,13 +16,14 @@
|
||||
|
||||
package top.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.BaseResp;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 字典项信息
|
||||
@@ -32,7 +33,7 @@ import top.charles7c.continew.starter.extension.crud.model.resp.BaseResp;
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "字典项信息")
|
||||
public class DictItemResp extends BaseResp {
|
||||
public class DictItemResp extends BaseDetailResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -56,14 +57,27 @@ public class DictItemResp extends BaseResp {
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "描述", example = "通知描述信息")
|
||||
private String description;
|
||||
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
||||
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class)
|
||||
private DisEnableStatusEnum status;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述", example = "通知描述信息")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 字典 ID
|
||||
*/
|
||||
@Schema(description = "字典 ID", example = "1")
|
||||
private Long dictId;
|
||||
}
|
@@ -16,13 +16,11 @@
|
||||
|
||||
package top.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.BaseResp;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 字典信息
|
||||
@@ -32,7 +30,7 @@ import top.charles7c.continew.starter.extension.crud.model.resp.BaseResp;
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "字典信息")
|
||||
public class DictResp extends BaseResp {
|
||||
public class DictResp extends BaseDetailResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@@ -20,10 +20,9 @@ import top.charles7c.continew.admin.common.model.resp.LabelValueResp;
|
||||
import top.charles7c.continew.admin.system.model.entity.DictItemDO;
|
||||
import top.charles7c.continew.admin.system.model.query.DictItemQuery;
|
||||
import top.charles7c.continew.admin.system.model.req.DictItemReq;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictItemDetailResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictItemResp;
|
||||
import top.charles7c.continew.starter.extension.crud.service.BaseService;
|
||||
import top.charles7c.continew.starter.data.mybatis.plus.service.IService;
|
||||
import top.charles7c.continew.starter.extension.crud.service.BaseService;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@@ -34,15 +33,7 @@ import java.util.List;
|
||||
* @author Charles7c
|
||||
* @since 2023/9/11 21:29
|
||||
*/
|
||||
public interface DictItemService extends BaseService<DictItemResp, DictItemDetailResp, DictItemQuery, DictItemReq>, IService<DictItemDO> {
|
||||
|
||||
/**
|
||||
* 根据字典 ID 查询
|
||||
*
|
||||
* @param dictId 字典 ID
|
||||
* @return 字典项列表
|
||||
*/
|
||||
List<DictItemDetailResp> listByDictId(Long dictId);
|
||||
public interface DictItemService extends BaseService<DictItemResp, DictItemResp, DictItemQuery, DictItemReq>, IService<DictItemDO> {
|
||||
|
||||
/**
|
||||
* 根据字典编码查询
|
||||
|
@@ -19,10 +19,9 @@ package top.charles7c.continew.admin.system.service;
|
||||
import top.charles7c.continew.admin.system.model.entity.DictDO;
|
||||
import top.charles7c.continew.admin.system.model.query.DictQuery;
|
||||
import top.charles7c.continew.admin.system.model.req.DictReq;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictDetailResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictResp;
|
||||
import top.charles7c.continew.starter.extension.crud.service.BaseService;
|
||||
import top.charles7c.continew.starter.data.mybatis.plus.service.IService;
|
||||
import top.charles7c.continew.starter.extension.crud.service.BaseService;
|
||||
|
||||
/**
|
||||
* 字典业务接口
|
||||
@@ -30,4 +29,4 @@ import top.charles7c.continew.starter.data.mybatis.plus.service.IService;
|
||||
* @author Charles7c
|
||||
* @since 2023/9/11 21:29
|
||||
*/
|
||||
public interface DictService extends BaseService<DictResp, DictDetailResp, DictQuery, DictReq>, IService<DictDO> {}
|
||||
public interface DictService extends BaseService<DictResp, DictResp, DictQuery, DictReq>, IService<DictDO> {}
|
@@ -23,12 +23,10 @@ import top.charles7c.continew.admin.system.mapper.DictItemMapper;
|
||||
import top.charles7c.continew.admin.system.model.entity.DictItemDO;
|
||||
import top.charles7c.continew.admin.system.model.query.DictItemQuery;
|
||||
import top.charles7c.continew.admin.system.model.req.DictItemReq;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictItemDetailResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictItemResp;
|
||||
import top.charles7c.continew.admin.system.service.DictItemService;
|
||||
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
|
||||
import top.charles7c.continew.starter.extension.crud.service.impl.BaseServiceImpl;
|
||||
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@@ -41,7 +39,7 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DictItemServiceImpl extends BaseServiceImpl<DictItemMapper, DictItemDO, DictItemResp, DictItemDetailResp, DictItemQuery, DictItemReq> implements DictItemService {
|
||||
public class DictItemServiceImpl extends BaseServiceImpl<DictItemMapper, DictItemDO, DictItemResp, DictItemResp, DictItemQuery, DictItemReq> implements DictItemService {
|
||||
|
||||
@Override
|
||||
protected void beforeAdd(DictItemReq req) {
|
||||
@@ -55,17 +53,6 @@ public class DictItemServiceImpl extends BaseServiceImpl<DictItemMapper, DictIte
|
||||
CheckUtils.throwIf(this.isValueExists(value, id, req.getDictId()), "修改失败,字典值 [{}] 已存在", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictItemDetailResp> listByDictId(Long dictId) {
|
||||
DictItemQuery dictItemQuery = new DictItemQuery();
|
||||
dictItemQuery.setDictId(dictId);
|
||||
SortQuery sortQuery = new SortQuery();
|
||||
sortQuery.setSort(new String[] {"sort,asc"});
|
||||
List<DictItemDetailResp> detailList = super.list(dictItemQuery, sortQuery, DictItemDetailResp.class);
|
||||
detailList.forEach(super::fill);
|
||||
return detailList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LabelValueResp<Serializable>> listByDictCode(String dictCode) {
|
||||
return baseMapper.listByDictCode(dictCode);
|
||||
|
@@ -16,24 +16,18 @@
|
||||
|
||||
package top.charles7c.continew.admin.system.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.charles7c.continew.admin.system.mapper.DictMapper;
|
||||
import top.charles7c.continew.admin.system.model.entity.DictDO;
|
||||
import top.charles7c.continew.admin.system.model.query.DictQuery;
|
||||
import top.charles7c.continew.admin.system.model.req.DictReq;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictDetailResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictItemDetailResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DictResp;
|
||||
import top.charles7c.continew.admin.system.service.DictItemService;
|
||||
import top.charles7c.continew.admin.system.service.DictService;
|
||||
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
|
||||
import top.charles7c.continew.starter.extension.crud.service.impl.BaseServiceImpl;
|
||||
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
||||
import top.charles7c.continew.starter.file.excel.util.ExcelUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -45,7 +39,7 @@ import java.util.Optional;
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DictServiceImpl extends BaseServiceImpl<DictMapper, DictDO, DictResp, DictDetailResp, DictQuery, DictReq> implements DictService {
|
||||
public class DictServiceImpl extends BaseServiceImpl<DictMapper, DictDO, DictResp, DictResp, DictQuery, DictReq> implements DictService {
|
||||
|
||||
private final DictItemService dictItemService;
|
||||
|
||||
@@ -64,7 +58,7 @@ public class DictServiceImpl extends BaseServiceImpl<DictMapper, DictDO, DictRes
|
||||
String code = req.getCode();
|
||||
CheckUtils.throwIf(this.isCodeExists(code, id), "修改失败,[{}] 已存在", code);
|
||||
DictDO oldDict = super.getById(id);
|
||||
if (oldDict.getIsSystem()) {
|
||||
if (Boolean.TRUE.equals(oldDict.getIsSystem())) {
|
||||
CheckUtils.throwIfNotEqual(req.getCode(), oldDict.getCode(), "[{}] 是系统内置字典,不允许修改字典编码", oldDict.getName());
|
||||
}
|
||||
}
|
||||
@@ -81,21 +75,6 @@ public class DictServiceImpl extends BaseServiceImpl<DictMapper, DictDO, DictRes
|
||||
dictItemService.deleteByDictIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export(DictQuery query, SortQuery sortQuery, HttpServletResponse response) {
|
||||
List<DictResp> dictList = this.list(query, sortQuery);
|
||||
List<DictItemDetailResp> dictItemList = new ArrayList<>();
|
||||
for (DictResp dict : dictList) {
|
||||
List<DictItemDetailResp> tempDictItemList = dictItemService.listByDictId(dict.getId());
|
||||
for (DictItemDetailResp dictItem : tempDictItemList) {
|
||||
dictItem.setDictName(dict.getName());
|
||||
dictItem.setDictCode(dict.getCode());
|
||||
dictItemList.add(dictItem);
|
||||
}
|
||||
}
|
||||
ExcelUtils.export(dictItemList, "导出数据", DictItemDetailResp.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 名称是否存在
|
||||
*
|
||||
|
Reference in New Issue
Block a user