diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/ApiService.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/ApiService.java index cc35bf9..98e4f9e 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/ApiService.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/mservice/ApiService.java @@ -3,16 +3,25 @@ package shkd.sys.sys.mservice; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import kd.bos.cache.CacheFactory; +import kd.bos.cache.TempFileCache; import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; 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.logging.Log; import kd.bos.logging.LogFactory; +import kd.bos.metadata.dao.MetadataDao; import kd.bos.orm.query.QCP; 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.PrintServiceHelper; import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.print.NotePrintService; 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.ReceiptPrintHelper; import kd.bos.util.ExceptionUtils; +import kd.tmc.bei.common.resource.BeiBizResource; import kd.tmc.fbp.common.ofd.OfdConvertUtil; import kd.tmc.fbp.common.util.EmptyUtil; import org.springframework.http.HttpEntity; @@ -31,10 +41,7 @@ import org.springframework.web.client.RestTemplate; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import javax.net.ssl.*; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; +import java.io.*; import java.math.BigDecimal; import java.net.HttpURLConnection; import java.net.URL; @@ -43,6 +50,7 @@ import java.nio.charset.StandardCharsets; import java.security.cert.X509Certificate; import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; /** * @Description @@ -317,36 +325,11 @@ public class ApiService { logger.info("电子回单查询 → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); result = "推送 → 电子回单查询 → 成功"; - List resList = new ArrayList<>(10); - String uploadFileName = ReceiptPrintHelper.getRealUploadUrl(dynamic); - String fileServerUrl = dynamic.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(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); + List errMsgList = new ArrayList<>(); +// String pdfUrl = getPdfUrl(view.getPageId(), receipts, errMsgList); +// if (!errMsgList.isEmpty()) { +// view.showErrorNotification(String.join(",", errMsgList)); +// } } else { logger.info("电子回单查询 → BIP推送接口 → 失败\n失败单据编号:{}\n失败请求体:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); result = "推送 → 电子回单查询 → 失败"; @@ -715,6 +698,123 @@ public class ApiService { return data; } + private static String getPdfUrl(String pageId, DynamicObjectCollection receipts, List errMsgList) { + List listPdf = new ArrayList<>(10); + List 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 pkIds = (Set)receipts.stream().map((receiptx) -> { + return receiptx.getLong("id"); + }).collect(Collectors.toSet()); + Map> 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 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 resList) { if (!resList.isEmpty()) { byte[] mergeMultiPdf; @@ -735,4 +835,34 @@ public class ApiService { return null; } } + + private static void readTemplate(List listPdf, List 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)); + } + } + + } + } } diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/PaymentProcessingBillPlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/PaymentProcessingBillPlugin.java index 87cacb2..1f8db0b 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/PaymentProcessingBillPlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/PaymentProcessingBillPlugin.java @@ -39,5 +39,9 @@ public class PaymentProcessingBillPlugin extends AbstractBillPlugIn implements P this.getView().showErrorNotification("打回失败,请确认银行支付状态"); } } + + if ("shkd_getpageid".equals(itemKey)) { + this.getView().showTipNotification("本单PageId:" + this.getView().getPageId()); + } } } \ No newline at end of file