controller.java.vm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package ${packageName}.controller;
  2. import com.zksy.common.core.controller.BaseController;
  3. import com.zksy.system.basicData.domain.${ClassName};
  4. import com.zksy.system.basicData.service.${ClassName}Service;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.zksy.utils.SearchUtil;
  7. import com.zksy.common.annotation.Log;
  8. import com.zksy.common.enums.BusinessType;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.*;
  13. import java.util.List;
  14. /**
  15. * ${functionName}Controller
  16. *
  17. * @author ${author}
  18. * @date ${datetime}
  19. */
  20. @RestController
  21. @RequestMapping("/${className}")
  22. @Api(tags = "${functionName}", description = "${functionName}desc")
  23. public class ${ClassName}Controller extends BaseController{
  24. @Autowired
  25. private ${ClassName}Service service;
  26. @GetMapping("/getById/{borrowId}")
  27. @ApiOperation(value = "${functionName}搜索getById")
  28. public ${ClassName} getById(@PathVariable String borrowId) {
  29. return service.getById(borrowId);
  30. }
  31. @GetMapping("/findByPage")
  32. @ApiOperation(value = "${functionName}分页")
  33. public Page findByPage(long pageNum, long pageSize, String conditionJson) throws Exception {
  34. return service.page(new Page<>(pageNum, pageSize), SearchUtil.parseWhereSql(conditionJson));
  35. }
  36. @GetMapping("/getList")
  37. @ApiOperation(value = "${functionName}查询所有")
  38. public List<${ClassName}> getList(String conditionJson) throws Exception {
  39. return service.list(SearchUtil.parseWhereSql(conditionJson));
  40. }
  41. /**
  42. * 新增${functionName}
  43. */
  44. @PostMapping("/save")
  45. @ApiOperation(value = "${functionName}新增")
  46. @Log(title = "新增${functionName}", businessType = BusinessType.INSERT)
  47. public boolean save(@RequestBody ${ClassName} ${className}) {
  48. return service.save(${className});
  49. }
  50. /**
  51. * 修改${functionName}
  52. */
  53. @PostMapping("/updateById")
  54. @ApiOperation(value = "${functionName}修改")
  55. @Log(title = "修改${functionName}", businessType = BusinessType.UPDATE)
  56. public boolean updateById(@RequestBody ${ClassName} ${className}) {
  57. return service.updateById(${className});
  58. }
  59. /**
  60. * 导入${functionName}
  61. */
  62. @ApiOperation("${functionName}导入")
  63. @Log(title = "${functionName}", businessType = BusinessType.IMPORT)
  64. @PostMapping("/importData")
  65. public AjaxResult importData(MultipartFile file)
  66. {
  67. try {
  68. List<${ClassName}> ${className}All = service.list();
  69. List<${ClassName}> list = ExcelUtils.readMultipartFile(file, ${ClassName}.class,${ClassName}.class.getDeclaredFields().length - 2);
  70. if(${className}All != null && ${className}All.size() > 0){
  71. //return AjaxResult.error("数据已存在,如需重新导入请清空数据");
  72. }
  73. if(list.size() > 0){
  74. service.saveBatch(list);
  75. return success("导入成功,共计:"+list.size()+"条");
  76. }else{
  77. return AjaxResult.error("无数据");
  78. }
  79. }catch (Exception e){
  80. e.printStackTrace();
  81. return AjaxResult.error("导入数据失败");
  82. }
  83. }
  84. @ApiOperation("${functionName}导出")
  85. @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
  86. @PostMapping("/exportData")
  87. public AjaxResult exportData(HttpServletResponse response,String conditionJson){
  88. try {
  89. List<${ClassName}> wrapperList = service.list(SearchUtil.parseWhereSql(conditionJson));
  90. ExcelUtils.export(response,"${functionName}",wrapperList,${ClassName}.class);
  91. return AjaxResult.success("导出数据成功");
  92. }catch (Exception e){
  93. e.printStackTrace();
  94. return AjaxResult.error("导出数据失败");
  95. }
  96. }
  97. @Log(title = "${functionName}", businessType = BusinessType.DELETE)
  98. @PostMapping("/delete")
  99. @ApiOperation(value = "删除${functionName}", notes = "删除${functionName}")
  100. public AjaxResult delete(@RequestBody List<String> ids)
  101. {
  102. return toAjax(service.removeByIds(ids));
  103. }
  104. @DeleteMapping("/deleteAll")
  105. @ApiOperation(value = "清除数据", notes = "清除数据")
  106. public AjaxResult deleteAll(){
  107. return service.deleteAll();
  108. }
  109. @PostMapping("/getUploadTemplate")
  110. @ApiOperation(value = "获取上传模板", notes = "获取上传模板")
  111. public void getUploadTemplate(HttpServletResponse response) throws IOException {
  112. DowntemplateUtil.downloadTemplate(response,"${functionName}模板");
  113. }
  114. }