You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.7 KiB

3 years ago
  1. package ${package.Controller};
  2. import java.util.List;
  3. import com.iteaj.framework.result.Result;
  4. import org.springframework.web.bind.annotation.*;
  5. import cn.afterturn.easypoi.excel.ExcelExportUtil;
  6. import org.apache.shiro.authz.annotation.RequiresPermissions;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import ${package.Entity}.${entity};
  10. import ${package.Dto}.${dto};
  11. import ${package.Service}.${table.serviceName};
  12. #if(${restControllerStyle})
  13. #else
  14. import org.springframework.stereotype.Controller;
  15. #end
  16. #if(${superControllerClassPackage})
  17. import ${superControllerClassPackage};
  18. #end
  19. /**
  20. * <p>
  21. * $!{cfg.moduleName}管理
  22. * </p>
  23. *
  24. * @author ${author}
  25. * @since ${date}
  26. */
  27. #if(${restControllerStyle})
  28. @RestController
  29. #else
  30. @Controller
  31. #end
  32. @RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
  33. #if(${kotlin})
  34. class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end
  35. #else
  36. #if(${superControllerClass})
  37. public class ${table.controllerName} extends ${superControllerClass} {
  38. #else
  39. public class ${table.controllerName} {
  40. #end
  41. #end
  42. private final ${table.serviceName} ${cfg.serviceName};
  43. public ${table.controllerName}(${table.serviceName} ${cfg.serviceName}) {
  44. this.${cfg.serviceName} = ${cfg.serviceName};
  45. }
  46. /**
  47. * 列表查询
  48. * @param page 分页
  49. * @param entity 搜索条件
  50. */
  51. @GetMapping("/view")
  52. @RequiresPermissions(value = {"${package.ModuleName}:${table.entityPath}:view"})
  53. public Result<IPage<${dto}>> list(Page<${dto}> page, ${dto} entity) {
  54. return this.${cfg.serviceName}.detailPage(page, entity);
  55. }
  56. /**
  57. * 获取编辑记录
  58. * @param id 记录id
  59. */
  60. @GetMapping("/edit")
  61. @RequiresPermissions({"${package.ModuleName}:${table.entityPath}:edit"})
  62. public Result<${dto}> getEditDetail(Long id) {
  63. return this.${cfg.serviceName}.detailById(id);
  64. }
  65. /**
  66. * 修改记录
  67. * @param entity
  68. */
  69. @PostMapping("/edit")
  70. @RequiresPermissions({"${package.ModuleName}:${table.entityPath}:edit"})
  71. public Result<Boolean> edit(@RequestBody ${entity} entity) {
  72. return this.${cfg.serviceName}.updateById(entity);
  73. }
  74. /**
  75. * 新增记录
  76. * @param entity
  77. */
  78. @PostMapping("/add")
  79. @RequiresPermissions({"${package.ModuleName}:${table.entityPath}:add"})
  80. public Result<Boolean> add(@RequestBody ${entity} entity) {
  81. return this.${cfg.serviceName}.save(entity);
  82. }
  83. /**
  84. * 删除指定记录
  85. * @param idList
  86. */
  87. @PostMapping("/del")
  88. @RequiresPermissions({"${package.ModuleName}:${table.entityPath}:del"})
  89. public Result<Boolean> remove(@RequestBody List<Long> idList) {
  90. return this.${cfg.serviceName}.removeByIds(idList);
  91. }
  92. #if(${table.exportable})
  93. /**
  94. * 导出记录
  95. * @param entity 导出参数
  96. */
  97. @GetMapping("/export")
  98. @RequiresPermissions({"${package.ModuleName}:${table.entityPath}:export"})
  99. public void exportRecord(Page<${dto}> page, ${dto} entity, HttpServletResponse response) {
  100. this.${cfg.serviceName}.detailPage(page, entity);
  101. ExcelExportUtil.exportExcel(null, ${dto}.class, page.getRecords());
  102. }
  103. #end
  104. #if(${table.importable})
  105. /**
  106. * 导入记录
  107. * @param entity 导入参数
  108. * @param file 导入文件
  109. */
  110. @PostMapping("/import")
  111. @RequiresPermissions({"${package.ModuleName}:${table.entityPath}:import"})
  112. public void importRecord(MultipartFile file, ${dto} entity) throws Exception {
  113. ExcelImportUtil.importExcel(file.getInputStream(), ${dto}.class, null);
  114. }
  115. #end
  116. }