潘志宝
5 天以前 6d75723f3e3bd43895db2470bc5fabb2314dbe8b
提交 | 用户 | 时间
e7c126 1 package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName};
H 2
3 import org.springframework.web.bind.annotation.*;
4 import ${jakartaPackage}.annotation.Resource;
5 import org.springframework.validation.annotation.Validated;
6 #if ($sceneEnum.scene == 1)import org.springframework.security.access.prepost.PreAuthorize;#end
7
8 import io.swagger.v3.oas.annotations.tags.Tag;
9 import io.swagger.v3.oas.annotations.Parameter;
10 import io.swagger.v3.oas.annotations.Operation;
11
12 import ${jakartaPackage}.validation.constraints.*;
13 import ${jakartaPackage}.validation.*;
14 import ${jakartaPackage}.servlet.http.*;
15 import java.util.*;
16 import java.io.IOException;
17
18 import ${PageParamClassName};
19 import ${PageResultClassName};
20 import ${CommonResultClassName};
21 import ${BeanUtils};
22 import static ${CommonResultClassName}.success;
23
24 import ${ExcelUtilsClassName};
25
26 import ${ApiAccessLogClassName};
27 import static ${OperateTypeEnumClassName}.*;
28
29 import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
30 import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
31 ## 特殊:主子表专属逻辑
32 #foreach ($subTable in $subTables)
33 import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
34 #end
35 import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service;
36
37 @Tag(name = "${sceneEnum.name} - ${table.classComment}")
38 @RestController
39 ##二级的 businessName 暂时不算在 HTTP 路径上,可以根据需要写
40 @RequestMapping("/${table.moduleName}/${simpleClassName_strikeCase}")
41 @Validated
42 public class ${sceneEnum.prefixClass}${table.className}Controller {
43
44     @Resource
45     private ${table.className}Service ${classNameVar}Service;
46
47     @PostMapping("/create")
48     @Operation(summary = "创建${table.classComment}")
49 #if ($sceneEnum.scene == 1)
50     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
51 #end
52     public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) {
53         return success(${classNameVar}Service.create${simpleClassName}(createReqVO));
54     }
55
56     @PutMapping("/update")
57     @Operation(summary = "更新${table.classComment}")
58 #if ($sceneEnum.scene == 1)
59     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
60 #end
61     public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) {
62         ${classNameVar}Service.update${simpleClassName}(updateReqVO);
63         return success(true);
64     }
65
66     @DeleteMapping("/delete")
67     @Operation(summary = "删除${table.classComment}")
68     @Parameter(name = "id", description = "编号", required = true)
69 #if ($sceneEnum.scene == 1)
70     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
71 #end
72     public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
73         ${classNameVar}Service.delete${simpleClassName}(id);
74         return success(true);
75     }
76
77     @GetMapping("/get")
78     @Operation(summary = "获得${table.classComment}")
79     @Parameter(name = "id", description = "编号", required = true, example = "1024")
80 #if ($sceneEnum.scene == 1)
81     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
82 #end
83     public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
84         ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id);
85         return success(BeanUtils.toBean(${classNameVar}, ${sceneEnum.prefixClass}${table.className}RespVO.class));
86     }
87
88 #if ( $table.templateType != 2 )
89     @GetMapping("/page")
90     @Operation(summary = "获得${table.classComment}分页")
91 #if ($sceneEnum.scene == 1)
92     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
93 #end
94     public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
95         PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO);
96         return success(BeanUtils.toBean(pageResult, ${sceneEnum.prefixClass}${table.className}RespVO.class));
97     }
98
99 ## 特殊:树表专属逻辑(树不需要分页接口)
100 #else
101     @GetMapping("/list")
102     @Operation(summary = "获得${table.classComment}列表")
103 #if ($sceneEnum.scene == 1)
104     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
105 #end
106     public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
107         List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
108         return success(BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class));
109     }
110
111 #end
112     @GetMapping("/export-excel")
113     @Operation(summary = "导出${table.classComment} Excel")
114 #if ($sceneEnum.scene == 1)
115     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")
116 #end
117     @ApiAccessLog(operateType = EXPORT)
118 #if ( $table.templateType != 2 )
119     public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO,
120               HttpServletResponse response) throws IOException {
121         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
122         List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO).getList();
123         // 导出 Excel
124         ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${table.className}RespVO.class,
125                         BeanUtils.toBean(list, ${table.className}RespVO.class));
126     }
127 ## 特殊:树表专属逻辑(树不需要分页接口)
128 #else
129     public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO,
130               HttpServletResponse response) throws IOException {
131         List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
132         // 导出 Excel
133         ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${table.className}RespVO.class,
134                         BeanUtils.toBean(list, ${table.className}RespVO.class));
135     }
136 #end
137
138 ## 特殊:主子表专属逻辑
139 #foreach ($subTable in $subTables)
140 #set ($index = $foreach.count - 1)
141 #set ($subSimpleClassName = $subSimpleClassNames.get($index))
142 #set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
143 #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
144 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
145 #set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
146 #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
147 #set ($subClassNameVar = $subClassNameVars.get($index))
148     // ==================== 子表($subTable.classComment) ====================
149
150 ## 情况一:MASTER_ERP 时,需要分查询页子表
151 #if ( $table.templateType == 11 )
152     @GetMapping("/${subSimpleClassName_strikeCase}/page")
153     @Operation(summary = "获得${subTable.classComment}分页")
154     @Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
155 #if ($sceneEnum.scene == 1)
156     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
157 #end
158     public CommonResult<PageResult<${subTable.className}DO>> get${subSimpleClassName}Page(PageParam pageReqVO,
159                                                                                         @RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
160         return success(${classNameVar}Service.get${subSimpleClassName}Page(pageReqVO, ${subJoinColumn.javaField}));
161     }
162
163 ## 情况二:非 MASTER_ERP 时,需要列表查询子表
164 #else
165     #if ( $subTable.subJoinMany )
166     @GetMapping("/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}")
167     @Operation(summary = "获得${subTable.classComment}列表")
168     @Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
169 #if ($sceneEnum.scene == 1)
170     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
171 #end
172     public CommonResult<List<${subTable.className}DO>> get${subSimpleClassName}ListBy${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
173         return success(${classNameVar}Service.get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}));
174     }
175
176     #else
177     @GetMapping("/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}")
178     @Operation(summary = "获得${subTable.classComment}")
179     @Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
180 #if ($sceneEnum.scene == 1)
181     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
182 #end
183     public CommonResult<${subTable.className}DO> get${subSimpleClassName}By${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
184         return success(${classNameVar}Service.get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}));
185     }
186
187     #end
188 #end
189 ## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
190 #if ( $table.templateType == 11 )
191     @PostMapping("/${subSimpleClassName_strikeCase}/create")
192     @Operation(summary = "创建${subTable.classComment}")
193 #if ($sceneEnum.scene == 1)
194     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
195 #end
196     public CommonResult<${subPrimaryColumn.javaType}> create${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) {
197         return success(${classNameVar}Service.create${subSimpleClassName}(${subClassNameVar}));
198     }
199
200     @PutMapping("/${subSimpleClassName_strikeCase}/update")
201     @Operation(summary = "更新${subTable.classComment}")
202 #if ($sceneEnum.scene == 1)
203     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
204 #end
205     public CommonResult<Boolean> update${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) {
206         ${classNameVar}Service.update${subSimpleClassName}(${subClassNameVar});
207         return success(true);
208     }
209
210     @DeleteMapping("/${subSimpleClassName_strikeCase}/delete")
211     @Parameter(name = "id", description = "编号", required = true)
212     @Operation(summary = "删除${subTable.classComment}")
213 #if ($sceneEnum.scene == 1)
214     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
215 #end
216     public CommonResult<Boolean> delete${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) {
217         ${classNameVar}Service.delete${subSimpleClassName}(id);
218         return success(true);
219     }
220
221     @GetMapping("/${subSimpleClassName_strikeCase}/get")
222     @Operation(summary = "获得${subTable.classComment}")
223     @Parameter(name = "id", description = "编号", required = true)
224 #if ($sceneEnum.scene == 1)
225     @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
226 #end
227     public CommonResult<${subTable.className}DO> get${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) {
228         return success(${classNameVar}Service.get${subSimpleClassName}(id));
229     }
230
231 #end
232 #end
233 }