|
|
@@ -1,5 +1,7 @@
|
|
|
package com.malk.huagao.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.malk.huagao.entity.*;
|
|
|
@@ -14,6 +16,7 @@ import com.malk.server.aliwork.YDParam;
|
|
|
import com.malk.server.dingtalk.DDR_New;
|
|
|
import com.malk.service.aliwork.YDClient;
|
|
|
import com.malk.utils.UtilMap;
|
|
|
+import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
import org.slf4j.MDC;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -23,8 +26,7 @@ import java.math.RoundingMode;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -177,6 +179,134 @@ public class KdYdDeliveryServiceImpl extends ServiceImpl<KdYdDeliveryMapper, KdY
|
|
|
// .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mgrqnxmm", id)))
|
|
|
// .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void CfkdYdDelivery(Map map) {
|
|
|
+ MDC.put("MDC_KEY_PID", "1003");
|
|
|
+ String formInstId = UtilMap.getString(map, "formInstId");
|
|
|
+
|
|
|
+ // 查询原表单数据
|
|
|
+ DDR_New ddrNew = ydClient.queryData(
|
|
|
+ YDParam.builder().formInstId(formInstId).build(),
|
|
|
+ YDConf.FORM_QUERY.retrieve_id
|
|
|
+ );
|
|
|
+ Map formData1 = ddrNew.getFormData();
|
|
|
+
|
|
|
+ // 提取需要特殊处理的主表字段
|
|
|
+ String glbdjson = String.valueOf(formData1.get("associationFormField_mejmml36_id"));
|
|
|
+ String sqr = String.valueOf(formData1.get("employeeField_krbgloal_id"));
|
|
|
+ String xsy = String.valueOf(formData1.get("employeeField_mejnamf3_id"));
|
|
|
+ String fhtzd = String.valueOf(formData1.get("serialNumberField_mheazm7w"));
|
|
|
+
|
|
|
+ // 解析关联字段 JSON
|
|
|
+ List<Map> sealjsonlist = parseJsonList(glbdjson);
|
|
|
+
|
|
|
+
|
|
|
+ // 获取原表单的子表数据
|
|
|
+ List<Map> tableField = UtilMap.getList(formData1, "tableField_mejnamfd");
|
|
|
+ if (tableField == null || tableField.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按 dz 分组
|
|
|
+ Map<String, List<Map>> groupedByDz = new LinkedHashMap<>();
|
|
|
+ for (Map item : tableField) {
|
|
|
+ String dz = UtilMap.getString(item, "textareaField_mf6a0h5e");
|
|
|
+ if (dz == null) dz = "";
|
|
|
+ groupedByDz.computeIfAbsent(dz, k -> new ArrayList<>()).add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 对每个 dz 分组,创建一条新表单
|
|
|
+ for (Map.Entry<String, List<Map>> entry : groupedByDz.entrySet()) {
|
|
|
+ String dz = entry.getKey();
|
|
|
+ List<Map> subTableRows = entry.getValue();
|
|
|
+
|
|
|
+ // 构建新子表数据
|
|
|
+ List<Map> newSubTable = new ArrayList<>();
|
|
|
+ for (Map row : subTableRows) {
|
|
|
+ newSubTable.add(new HashMap<>(row));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建新表单的formData
|
|
|
+ HashMap<String, Object> updateMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 1. 首先复制原表单的所有主表数据
|
|
|
+ for (Object obj : formData1.entrySet()) {
|
|
|
+ Map.Entry<String, Object> formEntry = (Map.Entry<String, Object>) obj;
|
|
|
+ String key = formEntry.getKey();
|
|
|
+ Object value = formEntry.getValue();
|
|
|
+
|
|
|
+ // 跳过不需要特殊处理的子表字段
|
|
|
+ if ("tableField_mejnamfd".equals(key)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 跳过需要特殊处理的主表关联字段
|
|
|
+ if (key.equals("associationFormField_mejmml36_id") ||
|
|
|
+ key.equals("associationFormField_mfavc4ve_id") ||
|
|
|
+ key.equals("associationFormField_mk0gzflu_id") ||
|
|
|
+ key.equals("employeeField_krbgloal_id") ||
|
|
|
+ key.equals("employeeField_mejnamf3_id") ||
|
|
|
+ key.equals("serialNumberField_mheazm7w")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 复制其他字段
|
|
|
+ updateMap.put(key, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 添加需要特殊处理的主表字段
|
|
|
+ updateMap.put("associationFormField_mejmml36", sealjsonlist);
|
|
|
+// updateMap.put("associationFormField_mfavc4ve", khjsonlist);
|
|
|
+ updateMap.put("associationFormField_mk0gzflu", Arrays.asList(getfhdAss(fhtzd,formInstId)));
|
|
|
+ updateMap.put("employeeField_krbgloal", sqr);
|
|
|
+ updateMap.put("employeeField_mejnamf3", xsy);
|
|
|
+ updateMap.put("textField_mjzk47so", fhtzd);
|
|
|
+
|
|
|
+ // 3. 添加处理后的子表数据
|
|
|
+ updateMap.put("tableField_mejnamfd", newSubTable);
|
|
|
+ String sqrid = sqr.substring(2, sqr.length() - 2);
|
|
|
+ System.out.println("sqrid=="+sqrid);
|
|
|
+ // 创建新表单实例
|
|
|
+ try {
|
|
|
+ ydClient.operateData(
|
|
|
+ YDParam.builder()
|
|
|
+ .formUuid("FORM-FAE2575E112644ED914CAB4FEC9309F32AVR")
|
|
|
+ .formDataJson(JSON.toJSONString(updateMap))
|
|
|
+ .userId(sqrid)
|
|
|
+ .build(),
|
|
|
+ YDConf.FORM_OPERATION.create
|
|
|
+ );
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("创建新单据失败,dz=" + dz, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 工具方法:安全解析 JSON 列表(处理宜搭返回的带引号字符串)
|
|
|
+ private List<Map> parseJsonList(String jsonStr) {
|
|
|
+ if (jsonStr == null || "null".equals(jsonStr) || jsonStr.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 宜搭有时返回的是 "\"[{...}]\"",需先 unescape
|
|
|
+ String clean = StringEscapeUtils.unescapeJava(jsonStr);
|
|
|
+ // 如果首尾是双引号,去掉
|
|
|
+ if (clean.startsWith("\"") && clean.endsWith("\"")) {
|
|
|
+ clean = clean.substring(1, clean.length() - 1);
|
|
|
+ }
|
|
|
+ return (List<Map>) JSONArray.parse(clean);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object getfhdAss(String title, String id) {
|
|
|
+ return UtilMap.map("appType, formUuid, formType, instanceId, title, subTitle", "APP_VQDMMWS6OR1VHL8VMFD3", "FORM-A7F03ACEE01D4F609550C86BF7FE87D35M6I", "receipt", id, title, "");
|
|
|
+ }
|
|
|
+
|
|
|
private static LocalDateTime parseTimestamp(String timestampStr) {
|
|
|
if (timestampStr == null || timestampStr.trim().isEmpty()) return null;
|
|
|
try {
|