Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
fang 2024-11-27 09:29:24 +08:00
commit 86d3eee8a9
2 changed files with 172 additions and 38 deletions

View File

@ -141,7 +141,7 @@ public class ApiService {
/**
* 组装推送BIP付款单JSON
*
* @param dynamic 某个单据的 某条需要推送的数据
* @param dynamic 某个单据的 某条需要推送的数据 映射字段必须包含在其中缺失字段会报错
* @param systemName 推送系统名称
* @return
*/
@ -180,7 +180,7 @@ public class ApiService {
floors.get(tier - 1).add(dynamicObject);
}
JSONObject resultJson = new JSONObject();
processFloor(resultJson, "data", floors.get(0), floors);
processFloor(resultJson, "data", floors.get(0), floors, dynamic);
logger.info("调用接口系统:{}\n调用接口单据{}\n调用JSON{}", systemName, dynamic, resultJson);
return resultJson;
}
@ -224,8 +224,8 @@ public class ApiService {
public static String buildPath(List<String> path, String key, String level) {
StringBuilder sb = new StringBuilder();
sb.append("层级 ").append(level).append(": ");
for (int i = 0; i < path.size(); i++) {
sb.append(path.get(i)).append(".");
for (String s : path) {
sb.append(s).append(".");
}
sb.append(key);
return sb.toString();
@ -239,14 +239,14 @@ public class ApiService {
* @param currentFloor
* @param floors
*/
public static void processFloor(JSONObject parentJson, String parentKey, List<DynamicObject> currentFloor, List<List<DynamicObject>> floors) {
public static void processFloor(JSONObject parentJson, String parentKey, List<DynamicObject> currentFloor, List<List<DynamicObject>> floors, DynamicObject dynamic) {
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);
processFloor(parentJson.getJSONObject(parentKey), parentKey, getChildren(floors, currentFloor.get(0).getString("shkd_tarfield")), floors, dynamic);
return;
}
@ -256,7 +256,31 @@ public class ApiService {
JSONObject json = new JSONObject();
for (DynamicObject dynamicObject : currentFloor) {
String key = dynamicObject.getString("shkd_tarfield");
Object value = dynamicObject.get("shkd_defaultdata");
Object shkd_soufield = dynamicObject.get("shkd_soufield");
Object value = null;
if (shkd_soufield != null) {
String[] parts = shkd_soufield.toString().split("\\.");
if (parts.length == 1) {
value = dynamic.get(parts[0]);
} else if (parts.length == 2) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection = dynamic.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection.get(0).get(parts[1]);
} else {
value = dynamic.getDynamicObject(parts[0]).get(parts[1]);
}
} else if (parts.length == 3) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection = dynamic.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection.get(0).getDynamicObject(parts[1]).get(parts[2]);
} else {
value = dynamic.getDynamicObject(parts[0]).getDynamicObject(parts[1]).get(parts[2]);
}
}
} else {
value = dynamicObject.get("shkd_defaultdata");
}
String tartype = dynamicObject.getString("shkd_tartype");
if ("string".equals(tartype) || "date".equals(tartype)) {
@ -265,13 +289,13 @@ public class ApiService {
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);
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, dynamic);
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);
processFloor(childJson, key, Collections.singletonList(childDynamicObject), floors, dynamic);
childJsonArray.add(childJson);
}
json.put(key, childJsonArray);
@ -282,7 +306,30 @@ public class ApiService {
} else {
for (DynamicObject dynamicObject : currentFloor) {
String key = dynamicObject.getString("shkd_tarfield");
Object value = dynamicObject.get("shkd_defaultdata");
Object shkd_soufield = dynamicObject.get("shkd_soufield");
Object value = null;
if (shkd_soufield != null) {
String[] parts = shkd_soufield.toString().split("\\.");
if (parts.length == 1) {
value = dynamic.get(parts[0]);
} else if (parts.length == 2) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection = dynamic.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection.get(0).get(parts[1]);
} else {
value = dynamic.getDynamicObject(parts[0]).get(parts[1]);
}
} else if (parts.length == 3) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection = dynamic.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection.get(0).getDynamicObject(parts[1]).get(parts[2]);
} else {
value = dynamic.getDynamicObject(parts[0]).getDynamicObject(parts[1]).get(parts[2]);
}
}
} else {
value = dynamicObject.get("shkd_defaultdata");
}
String tartype = dynamicObject.getString("shkd_tartype");
if ("string".equals(tartype) || "date".equals(tartype)) {
@ -291,12 +338,12 @@ public class ApiService {
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);
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, dynamic);
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);
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, dynamic);
childJsonArray.add(childJson);
parentJson.put(key, childJsonArray);
}
@ -322,4 +369,6 @@ public class ApiService {
}
return children;
}
}

