controller.vm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName};
  2. import org.springframework.web.bind.annotation.*;
  3. import javax.annotation.Resource;
  4. import org.springframework.validation.annotation.Validated;
  5. #if ($sceneEnum.scene == 1)import org.springframework.security.access.prepost.PreAuthorize;#end
  6. import io.swagger.v3.oas.annotations.tags.Tag;
  7. import io.swagger.v3.oas.annotations.Parameter;
  8. import io.swagger.v3.oas.annotations.Operation;
  9. import javax.validation.constraints.*;
  10. import javax.validation.*;
  11. import javax.servlet.http.*;
  12. import java.util.*;
  13. import java.io.IOException;
  14. import ${PageResultClassName};
  15. import ${CommonResultClassName};
  16. import static ${CommonResultClassName}.success;
  17. import ${ExcelUtilsClassName};
  18. import ${OperateLogClassName};
  19. import static ${OperateTypeEnumClassName}.*;
  20. import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
  21. import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
  22. import ${basePackage}.module.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;
  23. import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service;
  24. @Tag(name = "${sceneEnum.name} - ${table.classComment}")
  25. @RestController
  26. ##二级的 businessName 暂时不算在 HTTP 路径上,可以根据需要写
  27. @RequestMapping("/${table.moduleName}/${simpleClassName_strikeCase}")
  28. @Validated
  29. public class ${sceneEnum.prefixClass}${table.className}Controller {
  30. @Resource
  31. private ${table.className}Service ${classNameVar}Service;
  32. @PostMapping("/create")
  33. @Operation(summary = "创建${table.classComment}")
  34. #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")#end
  35. public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) {
  36. return success(${classNameVar}Service.create${simpleClassName}(createReqVO));
  37. }
  38. @PutMapping("/update")
  39. @Operation(summary = "更新${table.classComment}")
  40. #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")#end
  41. public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) {
  42. ${classNameVar}Service.update${simpleClassName}(updateReqVO);
  43. return success(true);
  44. }
  45. @DeleteMapping("/delete")
  46. @Operation(summary = "删除${table.classComment}")
  47. @Parameter(name = "id", description = "编号", required = true)
  48. #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")#end
  49. public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
  50. ${classNameVar}Service.delete${simpleClassName}(id);
  51. return success(true);
  52. }
  53. @GetMapping("/get")
  54. @Operation(summary = "获得${table.classComment}")
  55. @Parameter(name = "id", description = "编号", required = true, example = "1024")
  56. #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end
  57. public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
  58. ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id);
  59. return success(${table.className}Convert.INSTANCE.convert(${classNameVar}));
  60. }
  61. @GetMapping("/page")
  62. @Operation(summary = "获得${table.classComment}分页")
  63. #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end
  64. public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageVO) {
  65. PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO);
  66. return success(${table.className}Convert.INSTANCE.convertPage(pageResult));
  67. }
  68. @GetMapping("/export-excel")
  69. @Operation(summary = "导出${table.classComment} Excel")
  70. #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")#end
  71. @OperateLog(type = EXPORT)
  72. public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO,
  73. HttpServletResponse response) throws IOException {
  74. List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(exportReqVO);
  75. // 导出 Excel
  76. List<${sceneEnum.prefixClass}${table.className}ExcelVO> datas = ${table.className}Convert.INSTANCE.convertList02(list);
  77. ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas);
  78. }
  79. }