parent
f7f27c9693
commit
f6bb33863f
@ -0,0 +1,12 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.dict.vo.data;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@ApiModel("字典数据创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysDictDataCreateReqVO extends SysDictDataBaseVO {
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.dict.vo.data;
|
||||
|
||||
import cn.iocoder.dashboard.framework.excel.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 字典数据 Excel 导出响应 VO
|
||||
*/
|
||||
@Data
|
||||
public class SysDictDataExcelRespVO {
|
||||
|
||||
@Excel(name = "字典编码", cellType = Excel.ColumnType.NUMERIC)
|
||||
private Long id;
|
||||
|
||||
@Excel(name = "字典排序", cellType = Excel.ColumnType.NUMERIC)
|
||||
private Integer sort;
|
||||
|
||||
@Excel(name = "字典标签")
|
||||
private String label;
|
||||
|
||||
@Excel(name = "字典键值")
|
||||
private String value;
|
||||
|
||||
@Excel(name = "字典类型")
|
||||
private String dictType;
|
||||
|
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.dict.vo.data;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@ApiModel("字典类型分页列表 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysDictDataPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "字典标签", example = "芋道")
|
||||
@Size(max = 100, message = "字典标签长度不能超过100个字符")
|
||||
private String label;
|
||||
|
||||
@ApiModelProperty(value = "字典类型", example = "sys_common_sex", notes = "模糊匹配")
|
||||
@Size(max = 100, message = "字典类型类型长度不能超过100个字符")
|
||||
private String dictType;
|
||||
|
||||
@ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.dict.vo.data;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("字典数据信息 Response VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysDictDataRespVO extends SysDictDataBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "字典数据编号", required = true, example = "1024")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.dict.vo.data;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("字典数据更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysDictDataUpdateReqVO extends SysDictDataBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "字典数据编号", required = true, example = "1024")
|
||||
@NotNull(message = "字典数据编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
||||
@ -1,11 +1,21 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.dict.vo.type;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@ApiModel("字典类型创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysDictTypeCreateReqVO extends SysDictTypeBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "字典类型", required = true, example = "sys_common_sex")
|
||||
@NotNull(message = "字典类型不能为空")
|
||||
@Size(max = 100, message = "字典类型类型长度不能超过100个字符")
|
||||
private String type;
|
||||
|
||||
}
|
||||
|
||||
@ -1,17 +1,36 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.dict.vo.type;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("字典类型分页列表 Request VO")
|
||||
@Data
|
||||
public class SysDictTypePageReqVO {
|
||||
public class SysDictTypePageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "字典类型名称", example = "芋道", notes = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "字典类型", example = "sys_common_sex", notes = "模糊匹配")
|
||||
@Size(max = 100, message = "字典类型类型长度不能超过100个字符")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,39 @@
|
||||
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.baomidou.mybatisplus.core.metadata.OrderItem.asc;
|
||||
|
||||
@Mapper
|
||||
public interface SysDictDataMapper extends BaseMapper<SysDictDataDO> {
|
||||
|
||||
default SysDictDataDO selectByLabel(String label) {
|
||||
return selectOne(new QueryWrapper<SysDictDataDO>().eq("label", label));
|
||||
}
|
||||
|
||||
default int selectCountByDictType(String dictType) {
|
||||
return selectCount(new QueryWrapper<SysDictDataDO>().eq("dict_type", dictType));
|
||||
}
|
||||
|
||||
default IPage<SysDictDataDO> selectList(SysDictDataPageReqVO reqVO) {
|
||||
return selectPage(MyBatisUtils.buildPage(reqVO),
|
||||
new QueryWrapperX<SysDictDataDO>().likeIfPresent("label", reqVO.getLabel())
|
||||
.likeIfPresent("dict_type", reqVO.getDictType())
|
||||
.eqIfPresent("status", reqVO.getStatus()))
|
||||
.addOrder(asc("dict_type"), asc("sort"));
|
||||
}
|
||||
|
||||
default List<SysDictDataDO> selectList() {
|
||||
return selectList(new QueryWrapper<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysDictTypeMapper extends BaseMapper<SysDictTypeDO> {
|
||||
|
||||
default IPage<SysDictTypeDO> selectList(SysDictTypePageReqVO reqVO) {
|
||||
return selectPage(MyBatisUtils.buildPage(reqVO),
|
||||
new QueryWrapperX<SysDictTypeDO>().likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("dict_type", reqVO.getType())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
default SysDictTypeDO selectByType(String type) {
|
||||
return selectOne(new QueryWrapperX<SysDictTypeDO>().eq("dict_type", type));
|
||||
}
|
||||
|
||||
default SysDictTypeDO selectByName(String name) {
|
||||
return selectOne(new QueryWrapperX<SysDictTypeDO>().eq("name", name));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.dict.impl;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.dict.SysDictTypeConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict.SysDictTypeMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService;
|
||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 字典类型 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
|
||||
@Resource
|
||||
private SysDictTypeServiceImpl self;
|
||||
@Resource
|
||||
private SysDictDataService dictDataService;
|
||||
|
||||
@Resource
|
||||
private SysDictTypeMapper dictTypeMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<SysDictTypeDO> pageDictTypes(SysDictTypePageReqVO reqVO) {
|
||||
return SysDictTypeConvert.INSTANCE.convertPage02(dictTypeMapper.selectList(reqVO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDictTypeDO getDictType(Long id) {
|
||||
return dictTypeMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDictTypeDO getDictType(String type) {
|
||||
return dictTypeMapper.selectByType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createDictType(SysDictTypeCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(null, reqVO.getName(), reqVO.getType());
|
||||
// 插入字典类型
|
||||
SysDictTypeDO dictType = SysDictTypeConvert.INSTANCE.convert(reqVO);
|
||||
dictTypeMapper.insert(dictType);
|
||||
return dictType.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDictType(SysDictTypeUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), null);
|
||||
// 更新字典类型
|
||||
SysDictTypeDO updateObj = SysDictTypeConvert.INSTANCE.convert(reqVO);
|
||||
dictTypeMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDictType(Long id) {
|
||||
// 执行删除
|
||||
self.deleteDictType0(id);
|
||||
// TODO 发送 MQ 消息
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteDictType0(Long id) {
|
||||
// 校验是否存在
|
||||
SysDictTypeDO dictType = this.checkDictTypeExists(id);
|
||||
// 校验是否有字典数据
|
||||
if (dictDataService.countByDictType(dictType.getType()) > 0) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_HAS_CHILDREN);
|
||||
}
|
||||
// 删除字典类型
|
||||
dictTypeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String name, String type) {
|
||||
// 校验自己存在
|
||||
checkDictTypeExists(id);
|
||||
// 校验字典类型的名字的唯一性
|
||||
checkDictTypeNameUnique(id, name);
|
||||
// 校验字典类型的类型的唯一性
|
||||
checkDictTypeUnique(id, type);
|
||||
}
|
||||
|
||||
private void checkDictTypeNameUnique(Long id, String type) {
|
||||
SysDictTypeDO dictType = dictTypeMapper.selectByName(type);
|
||||
if (dictType == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的字典类型
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NAME_DUPLICATE);
|
||||
}
|
||||
if (!dictType.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDictTypeUnique(Long id, String type) {
|
||||
SysDictTypeDO dictType = dictTypeMapper.selectByType(type);
|
||||
if (dictType == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的字典类型
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_TYPE_DUPLICATE);
|
||||
}
|
||||
if (!dictType.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_TYPE_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
private SysDictTypeDO checkDictTypeExists(Long id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
SysDictTypeDO dictType = dictTypeMapper.selectById(id);
|
||||
if (dictType == null) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_FOUND);
|
||||
}
|
||||
return dictType;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue