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 98e4f9e..80716f5 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 @@ -325,11 +325,11 @@ public class ApiService { logger.info("电子回单查询 → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); result = "推送 → 电子回单查询 → 成功"; - List errMsgList = new ArrayList<>(); -// String pdfUrl = getPdfUrl(view.getPageId(), receipts, errMsgList); -// if (!errMsgList.isEmpty()) { -// view.showErrorNotification(String.join(",", errMsgList)); -// } + /*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 = "推送 → 电子回单查询 → 失败"; 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 1f8db0b..ee54365 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 @@ -1,21 +1,53 @@ package shkd.sys.sys.plugin.form; import kd.bos.bill.AbstractBillPlugIn; +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.form.control.Toolbar; import kd.bos.form.control.events.ItemClickEvent; +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.PrintServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; +import kd.bos.servicehelper.print.NotePrintService; +import kd.bos.util.ExceptionUtils; import kd.sdk.plugin.Plugin; +import kd.tmc.bei.business.ocr.impl.ScanServiceImpl; +import kd.tmc.bei.business.ocr.invoke.ScanSystemFactory; +import kd.tmc.bei.business.opservice.elec.ViewReceiptService; +import kd.tmc.bei.common.helper.BeiHelper; +import kd.tmc.bei.common.helper.ReceiptPrintHelper; +import kd.tmc.bei.common.resource.BeiBizResource; +import kd.tmc.fbp.common.ofd.OfdConvertUtil; +import kd.tmc.fbp.common.util.EmptyUtil; import shkd.sys.sys.mservice.ApiService; -import java.util.ArrayList; -import java.util.EventObject; -import java.util.List; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; /** * 单据界面插件 */ public class PaymentProcessingBillPlugin extends AbstractBillPlugIn implements Plugin { + private static final Log logger = LogFactory.getLog(PaymentProcessingBillPlugin.class); + @Override public void registerListener(EventObject e) { Toolbar tbmain = this.getView().getControl("tbmain"); @@ -41,7 +73,186 @@ public class PaymentProcessingBillPlugin extends AbstractBillPlugIn implements P } if ("shkd_getpageid".equals(itemKey)) { - this.getView().showTipNotification("本单PageId:" + this.getView().getPageId()); +// this.getView().showTipNotification("本单PageId:" + this.getView().getPageId()); + List errMsgList = new ArrayList<>(); + Long pkValue = (Long) this.getView().getModel().getDataEntity().getPkValue(); + DynamicObjectCollection receipts = QueryServiceHelper.query("bei_elecreceipt", "id,bank" + + "4,fileflag,filepath,biztype,bankcheckflag,fileserverurl,tcpurl,uploadfilename,username,password," + + "bank.bank_cate bankcate", new QFilter[]{new QFilter("id", QCP.equals, pkValue)}); + String pdfUrl = getPdfUrl(this.getView().getPageId(), receipts, errMsgList); + if (!errMsgList.isEmpty()) { + this.getView().showErrorNotification(String.join(",", errMsgList)); + } + logger.info("PageId:{}\npdfUrl:{}", this.getView().getPageId(), pdfUrl); + } + } + + + 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; + if (resList.size() > 1) { + try { + mergeMultiPdf = ReceiptPrintHelper.mergeMultiPdf(resList); + } catch (Exception var5) { + throw new KDBizException(ExceptionUtils.getExceptionStackTraceMessage(var5)); + } + } else { + mergeMultiPdf = (byte[]) resList.get(0); + } + + NotePrintService notePrintService = new NotePrintService(); + LocaleString localeString = new LocaleString("receipt"); + return notePrintService.createPdfUrl(localeString, mergeMultiPdf); + } else { + 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)); + } + } + } } } \ No newline at end of file