|
|
@@ -19,6 +19,8 @@ import com.xunmei.common.core.domain.registerbook.vo.PdfToZipTempVo;
|
|
|
import com.xunmei.common.core.enums.RegisterBookType;
|
|
|
import com.xunmei.common.core.utils.DateHelper;
|
|
|
import com.xunmei.common.core.utils.uuid.UUID;
|
|
|
+import com.xunmei.common.redis.delay.RedisDelayedQueue;
|
|
|
+import com.xunmei.common.redis.delay.RegisterBookFileExpirationListener;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.file.utils.FileDownUtils;
|
|
|
import com.xunmei.file.utils.FileUploadUtils;
|
|
|
@@ -77,6 +79,11 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
|
|
|
@Autowired
|
|
|
private HttpServletRequest request;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisDelayedQueue delayedQueue;
|
|
|
+
|
|
|
+
|
|
|
private static PdfFilePathVo getLocalFilePath(String localFilePath, String businessType, String fileName) {
|
|
|
final String path = File.separator + businessType + File.separator + DateUtil.format(new Date(), "yyyy" + File.separator + "MM" + File.separator + "dd" + File.separator);
|
|
|
final File file = new File(localFilePath + path);
|
|
|
@@ -608,8 +615,8 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
response.setContentType("application/octet-stream");
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + zipName);
|
|
|
List<PdfToZipTempVo> pdfToZipTempVoList = registerBookPdfList.parallelStream().map(pdf -> {
|
|
|
- return resolve(pdf, count);
|
|
|
- }).filter(Objects::nonNull)
|
|
|
+ return resolve(pdf, count);
|
|
|
+ }).filter(Objects::nonNull)
|
|
|
.collect(Collectors.toList());
|
|
|
count.await();
|
|
|
pdfToZipTempVoList.removeIf(pdfToZipTempVo -> !FileUtil.exist(pdfToZipTempVo.getFile()));
|
|
|
@@ -635,7 +642,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public PdfToZipTempVo resolve(CoreRegisterBookPdfPageVo pdf,CountDownLatch count) {
|
|
|
+ public PdfToZipTempVo resolve(CoreRegisterBookPdfPageVo pdf, CountDownLatch count) {
|
|
|
|
|
|
final File temp = new File(TEMP_DIR_NAME);
|
|
|
if (!temp.exists()) {
|
|
|
@@ -703,20 +710,21 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
fileInputStream.close();
|
|
|
}
|
|
|
|
|
|
- private List<SysOrgVO> getChildrenList(Long orgId){
|
|
|
+ private List<SysOrgVO> getChildrenList(Long orgId) {
|
|
|
List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
return cacheList.stream()
|
|
|
.filter(org -> ObjectUtil.equal(org.getParentId(), orgId))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- private SysOrgVO getCurOrg(Long orgId){
|
|
|
+ private SysOrgVO getCurOrg(Long orgId) {
|
|
|
List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
return cacheList.stream()
|
|
|
.filter(org -> ObjectUtil.equal(org.getId(), orgId))
|
|
|
.findFirst().get();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public void cutFileCompress(CoreRegisterBookPdfExportDto pdfDto) {
|
|
|
SysOrgVO org = getCurOrg(pdfDto.getOrgId());
|
|
|
@@ -735,7 +743,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
zipName = URLEncoder.encode(fileNameStr + ".zip", "UTF-8");
|
|
|
|
|
|
List<PdfToZipTempVo> pdfToZipTempVoList = list.parallelStream().map(pdf -> {
|
|
|
- return resolve(pdf, count);
|
|
|
+ return resolve(pdf, count);
|
|
|
}).filter(Objects::nonNull)
|
|
|
.collect(Collectors.toList());
|
|
|
pdfToZipTempVoList.removeIf(pdfToZipTempVo -> !FileUtil.exist(pdfToZipTempVo.getFile()));
|
|
|
@@ -755,17 +763,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
zos.close();
|
|
|
fos.close();
|
|
|
num++;
|
|
|
- PdfLocalFileTempVo pdfLocalFileTempVo = new PdfLocalFileTempVo();
|
|
|
- pdfLocalFileTempVo.setOrgId(pdfDto.getOrgId());
|
|
|
- pdfLocalFileTempVo.setOrgName(org.getName());
|
|
|
- pdfLocalFileTempVo.setOrgPath(org.getPath());
|
|
|
- pdfLocalFileTempVo.setLocalFileName(localFileName);
|
|
|
- pdfLocalFileTempVo.setZipName(URLDecoder.decode(zipName, "UTF-8"));
|
|
|
- pdfLocalFileTempVo.setFileSize(changeUnit(fileSize));
|
|
|
- pdfLocalFileTempVo.setDownLoadTime(DateUtil.format(date, "yyyy-MM-dd HH:mm:ss"));
|
|
|
- pdfLocalFileTempVo.setIsRegisterBookPage(pdfDto.getIsRegisterBookPage());
|
|
|
- pdfLocalFileTempVo.setCreateTime(new Date());
|
|
|
- RedisUtils.setCacheObject(URLDecoder.decode(localFileName, "UTF-8"), JSON.toJSONString(pdfLocalFileTempVo));
|
|
|
+ saveFileDataToRedis(org, date, zipName, localFileName, fileSize, pdfDto);
|
|
|
} catch (Throwable e) {
|
|
|
throw new RuntimeException(e);
|
|
|
} finally {
|
|
|
@@ -779,6 +777,21 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void saveFileDataToRedis(SysOrgVO org, Date date, String zipName, String localFileName, long fileSize, CoreRegisterBookPdfExportDto pdfDto) throws UnsupportedEncodingException {
|
|
|
+ PdfLocalFileTempVo pdfLocalFileTempVo = new PdfLocalFileTempVo();
|
|
|
+ pdfLocalFileTempVo.setOrgId(pdfDto.getOrgId());
|
|
|
+ pdfLocalFileTempVo.setOrgName(org.getName());
|
|
|
+ pdfLocalFileTempVo.setOrgPath(org.getPath());
|
|
|
+ pdfLocalFileTempVo.setLocalFileName(localFileName);
|
|
|
+ pdfLocalFileTempVo.setZipName(URLDecoder.decode(zipName, "UTF-8"));
|
|
|
+ pdfLocalFileTempVo.setFileSize(changeUnit(fileSize));
|
|
|
+ pdfLocalFileTempVo.setDownLoadTime(DateUtil.format(date, "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ pdfLocalFileTempVo.setIsRegisterBookPage(pdfDto.getIsRegisterBookPage());
|
|
|
+ pdfLocalFileTempVo.setCreateTime(new Date());
|
|
|
+ RedisUtils.setCacheObject(URLDecoder.decode(localFileName, "UTF-8"), JSON.toJSONString(pdfLocalFileTempVo));
|
|
|
+ delayedQueue.addQueueHours(pdfLocalFileTempVo.getLocalFileName(), 1, RegisterBookFileExpirationListener.class);
|
|
|
+ }
|
|
|
+
|
|
|
private List<List<CoreRegisterBookPdfPageVo>> checkSubList(CoreRegisterBookPdfExportDto pdfDto) {
|
|
|
List<List<CoreRegisterBookPdfPageVo>> list = new ArrayList<>();
|
|
|
List<CoreRegisterBookPdfPageVo> registerBookPdfList = pdfDto.getDataList();
|