提交内容:获取电子回单附件URL

备注:获取电子回单附件URL
提交人:邹江涛
This commit is contained in:
zoujiangtao 2024-12-26 10:43:30 +08:00
parent 5c9223ef1c
commit 0daa867f65
2 changed files with 65 additions and 15 deletions

View File

@ -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<String, Object> 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<String, Object> getSubmitRequestBody(String fullname, String billnum, String id) {
Map<String, Object> data = new HashMap<>();
Map<String, String> innerData = new HashMap<>();
@ -710,6 +729,19 @@ public class ApiService {
return data;
}
public static String getAttachmentRequestBody(Map<String, Object> 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<String> errMsgList) {
List<String> listPdf = new ArrayList<>(10);
List<byte[]> 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<Long> pkIds = (Set<Long>) receipts.stream().map((receiptx) -> {
return receiptx.getLong("id");
}).collect(Collectors.toSet());
Set<Long> pkIds = receipts.stream().map((receiptx) -> 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();
@ -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;
}
}

View File

@ -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);