parent
70744b1e6a
commit
d1eb58913d
|
@ -3,16 +3,25 @@ package shkd.sys.sys.mservice;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import kd.bos.cache.CacheFactory;
|
||||||
|
import kd.bos.cache.TempFileCache;
|
||||||
import kd.bos.context.RequestContext;
|
import kd.bos.context.RequestContext;
|
||||||
import kd.bos.dataentity.entity.DynamicObject;
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
import kd.bos.dataentity.entity.LocaleString;
|
import kd.bos.dataentity.entity.LocaleString;
|
||||||
|
import kd.bos.dataentity.resource.ResManager;
|
||||||
|
import kd.bos.dataentity.utils.StringUtils;
|
||||||
import kd.bos.exception.KDBizException;
|
import kd.bos.exception.KDBizException;
|
||||||
import kd.bos.logging.Log;
|
import kd.bos.logging.Log;
|
||||||
import kd.bos.logging.LogFactory;
|
import kd.bos.logging.LogFactory;
|
||||||
|
import kd.bos.metadata.dao.MetadataDao;
|
||||||
import kd.bos.orm.query.QCP;
|
import kd.bos.orm.query.QCP;
|
||||||
import kd.bos.orm.query.QFilter;
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.print.core.service.PrtAttach;
|
||||||
|
import kd.bos.print.matchtpl.MatcherTpl;
|
||||||
|
import kd.bos.print.matchtpl.ViewType;
|
||||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.PrintServiceHelper;
|
||||||
import kd.bos.servicehelper.QueryServiceHelper;
|
import kd.bos.servicehelper.QueryServiceHelper;
|
||||||
import kd.bos.servicehelper.print.NotePrintService;
|
import kd.bos.servicehelper.print.NotePrintService;
|
||||||
import kd.tmc.bei.business.ocr.impl.ScanServiceImpl;
|
import kd.tmc.bei.business.ocr.impl.ScanServiceImpl;
|
||||||
|
@ -20,6 +29,7 @@ import kd.tmc.bei.business.ocr.invoke.ScanSystemFactory;
|
||||||
import kd.tmc.bei.common.helper.BeiHelper;
|
import kd.tmc.bei.common.helper.BeiHelper;
|
||||||
import kd.tmc.bei.common.helper.ReceiptPrintHelper;
|
import kd.tmc.bei.common.helper.ReceiptPrintHelper;
|
||||||
import kd.bos.util.ExceptionUtils;
|
import kd.bos.util.ExceptionUtils;
|
||||||
|
import kd.tmc.bei.common.resource.BeiBizResource;
|
||||||
import kd.tmc.fbp.common.ofd.OfdConvertUtil;
|
import kd.tmc.fbp.common.ofd.OfdConvertUtil;
|
||||||
import kd.tmc.fbp.common.util.EmptyUtil;
|
import kd.tmc.fbp.common.util.EmptyUtil;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
|
@ -31,10 +41,7 @@ import org.springframework.web.client.RestTemplate;
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -43,6 +50,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description
|
* @Description
|
||||||
|
@ -317,36 +325,11 @@ public class ApiService {
|
||||||
logger.info("电子回单查询 → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody);
|
logger.info("电子回单查询 → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody);
|
||||||
result = "推送 → 电子回单查询 → 成功";
|
result = "推送 → 电子回单查询 → 成功";
|
||||||
|
|
||||||
List<byte[]> resList = new ArrayList<>(10);
|
List<String> errMsgList = new ArrayList<>();
|
||||||
String uploadFileName = ReceiptPrintHelper.getRealUploadUrl(dynamic);
|
// String pdfUrl = getPdfUrl(view.getPageId(), receipts, errMsgList);
|
||||||
String fileServerUrl = dynamic.getString("fileserverurl");
|
// if (!errMsgList.isEmpty()) {
|
||||||
try {
|
// view.showErrorNotification(String.join(",", errMsgList));
|
||||||
if (!EmptyUtil.isEmpty(fileServerUrl)) {
|
// }
|
||||||
ScanSystemFactory.getScanService();
|
|
||||||
Long userId = RequestContext.get().getCurrUserId();
|
|
||||||
DynamicObjectCollection userObj = QueryServiceHelper.query("bos_user", "id,phone", (new QFilter("id", "=", userId)).toArray());
|
|
||||||
DynamicObjectCollection configObj = QueryServiceHelper.query("bas_imageconfig", "imageurl,clientid,clientsecret", (new QFilter("enable", "=", "A")).toArray());
|
|
||||||
InputStream image = ScanServiceImpl.getImage(configObj.get(0).getString("clientid"), configObj.get(0).getString("clientsecret"), configObj.get(0).getString("imageurl"), userObj.get(0).getString("phone"), fileServerUrl);
|
|
||||||
ReceiptPrintHelper.imageConvertPdf("", resList, image);
|
|
||||||
} else if (!uploadFileName.endsWith("pdf") && !uploadFileName.endsWith("PDF")) {
|
|
||||||
if (!uploadFileName.endsWith("ofd") && !uploadFileName.endsWith("OFD")) {
|
|
||||||
logger.info("fileReceipt url:" + uploadFileName);
|
|
||||||
ReceiptPrintHelper.imageConvertPdf(uploadFileName, resList, null);
|
|
||||||
} else {
|
|
||||||
logger.info("ofdReceipt url:" + uploadFileName);
|
|
||||||
byte[] bytes = OfdConvertUtil.convertToPdfNew(BeiHelper.getPdfPutStream(uploadFileName, "old"));
|
|
||||||
resList.add(bytes);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.info("pdfReceipt url:" + uploadFileName);
|
|
||||||
BeiHelper.getPdfPutStream(uploadFileName, resList);
|
|
||||||
}
|
|
||||||
} catch (Exception var28) {
|
|
||||||
logger.info(ExceptionUtils.getExceptionStackTraceMessage(var28));
|
|
||||||
}
|
|
||||||
|
|
||||||
String pdfUrl = finlyOpenForm(resList);
|
|
||||||
logger.info("文件url:{}", pdfUrl);
|
|
||||||
} else {
|
} else {
|
||||||
logger.info("电子回单查询 → BIP推送接口 → 失败\n失败单据编号:{}\n失败请求体:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody);
|
logger.info("电子回单查询 → BIP推送接口 → 失败\n失败单据编号:{}\n失败请求体:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody);
|
||||||
result = "推送 → 电子回单查询 → 失败";
|
result = "推送 → 电子回单查询 → 失败";
|
||||||
|
@ -715,6 +698,123 @@ public class ApiService {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getPdfUrl(String pageId, DynamicObjectCollection receipts, List<String> errMsgList) {
|
||||||
|
List<String> listPdf = new ArrayList<>(10);
|
||||||
|
List<byte[]> resList = new ArrayList<>(10);
|
||||||
|
String getEreceipturlError = (new BeiBizResource()).getGetEreceipturlError();
|
||||||
|
String templateError = (new BeiBizResource()).getTemplateError();
|
||||||
|
String getTemplateError = (new BeiBizResource()).getGetTemplateError();
|
||||||
|
logger.info("ViewReceiptService.getPdfUrl receipts.size=" + receipts.size());
|
||||||
|
if (receipts.size() > 1000) {
|
||||||
|
errMsgList.add(ResManager.loadKDString("请求打印电子回单数量超过1000条,请分批处理。", "ViewReceiptService_6", "tmc-bei-business", new Object[0]));
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
Set<Long> pkIds = (Set<Long>)receipts.stream().map((receiptx) -> {
|
||||||
|
return receiptx.getLong("id");
|
||||||
|
}).collect(Collectors.toSet());
|
||||||
|
Map<Object, Set<MatcherTpl>> receiptTemplate = ReceiptPrintHelper.getMatchReceiptTemplate("bei", "bei_elecreceipt", pkIds, ViewType.LIST, pageId);
|
||||||
|
receiptTemplate.remove("");
|
||||||
|
long timeMillis = System.currentTimeMillis();
|
||||||
|
|
||||||
|
for (DynamicObject receipt : receipts) {
|
||||||
|
Long receiptID = receipt.getLong("id");
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.info("ViewReceiptService templateForm.size=" + receiptTemplate.size());
|
||||||
|
if (receiptTemplate.isEmpty()) {
|
||||||
|
errMsgList.add(templateError);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
for (Object o : (Set) receiptTemplate.get(receiptID)) {
|
||||||
|
MatcherTpl template = (MatcherTpl) o;
|
||||||
|
String templateId = template.getTplId();
|
||||||
|
logger.info("ViewReceiptService templateForm.keySet=" + templateId);
|
||||||
|
String templateFormId = "";
|
||||||
|
if (EmptyUtil.isNoEmpty(templateId)) {
|
||||||
|
templateFormId = MetadataDao.getNumberById(templateId);
|
||||||
|
logger.info("ViewReceiptService templateFormId=" + templateFormId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = PrintServiceHelper.createPdfUrl(pageId, "bei_elecreceipt", templateFormId, new Long[]{receiptID});
|
||||||
|
logger.info("ViewReceiptService url4old=" + url);
|
||||||
|
if (StringUtils.isNotEmpty(url)) {
|
||||||
|
if (receipt.getBoolean("fileflag")) {
|
||||||
|
logger.info("设置username-------" + receipt.getString("username"));
|
||||||
|
System.setProperty("ereceipt.authuser", receipt.getString("username"));
|
||||||
|
String uploadFileName = ReceiptPrintHelper.getRealUploadUrl(receipt);
|
||||||
|
if (StringUtils.isBlank(uploadFileName)) {
|
||||||
|
errMsgList.add(getEreceipturlError);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileServerUrl = receipt.getString("fileserverurl");
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!EmptyUtil.isEmpty(fileServerUrl)) {
|
||||||
|
ScanSystemFactory.getScanService();
|
||||||
|
Long userId = RequestContext.get().getCurrUserId();
|
||||||
|
DynamicObjectCollection userObj = QueryServiceHelper.query("bos_user", "id,phone", (new QFilter("id", "=", userId)).toArray());
|
||||||
|
DynamicObjectCollection configObj = QueryServiceHelper.query("bas_imageconfig", "imageurl,clientid,clientsecret", (new QFilter("enable", "=", "A")).toArray());
|
||||||
|
InputStream image = ScanServiceImpl.getImage(((DynamicObject) configObj.get(0)).getString("clientid"), ((DynamicObject) configObj.get(0)).getString("clientsecret"), ((DynamicObject) configObj.get(0)).getString("imageurl"), ((DynamicObject) userObj.get(0)).getString("phone"), fileServerUrl);
|
||||||
|
ReceiptPrintHelper.imageConvertPdf("", resList, image);
|
||||||
|
} else if (!uploadFileName.endsWith("pdf") && !uploadFileName.endsWith("PDF")) {
|
||||||
|
if (!uploadFileName.endsWith("ofd") && !uploadFileName.endsWith("OFD")) {
|
||||||
|
logger.info("fileReceipt url:" + uploadFileName);
|
||||||
|
ReceiptPrintHelper.imageConvertPdf(uploadFileName, resList, (InputStream) null);
|
||||||
|
} else {
|
||||||
|
logger.info("ofdReceipt url:" + uploadFileName);
|
||||||
|
byte[] bytes = OfdConvertUtil.convertToPdfNew(BeiHelper.getPdfPutStream(uploadFileName, "old"));
|
||||||
|
resList.add(bytes);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.info("pdfReceipt url:" + uploadFileName);
|
||||||
|
BeiHelper.getPdfPutStream(uploadFileName, resList);
|
||||||
|
}
|
||||||
|
} catch (Exception var28) {
|
||||||
|
logger.info(ExceptionUtils.getExceptionStackTraceMessage(var28));
|
||||||
|
errMsgList.add(getEreceipturlError);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
listPdf.add(url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
PrtAttach attach = ReceiptPrintHelper.doNewPrint(pageId, "bei_elecreceipt", templateId, receipt.get("id"));
|
||||||
|
if (Objects.nonNull(attach)) {
|
||||||
|
List<PrtAttach.AttachDetail> attachDetail = attach.getAttachDetail();
|
||||||
|
|
||||||
|
for (PrtAttach.AttachDetail detail : attachDetail) {
|
||||||
|
byte[] pdfPutStream = BeiHelper.getPdfPutStream(detail.getFilePath(), "new");
|
||||||
|
resList.add(pdfPutStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("ViewReceiptService listPdf=" + listPdf);
|
||||||
|
logger.info("ViewReceiptService resList.size=" + resList.size());
|
||||||
|
}
|
||||||
|
} catch (KDBizException var29) {
|
||||||
|
errMsgList.add(var29.getMessage());
|
||||||
|
} catch (Exception var30) {
|
||||||
|
logger.info(ExceptionUtils.getExceptionStackTraceMessage(var30));
|
||||||
|
errMsgList.add(getTemplateError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readTemplate(listPdf, resList);
|
||||||
|
String pdfUrl = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
pdfUrl = finlyOpenForm(resList);
|
||||||
|
} catch (Exception var27) {
|
||||||
|
logger.error("mergeMultiPdf Fail:", ExceptionUtils.getExceptionStackTraceMessage(var27));
|
||||||
|
errMsgList.add((new BeiBizResource()).dealPdfError());
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("printTimeCost: " + (System.currentTimeMillis() - timeMillis) + " generatePdfUrl: " + pdfUrl);
|
||||||
|
return pdfUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String finlyOpenForm(List<byte[]> resList) {
|
private static String finlyOpenForm(List<byte[]> resList) {
|
||||||
if (!resList.isEmpty()) {
|
if (!resList.isEmpty()) {
|
||||||
byte[] mergeMultiPdf;
|
byte[] mergeMultiPdf;
|
||||||
|
@ -735,4 +835,34 @@ public class ApiService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void readTemplate(List<String> listPdf, List<byte[]> resList) {
|
||||||
|
if (listPdf != null && !listPdf.isEmpty()) {
|
||||||
|
TempFileCache tempFileCache = CacheFactory.getCommonCacheFactory().getTempFileCache();
|
||||||
|
|
||||||
|
for (String string : listPdf) {
|
||||||
|
InputStream ins = tempFileCache.getInputStream(string);
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] bytes = new byte[ins.available()];
|
||||||
|
int bytesRead = 0;
|
||||||
|
int bytesToRead = ins.available();
|
||||||
|
|
||||||
|
while (bytesRead < bytesToRead) {
|
||||||
|
int result = ins.read(bytes, bytesRead, bytesToRead - bytesRead);
|
||||||
|
bytesRead += result;
|
||||||
|
if (result == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resList.add(bytes);
|
||||||
|
ins.close();
|
||||||
|
} catch (IOException var11) {
|
||||||
|
logger.info("IO流失败" + ExceptionUtils.getExceptionStackTraceMessage(var11));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,5 +39,9 @@ public class PaymentProcessingBillPlugin extends AbstractBillPlugIn implements P
|
||||||
this.getView().showErrorNotification("打回失败,请确认银行支付状态");
|
this.getView().showErrorNotification("打回失败,请确认银行支付状态");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("shkd_getpageid".equals(itemKey)) {
|
||||||
|
this.getView().showTipNotification("本单PageId:" + this.getView().getPageId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue