| | |
| | | package com.ruoyi.inspect.service.impl; |
| | | |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.lang.UUID; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | |
| | | /** |
| | | * @author 27233 |
| | |
| | | e.printStackTrace(); |
| | | log.error("附件上传错误"); |
| | | throw new ErrorException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void downloadOAFile(Long handlerFileId, HttpServletResponse response) { |
| | | response.reset(); |
| | | String fileName; |
| | | try { |
| | | //查询上传附件记录 |
| | | InsUnqualifiedHandlerFile file = baseMapper.selectById(handlerFileId); |
| | | if (file != null){ |
| | | fileName = file.getFileName(); |
| | | fileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
| | | //获取文件夹路径 |
| | | String path = file.getType()==1?imgUrl:wordUrl; |
| | | //文件完整路径 |
| | | String fullPath = path + file.getFileUrl(); |
| | | //判断文件是否存在 |
| | | File fullFile = new File(fullPath); |
| | | if(fullFile.exists()){ |
| | | IoUtil.copy(Files.newInputStream(fullFile.toPath()),response.getOutputStream()); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |