From f6bb33863fbd86c010b2851ed1ee6bc87fe10613 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 12 Jan 2021 19:55:07 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=AE=8C=E6=88=90=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=BF=81=E7=A7=BB=202.=20=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=E5=AD=97=E5=85=B8=E6=95=B0=E6=8D=AE=E7=9A=84=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/api/system/dict/type.js | 28 ++-- ruoyi-ui/src/views/system/dict/index.vue | 146 +++++++----------- ruoyi-ui/src/views/system/post/index.vue | 6 - .../dict/SysDictDataController.java | 123 +++++++-------- .../dict/SysDictTypeController.java | 10 +- .../dict/vo/data/SysDictDataBaseVO.java | 44 ++++++ .../dict/vo/data/SysDictDataCreateReqVO.java | 12 ++ .../dict/vo/data/SysDictDataExcelRespVO.java | 30 ++++ .../dict/vo/data/SysDictDataPageReqVO.java | 27 ++++ .../dict/vo/data/SysDictDataRespVO.java | 25 +++ ...SimpleVO.java => SysDictDataSimpleVO.java} | 2 +- .../dict/vo/data/SysDictDataUpdateReqVO.java | 19 +++ .../dict/vo/type/SysDictTypeBaseVO.java | 13 +- .../dict/vo/type/SysDictTypeCreateReqVO.java | 10 ++ .../dict/vo/type/SysDictTypePageReqVO.java | 21 ++- .../dict/vo/type/SysDictTypeRespVO.java | 3 + .../convert/dict/SysDictDataConvert.java | 21 ++- .../convert/dict/SysDictTypeConvert.java | 11 ++ .../dal/mysql/dao/dict/SysDictDataMapper.java | 30 ++++ .../dal/mysql/dao/dict/SysDictTypeMapper.java | 30 ++++ .../mysql/dataobject/dict/SysDictDataDO.java | 18 +-- .../mysql/dataobject/dict/SysDictTypeDO.java | 4 + .../system/enums/SysErrorCodeConstants.java | 16 +- .../service/dict/SysDictDataService.java | 50 ++++++ .../service/dict/SysDictTypeService.java | 40 ++++- .../dict/impl/SysDictDataServiceImpl.java | 101 +++++++++++- .../dict/impl/SysDictTypeServiceImpl.java | 137 ++++++++++++++++ 27 files changed, 754 insertions(+), 223 deletions(-) create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataBaseVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataCreateReqVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataExcelRespVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataPageReqVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataRespVO.java rename src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/{SysDataDictSimpleVO.java => SysDictDataSimpleVO.java} (93%) create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataUpdateReqVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dict/SysDictTypeMapper.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictTypeServiceImpl.java diff --git a/ruoyi-ui/src/api/system/dict/type.js b/ruoyi-ui/src/api/system/dict/type.js index d392f5042..6b20f4e17 100644 --- a/ruoyi-ui/src/api/system/dict/type.js +++ b/ruoyi-ui/src/api/system/dict/type.js @@ -3,7 +3,7 @@ import request from '@/utils/request' // 查询字典类型列表 export function listType(query) { return request({ - url: '/system/dict/type/list', + url: '/system/dict-type/page', method: 'get', params: query }) @@ -12,7 +12,7 @@ export function listType(query) { // 查询字典类型详细 export function getType(dictId) { return request({ - url: '/system/dict/type/' + dictId, + url: '/system/dict-type/get?id=' + dictId, method: 'get' }) } @@ -20,7 +20,7 @@ export function getType(dictId) { // 新增字典类型 export function addType(data) { return request({ - url: '/system/dict/type', + url: '/system/dict-type/create', method: 'post', data: data }) @@ -29,8 +29,8 @@ export function addType(data) { // 修改字典类型 export function updateType(data) { return request({ - url: '/system/dict/type', - method: 'put', + url: '/system/dict-type/update', + method: 'post', data: data }) } @@ -38,23 +38,15 @@ export function updateType(data) { // 删除字典类型 export function delType(dictId) { return request({ - url: '/system/dict/type/' + dictId, - method: 'delete' - }) -} - -// 清理参数缓存 -export function clearCache() { - return request({ - url: '/system/dict/type/clearCache', - method: 'delete' + url: '/system/dict-type/delete?id=' + dictId, + method: 'post' }) } // 导出字典类型 export function exportType(query) { return request({ - url: '/system/dict/type/export', + url: '/system/dict-type/export', method: 'get', params: query }) @@ -63,7 +55,7 @@ export function exportType(query) { // 获取字典选择框列表 export function optionselect() { return request({ - url: '/system/dict/type/optionselect', + url: '/system/dict-type/optionselect', method: 'get' }) -} \ No newline at end of file +} diff --git a/ruoyi-ui/src/views/system/dict/index.vue b/ruoyi-ui/src/views/system/dict/index.vue index c1de85af3..b62360684 100644 --- a/ruoyi-ui/src/views/system/dict/index.vue +++ b/ruoyi-ui/src/views/system/dict/index.vue @@ -1,9 +1,9 @@ \ No newline at end of file + diff --git a/ruoyi-ui/src/views/system/post/index.vue b/ruoyi-ui/src/views/system/post/index.vue index dd9d5d32a..605f35c06 100644 --- a/ruoyi-ui/src/views/system/post/index.vue +++ b/ruoyi-ui/src/views/system/post/index.vue @@ -141,12 +141,6 @@ export default { return { // 遮罩层 loading: true, - // 选中数组 - ids: [], - // 非单个禁用 - single: true, - // 非多个禁用 - multiple: true, // 显示搜索条件 showSearch: true, // 总条数 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java index bc81bfdf1..b34557d97 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java @@ -1,15 +1,16 @@ package cn.iocoder.dashboard.modules.system.controller.dict; import cn.iocoder.dashboard.common.pojo.CommonResult; -import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDataDictSimpleVO; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.*; import cn.iocoder.dashboard.modules.system.convert.dict.SysDictDataConvert; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @@ -27,79 +28,61 @@ public class SysDictDataController { @GetMapping("/list-all-simple") @ApiOperation(value = "获得全部字典数据列表", notes = "一般用于管理后台缓存字典数据在本地") // 无需添加权限认证,因为前端全局都需要 - public CommonResult> listSimpleDictDatas() { + public CommonResult> listSimpleDictDatas() { List list = dictDataService.listDictDatas(); return success(SysDictDataConvert.INSTANCE.convertList(list)); } + @ApiOperation("/获得字典类型的分页列表") + @GetMapping("/page") // @PreAuthorize("@ss.hasPermi('system:dict:list')") -// @GetMapping("/list") -// public TableDataInfo list(SysDictData dictData) { -// startPage(); -// List list = dictDataService.selectDictDataList(dictData); -// return getDataTable(list); -// } -// -// @Log(title = "字典数据", businessType = BusinessType.EXPORT) + public CommonResult> pageDictTypes(@Validated SysDictDataPageReqVO reqVO) { + return success(SysDictDataConvert.INSTANCE.convertPage(dictDataService.pageDictDatas(reqVO))); + } + + @ApiOperation("/查询字典数据详细") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @GetMapping(value = "/get") +// @PreAuthorize("@ss.hasPermi('system:dict:query')") + public CommonResult getDictData(@RequestParam("id") Long id) { + return success(SysDictDataConvert.INSTANCE.convert(dictDataService.getDictData(id))); + } + + @ApiOperation("新增字典数据") + @PostMapping("/create") +// @PreAuthorize("@ss.hasPermi('system:dict:add')") +// @Log(title = "字典数据", businessData = BusinessData.INSERT) + public CommonResult createDictData(@Validated @RequestBody SysDictDataCreateReqVO reqVO) { + Long dictDataId = dictDataService.createDictData(reqVO); + return success(dictDataId); + } + + @ApiOperation("修改字典数据") + @PostMapping("update") +// @PreAuthorize("@ss.hasPermi('system:dict:edit')") +// @Log(title = "字典数据", businessData = BusinessData.UPDATE) + public CommonResult updateDictData(@Validated @RequestBody SysDictDataUpdateReqVO reqVO) { + dictDataService.updateDictData(reqVO); + return success(true); + } + + @ApiOperation("删除字典数据") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @PostMapping("/delete") +// @PreAuthorize("@ss.hasPermi('system:dict:remove')") + public CommonResult deleteDictData(Long id) { + dictDataService.deleteDictData(id); + return success(true); + } + + // +// @Log(title = "字典类型", businessType = BusinessType.EXPORT) // @PreAuthorize("@ss.hasPermi('system:dict:export')") // @GetMapping("/export") -// public AjaxResult export(SysDictData dictData) { -// List list = dictDataService.selectDictDataList(dictData); -// ExcelUtil util = new ExcelUtil(SysDictData.class); -// return util.exportExcel(list, "字典数据"); -// } -// -// /** -// * 查询字典数据详细 -// */ -// @PreAuthorize("@ss.hasPermi('system:dict:query')") -// @GetMapping(value = "/{dictCode}") -// public AjaxResult getInfo(@PathVariable Long dictCode) { -// return AjaxResult.success(dictDataService.selectDictDataById(dictCode)); -// } -// -// /** -// * 根据字典类型查询字典数据信息 -// */ -// @GetMapping(value = "/type/{dictType}") -// public AjaxResult dictType(@PathVariable String dictType) { -// List data = dictTypeService.selectDictDataByType(dictType); -// if (StringUtils.isNull(data)) { -// data = new ArrayList(); -// } -// return AjaxResult.success(data); -// } -// -// /** -// * 新增字典类型 -// */ -// @PreAuthorize("@ss.hasPermi('system:dict:add')") -// @Log(title = "字典数据", businessType = BusinessType.INSERT) -// @PostMapping -// public AjaxResult add(@Validated @RequestBody SysDictData dict) { -// dict.setCreateBy(SecurityUtils.getUsername()); -// return toAjax(dictDataService.insertDictData(dict)); -// } -// -// /** -// * 修改保存字典类型 -// */ -// @PreAuthorize("@ss.hasPermi('system:dict:edit')") -// @Log(title = "字典数据", businessType = BusinessType.UPDATE) -// @PutMapping -// public AjaxResult edit(@Validated @RequestBody SysDictData dict) { -// dict.setUpdateBy(SecurityUtils.getUsername()); -// return toAjax(dictDataService.updateDictData(dict)); -// } -// -// /** -// * 删除字典类型 -// */ -// @PreAuthorize("@ss.hasPermi('system:dict:remove')") -// @Log(title = "字典类型", businessType = BusinessType.DELETE) -// @DeleteMapping("/{dictCodes}") -// public AjaxResult remove(@PathVariable Long[] dictCodes) { -// return toAjax(dictDataService.deleteDictDataByIds(dictCodes)); +// public AjaxResult export(SysDictType dictType) { +// List list = dictTypeService.selectDictTypeList(dictType); +// ExcelUtil util = new ExcelUtil(SysDictType.class); +// return util.exportExcel(list, "字典类型"); // } } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java index f4c077c07..cbfb24fb4 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java @@ -5,7 +5,7 @@ import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypePageReqVO; import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeRespVO; -import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeUpdateReqVO; import cn.iocoder.dashboard.modules.system.convert.dict.SysDictTypeConvert; import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService; import io.swagger.annotations.Api; @@ -26,14 +26,14 @@ public class SysDictTypeController { @Resource private SysDictTypeService dictTypeService; - @ApiOperation("/page") - @GetMapping("/list") + @ApiOperation("/获得字典类型的分页列表") + @GetMapping("/page") // @PreAuthorize("@ss.hasPermi('system:dict:list')") public CommonResult> pageDictTypes(@Validated SysDictTypePageReqVO reqVO) { return success(SysDictTypeConvert.INSTANCE.convertPage(dictTypeService.pageDictTypes(reqVO))); } - @ApiOperation("/查询字典详细") + @ApiOperation("/查询字典类型详细") @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") @GetMapping(value = "/get") // @PreAuthorize("@ss.hasPermi('system:dict:query')") @@ -54,7 +54,7 @@ public class SysDictTypeController { @PostMapping("update") // @PreAuthorize("@ss.hasPermi('system:dict:edit')") // @Log(title = "字典类型", businessType = BusinessType.UPDATE) - public CommonResult updateDictType(@Validated @RequestBody SysUserUpdateReqVO reqVO) { + public CommonResult updateDictType(@Validated @RequestBody SysDictTypeUpdateReqVO reqVO) { dictTypeService.updateDictType(reqVO); return success(true); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataBaseVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataBaseVO.java new file mode 100644 index 000000000..bfcdf570d --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataBaseVO.java @@ -0,0 +1,44 @@ +package cn.iocoder.dashboard.modules.system.controller.dict.vo.data; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * 字典数据 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class SysDictDataBaseVO { + + @ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024") + @NotBlank(message = "显示顺序不能为空") + private String sort; + + @ApiModelProperty(value = "字典标签", required = true, example = "芋道") + @NotBlank(message = "字典标签不能为空") + @Size(max = 100, message = "字典标签长度不能超过100个字符") + private String label; + + @ApiModelProperty(value = "字典值", required = true, example = "iocoder") + @NotBlank(message = "字典键值不能为空") + @Size(max = 100, message = "字典键值长度不能超过100个字符") + private String value; + + @ApiModelProperty(value = "字典类型", required = true, example = "sys_common_sex") + @NotBlank(message = "字典类型不能为空") + @Size(max = 100, message = "字典类型长度不能超过100个字符") + private String dictType; + + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 SysCommonStatusEnum 枚举") + @NotNull(message = "状态不能为空") +// @InEnum(value = SysCommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + + @ApiModelProperty(value = "备注", example = "我是一个角色") + private String remark; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataCreateReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataCreateReqVO.java new file mode 100644 index 000000000..abae7dcff --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataCreateReqVO.java @@ -0,0 +1,12 @@ +package cn.iocoder.dashboard.modules.system.controller.dict.vo.data; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel("字典数据创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class SysDictDataCreateReqVO extends SysDictDataBaseVO { + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataExcelRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataExcelRespVO.java new file mode 100644 index 000000000..2672c5528 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataExcelRespVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.dashboard.modules.system.controller.dict.vo.data; + +import cn.iocoder.dashboard.framework.excel.Excel; +import lombok.Data; + +/** + * 字典数据 Excel 导出响应 VO + */ +@Data +public class SysDictDataExcelRespVO { + + @Excel(name = "字典编码", cellType = Excel.ColumnType.NUMERIC) + private Long id; + + @Excel(name = "字典排序", cellType = Excel.ColumnType.NUMERIC) + private Integer sort; + + @Excel(name = "字典标签") + private String label; + + @Excel(name = "字典键值") + private String value; + + @Excel(name = "字典类型") + private String dictType; + + @Excel(name = "状态", readConverterExp = "0=正常,1=停用") + private Integer status; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataPageReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataPageReqVO.java new file mode 100644 index 000000000..ad5a07536 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataPageReqVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.dashboard.modules.system.controller.dict.vo.data; + +import cn.iocoder.dashboard.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.Size; + +@ApiModel("字典类型分页列表 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class SysDictDataPageReqVO extends PageParam { + + @ApiModelProperty(value = "字典标签", example = "芋道") + @Size(max = 100, message = "字典标签长度不能超过100个字符") + private String label; + + @ApiModelProperty(value = "字典类型", example = "sys_common_sex", notes = "模糊匹配") + @Size(max = 100, message = "字典类型类型长度不能超过100个字符") + private String dictType; + + @ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类") + private Integer status; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataRespVO.java new file mode 100644 index 000000000..2cad91af4 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataRespVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.dashboard.modules.system.controller.dict.vo.data; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@ApiModel("字典数据信息 Response VO") +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class SysDictDataRespVO extends SysDictDataBaseVO { + + @ApiModelProperty(value = "字典数据编号", required = true, example = "1024") + private Integer id; + + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDataDictSimpleVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataSimpleVO.java similarity index 93% rename from src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDataDictSimpleVO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataSimpleVO.java index 7b6e57aa0..afddd5fa9 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDataDictSimpleVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataSimpleVO.java @@ -6,7 +6,7 @@ import lombok.Data; @ApiModel("数据字典精简 VO") @Data -public class SysDataDictSimpleVO { +public class SysDictDataSimpleVO { @ApiModelProperty(value = "字典类型", required = true, example = "gender") private String dictType; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataUpdateReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataUpdateReqVO.java new file mode 100644 index 000000000..1d79f19ec --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/data/SysDictDataUpdateReqVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.dashboard.modules.system.controller.dict.vo.data; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; + +@ApiModel("字典数据更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class SysDictDataUpdateReqVO extends SysDictDataBaseVO { + + @ApiModelProperty(value = "字典数据编号", required = true, example = "1024") + @NotNull(message = "字典数据编号不能为空") + private Long id; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeBaseVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeBaseVO.java index 2f71f99e5..306ede795 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeBaseVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeBaseVO.java @@ -1,10 +1,10 @@ package cn.iocoder.dashboard.modules.system.controller.dict.vo.type; -import cn.iocoder.dashboard.framework.excel.Excel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; /** @@ -19,14 +19,11 @@ public class SysDictTypeBaseVO { @Size(max = 100, message = "字典类型名称长度不能超过100个字符") private String name; - @ApiModelProperty(value = "字典类型", required = true, example = "sys_common_sex") - @NotBlank(message = "字典类型不能为空") - @Size(max = 100, message = "字典类型类型长度不能超过100个字符") - private String type; - @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举类") - @NotBlank(message = "状态不能为空") - @Excel(name = "状态", readConverterExp = "0=正常,1=停用") + @NotNull(message = "状态不能为空") private Integer status; + @ApiModelProperty(value = "备注", example = "快乐的备注") + private String remark; + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeCreateReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeCreateReqVO.java index a3b88f2e4..747ad1902 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeCreateReqVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeCreateReqVO.java @@ -1,11 +1,21 @@ package cn.iocoder.dashboard.modules.system.controller.dict.vo.type; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + @ApiModel("字典类型创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) public class SysDictTypeCreateReqVO extends SysDictTypeBaseVO { + + @ApiModelProperty(value = "字典类型", required = true, example = "sys_common_sex") + @NotNull(message = "字典类型不能为空") + @Size(max = 100, message = "字典类型类型长度不能超过100个字符") + private String type; + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypePageReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypePageReqVO.java index ffbf904b0..c91031a4b 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypePageReqVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypePageReqVO.java @@ -1,17 +1,36 @@ package cn.iocoder.dashboard.modules.system.controller.dict.vo.type; +import cn.iocoder.dashboard.common.pojo.PageParam; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.Size; +import java.util.Date; + +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @ApiModel("字典类型分页列表 Request VO") @Data -public class SysDictTypePageReqVO { +public class SysDictTypePageReqVO extends PageParam { @ApiModelProperty(value = "字典类型名称", example = "芋道", notes = "模糊匹配") private String name; + @ApiModelProperty(value = "字典类型", example = "sys_common_sex", notes = "模糊匹配") + @Size(max = 100, message = "字典类型类型长度不能超过100个字符") + private String type; + @ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类") private Integer status; + @ApiModelProperty(value = "开始时间", example = "2020-10-24") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date beginTime; + + @ApiModelProperty(value = "结束时间", example = "2020-10-24") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date endTime; + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeRespVO.java index 280b28e40..e9c5116b5 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeRespVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/vo/type/SysDictTypeRespVO.java @@ -19,6 +19,9 @@ public class SysDictTypeRespVO extends SysDictTypeBaseVO { @ApiModelProperty(value = "字典类型编号", required = true, example = "1024") private Integer id; + @ApiModelProperty(value = "字典类型", required = true, example = "sys_common_sex") + private String type; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") private Date createTime; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/dict/SysDictDataConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/dict/SysDictDataConvert.java index b2a12e4e4..fe9cc38fe 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/convert/dict/SysDictDataConvert.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/convert/dict/SysDictDataConvert.java @@ -1,8 +1,14 @@ package cn.iocoder.dashboard.modules.system.convert.dict; -import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDataDictSimpleVO; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataRespVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataSimpleVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; @@ -12,6 +18,17 @@ public interface SysDictDataConvert { SysDictDataConvert INSTANCE = Mappers.getMapper(SysDictDataConvert.class); - List convertList(List list); + List convertList(List list); + + SysDictDataRespVO convert(SysDictDataDO bean); + + PageResult convertPage(PageResult page); + + SysDictDataDO convert(SysDictDataUpdateReqVO bean); + + SysDictDataDO convert(SysDictDataCreateReqVO bean); + + @Mapping(source = "records", target = "list") + PageResult convertPage02(IPage page); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/dict/SysDictTypeConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/dict/SysDictTypeConvert.java index 96fe80724..f7a52df2a 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/convert/dict/SysDictTypeConvert.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/convert/dict/SysDictTypeConvert.java @@ -1,9 +1,13 @@ package cn.iocoder.dashboard.modules.system.convert.dict; import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeRespVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeUpdateReqVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @Mapper @@ -15,4 +19,11 @@ public interface SysDictTypeConvert { SysDictTypeRespVO convert(SysDictTypeDO bean); + @Mapping(source = "records", target = "list") + PageResult convertPage02(IPage page); + + SysDictTypeDO convert(SysDictTypeCreateReqVO bean); + + SysDictTypeDO convert(SysDictTypeUpdateReqVO bean); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dict/SysDictDataMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dict/SysDictDataMapper.java index 4c49406f7..c18023bc4 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dict/SysDictDataMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dict/SysDictDataMapper.java @@ -1,9 +1,39 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict; +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + +import static com.baomidou.mybatisplus.core.metadata.OrderItem.asc; + @Mapper public interface SysDictDataMapper extends BaseMapper { + + default SysDictDataDO selectByLabel(String label) { + return selectOne(new QueryWrapper().eq("label", label)); + } + + default int selectCountByDictType(String dictType) { + return selectCount(new QueryWrapper().eq("dict_type", dictType)); + } + + default IPage selectList(SysDictDataPageReqVO reqVO) { + return selectPage(MyBatisUtils.buildPage(reqVO), + new QueryWrapperX().likeIfPresent("label", reqVO.getLabel()) + .likeIfPresent("dict_type", reqVO.getDictType()) + .eqIfPresent("status", reqVO.getStatus())) + .addOrder(asc("dict_type"), asc("sort")); + } + + default List selectList() { + return selectList(new QueryWrapper<>()); + } + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dict/SysDictTypeMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dict/SysDictTypeMapper.java new file mode 100644 index 000000000..7c348a174 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/dict/SysDictTypeMapper.java @@ -0,0 +1,30 @@ +package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict; + +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypePageReqVO; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SysDictTypeMapper extends BaseMapper { + + default IPage selectList(SysDictTypePageReqVO reqVO) { + return selectPage(MyBatisUtils.buildPage(reqVO), + new QueryWrapperX().likeIfPresent("name", reqVO.getName()) + .likeIfPresent("dict_type", reqVO.getType()) + .eqIfPresent("status", reqVO.getStatus()) + .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime())); + } + + default SysDictTypeDO selectByType(String type) { + return selectOne(new QueryWrapperX().eq("dict_type", type)); + } + + default SysDictTypeDO selectByName(String name) { + return selectOne(new QueryWrapperX().eq("name", name)); + } + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dict/SysDictDataDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dict/SysDictDataDO.java index 9b6ad4d92..549eb0a43 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dict/SysDictDataDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dict/SysDictDataDO.java @@ -1,16 +1,12 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict; import cn.iocoder.dashboard.common.enums.CommonStatusEnum; -import cn.iocoder.dashboard.framework.excel.Excel; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; - /** * 字典数据表 * @@ -22,45 +18,33 @@ import javax.validation.constraints.Size; public class SysDictDataDO extends BaseDO { /** - * 字典编码 + * 字典数据编号 */ @TableId - @Excel(name = "字典编码", cellType = Excel.ColumnType.NUMERIC) private Long id; /** * 字典排序 */ - @Excel(name = "字典排序", cellType = Excel.ColumnType.NUMERIC) private Integer sort; /** * 字典标签 */ - @Excel(name = "字典标签") - @NotBlank(message = "字典标签不能为空") - @Size(max = 100, message = "字典标签长度不能超过100个字符") private String label; /** * 字典值 */ - @Excel(name = "字典键值") - @NotBlank(message = "字典键值不能为空") - @Size(max = 100, message = "字典键值长度不能超过100个字符") private String value; /** * 字典类型 * * 冗余 {@link SysDictDataDO#getDictType()} */ - @Excel(name = "字典类型") - @NotBlank(message = "字典类型不能为空") - @Size(max = 100, message = "字典类型长度不能超过100个字符") private String dictType; /** * 状态 * * 枚举 {@link CommonStatusEnum} */ - @Excel(name = "状态", readConverterExp = "0=正常,1=停用") private Integer status; /** * 备注 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dict/SysDictTypeDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dict/SysDictTypeDO.java index f4bf5a249..e9816a5bd 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dict/SysDictTypeDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/dict/SysDictTypeDO.java @@ -38,5 +38,9 @@ public class SysDictTypeDO extends BaseDO { * 枚举 {@link CommonStatusEnum} */ private Integer status; + /** + * 备注 + */ + private String remark; } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java b/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java index 155ec1b43..29bebd751 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java @@ -51,7 +51,19 @@ public interface SysErrorCodeConstants { // ========== 岗位模块 1002005000 ========== ErrorCode POST_NOT_FOUND = new ErrorCode(1002005001, "当前岗位不存在"); ErrorCode POST_NOT_ENABLE = new ErrorCode(1002005002, "岗位({}) 不处于开启状态,不允许选择"); - ErrorCode POST_NAME_DUPLICATE = new ErrorCode(1002004001, "已经存在该名字的岗位"); - ErrorCode POST_CODE_DUPLICATE = new ErrorCode(1002004001, "已经存在该标识的岗位"); + ErrorCode POST_NAME_DUPLICATE = new ErrorCode(1002005001, "已经存在该名字的岗位"); + ErrorCode POST_CODE_DUPLICATE = new ErrorCode(1002005001, "已经存在该标识的岗位"); + + // ========== 字典类型 1002006000 ========== + ErrorCode DICT_TYPE_NOT_FOUND = new ErrorCode(1002006001, "当前字典类型不存在"); + ErrorCode DICT_TYPE_NOT_ENABLE = new ErrorCode(1002006002, "字典类型不处于开启状态,不允许选择"); + ErrorCode DICT_TYPE_NAME_DUPLICATE = new ErrorCode(1002006003, "已经存在该名字的字典类型"); + ErrorCode DICT_TYPE_TYPE_DUPLICATE = new ErrorCode(1002006004, "已经存在该类型的字典类型"); + ErrorCode DICT_TYPE_HAS_CHILDREN = new ErrorCode(1002006004, "无法删除,该字典类型还有字典数据"); + + // ========== 字典数据 1002007000 ========== + ErrorCode DICT_DATA_NOT_FOUND = new ErrorCode(1002007001, "当前字典数据不存在"); + ErrorCode DICT_DATA_NOT_ENABLE = new ErrorCode(1002007002, "字典数据不处于开启状态,不允许选择"); + ErrorCode DICT_DATA_VALUE_DUPLICATE = new ErrorCode(1002007003, "已经存在该值的字典数据"); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java index d1ea39f7b..1cfd5b331 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java @@ -1,5 +1,9 @@ package cn.iocoder.dashboard.modules.system.service.dict; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; import java.util.List; @@ -13,4 +17,50 @@ public interface SysDictDataService { List listDictDatas(); + /** + * 获得字典数据分页列表 + * + * @param reqVO 分页请求 + * @return 字典数据分页列表 + */ + PageResult pageDictDatas(SysDictDataPageReqVO reqVO); + + /** + * 获得字典数据详情 + * + * @param id 字典数据编号 + * @return 字典数据 + */ + SysDictDataDO getDictData(Long id); + + /** + * 创建字典数据 + * + * @param reqVO 字典数据信息 + * @return 字典数据编号 + */ + Long createDictData(SysDictDataCreateReqVO reqVO); + + /** + * 更新字典数据 + * + * @param reqVO 字典数据信息 + */ + void updateDictData(SysDictDataUpdateReqVO reqVO); + + /** + * 删除字典数据 + * + * @param id 字典数据编号 + */ + void deleteDictData(Long id); + + /** + * 获得指定字典类型的数据数量 + * + * @param dictType 字典类型 + * @return 数据数量 + */ + int countByDictType(String dictType); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictTypeService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictTypeService.java index 7fd6c944d..e4d1b594e 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictTypeService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictTypeService.java @@ -3,7 +3,7 @@ package cn.iocoder.dashboard.modules.system.service.dict; import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypePageReqVO; -import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeUpdateReqVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; /** @@ -13,14 +13,50 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictType */ public interface SysDictTypeService { + /** + * 获得字典类型分页列表 + * + * @param reqVO 分页请求 + * @return 字典类型分页列表 + */ PageResult pageDictTypes(SysDictTypePageReqVO reqVO); + /** + * 获得字典类型详情 + * + * @param id 字典类型编号 + * @return 字典类型 + */ SysDictTypeDO getDictType(Long id); + /** + * 获得字典类型详情 + * + * @param type 字典类型 + * @return 字典类型详情 + */ + SysDictTypeDO getDictType(String type); + + /** + * 创建字典类型 + * + * @param reqVO 字典类型信息 + * @return 字典类型编号 + */ Long createDictType(SysDictTypeCreateReqVO reqVO); - void updateDictType(SysUserUpdateReqVO reqVO); + /** + * 更新字典类型 + * + * @param reqVO 字典类型信息 + */ + void updateDictType(SysDictTypeUpdateReqVO reqVO); + /** + * 删除字典类型 + * + * @param id 字典类型编号 + */ void deleteDictType(Long id); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java index eb723e738..23ad9e060 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java @@ -1,14 +1,25 @@ package cn.iocoder.dashboard.modules.system.service.dict.impl; +import cn.iocoder.dashboard.common.enums.CommonStatusEnum; +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; +import cn.iocoder.dashboard.modules.system.convert.dict.SysDictDataConvert; import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict.SysDictDataMapper; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; +import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Comparator; import java.util.List; +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*; + /** * 字典数据 Service 实现类 * @@ -21,14 +32,102 @@ public class SysDictDataServiceImpl implements SysDictDataService { .comparing(SysDictDataDO::getDictType) .thenComparingInt(SysDictDataDO::getSort); + @Resource + private SysDictTypeService dictTypeService; + @Resource private SysDictDataMapper dictDataMapper; @Override public List listDictDatas() { - List list = dictDataMapper.selectList(null); + List list = dictDataMapper.selectList(); list.sort(COMPARATOR_TYPE_AND_SORT); return list; } + @Override + public PageResult pageDictDatas(SysDictDataPageReqVO reqVO) { + return SysDictDataConvert.INSTANCE.convertPage02(dictDataMapper.selectList(reqVO)); + } + + @Override + public SysDictDataDO getDictData(Long id) { + return dictDataMapper.selectById(id); + } + + @Override + public Long createDictData(SysDictDataCreateReqVO reqVO) { + // 校验正确性 + this.checkCreateOrUpdate(null, reqVO.getLabel(), reqVO.getDictType()); + // 插入字典类型 + SysDictDataDO dictData = SysDictDataConvert.INSTANCE.convert(reqVO); + dictDataMapper.insert(dictData); + return dictData.getId(); + } + + @Override + public void updateDictData(SysDictDataUpdateReqVO reqVO) { + // 校验正确性 + this.checkCreateOrUpdate(reqVO.getId(), reqVO.getLabel(), reqVO.getDictType()); + // 更新字典类型 + SysDictDataDO updateObj = SysDictDataConvert.INSTANCE.convert(reqVO); + dictDataMapper.updateById(updateObj); + } + + @Override + public void deleteDictData(Long id) { + // 校验是否存在 + this.checkDictDataExists(id); + // 删除字典数据 + dictDataMapper.deleteById(id); + } + + @Override + public int countByDictType(String dictType) { + return dictDataMapper.selectCountByDictType(dictType); + } + + private void checkCreateOrUpdate(Long id, String label, String dictType) { + // 校验自己存在 + checkDictDataExists(id); + // 校验字典数据的值的唯一性 + checkDictDataValueUnique(id, label); + // 校验字典类型有效 + checkDictTypeValid(dictType); + } + + private void checkDictDataValueUnique(Long id, String label) { + SysDictDataDO dictData = dictDataMapper.selectByLabel(label); + if (dictData == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的字典数据 + if (id == null) { + throw ServiceExceptionUtil.exception(DICT_DATA_VALUE_DUPLICATE); + } + if (!dictData.getId().equals(id)) { + throw ServiceExceptionUtil.exception(DICT_DATA_VALUE_DUPLICATE); + } + } + + private void checkDictDataExists(Long id) { + if (id == null) { + return; + } + SysDictDataDO dictData = dictDataMapper.selectById(id); + if (dictData == null) { + throw ServiceExceptionUtil.exception(DICT_DATA_NOT_FOUND); + } + } + + private void checkDictTypeValid(String type) { + SysDictTypeDO dictType = dictTypeService.getDictType(type); + if (dictType == null) { + throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_FOUND); + } + if (!CommonStatusEnum.ENABLE.getStatus().equals(dictType.getStatus())) { + throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_ENABLE); + } + } + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictTypeServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictTypeServiceImpl.java new file mode 100644 index 000000000..7c8dea31d --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictTypeServiceImpl.java @@ -0,0 +1,137 @@ +package cn.iocoder.dashboard.modules.system.service.dict.impl; + +import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypePageReqVO; +import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeUpdateReqVO; +import cn.iocoder.dashboard.modules.system.convert.dict.SysDictTypeConvert; +import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict.SysDictTypeMapper; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; +import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; +import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*; + +/** + * 字典类型 Service 实现类 + * + * @author 芋道源码 + */ +@Service +public class SysDictTypeServiceImpl implements SysDictTypeService { + + @Resource + private SysDictTypeServiceImpl self; + @Resource + private SysDictDataService dictDataService; + + @Resource + private SysDictTypeMapper dictTypeMapper; + + @Override + public PageResult pageDictTypes(SysDictTypePageReqVO reqVO) { + return SysDictTypeConvert.INSTANCE.convertPage02(dictTypeMapper.selectList(reqVO)); + } + + @Override + public SysDictTypeDO getDictType(Long id) { + return dictTypeMapper.selectById(id); + } + + @Override + public SysDictTypeDO getDictType(String type) { + return dictTypeMapper.selectByType(type); + } + + @Override + public Long createDictType(SysDictTypeCreateReqVO reqVO) { + // 校验正确性 + this.checkCreateOrUpdate(null, reqVO.getName(), reqVO.getType()); + // 插入字典类型 + SysDictTypeDO dictType = SysDictTypeConvert.INSTANCE.convert(reqVO); + dictTypeMapper.insert(dictType); + return dictType.getId(); + } + + @Override + public void updateDictType(SysDictTypeUpdateReqVO reqVO) { + // 校验正确性 + this.checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), null); + // 更新字典类型 + SysDictTypeDO updateObj = SysDictTypeConvert.INSTANCE.convert(reqVO); + dictTypeMapper.updateById(updateObj); + } + + @Override + public void deleteDictType(Long id) { + // 执行删除 + self.deleteDictType0(id); + // TODO 发送 MQ 消息 + } + + @Transactional + public void deleteDictType0(Long id) { + // 校验是否存在 + SysDictTypeDO dictType = this.checkDictTypeExists(id); + // 校验是否有字典数据 + if (dictDataService.countByDictType(dictType.getType()) > 0) { + throw ServiceExceptionUtil.exception(DICT_TYPE_HAS_CHILDREN); + } + // 删除字典类型 + dictTypeMapper.deleteById(id); + } + + private void checkCreateOrUpdate(Long id, String name, String type) { + // 校验自己存在 + checkDictTypeExists(id); + // 校验字典类型的名字的唯一性 + checkDictTypeNameUnique(id, name); + // 校验字典类型的类型的唯一性 + checkDictTypeUnique(id, type); + } + + private void checkDictTypeNameUnique(Long id, String type) { + SysDictTypeDO dictType = dictTypeMapper.selectByName(type); + if (dictType == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的字典类型 + if (id == null) { + throw ServiceExceptionUtil.exception(DICT_TYPE_NAME_DUPLICATE); + } + if (!dictType.getId().equals(id)) { + throw ServiceExceptionUtil.exception(DICT_TYPE_NAME_DUPLICATE); + } + } + + private void checkDictTypeUnique(Long id, String type) { + SysDictTypeDO dictType = dictTypeMapper.selectByType(type); + if (dictType == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的字典类型 + if (id == null) { + throw ServiceExceptionUtil.exception(DICT_TYPE_TYPE_DUPLICATE); + } + if (!dictType.getId().equals(id)) { + throw ServiceExceptionUtil.exception(DICT_TYPE_TYPE_DUPLICATE); + } + } + + private SysDictTypeDO checkDictTypeExists(Long id) { + if (id == null) { + return null; + } + SysDictTypeDO dictType = dictTypeMapper.selectById(id); + if (dictType == null) { + throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_FOUND); + } + return dictType; + } + +}