parent
395a62cf90
commit
a2507e8a6d
|
@ -118,113 +118,7 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
JSONArray jsonArray = new JSONArray();
|
||||
JSONObject json = new JSONObject();
|
||||
for (DynamicObject dynamicObject : dynamicObjectCollection) {
|
||||
String key = dynamicObject.getString("shkd_tarfield");
|
||||
|
||||
// 将映射字段塞入对应JSON中
|
||||
Object shkd_soufield = dynamicObject.get("shkd_soufield");
|
||||
logger.info("shkd_soufield: {}", shkd_soufield);
|
||||
Object value = null;
|
||||
if (shkd_soufield != null && !"".equals(shkd_soufield)) {
|
||||
String[] parts = shkd_soufield.toString().split("\\.");
|
||||
logger.info("billObject:{}\nparts: {}", billObject, Arrays.toString(parts));
|
||||
if (parts.length == 1) {
|
||||
if ("payeetype".equals(parts[0]) || "payertype".equals(parts[0])) {
|
||||
String objectType = billObject.getString(parts[0]);
|
||||
switch (objectType) {
|
||||
case "bos_org":
|
||||
value = "4";
|
||||
break;
|
||||
case "bd_supplier":
|
||||
value = "2";
|
||||
break;
|
||||
case "bd_customer":
|
||||
value = "1";
|
||||
break;
|
||||
case "bos_user":
|
||||
value = "3";
|
||||
break;
|
||||
case "other":
|
||||
value = "4";
|
||||
break;
|
||||
}
|
||||
} else if ("debitamount".equals(parts[0])) {
|
||||
// 付款金额
|
||||
BigDecimal debitamount = billObject.getBigDecimal("debitamount");
|
||||
// 收款金额
|
||||
BigDecimal creditamount = billObject.getBigDecimal("creditamount");
|
||||
if (debitamount.compareTo(BigDecimal.ZERO) != 0) {
|
||||
value = billObject.get("debitamount");
|
||||
} else {
|
||||
value = billObject.get("creditamount");
|
||||
}
|
||||
} else if ("direction".equals(parts[0])) {
|
||||
// 付款金额
|
||||
BigDecimal debitamount = billObject.getBigDecimal("debitamount");
|
||||
// 收款金额
|
||||
BigDecimal creditamount = billObject.getBigDecimal("creditamount");
|
||||
if (debitamount.compareTo(BigDecimal.ZERO) != 0) {
|
||||
value = "1";//支出
|
||||
} else {
|
||||
value = "2";//收入
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
DynamicObject object = billObject.getDynamicObject(parts[0]);
|
||||
if (object != null) {
|
||||
value = object.get(parts[1]);
|
||||
}
|
||||
}
|
||||
} else if (parts.length == 3) {
|
||||
if ("entry".equals(parts[0])) {
|
||||
DynamicObjectCollection dynamicObjectCollection1 = billObject.getDynamicObjectCollection(parts[0]);
|
||||
DynamicObject object = dynamicObjectCollection1.get(0).getDynamicObject(parts[1]);
|
||||
if (object != null) {
|
||||
value = object.get(parts[2]);
|
||||
}
|
||||
} else {
|
||||
DynamicObject object = billObject.getDynamicObject(parts[0]);
|
||||
if (object != null) {
|
||||
DynamicObject object1 = object.getDynamicObject(parts[1]);
|
||||
if (object1 != null) {
|
||||
value = object1.get(parts[2]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
value = dynamicObject.get("shkd_defaultdata");
|
||||
}
|
||||
|
||||
|
||||
String tartype = dynamicObject.getString("shkd_tartype");
|
||||
|
||||
if ("String".equals(tartype) || "Date".equals(tartype)) {
|
||||
json.put(key, value);
|
||||
} else if ("Integer".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)) {
|
||||
JSONObject childJson = new JSONObject();
|
||||
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, billObject);
|
||||
childJsonArray.add(childJson);
|
||||
}
|
||||
json.put(key, childJsonArray);
|
||||
}
|
||||
valueAssignment(dynamicObject, billObject, json, floors);
|
||||
}
|
||||
jsonArray.add(json);
|
||||
codeEdit.setText(format(jsonArray.toJSONString()));
|
||||
|
@ -291,7 +185,7 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
//目前JSONArray都是一层
|
||||
JSONObject json = new JSONObject();
|
||||
for (DynamicObject dynamicObject : currentFloor) {
|
||||
String key = dynamicObject.getString("shkd_tarfield");
|
||||
/*String key = dynamicObject.getString("shkd_tarfield");
|
||||
Object shkd_soufield = dynamicObject.get("shkd_soufield");
|
||||
logger.info("shkd_soufield: {}", shkd_soufield);
|
||||
Object value = null;
|
||||
|
@ -392,14 +286,15 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
childJsonArray.add(childJson);
|
||||
}
|
||||
json.put(key, childJsonArray);
|
||||
}
|
||||
}*/
|
||||
valueAssignment(dynamicObject, dynamic, json, floors);
|
||||
}
|
||||
jsonArray.add(json);
|
||||
parentJson.put(parentKey, jsonArray);
|
||||
} else {
|
||||
logger.info("进入对象");
|
||||
for (DynamicObject dynamicObject : currentFloor) {
|
||||
String key = dynamicObject.getString("shkd_tarfield");
|
||||
/*String key = dynamicObject.getString("shkd_tarfield");
|
||||
Object shkd_soufield = dynamicObject.get("shkd_soufield");
|
||||
logger.info("shkd_soufield: {}", shkd_soufield);
|
||||
Object value = null;
|
||||
|
@ -498,7 +393,8 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, dynamic);
|
||||
childJsonArray.add(childJson);
|
||||
parentJson.put(key, childJsonArray);
|
||||
}
|
||||
}*/
|
||||
valueAssignment(dynamicObject, dynamic, parentJson, floors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -548,6 +444,130 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
this.getModel().setValue("shkd_parentfield", pKey, dynamicObjectCollection.size() - 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给value赋值
|
||||
* @param dynamicObject 映射分录的单行数据
|
||||
* @param billObject 源单数据
|
||||
* @param jsonObject JSON对象
|
||||
* @param floors 层集合
|
||||
*/
|
||||
private void valueAssignment(DynamicObject dynamicObject, DynamicObject billObject, JSONObject jsonObject, List<List<DynamicObject>> floors) {
|
||||
|
||||
String key = dynamicObject.getString("shkd_tarfield");
|
||||
Object value = null;
|
||||
// 将映射字段塞入对应JSON中
|
||||
Object shkd_soufield = dynamicObject.get("shkd_soufield");
|
||||
logger.info("shkd_soufield: {}", shkd_soufield);
|
||||
if (shkd_soufield != null && !"".equals(shkd_soufield)) {
|
||||
String[] parts = shkd_soufield.toString().split("\\.");
|
||||
logger.info("billObject:{}\nparts: {}", billObject, Arrays.toString(parts));
|
||||
if (parts.length == 1) {
|
||||
if ("payeetype".equals(parts[0]) || "payertype".equals(parts[0])) {
|
||||
String objectType = billObject.getString(parts[0]);
|
||||
switch (objectType) {
|
||||
case "bos_org":
|
||||
value = "4";
|
||||
break;
|
||||
case "bd_supplier":
|
||||
value = "2";
|
||||
break;
|
||||
case "bd_customer":
|
||||
value = "1";
|
||||
break;
|
||||
case "bos_user":
|
||||
value = "3";
|
||||
break;
|
||||
case "other":
|
||||
value = "4";
|
||||
break;
|
||||
}
|
||||
} else if ("debitamount".equals(parts[0])) {
|
||||
// 付款金额
|
||||
BigDecimal debitamount = billObject.getBigDecimal("debitamount");
|
||||
// 收款金额
|
||||
BigDecimal creditamount = billObject.getBigDecimal("creditamount");
|
||||
if (debitamount.compareTo(BigDecimal.ZERO) != 0) {
|
||||
value = billObject.get("debitamount");
|
||||
} else {
|
||||
value = billObject.get("creditamount");
|
||||
}
|
||||
} else if ("direction".equals(parts[0])) {
|
||||
// 付款金额
|
||||
BigDecimal debitamount = billObject.getBigDecimal("debitamount");
|
||||
// 收款金额
|
||||
BigDecimal creditamount = billObject.getBigDecimal("creditamount");
|
||||
if (debitamount.compareTo(BigDecimal.ZERO) != 0) {
|
||||
value = "1";//支出
|
||||
} else {
|
||||
value = "2";//收入
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
DynamicObject object = billObject.getDynamicObject(parts[0]);
|
||||
if (object != null) {
|
||||
value = object.get(parts[1]);
|
||||
}
|
||||
}
|
||||
} else if (parts.length == 3) {
|
||||
if ("entry".equals(parts[0])) {
|
||||
DynamicObjectCollection dynamicObjectCollection1 = billObject.getDynamicObjectCollection(parts[0]);
|
||||
DynamicObject object = dynamicObjectCollection1.get(0).getDynamicObject(parts[1]);
|
||||
if (object != null) {
|
||||
value = object.get(parts[2]);
|
||||
}
|
||||
} else {
|
||||
DynamicObject object = billObject.getDynamicObject(parts[0]);
|
||||
if (object != null) {
|
||||
DynamicObject object1 = object.getDynamicObject(parts[1]);
|
||||
if (object1 != null) {
|
||||
value = object1.get(parts[2]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
value = dynamicObject.get("shkd_defaultdata");
|
||||
}
|
||||
|
||||
|
||||
String tartype = dynamicObject.getString("shkd_tartype");
|
||||
|
||||
if ("String".equals(tartype) || "Date".equals(tartype)) {
|
||||
jsonObject.put(key, value);
|
||||
} else if ("Integer".equals(tartype)) {
|
||||
jsonObject.put(key, Integer.parseInt(value.toString()));
|
||||
} else if ("BigDecimal".equals(tartype)) {
|
||||
jsonObject.put(key, new BigDecimal(value.toString()));
|
||||
} else if ("对象".equals(tartype)) {
|
||||
JSONObject childJson = new JSONObject();
|
||||
processFloor(childJson, key, getChildren(floors, dynamicObject.getString("shkd_tarfield")), floors, billObject);
|
||||
jsonObject.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, billObject);
|
||||
childJsonArray.add(childJson);
|
||||
}
|
||||
jsonObject.put(key, childJsonArray);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化JSON字符串
|
||||
*
|
||||
* @param jsonString 需要格式化的JSON字符串
|
||||
* @return 已经添加好缩进和换行的JSON字符串
|
||||
*/
|
||||
public String format(String jsonString) {
|
||||
StringBuilder prettyJson = new StringBuilder();
|
||||
char[] chars = jsonString.toCharArray();
|
||||
|
@ -583,6 +603,12 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
|
|||
return prettyJson.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化JSON字符串 -> 添加缩进
|
||||
*
|
||||
* @param sb
|
||||
* @param indentLevel
|
||||
*/
|
||||
private void addIndent(StringBuilder sb, int indentLevel) {
|
||||
for (int i = 0; i < indentLevel; i++) {
|
||||
sb.append(" "); // 使用4个空格作为缩进
|
||||
|
|
Loading…
Reference in New Issue