数据字典模块完成

This commit is contained in:
YunaiV 2020-07-15 08:48:24 +08:00
parent ac9d5f32f7
commit e1e42c0ce0
31 changed files with 993 additions and 299 deletions

View File

@ -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<Integer> createDataDict(@Valid DataDictCreateDTO createDTO) {
return success(dataDictManager.createDataDict(createDTO));
}
@PostMapping("/update")
@ApiOperation("更新数据字典")
public CommonResult<Boolean> updateDataDict(@Valid DataDictUpdateDTO updateDTO) {
dataDictManager.updateDataDict(updateDTO);
return success(true);
}
@PostMapping("/delete")
@ApiOperation("删除数据字典")
@ApiImplicitParam(name = "dataDictId", value = "数据字典编号", required = true)
public CommonResult<Boolean> deleteDataDict(@RequestParam("dataDictId") Integer dataDictId) {
dataDictManager.deleteDataDict(dataDictId);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得数据字典")
@ApiImplicitParam(name = "dataDictId", value = "数据字典编号", required = true)
public CommonResult<DataDictVO> getDataDict(@RequestParam("dataDictId") Integer dataDictId) {
return success(dataDictManager.getDataDict(dataDictId));
}
@GetMapping("/list")
@ApiOperation("获得数据字典列表")
@ApiImplicitParam(name = "dataDictIds", value = "数据字典编号列表", required = true)
public CommonResult<List<DataDictVO>> listDataDicts(@RequestParam("dataDictIds") List<Integer> dataDictIds) {
return success(dataDictManager.listDataDicts(dataDictIds));
}
@GetMapping("/list-all")
@ApiOperation("获得全部数据字典列表")
public CommonResult<List<DataDictVO>> listDataDicts() {
return success(dataDictManager.listDataDicts());
}
@GetMapping("/list-all-simple")
@ApiOperation(value = "获得全部数据字典列表", notes = "一般用于管理后台缓存数据字典在本地")
public CommonResult<List<DataDictSimpleVO>> listSimpleDataDicts() {
return success(dataDictManager.listSimpleDataDicts());
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<DataDictVO> convertList(List<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO> list);
List<DataDictSimpleVO> convertList02(List<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO> list);
}

View File

@ -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<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO> 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<Integer> createDataDictResult = dataDictRpc.createDataDict(DataDictConvert.INSTANCE.convert(createDTO));
createDataDictResult.checkError();
return createDataDictResult.getData();
}
/**
* 更新数据字典
*
* @param updateDTO 更新数据字典 DTO
*/
public void updateDataDict(DataDictUpdateDTO updateDTO) {
CommonResult<Boolean> updateDataDictResult = dataDictRpc.updateDataDict(DataDictConvert.INSTANCE.convert(updateDTO));
updateDataDictResult.checkError();
}
/**
* 删除数据字典
*
* @param dataDictId 数据字典编号
*/
public void deleteDataDict(Integer dataDictId) {
CommonResult<Boolean> deleteDataDictResult = dataDictRpc.deleteDataDict(dataDictId);
deleteDataDictResult.checkError();
}
/**
* 获得数据字典
*
* @param dataDictId 数据字典编号
* @return 数据字典
*/
public DataDictVO getDataDict(Integer dataDictId) {
CommonResult<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO> getDataDictResult = dataDictRpc.getDataDict(dataDictId);
getDataDictResult.checkError();
return DataDictConvert.INSTANCE.convert(getDataDictResult.getData());
}
/**
* 获得数据字典列表
*
* @param dataDictIds 数据字典编号列表
* @return 数据字典列表
*/
public List<DataDictVO> listDataDicts(List<Integer> dataDictIds) {
CommonResult<List<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO>> listDataDictResult = dataDictRpc.listDataDicts(dataDictIds);
listDataDictResult.checkError();
return DataDictConvert.INSTANCE.convertList(listDataDictResult.getData());
}
/**
* 获得全部数据字典
*
* @return 数据字典列表
*/
public List<DataDictVO> listDataDicts() {
CommonResult<List<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO>> listDataDictResult = dataDictRpc.listDataDicts();
listDataDictResult.checkError();
// 按照 enumValue sort 排序
listDataDictResult.getData().sort(COMPARATOR_ENUM_VALUE_SORT);
return DataDictConvert.INSTANCE.convertList(listDataDictResult.getData());
}
/**
* 获得全部数据字典
*
* 精简返回字段
*
* @return 数据字典列表
*/
public List<DataDictSimpleVO> listSimpleDataDicts() {
CommonResult<List<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO>> listDataDictResult = dataDictRpc.listDataDicts();
listDataDictResult.checkError();
// 按照 enumValue sort 排序
listDataDictResult.getData().sort(COMPARATOR_ENUM_VALUE_SORT);
return DataDictConvert.INSTANCE.convertList02(listDataDictResult.getData());
}
}

