java后端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

205 lines
7.2 KiB

  1. package ${packageName}.controller;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.springframework.security.access.prepost.PreAuthorize;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.PutMapping;
  9. import org.springframework.web.bind.annotation.DeleteMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import com.ruoyi.common.annotation.Log;
  15. import com.ruoyi.common.core.controller.BaseController;
  16. import com.ruoyi.common.core.domain.AjaxResult;
  17. import com.ruoyi.common.enums.BusinessType;
  18. import ${packageName}.domain.${ClassName};
  19. import ${packageName}.service.I${ClassName}Service;
  20. import com.ruoyi.common.utils.poi.ExcelUtil;
  21. #if($table.crud || $table.sub)
  22. import com.ruoyi.common.core.page.TableDataInfo;
  23. #elseif($table.tree)
  24. #end
  25. /**
  26. * ${functionName}Controller
  27. *
  28. * @author ${author}
  29. * @date ${datetime}
  30. */
  31. @RestController
  32. @RequestMapping("/${moduleName}/${businessName}")
  33. public class ${ClassName}Controller extends BaseController
  34. {
  35. @Autowired
  36. private I${ClassName}Service ${className}Service;
  37. /**
  38. * 查询${functionName}列表
  39. */
  40. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
  41. @GetMapping("/list")
  42. #if($table.crud || $table.sub)
  43. public TableDataInfo list(${ClassName} ${className})
  44. {
  45. startPage();
  46. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  47. return getDataTable(list);
  48. }
  49. #elseif($table.tree)
  50. public AjaxResult list(${ClassName} ${className})
  51. {
  52. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  53. return success(list);
  54. }
  55. #end
  56. /**
  57. * 导出${functionName}列表
  58. */
  59. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
  60. @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
  61. @PostMapping("/export")
  62. public void export(HttpServletResponse response, ${ClassName} ${className})
  63. {
  64. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  65. ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
  66. util.exportExcel(response, list, "${functionName}数据");
  67. }
  68. /**
  69. * ${functionName}导入模板
  70. */
  71. @PostMapping("/importTemplate")
  72. public void importTemplate(HttpServletResponse response) {
  73. ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
  74. util.importTemplateExcel(response, "${functionName}数据");
  75. }
  76. /**
  77. * ${functionName}导入
  78. */
  79. @Log(title = "${functionName}", businessType = BusinessType.IMPORT)
  80. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:import')")
  81. @PostMapping("/importData")
  82. public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
  83. ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
  84. List<${ClassName}> list = util.importExcel(file.getInputStream(), 0);
  85. String message = ${className}Service.import${ClassName}(list, updateSupport, getUsername());
  86. return AjaxResult.success(message);
  87. }
  88. /**
  89. * 获取${functionName}详细信息
  90. */
  91. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
  92. @GetMapping(value = "/{${pkColumn.javaField}}")
  93. public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
  94. {
  95. return success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
  96. }
  97. /**
  98. * 获取${functionName}详细信息,翻译字典
  99. */
  100. @GetMapping(value = "/detail/{${pkColumn.javaField}}")
  101. public AjaxResult detail(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
  102. {
  103. ${ClassName} detail = ${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField});
  104. TranslateUtils.translate(detail, false);
  105. return success(detail);
  106. }
  107. /**
  108. * 新增${functionName}
  109. */
  110. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
  111. @Log(title = "${functionName}", businessType = BusinessType.INSERT)
  112. @PostMapping("/add")
  113. public AjaxResult add(@RequestBody ${ClassName} ${className})
  114. {
  115. return toAjax(${className}Service.insert${ClassName}(${className}));
  116. }
  117. /**
  118. * 修改${functionName}
  119. */
  120. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
  121. @Log(title = "${functionName}", businessType = BusinessType.UPDATE)
  122. @PostMapping("/update")
  123. public AjaxResult edit(@RequestBody ${ClassName} ${className})
  124. {
  125. return toAjax(${className}Service.update${ClassName}(${className}));
  126. }
  127. /**
  128. * 删除${functionName}
  129. */
  130. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
  131. @Log(title = "${functionName}", businessType = BusinessType.DELETE)
  132. @GetMapping("/delete/{${pkColumn.javaField}s}")
  133. public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
  134. {
  135. return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
  136. }
  137. /**
  138. * 打印${functionName}
  139. */
  140. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:print')")
  141. @Log(title = "${functionName}", businessType = BusinessType.PRINT)
  142. @GetMapping("/print")
  143. public void printPdf(${ClassName} ${className}, HttpServletResponse response) throws Exception{
  144. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  145. TranslateUtils.translateList(list, false);
  146. PdfProperty pdf = new PdfProperty();
  147. pdf.setTitle("${functionName}");
  148. //pdf.setRowHeight(20f);
  149. ShoulderItem shoulder = new ShoulderItem();
  150. shoulder.setLeftItem("编制单位:");
  151. shoulder.setCenterItem("日期:" );
  152. shoulder.setRightItem("单位:");
  153. pdf.setShoulder(shoulder);
  154. float[] columnWidth = new float[]{20, 40, 10, 10, 10, 10};
  155. pdf.setColumnWidth(columnWidth);
  156. String[] header = new String[]{"A列", "B列", "C列", "D列", "E列", "F列"};
  157. pdf.setHeader(header);
  158. int[] aligns = new int[]{0, 0, 1, 1, 2, 2};
  159. pdf.setAligns(aligns);
  160. List<String[]> contentList = Lists.newArrayList();
  161. list.forEach(a ->{
  162. String[] str = new String[6];
  163. str[0] = "";
  164. str[1] = "";
  165. str[2] = "";
  166. str[3] = "";
  167. str[4] = "";
  168. str[5] = "";
  169. contentList.add(str);
  170. });
  171. pdf.setContentList(contentList);
  172. PageSet ps = new PageSet();
  173. ps.setPaperWidth(595.0f);
  174. ps.setPaperHeight(842.0f);
  175. ps.setPrintDirection("1");
  176. ps.setTableTotalWidth(520);
  177. ps.setMarginLeft(50);
  178. ps.setMarginRight(50);
  179. ps.setMarginTop(50);
  180. ps.setMarginBottom(50);
  181. pdf.setPageSet(ps);
  182. PdfUtils.initPdf(response, pdf);
  183. }
  184. }