ResearchController.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.ruoyi.project.VRdemo.controller;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import javax.servlet.http.HttpServletResponse;
  6. import com.alibaba.excel.EasyExcel;
  7. import com.ruoyi.common.utils.excel.ExcelReadUtil;
  8. import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
  9. import com.ruoyi.framework.web.page.TableDataInfo;
  10. import com.ruoyi.project.VRdemo.domain.Thesis;
  11. import com.ruoyi.project.VRdemo.domain.imData.ResearchImData;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.PutMapping;
  17. import org.springframework.web.bind.annotation.DeleteMapping;
  18. import org.springframework.web.bind.annotation.PathVariable;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  23. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  24. import com.ruoyi.project.VRdemo.domain.Research;
  25. import com.ruoyi.project.VRdemo.service.IResearchService;
  26. import com.ruoyi.framework.web.controller.BaseController;
  27. import com.ruoyi.framework.web.domain.AjaxResult;
  28. import com.ruoyi.common.utils.poi.ExcelUtil;
  29. import org.springframework.web.multipart.MultipartFile;
  30. /**
  31. * 研究Controller
  32. *
  33. * @author ruoyi
  34. * @date 2024-06-23
  35. */
  36. @RestController
  37. @RequestMapping("/vr/research")
  38. public class ResearchController extends BaseController {
  39. private final IResearchService researchService;
  40. public ResearchController(@Autowired IResearchService researchService) {
  41. this.researchService = researchService;
  42. }
  43. /**
  44. * 查询研究列表
  45. */
  46. @Anonymous
  47. @GetMapping("/list")
  48. public AjaxResult list(Research research) {
  49. List<Research> list = researchService.selectResearchList(research);
  50. AjaxResult ajaxResult = new AjaxResult();
  51. ajaxResult.put("code", 200);
  52. ajaxResult.put("rows", list);
  53. ajaxResult.put("total", list.size());
  54. return ajaxResult;
  55. }
  56. /**
  57. * 查询分页列表
  58. */
  59. @PreAuthorize("@ss.hasAnyRoles('admin,xmg')")
  60. @GetMapping("/pageList")
  61. public TableDataInfo pageList(Research research) {
  62. startPage();
  63. List<Research> list = researchService.selectResearchList(research);
  64. return getDataTable(list);
  65. }
  66. /**
  67. * 获取研究详细信息
  68. */
  69. @Anonymous
  70. @GetMapping(value = "/{id}")
  71. public AjaxResult getInfo(@PathVariable("id") Long id) {
  72. return success(researchService.selectResearchById(id));
  73. }
  74. /**
  75. * 新增研究
  76. */
  77. @PreAuthorize("@ss.hasAnyRoles('admin,xmg')")
  78. @Log(title = "研究", businessType = BusinessType.INSERT)
  79. @PostMapping
  80. public AjaxResult add(@RequestBody Research research) {
  81. return toAjax(researchService.insertResearch(research));
  82. }
  83. /**
  84. * 修改研究
  85. */
  86. @PreAuthorize("@ss.hasAnyRoles('admin,xmg')")
  87. @Log(title = "研究", businessType = BusinessType.UPDATE)
  88. @PutMapping
  89. public AjaxResult edit(@RequestBody Research research) {
  90. return toAjax(researchService.updateResearch(research));
  91. }
  92. /**
  93. * 删除研究
  94. */
  95. @PreAuthorize("@ss.hasAnyRoles('admin,xmg')")
  96. @Log(title = "研究", businessType = BusinessType.DELETE)
  97. @DeleteMapping("/{ids}")
  98. public AjaxResult remove(@PathVariable Long[] ids) {
  99. return toAjax(researchService.deleteResearchByIds(ids));
  100. }
  101. /**
  102. * 导出研究列表
  103. */
  104. @PreAuthorize("@ss.hasAnyRoles('admin,xmg')")
  105. @Log(title = "研究", businessType = BusinessType.EXPORT)
  106. @PostMapping("/export")
  107. public void export(HttpServletResponse response, Research research) {
  108. List<Research> list = researchService.selectResearchList(research);
  109. ExcelUtil<Research> util = new ExcelUtil<>(Research.class);
  110. util.exportExcel(response, list, "研究数据");
  111. }
  112. /**
  113. * 下载导入模板
  114. */
  115. @Anonymous
  116. @PostMapping("/importTemplate")
  117. public void importTemplate(HttpServletResponse response) throws IOException {
  118. List<ResearchImData> dataList = new ArrayList<>();
  119. EasyExcel.write(response.getOutputStream(), ResearchImData.class).sheet("Sheet1").doWrite(dataList);
  120. }
  121. /**
  122. * 导入数据
  123. */
  124. @Anonymous
  125. @PostMapping("/import")
  126. public AjaxResult importData(MultipartFile file, boolean updateSupport) throws IOException {
  127. List<Research> list = ExcelReadUtil.read(file, ResearchImData.class, Research.class);
  128. // 调用服务层方法进行数据导入处理
  129. String message = researchService.importData(list, updateSupport);
  130. // 返回成功响应,携带导入结果信息
  131. return AjaxResult.success(message);
  132. }
  133. }