parent
2f8b4b1ec4
commit
3294e5eabf
|
@ -3,8 +3,13 @@ package shkd.sys.sys.mservice;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
import kd.bos.logging.Log;
|
import kd.bos.logging.Log;
|
||||||
import kd.bos.logging.LogFactory;
|
import kd.bos.logging.LogFactory;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
import shkd.sys.sys.common.ApiEntity;
|
import shkd.sys.sys.common.ApiEntity;
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
|
@ -17,9 +22,7 @@ import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.Base64;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description
|
* @Description
|
||||||
|
@ -139,56 +142,184 @@ public class BIPService {
|
||||||
/**
|
/**
|
||||||
* 组装推送BIP付款单JSON
|
* 组装推送BIP付款单JSON
|
||||||
*
|
*
|
||||||
|
* @param dynamic 某个单据的 某条需要推送的数据
|
||||||
|
* @param systemName 推送系统名称
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static JSONObject paymentSlipsJson() {
|
public static JSONObject paymentSlipsJson(DynamicObject dynamic, String systemName) {
|
||||||
ApiEntity apiEntity = new ApiEntity();
|
// 获取推送的单据标识
|
||||||
|
String billMark = dynamic.getDataEntityType().getName();
|
||||||
|
|
||||||
JSONObject root = new JSONObject();
|
DynamicObject[] objects = BusinessDataServiceHelper.load("shkd_apimapping", "id,billno," +
|
||||||
|
"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",
|
||||||
|
new QFilter("shkd_sourcebill", QCP.equals, billMark).and(
|
||||||
|
new QFilter("shkd_targetsystem", QCP.equals, systemName)).toArray());
|
||||||
|
|
||||||
// 创建"data"节点
|
// 获取数据表信息
|
||||||
JSONObject data = new JSONObject();
|
DynamicObjectCollection dynamicObjectCollection = objects[0].getDynamicObjectCollection("entryentity");
|
||||||
|
|
||||||
// 设置"data"节点的属性
|
// 提取所有层级并存储在 Set 中
|
||||||
data.put("accentity_code", "SIG1040100");
|
Set<Integer> tiers = new HashSet<>();
|
||||||
data.put("vouchdate", "2022-04-20");
|
dynamicObjectCollection.forEach(dynamicObject -> {
|
||||||
data.put("tradetype_code", "cmp_fund_payment_other");
|
String shkd_tartier = dynamicObject.getString("shkd_tartier");
|
||||||
data.put("exchangeRateType_code", "01");
|
if (shkd_tartier != null && !shkd_tartier.isEmpty()) {
|
||||||
data.put("exchRate", 1);
|
tiers.add(Integer.parseInt(shkd_tartier));
|
||||||
data.put("currency_code", "CNY");
|
}
|
||||||
data.put("_status", "Insert");
|
});
|
||||||
|
|
||||||
// 创建"FundPayment_b"列表
|
List<List<DynamicObject>> floors = new ArrayList<>();
|
||||||
JSONArray fundPaymentList = new JSONArray();
|
// 目前定的4层,之后需要弄成动态的
|
||||||
|
for (int i = 1; i <= tiers.size(); i++) {
|
||||||
|
floors.add(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
// 创建"FundPayment_b"列表中的第一个对象
|
// 分层
|
||||||
JSONObject fundPayment = new JSONObject();
|
for (DynamicObject dynamicObject : dynamicObjectCollection) {
|
||||||
fundPayment.put("quickType_code", "6");
|
int tier = Integer.parseInt(dynamicObject.getString("shkd_tartier"));
|
||||||
fundPayment.put("settlestatus", "1");
|
floors.get(tier - 1).add(dynamicObject);
|
||||||
fundPayment.put("oriSum", 5000);
|
}
|
||||||
fundPayment.put("caobject", 2);
|
JSONObject resultJson = new JSONObject();
|
||||||
fundPayment.put("oppositeobjectname", "11510107MB1526717D");
|
processFloor(resultJson, "data", floors.get(0), floors);
|
||||||
fundPayment.put("_status", "Insert");
|
return resultJson;
|
||||||
|
}
|
||||||
|
|
||||||
// 将"FundPayment_b"对象添加到列表中
|
public static void traverseJson(JSONObject jsonObject, List<String> path, String level) {
|
||||||
fundPaymentList.add(fundPayment);
|
for (String key : jsonObject.keySet()) {
|
||||||
// 将"FundPayment_b"列表添加到"data"节点中
|
Object value = jsonObject.get(key);
|
||||||
data.put("FundPayment_b", fundPaymentList);
|
String fullPath = buildPath(path, key, level);
|
||||||
// 将"data"节点添加到根JSON对象中
|
System.out.println(fullPath + ": " + value);
|
||||||
root.put("data", data);
|
|
||||||
|
|
||||||
apiEntity.setURL("");
|
if (value instanceof JSONObject) {
|
||||||
apiEntity.setRequestBody(root);
|
path.add(key);
|
||||||
apiEntity.setMethod("POST");
|
traverseJson((JSONObject) value, path, level + "." + (path.size() + 1));
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
} else if (value instanceof JSONArray) {
|
||||||
|
path.add(key);
|
||||||
|
traverseJsonArray((JSONArray) value, path, level + "." + (path.size() + 1));
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> queryParams = new HashMap<>();
|
public static void traverseJsonArray(JSONArray jsonArray, List<String> path, String level) {
|
||||||
queryParams.put("access_token", getBIPToken());
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
apiEntity.setQueryParams(queryParams);
|
Object value = jsonArray.get(i);
|
||||||
|
if (value instanceof JSONObject) {
|
||||||
|
path.add("[" + i + "]");
|
||||||
|
traverseJson((JSONObject) value, path, level + "." + (i + 1));
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
} else if (value instanceof JSONArray) {
|
||||||
|
path.add("[" + i + "]");
|
||||||
|
traverseJsonArray((JSONArray) value, path, level + "." + (i + 1));
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
} else {
|
||||||
|
String fullPath = buildPath(path, "[" + i + "]", level);
|
||||||
|
System.out.println(fullPath + ": " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> headers = new HashMap<>();
|
public static String buildPath(List<String> path, String key, String level) {
|
||||||
headers.put("Content-Type", "application/json");
|
StringBuilder sb = new StringBuilder();
|
||||||
apiEntity.setHeaders(headers);
|
sb.append("层级 ").append(level).append(": ");
|
||||||
|
for (int i = 0; i < path.size(); i++) {
|
||||||
|
sb.append(path.get(i)).append(".");
|
||||||
|
}
|
||||||
|
sb.append(key);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
return ApiEntity.getResponseBody(apiEntity);
|
/**
|
||||||
|
* 遍历JSON对象
|
||||||
|
*
|
||||||
|
* @param parentJson
|
||||||
|
* @param parentKey
|
||||||
|
* @param currentFloor
|
||||||
|
* @param floors
|
||||||
|
*/
|
||||||
|
public static void processFloor(JSONObject parentJson, String parentKey, List<DynamicObject> currentFloor, List<List<DynamicObject>> floors) {
|
||||||
|
if (currentFloor.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentFloor.size() == 1 && "object".equals(currentFloor.get(0).getString("shkd_tartype"))) {
|
||||||
|
parentJson.put(parentKey, new JSONObject());
|
||||||
|
processFloor(parentJson.getJSONObject(parentKey), parentKey, getChildren(floors, currentFloor.get(0).getString("shkd_tarfield")), floors);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("arrayList".equals(currentFloor.get(0).getString("shkd_tartype"))) {
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
//目前JSONArray都是一层
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
for (DynamicObject dynamicObject : currentFloor) {
|
||||||
|
String key = dynamicObject.getString("shkd_tarfield");
|
||||||
|
Object value = dynamicObject.get("shkd_defaultdata");
|
||||||
|
String tartype = dynamicObject.getString("shkd_tartype");
|
||||||
|
|
||||||
|
if ("string".equals(tartype) || "date".equals(tartype)) {
|
||||||
|
json.put(key, value);
|
||||||
|
} else if ("int".equals(tartype)) {
|
||||||
|
json.put(key, Integer.parseInt(value.toString()));
|
||||||
|
} else if ("object".equals(tartype)) {
|
||||||
|
JSONObject childJson = new JSONObject();
|
||||||
|
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors);
|
||||||
|
json.put(key, childJson);
|
||||||
|
} else if ("arrayList".equals(tartype)) {
|
||||||
|
JSONArray childJsonArray = new JSONArray();
|
||||||
|
for (DynamicObject childDynamicObject : getChildren(floors, dynamicObject.getString("shkd_tarfield"))) {
|
||||||
|
JSONObject childJson = new JSONObject();
|
||||||
|
processFloor(childJson, key, Collections.singletonList(childDynamicObject), floors);
|
||||||
|
childJsonArray.add(childJson);
|
||||||
|
}
|
||||||
|
json.put(key, childJsonArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsonArray.add(json);
|
||||||
|
parentJson.put(parentKey, jsonArray);
|
||||||
|
} else {
|
||||||
|
for (DynamicObject dynamicObject : currentFloor) {
|
||||||
|
String key = dynamicObject.getString("shkd_tarfield");
|
||||||
|
Object value = dynamicObject.get("shkd_defaultdata");
|
||||||
|
String tartype = dynamicObject.getString("shkd_tartype");
|
||||||
|
|
||||||
|
if ("string".equals(tartype) || "date".equals(tartype)) {
|
||||||
|
parentJson.put(key, value);
|
||||||
|
} else if ("int".equals(tartype)) {
|
||||||
|
parentJson.put(key, Integer.parseInt(value.toString()));
|
||||||
|
} else if ("object".equals(tartype)) {
|
||||||
|
JSONObject childJson = new JSONObject();
|
||||||
|
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors);
|
||||||
|
parentJson.put(key, childJson);
|
||||||
|
} else if ("arrayList".equals(tartype)) {
|
||||||
|
JSONArray childJsonArray = new JSONArray();
|
||||||
|
JSONObject childJson = new JSONObject();
|
||||||
|
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors);
|
||||||
|
childJsonArray.add(childJson);
|
||||||
|
parentJson.put(key, childJsonArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子节点
|
||||||
|
*
|
||||||
|
* @param floors
|
||||||
|
* @param parentKey
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<DynamicObject> getChildren(List<List<DynamicObject>> floors, String parentKey) {
|
||||||
|
List<DynamicObject> children = new ArrayList<>();
|
||||||
|
for (List<DynamicObject> floor : floors) {
|
||||||
|
for (DynamicObject dynamicObject : floor) {
|
||||||
|
if (parentKey.equals(dynamicObject.getString("shkd_parentfield"))) {
|
||||||
|
children.add(dynamicObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return children;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue