数据字典

This commit is contained in:
lijiaqi 2023-02-01 15:58:58 +08:00
parent 00f7864d74
commit 63ecf171fa
15 changed files with 1002 additions and 7 deletions

View File

@ -14,14 +14,19 @@ public interface UrlConstant {
String DEPT = API + "/dept"; String DEPT = API + "/dept";
String ROLE = API + "/role"; String ROLE = API + "/role";
String DICT_TYPE = API + "/dict_type";
String DICT_DATA = API + "/dict_data";
String PERSON = API + "/person"; String PERSON = API + "/person";
String COMPANY = API + "/company"; String COMPANY = API + "/company";
/** /**
* 重要说明该值为项目生成后的缺省密钥 * 重要说明该值为项目生成后的缺省密钥
* 在实际的应用中一定要为不同的项目或服务自行生成公钥和私钥并将 PRIVATE_KEY 的引用改为服务的配置项 * 在实际的应用中一定要为不同的项目或服务自行生成公钥和私钥并将 PRIVATE_KEY 的引用改为服务的配置项

View File

@ -27,11 +27,11 @@ public class Generator {
public static void main(String[] args) { public static void main(String[] args) {
//表名 //表名
String tableName = "t_lc_personnel"; String tableName = "t_sys_dict_data";
//表前缀 //表前缀
String tablePrefix = "t_lc_"; String tablePrefix = "t_sys_";
//作者 //作者
String author = "msf"; String author = "ljq";
generate(tableName, tablePrefix, author); generate(tableName, tablePrefix, author);
} }
@ -66,7 +66,7 @@ public class Generator {
//包配置 //包配置
PackageConfig pc = new PackageConfig(); PackageConfig pc = new PackageConfig();
pc.setParent("com.ydool.staff"); pc.setParent("com.ydool.system");
pc.setEntity("entity"); pc.setEntity("entity");
pc.setServiceImpl("service"); pc.setServiceImpl("service");
pc.setServiceImpl("service.impl"); pc.setServiceImpl("service.impl");

View File

@ -0,0 +1,156 @@
package com.ydool.system.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;
import com.ydool.common.base.BaseController;
import com.ydool.common.constant.UrlConstant;
import com.ydool.common.data.dto.AjaxResult;
import com.ydool.system.entity.DictData;
import com.ydool.system.request.DictDataRequest;
import com.ydool.system.request.IdsRequest;
import com.ydool.system.service.IDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(UrlConstant.DICT_DATA)
@Api(tags = "字典数据", value = "字典数据")
@ApiSupport(order = 7)
public class DictDataController extends BaseController {
@Autowired
private IDictDataService dictDataService;
/**
* 字典数据列表
*
* @param value
* @param column
* @param orderBy
* @param status
* @return
*/
@GetMapping(value = "list")
@ApiOperation(value = "字典数据列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "current", value = "当前页", dataType = "Integer"),
@ApiImplicitParam(name = "size", value = "每页条数", dataType = "Integer"),
@ApiImplicitParam(name = "value", value = "搜索框中的内容(只支持字符串类型)"),
@ApiImplicitParam(name = "column", value = "排序字段 字段名"),
@ApiImplicitParam(name = "orderBy", value = "排序顺序 降序desc升序asc"),
@ApiImplicitParam(name = "status", value = "启用状态", dataType = "Boolean"),
@ApiImplicitParam(name = "dataType", value = "字典类型编码"),
})
@ApiOperationSupport(
responses = @DynamicResponseParameters(properties = {
@DynamicParameter(name = "data", dataTypeClass = DictData.class)
}),
order = 1
)
public AjaxResult dictDataList(String value,
String column,
String orderBy,
Boolean status,
String dataType
) {
return dictDataService.dictDataList(getPage(), value, column, orderBy, status,dataType);
}
/**
* 字典数据详情
*
* @param id
* @return
*/
@GetMapping(value = "detail")
@ApiOperation(value = "字典数据详情")
@ApiOperationSupport(
responses = @DynamicResponseParameters(properties = {
@DynamicParameter(name = "data", dataTypeClass = DictData.class)
}), order = 2
)
@ApiImplicitParam(name = "id", value = "字典类型Id")
public AjaxResult dictDataDetail(String id) {
return dictDataService.dictDataDetail(id);
}
/**
* 保存字典数据
* @param dictDataRequest
* @return
*/
@PostMapping(value = "save")
@ApiOperation(value = "保存字典数据")
@ApiOperationSupport(order = 3)
public AjaxResult saveDictData(@RequestBody @Validated DictDataRequest dictDataRequest) {
return dictDataService.saveDictData(dictDataRequest);
}
/**
* 编辑字典数据
* @param id
* @param dictDataRequest
* @return
*/
@PutMapping(value = "edit")
@ApiOperation(value = "编辑字典数据")
@ApiImplicitParam(name = "id", value = "字典数据Id")
@ApiOperationSupport(order = 4)
public AjaxResult editDictData(String id, @RequestBody @Validated DictDataRequest dictDataRequest) {
return dictDataService.editDictData(id, dictDataRequest);
}
/**
* 单个删除字典数据
*
* @param id
* @return
*/
@DeleteMapping(value = "remove")
@ApiOperation(value = "删除字典数据")
@ApiImplicitParam(name = "id", value = "字典数据Id")
@ApiOperationSupport(order = 5)
public AjaxResult removeDictData(String id) {
return dictDataService.removeDictData(id);
}
/**
* 批量删除字典数据
*
* @param ids
* @return
*/
@PostMapping(value = "removeBatch")
@ApiOperation(value = "批量删除字典数据")
@ApiOperationSupport(order = 6)
public AjaxResult removeDictDatas(@RequestBody @Validated IdsRequest ids) {
return dictDataService.removeDictDatas(ids);
}
/**
* 根据数据类型获取数据字典
*
* @param dataType
* @return
*/
@GetMapping(value = "dictDataByDictType")
@ApiOperation(value = "根据数据类型获取数据字典")
@ApiOperationSupport(
responses = @DynamicResponseParameters(properties = {
@DynamicParameter(name = "data", dataTypeClass = DictData.class)
}), order = 7
)
@ApiImplicitParam(name = "id", value = "字典类型Id")
public AjaxResult dictDataByDictType(String dataType){
return dictDataService.dictDataByDictType(dataType);
}
}

View File

@ -0,0 +1,137 @@
package com.ydool.system.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;
import com.ydool.common.base.BaseController;
import com.ydool.common.constant.UrlConstant;
import com.ydool.common.data.dto.AjaxResult;
import com.ydool.system.entity.Config;
import com.ydool.system.entity.DictType;
import com.ydool.system.entity.Role;
import com.ydool.system.request.DictTypeRequest;
import com.ydool.system.request.IdsRequest;
import com.ydool.system.request.RoleRequest;
import com.ydool.system.service.IDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(UrlConstant.DICT_TYPE)
@Api(tags = "字典类型", value = "字典类型")
@ApiSupport(order = 6)
public class DictTypeController extends BaseController {
@Autowired
private IDictTypeService dictTypeService;
/**
* 字典类型列表
*
* @param value
* @param column
* @param orderBy
* @param status
* @return
*/
@GetMapping(value = "list")
@ApiOperation(value = "字典类型列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "current", value = "当前页", dataType = "Integer"),
@ApiImplicitParam(name = "size", value = "每页条数", dataType = "Integer"),
@ApiImplicitParam(name = "value", value = "搜索框中的内容(只支持字符串类型)"),
@ApiImplicitParam(name = "column", value = "排序字段 字段名"),
@ApiImplicitParam(name = "orderBy", value = "排序顺序 降序desc升序asc"),
@ApiImplicitParam(name = "status", value = "启用状态", dataType = "Boolean"),
})
@ApiOperationSupport(
responses = @DynamicResponseParameters(properties = {
@DynamicParameter(name = "data", dataTypeClass = DictType.class)
}),
order = 1
)
public AjaxResult dictTypeList(String value,
String column,
String orderBy,
Boolean status
) {
return dictTypeService.dictTypeList(getPage(), value, column, orderBy, status);
}
/**
* 字典类型详情
*
* @param id
* @return
*/
@GetMapping(value = "detail")
@ApiOperation(value = "字典类型详情")
@ApiOperationSupport(
responses = @DynamicResponseParameters(properties = {
@DynamicParameter(name = "data", dataTypeClass = DictType.class)
}), order = 2
)
@ApiImplicitParam(name = "id", value = "字典类型Id")
public AjaxResult dictTypeDetail(String id) {
return dictTypeService.dictTypeDetail(id);
}
/**
* 保存字典类型
* @param dictTypeRequest
* @return
*/
@PostMapping(value = "save")
@ApiOperation(value = "保存字典类型")
@ApiOperationSupport(order = 3)
public AjaxResult saveDictType(@RequestBody @Validated DictTypeRequest dictTypeRequest) {
return dictTypeService.saveDictType(dictTypeRequest);
}
/**
* 编辑字典类型
* @param id
* @param dictTypeRequest
* @return
*/
@PutMapping(value = "edit")
@ApiOperation(value = "编辑字典类型")
@ApiImplicitParam(name = "id", value = "字典类型Id")
@ApiOperationSupport(order = 4)
public AjaxResult editDictType(String id, @RequestBody @Validated DictTypeRequest dictTypeRequest) {
return dictTypeService.editDictType(id, dictTypeRequest);
}
/**
* 单个删除字典类型
*
* @param id
* @return
*/
@DeleteMapping(value = "remove")
@ApiOperation(value = "删除字典类型")
@ApiImplicitParam(name = "id", value = "字典类型Id")
@ApiOperationSupport(order = 5)
public AjaxResult removeDictType(String id) {
return dictTypeService.removeDictType(id);
}
/**
* 批量删除字典类型
*
* @param ids
* @return
*/
@PostMapping(value = "removeBatch")
@ApiOperation(value = "批量删除字典类型")
@ApiOperationSupport(order = 6)
public AjaxResult removeDictTypes(@RequestBody @Validated IdsRequest ids) {
return dictTypeService.removeDictTypes(ids);
}
}