View File

@ -1,5 +1,7 @@
package shkd.sys.sys.plugin.form;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@ -10,6 +12,9 @@ import kd.bos.form.control.CodeEdit;
import kd.bos.form.control.Toolbar;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import shkd.sys.sys.common.ApiEntity;
import shkd.sys.sys.mservice.ApiService;
@ -21,6 +26,8 @@ import java.util.*;
* 动态表单插件
*/
public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
private static final Log logger = LogFactory.getLog(ApiMappingBillPlugin.class);
@Override
public void registerListener(EventObject e) {
Toolbar tbmain = this.getView().getControl("tbmain");
@ -41,6 +48,14 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
// 获取代码编辑器控件
CodeEdit codeEdit = this.getView().getControl("shkd_codeeditap");
if ("shkd_generatejson".equals(itemKey)) {
// 获取想要推送单据编码
String billNumber = dataEntity.getString("shkd_sourcenumber");
// 获取想要推送单据类型
String billMark = dataEntity.getDynamicObject("shkd_sourcebill").getDataEntityType().getName();
// 获取推送单据对象
DynamicObject billObject = BusinessDataServiceHelper.loadSingle(billMark, new QFilter("billno", QCP.equals, billNumber).toArray());
logger.info("获取推送对象 → billObject{}", billObject);
// 生成JSON
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("entryentity");
@ -71,7 +86,34 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
JSONObject json = new JSONObject();
for (DynamicObject dynamicObject : dynamicObjectCollection) {
String key = dynamicObject.getString("shkd_tarfield");
Object value = dynamicObject.get("shkd_defaultdata");
// 将映射字段塞入对应JSON中
Object shkd_soufield = dynamicObject.get("shkd_soufield");
Object value = null;
if (shkd_soufield != null) {
String[] parts = shkd_soufield.toString().split("\\.");
if (parts.length == 1) {
value = billObject.get(parts[0]);
} else if (parts.length == 2) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection1 = billObject.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection1.get(0).get(parts[1]);
} else {
value = billObject.getDynamicObject(parts[0]).get(parts[1]);
}
} else if (parts.length == 3) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection1 = billObject.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection1.get(0).getDynamicObject(parts[1]).get(parts[2]);
} else {
value = billObject.getDynamicObject(parts[0]).getDynamicObject(parts[1]).get(parts[2]);
}
}
} else {
value = dynamicObject.get("shkd_defaultdata");
}
String tartype = dynamicObject.getString("shkd_tartype");
if ("String".equals(tartype) || "Date".equals(tartype)) {
@ -82,13 +124,13 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
json.put(key, new BigDecimal(value.toString()));
} else if ("对象".equals(tartype)) {
JSONObject childJson = new JSONObject();
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors);
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, billObject);
json.put(key, childJson);
} else if ("数组".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);
processFloor(childJson, key, Collections.singletonList(childDynamicObject), floors, billObject);
childJsonArray.add(childJson);
}
json.put(key, childJsonArray);
@ -98,7 +140,7 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
codeEdit.setText(jsonArray.toJSONString());
} else {
JSONObject resultJson = new JSONObject();
processFloor(resultJson, "data", floors.get(0), floors);
processFloor(resultJson, "data", floors.get(0), floors, billObject);
codeEdit.setText(resultJson.toJSONString());
}
}
@ -132,41 +174,63 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
}
}
private void processFloor(JSONObject parentJson, String parentKey, List<DynamicObject> currentFloor, List<List<DynamicObject>> floors) {
private void processFloor(JSONObject parentJson, String parentKey, List<DynamicObject> currentFloor, List<List<DynamicObject>> floors, DynamicObject dynamic) {
if (currentFloor.isEmpty()) {
return;
}
if (currentFloor.size() == 1 && "对象".equals(currentFloor.get(0).getString("shkd_tartype"))) {
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);
processFloor(parentJson.getJSONObject(parentKey), parentKey, getChildren(floors, currentFloor.get(0).getString("shkd_tarfield")), floors, dynamic);
return;
}
if ("数组".equals(currentFloor.get(0).getString("shkd_tartype"))) {
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");
Object shkd_soufield = dynamicObject.get("shkd_soufield");
Object value = null;
if (shkd_soufield != null) {
String[] parts = shkd_soufield.toString().split("\\.");
if (parts.length == 1) {
value = dynamic.get(parts[0]);
} else if (parts.length == 2) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection = dynamic.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection.get(0).get(parts[1]);
} else {
value = dynamic.getDynamicObject(parts[0]).get(parts[1]);
}
} else if (parts.length == 3) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection = dynamic.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection.get(0).getDynamicObject(parts[1]).get(parts[2]);
} else {
value = dynamic.getDynamicObject(parts[0]).getDynamicObject(parts[1]).get(parts[2]);
}
}
} else {
value = dynamicObject.get("shkd_defaultdata");
}
String tartype = dynamicObject.getString("shkd_tartype");
if ("String".equals(tartype) || "Date".equals(tartype)) {
if ("string".equals(tartype) || "date".equals(tartype)) {
json.put(key, value);
} else if ("Integer".equals(tartype)) {
} else if ("int".equals(tartype)) {
json.put(key, Integer.parseInt(value.toString()));
} else if ("BigDecimal".equals(tartype)) {
json.put(key, new BigDecimal(value.toString()));
} else if ("对象".equals(tartype)) {
} else if ("object".equals(tartype)) {
JSONObject childJson = new JSONObject();
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors);
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, dynamic);
json.put(key, childJson);
} else if ("数组".equals(tartype)) {
} 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);
processFloor(childJson, key, Collections.singletonList(childDynamicObject), floors, dynamic);
childJsonArray.add(childJson);
}
json.put(key, childJsonArray);
@ -177,23 +241,44 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
} else {
for (DynamicObject dynamicObject : currentFloor) {
String key = dynamicObject.getString("shkd_tarfield");
Object value = dynamicObject.get("shkd_defaultdata");
Object shkd_soufield = dynamicObject.get("shkd_soufield");
Object value = null;
if (shkd_soufield != null) {
String[] parts = shkd_soufield.toString().split("\\.");
if (parts.length == 1) {
value = dynamic.get(parts[0]);
} else if (parts.length == 2) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection = dynamic.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection.get(0).get(parts[1]);
} else {
value = dynamic.getDynamicObject(parts[0]).get(parts[1]);
}
} else if (parts.length == 3) {
if ("entry".equals(parts[0])) {
DynamicObjectCollection dynamicObjectCollection = dynamic.getDynamicObjectCollection(parts[0]);
value = dynamicObjectCollection.get(0).getDynamicObject(parts[1]).get(parts[2]);
} else {
value = dynamic.getDynamicObject(parts[0]).getDynamicObject(parts[1]).get(parts[2]);
}
}
} else {
value = dynamicObject.get("shkd_defaultdata");
}
String tartype = dynamicObject.getString("shkd_tartype");
if ("String".equals(tartype) || "Date".equals(tartype)) {
if ("string".equals(tartype) || "date".equals(tartype)) {
parentJson.put(key, value);
} else if ("Integer".equals(tartype)) {
} else if ("int".equals(tartype)) {
parentJson.put(key, Integer.parseInt(value.toString()));
} else if ("BigDecimal".equals(tartype)) {
parentJson.put(key, new BigDecimal(value.toString()));
} else if ("对象".equals(tartype)) {
} else if ("object".equals(tartype)) {
JSONObject childJson = new JSONObject();
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors);
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, dynamic);
parentJson.put(key, childJson);
} else if ("数组".equals(tartype)) {
} else if ("arrayList".equals(tartype)) {
JSONArray childJsonArray = new JSONArray();
JSONObject childJson = new JSONObject();
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors);
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, dynamic);
childJsonArray.add(childJson);
parentJson.put(key, childJsonArray);
}