controller.vm 4.9 KB

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