View File

@ -38,6 +38,8 @@ dubbo:
version: 1.0.0 version: 1.0.0
DepartmentRpc: DepartmentRpc:
version: 1.0.0 version: 1.0.0
DataDictRpc:
version: 1.0.0
# Swagger 配置项 # Swagger 配置项
swagger: swagger:

View File

@ -50,8 +50,8 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable<Syste
ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE(1002004005, "不能删除类型为系统内置的角色"), ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE(1002004005, "不能删除类型为系统内置的角色"),
// ========== 数据字典模块 1002005000 ========== // ========== 数据字典模块 1002005000 ==========
// DATA_DICT_EXISTS(1002005000, "该数据字典已经存在"), DATA_DICT_EXISTS(1002005000, "该数据字典已经存在"),
// DATA_DICT_NOT_EXISTS(1002005001, "该数据字典不存在"), DATA_DICT_NOT_EXISTS(1002005001, "该数据字典不存在"),
// ========== 短信模板 1002006000 ========== // ========== 短信模板 1002006000 ==========
SMS_PLATFORM_FAIL(1002006000, "短信平台调用失败【具体错误会动态替换】"), SMS_PLATFORM_FAIL(1002006000, "短信平台调用失败【具体错误会动态替换】"),

View File

@ -0,0 +1,60 @@
package cn.iocoder.mall.systemservice.rpc.datadict;
import cn.iocoder.common.framework.vo.CommonResult;
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 java.util.List;
/**
* 数据字典 Rpc 接口
*/
public interface DataDictRpc {
/**
* 创建数据字典
*
* @param createDTO 创建数据字典 DTO
* @return 数据字典编号
*/
CommonResult<Integer> createDataDict(DataDictCreateDTO createDTO);
/**
* 更新数据字典
*
* @param updateDTO 更新数据字典 DTO
*/
CommonResult<Boolean> updateDataDict(DataDictUpdateDTO updateDTO);
/**
* 删除数据字典
*
* @param dataDictId 数据字典编号
*/
CommonResult<Boolean> deleteDataDict(Integer dataDictId);
/**
* 获得数据字典
*
* @param dataDictId 数据字典编号
* @return 数据字典
*/
CommonResult<DataDictVO> getDataDict(Integer dataDictId);
/**
* 获得全部数据字典
*
* @return 数据字典列表
*/
CommonResult<List<DataDictVO>> listDataDicts();
/**
* 获得数据字典列表
*
* @param dataDictIds 数据字典编号列表
* @return 数据字典列表
*/
CommonResult<List<DataDictVO>> listDataDicts(List<Integer> dataDictIds);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<DataDictBO> convertList(List<DataDictDO> list);
DataDictCreateBO convert(DataDictCreateDTO bean);
DataDictUpdateBO convert(DataDictUpdateDTO bean);
DataDictVO convert(DataDictBO bean);
List<DataDictVO> convertList02(List<DataDictBO> list);
}

View File

@ -9,7 +9,7 @@ import lombok.experimental.Accessors;
/** /**
* 部门实体 * 部门实体
*/ */
@TableName(value = "department") @TableName(value = "admin_department")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Accessors(chain = true) @Accessors(chain = true)

View File

@ -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 com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;

View File

@ -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<DataDictDO> {
default DataDictDO selectByEnumValueAndValue(String enumValue, String value) {
return selectOne(new QueryWrapper<DataDictDO>()
.eq("enumValue", enumValue).eq("value", value));
}
default List<DataDictDO> selectByEnumValueAndValues(String enumValue, Collection<String> values) {
return selectList(new QueryWrapper<DataDictDO>()
.eq("enumValue", enumValue).in("value", values));
}
default List<DataDictDO> selectByEnumValue(String enumValue) {
return selectList(new QueryWrapper<DataDictDO>().eq("enumValue", enumValue));
}
}

View File

@ -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<DataDictVO> listDataDicts() {
List<DataDictBO> dataDictBOs = dataDictService.listDataDicts();
return DataDictConvert.INSTANCE.convertList02(dataDictBOs);
}
/**
* 获得数据字典列表
*
* @param dataDictIds 数据字典编号列表
* @return 数据字典列表
*/
public List<DataDictVO> listDataDicts(List<Integer> dataDictIds) {
List<DataDictBO> dataDictBOs = dataDictService.listDataDicts(dataDictIds);
return DataDictConvert.INSTANCE.convertList02(dataDictBOs);
}
}

View File

