mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-11 08:41:53 +08:00
代码生成器:增加树形结构的 vm 模版
This commit is contained in:
@@ -85,28 +85,42 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
||||
return success(${table.className}Convert.INSTANCE.convert(${classNameVar}));
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 )
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得${table.classComment}分页")
|
||||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||
#end
|
||||
public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageVO) {
|
||||
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO);
|
||||
public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
||||
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO);
|
||||
return success(${table.className}Convert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
#else
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得${table.classComment}列表")
|
||||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||
#end
|
||||
public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
||||
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
||||
return success(${table.className}Convert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
#end
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出${table.classComment} Excel")
|
||||
#if ($sceneEnum.scene == 1)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")
|
||||
#end
|
||||
@OperateLog(type = EXPORT)
|
||||
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO,
|
||||
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(exportReqVO);
|
||||
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
||||
// 导出 Excel
|
||||
List<${sceneEnum.prefixClass}${table.className}ExcelVO> datas = ${table.className}Convert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas);
|
||||
List<${sceneEnum.prefixClass}${table.className}ExcelVO> dataList = ${table.className}Convert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, dataList);
|
||||
}
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
|
@@ -26,8 +26,10 @@ public interface ${table.className}Convert {
|
||||
${sceneEnum.prefixClass}${table.className}RespVO convert(${table.className}DO bean);
|
||||
|
||||
List<${sceneEnum.prefixClass}${table.className}RespVO> convertList(List<${table.className}DO> list);
|
||||
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
#if ( $table.templateType != 2 )
|
||||
PageResult<${sceneEnum.prefixClass}${table.className}RespVO> convertPage(PageResult<${table.className}DO> page);
|
||||
#end
|
||||
|
||||
List<${sceneEnum.prefixClass}${table.className}ExcelVO> convertList02(List<${table.className}DO> list);
|
||||
|
||||
|
@@ -49,6 +49,8 @@ import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePack
|
||||
@Mapper
|
||||
public interface ${table.className}Mapper extends BaseMapperX<${table.className}DO> {
|
||||
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
#if ( $table.templateType != 2 )
|
||||
default PageResult<${table.className}DO> selectPage(${sceneEnum.prefixClass}${table.className}PageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<${table.className}DO>()
|
||||
#listCondition()
|
||||
@@ -56,11 +58,20 @@ public interface ${table.className}Mapper extends BaseMapperX<${table.className}
|
||||
|
||||
}
|
||||
|
||||
default List<${table.className}DO> selectList(${sceneEnum.prefixClass}${table.className}ExportReqVO reqVO) {
|
||||
#end
|
||||
default List<${table.className}DO> selectList(${sceneEnum.prefixClass}${table.className}ListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<${table.className}DO>()
|
||||
#listCondition()
|
||||
.orderByDesc(${table.className}DO::getId));## 大多数情况下,id 倒序
|
||||
|
||||
}
|
||||
|
||||
## 特殊:树表专属逻辑
|
||||
#if ( $table.templateType == 2 )
|
||||
#set ($ParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||
default Long selectCountBy${ParentJavaField}(${treeParentColumn.javaType} ${treeParentColumn.javaField}) {
|
||||
return selectCount(${table.className}DO::get${ParentJavaField}, ${treeParentColumn.javaField});
|
||||
}
|
||||
|
||||
#end
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
// TODO 待办:请将下面的错误码复制到 yudao-module-${table.moduleName}-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!!
|
||||
// ========== ${table.classComment} TODO 补充编号 ==========
|
||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在");
|
||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在");
|
||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_EXITS_CHILDREN = new ErrorCode(TODO 补充编号, "存在存在子${table.classComment},无法删除");
|
@@ -48,6 +48,8 @@ public interface ${table.className}Service {
|
||||
*/
|
||||
${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id);
|
||||
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
#if ( $table.templateType != 2 )
|
||||
/**
|
||||
* 获得${table.classComment}分页
|
||||
*
|
||||
@@ -56,13 +58,14 @@ public interface ${table.className}Service {
|
||||
*/
|
||||
PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO);
|
||||
|
||||
#end
|
||||
/**
|
||||
* 获得${table.classComment}列表, 用于 Excel 导出
|
||||
* 获得${table.classComment}列表
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @param listReqVO 查询条件
|
||||
* @return ${table.classComment}列表
|
||||
*/
|
||||
List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO);
|
||||
List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO);
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
#foreach ($subTable in $subTables)
|
||||
|
@@ -110,6 +110,14 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
||||
public void delete${simpleClassName}(${primaryColumn.javaType} id) {
|
||||
// 校验存在
|
||||
validate${simpleClassName}Exists(id);
|
||||
## 特殊:树表专属逻辑
|
||||
#if ( $table.templateType == 2 )
|
||||
#set ($ParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||
// 校验是否有子${table.classComment}
|
||||
if (${classNameVar}Mapper.selectCountBy${ParentJavaField}(id) > 0) {
|
||||
throw exception(${simpleClassName_underlineCase.toUpperCase()}_EXITS_CHILDREN);
|
||||
}
|
||||
#end
|
||||
// 删除
|
||||
${classNameVar}Mapper.deleteById(id);
|
||||
## 特殊:主子表专属逻辑
|
||||
@@ -137,14 +145,17 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
||||
return ${classNameVar}Mapper.selectById(id);
|
||||
}
|
||||
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
#if ( $table.templateType != 2 )
|
||||
@Override
|
||||
public PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
||||
return ${classNameVar}Mapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
#end
|
||||
@Override
|
||||
public List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO) {
|
||||
return ${classNameVar}Mapper.selectList(exportReqVO);
|
||||
public List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
||||
return ${classNameVar}Mapper.selectList(listReqVO);
|
||||
}
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
|
@@ -137,6 +137,8 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest {
|
||||
assertServiceException(() -> ${classNameVar}Service.delete${simpleClassName}(id), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||
}
|
||||
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
#if ( $table.templateType != 2 )
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGet${simpleClassName}Page() {
|
||||
@@ -150,10 +152,11 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest {
|
||||
assertPojoEquals(db${simpleClassName}, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
#end
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGet${simpleClassName}List() {
|
||||
#getPageCondition("ExportReqVO")
|
||||
#getPageCondition("ListReqVO")
|
||||
|
||||
// 调用
|
||||
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(reqVO);
|
||||
|
Reference in New Issue
Block a user