|
|
@ -13,6 +13,7 @@ import com.xujie.sys.modules.pms.data.MesTypeData; |
|
|
import com.xujie.sys.modules.pms.mapper.EamObjectMapper; |
|
|
import com.xujie.sys.modules.pms.mapper.EamObjectMapper; |
|
|
import com.xujie.sys.modules.pms.service.EamObjectService; |
|
|
import com.xujie.sys.modules.pms.service.EamObjectService; |
|
|
import com.xujie.sys.modules.report.dao.ProcedureDao; |
|
|
import com.xujie.sys.modules.report.dao.ProcedureDao; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.logging.Log; |
|
|
import org.apache.commons.logging.Log; |
|
|
import org.apache.poi.ss.formula.functions.LogicalFunction; |
|
|
import org.apache.poi.ss.formula.functions.LogicalFunction; |
|
|
@ -28,10 +29,7 @@ import java.net.URL; |
|
|
import java.net.URLConnection; |
|
|
import java.net.URLConnection; |
|
|
import java.net.URLEncoder; |
|
|
import java.net.URLEncoder; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.logging.Logger; |
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -41,7 +39,7 @@ import java.util.logging.Logger; |
|
|
* @date 2023/2/26 15:29 |
|
|
* @date 2023/2/26 15:29 |
|
|
* @version 1.0 |
|
|
* @version 1.0 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class EamObjectServiceImpl implements EamObjectService { |
|
|
public class EamObjectServiceImpl implements EamObjectService { |
|
|
|
|
|
|
|
|
@ -271,35 +269,45 @@ public class EamObjectServiceImpl implements EamObjectService { |
|
|
if (getFileData.isEmpty()) { |
|
|
if (getFileData.isEmpty()) { |
|
|
throw new RuntimeException("该文件不存在,请刷新列表"); |
|
|
throw new RuntimeException("该文件不存在,请刷新列表"); |
|
|
} |
|
|
} |
|
|
File file = new File(getFileData.getFirst().getUrl()); |
|
|
|
|
|
|
|
|
SysOssEntity oss = getFileData.getFirst(); |
|
|
|
|
|
|
|
|
|
|
|
// 创建文件对象 |
|
|
|
|
|
File file = new File(oss.getUrl()); |
|
|
if (!file.exists()) { |
|
|
if (!file.exists()) { |
|
|
throw new RuntimeException("文件不存在"); |
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("文件不存在"); |
|
|
} |
|
|
} |
|
|
// 核心:先 reset,清空所有可能的 header |
|
|
|
|
|
response.reset(); |
|
|
|
|
|
response.setContentType("application/octet-stream"); |
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String encodedFileName; |
|
|
try { |
|
|
try { |
|
|
String fileName = URLEncoder.encode(getFileData.getFirst().getFileName(), StandardCharsets.UTF_8).replaceAll("\\+", "%20"); |
|
|
|
|
|
response.setHeader( |
|
|
|
|
|
"Content-Disposition", |
|
|
|
|
|
"attachment; filename*=UTF-8''" + fileName |
|
|
|
|
|
); |
|
|
|
|
|
try ( |
|
|
|
|
|
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); |
|
|
|
|
|
ServletOutputStream os = response.getOutputStream() |
|
|
|
|
|
) { |
|
|
|
|
|
byte[] buffer = new byte[8192]; |
|
|
|
|
|
int len; |
|
|
|
|
|
while ((len = bis.read(buffer)) != -1) { |
|
|
|
|
|
os.write(buffer, 0, len); |
|
|
|
|
|
} |
|
|
|
|
|
os.flush(); |
|
|
|
|
|
|
|
|
encodedFileName = URLEncoder.encode(oss.getFileName(), "UTF-8"); |
|
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
|
throw new RuntimeException("文件名编码失败", e); |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
|
|
|
// 不能再写 response 了 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置响应头 |
|
|
|
|
|
if ("txt".equals(oss.getFileSuffix())){ |
|
|
|
|
|
response.setContentType("text/plain;charset=utf-8"); |
|
|
|
|
|
}else { |
|
|
|
|
|
response.setContentType("application/octet-stream;charset=utf-8"); |
|
|
|
|
|
} |
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + encodedFileName); |
|
|
|
|
|
|
|
|
|
|
|
try (FileInputStream fis = new FileInputStream(file); |
|
|
|
|
|
BufferedInputStream bis = new BufferedInputStream(fis); |
|
|
|
|
|
ServletOutputStream os = response.getOutputStream()) { |
|
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
|
|
int bytesRead; |
|
|
|
|
|
|
|
|
|
|
|
// 循环读取文件内容并写入到响应流中 |
|
|
|
|
|
while ((bytesRead = bis.read(buffer)) != -1) { |
|
|
|
|
|
os.write(buffer, 0, bytesRead); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
throw new RuntimeException("文件下载失败", e); |
|
|
throw new RuntimeException("文件下载失败", e); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|