1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
57
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package ${controllerPackage};
 
import java.util.Collection;
import java.util.Map;
import java.util.List;
import com.vci.starter.web.exception.VciBaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.vci.starter.web.pagemodel.*;
import com.vci.starter.web.annotation.*;
import ${voPackage}.${className}VO;
import ${dtoPackage}.${className}DTO;
import ${servicePackage}.${className}ServiceI;
import org.springframework.stereotype.Controller;
import com.vci.starter.web.util.*;
#if(${hasExcel})
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
#end
 
 
/**
 * ${comments}控制器
 *
 * @author ${author}
 * @date ${datetime}
 */
@RestController
@RequestMapping("${controllerRequestMap}")
#if(${hasPermisssion})
@VciPermission(modelKey = "${classNameFristLowwer}")
#end
public class ${className}Controller {
    /**
    * ${comments} 服务
    */
    @Autowired
    private ${className}ServiceI ${classNameFristLowwer}Service;
 
#if(!${hasParentField})
    /**
     * ${comments}列表
     * @param baseQueryObject 基础查询对象,包含查询条件,分页,排序等
     * @return ${comments}显示对象列表
     */
    @GetMapping("/grid${className}")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"VIEW","QUERY","ADVQUERY"},methodAlias = {"查看","查询","高级查询"},modelKey = {1,2,3})
#end
    public DataGrid<${className}VO> grid${className}(BaseQueryObject baseQueryObject){
        if(baseQueryObject == null){
            baseQueryObject = new BaseQueryObject();
        }
        return ${classNameFristLowwer}Service.grid${className}(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper());
    }
#else
    /**
     * ${comments}树
     * @param treeQueryObject 树形查询对象
     * @return ${comments}显示树
     */
    @GetMapping("/tree${className}")
    public List<Tree> tree${className}(TreeQueryObject treeQueryObject)  {
        return  ${classNameFristLowwer}Service.tree${className}(treeQueryObject);
    }
 
#end
    /**
     * 增加 ${comments}
     * @param ${classNameFristLowwer}DTO ${comments}数据传输对象
     * @return 执行结果,success为true表示成功,msg是失败的提示信息,obj是添加完成后的显示对象
     */
    @PostMapping( "/addSave")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"ADD"},methodAlias = {"添加"},modelKey = {4})
#end
    public BaseResult<${className}VO> addSave(@RequestBody ${className}DTO ${classNameFristLowwer}DTO){
         ${className}VO ${classNameFristLowwer}VO = ${classNameFristLowwer}Service.addSave(${classNameFristLowwer}DTO);
         return BaseResult.success(${classNameFristLowwer}VO);
    }
 
    /**
     * 修改 ${comments}
     * @param ${classNameFristLowwer}DTO ${comments}数据传输对象
     * @return 执行结果,success为true表示成功,msg是失败的提示信息,obj是添加完成后的显示对象
     */
    @PutMapping("/editSave")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"EDIT"},methodAlias = {"修改"},modelKey = {5})
#end
    public BaseResult<${className}VO> editSave(@RequestBody ${className}DTO ${classNameFristLowwer}DTO){
        ${className}VO ${classNameFristLowwer}VO = ${classNameFristLowwer}Service.editSave(${classNameFristLowwer}DTO);
        return BaseResult.success(${classNameFristLowwer}VO);
    }
 
#if(${hasParentField})
    /**
    * 检查 ${comments}是否删除
    * @param ${classNameFristLowwer}DTO ${comments}数据传输对象,必须要有oid和ts属性
    * @return 执行结果 success为true为可以删除,false表示有数据引用,obj为true表示有下级
    */
    @PostMapping( "/checkIsCanDelete")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"DELETE"},methodAlias = {"删除"},modelKey = {6})
#end
    public BaseResult checkIsCanDelete( ${className}DTO ${classNameFristLowwer}DTO)  {
        return ${classNameFristLowwer}Service.checkIsCanDelete(${classNameFristLowwer}DTO);
    }
#end
 
    /**
     * 删除${comments}
     * @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
     * @return 删除结果反馈::success:成功,fail:失败
     */
    @DeleteMapping( "/deleteData")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"DELETE"},methodAlias = {"删除"},modelKey = {6})
#end
    public BaseResult del${className}( ${className}DTO ${classNameFristLowwer}DTO) {
        return ${classNameFristLowwer}Service.delete${className}(${classNameFristLowwer}DTO);
    }
 
    /**
    * 主键获取${comments}
    * @param oid 主键
    * @return ${comments}显示对象
    */
    @GetMapping("/getObjectByOid")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"VIEW"},methodAlias = {"查看"},modelKey = {1})
#end
    public BaseResult<${className}VO> getObjectByOid(String oid){
        ${className}VO ${classNameFristLowwer}VO = ${classNameFristLowwer}Service.getObjectByOid(oid);
        return BaseResult.success(${classNameFristLowwer}VO);
    }
 
    /**
     * 主键批量获取${comments}
     * @param oids 主键,多个以逗号分隔,但是受性能影响,建议一次查询不超过10000个
     * @return ${comments}显示对象
     */
    @GetMapping("/listDataByOids")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"VIEW"},methodAlias = {"查看"},modelKey = {1})
#end
    public BaseResult<${className}VO> list${className}ByOids(String oids){
        Collection<${className}VO> voCollection =  ${classNameFristLowwer}Service.list${className}ByOids(VciBaseUtil.str2List(oids));
        BaseResult baseResult = BaseResult.success();
        baseResult.setData(voCollection);
        return  baseResult;
    }
 
#if(${hasEnable})
    /**
    * 启用${comments}
    * @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
#if(${hasParentField})
     * @param cascade 级联启用
#end
    * @return 启用结果反馈::success:成功,fail:失败
    */
    @PostMapping( "/enableData")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"ENABLE"},methodAlias = {"启用"},modelKey = {7})
