parent
d8b51ce65f
commit
15753ba9ab
|
@ -1,5 +1,6 @@
|
|||
package shkd.sys.sys.mservice;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
|
@ -9,6 +10,7 @@ import kd.bos.logging.LogFactory;
|
|||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
@ -41,9 +43,8 @@ public class ApiService {
|
|||
private static final String APP_KEY = "22564a240d3140d0b15582aca71a748c";
|
||||
private static final String API_ENDPOINT = "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken";
|
||||
|
||||
public static Map<String, Object> getBIPToken(String domainName) {
|
||||
public static String getBIPToken(String domainName) {
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String signature = generateSignature("appKey" + APP_KEY + "timestamp" + currentTimeMillis);
|
||||
logger.info("getBIPToken → 签名: {}", signature);
|
||||
|
||||
|
@ -54,7 +55,6 @@ public class ApiService {
|
|||
"?appKey=" + APP_KEY +
|
||||
"×tamp=" + currentTimeMillis +
|
||||
"&signature=" + signature;
|
||||
map.put("url", urlString);
|
||||
// return urlString;
|
||||
|
||||
String token;
|
||||
|
@ -68,9 +68,8 @@ public class ApiService {
|
|||
logger.error("getBIPToken → 请求失败: ", e);
|
||||
token = null;
|
||||
}
|
||||
map.put("token", token);
|
||||
// 处理响应
|
||||
return map;
|
||||
return token;
|
||||
|
||||
}
|
||||
|
||||
|
@ -164,7 +163,8 @@ public class ApiService {
|
|||
* @param systemName 推送系统标识
|
||||
* @return
|
||||
*/
|
||||
public static String paymentSlipsJson(DynamicObject dynamic, String systemName) {
|
||||
public static String paymentSlipsJson(DynamicObject dynamic, String systemName, List<DynamicObject> dynamicObjects) {
|
||||
|
||||
// 获取推送的单据标识
|
||||
String billMark = dynamic.getDataEntityType().getName();
|
||||
|
||||
|
@ -172,20 +172,85 @@ public class ApiService {
|
|||
"shkd_name,shkd_sourcenumber,shkd_domainname,shkd_token,shkd_url,shkd_bodytype," +
|
||||
"shkd_sourcebill,shkd_targetsystem,entryentity,entryentity.shkd_tarfield,entryentity.shkd_tartier," +
|
||||
"entryentity.shkd_tartype,entryentity.shkd_parentfield,entryentity.shkd_soufield,entryentity.shkd_defaultdata," +
|
||||
"entryentity.shkd_required,entryentity.shkd_remarks",
|
||||
"entryentity.shkd_required,entryentity.shkd_remarks,shkd_submiturl",
|
||||
new QFilter("shkd_sourcebill", QCP.equals, billMark).and(
|
||||
new QFilter("shkd_targetsystem", QCP.equals, systemName)).toArray());
|
||||
|
||||
// 组装请求体数据
|
||||
String requestBody = assembleRequestBody(dynamic, objects[0]);
|
||||
logger.info("请求URL:{}\n组装请求body:{}", objects[0].getString("shkd_url"), requestBody);
|
||||
String saveUrl = objects[0].getString("shkd_url");
|
||||
|
||||
// 组装请求体数据
|
||||
String saveRequestBody = assembleRequestBody(dynamic, objects[0]);
|
||||
logger.info("请求URL:{}\n组装请求body:{}", saveUrl, saveRequestBody);
|
||||
|
||||
|
||||
String result = null;
|
||||
String saveResponseBody;
|
||||
JSONObject jsonObject;
|
||||
String code;
|
||||
JSONObject data;
|
||||
String submitUrl;
|
||||
Map<String, Object> submitRequestBody;
|
||||
String submitResponseBody;
|
||||
switch (saveUrl) {
|
||||
// 付款处理
|
||||
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/fi/fundpayment/save":
|
||||
// 保存
|
||||
saveResponseBody = pushBill(objects[0], saveUrl, saveRequestBody);
|
||||
logger.info("付款处理 → BIP保存接口 → 返回结果:{}", saveResponseBody);
|
||||
jsonObject = JSON.parseObject(saveResponseBody);
|
||||
code = jsonObject.getString("code");
|
||||
if ("200".equals(code)) {
|
||||
logger.info("付款处理 → BIP保存接口 → 成功\n失败单据编号:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveResponseBody);
|
||||
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_pushstatus", "已推送");
|
||||
dynamicObjects.add(dynamic);
|
||||
|
||||
submitUrl = objects[0].getString("shkd_submiturl");
|
||||
submitRequestBody = getSubmitRequestBody("cmp.fundpayment.FundPayment", "cmp_fundpayment", data.getString("id"));
|
||||
// 提交
|
||||
submitResponseBody = pushBill(objects[0], submitUrl, JSON.toJSONString(submitRequestBody));
|
||||
logger.info("付款处理 → BIP提交接口 → 返回结果:{}", submitResponseBody);
|
||||
result = "推送 → 付款处理单 → 成功";
|
||||
} else {
|
||||
logger.info("付款处理 → BIP保存接口 → 成功\n失败单据编号:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveResponseBody);
|
||||
result = "推送 → 付款处理单 → 失败";
|
||||
}
|
||||
|
||||
break;
|
||||
// 收款处理
|
||||
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/fi/fundcollection/save":
|
||||
break;
|
||||
// 银行收付处理
|
||||
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/ctm/cmp/bankReconciliationBatchSave":
|
||||
break;
|
||||
// 支付结果
|
||||
case "https://biptestctny.invest.com.cn:8002/iuap-api-auth/yonbip/ctm/api/settlement/feedback":
|
||||
saveResponseBody = pushBill(objects[0], saveUrl, saveRequestBody);
|
||||
jsonObject = JSON.parseObject(saveResponseBody);
|
||||
code = jsonObject.getString("code");
|
||||
if ("200".equals(code)) {
|
||||
dynamic.set("billstatus", "A");
|
||||
dynamicObjects.add(dynamic);
|
||||
logger.info("付款处理(支付结果) → BIP推送接口 → 成功\n成功单据编号:{}\n推送成功接口返回数据:{}", dynamic.getString("billno"), saveResponseBody);
|
||||
result = "推送 → 付款处理(支付结果) → 成功";
|
||||
} else {
|
||||
logger.info("付款处理(支付结果) → BIP推送接口 → 失败\n失败单据编号:{}\n推送失败接口返回数据:{}", dynamic.getString("billno"), saveResponseBody);
|
||||
result = "推送 → 付款处理(支付结果) → 失败";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result = "暂不支持该业务推送";
|
||||
}
|
||||
// 调用接口,获取响应数据
|
||||
return pushBill(objects[0], requestBody);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装请求体数据
|
||||
*
|
||||
* @param dynamic 推送数据对象
|
||||
* @param mapping API映射对象数据
|
||||
* @return
|
||||
|
@ -230,6 +295,7 @@ public class ApiService {
|
|||
return resultJson.toJSONString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理楼层
|
||||
*
|
||||
|
@ -413,21 +479,21 @@ public class ApiService {
|
|||
|
||||
/**
|
||||
* 推送单条数据
|
||||
*
|
||||
* @param dataEntity
|
||||
* @param requestBody
|
||||
* @return
|
||||
*/
|
||||
private static String pushBill(DynamicObject dataEntity, String requestBody) {
|
||||
private static String pushBill(DynamicObject dataEntity, String linkUrl, String requestBody) {
|
||||
// 响应数据
|
||||
String formattedContent;
|
||||
try {
|
||||
// 域名
|
||||
String domainName = dataEntity.getString("shkd_domainname");
|
||||
Map<String, Object> resultMap = ApiService.getBIPToken(domainName);
|
||||
Object token = resultMap.get("token");
|
||||
String token = ApiService.getBIPToken(domainName);
|
||||
logger.info("获取token:{}", token);
|
||||
// 请求URL
|
||||
URL url = new URL(dataEntity.getString("shkd_url") + "?access_token=" + token);
|
||||
URL url = new URL(linkUrl + "?access_token=" + token);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
// 设置请求方法为POST
|
||||
|
@ -475,4 +541,15 @@ public class ApiService {
|
|||
}
|
||||
return formattedContent;
|
||||
}
|
||||
|
||||
public static Map<String, Object> getSubmitRequestBody(String fullname, String billnum, String id) {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
Map<String, String> innerData = new HashMap<>();
|
||||
|
||||
data.put("fullname", fullname);
|
||||
data.put("billnum", billnum);
|
||||
innerData.put("id", id);
|
||||
data.put("data", innerData);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,7 @@ import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|||
import kd.sdk.plugin.Plugin;
|
||||
import shkd.sys.sys.mservice.ApiService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 动态表单插件
|
||||
|
@ -111,41 +108,23 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
List<DynamicObject> dynamicObjects = new ArrayList<>();
|
||||
|
||||
if ("shkd_testapi".equals(itemKey)) {
|
||||
String responseBody = ApiService.paymentSlipsJson(billObject, "BIP");
|
||||
JSONObject jsonObject = JSON.parseObject(responseBody);
|
||||
String code = jsonObject.getString("code");
|
||||
if ("200".equals(code)) {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
billObject.set("shkd_businessnumber", data.getString("code"));
|
||||
billObject.set("shkd_businessid", data.getString("id"));
|
||||
billObject.set("shkd_businessname", "BIP");
|
||||
billObject.set("shkd_pushstatus", "已推送");
|
||||
SaveServiceHelper.save(new DynamicObject[]{billObject});
|
||||
} else {
|
||||
logger.info("推送 → 失败\n失败单据编号:{}\n推送失败接口返回数据:{}", billObject.getString("billno"), responseBody);
|
||||
}
|
||||
this.getView().showTipNotification("返回结果:" + responseBody);
|
||||
String result = ApiService.paymentSlipsJson(billObject, "BIP", dynamicObjects);
|
||||
this.getView().showTipNotification("返回结果:" + result);
|
||||
}
|
||||
|
||||
if ("shkd_hitback".equals(itemKey)) {
|
||||
String responseBody = ApiService.paymentSlipsJson(billObject, "BIPNO");
|
||||
JSONObject jsonObject = JSON.parseObject(responseBody);
|
||||
String code = jsonObject.getString("code");
|
||||
if ("200".equals(code)) {
|
||||
billObject.set("billstatus", "A");
|
||||
SaveServiceHelper.save(new DynamicObject[]{billObject});
|
||||
} else {
|
||||
logger.info("推送 → 失败\n失败单据编号:{}\n推送失败接口返回数据:{}", billObject.getString("billno"), responseBody);
|
||||
}
|
||||
this.getView().showTipNotification("返回结果:" + responseBody);
|
||||
String result = ApiService.paymentSlipsJson(billObject, "BIPNO", dynamicObjects);
|
||||
this.getView().showTipNotification("返回结果:" + result);
|
||||
}
|
||||
|
||||
if ("shkd_gettoken".equals(itemKey)) {
|
||||
//域名
|
||||
String domainName = dataEntity.getString("shkd_domainname");
|
||||
Map<String, Object> resultMap = ApiService.getBIPToken(domainName);
|
||||
this.getModel().setValue("shkd_token", resultMap.get("token"));
|
||||
String token = ApiService.getBIPToken(domainName);
|
||||
this.getModel().setValue("shkd_token", token);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,14 +35,8 @@ public class ApiTestBillPlugin extends AbstractBillPlugIn implements Plugin {
|
|||
|
||||
if ("shkd_token".equals(key)) {
|
||||
String url = this.getModel().getValue("shkd_url").toString();
|
||||
Map<String, Object> resultMap = ApiService.getBIPToken(url);
|
||||
this.getView().showTipNotification(resultMap.get("token") == null ? "获取token为空" :resultMap.get("token").toString());
|
||||
}
|
||||
|
||||
if ("shkd_geturl".equals(key)) {
|
||||
String url = this.getModel().getValue("shkd_url").toString();
|
||||
Map<String, Object> resultMap = ApiService.getBIPToken(url);
|
||||
this.getView().showTipNotification(resultMap.get("url").toString());
|
||||
String token = ApiService.getBIPToken(url);
|
||||
this.getView().showTipNotification(token == null ? "获取token为空" :token);
|
||||
}
|
||||
|
||||
if ("shkd_api".equals(key)) {
|
||||
|
|
|
@ -48,11 +48,9 @@ public class PushTaskPlugin extends AbstractTask implements Plugin {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
String billName = null;
|
||||
|
||||
List<DynamicObject> dynamicObjects = new ArrayList<>();
|
||||
List<DynamicObject> objects = new ArrayList<>();
|
||||
String finalBillName;
|
||||
List<DynamicObject> dynamicObjects;
|
||||
String billName;
|
||||
List<DynamicObject> dynamicObjectList = new ArrayList<>();
|
||||
if (billMark != null) {
|
||||
switch (billMark.toString()) {
|
||||
// 付款处理
|
||||
|
@ -64,29 +62,10 @@ public class PushTaskPlugin extends AbstractTask implements Plugin {
|
|||
, new QFilter("bizdate", QCP.large_equals, date).and("shkd_pushstatus", QCP.not_equals, "已推送")
|
||||
.and("billstatus", QCP.equals, "D").toArray());
|
||||
dynamicObjects = Arrays.asList(objects1);
|
||||
billName = "付款处理";
|
||||
finalBillName = billName;
|
||||
dynamicObjects.forEach(dynamicObject -> {
|
||||
String responseBody = ApiService.paymentSlipsJson(dynamicObject, "BIP");
|
||||
logger.info("推送 → {} → 开始\n推送单据编号:{}\n接口响应数据:{}", finalBillName, dynamicObject.getString("billno"), responseBody);
|
||||
if (!responseBody.contains("失败")) {
|
||||
JSONObject jsonObject = JSON.parseObject(responseBody);
|
||||
String code = jsonObject.getString("code");
|
||||
if ("200".equals(code)) {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
dynamicObject.set("shkd_businessnumber", data.getString("code"));
|
||||
dynamicObject.set("shkd_businessid", data.getString("id"));
|
||||
dynamicObject.set("shkd_businessname", "BIP");
|
||||
dynamicObject.set("shkd_pushstatus", "已推送");
|
||||
objects.add(dynamicObject);
|
||||
} else {
|
||||
logger.info("推送 → {} → 失败\n失败单据编号:{}\n推送失败接口返回数据:{}", finalBillName, dynamicObject.getString("billno"), responseBody);
|
||||
}
|
||||
} else {
|
||||
logger.info("推送 → {} → 失败,失败单据编号:{}", finalBillName, dynamicObject.getString("billno"));
|
||||
}
|
||||
ApiService.paymentSlipsJson(dynamicObject, "BIP", dynamicObjectList);
|
||||
});
|
||||
SaveServiceHelper.save(objects.toArray(new DynamicObject[0]));
|
||||
SaveServiceHelper.save(dynamicObjectList.toArray(new DynamicObject[0]));
|
||||
break;
|
||||
// 收款处理
|
||||
case "cas_recbill":
|
||||
|
@ -116,24 +95,10 @@ public class PushTaskPlugin extends AbstractTask implements Plugin {
|
|||
"shkd_pushstatus,shkd_businessnumber,shkd_businessid,shkd_businessname,billstatus,bankpaystatus"
|
||||
, new QFilter("bizdate", QCP.large_equals, date).and("bankpaystatus", QCP.in, new String[]{"TF", "NC", "OF"}).toArray());
|
||||
dynamicObjects = Arrays.asList(objects4);
|
||||
finalBillName = billName;
|
||||
dynamicObjects.forEach(dynamicObject -> {
|
||||
String responseBody = ApiService.paymentSlipsJson(dynamicObject, "BIPNO");
|
||||
logger.info("推送 → {} → 开始\n推送单据编号:{}\n接口响应数据:{}", finalBillName, dynamicObject.getString("billno"), responseBody);
|
||||
if (!responseBody.contains("失败")) {
|
||||
JSONObject jsonObject = JSON.parseObject(responseBody);
|
||||
String code = jsonObject.getString("code");
|
||||
if ("200".equals(code)) {
|
||||
dynamicObject.set("billstatus", "A");
|
||||
objects.add(dynamicObject);
|
||||
} else {
|
||||
logger.info("推送 → {} → 失败\n失败单据编号:{}\n推送失败接口返回数据:{}", finalBillName, dynamicObject.getString("billno"), responseBody);
|
||||
}
|
||||
} else {
|
||||
logger.info("推送 → {} → 失败,失败单据编号:{}", finalBillName, dynamicObject.getString("billno"));
|
||||
}
|
||||
ApiService.paymentSlipsJson(dynamicObject, "BIPNO", dynamicObjectList);
|
||||
});
|
||||
SaveServiceHelper.save(objects.toArray(new DynamicObject[0]));
|
||||
SaveServiceHelper.save(dynamicObjectList.toArray(new DynamicObject[0]));
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue