From 8089319f648ca6d8f44d2824e17301e3b3a39be9 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 3 Mar 2019 12:54:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E9=83=A8=E5=88=86=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => admins}/AdminController.java | 2 +- .../controller/admins/DataDictController.java | 57 ++++++++++ .../{ => admins}/PassportController.java | 2 +- .../{ => admins}/ResourceController.java | 2 +- .../{ => admins}/RoleController.java | 2 +- .../application/convert/DataDictConvert.java | 29 +++++ .../mall/admin/application/vo/DataDictVO.java | 76 +++++++++++++ .../mall/admin/api/DataDictService.java | 20 ++++ .../iocoder/mall/admin/api/bo/DataDictBO.java | 102 ++++++++++++++++++ .../api/constant/AdminErrorCodeEnum.java | 5 + .../mall/admin/api/dto/DataDictAddDTO.java | 81 ++++++++++++++ .../mall/admin/api/dto/DataDictUpdateDTO.java | 81 ++++++++++++++ .../mall/admin/convert/DataDictConvert.java | 25 +++++ .../mall/admin/dao/DataDictMapper.java | 23 ++++ .../mall/admin/dataobject/DataDictDO.java | 94 ++++++++++++++++ .../mall/admin/service/AdminServiceImpl.java | 2 +- .../admin/service/DataDictServiceImpl.java | 89 +++++++++++++++ .../mall/admin/service/OAuth2ServiceImpl.java | 2 +- .../mall/admin/service/RoleServiceImpl.java | 2 +- .../main/resources/mapper/DataDictMapper.xml | 70 ++++++++++++ 20 files changed, 759 insertions(+), 7 deletions(-) rename admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/{ => admins}/AdminController.java (99%) create mode 100644 admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java rename admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/{ => admins}/PassportController.java (96%) rename admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/{ => admins}/ResourceController.java (99%) rename admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/{ => admins}/RoleController.java (99%) create mode 100644 admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java create mode 100644 admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java create mode 100644 admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java create mode 100644 admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/DataDictBO.java create mode 100644 admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictAddDTO.java create mode 100644 admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictUpdateDTO.java create mode 100644 admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DataDictConvert.java create mode 100644 admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java create mode 100644 admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java create mode 100644 admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java create mode 100644 admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java similarity index 99% rename from admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java rename to admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index abd6fe5c9..ca21069fd 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.controller; +package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.AdminService; 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 new file mode 100644 index 000000000..f9247257a --- /dev/null +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java @@ -0,0 +1,57 @@ +package cn.iocoder.mall.admin.application.controller.admins; + +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.application.convert.DataDictConvert; +import cn.iocoder.mall.admin.application.vo.DataDictVO; +import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; +import com.alibaba.dubbo.config.annotation.Reference; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("admins/data_dict") +@Api("数据字典模块") +public class DataDictController { + + @Reference(validation = "true") + private DataDictService dataDictService; + + @GetMapping("/list") + @ApiOperation(value = "数据字典全列表") + public CommonResult> list() { + CommonResult> result = dataDictService.selectDataDictList(); + return DataDictConvert.INSTANCE.convert(result); + } + + @PostMapping("/add") + @ApiOperation(value = "创建数据字典") + @ApiImplicitParams({ + @ApiImplicitParam(name = "enumValue", value = "大类枚举值", required = true, example = "gender"), + @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 add(@RequestParam("enumValue") String enumValue, + @RequestParam("value") String value, + @RequestParam("displayName") String displayName, + @RequestParam("sort") Integer sort, + @RequestParam(value = "memo", required = false) String memo) { + // 创建 DataDictAddDTO 对象 + DataDictAddDTO dataDictAddDTO = new DataDictAddDTO().setEnumValue(enumValue).setValue(value).setDisplayName(displayName) + .setSort(sort).setMemo(memo); + // 保存数据字典 + CommonResult result = dataDictService.addDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictAddDTO); + // 返回结果 + return DataDictConvert.INSTANCE.convert2(result); + } + +} \ No newline at end of file diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/PassportController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java similarity index 96% rename from admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/PassportController.java rename to admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java index 6b889fcb4..d555f23eb 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/PassportController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/PassportController.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.controller; +package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.OAuth2Service; diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/ResourceController.java similarity index 99% rename from admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java rename to admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/ResourceController.java index 8a0de17be..b3c359c7e 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/ResourceController.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.controller; +package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.ResourceService; diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java similarity index 99% rename from admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java rename to admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java index 5298fc2a6..2b2ca063c 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.application.controller; +package cn.iocoder.mall.admin.application.controller.admins; import cn.iocoder.common.framework.util.CollectionUtil; import cn.iocoder.common.framework.vo.CommonResult; diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java new file mode 100644 index 000000000..a7dc3c7fd --- /dev/null +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.admin.application.convert; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.api.bo.DataDictBO; +import cn.iocoder.mall.admin.application.vo.DataDictVO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface DataDictConvert { + + DataDictConvert INSTANCE = Mappers.getMapper(DataDictConvert.class); + + @Mappings({}) + DataDictVO convert(DataDictBO dataDictBO); + + @Mappings({}) + List convert(List dataDictBOs); + + @Mappings({}) + CommonResult> convert(CommonResult> result); + + @Mappings({}) + CommonResult convert2(CommonResult result); + +} \ 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 new file mode 100644 index 000000000..201ea6284 --- /dev/null +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictVO.java @@ -0,0 +1,76 @@ +package cn.iocoder.mall.admin.application.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel("数据字典 VO") +public class DataDictVO { + + @ApiModelProperty(value = "编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") + private String enumValue; + @ApiModelProperty(value = "小类数值", required = true, example = "1") + private String value; + @ApiModelProperty(value = "展示名", required = true, example = "男") + private String displayName; + @ApiModelProperty(value = "排序值", required = true, example = "10") + private Integer sort; + @ApiModelProperty(value = "备注", example = "你猜") + private Integer memo; + + public Integer getId() { + return id; + } + + public DataDictVO setId(Integer id) { + this.id = id; + return this; + } + + public String getEnumValue() { + return enumValue; + } + + public DataDictVO setEnumValue(String enumValue) { + this.enumValue = enumValue; + return this; + } + + public String getValue() { + return value; + } + + public DataDictVO setValue(String value) { + this.value = value; + return this; + } + + public String getDisplayName() { + return displayName; + } + + public DataDictVO setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public Integer getSort() { + return sort; + } + + public DataDictVO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public Integer getMemo() { + return memo; + } + + public DataDictVO setMemo(Integer memo) { + this.memo = memo; + return this; + } + +} \ No newline at end of file diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java new file mode 100644 index 000000000..c6dbaecc3 --- /dev/null +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.admin.api; + +import cn.iocoder.common.framework.vo.CommonResult; +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 java.util.List; + +public interface DataDictService { + + CommonResult> selectDataDictList(); + + CommonResult addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO); + + CommonResult updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO); + + CommonResult deleteDataDict(Integer adminId, Integer dataDictId); + +} diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/DataDictBO.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/DataDictBO.java new file mode 100644 index 000000000..2c404c22d --- /dev/null +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/DataDictBO.java @@ -0,0 +1,102 @@ +package cn.iocoder.mall.admin.api.bo; + +import java.util.Date; + +/** + * 数据字典 BO + */ +public class DataDictBO { + + /** + * 编号 + */ + private Integer id; + /** + * 大类枚举值 + */ + private String enumValue; + /** + * 小类数值 + */ + private String value; + /** + * 展示名 + */ + private String displayName; + /** + * 排序值 + */ + private Integer sort; + /** + * 备注 + */ + private String memo; + /** + * 创建时间 + */ + private Date createTime; + + public Integer getId() { + return id; + } + + public DataDictBO setId(Integer id) { + this.id = id; + return this; + } + + public String getEnumValue() { + return enumValue; + } + + public DataDictBO setEnumValue(String enumValue) { + this.enumValue = enumValue; + return this; + } + + public String getValue() { + return value; + } + + public DataDictBO setValue(String value) { + this.value = value; + return this; + } + + public String getDisplayName() { + return displayName; + } + + public DataDictBO setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public Integer getSort() { + return sort; + } + + public DataDictBO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getMemo() { + return memo; + } + + public DataDictBO setMemo(String memo) { + this.memo = memo; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public DataDictBO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + +} \ No newline at end of file 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 03efd89bd..197064e96 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 @@ -38,6 +38,11 @@ public enum AdminErrorCodeEnum { // ========== 角色模块 1002004000 ========== ROLE_NOT_EXISTS(1002004000, "角色不存在"), ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002004001, "分配角色资源时,有资源不存在"), + + // ========== 数据字典模块 1002005000 ========== + DATA_DICT_EXISTS(1002005000, "该数据字典已经存在"), + DATA_DICT_NOT_EXISTS(1002005001, "该数据字典已经存在"), + ; private final int code; diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictAddDTO.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictAddDTO.java new file mode 100644 index 000000000..db44b6e8c --- /dev/null +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictAddDTO.java @@ -0,0 +1,81 @@ +package cn.iocoder.mall.admin.api.dto; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * 数据字典添加 DTO + */ +public class DataDictAddDTO { + + /** + * 大类枚举值 + */ + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + /** + * 小类数值 + */ + @NotEmpty(message = "小类数值不能为空") + private String value; + /** + * 展示名 + */ + @NotEmpty(message = "展示名不能为空") + private String displayName; + /** + * 排序值 + */ + @NotNull(message = "排序值不能为空") + private Integer sort; + /** + * 备注 + */ + private String memo; + + public String getEnumValue() { + return enumValue; + } + + public DataDictAddDTO setEnumValue(String enumValue) { + this.enumValue = enumValue; + return this; + } + + public String getValue() { + return value; + } + + public DataDictAddDTO setValue(String value) { + this.value = value; + return this; + } + + public String getDisplayName() { + return displayName; + } + + public DataDictAddDTO setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public Integer getSort() { + return sort; + } + + public DataDictAddDTO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getMemo() { + return memo; + } + + public DataDictAddDTO setMemo(String memo) { + this.memo = memo; + return this; + } + +} \ No newline at end of file diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictUpdateDTO.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictUpdateDTO.java new file mode 100644 index 000000000..4bc3dc643 --- /dev/null +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/DataDictUpdateDTO.java @@ -0,0 +1,81 @@ +package cn.iocoder.mall.admin.api.dto; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * 数据字典更新 DTO + */ +public class DataDictUpdateDTO { + + /** + * 编号 + */ + @NotNull(message = "编号不能为空") + private Integer id; + /** + * 小类数值 + */ + @NotEmpty(message = "小类数值不能为空") + private String value; + /** + * 展示名 + */ + @NotEmpty(message = "展示名不能为空") + private String displayName; + /** + * 排序值 + */ + @NotNull(message = "排序值不能为空") + private Integer sort; + /** + * 备注 + */ + private String memo; + + public Integer getId() { + return id; + } + + public DataDictUpdateDTO setId(Integer id) { + this.id = id; + return this; + } + + public String getValue() { + return value; + } + + public DataDictUpdateDTO setValue(String value) { + this.value = value; + return this; + } + + public String getDisplayName() { + return displayName; + } + + public DataDictUpdateDTO setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public Integer getSort() { + return sort; + } + + public DataDictUpdateDTO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getMemo() { + return memo; + } + + public DataDictUpdateDTO setMemo(String memo) { + this.memo = memo; + return this; + } + +} \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DataDictConvert.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DataDictConvert.java new file mode 100644 index 000000000..2ccde04d7 --- /dev/null +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DataDictConvert.java @@ -0,0 +1,25 @@ +package cn.iocoder.mall.admin.convert; + +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.dataobject.DataDictDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface DataDictConvert { + + DataDictConvert INSTANCE = Mappers.getMapper(DataDictConvert.class); + + DataDictDO convert(DataDictAddDTO dataDictAddDTO); + + DataDictDO convert(DataDictUpdateDTO dataDictUpdateDTO); + + DataDictBO convert(DataDictDO dataDictDO); + + List convert(List dataDictDOs); + +} \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java new file mode 100644 index 000000000..2468358db --- /dev/null +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java @@ -0,0 +1,23 @@ +package cn.iocoder.mall.admin.dao; + +import cn.iocoder.mall.admin.dataobject.DataDictDO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface DataDictMapper { + + DataDictDO selectById(@Param("id") Integer id); + + DataDictDO selectByEnumValueAndValue(@Param("enumValue") String enumValue, + @Param("value") String value); + + List selectList(); + + void insert(DataDictDO dataDict); + + int update(DataDictDO dataDict); + +} diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java new file mode 100644 index 000000000..ba2e78f8e --- /dev/null +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java @@ -0,0 +1,94 @@ +package cn.iocoder.mall.admin.dataobject; + +import cn.iocoder.common.framework.dataobject.BaseDO; + +/** + * 数据字典 + * + * 使用 {@link #enumValue} 作为聚合。例如说: + * + * enumValue :gender 性别 + * value:1 男 + * value:2 女 + */ +public class DataDictDO extends BaseDO { + + /** + * 编号 + */ + private Integer id; + /** + * 大类枚举值 + */ + private String enumValue; + /** + * 小类数值 + */ + private String value; + /** + * 展示名 + */ + private String displayName; + /** + * 排序值 + */ + private Integer sort; + /** + * 备注 + */ + private String memo; + + public String getEnumValue() { + return enumValue; + } + + public DataDictDO setEnumValue(String enumValue) { + this.enumValue = enumValue; + return this; + } + + public String getValue() { + return value; + } + + public DataDictDO setValue(String value) { + this.value = value; + return this; + } + + public String getDisplayName() { + return displayName; + } + + public DataDictDO setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public Integer getSort() { + return sort; + } + + public DataDictDO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getMemo() { + return memo; + } + + public DataDictDO setMemo(String memo) { + this.memo = memo; + return this; + } + + public Integer getId() { + return id; + } + + public DataDictDO setId(Integer id) { + this.id = id; + return this; + } +} \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java index 09cd24bdf..b470ce9bb 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java @@ -28,7 +28,7 @@ import java.util.Set; import java.util.stream.Collectors; @Service -@com.alibaba.dubbo.config.annotation.Service +@com.alibaba.dubbo.config.annotation.Service(validation = "true") public class AdminServiceImpl implements AdminService { @Autowired 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 new file mode 100644 index 000000000..4abdd1c4b --- /dev/null +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java @@ -0,0 +1,89 @@ +package cn.iocoder.mall.admin.service; + +import cn.iocoder.common.framework.dataobject.BaseDO; +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +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.constant.AdminErrorCodeEnum; +import cn.iocoder.mall.admin.api.dto.DataDictAddDTO; +import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO; +import cn.iocoder.mall.admin.convert.DataDictConvert; +import cn.iocoder.mall.admin.dao.DataDictMapper; +import cn.iocoder.mall.admin.dataobject.DataDictDO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * 数据字典 Service + */ +@Service +@com.alibaba.dubbo.config.annotation.Service(validation = "true") +public class DataDictServiceImpl implements DataDictService { + + @Autowired + private DataDictMapper dataDictMapper; + + @Override + public CommonResult> selectDataDictList() { + List dataDicts = dataDictMapper.selectList(); + return CommonResult.success(DataDictConvert.INSTANCE.convert(dataDicts)); + } + + @Override + public CommonResult addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO) { + // 校验数据字典重复 + if (dataDictMapper.selectByEnumValueAndValue(dataDictAddDTO.getEnumValue(), dataDictAddDTO.getValue()) != null) { + return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); + } + // 保存到数据库 + DataDictDO dataDict = DataDictConvert.INSTANCE.convert(dataDictAddDTO); + dataDict.setCreateTime(new Date()).setDeleted(BaseDO.DELETED_NO); + dataDictMapper.insert(dataDict); + // TODO 插入操作日志 + // 返回成功 + return CommonResult.success(DataDictConvert.INSTANCE.convert(dataDict)); + } + + @Override + public CommonResult updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO) { + // 校验数据字典不存在 + DataDictDO existsDataDict = dataDictMapper.selectById(dataDictUpdateDTO.getId()); + if (existsDataDict == null) { + return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); + } + // 校验数据字典重复 + DataDictDO duplicateDataDict = dataDictMapper.selectByEnumValueAndValue(existsDataDict.getEnumValue(), dataDictUpdateDTO.getValue()); + if (duplicateDataDict != null && duplicateDataDict.getId().equals(dataDictUpdateDTO.getId())) { + return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); + } + // 更新到数据库 + DataDictDO updateDataDict = DataDictConvert.INSTANCE.convert(dataDictUpdateDTO); + dataDictMapper.update(updateDataDict); + // TODO 插入操作日志 + // 返回成功 + return CommonResult.success(true); + } + + // 一般情况下,不要删除数据字典。 + // 因为,业务数据正在使用该数据字典,删除后,可能有不可预知的问题。 + @Override + public CommonResult deleteDataDict(Integer adminId, Integer dataDictId) { + // 校验数据字典不存在 + DataDictDO existsDataDict = dataDictMapper.selectById(dataDictId); + if (existsDataDict == null) { + return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); + } + // 更新到数据库 + DataDictDO updateDataDict = new DataDictDO().setId(dataDictId); + updateDataDict.setDeleted(BaseDO.DELETED_YES); + dataDictMapper.update(updateDataDict); + // TODO 插入操作日志 + // 返回成功 + return CommonResult.success(true); + } + +} \ No newline at end of file diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java index 6a1af316a..ca88f7da4 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java @@ -21,7 +21,7 @@ import java.util.Set; import java.util.UUID; @Service -@com.alibaba.dubbo.config.annotation.Service +@com.alibaba.dubbo.config.annotation.Service(validation = "true") public class OAuth2ServiceImpl implements OAuth2Service { /** diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java index 2889d15df..0edc7f2e1 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java @@ -30,7 +30,7 @@ import java.util.Set; import java.util.stream.Collectors; @Service -@com.alibaba.dubbo.config.annotation.Service +@com.alibaba.dubbo.config.annotation.Service(validation = "true") public class RoleServiceImpl implements RoleService { @Autowired diff --git a/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml b/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml new file mode 100644 index 000000000..5aad44a5d --- /dev/null +++ b/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml @@ -0,0 +1,70 @@ + + + + + + id, enum_value, value, display_name, sort, + memo, create_time + + + + + + + + + + INSERT INTO data_dict ( + id, enum_value, value, display_name, sort, + memo, create_time, deleted + ) VALUES ( + #{id}, #{enumValue}, #{value}, #{displayName}, #{sort}, + #{memo}, #{createTime}, #{deleted} + ) + + + + UPDATE data_dict + + + enum_value = #{enumValue}, + + + value = #{value}, + + + display_name = #{displayName}, + + + sort = #{sort}, + + + memo = #{memo}, + + + deleted = #{deleted} + + + WHERE id = #{id} + + + \ No newline at end of file