|
|
@@ -3,6 +3,7 @@ package com.xunmei.core.registerbook.service.impl;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
@@ -32,7 +33,6 @@ import org.apache.commons.io.FileUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.BoundValueOperations;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
@@ -41,6 +41,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
+import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.file.Files;
|
|
|
import java.util.*;
|
|
|
@@ -75,11 +76,10 @@ public class CoreRegisterBookPdfServiceImpl extends ServiceImpl<CoreRegisterBook
|
|
|
} else {
|
|
|
wrapper.eq(CoreRegisterBookPdf::getOrgId, req.getOrgId());
|
|
|
}
|
|
|
- if(!ObjectUtil.isNull(req.getRegisterBookType()))
|
|
|
- {
|
|
|
+ if (!ObjectUtil.isNull(req.getRegisterBookType())) {
|
|
|
wrapper.eq(CoreRegisterBookPdf::getRegisterBookType, req.getRegisterBookType());
|
|
|
}
|
|
|
- if(req.getDate()!=null){
|
|
|
+ if (req.getDate() != null) {
|
|
|
wrapper.between(CoreRegisterBookPdf::getDate, DateUtil.beginOfMonth(req.getDate()), DateUtil.endOfMonth(req.getDate()));
|
|
|
wrapper.orderByDesc(CoreRegisterBookPdf::getDate);
|
|
|
}
|
|
|
@@ -215,7 +215,7 @@ public class CoreRegisterBookPdfServiceImpl extends ServiceImpl<CoreRegisterBook
|
|
|
}
|
|
|
List<PdfLocalFileTempVo> list = new ArrayList<>();
|
|
|
for (String key : keys) {
|
|
|
- String json = redisTemplate.opsForValue().get(key);
|
|
|
+ String json = redisTemplate.opsForValue().get(key);
|
|
|
PdfLocalFileTempVo pdfLocalFileTempVo = JSON.parseObject(json, PdfLocalFileTempVo.class);
|
|
|
if (pdfLocalFileTempVo == null || ObjectUtil.notEqual(pdfLocalFileTempVo.getIsRegisterBookPage(), exportDto.getIsRegisterBookPage())) {
|
|
|
continue;
|
|
|
@@ -237,10 +237,12 @@ public class CoreRegisterBookPdfServiceImpl extends ServiceImpl<CoreRegisterBook
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void downLoad(PdfLocalFileTempVo tempVo, HttpServletResponse response) {
|
|
|
+ public void downLoad(JSONObject tempVo, HttpServletResponse response) {
|
|
|
+ final String localPathPrefix = fileService.getLocalPathPrefix().getData();
|
|
|
ServletOutputStream out = null;
|
|
|
ByteArrayOutputStream baos = null;
|
|
|
- File file = FileUtils.getFile(tempVo.getLocalFileName());
|
|
|
+ String localFileName = tempVo.get("localFileName").toString();
|
|
|
+ File file = FileUtils.getFile(localFileName);
|
|
|
if (!file.exists()) {
|
|
|
response.setStatus(HttpStatus.NOT_FOUND.value());
|
|
|
return;
|
|
|
@@ -256,11 +258,13 @@ public class CoreRegisterBookPdfServiceImpl extends ServiceImpl<CoreRegisterBook
|
|
|
}
|
|
|
baos.flush();
|
|
|
response.setContentType("application/octet-stream");
|
|
|
-
|
|
|
-
|
|
|
- String header = "attachment; filename=" + URLEncoder.encode(tempVo.getZipName(), "UTF-8");
|
|
|
- if(header.matches("[a-zA-Z0-9._\\-]+") ){
|
|
|
- response.setHeader(HttpHeaders.CONTENT_DISPOSITION,header);
|
|
|
+ localFileName = localFileName.replace(localPathPrefix + File.separator , "");
|
|
|
+ final BoundValueOperations<String, String> ops = redisTemplate.boundValueOps(URLDecoder.decode(localFileName, "UTF-8"));
|
|
|
+ final String string = ops.get();
|
|
|
+ final PdfLocalFileTempVo object = JSON.parseObject(string, PdfLocalFileTempVo.class);
|
|
|
+ String header = "attachment; filename=" + URLEncoder.encode(object.getZipName(), "UTF-8");
|
|
|
+ if (header.matches("[a-zA-Z0-9._\\-]+")) {
|
|
|
+ response.setHeader(HttpHeaders.CONTENT_DISPOSITION, header);
|
|
|
}
|
|
|
response.setContentLength(baos.size());
|
|
|
baos.writeTo(out);
|