View File

@ -50,7 +50,7 @@ public class RoleController extends BaseController {
}) })
@ApiOperationSupport( @ApiOperationSupport(
responses = @DynamicResponseParameters(properties = { responses = @DynamicResponseParameters(properties = {
@DynamicParameter(name = "data", dataTypeClass = Config.class) @DynamicParameter(name = "data", dataTypeClass = Role.class)
}), }),
order = 1 order = 1
) )
@ -111,7 +111,7 @@ public class RoleController extends BaseController {
/** /**
* 单个删除角色 * 单个删除角色
* *
* @param id 参数Id * @param id 角色Id
* @return * @return
*/ */
@DeleteMapping(value = "remove") @DeleteMapping(value = "remove")

View File

@ -0,0 +1,44 @@
package com.ydool.system.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ydool.common.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
* 字典数据表
* </p>
*
* @author ljq
* @since 2023-02-01
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("t_sys_dict_data")
@ApiModel(value="DictData对象", description="字典数据表")
public class DictData extends BaseEntity{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "字典编码")
private String dataType;
@ApiModelProperty(value = "字典标签")
private String label;
@ApiModelProperty(value = "字典键值")
private String value;
@ApiModelProperty(value = "字典排序")
private Integer sortNo;
@ApiModelProperty(value = "启用状态")
private Boolean status;
@ApiModelProperty(value = "备注")
private String remarks;
}

View File

@ -0,0 +1,41 @@
package com.ydool.system.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ydool.common.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
* 字典类型表
* </p>
*
* @author ljq
* @since 2023-02-01
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("t_sys_dict_type")
@ApiModel(value="DictType对象", description="字典类型表")
public class DictType extends BaseEntity{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "字典类型编码")
private String code;
@ApiModelProperty(value = "字典类型名称")
private String name;
@ApiModelProperty(value = "字典类型排序")
private Integer sortNo;
@ApiModelProperty(value = "启用状态")
private Boolean status;
@ApiModelProperty(value = "备注")
private String remarks;
}

