mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-20 05:55:07 +08:00
完成 dict type 的单元测试
This commit is contained in:
@ -24,12 +24,12 @@ public interface BaseMapperX<T> extends BaseMapper<T> {
|
||||
return new PageResult<>(mpPage.getRecords(), mpPage.getTotal());
|
||||
}
|
||||
|
||||
default List<T> selectList() {
|
||||
return selectList(new QueryWrapper<>());
|
||||
}
|
||||
|
||||
default T selectOne(String field, Object value) {
|
||||
return selectOne(new QueryWrapper<T>().eq(field, value));
|
||||
}
|
||||
|
||||
default List<T> selectList() {
|
||||
return selectList(new QueryWrapper<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class SysDictTypeController {
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:list')")
|
||||
public CommonResult<PageResult<SysDictTypeRespVO>> pageDictTypes(@Validated SysDictTypePageReqVO reqVO) {
|
||||
return success(SysDictTypeConvert.INSTANCE.convertPage(dictTypeService.pageDictTypes(reqVO)));
|
||||
return success(SysDictTypeConvert.INSTANCE.convertPage(dictTypeService.getDictTypePage(reqVO)));
|
||||
}
|
||||
|
||||
@ApiOperation("/查询字典类型详细")
|
||||
@ -75,7 +75,7 @@ public class SysDictTypeController {
|
||||
@ApiOperation(value = "获得全部字典类型列表", notes = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项")
|
||||
// 无需添加权限认证,因为前端全局都需要
|
||||
public CommonResult<List<SysDictTypeSimpleRespVO>> listSimpleDictTypes() {
|
||||
List<SysDictTypeDO> list = dictTypeService.listDictTypes();
|
||||
List<SysDictTypeDO> list = dictTypeService.getDictTypeList();
|
||||
return success(SysDictTypeConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ public class SysDictTypeController {
|
||||
// @Log(title = "字典类型", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:export')")
|
||||
public void export(HttpServletResponse response, @Validated SysDictTypeExportReqVO reqVO) throws IOException {
|
||||
List<SysDictTypeDO> list = dictTypeService.listDictTypes(reqVO);
|
||||
List<SysDictTypeDO> list = dictTypeService.getDictTypeList(reqVO);
|
||||
List<SysDictTypeExcelVO> excelTypeList = SysDictTypeConvert.INSTANCE.convertList02(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "字典类型.xls", "类型列表",
|
||||
|
@ -5,7 +5,6 @@ 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;
|
||||
@ -18,18 +17,17 @@ public class SysDictTypeExportReqVO {
|
||||
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 = "开始创建时间")
|
||||
private Date beginCreateTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
@ApiModelProperty(value = "结束创建时间")
|
||||
private Date endCreateTime;
|
||||
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ public class SysDictTypePageReqVO extends PageParam {
|
||||
@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 = "开始创建时间")
|
||||
private Date beginCreateTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
@ApiModelProperty(value = "结束创建时间")
|
||||
private Date endCreateTime;
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class SysDictTypeDO extends BaseDO {
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
@TableField("dict_type")
|
||||
@TableField("`type`")
|
||||
private String type;
|
||||
/**
|
||||
* 状态
|
||||
|
@ -16,20 +16,21 @@ public interface SysDictTypeMapper extends BaseMapperX<SysDictTypeDO> {
|
||||
default PageResult<SysDictTypeDO> selectPage(SysDictTypePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<SysDictTypeDO>()
|
||||
.likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("dict_type", reqVO.getType())
|
||||
.likeIfPresent("`type`", reqVO.getType())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()));
|
||||
}
|
||||
|
||||
default List<SysDictTypeDO> selectList(SysDictTypeExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<SysDictTypeDO>().likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("dict_type", reqVO.getType())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
return selectList(new QueryWrapperX<SysDictTypeDO>()
|
||||
.likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("`type`", reqVO.getType())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()));
|
||||
}
|
||||
|
||||
default SysDictTypeDO selectByType(String type) {
|
||||
return selectOne(new QueryWrapperX<SysDictTypeDO>().eq("dict_type", type));
|
||||
return selectOne(new QueryWrapperX<SysDictTypeDO>().eq("`type`", type));
|
||||
}
|
||||
|
||||
default SysDictTypeDO selectByName(String name) {
|
||||
|
@ -58,7 +58,7 @@ public interface SysErrorCodeConstants {
|
||||
ErrorCode POST_CODE_DUPLICATE = new ErrorCode(1002005001, "已经存在该标识的岗位");
|
||||
|
||||
// ========== 字典类型 1002006000 ==========
|
||||
ErrorCode DICT_TYPE_NOT_FOUND = new ErrorCode(1002006001, "当前字典类型不存在");
|
||||
ErrorCode DICT_TYPE_NOT_EXISTS = new ErrorCode(1002006001, "当前字典类型不存在");
|
||||
ErrorCode DICT_TYPE_NOT_ENABLE = new ErrorCode(1002006002, "字典类型不处于开启状态,不允许选择");
|
||||
ErrorCode DICT_TYPE_NAME_DUPLICATE = new ErrorCode(1002006003, "已经存在该名字的字典类型");
|
||||
ErrorCode DICT_TYPE_TYPE_DUPLICATE = new ErrorCode(1002006004, "已经存在该类型的字典类型");
|
||||
|
@ -22,7 +22,7 @@ public interface SysDictTypeService {
|
||||
* @param reqVO 分页请求
|
||||
* @return 字典类型分页列表
|
||||
*/
|
||||
PageResult<SysDictTypeDO> pageDictTypes(SysDictTypePageReqVO reqVO);
|
||||
PageResult<SysDictTypeDO> getDictTypePage(SysDictTypePageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得字典类型列表
|
||||
@ -30,7 +30,7 @@ public interface SysDictTypeService {
|
||||
* @param reqVO 列表请求
|
||||
* @return 字典类型列表
|
||||
*/
|
||||
List<SysDictTypeDO> listDictTypes(SysDictTypeExportReqVO reqVO);
|
||||
List<SysDictTypeDO> getDictTypeList(SysDictTypeExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得字典类型详情
|
||||
@ -75,6 +75,6 @@ public interface SysDictTypeService {
|
||||
*
|
||||
* @return 字典类型列表
|
||||
*/
|
||||
List<SysDictTypeDO> listDictTypes();
|
||||
List<SysDictTypeDO> getDictTypeList();
|
||||
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
||||
private void checkDictTypeValid(String type) {
|
||||
SysDictTypeDO dictType = dictTypeService.getDictType(type);
|
||||
if (dictType == null) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_FOUND);
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_EXISTS);
|
||||
}
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(dictType.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_ENABLE);
|
||||
|
@ -1,14 +1,13 @@
|
||||
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.SysDictTypeExportReqVO;
|
||||
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.dict.SysDictTypeMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictTypeDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dict.SysDictTypeMapper;
|
||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService;
|
||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -16,6 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
@ -33,12 +33,12 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
private SysDictTypeMapper dictTypeMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<SysDictTypeDO> pageDictTypes(SysDictTypePageReqVO reqVO) {
|
||||
public PageResult<SysDictTypeDO> getDictTypePage(SysDictTypePageReqVO reqVO) {
|
||||
return dictTypeMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictTypeDO> listDictTypes(SysDictTypeExportReqVO reqVO) {
|
||||
public List<SysDictTypeDO> getDictTypeList(SysDictTypeExportReqVO reqVO) {
|
||||
return dictTypeMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@ -77,14 +77,14 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
SysDictTypeDO dictType = this.checkDictTypeExists(id);
|
||||
// 校验是否有字典数据
|
||||
if (dictDataService.countByDictType(dictType.getType()) > 0) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_HAS_CHILDREN);
|
||||
throw exception(DICT_TYPE_HAS_CHILDREN);
|
||||
}
|
||||
// 删除字典类型
|
||||
dictTypeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictTypeDO> listDictTypes() {
|
||||
public List<SysDictTypeDO> getDictTypeList() {
|
||||
return dictTypeMapper.selectList();
|
||||
}
|
||||
|
||||
@ -104,10 +104,10 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的字典类型
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NAME_DUPLICATE);
|
||||
throw exception(DICT_TYPE_NAME_DUPLICATE);
|
||||
}
|
||||
if (!dictType.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NAME_DUPLICATE);
|
||||
throw exception(DICT_TYPE_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,10 +118,10 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的字典类型
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_TYPE_DUPLICATE);
|
||||
throw exception(DICT_TYPE_TYPE_DUPLICATE);
|
||||
}
|
||||
if (!dictType.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_TYPE_DUPLICATE);
|
||||
throw exception(DICT_TYPE_TYPE_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
}
|
||||
SysDictTypeDO dictType = dictTypeMapper.selectById(id);
|
||||
if (dictType == null) {
|
||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_FOUND);
|
||||
throw exception(DICT_TYPE_NOT_EXISTS);
|
||||
}
|
||||
return dictType;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package cn.iocoder.dashboard.util.collection;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
* Array 工具类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public class ArrayUtils {
|
||||
|
||||
/**
|
||||
* 将 object 和 newElements 合并成一个数组
|
||||
*
|
||||
* @param object 对象
|
||||
* @param newElements 数组
|
||||
* @param <T> 泛型
|
||||
* @return 结果数组
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> T[] append(T object, T... newElements) {
|
||||
if (object == null) {
|
||||
return newElements;
|
||||
}
|
||||
T[] result = ArrayUtil.newArray(object.getClass(), 1 + newElements.length);
|
||||
result[0] = object;
|
||||
System.arraycopy(newElements, 0, result, 1, newElements.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user