From e1e42c0ce095394a4ae6aa61f4eaca89f1c94ae4 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Wed, 15 Jul 2020 08:48:24 +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=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datadict/DataDictController.java | 80 +++++++++ .../datadict/dto/DataDictCreateDTO.java | 29 ++++ .../datadict/dto/DataDictUpdateDTO.java | 32 ++++ .../datadict/vo/DataDictSimpleVO.java | 23 +++ .../controller/datadict/vo/DataDictVO.java | 34 ++++ .../convert/datadict/DataDictConvert.java | 27 ++++ .../manager/datadict/DataDictManager.java | 117 ++++++++++++++ .../src/main/resources/application.yml | 2 + .../enums/SystemErrorCodeEnum.java | 4 +- .../rpc/datadict/DataDictRpc.java | 60 +++++++ .../rpc/datadict/dto/DataDictCreateDTO.java | 42 +++++ .../rpc/datadict/dto/DataDictUpdateDTO.java | 47 ++++++ .../rpc/datadict/vo/DataDictVO.java | 45 ++++++ .../convert/datadict/DataDictConvert.java | 36 +++++ .../mysql/dataobject/admin/DepartmentDO.java | 2 +- .../dataobject/datadict}/DataDictDO.java | 4 +- .../mysql/mapper/datadict/DataDictMapper.java | 28 ++++ .../manager/datadict/DataDictManager.java | 84 ++++++++++ .../rpc/datadict/DataDictRpcImpl.java | 56 +++++++ .../service/datadict/DataDictService.java | 153 ++++++++++++++++++ .../service/datadict/bo}/DataDictBO.java | 9 +- .../service/datadict/bo/DataDictCreateBO.java | 41 +++++ .../service/datadict/bo/DataDictUpdateBO.java | 46 ++++++ .../src/main/resources/application.yaml | 2 + .../api/constant/DeptmentConstants.java | 16 -- .../system/api/constant/DictKeyConstants.java | 11 -- .../api/constant/ResourceConstants.java | 22 --- .../system/api/constant/ResourceTypeEnum.java | 54 ------- .../mall/admin/dao/DataDictMapper.java | 34 ---- .../admin/service/DataDictServiceImpl.java | 112 ------------- .../main/resources/mapper/DataDictMapper.xml | 40 ----- 31 files changed, 993 insertions(+), 299 deletions(-) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/DataDictController.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/dto/DataDictCreateDTO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/dto/DataDictUpdateDTO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/vo/DataDictSimpleVO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/vo/DataDictVO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/datadict/DataDictConvert.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/datadict/DataDictManager.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/DataDictRpc.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/dto/DataDictCreateDTO.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/dto/DataDictUpdateDTO.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/vo/DataDictVO.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/datadict/DataDictConvert.java rename {system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject => system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/datadict}/DataDictDO.java (85%) create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/datadict/DataDictMapper.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/datadict/DataDictManager.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/DataDictRpcImpl.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/DataDictService.java rename {system/system-service-api/src/main/java/cn/iocoder/mall/system/api/bo/datadict => system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo}/DataDictBO.java (78%) create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictCreateBO.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictUpdateBO.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/DeptmentConstants.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/DictKeyConstants.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/ResourceConstants.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/ResourceTypeEnum.java delete mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java delete mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java delete mode 100644 system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/DataDictController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/DataDictController.java new file mode 100644 index 00000000..f0610b99 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/DataDictController.java @@ -0,0 +1,80 @@ +package cn.iocoder.mall.managementweb.controller.datadict; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.controller.datadict.dto.DataDictCreateDTO; +import cn.iocoder.mall.managementweb.controller.datadict.dto.DataDictUpdateDTO; +import cn.iocoder.mall.managementweb.controller.datadict.vo.DataDictSimpleVO; +import cn.iocoder.mall.managementweb.controller.datadict.vo.DataDictVO; +import cn.iocoder.mall.managementweb.manager.datadict.DataDictManager; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** +* 数据字典 Controller +*/ +@RestController +@RequestMapping("/data_dict") +@Api(tags = "数据字典") +@Validated +public class DataDictController { + + @Autowired + private DataDictManager dataDictManager; + + @PostMapping("/create") + @ApiOperation("创建数据字典") + public CommonResult createDataDict(@Valid DataDictCreateDTO createDTO) { + return success(dataDictManager.createDataDict(createDTO)); + } + + @PostMapping("/update") + @ApiOperation("更新数据字典") + public CommonResult updateDataDict(@Valid DataDictUpdateDTO updateDTO) { + dataDictManager.updateDataDict(updateDTO); + return success(true); + } + + @PostMapping("/delete") + @ApiOperation("删除数据字典") + @ApiImplicitParam(name = "dataDictId", value = "数据字典编号", required = true) + public CommonResult deleteDataDict(@RequestParam("dataDictId") Integer dataDictId) { + dataDictManager.deleteDataDict(dataDictId); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得数据字典") + @ApiImplicitParam(name = "dataDictId", value = "数据字典编号", required = true) + public CommonResult getDataDict(@RequestParam("dataDictId") Integer dataDictId) { + return success(dataDictManager.getDataDict(dataDictId)); + } + + @GetMapping("/list") + @ApiOperation("获得数据字典列表") + @ApiImplicitParam(name = "dataDictIds", value = "数据字典编号列表", required = true) + public CommonResult> listDataDicts(@RequestParam("dataDictIds") List dataDictIds) { + return success(dataDictManager.listDataDicts(dataDictIds)); + } + + @GetMapping("/list-all") + @ApiOperation("获得全部数据字典列表") + public CommonResult> listDataDicts() { + return success(dataDictManager.listDataDicts()); + } + + @GetMapping("/list-all-simple") + @ApiOperation(value = "获得全部数据字典列表", notes = "一般用于管理后台缓存数据字典在本地") + public CommonResult> listSimpleDataDicts() { + return success(dataDictManager.listSimpleDataDicts()); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/dto/DataDictCreateDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/dto/DataDictCreateDTO.java new file mode 100644 index 00000000..5a5403fd --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/dto/DataDictCreateDTO.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.managementweb.controller.datadict.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("数据字典创建 DTO") +@Data +public class DataDictCreateDTO { + + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + @ApiModelProperty(value = "小类数值", required = true, example = "1") + @NotEmpty(message = "小类数值不能为空") + private String value; + @ApiModelProperty(value = "展示名", required = true, example = "男") + @NotEmpty(message = "展示名不能为空") + private String displayName; + @ApiModelProperty(value = "排序值", required = true, example = "1") + @NotNull(message = "排序值不能为空") + private Integer sort; + @ApiModelProperty(value = "备注", example = "性别 - 男(嗨)") + private String memo; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/dto/DataDictUpdateDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/dto/DataDictUpdateDTO.java new file mode 100644 index 00000000..32c705ab --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/dto/DataDictUpdateDTO.java @@ -0,0 +1,32 @@ +package cn.iocoder.mall.managementweb.controller.datadict.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("数据字典更新 DTO") +@Data +public class DataDictUpdateDTO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + @NotNull(message = "编号不能为空") + private Integer id; + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + @ApiModelProperty(value = "小类数值", required = true, example = "1") + @NotEmpty(message = "小类数值不能为空") + private String value; + @ApiModelProperty(value = "展示名", required = true, example = "男") + @NotEmpty(message = "展示名不能为空") + private String displayName; + @ApiModelProperty(value = "排序值", required = true, example = "1") + @NotNull(message = "排序值不能为空") + private Integer sort; + @ApiModelProperty(value = "备注", example = "性别 - 男(嗨)") + private String memo; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/vo/DataDictSimpleVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/vo/DataDictSimpleVO.java new file mode 100644 index 00000000..acdafbfc --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/vo/DataDictSimpleVO.java @@ -0,0 +1,23 @@ +package cn.iocoder.mall.managementweb.controller.datadict.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; + +@ApiModel("数据字典精简 VO") +@Data +public class DataDictSimpleVO { + + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + @ApiModelProperty(value = "小类数值", required = true, example = "1") + @NotEmpty(message = "小类数值不能为空") + private String value; + @ApiModelProperty(value = "展示名", required = true, example = "男") + @NotEmpty(message = "展示名不能为空") + private String displayName; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/vo/DataDictVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/vo/DataDictVO.java new file mode 100644 index 00000000..146c8c88 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/datadict/vo/DataDictVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.managementweb.controller.datadict.vo; + +import lombok.*; +import io.swagger.annotations.*; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.*; + +@ApiModel("数据字典 VO") +@Data +public class DataDictVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + @NotNull(message = "编号不能为空") + private Integer id; + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + @ApiModelProperty(value = "小类数值", required = true, example = "1") + @NotEmpty(message = "小类数值不能为空") + private String value; + @ApiModelProperty(value = "展示名", required = true, example = "男") + @NotEmpty(message = "展示名不能为空") + private String displayName; + @ApiModelProperty(value = "排序值", required = true, example = "1") + @NotNull(message = "排序值不能为空") + private Integer sort; + @ApiModelProperty(value = "备注", example = "性别 - 男(嗨)") + private String memo; + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/datadict/DataDictConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/datadict/DataDictConvert.java new file mode 100644 index 00000000..6e248d21 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/datadict/DataDictConvert.java @@ -0,0 +1,27 @@ +package cn.iocoder.mall.managementweb.convert.datadict; + +import cn.iocoder.mall.managementweb.controller.datadict.vo.DataDictSimpleVO; +import cn.iocoder.mall.managementweb.controller.datadict.vo.DataDictVO; +import cn.iocoder.mall.systemservice.rpc.datadict.dto.DataDictCreateDTO; +import cn.iocoder.mall.systemservice.rpc.datadict.dto.DataDictUpdateDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface DataDictConvert { + + DataDictConvert INSTANCE = Mappers.getMapper(DataDictConvert.class); + + DataDictCreateDTO convert(cn.iocoder.mall.managementweb.controller.datadict.dto.DataDictCreateDTO bean); + + DataDictUpdateDTO convert(cn.iocoder.mall.managementweb.controller.datadict.dto.DataDictUpdateDTO bean); + + DataDictVO convert(cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO bean); + + List convertList(List list); + + List convertList02(List list); + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/datadict/DataDictManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/datadict/DataDictManager.java new file mode 100644 index 00000000..c5555698 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/datadict/DataDictManager.java @@ -0,0 +1,117 @@ +package cn.iocoder.mall.managementweb.manager.datadict; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.controller.datadict.dto.DataDictCreateDTO; +import cn.iocoder.mall.managementweb.controller.datadict.dto.DataDictUpdateDTO; +import cn.iocoder.mall.managementweb.controller.datadict.vo.DataDictSimpleVO; +import cn.iocoder.mall.managementweb.controller.datadict.vo.DataDictVO; +import cn.iocoder.mall.managementweb.convert.datadict.DataDictConvert; +import cn.iocoder.mall.systemservice.rpc.datadict.DataDictRpc; +import org.apache.dubbo.config.annotation.Reference; +import org.springframework.stereotype.Service; + +import java.util.Comparator; +import java.util.List; + +/** +* 数据字典 Manager +*/ +@Service +public class DataDictManager { + + private static final Comparator COMPARATOR_ENUM_VALUE_SORT = (o1, o2) -> { + int cmp = o1.getEnumValue().compareTo(o2.getEnumValue()); + if (cmp == 0) { + return cmp; + } + return o1.getSort().compareTo(o2.getSort()); + }; + + @Reference(version = "${dubbo.consumer.DataDictRpc.version}", validation = "false") + private DataDictRpc dataDictRpc; + + /** + * 创建数据字典 + * + * @param createDTO 创建数据字典 DTO + * @return 数据字典 + */ + public Integer createDataDict(DataDictCreateDTO createDTO) { + CommonResult createDataDictResult = dataDictRpc.createDataDict(DataDictConvert.INSTANCE.convert(createDTO)); + createDataDictResult.checkError(); + return createDataDictResult.getData(); + } + + /** + * 更新数据字典 + * + * @param updateDTO 更新数据字典 DTO + */ + public void updateDataDict(DataDictUpdateDTO updateDTO) { + CommonResult updateDataDictResult = dataDictRpc.updateDataDict(DataDictConvert.INSTANCE.convert(updateDTO)); + updateDataDictResult.checkError(); + } + + /** + * 删除数据字典 + * + * @param dataDictId 数据字典编号 + */ + public void deleteDataDict(Integer dataDictId) { + CommonResult deleteDataDictResult = dataDictRpc.deleteDataDict(dataDictId); + deleteDataDictResult.checkError(); + } + + /** + * 获得数据字典 + * + * @param dataDictId 数据字典编号 + * @return 数据字典 + */ + public DataDictVO getDataDict(Integer dataDictId) { + CommonResult getDataDictResult = dataDictRpc.getDataDict(dataDictId); + getDataDictResult.checkError(); + return DataDictConvert.INSTANCE.convert(getDataDictResult.getData()); + } + + /** + * 获得数据字典列表 + * + * @param dataDictIds 数据字典编号列表 + * @return 数据字典列表 + */ + public List listDataDicts(List dataDictIds) { + CommonResult> listDataDictResult = dataDictRpc.listDataDicts(dataDictIds); + listDataDictResult.checkError(); + return DataDictConvert.INSTANCE.convertList(listDataDictResult.getData()); + } + + /** + * 获得全部数据字典 + * + * @return 数据字典列表 + */ + public List listDataDicts() { + CommonResult> listDataDictResult = dataDictRpc.listDataDicts(); + listDataDictResult.checkError(); + // 按照 enumValue 和 sort 排序 + listDataDictResult.getData().sort(COMPARATOR_ENUM_VALUE_SORT); + return DataDictConvert.INSTANCE.convertList(listDataDictResult.getData()); + } + + /** + * 获得全部数据字典 + * + * 精简返回字段 + * + * @return 数据字典列表 + */ + public List listSimpleDataDicts() { + CommonResult> listDataDictResult = dataDictRpc.listDataDicts(); + listDataDictResult.checkError(); + // 按照 enumValue 和 sort 排序 + listDataDictResult.getData().sort(COMPARATOR_ENUM_VALUE_SORT); + return DataDictConvert.INSTANCE.convertList02(listDataDictResult.getData()); + } + +} diff --git a/management-web-app/src/main/resources/application.yml b/management-web-app/src/main/resources/application.yml index 90ca2503..447829e3 100644 --- a/management-web-app/src/main/resources/application.yml +++ b/management-web-app/src/main/resources/application.yml @@ -38,6 +38,8 @@ dubbo: version: 1.0.0 DepartmentRpc: version: 1.0.0 + DataDictRpc: + version: 1.0.0 # Swagger 配置项 swagger: diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java index e1a1c7e1..9271387f 100644 --- a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java @@ -50,8 +50,8 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable createDataDict(DataDictCreateDTO createDTO); + + /** + * 更新数据字典 + * + * @param updateDTO 更新数据字典 DTO + */ + CommonResult updateDataDict(DataDictUpdateDTO updateDTO); + + /** + * 删除数据字典 + * + * @param dataDictId 数据字典编号 + */ + CommonResult deleteDataDict(Integer dataDictId); + + /** + * 获得数据字典 + * + * @param dataDictId 数据字典编号 + * @return 数据字典 + */ + CommonResult getDataDict(Integer dataDictId); + + /** + * 获得全部数据字典 + * + * @return 数据字典列表 + */ + CommonResult> listDataDicts(); + + /** + * 获得数据字典列表 + * + * @param dataDictIds 数据字典编号列表 + * @return 数据字典列表 + */ + CommonResult> listDataDicts(List dataDictIds); + +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/dto/DataDictCreateDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/dto/DataDictCreateDTO.java new file mode 100644 index 00000000..0e841bef --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/dto/DataDictCreateDTO.java @@ -0,0 +1,42 @@ +package cn.iocoder.mall.systemservice.rpc.datadict.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** +* 数据字典创建 DTO +*/ +@Data +@Accessors(chain = true) +public class DataDictCreateDTO implements Serializable { + + /** + * 大类枚举值 + */ + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + /** + * 小类数值 + */ + @NotEmpty(message = "小类数值不能为空") + private String value; + /** + * 展示名 + */ + @NotEmpty(message = "展示名不能为空") + private String displayName; + /** + * 排序值 + */ + @NotNull(message = "排序值不能为空") + private Integer sort; + /** + * 备注 + */ + private String memo; + +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/dto/DataDictUpdateDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/dto/DataDictUpdateDTO.java new file mode 100644 index 00000000..3e75e9bb --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/dto/DataDictUpdateDTO.java @@ -0,0 +1,47 @@ +package cn.iocoder.mall.systemservice.rpc.datadict.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** +* 数据字典更新 DTO +*/ +@Data +@Accessors(chain = true) +public class DataDictUpdateDTO implements Serializable { + + /** + * 编号 + */ + @NotNull(message = "编号不能为空") + private Integer id; + /** + * 大类枚举值 + */ + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + /** + * 小类数值 + */ + @NotEmpty(message = "小类数值不能为空") + private String value; + /** + * 展示名 + */ + @NotEmpty(message = "展示名不能为空") + private String displayName; + /** + * 排序值 + */ + @NotNull(message = "排序值不能为空") + private Integer sort; + /** + * 备注 + */ + private String memo; + +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/vo/DataDictVO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/vo/DataDictVO.java new file mode 100644 index 00000000..9cabb4ad --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/vo/DataDictVO.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.systemservice.rpc.datadict.vo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +/** +* 数据字典 VO +*/ +@Data +@Accessors(chain = true) +public class DataDictVO implements Serializable { + + /** + * 编号 + */ + private Integer id; + /** + * 大类枚举值 + */ + private String enumValue; + /** + * 小类数值 + */ + private String value; + /** + * 展示名 + */ + private String displayName; + /** + * 排序值 + */ + private Integer sort; + /** + * 备注 + */ + private String memo; + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/datadict/DataDictConvert.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/datadict/DataDictConvert.java new file mode 100644 index 00000000..fc6d5369 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/datadict/DataDictConvert.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.systemservice.convert.datadict; + +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.datadict.DataDictDO; +import cn.iocoder.mall.systemservice.rpc.datadict.dto.DataDictCreateDTO; +import cn.iocoder.mall.systemservice.rpc.datadict.dto.DataDictUpdateDTO; +import cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO; +import cn.iocoder.mall.systemservice.service.datadict.bo.DataDictBO; +import cn.iocoder.mall.systemservice.service.datadict.bo.DataDictCreateBO; +import cn.iocoder.mall.systemservice.service.datadict.bo.DataDictUpdateBO; +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(DataDictCreateBO bean); + + DataDictBO convert(DataDictDO bean); + + DataDictDO convert(DataDictUpdateBO bean); + + List convertList(List list); + + DataDictCreateBO convert(DataDictCreateDTO bean); + + DataDictUpdateBO convert(DataDictUpdateDTO bean); + + DataDictVO convert(DataDictBO bean); + + List convertList02(List list); + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/admin/DepartmentDO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/admin/DepartmentDO.java index 21b4ed8d..1f3cc14d 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/admin/DepartmentDO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/admin/DepartmentDO.java @@ -9,7 +9,7 @@ import lombok.experimental.Accessors; /** * 部门实体 */ -@TableName(value = "department") +@TableName(value = "admin_department") @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/datadict/DataDictDO.java similarity index 85% rename from system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java rename to system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/datadict/DataDictDO.java index 091ed72a..61475c34 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/datadict/DataDictDO.java @@ -1,6 +1,6 @@ -package cn.iocoder.mall.admin.dataobject; +package cn.iocoder.mall.systemservice.dal.mysql.dataobject.datadict; -import cn.iocoder.common.framework.dataobject.DeletableDO; +import cn.iocoder.mall.mybatis.dataobject.DeletableDO; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/datadict/DataDictMapper.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/datadict/DataDictMapper.java new file mode 100644 index 00000000..9ef3b885 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/datadict/DataDictMapper.java @@ -0,0 +1,28 @@ +package cn.iocoder.mall.systemservice.dal.mysql.mapper.datadict; + +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.datadict.DataDictDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Repository; + +import java.util.Collection; +import java.util.List; + +@Repository +public interface DataDictMapper extends BaseMapper { + + default DataDictDO selectByEnumValueAndValue(String enumValue, String value) { + return selectOne(new QueryWrapper() + .eq("enumValue", enumValue).eq("value", value)); + } + + default List selectByEnumValueAndValues(String enumValue, Collection values) { + return selectList(new QueryWrapper() + .eq("enumValue", enumValue).in("value", values)); + } + + default List selectByEnumValue(String enumValue) { + return selectList(new QueryWrapper().eq("enumValue", enumValue)); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/datadict/DataDictManager.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/datadict/DataDictManager.java new file mode 100644 index 00000000..cb313a59 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/datadict/DataDictManager.java @@ -0,0 +1,84 @@ +package cn.iocoder.mall.systemservice.manager.datadict; + +import cn.iocoder.mall.systemservice.convert.datadict.DataDictConvert; +import cn.iocoder.mall.systemservice.rpc.datadict.dto.DataDictCreateDTO; +import cn.iocoder.mall.systemservice.rpc.datadict.dto.DataDictUpdateDTO; +import cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO; +import cn.iocoder.mall.systemservice.service.datadict.DataDictService; +import cn.iocoder.mall.systemservice.service.datadict.bo.DataDictBO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** +* 数据字典 Manager +*/ +@Service +public class DataDictManager { + + @Autowired + private DataDictService dataDictService; + + /** + * 创建数据字典 + * + * @param createDTO 创建数据字典 DTO + * @return 数据字典 + */ + public Integer createDataDict(DataDictCreateDTO createDTO) { + DataDictBO dataDictBO = dataDictService.createDataDict(DataDictConvert.INSTANCE.convert(createDTO)); + return dataDictBO.getId(); + } + + /** + * 更新数据字典 + * + * @param updateDTO 更新数据字典 DTO + */ + public void updateDataDict(DataDictUpdateDTO updateDTO) { + dataDictService.updateDataDict(DataDictConvert.INSTANCE.convert(updateDTO)); + } + + /** + * 删除数据字典 + * + * @param dataDictId 数据字典编号 + */ + public void deleteDataDict(Integer dataDictId) { + dataDictService.deleteDataDict(dataDictId); + } + + /** + * 获得数据字典 + * + * @param dataDictId 数据字典编号 + * @return 数据字典 + */ + public DataDictVO getDataDict(Integer dataDictId) { + DataDictBO dataDictBO = dataDictService.getDataDict(dataDictId); + return DataDictConvert.INSTANCE.convert(dataDictBO); + } + + /** + * 获得全部数据字典 + * + * @return 数据字典列表 + */ + public List listDataDicts() { + List dataDictBOs = dataDictService.listDataDicts(); + return DataDictConvert.INSTANCE.convertList02(dataDictBOs); + } + + /** + * 获得数据字典列表 + * + * @param dataDictIds 数据字典编号列表 + * @return 数据字典列表 + */ + public List listDataDicts(List dataDictIds) { + List dataDictBOs = dataDictService.listDataDicts(dataDictIds); + return DataDictConvert.INSTANCE.convertList02(dataDictBOs); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/DataDictRpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/DataDictRpcImpl.java new file mode 100644 index 00000000..faa15b80 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/datadict/DataDictRpcImpl.java @@ -0,0 +1,56 @@ +package cn.iocoder.mall.systemservice.rpc.datadict; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.systemservice.manager.datadict.DataDictManager; +import cn.iocoder.mall.systemservice.rpc.datadict.dto.DataDictCreateDTO; +import cn.iocoder.mall.systemservice.rpc.datadict.dto.DataDictUpdateDTO; +import cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO; +import org.apache.dubbo.config.annotation.Service; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** +* 数据字典 Rpc 实现类 +*/ +@Service(version = "${dubbo.provider.DataDictRpc.version}", validation = "false") +public class DataDictRpcImpl implements DataDictRpc { + + @Autowired + private DataDictManager dataDictManager; + + @Override + public CommonResult createDataDict(DataDictCreateDTO createDTO) { + return success(dataDictManager.createDataDict(createDTO)); + } + + @Override + public CommonResult updateDataDict(DataDictUpdateDTO updateDTO) { + dataDictManager.updateDataDict(updateDTO); + return success(true); + } + + @Override + public CommonResult deleteDataDict(Integer dataDictId) { + dataDictManager.deleteDataDict(dataDictId); + return success(true); + } + + @Override + public CommonResult getDataDict(Integer dataDictId) { + return success(dataDictManager.getDataDict(dataDictId)); + } + + @Override + public CommonResult> listDataDicts() { + return success(dataDictManager.listDataDicts()); + } + + @Override + public CommonResult> listDataDicts(List dataDictIds) { + return success(dataDictManager.listDataDicts(dataDictIds)); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/DataDictService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/DataDictService.java new file mode 100644 index 00000000..58488de3 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/DataDictService.java @@ -0,0 +1,153 @@ +package cn.iocoder.mall.systemservice.service.datadict; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.mall.systemservice.convert.datadict.DataDictConvert; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.datadict.DataDictDO; +import cn.iocoder.mall.systemservice.dal.mysql.mapper.datadict.DataDictMapper; +import cn.iocoder.mall.systemservice.service.datadict.bo.DataDictBO; +import cn.iocoder.mall.systemservice.service.datadict.bo.DataDictCreateBO; +import cn.iocoder.mall.systemservice.service.datadict.bo.DataDictUpdateBO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.List; + +import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*; + +/** +* 数据字典 Service +*/ +@Service +@Validated +public class DataDictService { + + @Autowired + private DataDictMapper dataDictMapper; + + /** + * 创建数据字典 + * + * @param createBO 创建数据字典 BO + * @return 数据字典 + */ + public DataDictBO createDataDict(@Valid DataDictCreateBO createBO) { + // 校验数据字典重复 + checkDataDict(createBO.getEnumValue(), createBO.getValue(), null); + // 插入到数据库 + DataDictDO dataDictDO = DataDictConvert.INSTANCE.convert(createBO); + dataDictMapper.insert(dataDictDO); + // 返回 + return DataDictConvert.INSTANCE.convert(dataDictDO); + } + + /** + * 更新数据字典 + * + * @param updateBO 更新数据字典 BO + */ + public void updateDataDict(@Valid DataDictUpdateBO updateBO) { + // 校验更新的数据字典是否存在 + if (dataDictMapper.selectById(updateBO.getId()) == null) { + throw ServiceExceptionUtil.exception(DATA_DICT_NOT_EXISTS); + } + // 校验数据字典重复 + checkDataDict(updateBO.getEnumValue(), updateBO.getValue(), updateBO.getId()); + // 更新到数据库 + DataDictDO updateObject = DataDictConvert.INSTANCE.convert(updateBO); + dataDictMapper.updateById(updateObject); + } + + /** + * 删除数据字典 + * + * @param dataDictId 数据字典编号 + */ + public void deleteDataDict(Integer dataDictId) { + // 校验删除的数据字典是否存在 + if (dataDictMapper.selectById(dataDictId) == null) { + throw ServiceExceptionUtil.exception(DATA_DICT_NOT_EXISTS); + } + // 标记删除 + dataDictMapper.deleteById(dataDictId); + } + + /** + * 获得数据字典 + * + * @param dataDictId 数据字典编号 + * @return 数据字典 + */ + public DataDictBO getDataDict(Integer dataDictId) { + DataDictDO dataDictDO = dataDictMapper.selectById(dataDictId); + return DataDictConvert.INSTANCE.convert(dataDictDO); + } + + /** + * 获得全部数据字典 + * + * @return 数据字典列表 + */ + public List listDataDicts() { + List dataDictDOs = dataDictMapper.selectList(null); + return DataDictConvert.INSTANCE.convertList(dataDictDOs); + } + + /** + * 获得数据字典列表 + * + * @param dataDictIds 数据字典编号列表 + * @return 数据字典列表 + */ + public List listDataDicts(List dataDictIds) { + List dataDictDOs = dataDictMapper.selectBatchIds(dataDictIds); + return DataDictConvert.INSTANCE.convertList(dataDictDOs); + } + + /** + * 校验数据字典是否合法 + * + * 1. 校验相同大类下,是否有相同的小类 + * + * @param enumValue 枚举大类 + * @param value 枚举小类 + * @param id 资源编号 + */ + private void checkDataDict(String enumValue, String value, Integer id) { + DataDictDO dataDict = dataDictMapper.selectByEnumValueAndValue(enumValue, value); + if (dataDict == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的资源 + if (id == null) { + throw ServiceExceptionUtil.exception(DATA_DICT_EXISTS); + } + if (!dataDict.getId().equals(id)) { + throw ServiceExceptionUtil.exception(DATA_DICT_EXISTS); + } + } + +// @Override +// public CommonResult getDataDict(String dictKey, Object dictValue) { +// DataDictDO dataDictDO = dataDictMapper.selectByEnumValueAndValue(dictKey, String.valueOf(dictValue)); +// DataDictBO dataDictBO = DataDictConvert.INSTANCE.convert(dataDictDO); +// return CommonResult.success(dataDictBO); +// } +// +// @Override +// public CommonResult> getDataDict(String dictKey) { +// List dataDictDOList = dataDictMapper.selectByEnumValue(dictKey); +// List dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList); +// return CommonResult.success(dataDictBOList); +// } +// +// @Override +// public CommonResult> getDataDictList(String dictKey, Collection dictValueList) { +// Set convertDictValueList = dictValueList.stream().map(String::valueOf).collect(Collectors.toSet()); +// List dataDictDOList = dataDictMapper.selectByEnumValueAndValues(dictKey, convertDictValueList); +// List dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList); +// return CommonResult.success(dataDictBOList); +// } + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/bo/datadict/DataDictBO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictBO.java similarity index 78% rename from system/system-service-api/src/main/java/cn/iocoder/mall/system/api/bo/datadict/DataDictBO.java rename to system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictBO.java index 71a0dd84..be27be7f 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/bo/datadict/DataDictBO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictBO.java @@ -1,17 +1,16 @@ -package cn.iocoder.mall.system.api.bo.datadict; +package cn.iocoder.mall.systemservice.service.datadict.bo; import lombok.Data; import lombok.experimental.Accessors; -import java.io.Serializable; import java.util.Date; /** - * 数据字典 BO - */ +* 数据字典 BO +*/ @Data @Accessors(chain = true) -public class DataDictBO implements Serializable { +public class DataDictBO { /** * 编号 diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictCreateBO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictCreateBO.java new file mode 100644 index 00000000..1611da8c --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictCreateBO.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.systemservice.service.datadict.bo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** +* 数据字典创建 BO +*/ +@Data +@Accessors(chain = true) +public class DataDictCreateBO { + + /** + * 大类枚举值 + */ + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + /** + * 小类数值 + */ + @NotEmpty(message = "小类数值不能为空") + private String value; + /** + * 展示名 + */ + @NotEmpty(message = "展示名不能为空") + private String displayName; + /** + * 排序值 + */ + @NotNull(message = "排序值不能为空") + private Integer sort; + /** + * 备注 + */ + private String memo; + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictUpdateBO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictUpdateBO.java new file mode 100644 index 00000000..229a797f --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/datadict/bo/DataDictUpdateBO.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.systemservice.service.datadict.bo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** +* 数据字典更新 BO +*/ +@Data +@Accessors(chain = true) +public class DataDictUpdateBO { + + /** + * 编号 + */ + @NotNull(message = "编号不能为空") + private Integer id; + /** + * 大类枚举值 + */ + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + /** + * 小类数值 + */ + @NotEmpty(message = "小类数值不能为空") + private String value; + /** + * 展示名 + */ + @NotEmpty(message = "展示名不能为空") + private String displayName; + /** + * 排序值 + */ + @NotNull(message = "排序值不能为空") + private Integer sort; + /** + * 备注 + */ + private String memo; + +} diff --git a/system-service-project/system-service-app/src/main/resources/application.yaml b/system-service-project/system-service-app/src/main/resources/application.yaml index be0854c1..81112d06 100644 --- a/system-service-project/system-service-app/src/main/resources/application.yaml +++ b/system-service-project/system-service-app/src/main/resources/application.yaml @@ -47,3 +47,5 @@ dubbo: version: 1.0.0 DepartmentRpc: version: 1.0.0 + DataDictRpc: + version: 1.0.0 diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/DeptmentConstants.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/DeptmentConstants.java deleted file mode 100644 index 2e94fe98..00000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/DeptmentConstants.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.mall.system.api.constant; - -/** - * Description: - * - * @author: zhenxianyimeng - * @date: 2019-06-16 - * @time: 23:15 - */ -public interface DeptmentConstants { - - /** - * 顶级部门的pid - */ - Integer PID_ROOT = 0; -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/DictKeyConstants.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/DictKeyConstants.java deleted file mode 100644 index 5fb26317..00000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/DictKeyConstants.java +++ /dev/null @@ -1,11 +0,0 @@ -package cn.iocoder.mall.system.api.constant; - -/** - * 字典 key - * - * @author Sin - * @time 2019/5/25 3:36 PM - */ -public class DictKeyConstants { - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/ResourceConstants.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/ResourceConstants.java deleted file mode 100644 index 58aee79f..00000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/ResourceConstants.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.mall.system.api.constant; - -/** - * 资源类型 - */ -public interface ResourceConstants { - - /** - * 类型 - 菜单 - */ - Integer TYPE_MENU = 1; - /** - * 类型 - 按钮 - */ - Integer TYPE_BUTTON = 2; - - /** - * 父资源编号 - 根节点 - */ - Integer PID_ROOT = 0; - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/ResourceTypeEnum.java b/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/ResourceTypeEnum.java deleted file mode 100644 index 94e3dd5e..00000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/ResourceTypeEnum.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.mall.system.api.constant; - -import cn.iocoder.common.framework.core.IntArrayValuable; - -import java.util.Arrays; - -/** - * 资源类型枚举 - */ -public enum ResourceTypeEnum implements IntArrayValuable { - - MENU(1, "菜单"), - BUTTON(2, "按钮"); - - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ResourceTypeEnum::getValue).toArray(); - - /** - * 资源类型 - */ - private Integer value; - /** - * 资源类型名 - */ - private String name; - - ResourceTypeEnum(Integer value, String name) { - this.value = value; - this.name = name; - } - - public Integer getValue() { - return value; - } - - public ResourceTypeEnum setValue(Integer value) { - this.value = value; - return this; - } - - public String getName() { - return name; - } - - public ResourceTypeEnum setName(String name) { - this.name = name; - return this; - } - - @Override - public int[] array() { - return ARRAYS; - } - -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java deleted file mode 100644 index 90bb43f1..00000000 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.mall.admin.dao; - -import cn.iocoder.mall.admin.dataobject.DataDictDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.Collection; -import java.util.List; - -@Repository -public interface DataDictMapper extends BaseMapper { - - DataDictDO selectByEnumValueAndValue( - @Param("enumValue") String enumValue, - @Param("value") String value - ); - - List selectByEnumValueAndValues( - @Param("enumValue") String enumValue, - @Param("values") Collection values - ); - - List selectByEnumValue( - @Param("enumValue") String enumValue - ); - - default List selectList() { - return selectList(new QueryWrapper<>()); - } - - -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java deleted file mode 100644 index 5c0ffe32..00000000 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java +++ /dev/null @@ -1,112 +0,0 @@ -package cn.iocoder.mall.admin.service; - -import cn.iocoder.common.framework.enums.DeletedStatusEnum; -import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.system.api.DataDictService; -import cn.iocoder.mall.system.api.bo.datadict.DataDictBO; -import cn.iocoder.mall.system.api.constant.AdminErrorCodeEnum; -import cn.iocoder.mall.system.api.dto.datadict.DataDictAddDTO; -import cn.iocoder.mall.system.api.dto.datadict.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.Collection; -import java.util.Date; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * 数据字典 Service - */ -@Service -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.DataDictService.version}") -public class DataDictServiceImpl implements DataDictService { - - @Autowired - private DataDictMapper dataDictMapper; - - @Override - public List selectDataDictList() { - List dataDicts = dataDictMapper.selectList(); - return DataDictConvert.INSTANCE.convert(dataDicts); - } - - @Override - public DataDictBO addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO) { - // 校验数据字典重复 - if (dataDictMapper.selectByEnumValueAndValue(dataDictAddDTO.getEnumValue(), dataDictAddDTO.getValue()) != null) { - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); - } - // 保存到数据库 - DataDictDO dataDict = DataDictConvert.INSTANCE.convert(dataDictAddDTO); - dataDict.setCreateTime(new Date()); - dataDict.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); - dataDictMapper.insert(dataDict); - // TODO 插入操作日志 - // 返回成功 - return DataDictConvert.INSTANCE.convert(dataDict); - } - - @Override - public Boolean updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO) { - // 校验数据字典不存在 - DataDictDO existsDataDict = dataDictMapper.selectById(dataDictUpdateDTO.getId()); - if (existsDataDict == null) { - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); - } - // 校验数据字典重复 - DataDictDO duplicateDataDict = dataDictMapper.selectByEnumValueAndValue(existsDataDict.getEnumValue(), dataDictUpdateDTO.getValue()); - if (duplicateDataDict != null && !duplicateDataDict.getId().equals(dataDictUpdateDTO.getId())) { - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); - } - // 更新到数据库 - DataDictDO updateDataDict = DataDictConvert.INSTANCE.convert(dataDictUpdateDTO); - dataDictMapper.updateById(updateDataDict); - // TODO 插入操作日志 - // 返回成功 - return true; - } - - // 一般情况下,不要删除数据字典。 - // 因为,业务数据正在使用该数据字典,删除后,可能有不可预知的问题。 - @Override - public Boolean deleteDataDict(Integer adminId, Integer dataDictId) { - // 校验数据字典不存在 - DataDictDO existsDataDict = dataDictMapper.selectById(dataDictId); - if (existsDataDict == null) { - throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); - } - // 标记删除 - dataDictMapper.deleteById(dataDictId); - // TODO 插入操作日志 - // 返回成功 - return true; - } - - @Override - public CommonResult getDataDict(String dictKey, Object dictValue) { - DataDictDO dataDictDO = dataDictMapper.selectByEnumValueAndValue(dictKey, String.valueOf(dictValue)); - DataDictBO dataDictBO = DataDictConvert.INSTANCE.convert(dataDictDO); - return CommonResult.success(dataDictBO); - } - - @Override - public CommonResult> getDataDict(String dictKey) { - List dataDictDOList = dataDictMapper.selectByEnumValue(dictKey); - List dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList); - return CommonResult.success(dataDictBOList); - } - - @Override - public CommonResult> getDataDictList(String dictKey, Collection dictValueList) { - Set convertDictValueList = dictValueList.stream().map(String::valueOf).collect(Collectors.toSet()); - List dataDictDOList = dataDictMapper.selectByEnumValueAndValues(dictKey, convertDictValueList); - List dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList); - return CommonResult.success(dataDictBOList); - } -} diff --git a/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml b/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml deleted file mode 100644 index 546d268c..00000000 --- a/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - id, enum_value, value, display_name, sort, - memo, create_time - - - - - - - - -