View File

@ -0,0 +1,18 @@
package com.ydool.system.mapper;
import com.ydool.system.entity.DictData;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* 字典数据表 Mapper 接口
* </p>
*
* @author ljq
* @since 2023-02-01
*/
@Mapper
public interface DictDataMapper extends MPJBaseMapper<DictData> {
}

View File

@ -0,0 +1,18 @@
package com.ydool.system.mapper;
import com.ydool.system.entity.DictType;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* 字典类型表 Mapper 接口
* </p>
*
* @author ljq
* @since 2023-02-01
*/
@Mapper
public interface DictTypeMapper extends MPJBaseMapper<DictType> {
}

View File

@ -0,0 +1,33 @@
package com.ydool.system.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
public class DictDataRequest {
@ApiModelProperty(value = "字典类型编码")
@NotBlank(message = "字典类型编码不能为空")
private String dataType;
@ApiModelProperty(value = "字典标签")
@NotBlank(message = "字典标签不能为空")
private String label;
@ApiModelProperty(value = "字典键值")
@NotBlank(message = "字典键值不能为空")
private String value;
@ApiModelProperty(value = "字典排序")
@NotNull(message = "字典排序不能为空")
private Integer sortNo;
@ApiModelProperty(value = "启用状态")
@NotNull(message = "启用状态不能为空")
private Boolean status;
@ApiModelProperty(value = "备注")
private String remarks;
}

View File

@ -0,0 +1,31 @@
package com.ydool.system.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
public class DictTypeRequest {
@ApiModelProperty(value = "字典类型编码")
@NotBlank(message = "字典类型编码不能为空")
private String code;
@ApiModelProperty(value = "字典类型名称")
@NotBlank(message = "字典类型名称不能为空")
private String name;
@ApiModelProperty(value = "字典类型排序")
@NotNull(message = "字典排序不能为空")
private Integer sortNo;
@ApiModelProperty(value = "启用状态")
@NotNull(message = "启用状态不能为空")
private Boolean status;
@ApiModelProperty(value = "备注")
private String remarks;
}

View File

@ -0,0 +1,77 @@
package com.ydool.system.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ydool.common.data.dto.AjaxResult;
import com.ydool.system.request.DictDataRequest;
import com.ydool.system.request.IdsRequest;
import org.aspectj.weaver.loadtime.Aj;
/**
* <p>
* 字典数据表 服务类
* </p>
*
* @author ljq
* @since 2023-02-01
*/
public interface IDictDataService {
/**
* 保存字典数据
* @param dictDataRequest
* @return
*/
AjaxResult saveDictData(DictDataRequest dictDataRequest);
/**
* 编辑字典数据
* @param id
* @param dictDataRequest
* @return
*/
AjaxResult editDictData(String id,DictDataRequest dictDataRequest);
/**
* 删除字典数据
* @param id
* @return
*/
AjaxResult removeDictData(String id);
/**
* 批量删除字典数据
* @param ids
* @return
*/
AjaxResult removeDictDatas(IdsRequest ids);
/**
* 字典数据详情
* @param id
* @return
*/
AjaxResult dictDataDetail(String id);
/**
* 字典数据列表
* @param page
* @param value
* @param column
* @param orderBy
* @param status
* @param dataType
* @return
*/
AjaxResult dictDataList(Page page, String value, String column, String orderBy, Boolean status,String dataType);
/**
* 根据数据类型获取数据字典
* @param dataType
* @return
*/
AjaxResult dictDataByDictType(String dataType);
}

View File

