2022-02-02 22:10:24 +08:00
|
|
|
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName};
|
2021-02-09 12:51:01 +08:00
|
|
|
|
|
2021-02-05 01:31:53 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2024-01-20 00:42:46 +08:00
|
|
|
|
import ${jakartaPackage}.annotation.Resource;
|
2021-02-09 12:51:01 +08:00
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
2022-02-02 22:10:24 +08:00
|
|
|
|
#if ($sceneEnum.scene == 1)import org.springframework.security.access.prepost.PreAuthorize;#end
|
2021-02-09 12:51:01 +08:00
|
|
|
|
|
2023-01-17 21:18:10 +08:00
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
2021-02-09 12:51:01 +08:00
|
|
|
|
|
2024-01-20 00:42:46 +08:00
|
|
|
|
import ${jakartaPackage}.validation.constraints.*;
|
|
|
|
|
import ${jakartaPackage}.validation.*;
|
|
|
|
|
import ${jakartaPackage}.servlet.http.*;
|
2021-02-05 01:31:53 +08:00
|
|
|
|
import java.util.*;
|
2021-02-11 23:02:53 +08:00
|
|
|
|
import java.io.IOException;
|
2021-02-05 01:31:53 +08:00
|
|
|
|
|
2023-11-13 20:35:03 +08:00
|
|
|
|
import ${PageParamClassName};
|
2021-02-09 12:51:01 +08:00
|
|
|
|
import ${PageResultClassName};
|
|
|
|
|
import ${CommonResultClassName};
|
2023-11-15 21:03:16 +08:00
|
|
|
|
import ${BeanUtils};
|
2021-02-09 12:51:01 +08:00
|
|
|
|
import static ${CommonResultClassName}.success;
|
|
|
|
|
|
2021-02-11 23:02:53 +08:00
|
|
|
|
import ${ExcelUtilsClassName};
|
|
|
|
|
|
2024-04-04 01:21:08 +08:00
|
|
|
|
import ${ApiAccessLogClassName};
|
2021-02-12 12:58:41 +08:00
|
|
|
|
import static ${OperateTypeEnumClassName}.*;
|
|
|
|
|
|
2022-02-02 22:10:24 +08:00
|
|
|
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
2022-02-02 13:57:25 +08:00
|
|
|
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
2023-11-09 20:49:52 +08:00
|
|
|
|
## 特殊:主子表专属逻辑
|
|
|
|
|
#foreach ($subTable in $subTables)
|
|
|
|
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
|
|
|
|
#end
|
2022-02-02 13:57:25 +08:00
|
|
|
|
import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service;
|
2021-02-05 01:31:53 +08:00
|
|
|
|
|
2022-12-09 13:43:15 +08:00
|
|
|
|
@Tag(name = "${sceneEnum.name} - ${table.classComment}")
|
2021-02-05 01:31:53 +08:00
|
|
|
|
@RestController
|
2021-02-09 12:51:01 +08:00
|
|
|
|
##二级的 businessName 暂时不算在 HTTP 路径上,可以根据需要写
|
|
|
|
|
@RequestMapping("/${table.moduleName}/${simpleClassName_strikeCase}")
|
2021-02-05 01:31:53 +08:00
|
|
|
|
@Validated
|
2022-02-02 22:10:24 +08:00
|
|
|
|
public class ${sceneEnum.prefixClass}${table.className}Controller {
|
2021-02-05 01:31:53 +08:00
|
|
|
|
|
2021-02-09 12:51:01 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private ${table.className}Service ${classNameVar}Service;
|
2021-02-05 01:31:53 +08:00
|
|
|
|
|
|
|
|
|
@PostMapping("/create")
|
2022-12-09 13:43:15 +08:00
|
|
|
|
@Operation(summary = "创建${table.classComment}")
|
2023-11-09 20:49:52 +08:00
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
|
|
|
|
|
#end
|
2025-05-19 13:04:25 +08:00
|
|
|
|
public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${saveReqVOClass} ${saveReqVOVar}) {
|
|
|
|
|
return success(${classNameVar}Service.create${simpleClassName}(${saveReqVOVar}));
|
2021-02-05 01:31:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-09 12:51:01 +08:00
|
|
|
|
@PutMapping("/update")
|
2022-12-09 13:43:15 +08:00
|
|
|
|
@Operation(summary = "更新${table.classComment}")
|
2023-11-09 20:49:52 +08:00
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
|
|
|
|
|
#end
|
2025-05-19 13:04:25 +08:00
|
|
|
|
public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${updateReqVOClass} ${updateReqVOVar}) {
|
|
|
|
|
${classNameVar}Service.update${simpleClassName}(${updateReqVOVar});
|
2021-02-05 01:31:53 +08:00
|
|
|
|
return success(true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 01:29:18 +08:00
|
|
|
|
@DeleteMapping("/delete")
|
2022-12-09 13:43:15 +08:00
|
|
|
|
@Operation(summary = "删除${table.classComment}")
|
|
|
|
|
@Parameter(name = "id", description = "编号", required = true)
|
2023-11-09 20:49:52 +08:00
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
|
|
|
|
#end
|
2021-02-09 12:51:01 +08:00
|
|
|
|
public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
|
|
|
|
${classNameVar}Service.delete${simpleClassName}(id);
|
2021-02-05 01:31:53 +08:00
|
|
|
|
return success(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 11:50:07 +08:00
|
|
|
|
#if ( $table.templateType != 2 && $table.deleteBatch)
|
|
|
|
|
@DeleteMapping("/delete-batch")
|
|
|
|
|
@Parameter(name = "ids", description = "编号", required = true)
|
|
|
|
|
@Operation(summary = "批量删除${table.classComment}")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
|
|
|
|
#end
|
2025-05-19 16:52:52 +08:00
|
|
|
|
public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("ids") List<${primaryColumn.javaType}> ids) {
|
2025-05-19 11:50:07 +08:00
|
|
|
|
${classNameVar}Service.delete${simpleClassName}ByIds(ids);
|
|
|
|
|
return success(true);
|
|
|
|
|
}
|
|
|
|
|
#end
|
|
|
|
|
|
2021-02-05 01:31:53 +08:00
|
|
|
|
@GetMapping("/get")
|
2022-12-09 13:43:15 +08:00
|
|
|
|
@Operation(summary = "获得${table.classComment}")
|
|
|
|
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
2023-11-09 20:49:52 +08:00
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
|
|
|
|
#end
|
2025-05-19 13:04:25 +08:00
|
|
|
|
public CommonResult<${respVOClass}> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
2021-02-09 12:51:01 +08:00
|
|
|
|
${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id);
|
2025-05-19 13:04:25 +08:00
|
|
|
|
#if ($voType == 10)
|
|
|
|
|
return success(BeanUtils.toBean(${classNameVar}, ${respVOClass}.class));
|
|
|
|
|
#else
|
|
|
|
|
return success(${classNameVar});
|
|
|
|
|
#end
|
2021-02-05 01:31:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 19:37:35 +08:00
|
|
|
|
#if ( $table.templateType != 2 )
|
2021-02-05 01:31:53 +08:00
|
|
|
|
@GetMapping("/page")
|
2022-12-09 13:43:15 +08:00
|
|
|
|
@Operation(summary = "获得${table.classComment}分页")
|
2023-11-09 20:49:52 +08:00
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
|
|
|
|
#end
|
2025-05-19 13:04:25 +08:00
|
|
|
|
public CommonResult<PageResult<${respVOClass}>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
2023-11-14 19:37:35 +08:00
|
|
|
|
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO);
|
2025-05-19 13:04:25 +08:00
|
|
|
|
#if ($voType == 10)
|
|
|
|
|
return success(BeanUtils.toBean(pageResult, ${respVOClass}.class));
|
|
|
|
|
#else
|
|
|
|
|
return success(pageResult);
|
|
|
|
|
#end
|
2021-02-05 01:31:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 19:37:35 +08:00
|
|
|
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
|
|
|
|
#else
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
@Operation(summary = "获得${table.classComment}列表")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
|
|
|
|
#end
|
2025-05-19 13:04:25 +08:00
|
|
|
|
public CommonResult<List<${respVOClass}>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
2023-11-14 19:37:35 +08:00
|
|
|
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
2025-05-19 13:04:25 +08:00
|
|
|
|
#if ($voType == 10)
|
|
|
|
|
return success(BeanUtils.toBean(list, ${respVOClass}.class));
|
|
|
|
|
#else
|
|
|
|
|
return success(list);
|
|
|
|
|
#end
|
2023-11-14 19:37:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#end
|
2021-02-11 23:02:53 +08:00
|
|
|
|
@GetMapping("/export-excel")
|
2022-12-09 13:43:15 +08:00
|
|
|
|
@Operation(summary = "导出${table.classComment} Excel")
|
2023-11-09 20:49:52 +08:00
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")
|
|
|
|
|
#end
|
2024-04-04 01:21:08 +08:00
|
|
|
|
@ApiAccessLog(operateType = EXPORT)
|
2023-11-15 21:03:16 +08:00
|
|
|
|
#if ( $table.templateType != 2 )
|
|
|
|
|
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO,
|
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
|
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO).getList();
|
|
|
|
|
// 导出 Excel
|
2025-05-19 13:04:25 +08:00
|
|
|
|
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${respVOClass}.class,
|
|
|
|
|
BeanUtils.toBean(list, ${respVOClass}.class));
|
2023-11-15 21:03:16 +08:00
|
|
|
|
}
|
|
|
|
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
|
|
|
|
#else
|
2023-11-14 19:37:35 +08:00
|
|
|
|
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO,
|
2021-02-11 23:02:53 +08:00
|
|
|
|
HttpServletResponse response) throws IOException {
|
2023-11-14 19:37:35 +08:00
|
|
|
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
2021-02-11 23:02:53 +08:00
|
|
|
|
// 导出 Excel
|
2023-11-15 21:03:16 +08:00
|
|
|
|
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${table.className}RespVO.class,
|
|
|
|
|
BeanUtils.toBean(list, ${table.className}RespVO.class));
|
2021-02-11 23:02:53 +08:00
|
|
|
|
}
|
2023-11-15 21:03:16 +08:00
|
|
|
|
#end
|
2021-02-11 19:49:14 +08:00
|
|
|
|
|
2023-11-09 20:49:52 +08:00
|
|
|
|
## 特殊:主子表专属逻辑
|
|
|
|
|
#foreach ($subTable in $subTables)
|
|
|
|
|
#set ($index = $foreach.count - 1)
|
|
|
|
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
|
|
|
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
|
|
|
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
|
|
|
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
|
|
|
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
|
|
|
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
|
|
|
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
|
|
|
|
// ==================== 子表($subTable.classComment) ====================
|
|
|
|
|
|
|
|
|
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
|
|
|
|
#if ( $table.templateType == 11 )
|
|
|
|
|
@GetMapping("/${subSimpleClassName_strikeCase}/page")
|
|
|
|
|
@Operation(summary = "获得${subTable.classComment}分页")
|
|
|
|
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
|
|
|
|
#end
|
|
|
|
|
public CommonResult<PageResult<${subTable.className}DO>> get${subSimpleClassName}Page(PageParam pageReqVO,
|
|
|
|
|
@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
|
|
|
|
return success(${classNameVar}Service.get${subSimpleClassName}Page(pageReqVO, ${subJoinColumn.javaField}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
|
|
|
|
#else
|
|
|
|
|
#if ( $subTable.subJoinMany )
|
|
|
|
|
@GetMapping("/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}")
|
|
|
|
|
@Operation(summary = "获得${subTable.classComment}列表")
|
|
|
|
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
|
|
|
|
#end
|
|
|
|
|
public CommonResult<List<${subTable.className}DO>> get${subSimpleClassName}ListBy${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
|
|
|
|
return success(${classNameVar}Service.get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@GetMapping("/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}")
|
|
|
|
|
@Operation(summary = "获得${subTable.classComment}")
|
|
|
|
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
|
|
|
|
#end
|
|
|
|
|
public CommonResult<${subTable.className}DO> get${subSimpleClassName}By${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
|
|
|
|
return success(${classNameVar}Service.get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#end
|
|
|
|
|
#end
|
|
|
|
|
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
|
|
|
|
#if ( $table.templateType == 11 )
|
|
|
|
|
@PostMapping("/${subSimpleClassName_strikeCase}/create")
|
|
|
|
|
@Operation(summary = "创建${subTable.classComment}")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
|
|
|
|
|
#end
|
|
|
|
|
public CommonResult<${subPrimaryColumn.javaType}> create${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) {
|
|
|
|
|
return success(${classNameVar}Service.create${subSimpleClassName}(${subClassNameVar}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/${subSimpleClassName_strikeCase}/update")
|
|
|
|
|
@Operation(summary = "更新${subTable.classComment}")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
|
|
|
|
|
#end
|
2023-11-13 20:35:03 +08:00
|
|
|
|
public CommonResult<Boolean> update${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) {
|
2023-11-09 20:49:52 +08:00
|
|
|
|
${classNameVar}Service.update${subSimpleClassName}(${subClassNameVar});
|
|
|
|
|
return success(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/${subSimpleClassName_strikeCase}/delete")
|
|
|
|
|
@Parameter(name = "id", description = "编号", required = true)
|
|
|
|
|
@Operation(summary = "删除${subTable.classComment}")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
|
|
|
|
#end
|
2023-11-13 20:35:03 +08:00
|
|
|
|
public CommonResult<Boolean> delete${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) {
|
|
|
|
|
${classNameVar}Service.delete${subSimpleClassName}(id);
|
2023-11-09 20:49:52 +08:00
|
|
|
|
return success(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 16:52:52 +08:00
|
|
|
|
#if ($table.deleteBatch)
|
|
|
|
|
@DeleteMapping("/${subSimpleClassName_strikeCase}/delete-batch")
|
|
|
|
|
@Parameter(name = "ids", description = "编号", required = true)
|
|
|
|
|
@Operation(summary = "批量删除${subTable.classComment}")
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
|
|
|
|
#end
|
|
|
|
|
public CommonResult<Boolean> delete${subSimpleClassName}(@RequestParam("ids") List<${subPrimaryColumn.javaType}> ids) {
|
|
|
|
|
${classNameVar}Service.delete${subSimpleClassName}ByIds(ids);
|
|
|
|
|
return success(true);
|
|
|
|
|
}
|
|
|
|
|
#end
|
|
|
|
|
|
2023-11-13 21:46:54 +08:00
|
|
|
|
@GetMapping("/${subSimpleClassName_strikeCase}/get")
|
|
|
|
|
@Operation(summary = "获得${subTable.classComment}")
|
|
|
|
|
@Parameter(name = "id", description = "编号", required = true)
|
|
|
|
|
#if ($sceneEnum.scene == 1)
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
|
|
|
|
#end
|
|
|
|
|
public CommonResult<${subTable.className}DO> get${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) {
|
|
|
|
|
return success(${classNameVar}Service.get${subSimpleClassName}(id));
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-09 20:49:52 +08:00
|
|
|
|
#end
|
|
|
|
|
#end
|
2023-11-07 20:43:53 +08:00
|
|
|
|
}
|