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 07cef59..23c6a61 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 @@ -205,7 +205,7 @@ public class ApiService { String saveRequestBody; - String result = null; + String result; String saveResponseBody; JSONObject jsonObject; String code; @@ -264,7 +264,7 @@ public class ApiService { data = jsonObject.getJSONObject("data"); dynamic.set("shkd_businessnumber", data.getString("code")); dynamic.set("shkd_businessid", data.getString("id")); - dynamic.set("shkd_businessname", "BIP"); + dynamic.set("shkd_businessname", "共享系统"); dynamic.set("shkd_pushstatus", "已结算"); dynamicObjects.add(dynamic); @@ -287,6 +287,7 @@ public class ApiService { code = jsonObject.getString("code"); if ("200".equals(code)) { dynamic.set("shkd_pushstatus", "已推送"); + dynamic.set("shkd_businessname", "共享系统"); dynamicObjects.add(dynamic); logger.info("银行收付处理 → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); result = "推送 → 银行收付处理 → 成功"; @@ -328,6 +329,8 @@ public class ApiService { code = jsonObject.getString("code"); if ("200".equals(code)) { dynamic.set("shkd_pushstatus", "已推送"); + dynamic.set("shkd_businessname", "共享系统"); + dynamic.set("shkd_businessid", jsonObject.getJSONArray("data").get(0)); dynamicObjects.add(dynamic); logger.info("电子回单查询 → BIP推送接口 → 成功\n成功单据编号:{}\n成功请求体:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); @@ -340,7 +343,15 @@ public class ApiService { "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); + + Map hashMap = new HashMap<>(); + hashMap.put("bankpdf", attachmentBase64(pdfUrl)); + hashMap.put("fileName", dynamic.getString("uploadfilename")); + hashMap.put("id", jsonObject.getJSONArray("data").get(0).toString()); + hashMap.put("receiptno", dynamic.getString("billno")); + String attachmentRequestBody = getAttachmentRequestBody(hashMap); + String pushResult = pushBill(token, "https://biptestctny.invest.com.cn:8002/iuap-api-auth//yonbip/ctm/bank/tran/update", attachmentRequestBody); + logger.info("电子回单查询 → BIP推送附件接口 → \n推送数据:{}\n请求返回结果:{}", attachmentRequestBody, pushResult); } else { logger.info("电子回单查询 → BIP推送接口 → 失败\n失败单据编号:{}\n失败请求体:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveRequestBody, saveResponseBody); @@ -699,6 +710,14 @@ public class ApiService { } } + /** + * 组装提交接口请求体 + * + * @param fullname + * @param billnum + * @param id + * @return + */ public static Map getSubmitRequestBody(String fullname, String billnum, String id) { Map data = new HashMap<>(); Map innerData = new HashMap<>(); @@ -710,6 +729,19 @@ public class ApiService { return data; } + public static String getAttachmentRequestBody(Map hashMap) { + + // 创建 JSONObject 并填充数据 + JSONObject jsonObject = new JSONObject(hashMap); + + // 创建 JSONArray 并添加 JSONObject + JSONArray jsonArray = new JSONArray(); + jsonArray.add(jsonObject); + + // 输出最终的 JSON 数组字符串 + return jsonArray.toJSONString(); + } + private static String getPdfUrl(String pageId, DynamicObjectCollection receipts, List errMsgList) { List listPdf = new ArrayList<>(10); List resList = new ArrayList<>(10); @@ -718,12 +750,10 @@ public class ApiService { 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])); + errMsgList.add(ResManager.loadKDString("请求打印电子回单数量超过1000条,请分批处理。", "ViewReceiptService_6", "tmc-bei-business")); return null; } else { - Set pkIds = (Set) receipts.stream().map((receiptx) -> { - return receiptx.getLong("id"); - }).collect(Collectors.toSet()); + Set pkIds = receipts.stream().map((receiptx) -> receiptx.getLong("id")).collect(Collectors.toSet()); Map> receiptTemplate = ReceiptPrintHelper.getMatchReceiptTemplate("bei", "bei_elecreceipt", pkIds, ViewType.LIST, pageId); receiptTemplate.remove(""); long timeMillis = System.currentTimeMillis(); @@ -737,9 +767,8 @@ public class ApiService { errMsgList.add(templateError); } else { - for (Object o : (Set) receiptTemplate.get(receiptID)) { - MatcherTpl template = (MatcherTpl) o; - String templateId = template.getTplId(); + for (MatcherTpl o : receiptTemplate.get(receiptID)) { + String templateId = o.getTplId(); logger.info("ViewReceiptService templateForm.keySet=" + templateId); String templateFormId = ""; if (EmptyUtil.isNoEmpty(templateId)) { @@ -766,12 +795,12 @@ public class ApiService { 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); + 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, (InputStream) null); + ReceiptPrintHelper.imageConvertPdf(uploadFileName, resList, null); } else { logger.info("ofdReceipt url:" + uploadFileName); byte[] bytes = OfdConvertUtil.convertToPdfNew(BeiHelper.getPdfPutStream(uploadFileName, "old")); @@ -884,7 +913,7 @@ public class ApiService { /** * 按照动态对象来创建页面视图,可在后端模拟操作并且修改值触发对应插件 * - * @return + * @return IFormView */ public static IFormView createViewByDynamicObj(DynamicObject dynamicObj) { MainEntityType type = MetadataServiceHelper.getDataEntityType(dynamicObj.getDataEntityType().getName()); @@ -901,7 +930,7 @@ public class ApiService { * * @param formId:表单标识 * @param appId:应用id - * @return + * @return IFormView */ public static IFormView createView(String formId, String appId, Object pkId) { BillShowParameter para = new BillShowParameter(); @@ -914,4 +943,24 @@ public class ApiService { SessionManager sm = SessionManager.getCurrent(); return sm.getView(para.getPageId()); } + + public static String attachmentBase64(String url) { + String base64; + try (InputStream inputStream = CacheFactory.getCommonCacheFactory().getTempFileCache().getInputStream(url); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStream base64OutputStream = Base64.getEncoder().wrap(outputStream)) { + byte[] buffer = new byte[4096]; // 使用 4KB 缓冲区 + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + base64OutputStream.write(buffer, 0, bytesRead); + } + base64OutputStream.flush(); // 确保所有数据都被写入 + // 获取 Base64 编码后的字节数组 + byte[] base64Data = outputStream.toByteArray(); + base64 = new String(base64Data, StandardCharsets.UTF_8); + } catch (IOException e) { + throw new RuntimeException(e); + } + return base64; + } } diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java index 69143a9..88e0d48 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java @@ -108,7 +108,8 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin { case "bei_elecreceipt": DynamicObject[] objects4 = BusinessDataServiceHelper.load("bei_elecreceipt", "id,billno,shkd_pushstatus,fileserverurl,bizdate,oppbankname,description,company,oppbanknumber," + - "detaildatetime,accountbank,amount,use,debitamount,creditamount,detailid,uploadfilename" + "detaildatetime,accountbank,amount,use,debitamount,creditamount,detailid,uploadfilename," + + "shkd_businessnumber,shkd_businessid,shkd_businessname" , new QFilter("billno", QCP.equals, billNumber).toArray()); billObject = objects4[0]; logger.info("获取银企交易明细查询推送对象 → billObject:{}", billObject);