@ -0,0 +1,67 @@
package com.ydool.system.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ydool.common.data.dto.AjaxResult;
import com.ydool.system.request.DictTypeRequest;
import com.ydool.system.request.IdsRequest;
/**
* <p>
* 字典类型表 服务类
* </p>
*
* @author ljq
* @since 2023-02-01
*/
public interface IDictTypeService {
/**
* 保存字典类型
* @param dictTypeRequest
* @return
*/
AjaxResult saveDictType(DictTypeRequest dictTypeRequest);
/**
* 编辑字典类型
* @param id
* @param dictTypeRequest
* @return
*/
AjaxResult editDictType(String id,DictTypeRequest dictTypeRequest);
/**
* 删除字典类型
*
* @param id
* @return
*/
AjaxResult removeDictType(String id);
/**
* 批量删除字典类型
* @param ids
* @return
*/
AjaxResult removeDictTypes(IdsRequest ids);
/**
* 字典类型详情
* @param id
* @return
*/
AjaxResult dictTypeDetail(String id);
/**
* 字典类型列表
* @param page
* @param value
* @param column
* @param orderBy
* @param status
* @return
*/
AjaxResult dictTypeList(Page page, String value, String column, String orderBy, Boolean status);
}

View File

@ -0,0 +1,209 @@
package com.ydool.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ydool.common.base.BaseService;
import com.ydool.common.data.dto.AjaxResult;
import com.ydool.system.entity.DictData;
import com.ydool.system.entity.DictType;
import com.ydool.system.mapper.DictDataMapper;
import com.ydool.system.request.DictDataRequest;
import com.ydool.system.request.IdsRequest;
import com.ydool.system.service.IDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
/**
* <p>
* 字典数据表 服务类
* </p>
*
* @author ljq
* @since 2023-02-01
*/
@Service
public class DictDataServiceImpl extends BaseService<DictDataMapper, DictData> implements IDictDataService {
@Autowired
private DictTypeServiceImpl dictTypeService;
/**
* 保存字典数据
*
* @param dictDataRequest
* @return
*/
@Override
public AjaxResult saveDictData(DictDataRequest dictDataRequest) {
String message = checkDictData("", dictDataRequest);
if (StrUtil.isNotBlank(message)) return AjaxResult.fail(message);
DictData dictData = BeanUtil.copyProperties(dictDataRequest, DictData.class);
boolean flag = save(dictData);
return flag ? AjaxResult.ok().msg("保存成功") : AjaxResult.fail("保存失败");
}
/**
* 编辑字典数据
*
* @param id
* @param dictDataRequest
* @return
*/
@Override
public AjaxResult editDictData(String id, DictDataRequest dictDataRequest) {
if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空");
String message = checkDictData("", dictDataRequest);
if (StrUtil.isNotBlank(message)) return AjaxResult.fail(message);
DictData dictData = getById(id);
if (ObjectUtil.isNull(dictData)) return AjaxResult.fail("该字典数据不存在");
BeanUtil.copyProperties(dictDataRequest, dictData);
boolean flag = updateById(dictData);
return flag ? AjaxResult.ok().msg("编辑成功") : AjaxResult.fail("编辑失败");
}
/**
* 删除字典数据
*
* @param id
* @return
*/
@Override
public AjaxResult removeDictData(String id) {
if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空");
DictData dictData = getById(id);
if (ObjectUtil.isNull(dictData)) return AjaxResult.fail("该字典数据不存在");
return removeById(id) ? AjaxResult.ok().msg("删除成功") : AjaxResult.fail("删除失败");
}
/**
* 批量删除字典数据
*
* @param ids
* @return
*/
@Override
public AjaxResult removeDictDatas(IdsRequest ids) {
String[] idList = ids.getIds();
if (ArrayUtil.isEmpty(idList)) return AjaxResult.fail("字典数据集合不能为空");
List<DictData> dictDataList = listByIds(Arrays.asList(idList));
if (CollUtil.isEmpty(dictDataList)) return AjaxResult.fail("该字典数据集合全部不存在");
return removeByIds(Arrays.asList(idList)) ? AjaxResult.ok().msg("批量删除成功") : AjaxResult.fail("批量删除失败");
}
/**
* 字典数据详情
*
* @param id
* @return
*/
@Override
public AjaxResult dictDataDetail(String id) {
if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空");
DictData dictData = getById(id);
if (ObjectUtil.isNull(dictData)) return AjaxResult.fail("该字典数据不存在");
return AjaxResult.ok().data(dictData);
}
/**
* 字典数据列表
*
* @param page
* @param value
* @param column
* @param orderBy
* @param status
* @param dataType
* @return
*/
@Override
public AjaxResult dictDataList(Page page, String value, String column, String orderBy, Boolean status,
String dataType) {
DictType dictType = dictTypeService.getOne(new QueryWrapper<DictType>().lambda()
.eq(DictType::getCode, dataType)
.last("limit 1")
);
if (ObjectUtil.isNull(dictType)) return AjaxResult.fail("字典类型编码不存在");
QueryWrapper<DictData> qw = new QueryWrapper<DictData>();
if (StrUtil.isNotBlank(value)) {
qw.lambda().like(DictData::getLabel, value)
.or().like(DictData::getRemarks, value)
.or().like(DictData::getValue, value);
}
qw.lambda().eq(ObjectUtil.isNotNull(status), DictData::getStatus, status)
.eq(DictData::getDataType, dataType);
if ("desc".equals(orderBy) && StrUtil.isNotBlank(column)) {
qw.orderByDesc(StrUtil.toUnderlineCase(column));
}
if ("asc".equals(orderBy) && StrUtil.isNotBlank(column)) {
qw.orderByAsc(StrUtil.toUnderlineCase(column));
}
Page<DictData> pageList = page(page, qw);
return AjaxResult.ok().data(pageList);
}
/**
* 根据数据类型获取数据字典
*
* @param dataType
* @return
*/
@Override
public AjaxResult dictDataByDictType(String dataType) {
DictType dictType = dictTypeService.getOne(new QueryWrapper<DictType>().lambda()
.eq(DictType::getCode, dataType)
.eq(DictType::getStatus, true)
.last("limit 1")
);
if (ObjectUtil.isNull(dictType)) return AjaxResult.fail("字典类型编码不存在或禁用");
QueryWrapper<DictData> qw = new QueryWrapper<DictData>();
qw.lambda().eq(DictData::getStatus, true)
.eq(DictData::getDataType, dataType)
.orderByAsc(DictData::getSortNo);
List<DictData> dictDataList = list(qw);
return AjaxResult.ok().data(dictDataList);
}
/**
* 校验字典数据
*
* @param id
* @param dictDataRequest
* @return
*/
private String checkDictData(String id, DictDataRequest dictDataRequest) {
DictType dictType = dictTypeService.getOne(new QueryWrapper<DictType>().lambda()
.eq(DictType::getCode, dictDataRequest.getDataType())
.last("limit 1")
);
if (ObjectUtil.isNull(dictType)) return "字典类型编码不存在";
DictData dictData = getOne(new QueryWrapper<DictData>().lambda()
.eq(DictData::getLabel, dictDataRequest.getLabel())
.eq(DictData::getDataType, dictDataRequest.getDataType())
.ne(StrUtil.isNotBlank(id), DictData::getId, id)
);
if (ObjectUtil.isNotNull(dictData)) return "字典标签不允许重复";
return null;
}
}

