|
@@ -1,18 +1,39 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
+import com.aspose.cells.PdfCompliance;
|
|
|
+import com.aspose.cells.PdfSaveOptions;
|
|
|
+import com.aspose.words.Document;
|
|
|
+import com.aspose.words.SaveFormat;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.rongwei.bscommon.sys.common.fegin.AdminFeginService;
|
|
|
import com.rongwei.bscommon.sys.dao.QhseVisitorManagementDao;
|
|
|
import com.rongwei.bscommon.sys.service.QhseVisitorManagementService;
|
|
|
+import com.rongwei.bscommon.sys.utils.WordMergeHandler;
|
|
|
+import com.rongwei.bscommon.sys.utils.WordUtils;
|
|
|
import com.rongwei.bsentity.domain.QhseVisitorManagementDo;
|
|
|
import com.rongwei.bsentity.vo.QhseVisitorManagementVo;
|
|
|
+import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommon.vo.generalsql.MasterSlaveInsertVo;
|
|
|
+import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static com.rongwei.bscommon.sys.utils.QHSEConstant.FILE_SEPARATOR;
|
|
|
+
|
|
|
/**
|
|
|
* 访客管理(QhseVisitorManagement)表服务实现类
|
|
|
*
|
|
@@ -22,6 +43,8 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class QhseVisitorManagementServiceImpl extends ServiceImpl<QhseVisitorManagementDao, QhseVisitorManagementDo> implements QhseVisitorManagementService {
|
|
|
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
@Autowired
|
|
|
private AdminFeginService adminFeginService;
|
|
|
|
|
@@ -31,6 +54,9 @@ public class QhseVisitorManagementServiceImpl extends ServiceImpl<QhseVisitorMan
|
|
|
@Autowired
|
|
|
private QhseVisitorManagementService qhseVisitorManagementService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FileFormatConversionServiceImpl fileFormatConversionService;
|
|
|
+
|
|
|
@Override
|
|
|
public void generalMsInsert(MasterSlaveInsertVo masterSlaveInsert) {
|
|
|
adminFeginService.generalMsInsert(masterSlaveInsert);
|
|
@@ -62,5 +88,72 @@ public class QhseVisitorManagementServiceImpl extends ServiceImpl<QhseVisitorMan
|
|
|
public int getBlackListByIdNum(String idNumber) {
|
|
|
return qhseVisitorManagementDao.getBlackListByIdNum(idNumber);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void previewForAttachmentWithSignature(String signature, String fileId, HttpServletResponse response) {
|
|
|
+
|
|
|
+ SysFileItemDo tempDo = fileFormatConversionService.fileCheck(fileId);
|
|
|
+ if (tempDo == null) {
|
|
|
+ logger.error("无法根据id:{}获取到文件信息", fileId);
|
|
|
+ throw new CustomException("无法获取到附件模板");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 模板路径
|
|
|
+ String tempFullpath = tempDo.getFullpath();
|
|
|
+ if (StringUtils.isBlank(tempFullpath)) {
|
|
|
+ logger.error("无法根据id:{}获取到文件信息", fileId);
|
|
|
+ throw new CustomException("无法获取到附件模板");
|
|
|
+ }
|
|
|
+
|
|
|
+ String signatureId = signature.split(FILE_SEPARATOR)[1];
|
|
|
+ SysFileItemDo signatureDo = fileFormatConversionService.fileCheck(signatureId);
|
|
|
+ if (signatureDo == null) {
|
|
|
+ logger.error("无法根据id:{}获取到签名信息", signatureId);
|
|
|
+ throw new CustomException("无法获取到签名");
|
|
|
+ }
|
|
|
+ // 乙方签名路径
|
|
|
+ String signaturePath = signatureDo.getFullpath();
|
|
|
+ if (StringUtils.isBlank(signaturePath)) {
|
|
|
+ logger.error("无法根据id:{}获取到签名信息", signatureId);
|
|
|
+ throw new CustomException("无法获取到签名");
|
|
|
+ }
|
|
|
+
|
|
|
+ File file = new File(tempFullpath);
|
|
|
+
|
|
|
+
|
|
|
+ try (InputStream templateStream = Files.newInputStream(Paths.get(tempFullpath));
|
|
|
+ OutputStream out = response.getOutputStream();) {
|
|
|
+ Document doc = new Document(templateStream);
|
|
|
+ // 设置邮件合并回调
|
|
|
+ doc.getMailMerge().setFieldMergingCallback(new WordMergeHandler());
|
|
|
+ HashMap<String, String> objectObjectHashMap = new HashMap<>();
|
|
|
+ objectObjectHashMap.put("YFQM", signaturePath);
|
|
|
+ WordUtils.MailMergeFill(objectObjectHashMap, doc);
|
|
|
+
|
|
|
+ String fileName = null;
|
|
|
+ try {
|
|
|
+ fileName = URLEncoder.encode(tempDo.getFilename(), "utf-8");
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("文件名转换异常");
|
|
|
+ }
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+
|
|
|
+ response.setHeader("X-Content-Length", String.valueOf(tempDo.getFilesize()));
|
|
|
+ response.setHeader("X-Content-Length", String.valueOf( file.length()));
|
|
|
+
|
|
|
+
|
|
|
+ // 设置 PDF 转换选项
|
|
|
+ PdfSaveOptions options = new PdfSaveOptions();
|
|
|
+ options.setCompliance(PdfCompliance.PDF_A_1_A); // 设置PDF/A-1a标准
|
|
|
+ // 3. 直接输出到响应流(避免中间文件)
|
|
|
+ doc.save(out, SaveFormat.PDF);
|
|
|
+ // 4. 强制刷新缓冲区(确保数据完整传输)
|
|
|
+ out.flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("excel转pdf失败- 原因: {} | 异常类型: {}", e.getMessage(), e.getClass().getSimpleName(), e);
|
|
|
+ throw new CustomException("获取签名责任书失败!请联系系统管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|