mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
Merge branch 'master' into unit_system_dept
This commit is contained in:
commit
b86fb4c3f5
@ -43,11 +43,12 @@
|
|||||||
1. 幂等组件:基于 Redis 实现幂等组件,解决重复请求问题
|
1. 幂等组件:基于 Redis 实现幂等组件,解决重复请求问题
|
||||||
1. 服务保障:基于 Resilience4j 实现服务的稳定性,包括限流、熔断等功能
|
1. 服务保障:基于 Resilience4j 实现服务的稳定性,包括限流、熔断等功能
|
||||||
1. 日志服务:轻量级日志中心,查看远程服务器的日志
|
1. 日志服务:轻量级日志中心,查看远程服务器的日志
|
||||||
|
1. 单元测试:基于 JUnit + Mockito 实现单元测试,保证功能的正确性、代码的质量等
|
||||||
|
|
||||||
### 研发工具
|
### 研发工具
|
||||||
|
|
||||||
1. 表单构建:拖动表单元素生成相应的 HTML 代码
|
1. 表单构建:拖动表单元素生成相应的 HTML 代码
|
||||||
1. 代码生成:前后端代码的生成(Java、Vue、SQL),支持 CRUD 下载
|
1. 代码生成:前后端代码的生成(Java、Vue、SQL、单元测试),支持 CRUD 下载
|
||||||
1. 系统接口:基于 Swagger 自动生成相关的 RESTful API 接口文档
|
1. 系统接口:基于 Swagger 自动生成相关的 RESTful API 接口文档
|
||||||
1. 数据库文档:基于 Screw 自动生成数据库文档
|
1. 数据库文档:基于 Screw 自动生成数据库文档
|
||||||
|
|
||||||
@ -83,7 +84,9 @@
|
|||||||
| [Spring Boot Admin](https://github.com/skywalking) | Spring Boot 监控平台 | 8.6.0 | [文档](http://www.iocoder.cn/Spring-Boot/Admin/?yudao) |
|
| [Spring Boot Admin](https://github.com/skywalking) | Spring Boot 监控平台 | 8.6.0 | [文档](http://www.iocoder.cn/Spring-Boot/Admin/?yudao) |
|
||||||
| [Jackson](https://github.com/FasterXML/jackson) | JSON 工具库 | 2.11.4 | |
|
| [Jackson](https://github.com/FasterXML/jackson) | JSON 工具库 | 2.11.4 | |
|
||||||
| [MapStruct](https://mapstruct.org/) | Java Bean 转换 | 1.4.1 | [文档](http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao) |
|
| [MapStruct](https://mapstruct.org/) | Java Bean 转换 | 1.4.1 | [文档](http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao) |
|
||||||
| [Lombok](https://projectlombok.org/) | 消除冗长的 Java 代码| 1.16.14 | [文档](http://www.iocoder.cn/Spring-Boot/Lombok/?yudao) |
|
| [Lombok](https://projectlombok.org/) | 消除冗长的 Java 代码 | 1.16.14 | [文档](http://www.iocoder.cn/Spring-Boot/Lombok/?yudao) |
|
||||||
|
| [JUnit](https://junit.org/junit5/) | Java 单元测试框架 | 5.7.0 | - |
|
||||||
|
| [Mockito](https://github.com/mockito/mockito) | Java Mock 框架 | 3.6.28 | - |
|
||||||
|
|
||||||
**前端**
|
**前端**
|
||||||
|
|
||||||
@ -125,7 +128,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><img src="https://oscimg.oschina.net/oscnet/b6115bc8c31de52951982e509930b20684a.jpg"/></td>
|
<td><img src="https://oscimg.oschina.net/oscnet/b6115bc8c31de52951982e509930b20684a.jpg"/></td>
|
||||||
<td><img src="https://oscimg.oschina.net/oscnet/up-6d73c2140ce694e3de4c05035fdc1868d4c.png"/></td>
|
<td> - </td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="创建时间">
|
<el-form-item label="创建时间">
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-model="dateRange"
|
v-model="dateRangeCreateTime"
|
||||||
size="small"
|
size="small"
|
||||||
style="width: 240px"
|
style="width: 240px"
|
||||||
value-format="yyyy-MM-dd"
|
value-format="yyyy-MM-dd"
|
||||||
@ -177,7 +177,7 @@ export default {
|
|||||||
// 状态数据字典
|
// 状态数据字典
|
||||||
statusOptions: [],
|
statusOptions: [],
|
||||||
// 日期范围
|
// 日期范围
|
||||||
dateRange: [],
|
dateRangeCreateTime: [],
|
||||||
// 查询参数
|
// 查询参数
|
||||||
queryParams: {
|
queryParams: {
|
||||||
pageNo: 1,
|
pageNo: 1,
|
||||||
@ -211,15 +211,15 @@ export default {
|
|||||||
/** 查询字典类型列表 */
|
/** 查询字典类型列表 */
|
||||||
getList() {
|
getList() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
listType(this.addDateRange(this.queryParams, [
|
// 处理查询参数
|
||||||
this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
|
let params = {...this.queryParams};
|
||||||
this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
|
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
|
||||||
])).then(response => {
|
// 执行查询
|
||||||
this.typeList = response.data.list;
|
listType(params).then(response => {
|
||||||
this.total = response.data.total;
|
this.typeList = response.data.list;
|
||||||
this.loading = false;
|
this.total = response.data.total;
|
||||||
}
|
this.loading = false;
|
||||||
);
|
});
|
||||||
},
|
},
|
||||||
// 字典状态字典翻译
|
// 字典状态字典翻译
|
||||||
statusFormat(row, column) {
|
statusFormat(row, column) {
|
||||||
@ -248,7 +248,7 @@ export default {
|
|||||||
},
|
},
|
||||||
/** 重置按钮操作 */
|
/** 重置按钮操作 */
|
||||||
resetQuery() {
|
resetQuery() {
|
||||||
this.dateRange = [];
|
this.dateRangeCreateTime = [];
|
||||||
this.resetForm("queryForm");
|
this.resetForm("queryForm");
|
||||||
this.handleQuery();
|
this.handleQuery();
|
||||||
},
|
},
|
||||||
@ -304,19 +304,21 @@ export default {
|
|||||||
},
|
},
|
||||||
/** 导出按钮操作 */
|
/** 导出按钮操作 */
|
||||||
handleExport() {
|
handleExport() {
|
||||||
const queryParams = this.addDateRange(this.queryParams, [
|
// 处理查询参数
|
||||||
this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
|
let params = {...this.queryParams};
|
||||||
this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
|
params.pageNo = undefined;
|
||||||
]);
|
params.pageSize = undefined;
|
||||||
this.$confirm('是否确认导出所有类型数据项?', "警告", {
|
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
|
||||||
confirmButtonText: "确定",
|
// 执行导出
|
||||||
cancelButtonText: "取消",
|
this.$confirm('是否确认导出所有字典类型数据项?', "警告", {
|
||||||
type: "warning"
|
confirmButtonText: "确定",
|
||||||
}).then(function() {
|
cancelButtonText: "取消",
|
||||||
return exportType(queryParams);
|
type: "warning"
|
||||||
}).then(response => {
|
}).then(function() {
|
||||||
this.downloadExcel(response, '数据类型.xls');
|
return exportType(params);
|
||||||
})
|
}).then(response => {
|
||||||
|
this.downloadExcel(response, '字典类型.xls');
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -24,12 +24,12 @@ public interface BaseMapperX<T> extends BaseMapper<T> {
|
|||||||
return new PageResult<>(mpPage.getRecords(), mpPage.getTotal());
|
return new PageResult<>(mpPage.getRecords(), mpPage.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<T> selectList() {
|
|
||||||
return selectList(new QueryWrapper<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
default T selectOne(String field, Object value) {
|
default T selectOne(String field, Object value) {
|
||||||
return selectOne(new QueryWrapper<T>().eq(field, value));
|
return selectOne(new QueryWrapper<T>().eq(field, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<T> selectList() {
|
||||||
|
return selectList(new QueryWrapper<>());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
<http://www.iocoder.cn/Spring-Boot/Spring-Security/?github>
|
|
@ -0,0 +1 @@
|
|||||||
|
<https://www.iocoder.cn/Spring-Boot/Resilience4j/?yudao>
|
@ -27,9 +27,10 @@ public class WebConfiguration implements WebMvcConfigurer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configurePathMatch(PathMatchConfigurer configurer) {
|
public void configurePathMatch(PathMatchConfigurer configurer) {
|
||||||
|
// 设置 API 前缀,仅仅匹配 controller 包下的
|
||||||
configurer.addPathPrefix(webProperties.getApiPrefix(), clazz ->
|
configurer.addPathPrefix(webProperties.getApiPrefix(), clazz ->
|
||||||
clazz.isAnnotationPresent(RestController.class)
|
clazz.isAnnotationPresent(RestController.class)
|
||||||
&& clazz.getPackage().getName().startsWith(webProperties.getControllerPackage()));
|
&& clazz.getPackage().getName().startsWith(webProperties.getControllerPackage())); // 仅仅匹配 controller 包
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== Filter 相关 ==========
|
// ========== Filter 相关 ==========
|
||||||
|
@ -32,7 +32,7 @@ public class SysDictDataController {
|
|||||||
@GetMapping("/list-all-simple")
|
@GetMapping("/list-all-simple")
|
||||||
// 无需添加权限认证,因为前端全局都需要
|
// 无需添加权限认证,因为前端全局都需要
|
||||||
public CommonResult<List<SysDictDataSimpleVO>> listSimpleDictDatas() {
|
public CommonResult<List<SysDictDataSimpleVO>> listSimpleDictDatas() {
|
||||||
List<SysDictDataDO> list = dictDataService.listDictDatas();
|
List<SysDictDataDO> list = dictDataService.getDictDataList();
|
||||||
return success(SysDictDataConvert.INSTANCE.convertList(list));
|
return success(SysDictDataConvert.INSTANCE.convertList(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public class SysDictDataController {
|
|||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
// @PreAuthorize("@ss.hasPermi('system:dict:list')")
|
// @PreAuthorize("@ss.hasPermi('system:dict:list')")
|
||||||
public CommonResult<PageResult<SysDictDataRespVO>> pageDictTypes(@Validated SysDictDataPageReqVO reqVO) {
|
public CommonResult<PageResult<SysDictDataRespVO>> pageDictTypes(@Validated SysDictDataPageReqVO reqVO) {
|
||||||
return success(SysDictDataConvert.INSTANCE.convertPage(dictDataService.pageDictDatas(reqVO)));
|
return success(SysDictDataConvert.INSTANCE.convertPage(dictDataService.getDictDataPage(reqVO)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("/查询字典数据详细")
|
@ApiOperation("/查询字典数据详细")
|
||||||
@ -83,7 +83,7 @@ public class SysDictDataController {
|
|||||||
// @Log(title = "字典类型", businessType = BusinessType.EXPORT)
|
// @Log(title = "字典类型", businessType = BusinessType.EXPORT)
|
||||||
// @PreAuthorize("@ss.hasPermi('system:dict:export')")
|
// @PreAuthorize("@ss.hasPermi('system:dict:export')")
|
||||||
public void export(HttpServletResponse response, @Validated SysDictDataExportReqVO reqVO) throws IOException {
|
public void export(HttpServletResponse response, @Validated SysDictDataExportReqVO reqVO) throws IOException {
|
||||||
List<SysDictDataDO> list = dictDataService.listDictDatas(reqVO);
|
List<SysDictDataDO> list = dictDataService.getDictDataList(reqVO);
|
||||||
List<SysDictDataExcelVO> excelDataList = SysDictDataConvert.INSTANCE.convertList02(list);
|
List<SysDictDataExcelVO> excelDataList = SysDictDataConvert.INSTANCE.convertList02(list);
|
||||||
// 输出
|
// 输出
|
||||||
ExcelUtils.write(response, "字典数据.xls", "数据列表",
|
ExcelUtils.write(response, "字典数据.xls", "数据列表",
|
||||||
|
@ -32,7 +32,7 @@ public class SysDictTypeController {
|
|||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
// @PreAuthorize("@ss.hasPermi('system:dict:list')")
|
// @PreAuthorize("@ss.hasPermi('system:dict:list')")
|
||||||
public CommonResult<PageResult<SysDictTypeRespVO>> pageDictTypes(@Validated SysDictTypePageReqVO reqVO) {
|
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("/查询字典类型详细")
|
@ApiOperation("/查询字典类型详细")
|
||||||
@ -75,7 +75,7 @@ public class SysDictTypeController {
|
|||||||
@ApiOperation(value = "获得全部字典类型列表", notes = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项")
|
@ApiOperation(value = "获得全部字典类型列表", notes = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项")
|
||||||
// 无需添加权限认证,因为前端全局都需要
|
// 无需添加权限认证,因为前端全局都需要
|
||||||
public CommonResult<List<SysDictTypeSimpleRespVO>> listSimpleDictTypes() {
|
public CommonResult<List<SysDictTypeSimpleRespVO>> listSimpleDictTypes() {
|
||||||
List<SysDictTypeDO> list = dictTypeService.listDictTypes();
|
List<SysDictTypeDO> list = dictTypeService.getDictTypeList();
|
||||||
return success(SysDictTypeConvert.INSTANCE.convertList(list));
|
return success(SysDictTypeConvert.INSTANCE.convertList(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ public class SysDictTypeController {
|
|||||||
// @Log(title = "字典类型", businessType = BusinessType.EXPORT)
|
// @Log(title = "字典类型", businessType = BusinessType.EXPORT)
|
||||||
// @PreAuthorize("@ss.hasPermi('system:dict:export')")
|
// @PreAuthorize("@ss.hasPermi('system:dict:export')")
|
||||||
public void export(HttpServletResponse response, @Validated SysDictTypeExportReqVO reqVO) throws IOException {
|
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);
|
List<SysDictTypeExcelVO> excelTypeList = SysDictTypeConvert.INSTANCE.convertList02(list);
|
||||||
// 输出
|
// 输出
|
||||||
ExcelUtils.write(response, "字典类型.xls", "类型列表",
|
ExcelUtils.write(response, "字典类型.xls", "类型列表",
|
||||||
|
@ -16,7 +16,7 @@ public class SysDictDataBaseVO {
|
|||||||
|
|
||||||
@ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024")
|
@ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024")
|
||||||
@NotBlank(message = "显示顺序不能为空")
|
@NotBlank(message = "显示顺序不能为空")
|
||||||
private String sort;
|
private Integer sort;
|
||||||
|
|
||||||
@ApiModelProperty(value = "字典标签", required = true, example = "芋道")
|
@ApiModelProperty(value = "字典标签", required = true, example = "芋道")
|
||||||
@NotBlank(message = "字典标签不能为空")
|
@NotBlank(message = "字典标签不能为空")
|
||||||
|
@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
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;
|
private String name;
|
||||||
|
|
||||||
@ApiModelProperty(value = "字典类型", example = "sys_common_sex", notes = "模糊匹配")
|
@ApiModelProperty(value = "字典类型", example = "sys_common_sex", notes = "模糊匹配")
|
||||||
@Size(max = 100, message = "字典类型类型长度不能超过100个字符")
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
|
@ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24")
|
|
||||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
@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)
|
@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 枚举类")
|
@ApiModelProperty(value = "展示状态", example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24")
|
|
||||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
@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)
|
@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;
|
private String type;
|
||||||
/**
|
/**
|
||||||
* 状态
|
* 状态
|
||||||
|
@ -16,20 +16,21 @@ public interface SysDictTypeMapper extends BaseMapperX<SysDictTypeDO> {
|
|||||||
default PageResult<SysDictTypeDO> selectPage(SysDictTypePageReqVO reqVO) {
|
default PageResult<SysDictTypeDO> selectPage(SysDictTypePageReqVO reqVO) {
|
||||||
return selectPage(reqVO, new QueryWrapperX<SysDictTypeDO>()
|
return selectPage(reqVO, new QueryWrapperX<SysDictTypeDO>()
|
||||||
.likeIfPresent("name", reqVO.getName())
|
.likeIfPresent("name", reqVO.getName())
|
||||||
.likeIfPresent("dict_type", reqVO.getType())
|
.likeIfPresent("`type`", reqVO.getType())
|
||||||
.eqIfPresent("status", reqVO.getStatus())
|
.eqIfPresent("status", reqVO.getStatus())
|
||||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<SysDictTypeDO> selectList(SysDictTypeExportReqVO reqVO) {
|
default List<SysDictTypeDO> selectList(SysDictTypeExportReqVO reqVO) {
|
||||||
return selectList(new QueryWrapperX<SysDictTypeDO>().likeIfPresent("name", reqVO.getName())
|
return selectList(new QueryWrapperX<SysDictTypeDO>()
|
||||||
.likeIfPresent("dict_type", reqVO.getType())
|
.likeIfPresent("name", reqVO.getName())
|
||||||
.eqIfPresent("status", reqVO.getStatus())
|
.likeIfPresent("`type`", reqVO.getType())
|
||||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
.eqIfPresent("status", reqVO.getStatus())
|
||||||
|
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
default SysDictTypeDO selectByType(String type) {
|
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) {
|
default SysDictTypeDO selectByName(String name) {
|
||||||
|
@ -58,14 +58,14 @@ public interface SysErrorCodeConstants {
|
|||||||
ErrorCode POST_CODE_DUPLICATE = new ErrorCode(1002005001, "已经存在该标识的岗位");
|
ErrorCode POST_CODE_DUPLICATE = new ErrorCode(1002005001, "已经存在该标识的岗位");
|
||||||
|
|
||||||
// ========== 字典类型 1002006000 ==========
|
// ========== 字典类型 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_NOT_ENABLE = new ErrorCode(1002006002, "字典类型不处于开启状态,不允许选择");
|
||||||
ErrorCode DICT_TYPE_NAME_DUPLICATE = new ErrorCode(1002006003, "已经存在该名字的字典类型");
|
ErrorCode DICT_TYPE_NAME_DUPLICATE = new ErrorCode(1002006003, "已经存在该名字的字典类型");
|
||||||
ErrorCode DICT_TYPE_TYPE_DUPLICATE = new ErrorCode(1002006004, "已经存在该类型的字典类型");
|
ErrorCode DICT_TYPE_TYPE_DUPLICATE = new ErrorCode(1002006004, "已经存在该类型的字典类型");
|
||||||
ErrorCode DICT_TYPE_HAS_CHILDREN = new ErrorCode(1002006004, "无法删除,该字典类型还有字典数据");
|
ErrorCode DICT_TYPE_HAS_CHILDREN = new ErrorCode(1002006004, "无法删除,该字典类型还有字典数据");
|
||||||
|
|
||||||
// ========== 字典数据 1002007000 ==========
|
// ========== 字典数据 1002007000 ==========
|
||||||
ErrorCode DICT_DATA_NOT_FOUND = new ErrorCode(1002007001, "当前字典数据不存在");
|
ErrorCode DICT_DATA_NOT_EXISTS = new ErrorCode(1002007001, "当前字典数据不存在");
|
||||||
ErrorCode DICT_DATA_NOT_ENABLE = new ErrorCode(1002007002, "字典数据不处于开启状态,不允许选择");
|
ErrorCode DICT_DATA_NOT_ENABLE = new ErrorCode(1002007002, "字典数据不处于开启状态,不允许选择");
|
||||||
ErrorCode DICT_DATA_VALUE_DUPLICATE = new ErrorCode(1002007003, "已经存在该值的字典数据");
|
ErrorCode DICT_DATA_VALUE_DUPLICATE = new ErrorCode(1002007003, "已经存在该值的字典数据");
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public interface SysDictDataService extends DictDataFrameworkService {
|
|||||||
*
|
*
|
||||||
* @return 字典数据全列表
|
* @return 字典数据全列表
|
||||||
*/
|
*/
|
||||||
List<SysDictDataDO> listDictDatas();
|
List<SysDictDataDO> getDictDataList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得字典数据分页列表
|
* 获得字典数据分页列表
|
||||||
@ -35,7 +35,7 @@ public interface SysDictDataService extends DictDataFrameworkService {
|
|||||||
* @param reqVO 分页请求
|
* @param reqVO 分页请求
|
||||||
* @return 字典数据分页列表
|
* @return 字典数据分页列表
|
||||||
*/
|
*/
|
||||||
PageResult<SysDictDataDO> pageDictDatas(SysDictDataPageReqVO reqVO);
|
PageResult<SysDictDataDO> getDictDataPage(SysDictDataPageReqVO reqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得字典数据列表
|
* 获得字典数据列表
|
||||||
@ -43,7 +43,7 @@ public interface SysDictDataService extends DictDataFrameworkService {
|
|||||||
* @param reqVO 列表请求
|
* @param reqVO 列表请求
|
||||||
* @return 字典数据列表
|
* @return 字典数据列表
|
||||||
*/
|
*/
|
||||||
List<SysDictDataDO> listDictDatas(SysDictDataExportReqVO reqVO);
|
List<SysDictDataDO> getDictDataList(SysDictDataExportReqVO reqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得字典数据详情
|
* 获得字典数据详情
|
||||||
|
@ -22,7 +22,7 @@ public interface SysDictTypeService {
|
|||||||
* @param reqVO 分页请求
|
* @param reqVO 分页请求
|
||||||
* @return 字典类型分页列表
|
* @return 字典类型分页列表
|
||||||
*/
|
*/
|
||||||
PageResult<SysDictTypeDO> pageDictTypes(SysDictTypePageReqVO reqVO);
|
PageResult<SysDictTypeDO> getDictTypePage(SysDictTypePageReqVO reqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得字典类型列表
|
* 获得字典类型列表
|
||||||
@ -30,7 +30,7 @@ public interface SysDictTypeService {
|
|||||||
* @param reqVO 列表请求
|
* @param reqVO 列表请求
|
||||||
* @return 字典类型列表
|
* @return 字典类型列表
|
||||||
*/
|
*/
|
||||||
List<SysDictTypeDO> listDictTypes(SysDictTypeExportReqVO reqVO);
|
List<SysDictTypeDO> getDictTypeList(SysDictTypeExportReqVO reqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得字典类型详情
|
* 获得字典类型详情
|
||||||
@ -75,6 +75,6 @@ public interface SysDictTypeService {
|
|||||||
*
|
*
|
||||||
* @return 字典类型列表
|
* @return 字典类型列表
|
||||||
*/
|
*/
|
||||||
List<SysDictTypeDO> listDictTypes();
|
List<SysDictTypeDO> getDictTypeList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -130,19 +130,19 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDictDataDO> listDictDatas() {
|
public List<SysDictDataDO> getDictDataList() {
|
||||||
List<SysDictDataDO> list = dictDataMapper.selectList();
|
List<SysDictDataDO> list = dictDataMapper.selectList();
|
||||||
list.sort(COMPARATOR_TYPE_AND_SORT);
|
list.sort(COMPARATOR_TYPE_AND_SORT);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<SysDictDataDO> pageDictDatas(SysDictDataPageReqVO reqVO) {
|
public PageResult<SysDictDataDO> getDictDataPage(SysDictDataPageReqVO reqVO) {
|
||||||
return dictDataMapper.selectPage(reqVO);
|
return dictDataMapper.selectPage(reqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDictDataDO> listDictDatas(SysDictDataExportReqVO reqVO) {
|
public List<SysDictDataDO> getDictDataList(SysDictDataExportReqVO reqVO) {
|
||||||
List<SysDictDataDO> list = dictDataMapper.selectList(reqVO);
|
List<SysDictDataDO> list = dictDataMapper.selectList(reqVO);
|
||||||
list.sort(COMPARATOR_TYPE_AND_SORT);
|
list.sort(COMPARATOR_TYPE_AND_SORT);
|
||||||
return list;
|
return list;
|
||||||
@ -194,10 +194,10 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
|||||||
private void checkCreateOrUpdate(Long id, String label, String dictType) {
|
private void checkCreateOrUpdate(Long id, String label, String dictType) {
|
||||||
// 校验自己存在
|
// 校验自己存在
|
||||||
checkDictDataExists(id);
|
checkDictDataExists(id);
|
||||||
// 校验字典数据的值的唯一性
|
|
||||||
checkDictDataValueUnique(id, dictType, label);
|
|
||||||
// 校验字典类型有效
|
// 校验字典类型有效
|
||||||
checkDictTypeValid(dictType);
|
checkDictTypeValid(dictType);
|
||||||
|
// 校验字典数据的值的唯一性
|
||||||
|
checkDictDataValueUnique(id, dictType, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDictDataValueUnique(Long id, String dictType, String label) {
|
private void checkDictDataValueUnique(Long id, String dictType, String label) {
|
||||||
@ -220,14 +220,14 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
|||||||
}
|
}
|
||||||
SysDictDataDO dictData = dictDataMapper.selectById(id);
|
SysDictDataDO dictData = dictDataMapper.selectById(id);
|
||||||
if (dictData == null) {
|
if (dictData == null) {
|
||||||
throw ServiceExceptionUtil.exception(DICT_DATA_NOT_FOUND);
|
throw ServiceExceptionUtil.exception(DICT_DATA_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDictTypeValid(String type) {
|
private void checkDictTypeValid(String type) {
|
||||||
SysDictTypeDO dictType = dictTypeService.getDictType(type);
|
SysDictTypeDO dictType = dictTypeService.getDictType(type);
|
||||||
if (dictType == null) {
|
if (dictType == null) {
|
||||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_FOUND);
|
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(dictType.getStatus())) {
|
if (!CommonStatusEnum.ENABLE.getStatus().equals(dictType.getStatus())) {
|
||||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_ENABLE);
|
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_ENABLE);
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package cn.iocoder.dashboard.modules.system.service.dict.impl;
|
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.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeCreateReqVO;
|
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.SysDictTypeExportReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypePageReqVO;
|
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.controller.dict.vo.type.SysDictTypeUpdateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.convert.dict.SysDictTypeConvert;
|
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.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.SysDictDataService;
|
||||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService;
|
import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -16,6 +15,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,12 +33,12 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
|||||||
private SysDictTypeMapper dictTypeMapper;
|
private SysDictTypeMapper dictTypeMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<SysDictTypeDO> pageDictTypes(SysDictTypePageReqVO reqVO) {
|
public PageResult<SysDictTypeDO> getDictTypePage(SysDictTypePageReqVO reqVO) {
|
||||||
return dictTypeMapper.selectPage(reqVO);
|
return dictTypeMapper.selectPage(reqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDictTypeDO> listDictTypes(SysDictTypeExportReqVO reqVO) {
|
public List<SysDictTypeDO> getDictTypeList(SysDictTypeExportReqVO reqVO) {
|
||||||
return dictTypeMapper.selectList(reqVO);
|
return dictTypeMapper.selectList(reqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,14 +77,14 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
|||||||
SysDictTypeDO dictType = this.checkDictTypeExists(id);
|
SysDictTypeDO dictType = this.checkDictTypeExists(id);
|
||||||
// 校验是否有字典数据
|
// 校验是否有字典数据
|
||||||
if (dictDataService.countByDictType(dictType.getType()) > 0) {
|
if (dictDataService.countByDictType(dictType.getType()) > 0) {
|
||||||
throw ServiceExceptionUtil.exception(DICT_TYPE_HAS_CHILDREN);
|
throw exception(DICT_TYPE_HAS_CHILDREN);
|
||||||
}
|
}
|
||||||
// 删除字典类型
|
// 删除字典类型
|
||||||
dictTypeMapper.deleteById(id);
|
dictTypeMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDictTypeDO> listDictTypes() {
|
public List<SysDictTypeDO> getDictTypeList() {
|
||||||
return dictTypeMapper.selectList();
|
return dictTypeMapper.selectList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,10 +104,10 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
|||||||
}
|
}
|
||||||
// 如果 id 为空,说明不用比较是否为相同 id 的字典类型
|
// 如果 id 为空,说明不用比较是否为相同 id 的字典类型
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NAME_DUPLICATE);
|
throw exception(DICT_TYPE_NAME_DUPLICATE);
|
||||||
}
|
}
|
||||||
if (!dictType.getId().equals(id)) {
|
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 的字典类型
|
// 如果 id 为空,说明不用比较是否为相同 id 的字典类型
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw ServiceExceptionUtil.exception(DICT_TYPE_TYPE_DUPLICATE);
|
throw exception(DICT_TYPE_TYPE_DUPLICATE);
|
||||||
}
|
}
|
||||||
if (!dictType.getId().equals(id)) {
|
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);
|
SysDictTypeDO dictType = dictTypeMapper.selectById(id);
|
||||||
if (dictType == null) {
|
if (dictType == null) {
|
||||||
throw ServiceExceptionUtil.exception(DICT_TYPE_NOT_FOUND);
|
throw exception(DICT_TYPE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
return dictType;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -29,7 +29,7 @@ import static org.mockito.Mockito.*;
|
|||||||
## 字段模板
|
## 字段模板
|
||||||
#macro(getPageCondition $VO)
|
#macro(getPageCondition $VO)
|
||||||
// mock 数据
|
// mock 数据
|
||||||
${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class, o -> {); // 等会查询到
|
${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class, o -> { // 等会查询到
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if (${column.listOperation})
|
#if (${column.listOperation})
|
||||||
#set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
|
#set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
|
||||||
@ -123,7 +123,7 @@ public class ${table.className}ServiceTest extends BaseSpringBootUnitTest {
|
|||||||
// 调用
|
// 调用
|
||||||
${classNameVar}Service.delete${simpleClassName}(id);
|
${classNameVar}Service.delete${simpleClassName}(id);
|
||||||
// 校验数据不存在了
|
// 校验数据不存在了
|
||||||
assertNull(configMapper.selectById(id));
|
assertNull(${classNameVar}Mapper.selectById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -140,7 +140,7 @@ public class ${table.className}ServiceTest extends BaseSpringBootUnitTest {
|
|||||||
#getPageCondition("PageReqVO")
|
#getPageCondition("PageReqVO")
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
PageResult<${table.className}DO> pageResult = configService.getConfigPage(reqVO);
|
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(reqVO);
|
||||||
// 断言
|
// 断言
|
||||||
assertEquals(1, pageResult.getTotal());
|
assertEquals(1, pageResult.getTotal());
|
||||||
assertEquals(1, pageResult.getList().size());
|
assertEquals(1, pageResult.getList().size());
|
||||||
@ -152,7 +152,7 @@ public class ${table.className}ServiceTest extends BaseSpringBootUnitTest {
|
|||||||
#getPageCondition("ExportReqVO")
|
#getPageCondition("ExportReqVO")
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
PageResult<${table.className}DO> list = configService.getConfigPage(reqVO);
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(reqVO);
|
||||||
// 断言
|
// 断言
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, list.size());
|
||||||
assertPojoEquals(db${simpleClassName}, list.get(0));
|
assertPojoEquals(db${simpleClassName}, list.get(0));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.iocoder.dashboard.modules.infra.service.config;
|
package cn.iocoder.dashboard.modules.infra.service.config;
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
||||||
@ -12,6 +11,7 @@ import cn.iocoder.dashboard.modules.infra.dal.mysql.config.InfConfigMapper;
|
|||||||
import cn.iocoder.dashboard.modules.infra.enums.config.InfConfigTypeEnum;
|
import cn.iocoder.dashboard.modules.infra.enums.config.InfConfigTypeEnum;
|
||||||
import cn.iocoder.dashboard.modules.infra.mq.producer.config.InfConfigProducer;
|
import cn.iocoder.dashboard.modules.infra.mq.producer.config.InfConfigProducer;
|
||||||
import cn.iocoder.dashboard.modules.infra.service.config.impl.InfConfigServiceImpl;
|
import cn.iocoder.dashboard.modules.infra.service.config.impl.InfConfigServiceImpl;
|
||||||
|
import cn.iocoder.dashboard.util.collection.ArrayUtils;
|
||||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
@ -20,13 +20,16 @@ import javax.annotation.Resource;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static cn.hutool.core.util.RandomUtil.*;
|
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.*;
|
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.*;
|
||||||
import static cn.iocoder.dashboard.util.AssertUtils.*;
|
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||||
import static cn.iocoder.dashboard.util.RandomUtils.*;
|
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
||||||
import static cn.iocoder.dashboard.util.date.DateUtils.*;
|
import static cn.iocoder.dashboard.util.RandomUtils.randomLongId;
|
||||||
|
import static cn.iocoder.dashboard.util.RandomUtils.randomPojo;
|
||||||
|
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link InfConfigServiceImpl} 的单元测试类
|
* {@link InfConfigServiceImpl} 的单元测试类
|
||||||
@ -227,12 +230,11 @@ public class InfConfigServiceTest extends BaseSpringBootUnitTest {
|
|||||||
// ========== 随机对象 ==========
|
// ========== 随机对象 ==========
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static InfConfigDO randomInfConfigDO(Consumer<InfConfigDO>... consumers) {
|
private static InfConfigDO randomInfConfigDO(Consumer<InfConfigDO>... consumers) {
|
||||||
Consumer<InfConfigDO> consumer = (o) -> {
|
Consumer<InfConfigDO> consumer = (o) -> {
|
||||||
o.setType(randomEle(InfConfigTypeEnum.values()).getType()); // 保证 key 的范围
|
o.setType(randomEle(InfConfigTypeEnum.values()).getType()); // 保证 key 的范围
|
||||||
};
|
};
|
||||||
return randomPojo(InfConfigDO.class, ArrayUtil.append(new Consumer[]{consumer}, consumers));
|
return randomPojo(InfConfigDO.class, ArrayUtils.append(consumer, consumers));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,173 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.system.service.dict;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||||
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataExportReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictDataDO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictTypeDO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dict.SysDictDataMapper;
|
||||||
|
import cn.iocoder.dashboard.modules.system.mq.producer.dict.SysDictDataProducer;
|
||||||
|
import cn.iocoder.dashboard.modules.system.service.dict.impl.SysDictDataServiceImpl;
|
||||||
|
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.DICT_DATA_NOT_EXISTS;
|
||||||
|
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||||
|
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
||||||
|
import static cn.iocoder.dashboard.util.RandomUtils.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link SysDictDataServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class SysDictDataServiceTest extends BaseSpringBootUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysDictDataServiceImpl dictDataService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysDictDataMapper dictDataMapper;
|
||||||
|
@MockBean
|
||||||
|
private SysDictTypeService dictTypeService;
|
||||||
|
@MockBean
|
||||||
|
private SysDictDataProducer dictDataProducer;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDictDataPage() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictDataDO dbDictData = randomPojo(SysDictDataDO.class, o -> { // 等会查询到
|
||||||
|
o.setLabel("芋艿");
|
||||||
|
o.setDictType("yunai");
|
||||||
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
});
|
||||||
|
dictDataMapper.insert(dbDictData);
|
||||||
|
// 测试 label 不匹配
|
||||||
|
dictDataMapper.insert(ObjectUtils.clone(dbDictData, o -> o.setLabel("艿")));
|
||||||
|
// 测试 dictType 不匹配
|
||||||
|
dictDataMapper.insert(ObjectUtils.clone(dbDictData, o -> o.setDictType("nai")));
|
||||||
|
// 测试 status 不匹配
|
||||||
|
dictDataMapper.insert(ObjectUtils.clone(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||||
|
// 准备参数
|
||||||
|
SysDictDataPageReqVO reqVO = new SysDictDataPageReqVO();
|
||||||
|
reqVO.setLabel("芋");
|
||||||
|
reqVO.setDictType("yu");
|
||||||
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<SysDictDataDO> pageResult = dictDataService.getDictDataPage(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(dbDictData, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDictDataList() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictDataDO dbDictData = randomPojo(SysDictDataDO.class, o -> { // 等会查询到
|
||||||
|
o.setLabel("芋艿");
|
||||||
|
o.setDictType("yunai");
|
||||||
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
});
|
||||||
|
dictDataMapper.insert(dbDictData);
|
||||||
|
// 测试 label 不匹配
|
||||||
|
dictDataMapper.insert(ObjectUtils.clone(dbDictData, o -> o.setLabel("艿")));
|
||||||
|
// 测试 dictType 不匹配
|
||||||
|
dictDataMapper.insert(ObjectUtils.clone(dbDictData, o -> o.setDictType("nai")));
|
||||||
|
// 测试 status 不匹配
|
||||||
|
dictDataMapper.insert(ObjectUtils.clone(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||||
|
// 准备参数
|
||||||
|
SysDictDataExportReqVO reqVO = new SysDictDataExportReqVO();
|
||||||
|
reqVO.setLabel("芋");
|
||||||
|
reqVO.setDictType("yu");
|
||||||
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
List<SysDictDataDO> list = dictDataService.getDictDataList(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertPojoEquals(dbDictData, list.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDictData_success() {
|
||||||
|
// 准备参数
|
||||||
|
SysDictDataCreateReqVO reqVO = randomPojo(SysDictDataCreateReqVO.class,
|
||||||
|
o -> o.setStatus(randomCommonStatus()));
|
||||||
|
// mock 方法
|
||||||
|
when(dictTypeService.getDictType(eq(reqVO.getDictType())))
|
||||||
|
.thenReturn(randomPojo(SysDictTypeDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Long dictDataId = dictDataService.createDictData(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(dictDataId);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
SysDictDataDO dictData = dictDataMapper.selectById(dictDataId);
|
||||||
|
assertPojoEquals(reqVO, dictData);
|
||||||
|
// 校验调用
|
||||||
|
verify(dictDataProducer, times(1)).sendDictDataRefreshMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDictData_success() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictDataDO dbDictData = randomPojo(SysDictDataDO.class);
|
||||||
|
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
SysDictDataUpdateReqVO reqVO = randomPojo(SysDictDataUpdateReqVO.class, o -> {
|
||||||
|
o.setId(dbDictData.getId()); // 设置更新的 ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
dictDataService.updateDictData(reqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
SysDictDataDO dictData = dictDataMapper.selectById(reqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(reqVO, dictData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDictData_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
SysDictDataUpdateReqVO reqVO = randomPojo(SysDictDataUpdateReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> dictDataService.updateDictData(reqVO), DICT_DATA_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDictData_success() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictDataDO dbDictData = randomPojo(SysDictDataDO.class);
|
||||||
|
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbDictData.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
dictDataService.deleteDictData(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(dictDataMapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDictData_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
Long id = randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> dictDataService.deleteDictData(id), DICT_DATA_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,263 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.system.service.dict;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||||
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
|
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.dal.dataobject.dict.SysDictTypeDO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dict.SysDictTypeMapper;
|
||||||
|
import cn.iocoder.dashboard.modules.system.service.dict.impl.SysDictTypeServiceImpl;
|
||||||
|
import cn.iocoder.dashboard.util.collection.ArrayUtils;
|
||||||
|
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||||
|
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||||
|
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||||
|
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
||||||
|
import static cn.iocoder.dashboard.util.RandomUtils.randomLongId;
|
||||||
|
import static cn.iocoder.dashboard.util.RandomUtils.randomPojo;
|
||||||
|
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link SysDictTypeServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class SysDictTypeServiceTest extends BaseSpringBootUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysDictTypeServiceImpl dictTypeService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysDictTypeMapper dictTypeMapper;
|
||||||
|
@MockBean
|
||||||
|
private SysDictDataService dictDataService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDictTypePage() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictTypeDO dbDictType = randomPojo(SysDictTypeDO.class, o -> { // 等会查询到
|
||||||
|
o.setName("yunai");
|
||||||
|
o.setType("芋艿");
|
||||||
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
o.setCreateTime(buildTime(2021, 1, 15));
|
||||||
|
});
|
||||||
|
dictTypeMapper.insert(dbDictType);
|
||||||
|
// 测试 name 不匹配
|
||||||
|
dictTypeMapper.insert(ObjectUtils.clone(dbDictType, o -> o.setName("tudou")));
|
||||||
|
// 测试 type 不匹配
|
||||||
|
dictTypeMapper.insert(ObjectUtils.clone(dbDictType, o -> o.setType("土豆")));
|
||||||
|
// 测试 status 不匹配
|
||||||
|
dictTypeMapper.insert(ObjectUtils.clone(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
dictTypeMapper.insert(ObjectUtils.clone(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
||||||
|
// 准备参数
|
||||||
|
SysDictTypePageReqVO reqVO = new SysDictTypePageReqVO();
|
||||||
|
reqVO.setName("nai");
|
||||||
|
reqVO.setType("艿");
|
||||||
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
reqVO.setBeginCreateTime(buildTime(2021, 1, 10));
|
||||||
|
reqVO.setEndCreateTime(buildTime(2021, 1, 20));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<SysDictTypeDO> pageResult = dictTypeService.getDictTypePage(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(dbDictType, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDictTypeList() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictTypeDO dbDictType = randomPojo(SysDictTypeDO.class, o -> { // 等会查询到
|
||||||
|
o.setName("yunai");
|
||||||
|
o.setType("芋艿");
|
||||||
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
o.setCreateTime(buildTime(2021, 1, 15));
|
||||||
|
});
|
||||||
|
dictTypeMapper.insert(dbDictType);
|
||||||
|
// 测试 name 不匹配
|
||||||
|
dictTypeMapper.insert(ObjectUtils.clone(dbDictType, o -> o.setName("tudou")));
|
||||||
|
// 测试 type 不匹配
|
||||||
|
dictTypeMapper.insert(ObjectUtils.clone(dbDictType, o -> o.setType("土豆")));
|
||||||
|
// 测试 status 不匹配
|
||||||
|
dictTypeMapper.insert(ObjectUtils.clone(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
dictTypeMapper.insert(ObjectUtils.clone(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
||||||
|
// 准备参数
|
||||||
|
SysDictTypeExportReqVO reqVO = new SysDictTypeExportReqVO();
|
||||||
|
reqVO.setName("nai");
|
||||||
|
reqVO.setType("艿");
|
||||||
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
reqVO.setBeginCreateTime(buildTime(2021, 1, 10));
|
||||||
|
reqVO.setEndCreateTime(buildTime(2021, 1, 20));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
List<SysDictTypeDO> list = dictTypeService.getDictTypeList(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertPojoEquals(dbDictType, list.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDictType() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictTypeDO dbDictType = randomDictTypeDO();
|
||||||
|
dictTypeMapper.insert(dbDictType);
|
||||||
|
// 准备参数
|
||||||
|
String type = dbDictType.getType();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
SysDictTypeDO dictType = dictTypeService.getDictType(type);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(dictType);
|
||||||
|
assertPojoEquals(dbDictType, dictType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDictType_success() {
|
||||||
|
// 准备参数
|
||||||
|
SysDictTypeCreateReqVO reqVO = randomPojo(SysDictTypeCreateReqVO.class,
|
||||||
|
o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Long dictTypeId = dictTypeService.createDictType(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(dictTypeId);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
SysDictTypeDO dictType = dictTypeMapper.selectById(dictTypeId);
|
||||||
|
assertPojoEquals(reqVO, dictType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDictType_nameDuplicate() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictTypeDO dbDictType = randomDictTypeDO();
|
||||||
|
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
SysDictTypeCreateReqVO reqVO = randomPojo(SysDictTypeCreateReqVO.class,
|
||||||
|
o -> o.setName(dbDictType.getName())); // 模拟 name 重复
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> dictTypeService.createDictType(reqVO), DICT_TYPE_NAME_DUPLICATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateDictType_typeDuplicate() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictTypeDO dbDictType = randomDictTypeDO();
|
||||||
|
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
SysDictTypeCreateReqVO reqVO = randomPojo(SysDictTypeCreateReqVO.class,
|
||||||
|
o -> o.setType(dbDictType.getType())); // 模拟 type 重复
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> dictTypeService.createDictType(reqVO), DICT_TYPE_TYPE_DUPLICATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDictType_success() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictTypeDO dbDictType = randomDictTypeDO();
|
||||||
|
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
SysDictTypeUpdateReqVO reqVO = randomPojo(SysDictTypeUpdateReqVO.class, o -> {
|
||||||
|
o.setId(dbDictType.getId()); // 设置更新的 ID
|
||||||
|
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus());
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
dictTypeService.updateDictType(reqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
SysDictTypeDO dictType = dictTypeMapper.selectById(reqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(reqVO, dictType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDictType_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
SysDictTypeUpdateReqVO reqVO = randomPojo(SysDictTypeUpdateReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> dictTypeService.updateDictType(reqVO), DICT_TYPE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateDictType_nameDuplicate() {
|
||||||
|
// mock 数据,稍后更新它
|
||||||
|
SysDictTypeDO dbDictType = randomDictTypeDO();
|
||||||
|
dictTypeMapper.insert(dbDictType);
|
||||||
|
// mock 数据,ks稍后模拟重复它的名字
|
||||||
|
SysDictTypeDO nameDictType = randomDictTypeDO();
|
||||||
|
dictTypeMapper.insert(nameDictType);
|
||||||
|
// 准备参数
|
||||||
|
SysDictTypeUpdateReqVO reqVO = randomPojo(SysDictTypeUpdateReqVO.class, o -> {
|
||||||
|
o.setId(dbDictType.getId()); // 设置更新的 ID
|
||||||
|
o.setName(nameDictType.getName()); // 模拟 name 重复
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> dictTypeService.updateDictType(reqVO), DICT_TYPE_NAME_DUPLICATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDictType_success() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictTypeDO dbDictType = randomDictTypeDO();
|
||||||
|
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbDictType.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
dictTypeService.deleteDictType(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(dictTypeMapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDictType_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
Long id = randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> dictTypeService.deleteDictType(id), DICT_TYPE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDictType_hasChildren() {
|
||||||
|
// mock 数据
|
||||||
|
SysDictTypeDO dbDictType = randomDictTypeDO();
|
||||||
|
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbDictType.getId();
|
||||||
|
// mock 方法
|
||||||
|
when(dictDataService.countByDictType(eq(dbDictType.getType()))).thenReturn(1);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> dictTypeService.deleteDictType(id), DICT_TYPE_HAS_CHILDREN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 随机对象 ==========
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
private static SysDictTypeDO randomDictTypeDO(Consumer<SysDictTypeDO>... consumers) {
|
||||||
|
Consumer<SysDictTypeDO> consumer = (o) -> {
|
||||||
|
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围
|
||||||
|
};
|
||||||
|
return randomPojo(SysDictTypeDO.class, ArrayUtils.append(consumer, consumers));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
package cn.iocoder.dashboard.modules.system.service;
|
|
@ -2,6 +2,7 @@ package cn.iocoder.dashboard.util;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||||
import uk.co.jemos.podam.api.PodamFactory;
|
import uk.co.jemos.podam.api.PodamFactory;
|
||||||
import uk.co.jemos.podam.api.PodamFactoryImpl;
|
import uk.co.jemos.podam.api.PodamFactoryImpl;
|
||||||
@ -67,6 +68,10 @@ public class RandomUtils {
|
|||||||
.map(i -> randomPojo(clazz)).collect(Collectors.toSet());
|
.map(i -> randomPojo(clazz)).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Integer randomCommonStatus() {
|
||||||
|
return RandomUtil.randomEle(CommonStatusEnum.values()).getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static SysUserDO randomUserDO(Consumer<SysUserDO>... consumers) {
|
public static SysUserDO randomUserDO(Consumer<SysUserDO>... consumers) {
|
||||||
return randomPojo(SysUserDO.class, consumers);
|
return randomPojo(SysUserDO.class, consumers);
|
||||||
|
@ -7,3 +7,4 @@ DELETE FROM "sys_dict_data";
|
|||||||
DELETE FROM "sys_role";
|
DELETE FROM "sys_role";
|
||||||
DELETE FROM "sys_role_menu";
|
DELETE FROM "sys_role_menu";
|
||||||
DELETE FROM "sys_menu";
|
DELETE FROM "sys_menu";
|
||||||
|
DELETE FROM "sys_dict_type";
|
||||||
|
@ -100,3 +100,17 @@ CREATE TABLE IF NOT EXISTS "sys_menu" (
|
|||||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY ("id")
|
PRIMARY KEY ("id")
|
||||||
) COMMENT '菜单权限表';
|
) COMMENT '菜单权限表';
|
||||||
|
|
||||||
|
CREATE TABLE "sys_dict_type" (
|
||||||
|
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||||
|
"name" varchar(100) NOT NULL DEFAULT '',
|
||||||
|
"type" varchar(100) NOT NULL DEFAULT '',
|
||||||
|
"status" tinyint NOT NULL DEFAULT '0',
|
||||||
|
"remark" varchar(500) DEFAULT NULL,
|
||||||
|
"create_by" varchar(64) DEFAULT '',
|
||||||
|
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"update_by" varchar(64) DEFAULT '',
|
||||||
|
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
|
PRIMARY KEY ("id")
|
||||||
|
) COMMENT '字典类型表';
|
||||||
|
Loading…
Reference in New Issue
Block a user