@ -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<Integer> createDataDict(DataDictCreateDTO createDTO) {
return success(dataDictManager.createDataDict(createDTO));
}
@Override
public CommonResult<Boolean> updateDataDict(DataDictUpdateDTO updateDTO) {
dataDictManager.updateDataDict(updateDTO);
return success(true);
}
@Override
public CommonResult<Boolean> deleteDataDict(Integer dataDictId) {
dataDictManager.deleteDataDict(dataDictId);
return success(true);
}
@Override
public CommonResult<DataDictVO> getDataDict(Integer dataDictId) {
return success(dataDictManager.getDataDict(dataDictId));
}
@Override
public CommonResult<List<DataDictVO>> listDataDicts() {
return success(dataDictManager.listDataDicts());
}
@Override
public CommonResult<List<DataDictVO>> listDataDicts(List<Integer> dataDictIds) {
return success(dataDictManager.listDataDicts(dataDictIds));
}
}

View File

@ -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<DataDictBO> listDataDicts() {
List<DataDictDO> dataDictDOs = dataDictMapper.selectList(null);
return DataDictConvert.INSTANCE.convertList(dataDictDOs);
}
/**
* 获得数据字典列表
*
* @param dataDictIds 数据字典编号列表
* @return 数据字典列表
*/
public List<DataDictBO> listDataDicts(List<Integer> dataDictIds) {
List<DataDictDO> 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<DataDictBO> 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<List<DataDictBO>> getDataDict(String dictKey) {
// List<DataDictDO> dataDictDOList = dataDictMapper.selectByEnumValue(dictKey);
// List<DataDictBO> dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList);
// return CommonResult.success(dataDictBOList);
// }
//
// @Override
// public CommonResult<List<DataDictBO>> getDataDictList(String dictKey, Collection<?> dictValueList) {
// Set<String> convertDictValueList = dictValueList.stream().map(String::valueOf).collect(Collectors.toSet());
// List<DataDictDO> dataDictDOList = dataDictMapper.selectByEnumValueAndValues(dictKey, convertDictValueList);
// List<DataDictBO> dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList);
// return CommonResult.success(dataDictBOList);
// }
}

View File

@ -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.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
/** /**
* 数据字典 BO * 数据字典 BO
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class DataDictBO implements Serializable { public class DataDictBO {
/** /**
* 编号 * 编号

View File

@ -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;
}

View File

@ -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;
}

View File

@ -47,3 +47,5 @@ dubbo:
version: 1.0.0 version: 1.0.0
DepartmentRpc: DepartmentRpc:
version: 1.0.0 version: 1.0.0
DataDictRpc:
version: 1.0.0

View File

@ -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;
}

View File

@ -1,11 +0,0 @@
package cn.iocoder.mall.system.api.constant;
/**
* 字典 key
*
* @author Sin
* @time 2019/5/25 3:36 PM
*/
public class DictKeyConstants {
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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> {
DataDictDO selectByEnumValueAndValue(
@Param("enumValue") String enumValue,
@Param("value") String value
);
List<DataDictDO> selectByEnumValueAndValues(
@Param("enumValue") String enumValue,
@Param("values") Collection<String> values
);
List<DataDictDO> selectByEnumValue(
@Param("enumValue") String enumValue
);
default List<DataDictDO> selectList() {
return selectList(new QueryWrapper<>());
}
}

View File

@ -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<DataDictBO> selectDataDictList() {
List<DataDictDO> 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<DataDictBO> 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<List<DataDictBO>> getDataDict(String dictKey) {
List<DataDictDO> dataDictDOList = dataDictMapper.selectByEnumValue(dictKey);
List<DataDictBO> dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList);
return CommonResult.success(dataDictBOList);
}
@Override
public CommonResult<List<DataDictBO>> getDataDictList(String dictKey, Collection<?> dictValueList) {
Set<String> convertDictValueList = dictValueList.stream().map(String::valueOf).collect(Collectors.toSet());
List<DataDictDO> dataDictDOList = dataDictMapper.selectByEnumValueAndValues(dictKey, convertDictValueList);
List<DataDictBO> dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList);
return CommonResult.success(dataDictBOList);
}
}

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.admin.dao.DataDictMapper">
<sql id="FIELDS">
id, enum_value, value, display_name, sort,
memo, create_time
</sql>
<select id="selectByEnumValueAndValue" resultType="DataDictDO">
SELECT
<include refid="FIELDS"/>
FROM data_dict
WHERE enum_value = #{enumValue}
AND value = #{value}
AND deleted = 0
LIMIT 1
</select>
<select id="selectByEnumValueAndValues" resultType="cn.iocoder.mall.admin.dataobject.DataDictDO">
SELECT
<include refid="FIELDS"/>
FROM data_dict
WHERE deleted = 0
AND enum_value = #{enumValue}
AND `value` IN
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</select>
<select id="selectByEnumValue" resultType="cn.iocoder.mall.admin.dataobject.DataDictDO">
SELECT
<include refid="FIELDS"/>
FROM data_dict
WHERE deleted = 0
AND enum_value = #{enumValue}
</select>
</mapper>