TextbookDocController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.kgraph.web.controller;
  2. import java.io.IOException;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.kgraph.common.service.IFileService;
  6. import com.kgraph.common.utils.file.FileUtils;
  7. import org.springframework.security.access.prepost.PreAuthorize;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.PutMapping;
  12. import org.springframework.web.bind.annotation.DeleteMapping;
  13. import org.springframework.web.bind.annotation.PathVariable;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import com.kgraph.common.annotation.Log;;
  18. import com.kgraph.common.core.controller.BaseController;;
  19. import com.kgraph.common.core.domain.AjaxResult;;
  20. import com.kgraph.common.enums.BusinessType;;
  21. import com.kgraph.web.domain.TextbookDoc;
  22. import com.kgraph.web.service.ITextbookDocService;
  23. import com.kgraph.common.utils.poi.ExcelUtil;;
  24. import com.kgraph.common.core.page.TableDataInfo;;
  25. /**
  26. * 教材Controller
  27. *
  28. * @author Allen
  29. * @date 2023-04-13
  30. */
  31. @RestController
  32. @RequestMapping("/doc/textbook")
  33. public class TextbookDocController extends BaseController
  34. {
  35. @Autowired
  36. private ITextbookDocService textbookDocService;
  37. @Autowired
  38. private IFileService fileService;
  39. /**
  40. * 查询教材列表
  41. */
  42. @PreAuthorize("@ss.hasPermi('doc:textbook:list')")
  43. @GetMapping("/list")
  44. public TableDataInfo list(TextbookDoc textbookDoc)
  45. {
  46. startPage();
  47. List<TextbookDoc> list = textbookDocService.selectTextbookDocList(textbookDoc);
  48. return getDataTable(list);
  49. }
  50. /**
  51. * 导出教材列表
  52. */
  53. @PreAuthorize("@ss.hasPermi('doc:textbook:export')")
  54. @Log(title = "教材", businessType = BusinessType.EXPORT)
  55. @PostMapping("/export")
  56. public void export(HttpServletResponse response, TextbookDoc textbookDoc)
  57. {
  58. List<TextbookDoc> list = textbookDocService.selectTextbookDocList(textbookDoc);
  59. ExcelUtil<TextbookDoc> util = new ExcelUtil<TextbookDoc>(TextbookDoc.class);
  60. util.exportExcel(response, list, "教材数据");
  61. }
  62. /**
  63. * 获取教材详细信息
  64. */
  65. @PreAuthorize("@ss.hasPermi('doc:textbook:query')")
  66. @GetMapping(value = "/{id}")
  67. public AjaxResult getInfo(@PathVariable("id") Long id)
  68. {
  69. return success(textbookDocService.selectTextbookDocById(id));
  70. }
  71. /**
  72. * 新增教材
  73. */
  74. @PreAuthorize("@ss.hasPermi('doc:textbook:add')")
  75. @Log(title = "教材", businessType = BusinessType.INSERT)
  76. @PostMapping
  77. public AjaxResult add(@RequestBody TextbookDoc textbookDoc) throws IOException {
  78. int rows = textbookDocService.insertTextbookDoc(textbookDoc);
  79. if (rows > 0) {
  80. fileService.copyFileToESPath(FileUtils.getFileRealPath(textbookDoc.getFilePath()));
  81. }
  82. return toAjax(rows);
  83. }
  84. /**
  85. * 修改教材
  86. */
  87. @PreAuthorize("@ss.hasPermi('doc:textbook:edit')")
  88. @Log(title = "教材", businessType = BusinessType.UPDATE)
  89. @PutMapping
  90. public AjaxResult edit(@RequestBody TextbookDoc textbookDoc) throws IOException {
  91. int rows = textbookDocService.updateTextbookDoc(textbookDoc);
  92. if (rows > 0) {
  93. fileService.copyFileToESPath(FileUtils.getFileRealPath(textbookDoc.getFilePath()));
  94. }
  95. return toAjax(rows);
  96. }
  97. /**
  98. * 删除教材
  99. */
  100. @PreAuthorize("@ss.hasPermi('doc:textbook:remove')")
  101. @Log(title = "教材", businessType = BusinessType.DELETE)
  102. @DeleteMapping("/{ids}")
  103. public AjaxResult remove(@PathVariable Long[] ids)
  104. {
  105. return toAjax(textbookDocService.deleteTextbookDocByIds(ids));
  106. }
  107. }