package com.lxkj.document.service.impl;
import com.lxkj.activities.service.TCorrectArchiveService;
import com.lxkj.correct.dao.ArchiveAdjunctDao;
import com.lxkj.correct.domain.TCorrectArchiveVo;
import com.lxkj.correct.domain.vo.ArchiveAdjunctFileBean;
import com.lxkj.correct.service.AdjunctService;
import com.lxkj.correct.service.PenaltyInfoService;
import com.lxkj.document.bean.DataToFileResult;
import com.lxkj.document.bean.PdfFileBean;
import com.lxkj.document.bean.PdfFileVo;
import com.lxkj.document.domain.vo.PrintArchiveItemBean;
import com.lxkj.document.domain.vo.PrintParamBean;
import com.lxkj.document.entity.TDocumentPage;
import com.lxkj.document.entity.TDocumentPrintLog;
import com.lxkj.document.entity.TPdfFile;
import com.lxkj.document.handler.SignHandler;
import com.lxkj.document.service.*;
import com.lxkj.equipment.utils.BASE64DecodedMultipartFile;
import com.lxkj.frame.core.dao.BaseDao;
import com.lxkj.frame.core.dao.impl.BaseServiceImpl;
import com.lxkj.frame.core.security.CrossDomainToken;
import com.lxkj.frame.core.status.*;
import com.lxkj.frame.core.utils.*;
import com.lxkj.law.domain.CollegiateBench;
import com.lxkj.law.service.CollegiateBenchService;
import com.lxkj.manage.service.ITCorrectDiseaseCertificationService;
import com.lxkj.manage.service.ITCorrectDiseaseReviewService;
import com.lxkj.sys.domain.Material;
import com.lxkj.sys.domain.vo.TSignInfoBean;
import com.lxkj.sys.entity.*;
import com.lxkj.sys.service.*;
import com.core.util.AsyncSingleTaskSubmitter;
import com.core.util.AsyncTaskSubmitter;
import com.google.common.base.Verify;
import com.google.common.util.concurrent.ListenableFutureTask;
import com.itextpdf.text.Element;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.util.DateUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class DocumentServiceImpl extends BaseServiceImpl implements DocumentService {
private Logger log = LoggerFactory.getLogger(DocumentServiceImpl.class);
@Autowired
protected PrintArchiveService printArchiveService;
@Autowired
protected SignHisService signHisService;
@Autowired
protected TCorrectArchiveService correctArchiveService;
@Autowired
private OrgService orgService;
@Autowired
private DeptService deptService;
@Autowired
protected SignInfoService signInfoService;
@Autowired
private ISysOrgConfigService sysOrgConfigService;
@Autowired
private PdfFileService pdfFileService;
@Autowired
private DataToFileFactory dataToFileFactory;
@Autowired
private DocumentMenuService documentMenuService;
@Autowired
private DocumentVersionService documentVersionService;
@Autowired
private DocumentPageService documentPageService;
@Autowired
private ISysTenantConfigureService sysTenantConfigureService;
@Autowired
private SignControlService signControlService;
@Autowired
private DocumentPrintLogService documentPrintLogService;
@Autowired
private DocumentOrgConfigService documentOrgConfigService;
@Autowired
private SignPageInfoService signPageInfoService;
@Autowired
private MinioUploadUtils minioUploadUtils;
@Autowired
private MaterialService materialService;
@Autowired
private PenaltyInfoService penaltyInfoService;
@Autowired
private CollegiateBenchService collegiateBenchService;
@Autowired
private DataToPdfService dataToPdfService;
@Autowired
private ArchiveAdjunctDao archiveAdjunctDao;
@Autowired
private AdjunctService adjunctService;
@Autowired
private ITCorrectDiseaseReviewService correctDiseaseReviewService;
@Autowired
private ITCorrectDiseaseCertificationService diseaseCertificationService;
@Override
protected BaseDao getBaseDao() {
// TODO Auto-generated method stub
return null;
}
/**
* 根据文书标识获取服务类
*
* @param pageKey
*/
@Override
public DocumentBaseService getModualService(String pageKey) {
DocumentBaseService service = null;
try {
service = (DocumentBaseService) SpringHelper.getBean(EnumPageKey.lookup(pageKey).getClazz());
} catch (Exception e) {
log.error("获取文书功能模块Service失败({})", pageKey, e);
}
return service;
}
/**
* 显示打印文书
*
* @param dataPk
* @param pageKey
*/
@Override
public void showPrintPdf(Long dataPk, String pageKey, Boolean forceCreate, OutputStream out, PrintParamBean printParamBean) {
try {
printParamBean = getPrintParamBean(dataPk, pageKey, printParamBean);
TPdfFile pdf = getPdfFile(dataPk, pageKey, forceCreate, printParamBean);
if (pdf != null) {
// try {
//兼容已生成老版文书密码的问题
PdfUtils.onePDF(pdf, out, this.getWaterMarker(EnumPrintType.MODULE), true);
this.recordPrintOperate(EnumPrintType.MODULE, pageKey, Arrays.asList(pdf.getPdfPath()), printParamBean.getCurrentUser());
// //兼容云签章PDF文书和非云签章PDF文书
// PdfReader reader = new PdfReader(RequestUtil.getRootRealPath() + getPdfFold(dataPk, pageKey) + pdf.getPdfPath(), pdf.getPassword().getBytes());
// PdfStamper stamper = new PdfStamper(reader, out);
// stamper.close();
// reader.close();
// }catch(Exception e){
// log.error();
// }
} else {
log.warn("文书打开失败({}-{})", dataPk, printParamBean.getDocPage().getPageKeySub());
}
} catch (Exception e) {
log.error("文书打开异常({}-{})", dataPk, printParamBean.getDocPage().getPageKeySub(), e);
}
}
/**
* 获取指定矫正对象所有指定文书
*
* @param aPk 记录PK
* @param pageKey 文书标识
* @author 陈洪方
*/
@Override
public List
List
try {
//获取所有该文书的PDF记录
TPdfFile param = new TPdfFile();
param.setaPk(aPk);
param.setPageKey(pageKey);
param.setStatus(1L);
param.setDr(EnumDr.Valid.getValue());
List
if(dataList != null && dataList.size() > 0) {
//确认每个PDF是否存在,并加入打印列表中
for(TPdfFile item : dataList){
TPdfFile pdf = null;
if (minioUploadUtils.isExists(item.getPdfPath())) {
pdf = item;
}else {
//根据文书唯一标识获取文书枚举
EnumPageKey enumPageKey = EnumPageKey.lookup(pageKey);
//如果文书标识不存在或是文书不是系统生成的,则直接获取该文书
if(enumPageKey != null && enumPageKey.getClazz() != null){
PrintParamBean printParamBean = getPrintParamBean(item.getDataPk(), pageKey, null);
pdf = getPdfFile(item.getDataPk(), pageKey, null == doCreate ? false : doCreate, printParamBean);
}
}
if(pdf != null) {
int index = 0;
//以时间顺序排序
for (TPdfFile file : pdfList) {
if (pdf.getPkId() < file.getPkId()) {
break;
}
index++;
}
pdfList.add(index, pdf);
}
}
}
List
{
put("aPk", aPk);
if (StringUtils.isNotBlank(pageKey)) {
put("pageKey", pageKey);
}
}
});
if (CollectionUtils.isNotEmpty(aafList)) {
for (ArchiveAdjunctFileBean aaf : aafList) {
TPdfFile pdf = new TPdfFile();
if (minioUploadUtils.isExists(aaf.getUrl())) {
String pdfUrl = adjunctService.minioImageAdjToPdf(aaf.getUrl());
if (StringUtils.isNotBlank(pdfUrl)) {
pdf.setPageKey(aaf.getPageKey());
pdf.setPdfPath(pdfUrl);
pdf.setPdfName(aaf.getFileName());
pdfList.add(pdf);
}
} else {
continue;
}
}
}
} catch (Exception e) {
log.error("文书获取异常({}-{})", aPk, pageKey, e);
}
return pdfList;
}
/**
* 显示即时打印文书
*
* @param dataPk 记录PK
* @param pageKey 文书标识
* @param out http输出
* @param org
* @author 陈洪方
*/
@Override
public void showTempPrintPdf(Long dataPk, String pageKey, OutputStream out, PrintParamBean printParamBean, TOrg org) {
try {
//获取功能模块service
DocumentBaseService service = getModualService(pageKey);
if (service != null) {
EnumPageKey enumPageKey = EnumPageKey.lookup(pageKey);
DataToFileResult result = createTempPdf(dataPk, enumPageKey, getPrintParamBean(dataPk, pageKey, printParamBean));
if (result != null && result.isResult()) {
Path path = Paths.get(FileUtil.getRealPath() + result.getPath() + result.getFileName());
String minioPath = minioUploadUtils.upload(Files.newInputStream(path), Files.size(path), Files.probeContentType(path),
result.getFileName(), minioUploadUtils.filePath(org.getPkId(), pageKey));
Files.deleteIfExists(path);
TPdfFile pdf = new TPdfFile();
pdf.setPdfPath(minioPath);
PdfUtils.onePDF(pdf, out, this.getWaterMarker(EnumPrintType.OTHERS), true);
this.recordPrintOperate(EnumPrintType.ATTACHE, null, Arrays.asList(pdf.getPdfPath()), printParamBean.getCurrentUser());
// PdfReader reader = new PdfReader(RequestUtil.getRootRealPath() + result.getPath() + result.getFileName(), null);
// PdfStamper stamper = new PdfStamper(reader, out);
// stamper.close();
// reader.close();
} else {
log.warn("文书打开失败({}-{})", dataPk, printParamBean.getDocPage().getPageKeySub());
}
}
} catch (Exception e) {
log.error("文书打开异常({}-{})", dataPk, printParamBean.getDocPage().getPageKeySub(), e);
}
}
/**
* 显示动态生成文书
*
* @param dataPk 记录PK
* @param pageKey 文书标识
* @param out http输出
* @author 陈洪方
*/
@Override
public void showDynamicPdf(Long dataPk, String pageKey, OutputStream out, PrintParamBean printParamBean) {
try {
EnumPageKey enumPageKey = EnumPageKey.lookup(pageKey);
DataToFileResult fileResult = createTempPdf(dataPk, enumPageKey, getPrintParamBean(dataPk, pageKey, printParamBean));
if (fileResult != null && fileResult.isResult()) {
String filePath = RequestUtil.getRootRealPath() + fileResult.getPath() + fileResult.getFileName();
PdfReader reader = new PdfReader(filePath, null);
PdfStamper stamper = new PdfStamper(reader, out);
stamper.close();
reader.close();
} else {
log.warn("文书打开失败({}-{})", dataPk, printParamBean.getDocPage().getPageKeySub());
}
} catch (Exception e) {
log.error("文书打开异常({}-{})", dataPk, printParamBean.getDocPage().getPageKeySub(), e);
}
}
/**
* 显示签签名板页面
*
* @param dataPk 记录PK
* @param pageKey 文书标识
*/
@Override
public String showHandSignPage(Long dataPk, String pageKey, PrintParamBean printParamBean) {
try {
//获取功能模块service
DocumentBaseService service = getModualService(pageKey);
if (service == null) {
return null;
}
EnumPageKey enumPageKey = EnumPageKey.lookup(pageKey);
DataToFileResult result = createTempPdf(dataPk, enumPageKey, getPrintParamBean(dataPk, pageKey, printParamBean));
if (result != null && result.isResult()) {
result.getFilePath();
File file = new File(result.getFilePath());
if(file.exists()) {
InputStream in = new FileInputStream(file);
byte[] buffer = new byte[Integer.parseInt(String.valueOf(file.length()))];
in.read(buffer);
in.close();
FileUtils.forceDelete(file);
String tokenId = CrossDomainToken.addToken(buffer);
return "/com/document/getTempPdf?tokenId=" + tokenId;
}
}
} catch (Exception e) {
log.error("文书打开异常({}-{})", dataPk, printParamBean.getDocPage().getPageKeySub(), e);
}
return null;
}
/**
* 显示签章页面
*
* @param model
* @param dataPk 记录PK
* @param pageKey 文书标识
*/
@Override
public String showSignPage(Model model, Long dataPk, String pageKey, PrintParamBean printParamBean) {
return getHtml(model, dataPk, pageKey, true, getPrintParamBean(dataPk, pageKey, printParamBean));
}
/**
* 获取html模板页面
*
* @param model
* @param dataPk 记录PK
* @param pageKey 文书标识
*/
@Override
public String getHtmlTemplate(Model model, Long dataPk, String pageKey, PrintParamBean printParamBean) {
return getHtml(model, dataPk, pageKey, false, getPrintParamBean(dataPk, pageKey, printParamBean));
}
/**
* 重新创建Pdf
*
* @param dataPk 记录PK
* @param enumPageKey 文书标识
* @return 成功/失败
*/
@Override
public boolean createNewPdf(Long dataPk, EnumPageKey enumPageKey) {
TPdfFile pdf = getPdfFile(dataPk, enumPageKey.getPageKey(), true, getPrintParamBean(dataPk, enumPageKey.getPageKey(), null));
if (pdf == null) {
return false;
}
return true;
}
/**
* 创建指定记录PDF
*
* @param dataPk 记录PK
* @param enumPageKey 文书标识枚举
* @param printParamBean 文书参数
* @return 成功/失败
* @author 陈洪方
*/
@Override
public boolean createNewPdf(Long dataPk, EnumPageKey enumPageKey, PrintParamBean printParamBean) {
TPdfFile pdf = getPdfFile(dataPk, enumPageKey.getPageKey(), true, getPrintParamBean(dataPk, enumPageKey.getPageKey(), printParamBean));
if (pdf == null) {
return false;
}
return true;
}
/**
* 创建指定记录的多个文书
*
* @param dataPk 记录PK
* @param enumPageKeys 文书标识枚举
* @return 成功/失败
* @author 陈洪方
*/
@Override
public boolean createNewPdfs(Long dataPk, EnumPageKey... enumPageKeys) {
return this.createNewPdfs(dataPk, null, true, enumPageKeys);
}
/**
* 创建指定记录的多个文书
*
* @param dataPk 记录PK
* @param printParamBean 文书参数
* @param isSynchronized 是否未同步方式
* @param enumPageKeys 文书标识枚举
* @return 成功/失败
* @author 陈洪方
*/
@Override
public boolean createNewPdfs(Long dataPk, PrintParamBean printParamBean, boolean isSynchronized, EnumPageKey... enumPageKeys) {
Map
List
if (enumPageKeys != null && enumPageKeys.length > 0) {
List
String tenant = ThreadLocalUtil.get();
for (EnumPageKey enumPageKey : enumPageKeys) {
PrintParamBean bean = getPrintParamBean(dataPk, enumPageKey.getPageKey(), printParamBean);
printParamBeanMap.put(enumPageKey.getPageKey(), bean);
}
for (EnumPageKey enumPageKey : enumPageKeys) {
TDocumentPage page = printParamBeanMap.get(enumPageKey.getPageKey()).getDocPage();
if (page != null && !keyList.contains(page.getPageKey())) {
ListenableFutureTask
ThreadLocalUtil.set(tenant);
try {
this.getPdfFile(dataPk, enumPageKey.getPageKey(), true, printParamBeanMap.get(enumPageKey.getPageKey()));
} catch (Exception e) {
log.error("文书创建异常({}-{})", dataPk, enumPageKey.getPageKey(), e);
}
ThreadLocalUtil.remove();
}, null);
taskList.add(task);
keyList.add(page.getPageKey());
}
}
//如果为同步方式,则等待所有创建都完成
if (isSynchronized) {
for (int i = 0; i < taskList.size(); i++) {
try {
taskList.get(i).get();
} catch (Exception e) {
log.error("文书创建任务异常({}-{})", dataPk, taskList.get(i), e);
}
}
}
}
return true;
}
/**
* 异步生成文书
*
* @param dataPk
* @param printParamBean
* @param enumPageKeys
*/
@Override
public void asyncCreateNewPdfs(Long dataPk, PrintParamBean printParamBean, EnumPageKey... enumPageKeys) {
try {
String tenant = ThreadLocalUtil.get();
if (printParamBean == null && RequestUtil.getCurrentUser() != null) {
printParamBean = new PrintParamBean();
printParamBean.setHtmlUrl(UrlUtil.getUrl(RequestUtil.getRequest()));
printParamBean.setCurrentOrg(RequestUtil.getCurrentUserOrg());
printParamBean.setCurrentUser(RequestUtil.getCurrentUser());
printParamBean.setCurrentDept(RequestUtil.getCurrentUserDept());
}
PrintParamBean finalPrintParamBean = printParamBean;
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
AsyncSingleTaskSubmitter.submitAsyncTask(() -> {
RequestContextHolder.setRequestAttributes(sra, true);
ThreadLocalUtil.set(tenant);
SpringHelper.getBean(DocumentService.class).createNewPdfs(dataPk, finalPrintParamBean, true, enumPageKeys);
ThreadLocalUtil.remove();
}, null);
} catch (Exception e) {
log.error("生成文书[asyncCreateNewPdfs]出错:", e);
}
}
/**
* 文书签章签名
*
* @param pageKey 文书标识
* @param dataPk 被签章数据的PK
* @param signPk 签章PK
* @param position 签章在打印页面显示的位置
* @param signKey 签章关键字
* @return 签名签章结果
* @author 陈洪方
*/
@Override
public String addSignHis(Long dataPk, String pageKey, Long signPk, String position, String signKey, TUser user) {
//检查签名或签章是否存在
TSignInfo signInfo = signInfoService.selectById(signPk);
if (signInfo == null) {
return "未找到签章或签名";
}
//添加签名或签章记录
String msg = signHisService.addSignHis(pageKey, dataPk, user.getPkId(), signPk, position, signKey);
if (msg != null) {
return msg;
}
try {
DocumentBaseService service = getModualService(pageKey);
if (service != null && service.skipCreatePdf(EnumPageKey.lookup(pageKey))) {
//判断是否跳过生成PDF
return null;
}
} catch (Exception e) {
}
//创建签章文档
TPdfFile pdf = getPdfFile(dataPk, pageKey, true, getPrintParamBean(dataPk, pageKey, null));
if (pdf == null) {
return EnumSign.lookupLabel(signInfo.getVtype()) + "失败";
}
return null;
}
/**
* 文书签字捺印
*
* @param pageKey 文书标识
* @param dataPk 签字的数据的PK
* @param signType 类型(2:签字;3:捺印)
* @param imgData 签字或捺印图片(base64位数据)
* @param position 签字位置
* @param signKey 签章关键字
* @return 签字捺印结果
* @author 陈洪方
*/
@Override
public String addHandSign(Long dataPk, String pageKey, Short signType, String imgData, String position, String signKey, TUser user, TOrg org) {
String url;
try {
MultipartFile imageFile = BASE64DecodedMultipartFile.base64ToMultipart(imgData,
"data:image/png;base64,");
byte[] imageData = imageFile.getBytes();
Verify.verifyNotNull(imageData, "BASE64转文件失败");
url = "/" + minioUploadUtils.upload(imageFile, minioUploadUtils.filePath(ThreadLocalUtil.get(),
org.getOrgCode(), EnumUploadFilePath.WRITEFINGER.getRoute()));
} catch (IOException ignored) {
return "签字或捺印录入失败";
}
TSignInfo signInfo = new TSignInfo();
signInfo.setOrgPk(user.getOrgPk());
signInfo.setDeptPk(user.getDeptId());
signInfo.setUrl(url);
signInfo.setVtype(signType);
signInfo.setSignLevel((short) 0);
signInfo.setCreatePk(user.getPkId());
signInfo.setCreateTime(TimeUtil.getCurrentDateTime());
signInfoService.insertSelective(signInfo);
//添加签名或签章记录
String msg = signHisService.addSignHis(pageKey, dataPk, user.getPkId(), signInfo.getPkId(), position, signKey);
if (msg != null) {
return msg;
}
try {
DocumentBaseService service = getModualService(pageKey);
if (service != null && service.skipCreatePdf(EnumPageKey.lookup(pageKey))) {
//判断是否跳过生成PDF
return null;
}
} catch (Exception ignored) {
}
//创建签章文档
TPdfFile pdf = getPdfFile(dataPk, pageKey, true, getPrintParamBean(dataPk, pageKey, null));
if (pdf == null) {
return EnumSign.lookupLabel(signType) + "失败";
}
return null;
}
/**
* 删除签名签章/签字捺印
*
* @param pageKey 文书标识
* @param dataPk 被签章数据的PK
* @param signType 签章类型(0:签名 1:印章 2:签字 3:捺印)
* @param signKey 签章关键字
* @return 签名签章/签字捺印删除结果
* @author 陈洪方
*/
@Override
public String deleteSignHis(Long dataPk, String pageKey, Short signType, String signKey, TUser user) {
//删除签章
String msg = signHisService.deleteSignHis(pageKey, dataPk, user.getPkId(), signType, signKey);
if (msg != null) {
return msg;
}
try {
DocumentBaseService service = getModualService(pageKey);
if (service != null && service.skipCreatePdf(EnumPageKey.lookup(pageKey))) {
//判断是否跳过生成PDF
return null;
}
} catch (Exception e) {
}
//创建签章文档
TPdfFile pdf = getPdfFile(dataPk, pageKey, true, getPrintParamBean(dataPk, pageKey, null));
if (pdf == null) {
return EnumSign.lookupLabel(signType) + "撤销失败";
}
return null;
}
/**
* 执行自动签章
*
* @param dataPk 记录PK
* @param pageKey 文书标识
* @param signType 签章类型
* @param signLevel 签章等级
* @param printParamBean 签章参数
* @return 成功/失败
* @author 陈洪方
*
*/
@Override
public boolean doAutoSign(Long dataPk, String pageKey, Short signType, Short signLevel, PrintParamBean printParamBean) {
return doAutoSign(dataPk, pageKey, signType, signLevel, EnumAutoSignMode.USER_BOUND_SIGN.getValue(), printParamBean);
}
/**
* 执行自动签章(根据自动签章模式)
*
* @param dataPk 记录PK
* @param pageKey 文书标识
* @param signType 签章类型
* @param signLevel 签章等级
* @param mode 自动签章模式
* @param printParamBean 签章参数
* @return 成功/失败
* @author 陈洪方
*/
@Override
public boolean doAutoSign(Long dataPk, String pageKey, Short signType, Short signLevel, Integer mode, PrintParamBean printParamBean) {
Long orgPk = null;
Long userPk = null;
printParamBean = getPrintParamBean(dataPk, pageKey, printParamBean);
if(EnumAutoSignMode.USER_BOUND_SIGN.getValue().equals(mode)) {
TUser user = printParamBean.getCurrentUser();
if(user == null){
return false;
}
userPk = user.getPkId();
}else{
TOrg org = printParamBean.getCurrentOrg();
if(org == null){
return false;
}
orgPk = org.getPkId();
}
//使用版本文书标识
pageKey = printParamBean.getDocPage().getPageKeySub();
//确认当前是否允许单位签章
boolean isAllow = signInfoService.checkCurrentStep(pageKey, dataPk, signType, signLevel, orgPk, userPk, null, null);
if (!isAllow) {
return false;
}
return signInfoService.doAutoSign(dataPk, pageKey, signType, signLevel, mode, printParamBean);
}
/**
* 执行派驻干警签章
* @param aPk 档案pk
* @param dataPk 数据pk
* @param pageKey 文书key
* @param signType 签章类型 0:签名; 1:印章;3:平板签字;4:平板指纹
* @param printParamBean 签章参数
*/
@Override
public boolean doPoliceAutoSign(Long aPk, Long dataPk, String pageKey, Short signType, PrintParamBean printParamBean) {
return signInfoService.doPoliceAutoSign(aPk, dataPk, pageKey, signType, getPrintParamBean(dataPk, pageKey, printParamBean));
}
/**
* 删除派驻干警签章
* @param dataPk 数据pk
* @param pageKey 文书key
* @param printParamBean 签章参数
*/
@Override
public boolean delPoliceAutoSign(Long dataPk, String pageKey, PrintParamBean printParamBean) {
return signInfoService.delPoliceAutoSign(dataPk, pageKey, getPrintParamBean(dataPk, pageKey, printParamBean));
}
/**
* 获取模块打印签章菜单数据
* @param moduleKey 模块标识
* @param printParamBean 签章参数
*/
@Override
public Map
if(printParamBean == null){
if(RequestUtil.getCurrentUser() == null){
return null;
}
printParamBean = new PrintParamBean();
printParamBean.setCurrentUser(RequestUtil.getCurrentUser());
}
//获取文书版本
if(printParamBean.getVersionKey() == null){
Integer version = this.getCurrentDocVersion(ThreadLocalUtil.get());
if(version == null) {
log.warn("默认版本文书不存在");
return null;
}
printParamBean.setVersionKey(version);
}
//获取菜单数据
return documentMenuService.getModuleMenu(moduleKey, printParamBean.getVersionKey(), ThreadLocalUtil.get());
}
/**
* 根据租户获取当前文书版本
* @param tenant 租户标识
*/
@Override
public Integer getCurrentDocVersion(String tenant){
Integer version = null;
//根据租户获取文书版本
SysTenantConfigure info = sysTenantConfigureService.selectSysTenantConfigureByTenant(tenant);
if(info != null){
version = info.getDocVersion();
}
//若获取不到,则获取默认文书版本
if(version == null) {
version = documentVersionService.getDefaultVersion();
}
return version;
}
/**
* 变更当前租户文书版本
* @param tenant 租户标识
* @param version 文书版本标识
* @param user 用户信息
*/
@Override
public String changeDocVersion(String tenant, Integer version, TUser user){
SysTenantConfigure info = sysTenantConfigureService.selectSysTenantConfigureByTenant(tenant);
if(info == null){
return "未找当前住户";
}
info.setDocVersion(version);
info.setUpdatePk(user.getPkId());
info.setUpdateTime(DateUtils.getNowDate());
sysTenantConfigureService.updateSelectiveById(info);
return null;
}
/**
* 获取统一文书标识
* @param pageKey 文书标识
*/
@Override
public String getPageKey(String pageKey){
TDocumentPage param = new TDocumentPage();
param.setPageKeySub(pageKey);
param.setDelFlag(EnumDelFlag.VISIBLE.getCode());
TDocumentPage documentPage = documentPageService.selectOne(param);
if(documentPage != null){
return documentPage.getPageKey();
}
return pageKey;
}
/**
* 获取版本文书标识
* @param dataPk 文书标识
* @param pageKey 文书标识
*/
@Override
public String getPageKeySub(Long dataPk, String pageKey){
PrintParamBean bean = getPrintParamBean(dataPk, pageKey, null);
if(bean != null && bean.getDocPage() != null){
return bean.getDocPage().getPageKeySub();
}
return pageKey;
}
/**
* 获取PDF
*/
@Override
public TPdfFile getPdfFile(Long dataPk, String pageKey) {
return getPdfFile(dataPk, pageKey, false, getPrintParamBean(dataPk, pageKey, null));
}
/**
* 重新创建PDF
*/
private TPdfFile getPdfFile(Long dataPk, String pageKey, boolean forceCreate, PrintParamBean printParamBean) {
boolean createFlag = forceCreate;
// TPdfFile pdf = null;
PdfFileBean pdfBean = null;
DocumentBaseService service = getModualService(pageKey);
if (service == null) {
log.warn("文书标识无法识别,PDF生成失败({}-{})", dataPk, pageKey);
return null;
}
TUser user = printParamBean.getCurrentUser();
if(user == null){
log.warn("用户获取失败,PDF生成失败({}-{})", dataPk, pageKey);
return null;
}
if(!pageKey.equals(printParamBean.getDocPage().getPageKeySub()) && !pageKey.equals(printParamBean.getDocPage().getPageKey())){
log.warn("文书Key不一致({}-{}-{})",dataPk, pageKey, printParamBean.getDocPage().getPageKeySub());
}
EnumPageKey enumPageKey = EnumPageKey.lookup(printParamBean.getDocPage().getPageKeySub());
Long aPk = service.getArchivePk(dataPk);
if (forceCreate) {
pdfBean = createPdf(dataPk, enumPageKey, printParamBean);
if (pdfBean == null) {
log.warn("PDF生成失败({}-{}-{})", dataPk, enumPageKey.getPageKey(),aPk);
return null;
}
}else {
//获取最后有效的pdf记录
TPdfFile pdf = printArchiveService.getLastArchivePdf(dataPk, aPk, pageKey);
if (pdf != null && minioUploadUtils.isExists(pdf.getPdfPath())) {
pdfBean = new PdfFileBean();
BeanUtils.copyProperties(pdf, pdfBean);
} else { //如果不存在或是文件不存在,则重新创建
pdfBean = createPdf(dataPk, enumPageKey, printParamBean);
if (pdfBean == null) {
log.warn("PDF创建失败({}-{}-{})", dataPk, pageKey, aPk);
return null;
}
createFlag = true;
log.warn("PDF数据不存在,重新创建({}-{}-{})", dataPk, pageKey, aPk);
}
}
//记录不存在,则退出处理
if (pdfBean == null) {
log.warn("PDF文件不存在({}-{}-{})", dataPk, pageKey, aPk);
return null;
}
//如果pdf重新创建,则执行盖章处理
if (createFlag) {
try {
//获取历史签章数据
List
// //生成图片方式文书
// SignHandler defaultHandle = getSignHandler(dataPk, pageKey, true);
// DataToFileResult result = defaultHandle.doKeySign(pdfBean, signList);
// if (!result.isResult()) {
// log.warn("{}({}-{}-{})", result.getMessage(), dataPk, pageKey, aPk);
// return null;
// }
//获取
SignHandler handler = getSignHandler(dataPk, pageKey, false);
if (handler == null) {
log.warn("PDF文件签章失败({}-{}-{})", dataPk, pageKey, aPk);
return null;
}
//执行签章处理
DataToFileResult result = handler.doKeySign(pdfBean, signList);
if (!result.isResult()) {
log.info("{}({}-{}-{})", result.getMessage(), dataPk, pageKey, aPk);
return null;
}
pdfBean.setSrcPdfPath(result.getFilePath());
pdfBean.setaPk(aPk);
pdfBean.setFileName(enumPageKey.getName());
pdfBean.setPdfPath(minioUploadUtils.filePath(printParamBean.getCurrentUser().getOrgPk(), pageKey.toLowerCase()));
pdfBean.setDataPk(dataPk);
pdfBean.setPageKey(printParamBean.getDocPage().getPageKey());
//保存PDF记录
pdfBean = pdfFileService.savePdfFile(pdfBean, EnumFileSourceType.Auto.getValue(), printParamBean.getCurrentUser());
if (pdfBean == null) {
log.warn("PDF文件保存失败({}-{})", dataPk, enumPageKey.getPageKey());
return null;
}
service.createSpecialPdfForMaterial(dataPk, enumPageKey, pdfBean, printParamBean.getCurrentUser());
log.info("PDF文件保存成功({}-{})", dataPk, enumPageKey.getPageKey());
} catch (Exception e) {
log.error("签章处理失败({}-{}-{})", dataPk, pageKey, aPk, e);
return null;
}
}
return pdfBean;
}
private String getPdfFold(Long dataPk, String pageKey) {
SignHandler handler = getSignHandler(dataPk, pageKey, false);
String pdfFold = File.separator + (StringUtils.isEmpty(handler.getPdfFold()) ? "" : (handler.getPdfFold() + File.separator));
return pdfFold;
}
/**
* 创建临时PDF
*
* @param dataPk 记录PK
* @param enumPageKey 文书标识枚举
* @return 成功/失败
*/
private DataToFileResult createTempPdf(Long dataPk, EnumPageKey enumPageKey, PrintParamBean printParamBean) {
return createPdf(dataPk, enumPageKey, true, printParamBean);
}
/**
* 创建PDF
*
* @param dataPk 记录PK
* @param enumPageKey 文书标识枚举
* @return 成功/失败
*/
private PdfFileBean createPdf(Long dataPk, EnumPageKey enumPageKey, PrintParamBean printParamBean) {
DataToFileResult result = createPdf(dataPk, enumPageKey, false, printParamBean);
if(result != null && result.isResult()) {
PdfFileBean pdf = new PdfFileBean();
pdf.setSrcPdfPath(result.getFilePath());
pdf.setPassword(result.getPassword());
return pdf;
}
return null;
}
/**
* 创建PDF
*
* @param dataPk 记录PK
* @param enumPageKey 文书标识枚举
* @return 成功/失败
*/
private DataToFileResult createPdf(Long dataPk, EnumPageKey enumPageKey, boolean isTempFile, PrintParamBean printParamBean) {
//获取文书配置
TDocumentPage docPage = printParamBean.getDocPage();
//根据当前用户所在租户文书版本获取文书标识
enumPageKey = EnumPageKey.lookup(docPage.getPageKeySub());
if(enumPageKey == null){
return null;
}
//获取功能模块service
DocumentBaseService service = getModualService(enumPageKey.getPageKey());
if (service == null) {
return null;
}
//生成PDF文件
DataToFileResult fileResult = null;
if (docPage.getTemplateType().intValue() == 1) {
String filePath = FileUtil.getRealPath() + CDFileUtils.TMP;
fileResult = createPdfByUrl(dataPk, enumPageKey, filePath, isTempFile, printParamBean);
} else {
String template = service.getPdfTemplate(dataPk, enumPageKey);
String templateName = (template == null ? docPage.getPdfTemplate() : template) + ".pdf";
//获取功能模块数据
Map
if (data == null) {
return null;
}
//根据内容模式,选择不同的处理类
DataToFileHandler handle = dataToFileFactory.getNewDefaultTransHandler();
if (docPage.getContentMode().intValue() == 1) {
handle = dataToFileFactory.getNewDefaultTransHandler();
}
//根据创建模式,选择不同的处理方法
if (docPage.getCreateMode().intValue() == 2) {
fileResult = handle.documentToFile((List
} else {
fileResult = handle.dataToFile(data, templateName, !isTempFile, printParamBean.getCurrentUser());
}
}
// //保存PDF文件生成记录
// if (fileResult != null && fileResult.isResult() && !isTempFile) {
// boolean isSuccess = pdfFileService.savePdfFile(service.getArchivePk(dataPk), enumPageKey.getPageKey(), enumPageKey.getName(),
// fileResult.getPath() + fileResult.getFileName(), EnumFileSourceType.Auto.getValue(), dataPk, fileResult.getPassword(),
// (printParamBean != null && printParamBean.getCurrentUser() != null) ? printParamBean.getCurrentUser() : printParamBean.getCurrentUser());
// if (!isSuccess) {
// log.warn("PDF文件保存失败({}-{})", dataPk, enumPageKey.getPageKey());
// return null;
// }
// log.info("PDF文件保存成功({}-{})", dataPk, enumPageKey.getPageKey());
// } else if (fileResult != null && !fileResult.isResult()) {
// log.warn("PDF文件生成失败({}-{}-{})", dataPk, enumPageKey.getPageKey(),fileResult.toString());
// }
return fileResult;
}
/**
* 获取签章实例
*/
private SignHandler getSignHandler(Long dataPk, String pageKey, boolean isDefault) {
EnumOrgDocSignType type = EnumOrgDocSignType.doc_sign_default;
TOrg org = this.getOrgPkOfData(dataPk, pageKey);
if (org != null && !isDefault) {
String docSignType = sysOrgConfigService.getConfig(org.getPkId(), EnumOrgConfig.ELECTRONIC_SIGN_TYPE);
type = EnumOrgDocSignType.getEnumByValue(docSignType);
}
return (SignHandler) SpringHelper.getBean(type.getBeanName());
}
/**
* 获取当前文书记录的档案PK
*/
private Long getArchivePkOfData(Long dataPk, String pageKey) {
DocumentBaseService service = this.getModualService(pageKey);
if (service != null) {
return service.getArchivePk(dataPk);
}
return null;
}
/**
* 获取当前文书记录的档案所属单位信息
*/
private TOrg getOrgPkOfData(Long dataPk, String pageKey) {
DocumentBaseService service = this.getModualService(pageKey);
if (service != null) {
Long aPk = service.getArchivePk(dataPk);
if (aPk != null) {
TCorrectArchiveVo correct = correctArchiveService.selectTCorrectArchiveByPkId(aPk);
if (correct != null) {
return orgService.selectById(correct.getOrgPk());
}
}
}
return null;
}
/**
* 转换为Bean
*/
private PdfFileBean getPdfFileBean(TPdfFile pdf) {
if (pdf == null) {
return null;
}
PdfFileBean bean = new PdfFileBean();
bean.setPkId(pdf.getPkId());
bean.setaPk(pdf.getaPk());
bean.setPageKey(pdf.getPageKey());
bean.setPdfPath(pdf.getPdfPath());
bean.setPassword(pdf.getPassword());
return bean;
}
/**
* 获取历史签章列表
*/
private List
List
List
//将最后的签章或签名放置最后的位置(为了防止签字和捺印是排在最后)
if (dataList != null && dataList.size() > 0) {
int lastSignIndex = -1;
for (int i = dataList.size() - 1; i >= 0; i--) {
TSignInfoBean bean = dataList.get(i);
if ((bean.getVtype().intValue() == EnumSign.Signet.getValue() ||
bean.getVtype().intValue() == EnumSign.Hand.getValue()) &&
StringUtils.isNotEmpty(bean.getSealSn())) {
if (i == dataList.size() - 1) {
return dataList;
} else if (lastSignIndex == -1) {
lastSignIndex = i;
continue;
}
}
signList.add(bean);
}
if (lastSignIndex >= 0) {
signList.add(dataList.get(lastSignIndex));
}
}
return dataList;
}
/**
* 获取HTML页面
*/
private String getHtml(Model model, Long dataPk, String pageKey, boolean isSign, PrintParamBean printParamBean) {
//获取功能模块service
DocumentBaseService service = getModualService(pageKey);
if (service == null) {
return null;
}
return service.getHtmlTemplate(model, dataPk, EnumPageKey.lookup(pageKey), isSign, printParamBean);
}
private DataToFileResult createPdfByUrl(Long dataPk, EnumPageKey enumPageKey, String realPath, boolean isTemp, PrintParamBean printParamBean) {
DataToFileResult fileResult = new DataToFileResult();
String resultFile = null;
String password = UUIDUtils.random();
fileResult.setResult(false);
//获取功能模块service
DocumentBaseService service = getModualService(enumPageKey.getPageKey());
if (service == null) {
return null;
}
TUser user = printParamBean.getCurrentUser();
//如果用户信息不存在,则退出创建
if(user == null){
return null;
}
//设定请求参数
Map
if(param == null) {
param = new HashMap
printParamBean.setMap(param);
}
param.put("dataPk", dataPk);
param.put("pageKey", enumPageKey.getPageKey());
param.put("tenant", ThreadLocalUtil.get());
//生成token
String tokenId = CrossDomainToken.addToken(printParamBean);
String url = Config.getUrlToHtml() + "/com/document/getPdfHtml?tokenId=" + tokenId;
StringBuffer fileName = new StringBuffer();
fileName.append(UUID.randomUUID() + ".pdf");
//TODO 解决bug#5361 【天津正式环境】教育谈话记录打印时显示其他人员的信息,记录pdf生成信息,问题解决后需将日志等级调整为info
log.warn("html生成pdf[登录用户:{},文书pagekey:{},业务datapk:{},pdf文件名称:{}]",user==null?0L:user.getPkId(),enumPageKey.getPageKey(),dataPk,fileName.toString());
//根据URL生成PDF文件
resultFile = PdfUtils.createPdfByUrl(url, realPath, fileName.toString(), new HashMap
if (resultFile != null) {
fileResult.setPath(realPath);
fileResult.setFileName(fileName.toString());
//如果是临时文书,则不添加密码
if(!isTemp) {
//添加密码
resultFile = PdfUtils.addPassWord(realPath + File.separator + fileName.toString(), null, "", password, true);
}
if (resultFile != null) {
//生成pdf记录
fileResult.addSucc(resultFile);
fileResult.setPassword(password);
fileResult.setResult(true);
return fileResult;
}
}
return fileResult;
}
/**
* 获取文书参数
* PrintParamBean 加一个社矫对象信息,用于自动签章 add 2022-06-30
* */
private PrintParamBean getPrintParamBean(Long dataPk, String pageKey, PrintParamBean printParamBean) {
PrintParamBean bean = new PrintParamBean(printParamBean);
DocumentBaseService service = getModualService(pageKey);
if (service == null) {
log.warn("文书定义不存在({}-{})", pageKey, printParamBean.getVersionKey());
return null;
}
Long aPk = service.getArchivePk(dataPk);
TCorrectArchiveVo correct = correctArchiveService.selectTCorrectArchiveByPkId(aPk);
if(printParamBean == null) {
if(RequestUtil.getCurrentUser() != null) {
bean.setHtmlUrl(UrlUtil.getUrl(RequestUtil.getRequest()));
bean.setCurrentOrg(RequestUtil.getCurrentUserOrg());
bean.setCurrentUser(RequestUtil.getCurrentUser());
bean.setCurrentDept(RequestUtil.getCurrentUserDept());
}else{
if (correct != null) {
TOrg org = orgService.selectById(correct.getOrgPk());
if(org != null) {
TDept dept = deptService.selectById(correct.getDeptPk());
if(dept != null) {
TUser user = new TUser();
user.setPkId(0L);
user.setNickName("系统自动");
bean.setHtmlUrl(UrlUtil.getUrl(RequestUtil.getRequest()));
bean.setCurrentOrg(org);
bean.setCurrentUser(user);
bean.setCurrentDept(dept);
}
}
}
}
}
//如果文书版本为空,则重新获取
if(bean.getVersionKey() == null) {
Integer version = this.getCurrentDocVersion(ThreadLocalUtil.get());
if (version == null) {
log.warn("默认版本文书不存在({}-{})", dataPk, pageKey);
return null;
}
bean.setVersionKey(version);
}
//获取文书配置
TDocumentPage docPage = documentPageService.getDocumentPageByVersion(pageKey, bean.getVersionKey());
if(docPage == null){
log.warn("文书配置不存在({}-{})", pageKey, bean.getVersionKey());
return null;
}
bean.setDocPage(docPage);
if(correct != null){
bean.setArchive(correct);
}
return bean;
}
/**
* 进行二次签字、捺印的权限校验
* 只校验用户权限相关的签章控制数据是否存在:
* 存在 返回true,保持原流程不变;
* 不存在 返回false, 则结束流程
* @param pageKey
* @param signType
* @param userPk
* @return
*/
@Override
public boolean checkControlInfo(String pageKey, Short signType, Long userPk) {
List
TSignControl contorlParam = new TSignControl();
contorlParam.setPageKey(pageKey);
contorlParam.setSignType(signType);
contorlParam.setDr(EnumDr.Valid.getValue());
List
if(controlList != null && controlList.size() > 0){
TSignControl contorl = null;
for(TSignControl item : controlList){
if(item.getSignLevel() == 0){
contorl = item;
break;
}else{
for(TSignInfo sign : signList){
if(item.getSignLevel().intValue() == sign.getSignLevel()){
contorl = item;
break;
}
}
}
}
//如果无法获取用户权限相关的签章控制数据则禁止签章
if (contorl == null || contorl.getSignMax() == null || contorl.getSignMax() <= 0) {
return false;
}
}else{
return false;
}
return true;
}
/**
* 获取历史签章数据
*
* @param dataPk
* @param pageKey
* @return
*/
@Override
public List
DocumentBaseService service = getModualService(pageKey);
if (service == null) {
return null;
}
List
if(signList != null && signList.size() > 0) {
for (TSignInfoBean sign : signList) {
String base64 = null;
try{
base64 = ImgBase64Utils.getBase64(minioUploadUtils.readFileToByteArray(sign.getUrl()));
}catch(Exception e){}
if(StringUtils.isNotEmpty(base64)) {
sign.setSignUrl("data:image/png;base64," + base64);
}
}
}
//获取历史签章数据
return signList;
}
/**
* 获取水印内容
*
* @param enumPrintType 打印方式
* @return
*/
@Override
public Map
Map
TUser user = RequestUtil.getCurrentUser();
if(user == null) {
return null;
}
boolean mainEnable = sysOrgConfigService.getConfig(user.getOrgPk(), EnumOrgConfig.PRINT_CONTROL_WATER_MARKER_MAIN_ENABLE);
if(!mainEnable){
return null;
}
boolean enable = sysOrgConfigService.getConfig(user.getOrgPk(), enumPrintType.getEnumOrgConfig());
if(!enable){
return null;
}
Integer fontSize = sysOrgConfigService.getConfig(user.getOrgPk(), EnumOrgConfig.PRINT_CONTROL_WATER_MARKER_FONT_SIZE);
//确认当前用户是否
List
String phone = user.getPhonenumber();
if (StringUtils.isEmpty(phone)) {
phone = user.getPhone();
}
// if (StringUtils.isNotEmpty(phone)) {
// waterList.add("打印人员:" + user.getNickName() + "(" + phone + ")");
// }else{
// waterList.add("打印人员:" + user.getNickName());
// }
// waterList.add("打印时间:" + DateUtils.getTime());
String waterStr = user.getNickName();
if (StringUtils.isNotEmpty(phone)) {
waterStr = waterStr + "(" + phone + ")";
}
waterStr = waterStr + " " + DateUtils.getTime();
waterList.add(waterStr);
waterMarker.put("waterList", waterList);
waterMarker.put("fontSize", fontSize);
String url = RequestUtil.getRequest().getRequestURL().toString();
if(StringUtils.isNotEmpty(url)){
waterMarker.put("url", url);
}
return waterMarker;
}
/**
* 生成打印日志
*
* @param enumPrintType 打印类型
* @param pageKey 文书表示
* @param fileList 打印文书列表
* @param user 用户信息
* @return
*/
@Override
public void recordPrintOperate(EnumPrintType enumPrintType, String pageKey, List
//如果操作用户为空,则忽略
if(user == null){
return;
}
//如果打印文件列表为空,则忽略
if(fileList == null || fileList.size() == 0){
return;
}
//创建日志记录
TDocumentPrintLog printLog = new TDocumentPrintLog();
printLog.setOperatorPk(user.getPkId());
printLog.setOperatorName(user.getNickName());
printLog.setOperatorMobile(StringUtils.isEmpty(user.getPhone()) ? user.getPhonenumber() : user.getPhone());
if(RequestUtil.getRequest() != null && RequestUtil.getRequest().getRequestURL() != null) {
printLog.setPrintUrl(RequestUtil.getRequest().getRequestURL().toString());
}
printLog.setFunctionType(enumPrintType.getValue());
printLog.setFunctionModule(enumPrintType.getName());
//如果文书标识不为空,则获取文书所属模块名称
if(StringUtils.isNotEmpty(pageKey)) {
String remark = "未知模块";
TSignPageInfo paramInfo = new TSignPageInfo();
paramInfo.setPageKey(pageKey);
paramInfo.setDr(EnumDr.Valid.getValue().intValue());
List
if (infoList != null && infoList.size() > 0) {
EnumModuleInfo enumModuleInfo = EnumModuleInfo.lookMap(infoList.get(0).getModuleVal());
remark = enumModuleInfo.getName() + "->" + infoList.get(0).getPageName() ;
}
printLog.setRemark(remark);
}
printLog.setPrintList(fileList.stream().collect(Collectors.joining(",")));
printLog.setOperatorType(user.getUserType());
printLog.setPrintTime(DateUtils.getNowDate());
printLog.setVstatus(0);
printLog.setDelFlag(EnumDelFlag.VISIBLE.getCode());
printLog.setCreateTime(DateUtils.getNowDate());
printLog.setCreatePk(user.getPkId());
documentPrintLogService.insert(printLog);
}
@Override
public void updateSignPageDataByModule(Long dataPk, Integer moduleVal, TUser user) {
DocumentBaseService service = null;
try {
List
if(null != pageInfoList && pageInfoList.size() != 0){
for(TSignPageInfo item : pageInfoList){
service = (DocumentBaseService) SpringHelper.getBean(EnumPageKey.lookup(item.getPageKey()).getClazz());
break;
}
}
if(null != service){
service.updateSignPageData(dataPk, moduleVal, pageInfoList, user);
}
} catch (Exception e) {
log.error("更新模块[{}]对应的签章进度统计数据异常", moduleVal, e);
}
}
/**
* 过滤合议评议文书的代码有待优化
* 注意(后期优化):如果后续类似这样的文书超过三个,可以在把 获取具体的业务数据id 放在各个模块的DocumentXXXXService中获取; 需要一起优化的方法 isFilterPrintArchiveItemData
* 适用于单个模块一个文书会有多个不同类型的业务数据
* @param list
* @param pageKey
* @param id 是单个文书目录在sys_material表里的id
* @param aPk
* @return
*/
@Override
public List
List
try{
if(getCurrentDocVersion(ThreadLocalUtil.get()).equals(EnumVersionKey.TianJin.getValue())){
if(EnumPageKey.HYYJB.getPageKey().equals(pageKey)){
if(null == id){
log.warn("[{}][{}][缺少必要参数]",EnumVersionKey.TianJin.getLabel(), EnumPageKey.HYYJB.getPageKey());
return resList;
}
//根据id获取当前文书目录配置的业务数据类型
Material material = materialService.loadEqual(Material.class,"selectById", id);
if(null != material && StringUtils.isNotEmpty(material.getDataType())){
//根据data_type 和 aPk 获取具体的 业务数据id
Map
params.put("aPk", aPk);
params.put("hylx", material.getDataType());
List
if(CollectionUtils.isNotEmpty(dataList)){
//获取最终的pdf
Map
paramsPdf.put("aPk", aPk);
paramsPdf.put("pageKey", pageKey);
for(CollegiateBench item : dataList){
paramsPdf.put("dataPk", item.getPkId());
List
if(CollectionUtils.isNotEmpty(pdfList)){
resList.addAll(pdfList);
}
}
//附件上传的合议评议文书
paramsPdf.put("dataPk", 0);
paramsPdf.put("dataType", material.getDataType());
List
if(CollectionUtils.isNotEmpty(pdfAdjList)){
resList.addAll(pdfAdjList);
}
}
}
}else{
resList = list;
}
}else{
resList = list;
}
}catch (Exception e){
log.error("电子卷宗特殊文书预览或打印处理异常", e);
}
return resList;
}
@Override
public boolean isTianJinVersion() {
return EnumVersionKey.TianJin.getValue().equals(getCurrentDocVersion(ThreadLocalUtil.get()));
}
/**
* 过滤合议评议文书的代码有待优化
* 注意(后期优化):如果后续类似这样的文书超过三个,可以在把 获取具体的业务数据id 放在各个模块的DocumentXXXXService中获取; 需要一起优化的方法 isFilterData
* 适用于单个模块一个文书会有多个不同类型的业务数据
* 电子卷宗目录获取
* @param resutList
* @param aPk
*/
@Override
public void isFilterPrintArchiveItemData(List
try{
if(getCurrentDocVersion(ThreadLocalUtil.get()).equals(EnumVersionKey.TianJin.getValue())){
for(PrintArchiveItemBean item : resutList){
if(EnumPageKey.HYYJB.getPageKey().equals(item.getPageKey())){
Material material = materialService.loadEqual(Material.class,"selectById", item.getId());
if(null != material && StringUtils.isNotEmpty(material.getDataType())){
//根据data_type 和 aPk 获取具体的 业务数据id
Map
params.put("aPk", aPk);
params.put("hylx", material.getDataType());
List
//t_pdf_file里查询通过附件上传的文书有几个
params.put("dataType", material.getDataType());
params.put("dataPk", 0);
List
int count = 0;
if(null != dataList && dataList.size() > 0){
count += dataList.size();
}
if(null != pdfList && pdfList.size() > 0){
count += pdfList.size();
}
item.setPageCount(count);
}
}
}
}
}catch (Exception e){
log.error("电子卷宗特殊文书数据处理异常", e);
}
}
/**
* 过滤合议评议文书的代码有待优化
* 适用于单个模块一个文书会有多个不同类型的业务数据
* list 删除所有特殊pagekey的文书;重新获取data_type 和 aPk 获取具体的 业务数据id对应的pdf,把新的pdf在放到list中
* @param list
* @param aPk
* @return
*/
@Override
public List
List
try{
Integer versionKey = getCurrentDocVersion(ThreadLocalUtil.get());
if(versionKey.equals(EnumVersionKey.TianJin.getValue())){
if(CollectionUtils.isNotEmpty(list)){
for(PdfFileVo vo : list){
TPdfFile pdfFile = new TPdfFile();
BeanUtils.copyProperties(vo, pdfFile);
if(StringUtils.isNotBlank(StringUtils.trimToEmpty(vo.getPageKey())) && EnumPageKey.HYYJB.getPageKey().equals(vo.getPageKey())){
//过滤重复的文书
Material material = materialService.loadEqual(Material.class,"selectById", vo.getmPk());
if(null != material && StringUtils.isNotEmpty(material.getDataType())){
// 根据data_type 和 aPk 获取具体的 业务数据id
Map
params.put("aPk", aPk);
params.put("hylx", material.getDataType());
params.put("dataPk", vo.getDataPk());
List
if(null != dataList && dataList.size() != 0){
resList.add(pdfFile);
}
}
}else{
resList.add(pdfFile);
}
}
}
}else{
for(PdfFileVo vo : list) {
TPdfFile pdfFile = new TPdfFile();
BeanUtils.copyProperties(vo, pdfFile);
resList.add(pdfFile);
}
}
if (CollectionUtils.isNotEmpty(resList)) {
for (TPdfFile p : resList) {
if (StringUtils.isNotBlank(p.getPdfPath()) && CDFileUtils.isImageFile(p.getPdfPath())) {
//如果是附件图片,则取获取转pdf后的文件
String pdfUrl = adjunctService.minioImageAdjToPdf(p.getPdfPath());
if (StringUtils.isNotBlank(pdfUrl)) {
p.setPdfPath(pdfUrl);
}
}
}
}
}catch (Exception e){
log.error("电子卷宗打印-特殊文书处理异常", e);
}
return resList;
}
@Override
public byte[] genPdf(Long pkId, String module, TUser user,String isHorizontal) throws IOException {
PrintParamBean printParamBean=new PrintParamBean();
printParamBean.setMap(new HashMap
printParamBean.setCurrentUser(user);
String tenant=ThreadLocalUtil.get();
printParamBean.getMap().put("tenant",tenant);
printParamBean.getMap().put("dataPk",pkId);
printParamBean.getMap().put("module",module);
String tokenId = CrossDomainToken.addToken(printParamBean);
String url = Config.getUrlToHtml() + "/com/document/getPdfHtmlContent?tokenId="+tokenId;
Map
if(StringUtils.isNotEmpty(isHorizontal)&&isHorizontal.equals(String.valueOf(EnumYesNo.YES.getValue()))){
options.put("isHorizontal", "Y");
}
Map
params.put("url", url);
params.put("options",options);
InputStream in = null;
try {
OkHttpClientUtil okHttp = SpringHelper.getBean(OkHttpClientUtil.class);
in = okHttp.sendPostJsonRequestIn(Config.getHtmlToPdfByUrl(), params);
} catch (Exception e) {
log.error("PDF转换服务调用失败:html转PDF服务地址[{}],url转html服务地址[{}]", Config.getHtmlToPdfByUrl(), url, e);
}
byte[] pdfData = IOUtils.toByteArray(in);
//ps:这里pdfData字节数组有个坑,如果需要将pdf保存到本地需要将字节数组重新转换成字节数组 ,否则生成的pdf文件内容为空
if (pdfData == null || pdfData.length == 0) {
log.info("PDF转换服务获取数据为空[{}]", url);
}
return pdfData;
}
@Override
public Map
Map
if(module.equals(EnumPdfModuleInfo.DISEASECERTIFICATION.getModule())) {
result=diseaseCertificationService.getDocData(dataPk);
}else if(module.equals(EnumPdfModuleInfo.DISEASEREVIEW.getModule())){
result=correctDiseaseReviewService.getDocData(dataPk);
}
return result;
}
/**
* 业务数据删除,批量删除业务关联的自动生成的文书数据
*
* @param dataPk
* @param aPk
* @param enumPageKeys
*/
@Override
public void batchDeleteAutoPdfFileByDataPk(Long dataPk, Long aPk, EnumPageKey... enumPageKeys) {
pdfFileService.batchDeleteAutoPdfFile(dataPk, aPk, enumPageKeys);
}
}