|
|
@@ -1,17 +1,21 @@
|
|
|
package com.xunmei.file.service;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.lowagie.text.*;
|
|
|
import com.lowagie.text.pdf.BaseFont;
|
|
|
import com.lowagie.text.pdf.PdfPCell;
|
|
|
import com.lowagie.text.pdf.PdfPTable;
|
|
|
import com.lowagie.text.pdf.PdfWriter;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.domain.IdName;
|
|
|
import com.xunmei.common.core.domain.registerbook.dto.CoreRegisterBookPdfExportDto;
|
|
|
import com.xunmei.common.core.domain.registerbook.dto.ExportPdfDto;
|
|
|
import com.xunmei.common.core.domain.registerbook.vo.CoreRegisterBookPdfPageVo;
|
|
|
+import com.xunmei.common.core.domain.registerbook.vo.PdfLocalFileTempVo;
|
|
|
import com.xunmei.common.core.domain.registerbook.vo.PdfToZipTempVo;
|
|
|
import com.xunmei.common.core.enums.RegisterBookType;
|
|
|
import com.xunmei.common.core.utils.DateHelper;
|
|
|
@@ -22,6 +26,7 @@ import com.xunmei.file.utils.PdfUtil;
|
|
|
import com.xunmei.file.vo.FileBase64Vo;
|
|
|
import com.xunmei.file.vo.ItextPdfTableVo;
|
|
|
import com.xunmei.file.vo.PdfFilePathVo;
|
|
|
+import com.xunmei.system.api.domain.SysOrg;
|
|
|
import io.netty.util.internal.StringUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.tools.zip.ZipEntry;
|
|
|
@@ -41,6 +46,7 @@ import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
@@ -187,6 +193,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
}
|
|
|
return path;
|
|
|
}
|
|
|
+
|
|
|
private void dealHeader(Map<String, Object> dataMap, Document document, BaseFont abf, BaseFont fs) throws
|
|
|
DocumentException {
|
|
|
//处理标题
|
|
|
@@ -271,8 +278,10 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
String filePath = FileUploadUtils.uploadBase64(localFilePath, file);
|
|
|
return filePath;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 履职转pdf
|
|
|
+ *
|
|
|
* @param dest
|
|
|
* @throws IOException
|
|
|
* @throws DocumentException
|
|
|
@@ -283,7 +292,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
document.open();
|
|
|
|
|
|
// 使用语言包字体
|
|
|
- BaseFont abf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
|
|
|
+ BaseFont abf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
|
|
//字体
|
|
|
Font font = new Font(abf, 8);
|
|
|
|
|
|
@@ -563,7 +572,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
log.info("登记簿全部下载完成,开始压缩文件,数量:{}", pdfToZipTempVoList.size());
|
|
|
for (PdfToZipTempVo tempVo : pdfToZipTempVoList) {
|
|
|
log.info("当前开始处理第{}个文件 ", pdfToZipTempVoList.indexOf(tempVo) + 1);
|
|
|
- deal(zos, pdfDto, tempVo);
|
|
|
+ deal(zos, tempVo);
|
|
|
}
|
|
|
zos.flush();
|
|
|
zos.close();
|
|
|
@@ -637,7 +646,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void deal(ZipOutputStream zos, ExportPdfDto pdfDto, PdfToZipTempVo zipTempVo) throws Throwable {
|
|
|
+ public void deal(ZipOutputStream zos, PdfToZipTempVo zipTempVo) throws Throwable {
|
|
|
zos.setEncoding("GBK");
|
|
|
FileInputStream fileInputStream = new FileInputStream(zipTempVo.getFile());
|
|
|
zos.putNextEntry(new ZipEntry(zipTempVo.getEntryName()));
|
|
|
@@ -651,12 +660,15 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void cutFileCompress(CoreRegisterBookPdfExportDto pdfDto) {
|
|
|
+ //List<SysOrgCacheVo> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+
|
|
|
// String orgName = objectMapper.selectOrgNameById(pdfDto.getOrgId());
|
|
|
- /* Date date = new Date();
|
|
|
- Sy org = objectMapper.selectOrg(pdfDto.getOrgId());
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+
|
|
|
+ SysOrg org = getOrg(pdfDto.getOrgId());
|
|
|
String fileName = pdfDto.getIsRegisterBookPage() ? org.getName() + "_登记簿_" : org.getName() + "_数据报表_";
|
|
|
|
|
|
//判断需要分几片导出
|
|
|
@@ -677,14 +689,14 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
pdfToZipTempVoList.removeIf(pdfToZipTempVo -> !FileUtil.exist(pdfToZipTempVo.getFile()));
|
|
|
log.info("登记簿全部下载完成,开始压缩文件,数量:{}", pdfToZipTempVoList.size());
|
|
|
|
|
|
- String localFileName = URLEncoder.encode(RedisConstantKey.REGISTER_PDF_FILE_KEY + DateHelper.getDateString(date) + str + ZipUtil.ZIP_EXT, "UTF-8");
|
|
|
+ String localFileName = URLEncoder.encode(CacheConstants.REGISTER_PDF_FILE_KEY + DateHelper.getDateString(date) + str + ".zip", "UTF-8");
|
|
|
FileOutputStream fos = new FileOutputStream(localFileName);
|
|
|
ZipOutputStream zos = new ZipOutputStream(fos);
|
|
|
long fileSize = 0L;
|
|
|
for (PdfToZipTempVo tempVo : pdfToZipTempVoList) {
|
|
|
fileSize += tempVo.getFile().length();
|
|
|
- logger.info("当前开始处理第{}个文件 ", pdfToZipTempVoList.indexOf(tempVo) + 1);
|
|
|
- deal(zos, null, tempVo);
|
|
|
+ log.info("当前开始处理第{}个文件 ", pdfToZipTempVoList.indexOf(tempVo) + 1);
|
|
|
+ deal(zos, tempVo);
|
|
|
}
|
|
|
zos.flush();
|
|
|
fos.flush();
|
|
|
@@ -703,7 +715,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
pdfLocalFileTempVo.setCreateTime(new Date());
|
|
|
redisTemplate.opsForValue().set(URLDecoder.decode(localFileName, "UTF-8"), JSON.toJSONString(pdfLocalFileTempVo));
|
|
|
DateTime dateTime = DateUtil.offsetHour(new Date(), 1);
|
|
|
- delayTaskService.add("ExportLocalFileBusiness", dateTime, URLDecoder.decode(localFileName, "UTF-8"), 5, 2);
|
|
|
+ //delayTaskService.add("ExportLocalFileBusiness", dateTime, URLDecoder.decode(localFileName, "UTF-8"), 5, 2);
|
|
|
} catch (Throwable e) {
|
|
|
throw new RuntimeException(e);
|
|
|
} finally {
|
|
|
@@ -713,11 +725,12 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-*/
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
- /* private List<List<CoreRegisterBookPdfPageVo>> checkSubList(CoreRegisterBookPdfExportDto pdfDto) {
|
|
|
+
|
|
|
+ private List<List<CoreRegisterBookPdfPageVo>> checkSubList(CoreRegisterBookPdfExportDto pdfDto) {
|
|
|
List<List<CoreRegisterBookPdfPageVo>> list = new ArrayList<>();
|
|
|
- Long orgId = pdfDto.getOrgId();
|
|
|
List<CoreRegisterBookPdfPageVo> registerBookPdfList = pdfDto.getDataList();
|
|
|
if (registerBookPdfList == null || registerBookPdfList.size() == 0) {
|
|
|
throw new RuntimeException("暂无可下载数据!");
|
|
|
@@ -727,12 +740,13 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
list.add(registerBookPdfList);
|
|
|
return list;
|
|
|
}
|
|
|
- List<SysOrgVO> orgList = objectMapper.selectChildOrgList(orgId);
|
|
|
+// List<SysOrg> orgList = orgService.selectSysOrgByParentId(pdfDto.getOrgId(), SecurityConstants.INNER);
|
|
|
+ List<SysOrg> orgList = new ArrayList<>();
|
|
|
//大于3000条需要分片
|
|
|
return splitList(registerBookPdfList, orgList, 3000);
|
|
|
}
|
|
|
|
|
|
- public static List<List<CoreRegisterBookPdfPageVo>> splitList(List<CoreRegisterBookPdfPageVo> list, List<SysOrgVO> orgList, int size) {
|
|
|
+ public static List<List<CoreRegisterBookPdfPageVo>> splitList(List<CoreRegisterBookPdfPageVo> list, List<SysOrg> orgList, int size) {
|
|
|
// 根据机构分组
|
|
|
List<List<CoreRegisterBookPdfPageVo>> collect = orgList.stream().map(org -> {
|
|
|
List<CoreRegisterBookPdfPageVo> arrayList = new ArrayList<>();
|
|
|
@@ -748,11 +762,11 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
List<List<CoreRegisterBookPdfPageVo>> merged = new LinkedList<>();
|
|
|
List<CoreRegisterBookPdfPageVo> current = new ArrayList<>();
|
|
|
for (List<CoreRegisterBookPdfPageVo> group : collect) {
|
|
|
- if (group.size() >= 3000) {
|
|
|
+ if (group.size() >= size) {
|
|
|
merged.add(group);
|
|
|
} else {
|
|
|
current.addAll(group);
|
|
|
- if (current.size() >= 3000) {
|
|
|
+ if (current.size() >= size) {
|
|
|
merged.add(current);
|
|
|
current = new ArrayList<>();
|
|
|
}
|
|
|
@@ -763,5 +777,23 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
}
|
|
|
return merged;
|
|
|
//return merged.stream().limit(size).collect(Collectors.toList());
|
|
|
- }*/
|
|
|
+ }
|
|
|
+
|
|
|
+ public String changeUnit(Long fileSize) {
|
|
|
+ if (fileSize == null || fileSize == 0) {
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ //将fileSize转换为MB,保留整数
|
|
|
+ BigDecimal fileSizeMB = new BigDecimal(fileSize).divide(new BigDecimal(1024 * 1024), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ return fileSizeMB.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysOrg getOrg(Long orgId) {
|
|
|
+ /* SysOrg sysOrg = orgService.selectOrgById(orgId, SecurityConstants.INNER);
|
|
|
+ return sysOrg;*/
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|