数据字典模块完成
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import lombok.experimental.Accessors;
|
||||
/**
|
||||
* 部门实体
|
||||
*/
|
||||
@TableName(value = "department")
|
||||
@TableName(value = "admin_department")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.mall.systemservice.dal.mysql.dataobject.datadict;
|
||||
|
||||
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
*
|
||||
* 使用 {@link #enumValue} 作为聚合。例如说:
|
||||
*
|
||||
* enumValue :gender 性别
|
||||
* value:1 男
|
||||
* value:2 女
|
||||
*/
|
||||
@TableName("data_dict")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DataDictDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 大类枚举值
|
||||
*/
|
||||
private String enumValue;
|
||||
/**
|
||||
* 小类数值
|
||||
*/
|
||||
private String value;
|
||||
/**
|
||||
* 展示名
|
||||
*/
|
||||
private String displayName;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String memo;
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.iocoder.mall.systemservice.service.datadict.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据字典 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DataDictBO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 大类枚举值
|
||||
*/
|
||||
private String enumValue;
|
||||
/**
|
||||
* 小类数值
|
||||
*/
|
||||
private String value;
|
||||
/**
|
||||
* 展示名
|
||||
*/
|
||||
private String displayName;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String memo;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user