#end
    public BaseResult enable${className}( ${className}DTO ${classNameFristLowwer}DTO#if(${hasParentField}),boolean cascade #end) {
        return ${classNameFristLowwer}Service.enable${className}(${classNameFristLowwer}DTO#if(${hasParentField}), cascade #end);
    }
 
    /**
     * 停用${comments}
     * @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
#if(${hasParentField})
     * @param cascade 级联停用
#end
     * @return 停用结果反馈::success:成功,fail:失败
     */
    @PostMapping(value = "/disableData")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"DISABLE"},methodAlias = {"停用"},modelKey = {8})
#end
    public BaseResult disable${className}( ${className}DTO ${classNameFristLowwer}DTO#if(${hasParentField}),boolean cascade #end) {
        return ${classNameFristLowwer}Service.disable${className}(${classNameFristLowwer}DTO#if(${hasParentField}), cascade #end);
    }
#end
 
#if(${hasExcel})
 
    /**
    * 导出的excel文件的名称
    */
    public static final String EXPORT_TEMPLATE_SHOW_NAME = "${comments}.xls";
 
    /**
    * excel模板的文件
    */
    public static final String EXPORT_TEMPLATE_FILE_NAME = "excelTemplate/${className}.xls";
 
    /**
    * 下载导入模板
    * @param response 响应对象
    * @param downloadUUID 下载需求,可以不传递
    * @return 执行的结果
    */
    @GetMapping("/downloadImportTemplate")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"IMPORT"},methodAlias = {"导入"},modelKey = {9})
#end
    public BaseResult downloadImportTemplate(HttpServletResponse response,String downloadUUID){
        //下载模板这个可以不校验downloadUUID
        //1.拷贝文件到临时文件夹中
        //2.可以根据实际情况,是否在下载导入模板时写入默认的值
        //3.下载excel
        String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + EXPORT_TEMPLATE_SHOW_NAME;
        LocalFileUtil.copyFileInJar(EXPORT_TEMPLATE_FILE_NAME,excelFileName);
        try {
            ControllerUtil.writeFileToResponse(response,new File(excelFileName),EXPORT_TEMPLATE_SHOW_NAME,true);
        } catch (FileNotFoundException e) {
            return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_TEMPLATE_FILE_NOT_FOUND);
        } catch (IOException e) {
            return BaseResult.fail(FrameWorkLangCodeConstant.DOWNLOAD_FAIL,new String[]{LangBaseUtil.getErrorMsg(e)},e);
        }
        return BaseResult.successMsg(FrameWorkLangCodeConstant.DOWNLOAD_SUCCESS);
    }
 
    /**
    * 导入 ${comments}
    * @param file excel文件
    * @param ${classNameFristLowwer}DTO 数据传输对象,作为导入的附加条件判断
    * @return 执行的结果,success为true表示执行成功·
    */
    @PostMapping( "/importData")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"IMPORT"},methodAlias = {"导入"},modelKey = {9})
#end
    public BaseResult import${className}(MultipartFile  file,${className}DTO ${classNameFristLowwer}DTO)  {
        BaseResult<?> baseResult = null;
        InputStream ins = null;
        try {
            if (file != null && !file.isEmpty()) {
                ins = file.getInputStream();
                baseResult = ${classNameFristLowwer}Service.import${className}(ins,${classNameFristLowwer}DTO);
            } else {
                return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL);
            }
        }catch (IOException e){
            throw new VciBaseException(e.getMessage(),new String[0],e);
        }catch (Throwable e) {
            throw e;
        }finally {
            IOUtils.closeQuietly(ins);
        }
        return baseResult;
    }
 
    /**
    * 导出${comments}
    * @param baseQueryObject 基础查询对象,包含查询条件,分页和排序
    * @param response 相应对象
    * @return 只有执行失败的时候返回结果才有效,msg是错误信息
    */
    @PostMapping(value = "/exportData")
#if(${hasPermisssion})
    @VciPermission(methodKey = {"EXPORT"},methodAlias = {"导出"},modelKey = {10})
#end
    public void export${className}(BaseQueryObject baseQueryObject, HttpServletResponse response){
        if(baseQueryObject == null){
            baseQueryObject = new BaseQueryObject();
        }
        String excelFileName = ${classNameFristLowwer}Service.export${className}(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper());
        try {
            ControllerUtil.writeFileToResponse(response, excelFileName);
        }catch (IOException e){
            throw new VciBaseException(e.getMessage(),new String[0],e);
        }catch (Throwable e){
            throw e;
        }
    }
#end
 
#if(!${hasParentField})
    /**
     * 参照${comments}列表
     * @param baseQueryObject 基础查询对象,包含查询条件,分页,排序等
     * @return ${comments}显示对象列表,生效的内容
     */
    @GetMapping("/refDataGrid")
#if(${hasPermisssion})
    @VciReferPermission(referedKey = "${className}Refer")
#end
    public DataGrid<${className}VO> refDataGrid${className}(BaseQueryObject baseQueryObject){
        if(baseQueryObject == null){
            baseQueryObject = new BaseQueryObject();
        }
        return ${classNameFristLowwer}Service.refDataGrid${className}(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper());
    }
#else
    /**
    * 参照树 ${comments}
    * @param treeQueryObject 树形查询对象
    * @return ${comments}显示树
    */
    @GetMapping("/referTree")
    #if(${hasPermisssion})
    @VciReferPermission(referedKey = "${className}ReferTree")
    #end
    public List<Tree> referTree(TreeQueryObject treeQueryObject)  {
        return ${classNameFristLowwer}Service.referTree(treeQueryObject);
    }
#end
 
}