|
|
|
@ -5,17 +5,20 @@ import cn.org.bjca.seal.esspdf.client.message.ChannelMessage;
|
|
|
|
|
import cn.org.bjca.seal.esspdf.client.message.RectangleBean;
|
|
|
|
|
import cn.org.bjca.seal.esspdf.client.tools.AnySignClientTool;
|
|
|
|
|
import cn.org.bjca.seal.esspdf.client.utils.ClientUtil;
|
|
|
|
|
import com.emr.dao.Archive_Detail_ca_reqParamMapper;
|
|
|
|
|
import com.emr.dto.Archive_DetailPdfPathDto;
|
|
|
|
|
import com.emr.entity.Archive_Detail_caSign;
|
|
|
|
|
import com.emr.entity.Archive_Detail_ca_reqParam;
|
|
|
|
|
import com.emr.service.Archive_DetailService;
|
|
|
|
|
import com.lowagie.text.Rectangle;
|
|
|
|
|
import com.lowagie.text.pdf.PdfReader;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.*;
|
|
|
|
@ -40,14 +43,6 @@ public class CaSignServiceImpl {
|
|
|
|
|
private int caServerPort;
|
|
|
|
|
@Value("${signNo}")
|
|
|
|
|
private String signNo;
|
|
|
|
|
@Value("${signLeft}")
|
|
|
|
|
private String signLeft;
|
|
|
|
|
@Value("${signTop}")
|
|
|
|
|
private String signTop;
|
|
|
|
|
@Value("${signRight}")
|
|
|
|
|
private String signRight;
|
|
|
|
|
@Value("${signBottom}")
|
|
|
|
|
private String signBottom;
|
|
|
|
|
@Value("${isCaOpen}")
|
|
|
|
|
private int isCaOpen;
|
|
|
|
|
@Value("${caCopyPath}")
|
|
|
|
@ -56,6 +51,8 @@ public class CaSignServiceImpl {
|
|
|
|
|
private Archive_DetailService archiveDetailService;
|
|
|
|
|
@Resource
|
|
|
|
|
private Archive_Detai_CaSignServiceImpl archiveDetaiCaSignService;
|
|
|
|
|
@Resource
|
|
|
|
|
private Archive_Detail_ca_reqParamMapper archiveDetailCaReqParamMapper;
|
|
|
|
|
/**
|
|
|
|
|
* @Description: caSignByMasterId方法是根据masterId查询所有文件进行ca签章
|
|
|
|
|
* @param: [masterId]
|
|
|
|
@ -72,6 +69,8 @@ public class CaSignServiceImpl {
|
|
|
|
|
try {
|
|
|
|
|
List<Archive_DetailPdfPathDto> pdfPathList = archiveDetailService.getPdfPathByMasterId(masterId);
|
|
|
|
|
if (!CollectionUtils.isEmpty(pdfPathList)) {
|
|
|
|
|
//查询签章位置比例
|
|
|
|
|
Archive_Detail_ca_reqParam caReqParam = archiveDetailCaReqParamMapper.selectAll();
|
|
|
|
|
//定义此次需要签章的文件id集合
|
|
|
|
|
List<String> idList = new ArrayList<>();
|
|
|
|
|
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
@ -86,7 +85,7 @@ public class CaSignServiceImpl {
|
|
|
|
|
//备份源文件
|
|
|
|
|
caCopyFile(pdfPath, todayDate, masterId);
|
|
|
|
|
//进行签章
|
|
|
|
|
boolean isSign = caSign(pdfPath);
|
|
|
|
|
boolean isSign = caSign(pdfPath,caReqParam);
|
|
|
|
|
if (isSign) {
|
|
|
|
|
idList.add(dto.getId());
|
|
|
|
|
}
|
|
|
|
@ -159,7 +158,8 @@ public class CaSignServiceImpl {
|
|
|
|
|
* @author 曾文和
|
|
|
|
|
* @createTime 2023/7/25 10:30
|
|
|
|
|
*/
|
|
|
|
|
private boolean caSign(String fileSrc) throws Exception {
|
|
|
|
|
private boolean caSign(String fileSrc,Archive_Detail_ca_reqParam caReqParam) throws Exception {
|
|
|
|
|
System.out.println("fileSrc:"+fileSrc);
|
|
|
|
|
//定义是否成功
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
PdfReader pdfReader = null;
|
|
|
|
@ -169,38 +169,51 @@ public class CaSignServiceImpl {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (pdfReader != null) {
|
|
|
|
|
anySignClientTool = new AnySignClientTool(caServerIp, caServerPort);
|
|
|
|
|
File file = new File(fileSrc);
|
|
|
|
|
byte[] pdfBty = ClientUtil.readFileToByteArray(file);
|
|
|
|
|
//pdf验章
|
|
|
|
|
ChannelMessage messageExist = anySignClientTool.pdfVerify(pdfBty);
|
|
|
|
|
if(!StringUtils.isEmpty(messageExist.getStatusInfo()) && "pdf文档未签章".equals(messageExist.getStatusInfo())) {
|
|
|
|
|
RectangleBean bean = new RectangleBean();
|
|
|
|
|
bean.setLeft(Float.valueOf(signLeft));
|
|
|
|
|
bean.setTop(Float.valueOf(signTop));
|
|
|
|
|
bean.setRight(Float.valueOf(signRight));
|
|
|
|
|
bean.setBottom(Float.valueOf(signBottom));
|
|
|
|
|
int numberOfPages = pdfReader.getNumberOfPages();
|
|
|
|
|
for (int i = 0; i < numberOfPages; i++) {
|
|
|
|
|
if (i != 0) {
|
|
|
|
|
pdfBty = ClientUtil.readFileToByteArray(file);
|
|
|
|
|
}
|
|
|
|
|
bean.setPageNo(i + 1);
|
|
|
|
|
ChannelMessage message = null;
|
|
|
|
|
message = anySignClientTool.pdfSignByParam(pdfBty, signNo, bean);
|
|
|
|
|
if ("200".equals(message.getStatusCode())) {//成功
|
|
|
|
|
ClientUtil.writeByteArrayToFile(new File(fileSrc), message.getBody());
|
|
|
|
|
} else {
|
|
|
|
|
String statusCode = message.getStatusCode();
|
|
|
|
|
String statusInfo = message.getStatusInfo();
|
|
|
|
|
System.out.println("statusCode=" + statusCode + ";statusInfo=" + statusInfo);
|
|
|
|
|
try {
|
|
|
|
|
anySignClientTool = new AnySignClientTool(caServerIp, caServerPort);
|
|
|
|
|
File file = new File(fileSrc);
|
|
|
|
|
byte[] pdfBty = ClientUtil.readFileToByteArray(file);
|
|
|
|
|
//pdf验章
|
|
|
|
|
ChannelMessage messageExist = anySignClientTool.pdfVerify(pdfBty);
|
|
|
|
|
if(!StringUtils.isEmpty(messageExist.getStatusInfo()) && "pdf文档未签章".equals(messageExist.getStatusInfo())) {
|
|
|
|
|
RectangleBean bean = new RectangleBean();
|
|
|
|
|
int numberOfPages = pdfReader.getNumberOfPages();
|
|
|
|
|
for (int i = 0; i < numberOfPages; i++) {
|
|
|
|
|
if (i != 0) {
|
|
|
|
|
pdfBty = ClientUtil.readFileToByteArray(file);
|
|
|
|
|
}
|
|
|
|
|
bean.setPageNo(i + 1);
|
|
|
|
|
ChannelMessage message = null;
|
|
|
|
|
//获取pdf的高宽
|
|
|
|
|
Rectangle pageSize = pdfReader.getPageSizeWithRotation(i+1);
|
|
|
|
|
// 获取页面的宽度和高度
|
|
|
|
|
float width = pageSize.getWidth();
|
|
|
|
|
float height = pageSize.getHeight();
|
|
|
|
|
System.out.println("pdf尺寸:width:"+width+",height:"+height);
|
|
|
|
|
bean.setLeft(Float.valueOf(width - caReqParam.getSignLeft()));
|
|
|
|
|
bean.setTop(Float.valueOf(caReqParam.getSignTop()));
|
|
|
|
|
bean.setRight(Float.valueOf(width));
|
|
|
|
|
bean.setBottom(Float.valueOf(caReqParam.getSignBottom()));
|
|
|
|
|
System.out.println("左:"+bean.getLeft()+",上:"+bean.getTop()+",右:"+bean.getRight()+",下:"+bean.getBottom());
|
|
|
|
|
message = anySignClientTool.pdfSignByParam(pdfBty, signNo, bean);
|
|
|
|
|
if ("200".equals(message.getStatusCode())) {//成功
|
|
|
|
|
ClientUtil.writeByteArrayToFile(new File(fileSrc), message.getBody());
|
|
|
|
|
System.out.println("签章成功");
|
|
|
|
|
} else {
|
|
|
|
|
String statusCode = message.getStatusCode();
|
|
|
|
|
String statusInfo = message.getStatusInfo();
|
|
|
|
|
log.error("statusCode=" + statusCode + ";statusInfo=" + statusInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
flag = true;
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
flag = true;
|
|
|
|
|
} else {
|
|
|
|
|
log.error("进行签章pdf:"+fileSrc+"不存在或损坏");
|
|
|
|
|
}
|
|
|
|
|
System.out.println("完成");
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|