数据字典模块完成
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,8 @@ dubbo:
|
||||
version: 1.0.0
|
||||
DepartmentRpc:
|
||||
version: 1.0.0
|
||||
DataDictRpc:
|
||||
version: 1.0.0
|
||||
|
||||
# Swagger 配置项
|
||||
swagger:
|
||||
|
||||
Reference in New Issue
Block a user