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.SpecialCollection; import com.ruoyi.project.VRdemo.domain.imData.SpecialCollectionImData; 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.service.ISpecialCollectionService; 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-10-06 */ @RestController @RequestMapping("/vr/specialCollection") public class SpecialCollectionController extends BaseController { private final ISpecialCollectionService collectionService; public SpecialCollectionController(@Autowired ISpecialCollectionService collectionService) { this.collectionService = collectionService; } /** * 查询东南亚大型特藏列表 */ @Anonymous @GetMapping("/list") public AjaxResult list(SpecialCollection specialCollection) { List list = collectionService.selectCollectionList(specialCollection); 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(SpecialCollection specialCollection) { startPage(); List list = collectionService.selectCollectionList(specialCollection); return getDataTable(list); } /** * 获取东南亚大型特藏详细信息 */ @Anonymous @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(collectionService.selectCollectionById(id)); } /** * 新增东南亚大型特藏 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @Log(title = "东南亚大型特藏", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody SpecialCollection specialCollection) { return toAjax(collectionService.insertCollection(specialCollection)); } /** * 修改东南亚大型特藏 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @Log(title = "东南亚大型特藏", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody SpecialCollection specialCollection) { return toAjax(collectionService.updateCollection(specialCollection)); } /** * 删除东南亚大型特藏 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @Log(title = "东南亚大型特藏", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(collectionService.deleteCollectionByIds(ids)); } /** * 导出东南亚大型特藏列表 */ @PreAuthorize("@ss.hasAnyRoles('admin,xmg')") @Log(title = "东南亚大型特藏", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, SpecialCollection specialCollection) { List list = collectionService.selectCollectionList(specialCollection); ExcelUtil util = new ExcelUtil<>(SpecialCollection.class); util.exportExcel(response, list, "东南亚大型特藏数据"); } /** * 下载导入模板 */ @Anonymous @PostMapping("/importTemplate") public void importTemplate(HttpServletResponse response) throws IOException { List dataList = new ArrayList<>(); EasyExcel.write(response.getOutputStream(), SpecialCollectionImData.class).sheet("Sheet1").doWrite(dataList); } /** * 导入数据 */ @Anonymous @PostMapping("/import") public AjaxResult importData(MultipartFile file, boolean updateSupport) throws IOException { List list = ExcelReadUtil.read(file, SpecialCollectionImData.class, SpecialCollection.class); // 调用服务层方法进行数据导入处理 String message = collectionService.importData(list, updateSupport); // 返回成功响应,携带导入结果信息 return AjaxResult.success(message); } }