View File

@ -0,0 +1,159 @@
package com.ydool.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ydool.common.data.dto.AjaxResult;
import com.ydool.system.entity.DictType;
import com.ydool.common.base.BaseService;
import com.ydool.system.entity.Role;
import com.ydool.system.mapper.DictTypeMapper;
import com.ydool.system.request.DictTypeRequest;
import com.ydool.system.request.IdsRequest;
import com.ydool.system.service.IDictTypeService;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
/**
* <p>
* 字典类型表 服务类
* </p>
*
* @author ljq
* @since 2023-02-01
*/
@Service
public class DictTypeServiceImpl extends BaseService<DictTypeMapper, DictType> implements IDictTypeService {
/**
* 保存字典类型
* @param dictTypeRequest
* @return
*/
@Override
public AjaxResult saveDictType(DictTypeRequest dictTypeRequest) {
String message = checkDictType("", dictTypeRequest);
if (StrUtil.isNotBlank(message)) return AjaxResult.fail(message);
DictType dictType = BeanUtil.copyProperties(dictTypeRequest, DictType.class);
boolean flag = save(dictType);
return flag ? AjaxResult.ok().msg("保存成功") : AjaxResult.fail("保存失败");
}
/**
* 编辑字典类型
* @param id
* @param dictTypeRequest
* @return
*/
@Override
public AjaxResult editDictType(String id, DictTypeRequest dictTypeRequest) {
if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空");
String message = checkDictType("", dictTypeRequest);
if (StrUtil.isNotBlank(message)) return AjaxResult.fail(message);
DictType dictType = getById(id);
if (ObjectUtil.isNull(dictType)) return AjaxResult.fail("该字典类型不存在");
BeanUtil.copyProperties(dictTypeRequest, dictType);
boolean flag = updateById(dictType);
return flag ? AjaxResult.ok().msg("编辑成功") : AjaxResult.fail("编辑失败");
}
/**
* 删除字典类型
*
* @param id
* @return
*/
@Override
public AjaxResult removeDictType(String id) {
if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空");
DictType dictType = getById(id);
if (ObjectUtil.isNull(dictType)) return AjaxResult.fail("该字典类型不存在");
return removeById(id) ? AjaxResult.ok().msg("删除成功") : AjaxResult.fail("删除失败");
}
/**
* 批量删除字典类型
* @param ids
* @return
*/
@Override
public AjaxResult removeDictTypes(IdsRequest ids) {
String[] idList = ids.getIds();
if (ArrayUtil.isEmpty(idList)) return AjaxResult.fail("字典类型集合不能为空");
List<DictType> dictTypeList = listByIds(Arrays.asList(idList));
if (CollUtil.isEmpty(dictTypeList)) return AjaxResult.fail("该字典类型集合全部不存在");
return removeByIds(Arrays.asList(idList)) ? AjaxResult.ok().msg("批量删除成功") : AjaxResult.fail("批量删除失败");
}
/**
* 字典类型详情
* @param id
* @return
*/
@Override
public AjaxResult dictTypeDetail(String id) {
if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空");
DictType dictType = getById(id);
if (ObjectUtil.isNull(dictType)) return AjaxResult.fail("该字典类型不存在");
return AjaxResult.ok().data(dictType);
}
/**
* 字典类型列表
* @param page
* @param value
* @param column
* @param orderBy
* @param status
* @return
*/
@Override
public AjaxResult dictTypeList(Page page, String value, String column, String orderBy, Boolean status) {
QueryWrapper<DictType> qw = new QueryWrapper<DictType>();
if (StrUtil.isNotBlank(value)) {
qw.lambda().like(DictType::getName, value)
.or().like(DictType::getRemarks, value)
.or().like(DictType::getCode, value);
}
qw.lambda().eq(ObjectUtil.isNotNull(status), DictType::getStatus, status);
if ("desc".equals(orderBy) && StrUtil.isNotBlank(column)) {
qw.orderByDesc(StrUtil.toUnderlineCase(column));
}
if ("asc".equals(orderBy) && StrUtil.isNotBlank(column)) {
qw.orderByAsc(StrUtil.toUnderlineCase(column));
}
Page<DictType> pageList = page(page, qw);
return AjaxResult.ok().data(pageList);
}
/**
* 校验字典类型
* @param id
* @param dictTypeRequest
* @return
*/
private String checkDictType(String id,DictTypeRequest dictTypeRequest) {
DictType dictType = getOne(new QueryWrapper<DictType>().lambda()
.eq(DictType::getCode, dictTypeRequest.getCode())
.ne(StrUtil.isNotBlank(id), DictType::getId, id)
.last("limit 1")
);
if (ObjectUtil.isNotNull(dictType)) return "字典类型编码不能重复";
return null;
}
}