🔧 简化 dictType 和 dictData 模块的 VO

This commit is contained in:
YunaiV 2023-12-02 18:21:33 +08:00
parent 2802b77148
commit 7b97d1a3e4
29 changed files with 200 additions and 502 deletions

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.system.api.dict;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import cn.iocoder.yudao.module.system.service.dict.DictDataService;
import org.springframework.validation.annotation.Validated;
@ -29,13 +29,13 @@ public class DictDataApiImpl implements DictDataApi {
@Override
public CommonResult<DictDataRespDTO> getDictData(String dictType, String value) {
DictDataDO dictData = dictDataService.getDictData(dictType, value);
return success(DictDataConvert.INSTANCE.convert02(dictData));
return success(BeanUtils.toBean(dictData, DictDataRespDTO.class));
}
@Override
public CommonResult<DictDataRespDTO> parseDictData(String dictType, String label) {
DictDataDO dictData = dictDataService.parseDictData(dictType, label);
return success(DictDataConvert.INSTANCE.convert02(dictData));
return success(BeanUtils.toBean(dictData, DictDataRespDTO.class));
}
}

View File

@ -1,16 +1,20 @@
package cn.iocoder.yudao.module.system.controller.admin.dict;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.*;
import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataRespVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSimpleRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import cn.iocoder.yudao.module.system.service.dict.DictDataService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -36,16 +40,16 @@ public class DictDataController {
@PostMapping("/create")
@Operation(summary = "新增字典数据")
@PreAuthorize("@ss.hasPermission('system:dict:create')")
public CommonResult<Long> createDictData(@Valid @RequestBody DictDataCreateReqVO reqVO) {
Long dictDataId = dictDataService.createDictData(reqVO);
public CommonResult<Long> createDictData(@Valid @RequestBody DictDataSaveReqVO createReqVO) {
Long dictDataId = dictDataService.createDictData(createReqVO);
return success(dictDataId);
}
@PutMapping("/update")
@Operation(summary = "修改字典数据")
@PreAuthorize("@ss.hasPermission('system:dict:update')")
public CommonResult<Boolean> updateDictData(@Valid @RequestBody DictDataUpdateReqVO reqVO) {
dictDataService.updateDictData(reqVO);
public CommonResult<Boolean> updateDictData(@Valid @RequestBody DictDataSaveReqVO updateReqVO) {
dictDataService.updateDictData(updateReqVO);
return success(true);
}
@ -63,14 +67,15 @@ public class DictDataController {
// 无需添加权限认证因为前端全局都需要
public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() {
List<DictDataDO> list = dictDataService.getDictDataList();
return success(DictDataConvert.INSTANCE.convertList(list));
return success(BeanUtils.toBean(list, DictDataSimpleRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "/获得字典类型的分页列表")
@PreAuthorize("@ss.hasPermission('system:dict:query')")
public CommonResult<PageResult<DictDataRespVO>> getDictTypePage(@Valid DictDataPageReqVO reqVO) {
return success(DictDataConvert.INSTANCE.convertPage(dictDataService.getDictDataPage(reqVO)));
public CommonResult<PageResult<DictDataRespVO>> getDictTypePage(@Valid DictDataPageReqVO pageReqVO) {
PageResult<DictDataDO> pageResult = dictDataService.getDictDataPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, DictDataRespVO.class));
}
@GetMapping(value = "/get")
@ -78,18 +83,20 @@ public class DictDataController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:dict:query')")
public CommonResult<DictDataRespVO> getDictData(@RequestParam("id") Long id) {
return success(DictDataConvert.INSTANCE.convert(dictDataService.getDictData(id)));
DictDataDO dictData = dictDataService.getDictData(id);
return success(BeanUtils.toBean(dictData, DictDataRespVO.class));
}
@GetMapping("/export")
@Operation(summary = "导出字典数据")
@PreAuthorize("@ss.hasPermission('system:dict:export')")
@OperateLog(type = EXPORT)
public void export(HttpServletResponse response, @Valid DictDataExportReqVO reqVO) throws IOException {
List<DictDataDO> list = dictDataService.getDictDataList(reqVO);
List<DictDataExcelVO> data = DictDataConvert.INSTANCE.convertList02(list);
public void export(HttpServletResponse response, @Valid DictDataPageReqVO exportReqVO) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<DictDataDO> list = dictDataService.getDictDataPage(exportReqVO).getList();
// 输出
ExcelUtils.write(response, "字典数据.xls", "数据列表", DictDataExcelVO.class, data);
ExcelUtils.write(response, "字典数据.xls", "数据", DictDataRespVO.class,
BeanUtils.toBean(list, DictDataRespVO.class));
}
}

View File

@ -1,16 +1,20 @@
package cn.iocoder.yudao.module.system.controller.admin.dict;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.*;
import cn.iocoder.yudao.module.system.convert.dict.DictTypeConvert;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeRespVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSimpleRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import cn.iocoder.yudao.module.system.service.dict.DictTypeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -36,16 +40,16 @@ public class DictTypeController {
@PostMapping("/create")
@Operation(summary = "创建字典类型")
@PreAuthorize("@ss.hasPermission('system:dict:create')")
public CommonResult<Long> createDictType(@Valid @RequestBody DictTypeCreateReqVO reqVO) {
Long dictTypeId = dictTypeService.createDictType(reqVO);
public CommonResult<Long> createDictType(@Valid @RequestBody DictTypeSaveReqVO createReqVO) {
Long dictTypeId = dictTypeService.createDictType(createReqVO);
return success(dictTypeId);
}
@PutMapping("/update")
@Operation(summary = "修改字典类型")
@PreAuthorize("@ss.hasPermission('system:dict:update')")
public CommonResult<Boolean> updateDictType(@Valid @RequestBody DictTypeUpdateReqVO reqVO) {
dictTypeService.updateDictType(reqVO);
public CommonResult<Boolean> updateDictType(@Valid @RequestBody DictTypeSaveReqVO updateReqVO) {
dictTypeService.updateDictType(updateReqVO);
return success(true);
}
@ -58,11 +62,12 @@ public class DictTypeController {
return success(true);
}
@Operation(summary = "/获得字典类型的分页列表")
@GetMapping("/page")
@Operation(summary = "获得字典类型的分页列表")
@PreAuthorize("@ss.hasPermission('system:dict:query')")
public CommonResult<PageResult<DictTypeRespVO>> pageDictTypes(@Valid DictTypePageReqVO reqVO) {
return success(DictTypeConvert.INSTANCE.convertPage(dictTypeService.getDictTypePage(reqVO)));
public CommonResult<PageResult<DictTypeRespVO>> pageDictTypes(@Valid DictTypePageReqVO pageReqVO) {
PageResult<DictTypeDO> pageResult = dictTypeService.getDictTypePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, DictTypeRespVO.class));
}
@Operation(summary = "/查询字典类型详细")
@ -70,26 +75,28 @@ public class DictTypeController {
@GetMapping(value = "/get")
@PreAuthorize("@ss.hasPermission('system:dict:query')")
public CommonResult<DictTypeRespVO> getDictType(@RequestParam("id") Long id) {
return success(DictTypeConvert.INSTANCE.convert(dictTypeService.getDictType(id)));
DictTypeDO dictType = dictTypeService.getDictType(id);
return success(BeanUtils.toBean(dictType, DictTypeRespVO.class));
}
@GetMapping("/list-all-simple")
@GetMapping(value = {"/list-all-simple", "simple-list"})
@Operation(summary = "获得全部字典类型列表", description = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项")
// 无需添加权限认证因为前端全局都需要
public CommonResult<List<DictTypeSimpleRespVO>> getSimpleDictTypeList() {
List<DictTypeDO> list = dictTypeService.getDictTypeList();
return success(DictTypeConvert.INSTANCE.convertList(list));
return success(BeanUtils.toBean(list, DictTypeSimpleRespVO.class));
}
@Operation(summary = "导出数据类型")
@GetMapping("/export")
@PreAuthorize("@ss.hasPermission('system:dict:query')")
@OperateLog(type = EXPORT)
public void export(HttpServletResponse response, @Valid DictTypeExportReqVO reqVO) throws IOException {
List<DictTypeDO> list = dictTypeService.getDictTypeList(reqVO);
List<DictTypeExcelVO> data = DictTypeConvert.INSTANCE.convertList02(list);
// 输出
ExcelUtils.write(response, "字典类型.xls", "类型列表", DictTypeExcelVO.class, data);
public void export(HttpServletResponse response, @Valid DictTypePageReqVO exportReqVO) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<DictTypeDO> list = dictTypeService.getDictTypePage(exportReqVO).getList();
// 导出
ExcelUtils.write(response, "字典类型.xls", "数据", DictTypeRespVO.class,
BeanUtils.toBean(list, DictTypeRespVO.class));
}
}

View File

@ -1,12 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Schema(description = "管理后台 - 字典数据创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class DictDataCreateReqVO extends DictDataBaseVO {
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* 字典数据 Excel 导出响应 VO
*/
@Data
public class DictDataExcelVO {
@ExcelProperty("字典编码")
private Long id;
@ExcelProperty("字典排序")
private Integer sort;
@ExcelProperty("字典标签")
private String label;
@ExcelProperty("字典键值")
private String value;
@ExcelProperty("字典类型")
private String dictType;
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
}

View File

@ -1,23 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.Size;
@Schema(description = "管理后台 - 字典类型导出 Request VO")
@Data
public class DictDataExportReqVO {
@Schema(description = "字典标签", example = "芋道")
@Size(max = 100, message = "字典标签长度不能超过100个字符")
private String label;
@Schema(description = "字典类型,模糊匹配", example = "sys_common_sex")
@Size(max = 100, message = "字典类型类型长度不能超过100个字符")
private String dictType;
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
private Integer status;
}

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -21,6 +23,7 @@ public class DictDataPageReqVO extends PageParam {
private String dictType;
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}
}

View File

@ -1,23 +1,54 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 字典数据信息 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class DictDataRespVO extends DictDataBaseVO {
@ExcelIgnoreUnannotated
public class DictDataRespVO {
@Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("字典编码")
private Long id;
@Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("字典排序")
private Integer sort;
@Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
@ExcelProperty("字典标签")
private String label;
@Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder")
@ExcelProperty("字典键值")
private String value;
@Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
@ExcelProperty("字典类型")
private String dictType;
@Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
@Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default")
private String colorType;
@Schema(description = "css 样式", example = "btn-visible")
private String cssClass;
@Schema(description = "备注", example = "我是一个角色")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
private LocalDateTime createTime;

View File

@ -9,12 +9,12 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* 字典数据 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Schema(description = "管理后台 - 字典数据创建/修改 Request VO")
@Data
public class DictDataBaseVO {
public class DictDataSaveReqVO {
@Schema(description = "字典数据编号", example = "1024")
private Long id;
@Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "显示顺序不能为空")
@ -37,11 +37,12 @@ public class DictDataBaseVO {
@Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
@Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default")
private String colorType;
@Schema(description = "css 样式", example = "btn-visible")
private String cssClass;

View File

@ -1,18 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 字典数据更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class DictDataUpdateReqVO extends DictDataBaseVO {
@Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "字典数据编号不能为空")
private Long id;
}

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@Schema(description = "管理后台 - 字典类型创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class DictTypeCreateReqVO extends DictTypeBaseVO {
@Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
@NotNull(message = "字典类型不能为空")
@Size(max = 100, message = "字典类型类型长度不能超过100个字符")
private String type;
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* 字典类型 Excel 导出响应 VO
*/
@Data
public class DictTypeExcelVO {
@ExcelProperty("字典主键")
private Long id;
@ExcelProperty("字典名称")
private String name;
@ExcelProperty("字典类型")
private String type;
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 字典类型分页列表 Request VO")
@Data
public class DictTypeExportReqVO {
@Schema(description = "字典类型名称,模糊匹配", example = "芋道")
private String name;
@Schema(description = "字典类型,模糊匹配", example = "sys_common_sex")
private String type;
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@Schema(description = "创建时间")
private LocalDateTime[] createTime;
}

View File

@ -30,4 +30,4 @@ public class DictTypePageReqVO extends PageParam {
@Schema(description = "创建时间")
private LocalDateTime[] createTime;
}
}

View File

@ -1,26 +1,40 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 字典类型信息 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class DictTypeRespVO extends DictTypeBaseVO {
@ExcelIgnoreUnannotated
public class DictTypeRespVO {
@Schema(description = "字典类型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("字典主键")
private Long id;
@Schema(description = "字典名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "性别")
@ExcelProperty("字典名称")
private String name;
@Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
@ExcelProperty("字典类型")
private String type;
@Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
@Schema(description = "备注", example = "快乐的备注")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
private LocalDateTime createTime;

View File

@ -7,18 +7,23 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* 字典类型 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Schema(description = "管理后台 - 字典类型创建/修改 Request VO")
@Data
public class DictTypeBaseVO {
public class DictTypeSaveReqVO {
@Schema(description = "字典类型编号", example = "1024")
private Long id;
@Schema(description = "字典名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "性别")
@NotBlank(message = "字典名称不能为空")
@Size(max = 100, message = "字典类型名称长度不能超过100个字符")
private String name;
@Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
@NotNull(message = "字典类型不能为空")
@Size(max = 100, message = "字典类型类型长度不能超过 100 个字符")
private String type;
@Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
private Integer status;

View File

@ -1,14 +1,10 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Schema(description = "管理后台 - 字典类型精简信息 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DictTypeSimpleRespVO {
@Schema(description = "字典类型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")

View File

@ -1,18 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 字典类型更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class DictTypeUpdateReqVO extends DictTypeBaseVO {
@Schema(description = "字典类型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "字典类型编号不能为空")
private Long id;
}

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.system.controller.app.dict;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO;
import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import cn.iocoder.yudao.module.system.service.dict.DictDataService;
import io.swagger.v3.oas.annotations.Operation;
@ -33,7 +33,7 @@ public class AppDictDataController {
@Parameter(name = "type", description = "字典类型", required = true, example = "common_status")
public CommonResult<List<AppDictDataRespVO>> getDictDataListByType(@RequestParam("type") String type) {
List<DictDataDO> list = dictDataService.getEnabledDictDataListByType(type);
return success(DictDataConvert.INSTANCE.convertList03(list));
return success(BeanUtils.toBean(list, AppDictDataRespVO.class));
}
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.system.convert.dict;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.*;
import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface DictDataConvert {
DictDataConvert INSTANCE = Mappers.getMapper(DictDataConvert.class);
List<DictDataSimpleRespVO> convertList(List<DictDataDO> list);
DictDataRespVO convert(DictDataDO bean);
PageResult<DictDataRespVO> convertPage(PageResult<DictDataDO> page);
DictDataDO convert(DictDataUpdateReqVO bean);
DictDataDO convert(DictDataCreateReqVO bean);
List<DictDataExcelVO> convertList02(List<DictDataDO> bean);
DictDataRespDTO convert02(DictDataDO bean);
List<AppDictDataRespVO> convertList03(List<DictDataDO> list);
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.module.system.convert.dict;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.*;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface DictTypeConvert {
DictTypeConvert INSTANCE = Mappers.getMapper(DictTypeConvert.class);
PageResult<DictTypeRespVO> convertPage(PageResult<DictTypeDO> bean);
DictTypeRespVO convert(DictTypeDO bean);
DictTypeDO convert(DictTypeCreateReqVO bean);
DictTypeDO convert(DictTypeUpdateReqVO bean);
List<DictTypeSimpleRespVO> convertList(List<DictTypeDO> list);
List<DictTypeExcelVO> convertList02(List<DictTypeDO> list);
}

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.dict;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -41,13 +40,6 @@ public interface DictDataMapper extends BaseMapperX<DictDataDO> {
.orderByDesc(Arrays.asList(DictDataDO::getDictType, DictDataDO::getSort)));
}
default List<DictDataDO> selectList(DictDataExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<DictDataDO>()
.likeIfPresent(DictDataDO::getLabel, reqVO.getLabel())
.eqIfPresent(DictDataDO::getDictType, reqVO.getDictType())
.eqIfPresent(DictDataDO::getStatus, reqVO.getStatus()));
}
default List<DictDataDO> selectListByTypeAndStatus(String dictType, Integer status) {
return selectList(new LambdaQueryWrapper<DictDataDO>()
.eq(DictDataDO::getDictType, dictType)

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.dict;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import org.apache.ibatis.annotations.Mapper;
@ -11,7 +10,6 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime;
import java.util.List;
@Mapper
public interface DictTypeMapper extends BaseMapperX<DictTypeDO> {
@ -25,14 +23,6 @@ public interface DictTypeMapper extends BaseMapperX<DictTypeDO> {
.orderByDesc(DictTypeDO::getId));
}
default List<DictTypeDO> selectList(DictTypeExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<DictTypeDO>()
.likeIfPresent(DictTypeDO::getName, reqVO.getName())
.likeIfPresent(DictTypeDO::getType, reqVO.getType())
.eqIfPresent(DictTypeDO::getStatus, reqVO.getStatus())
.betweenIfPresent(DictTypeDO::getCreateTime, reqVO.getCreateTime()));
}
default DictTypeDO selectByType(String type) {
return selectOne(DictTypeDO::getType, type);
}
@ -41,8 +31,7 @@ public interface DictTypeMapper extends BaseMapperX<DictTypeDO> {
return selectOne(DictTypeDO::getName, name);
}
int deleteById(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
@Update("UPDATE system_dict_type SET deleted = 1, deleted_time = #{deletedTime} WHERE id = #{id}")
void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}

View File

@ -1,10 +1,8 @@
package cn.iocoder.yudao.module.system.service.dict;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import java.util.Collection;
@ -20,17 +18,17 @@ public interface DictDataService {
/**
* 创建字典数据
*
* @param reqVO 字典数据信息
* @param createReqVO 字典数据信息
* @return 字典数据编号
*/
Long createDictData(DictDataCreateReqVO reqVO);
Long createDictData(DictDataSaveReqVO createReqVO);
/**
* 更新字典数据
*
* @param reqVO 字典数据信息
* @param updateReqVO 字典数据信息
*/
void updateDictData(DictDataUpdateReqVO reqVO);
void updateDictData(DictDataSaveReqVO updateReqVO);
/**
* 删除字典数据
@ -49,18 +47,10 @@ public interface DictDataService {
/**
* 获得字典数据分页列表
*
* @param reqVO 分页请求
* @param pageReqVO 分页请求
* @return 字典数据分页列表
*/
PageResult<DictDataDO> getDictDataPage(DictDataPageReqVO reqVO);
/**
* 获得字典数据列表
*
* @param reqVO 列表请求
* @return 字典数据列表
*/
List<DictDataDO> getDictDataList(DictDataExportReqVO reqVO);
PageResult<DictDataDO> getDictDataPage(DictDataPageReqVO pageReqVO);
/**
* 获得字典数据列表

View File

@ -4,11 +4,9 @@ import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import cn.iocoder.yudao.module.system.dal.mysql.dict.DictDataMapper;
@ -55,15 +53,8 @@ public class DictDataServiceImpl implements DictDataService {
}
@Override
public PageResult<DictDataDO> getDictDataPage(DictDataPageReqVO reqVO) {
return dictDataMapper.selectPage(reqVO);
}
@Override
public List<DictDataDO> getDictDataList(DictDataExportReqVO reqVO) {
List<DictDataDO> list = dictDataMapper.selectList(reqVO);
list.sort(COMPARATOR_TYPE_AND_SORT);
return list;
public PageResult<DictDataDO> getDictDataPage(DictDataPageReqVO pageReqVO) {
return dictDataMapper.selectPage(pageReqVO);
}
@Override
@ -79,23 +70,29 @@ public class DictDataServiceImpl implements DictDataService {
}
@Override
public Long createDictData(DictDataCreateReqVO reqVO) {
// 校验正确性
validateDictDataForCreateOrUpdate(null, reqVO.getValue(), reqVO.getDictType());
public Long createDictData(DictDataSaveReqVO createReqVO) {
// 校验字典类型有效
validateDictTypeExists(createReqVO.getDictType());
// 校验字典数据的值的唯一性
validateDictDataValueUnique(null, createReqVO.getDictType(), createReqVO.getValue());
// 插入字典类型
DictDataDO dictData = DictDataConvert.INSTANCE.convert(reqVO);
DictDataDO dictData = BeanUtils.toBean(createReqVO, DictDataDO.class);
dictDataMapper.insert(dictData);
return dictData.getId();
}
@Override
public void updateDictData(DictDataUpdateReqVO reqVO) {
// 校验正确性
validateDictDataForCreateOrUpdate(reqVO.getId(), reqVO.getValue(), reqVO.getDictType());
public void updateDictData(DictDataSaveReqVO updateReqVO) {
// 校验自己存在
validateDictDataExists(updateReqVO.getId());
// 校验字典类型有效
validateDictTypeExists(updateReqVO.getDictType());
// 校验字典数据的值的唯一性
validateDictDataValueUnique(updateReqVO.getId(), updateReqVO.getDictType(), updateReqVO.getValue());
// 更新字典类型
DictDataDO updateObj = DictDataConvert.INSTANCE.convert(reqVO);
DictDataDO updateObj = BeanUtils.toBean(updateReqVO, DictDataDO.class);
dictDataMapper.updateById(updateObj);
}
@ -113,15 +110,6 @@ public class DictDataServiceImpl implements DictDataService {
return dictDataMapper.selectCountByDictType(dictType);
}
private void validateDictDataForCreateOrUpdate(Long id, String value, String dictType) {
// 校验自己存在
validateDictDataExists(id);
// 校验字典类型有效
validateDictTypeExists(dictType);
// 校验字典数据的值的唯一性
validateDictDataValueUnique(id, dictType, value);
}
@VisibleForTesting
public void validateDictDataValueUnique(Long id, String dictType, String value) {
DictDataDO dictData = dictDataMapper.selectByDictTypeAndValue(dictType, value);

View File

@ -1,10 +1,8 @@
package cn.iocoder.yudao.module.system.service.dict;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import java.util.List;
@ -19,17 +17,17 @@ public interface DictTypeService {
/**
* 创建字典类型
*
* @param reqVO 字典类型信息
* @param createReqVO 字典类型信息
* @return 字典类型编号
*/
Long createDictType(DictTypeCreateReqVO reqVO);
Long createDictType(DictTypeSaveReqVO createReqVO);
/**
* 更新字典类型
*
* @param reqVO 字典类型信息
* @param updateReqVO 字典类型信息
*/
void updateDictType(DictTypeUpdateReqVO reqVO);
void updateDictType(DictTypeSaveReqVO updateReqVO);
/**
* 删除字典类型
@ -41,18 +39,10 @@ public interface DictTypeService {
/**
* 获得字典类型分页列表
*
* @param reqVO 分页请求
* @param pageReqVO 分页请求
* @return 字典类型分页列表
*/
PageResult<DictTypeDO> getDictTypePage(DictTypePageReqVO reqVO);
/**
* 获得字典类型列表
*
* @param reqVO 列表请求
* @return 字典类型列表
*/
List<DictTypeDO> getDictTypeList(DictTypeExportReqVO reqVO);
PageResult<DictTypeDO> getDictTypePage(DictTypePageReqVO pageReqVO);
/**
* 获得字典类型详情

View File

@ -3,11 +3,9 @@ package cn.iocoder.yudao.module.system.service.dict;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.dict.DictTypeConvert;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper;
import com.google.common.annotations.VisibleForTesting;
@ -35,13 +33,8 @@ public class DictTypeServiceImpl implements DictTypeService {
private DictTypeMapper dictTypeMapper;
@Override
public PageResult<DictTypeDO> getDictTypePage(DictTypePageReqVO reqVO) {
return dictTypeMapper.selectPage(reqVO);
}
@Override
public List<DictTypeDO> getDictTypeList(DictTypeExportReqVO reqVO) {
return dictTypeMapper.selectList(reqVO);
public PageResult<DictTypeDO> getDictTypePage(DictTypePageReqVO pageReqVO) {
return dictTypeMapper.selectPage(pageReqVO);
}
@Override
@ -55,24 +48,30 @@ public class DictTypeServiceImpl implements DictTypeService {
}
@Override
public Long createDictType(DictTypeCreateReqVO reqVO) {
// 校验正确性
validateDictTypeForCreateOrUpdate(null, reqVO.getName(), reqVO.getType());
public Long createDictType(DictTypeSaveReqVO createReqVO) {
// 校验字典类型的名字的唯一性
validateDictTypeNameUnique(null, createReqVO.getName());
// 校验字典类型的类型的唯一性
validateDictTypeUnique(null, createReqVO.getType());
// 插入字典类型
DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO)
.setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引避免 null
DictTypeDO dictType = BeanUtils.toBean(createReqVO, DictTypeDO.class);
dictType.setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引避免 null
dictTypeMapper.insert(dictType);
return dictType.getId();
}
@Override
public void updateDictType(DictTypeUpdateReqVO reqVO) {
// 校验正确性
validateDictTypeForCreateOrUpdate(reqVO.getId(), reqVO.getName(), null);
public void updateDictType(DictTypeSaveReqVO updateReqVO) {
// 校验自己存在
validateDictTypeExists(updateReqVO.getId());
// 校验字典类型的名字的唯一性
validateDictTypeNameUnique(updateReqVO.getId(), updateReqVO.getName());
// 校验字典类型的类型的唯一性
validateDictTypeUnique(updateReqVO.getId(), updateReqVO.getType());
// 更新字典类型
DictTypeDO updateObj = DictTypeConvert.INSTANCE.convert(reqVO);
DictTypeDO updateObj = BeanUtils.toBean(updateReqVO, DictTypeDO.class);
dictTypeMapper.updateById(updateObj);
}
@ -93,15 +92,6 @@ public class DictTypeServiceImpl implements DictTypeService {
return dictTypeMapper.selectList();
}
private void validateDictTypeForCreateOrUpdate(Long id, String name, String type) {
// 校验自己存在
validateDictTypeExists(id);
// 校验字典类型的名字的唯一性
validateDictTypeNameUnique(id, name);
// 校验字典类型的类型的唯一性
validateDictTypeUnique(id, type);
}
@VisibleForTesting
void validateDictTypeNameUnique(Long id, String name) {
DictTypeDO dictType = dictTypeMapper.selectByName(name);

View File

@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import cn.iocoder.yudao.module.system.dal.mysql.dict.DictDataMapper;
@ -91,34 +89,6 @@ public class DictDataServiceImplTest extends BaseDbUnitTest {
assertPojoEquals(dbDictData, pageResult.getList().get(0));
}
@Test
public void testGetDictDataList_export() {
// mock 数据
DictDataDO dbDictData = randomPojo(DictDataDO.class, o -> { // 等会查询到
o.setLabel("芋艿");
o.setDictType("yunai");
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
});
dictDataMapper.insert(dbDictData);
// 测试 label 不匹配
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setLabel("")));
// 测试 dictType 不匹配
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setDictType("nai")));
// 测试 status 不匹配
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
// 准备参数
DictDataExportReqVO reqVO = new DictDataExportReqVO();
reqVO.setLabel("");
reqVO.setDictType("yunai");
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
// 调用
List<DictDataDO> list = dictDataService.getDictDataList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbDictData, list.get(0));
}
@Test
public void testGetDictData() {
// mock 数据
@ -136,8 +106,9 @@ public class DictDataServiceImplTest extends BaseDbUnitTest {
@Test
public void testCreateDictData_success() {
// 准备参数
DictDataCreateReqVO reqVO = randomPojo(DictDataCreateReqVO.class,
o -> o.setStatus(randomCommonStatus()));
DictDataSaveReqVO reqVO = randomPojo(DictDataSaveReqVO.class,
o -> o.setStatus(randomCommonStatus()))
.setId(null); // 防止 id 被赋值
// mock 方法
when(dictTypeService.getDictType(eq(reqVO.getDictType()))).thenReturn(randomDictTypeDO(reqVO.getDictType()));
@ -147,7 +118,7 @@ public class DictDataServiceImplTest extends BaseDbUnitTest {
assertNotNull(dictDataId);
// 校验记录的属性是否正确
DictDataDO dictData = dictDataMapper.selectById(dictDataId);
assertPojoEquals(reqVO, dictData);
assertPojoEquals(reqVO, dictData, "id");
}
@Test
@ -156,7 +127,7 @@ public class DictDataServiceImplTest extends BaseDbUnitTest {
DictDataDO dbDictData = randomDictDataDO();
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
// 准备参数
DictDataUpdateReqVO reqVO = randomPojo(DictDataUpdateReqVO.class, o -> {
DictDataSaveReqVO reqVO = randomPojo(DictDataSaveReqVO.class, o -> {
o.setId(dbDictData.getId()); // 设置更新的 ID
o.setStatus(randomCommonStatus());
});

View File

@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper;
import org.junit.jupiter.api.Test;
@ -74,38 +72,6 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest {
assertPojoEquals(dbDictType, pageResult.getList().get(0));
}
@Test
public void testGetDictTypeList_export() {
// mock 数据
DictTypeDO dbDictType = randomPojo(DictTypeDO.class, o -> { // 等会查询到
o.setName("yunai");
o.setType("芋艿");
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
o.setCreateTime(buildTime(2021, 1, 15));
});
dictTypeMapper.insert(dbDictType);
// 测试 name 不匹配
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setName("tudou")));
// 测试 type 不匹配
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setType("土豆")));
// 测试 status 不匹配
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
// 测试 createTime 不匹配
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1))));
// 准备参数
DictTypeExportReqVO reqVO = new DictTypeExportReqVO();
reqVO.setName("nai");
reqVO.setType("");
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
reqVO.setCreateTime(buildBetweenTime(2021, 1, 10, 2021, 1, 20));
// 调用
List<DictTypeDO> list = dictTypeService.getDictTypeList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbDictType, list.get(0));
}
@Test
public void testGetDictType_id() {
// mock 数据
@ -139,8 +105,9 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest {
@Test
public void testCreateDictType_success() {
// 准备参数
DictTypeCreateReqVO reqVO = randomPojo(DictTypeCreateReqVO.class,
o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()));
DictTypeSaveReqVO reqVO = randomPojo(DictTypeSaveReqVO.class,
o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()))
.setId(null); // 避免 id 被赋值
// 调用
Long dictTypeId = dictTypeService.createDictType(reqVO);
@ -148,7 +115,7 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest {
assertNotNull(dictTypeId);
// 校验记录的属性是否正确
DictTypeDO dictType = dictTypeMapper.selectById(dictTypeId);
assertPojoEquals(reqVO, dictType);
assertPojoEquals(reqVO, dictType, "id");
}
@Test
@ -157,7 +124,7 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest {
DictTypeDO dbDictType = randomDictTypeDO();
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
// 准备参数
DictTypeUpdateReqVO reqVO = randomPojo(DictTypeUpdateReqVO.class, o -> {
DictTypeSaveReqVO reqVO = randomPojo(DictTypeSaveReqVO.class, o -> {
o.setId(dbDictType.getId()); // 设置更新的 ID
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus());
});