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 80716f5..bc7d3a9 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,6 +3,7 @@ package shkd.sys.sys.mservice; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import kd.bos.bill.BillShowParameter; import kd.bos.cache.CacheFactory; import kd.bos.cache.TempFileCache; import kd.bos.context.RequestContext; @@ -11,16 +12,21 @@ 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.entity.MainEntityType; import kd.bos.exception.KDBizException; +import kd.bos.form.IFormView; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.bos.metadata.dao.MetadataDao; +import kd.bos.mvc.FormConfigFactory; +import kd.bos.mvc.SessionManager; 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.MetadataServiceHelper; import kd.bos.servicehelper.PrintServiceHelper; import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.print.NotePrintService; @@ -307,10 +313,12 @@ public class ApiService { } dynamicObjects.add(dynamic); - logger.info("付款处理(支付结果) → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); + logger.info("付款处理(支付结果) → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", + dynamic.getString("billno"), saveRequestBody, saveResponseBody); result = "推送 → 付款处理(支付结果) → 成功"; } else { - logger.info("付款处理(支付结果) → BIP推送接口 → 失败\n失败单据编号:{}\n失败请求体:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); + logger.info("付款处理(支付结果) → BIP推送接口 → 失败\n失败单据编号:{}\n失败请求体:{}\n推送失败接口返回数据:{}", + dynamic.getString("billno"), saveRequestBody, saveResponseBody); result = "推送 → 付款处理(支付结果) → 失败"; } break; @@ -322,16 +330,21 @@ public class ApiService { if ("200".equals(code)) { dynamic.set("shkd_pushstatus", "已推送"); dynamicObjects.add(dynamic); - logger.info("电子回单查询 → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); + 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)); - }*/ + DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(dynamic.getPkValue(), dynamic.getDynamicObjectType().getName()); + IFormView viewByDynamicObj = createViewByDynamicObj(dynamicObject); + List errMsgList = new ArrayList<>(); + DynamicObjectCollection receipts = QueryServiceHelper.query("bei_elecreceipt", "id,bank," + + "fileflag,filepath,biztype,bankcheckflag,fileserverurl,tcpurl,uploadfilename,username,password," + + "bank.bank_cate bankcate", new QFilter[]{new QFilter("id", QCP.equals, dynamic.getPkValue())}); + String pdfUrl = getPdfUrl(viewByDynamicObj.getPageId(), receipts, errMsgList); + logger.info("获取回单附件pdfUrl:{}", pdfUrl); } else { - logger.info("电子回单查询 → BIP推送接口 → 失败\n失败单据编号:{}\n失败请求体:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); + logger.info("电子回单查询 → BIP推送接口 → 失败\n失败单据编号:{}\n失败请求体:{}\n推送失败接口返回数据:{}", + dynamic.getString("billno"), saveRequestBody, saveResponseBody); result = "推送 → 电子回单查询 → 失败"; } break; @@ -709,7 +722,7 @@ public class ApiService { errMsgList.add(ResManager.loadKDString("请求打印电子回单数量超过1000条,请分批处理。", "ViewReceiptService_6", "tmc-bei-business", new Object[0])); return null; } else { - Set pkIds = (Set)receipts.stream().map((receiptx) -> { + 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); @@ -778,6 +791,7 @@ public class ApiService { } } else { PrtAttach attach = ReceiptPrintHelper.doNewPrint(pageId, "bei_elecreceipt", templateId, receipt.get("id")); + logger.info("ViewReceiptService attach=" + attach); if (Objects.nonNull(attach)) { List attachDetail = attach.getAttachDetail(); @@ -785,6 +799,7 @@ public class ApiService { byte[] pdfPutStream = BeiHelper.getPdfPutStream(detail.getFilePath(), "new"); resList.add(pdfPutStream); } + logger.info("ViewReceiptService resList.size=" + resList.size()); } } } @@ -804,6 +819,7 @@ public class ApiService { String pdfUrl = null; try { + logger.info("resList:{}", resList); pdfUrl = finlyOpenForm(resList); } catch (Exception var27) { logger.error("mergeMultiPdf Fail:", ExceptionUtils.getExceptionStackTraceMessage(var27)); @@ -825,7 +841,7 @@ public class ApiService { throw new KDBizException(ExceptionUtils.getExceptionStackTraceMessage(var5)); } } else { - mergeMultiPdf = (byte[]) resList.get(0); + mergeMultiPdf = resList.get(0); } NotePrintService notePrintService = new NotePrintService(); @@ -865,4 +881,38 @@ public class ApiService { } } + + /** + * 按照动态对象来创建页面视图,可在后端模拟操作并且修改值触发对应插件 + * + * @return + */ + public static IFormView createViewByDynamicObj(DynamicObject dynamicObj) { + MainEntityType type = MetadataServiceHelper.getDataEntityType(dynamicObj.getDataEntityType().getName()); + String appId = type.getAppId(); + IFormView view = createView(dynamicObj.getDataEntityType().getName(), appId, dynamicObj.getPkValue()); + if (view != null) { + view.getModel().createNewData(dynamicObj); + } + return view; + } + + /** + * 创建视图 + * + * @param formId:表单标识 + * @param appId:应用id + * @return + */ + public static IFormView createView(String formId, String appId, Object pkId) { + BillShowParameter para = new BillShowParameter(); + para.setFormId(formId); + para.setAppId(appId); + para.setPkId(pkId); + // 创建单据配置 + FormConfigFactory.createConfigInCurrentAppService(para); + // 获取单据页面视图 + SessionManager sm = SessionManager.getCurrent(); + return sm.getView(para.getPageId()); + } } diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java index 30e5b1f..59a1e7f 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java @@ -75,6 +75,10 @@ public class PayBillApiSavePlugin implements ApiSavePlugin { map.put("payeeformid", "other"); } + if ("bd_supplier".equals(payeetype) || "bd_customer".equals(payeetype)) { +// BusinessDataServiceHelper.load(payeetype, "id,number,name,societycreditcode",) + } + logger.info("进入付款处理单API"); //收款人类型 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 caf90a5..d9889a1 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,6 +1,7 @@ package shkd.sys.sys.plugin.form; import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.bill.BillShowParameter; import kd.bos.cache.CacheFactory; import kd.bos.cache.TempFileCache; import kd.bos.context.RequestContext; @@ -9,17 +10,22 @@ 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.entity.MainEntityType; import kd.bos.exception.KDBizException; +import kd.bos.form.IFormView; 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.mvc.FormConfigFactory; +import kd.bos.mvc.SessionManager; 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.MetadataServiceHelper; import kd.bos.servicehelper.PrintServiceHelper; import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; @@ -60,203 +66,25 @@ public class PaymentProcessingBillPlugin extends AbstractBillPlugIn implements P if ("shkd_hitback".equals(itemKey)) { DynamicObject dataEntity = this.getModel().getDataEntity(true); String bankpaystatus = dataEntity.getString("bankpaystatus"); + + if (!"共享系统".equals(dataEntity.getString("shkd_businessname"))) { + this.getView().showTipNotification("只允许打回BIP推送单据"); + return; + } + if ("TF、NC、OF".contains(bankpaystatus)) { List dynamicObjects = new ArrayList<>(); String result = ApiService.paymentSlipsJson(dataEntity, "BIPNO", dynamicObjects, null); + logger.info("result信息:{}", result); if (result.contains("成功")) { SaveServiceHelper.save(dynamicObjects.toArray(new DynamicObject[0])); this.getView().showSuccessNotification("打回成功"); + } else { + this.getView().showTipNotification("打回失败"); } } else { - this.getView().showErrorNotification("打回失败,请确认银行支付状态"); + this.getView().showTipNotification("打回失败,请确认银行支付状态"); } } - - if ("shkd_getpageid".equals(itemKey)) { -// 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," + - "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")); - logger.info("ViewReceiptService attach=" + attach); - 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 resList.size=" + resList.size()); - } - } - } - - 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 { - logger.info("resList:{}", resList); - 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