From eddec34e5d8274a9c93b43d0f6ccb85655990952 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 3 Mar 2019 13:13:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=AE=8C=E6=88=90~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admins/DataDictController.java | 29 +++++++++++++++++++ .../mall/admin/application/vo/DataDictVO.java | 6 ++-- .../api/constant/AdminErrorCodeEnum.java | 2 +- .../admin/service/DataDictServiceImpl.java | 2 +- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java index f9247257a..90903c4f9 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java @@ -4,6 +4,7 @@ import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.DataDictService; import cn.iocoder.mall.admin.api.bo.DataDictBO; import cn.iocoder.mall.admin.api.dto.DataDictAddDTO; +import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO; import cn.iocoder.mall.admin.application.convert.DataDictConvert; import cn.iocoder.mall.admin.application.vo.DataDictVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; @@ -54,4 +55,32 @@ public class DataDictController { return DataDictConvert.INSTANCE.convert2(result); } + @PostMapping("/update") + @ApiOperation(value = "更新数据字典") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "100"), + @ApiImplicitParam(name = "value", value = "小类数值", required = true, example = "1"), + @ApiImplicitParam(name = "displayName", value = "展示名", required = true, example = "男"), + @ApiImplicitParam(name = "sort", required = true, value = "排序值", defaultValue = "10"), + @ApiImplicitParam(name = "memo", value = "备注", example = "你猜我猜不猜"), + }) + public CommonResult update(@RequestParam("id") Integer id, + @RequestParam("value") String value, + @RequestParam("displayName") String displayName, + @RequestParam("sort") Integer sort, + @RequestParam(value = "memo", required = false) String memo) { + // 创建 DataDictAddDTO 对象 + DataDictUpdateDTO dataDictUpdateDTO = new DataDictUpdateDTO().setId(id).setValue(value).setDisplayName(displayName) + .setSort(sort).setMemo(memo); + // 更新数据字典 + return dataDictService.updateDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictUpdateDTO); + } + + @PostMapping("/delete") + @ApiOperation(value = "删除数据字典") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "100") + public CommonResult delete(@RequestParam("id") Integer id) { + return dataDictService.deleteDataDict(AdminSecurityContextHolder.getContext().getAdminId(), id); + } + } \ No newline at end of file diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java index 201ea6284..c64d1d493 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java @@ -17,7 +17,7 @@ public class DataDictVO { @ApiModelProperty(value = "排序值", required = true, example = "10") private Integer sort; @ApiModelProperty(value = "备注", example = "你猜") - private Integer memo; + private String memo; public Integer getId() { return id; @@ -64,11 +64,11 @@ public class DataDictVO { return this; } - public Integer getMemo() { + public String getMemo() { return memo; } - public DataDictVO setMemo(Integer memo) { + public DataDictVO setMemo(String memo) { this.memo = memo; return this; } diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java index 197064e96..1d8c3d1f4 100644 --- a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java @@ -41,7 +41,7 @@ public enum AdminErrorCodeEnum { // ========== 数据字典模块 1002005000 ========== DATA_DICT_EXISTS(1002005000, "该数据字典已经存在"), - DATA_DICT_NOT_EXISTS(1002005001, "该数据字典已经存在"), + DATA_DICT_NOT_EXISTS(1002005001, "该数据字典不存在"), ; diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java index 4abdd1c4b..42fe01a57 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java @@ -57,7 +57,7 @@ public class DataDictServiceImpl implements DataDictService { } // 校验数据字典重复 DataDictDO duplicateDataDict = dataDictMapper.selectByEnumValueAndValue(existsDataDict.getEnumValue(), dataDictUpdateDTO.getValue()); - if (duplicateDataDict != null && duplicateDataDict.getId().equals(dataDictUpdateDTO.getId())) { + if (duplicateDataDict != null && !duplicateDataDict.getId().equals(dataDictUpdateDTO.getId())) { return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); } // 更新到数据库