package com.ruoyi.project.VRdemo.controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.alibaba.excel.EasyExcel; import com.ruoyi.common.utils.excel.ExcelReadUtil; import com.ruoyi.framework.aspectj.lang.annotation.Anonymous; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.project.VRdemo.domain.Thesis; import com.ruoyi.project.VRdemo.domain.imData.ResearchImData; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.project.VRdemo.domain.Research; import com.ruoyi.project.VRdemo.service.IResearchService; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.common.utils.poi.ExcelUtil; import org.springframework.web.multipart.MultipartFile; /** * 研究Controller * * @author ruoyi * @date 2024-06-23 */ @RestController @RequestMapping("/vr/research") public class ResearchController extends BaseController { private final IResearchService researchService; public ResearchController(@Autowired IResearchService researchService) { this.researchService = researchService; } /** * 查询研究列表 */ @Anonymous @GetMapping("/list") public AjaxResult list(Research research) { List list = researchService.selectResearchList(research); AjaxResult ajaxResult = new AjaxResult(); ajaxResult.put("code", 200); ajaxResult.put("rows", list); ajaxResult.put("total", list.size()); return ajaxResult; } /** * 查询分页列表 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @GetMapping("/pageList") public TableDataInfo pageList(Research research) { startPage(); List list = researchService.selectResearchList(research); return getDataTable(list); } /** * 获取研究详细信息 */ @Anonymous @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(researchService.selectResearchById(id)); } /** * 新增研究 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @Log(title = "研究", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody Research research) { return toAjax(researchService.insertResearch(research)); } /** * 修改研究 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @Log(title = "研究", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody Research research) { return toAjax(researchService.updateResearch(research)); } /** * 删除研究 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @Log(title = "研究", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(researchService.deleteResearchByIds(ids)); } /** * 导出研究列表 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @Log(title = "研究", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, Research research) { List list = researchService.selectResearchList(research); ExcelUtil util = new ExcelUtil<>(Research.class); util.exportExcel(response, list, "研究数据"); } /** * 下载导入模板 */ @Anonymous @PostMapping("/importTemplate") public void importTemplate(HttpServletResponse response) throws IOException { List dataList = new ArrayList<>(); EasyExcel.write(response.getOutputStream(), ResearchImData.class).sheet("Sheet1").doWrite(dataList); } /** * 导入数据 */ @Anonymous @PostMapping("/import") public AjaxResult importData(MultipartFile file, boolean updateSupport) throws IOException { List list = ExcelReadUtil.read(file, ResearchImData.class, Research.class); // 调用服务层方法进行数据导入处理 String message = researchService.importData(list, updateSupport); // 返回成功响应,携带导入结果信息 return AjaxResult.success(message); } }