Blame view

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