From a14c7776e8233a631867806e302719d2de9fd709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E8=BE=89?= <2830717623@qq.com> Date: Tue, 23 Jun 2026 14:00:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E7=94=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserShipperApplicationService.java | 104 +++++++++++++----- 1 file changed, 78 insertions(+), 26 deletions(-) diff --git a/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java b/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java index 841504787..dcbc8abb5 100644 --- a/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java +++ b/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java @@ -1665,19 +1665,19 @@ public class UserShipperApplicationService { // 根据查询结果同步数据 com.alibaba.fastjson.JSONObject dataJson = resultJson.getJSONObject("data"); if (dataJson != null) { + // 解析现有的orgCode数组 + com.alibaba.fastjson.JSONArray orgCodeArray = new com.alibaba.fastjson.JSONArray(); + if (StringUtils.isNotEmpty(userShipperEntity1.getOrgCode())) { + try { + orgCodeArray = com.alibaba.fastjson.JSONArray.parseArray(userShipperEntity1.getOrgCode()); + } catch (Exception e) { + log.warn("解析现有orgCode失败,将创建新的数组,shipperId={}", userShipperEntity1.getShipperId()); + } + } + // 同步额度数据(limitdatas) com.alibaba.fastjson.JSONArray limitdatas = dataJson.getJSONArray("limitdatas"); if (limitdatas != null && !limitdatas.isEmpty()) { - // 解析现有的orgCode数组 - com.alibaba.fastjson.JSONArray orgCodeArray = new com.alibaba.fastjson.JSONArray(); - if (StringUtils.isNotEmpty(userShipperEntity1.getOrgCode())) { - try { - orgCodeArray = com.alibaba.fastjson.JSONArray.parseArray(userShipperEntity1.getOrgCode()); - } catch (Exception e) { - log.warn("解析现有orgCode失败,将创建新的数组,shipperId={}", userShipperEntity1.getShipperId()); - } - } - // 将limitdatas按orgcode值合并到orgCode数组中 for (int i = 0; i < limitdatas.size(); i++) { com.alibaba.fastjson.JSONObject limitItem = limitdatas.getJSONObject(i); @@ -1711,9 +1711,6 @@ public class UserShipperApplicationService { } } - // 保存更新后的orgCode数组 - userShipperEntity1.setOrgCode(orgCodeArray.toJSONString()); - // 使用limitdatas中的数据更新额度字段 com.alibaba.fastjson.JSONObject firstLimitData = limitdatas.getJSONObject(0); userShipperEntity1.setLimitTime(new Date()); @@ -1737,6 +1734,32 @@ public class UserShipperApplicationService { log.info("第一次循环,删除货主所有协议明细,shipperId={}", userShipperEntity1.getShipperId()); } + // 将agreedaydatas保存到orgCode数组中,与code同一级别 + String currentOrgCodeStr = String.valueOf(orgCode); + boolean foundOrg = false; + for (int j = 0; j < orgCodeArray.size(); j++) { + com.alibaba.fastjson.JSONObject orgItem = orgCodeArray.getJSONObject(j); + String orgItemCode = orgItem.getString("code"); + + // 找到当前组织,将agreedaydatas添加到该组织对象中 + if (currentOrgCodeStr.equals(orgItemCode)) { + orgItem.put("agreedaydatas", agreedaydatas); + foundOrg = true; + log.info("将agreedaydatas添加到code={}的组织中,共{}条", orgItemCode, agreedaydatas.size()); + break; + } + } + + // 如果没找到,创建新组织对象 + if (!foundOrg) { + com.alibaba.fastjson.JSONObject newOrgItem = new com.alibaba.fastjson.JSONObject(); + newOrgItem.put("code", orgCode); + newOrgItem.put("agreedaydatas", agreedaydatas); + orgCodeArray.add(newOrgItem); + log.info("创建新组织并添加agreedaydatas,code={},共{}条", orgCode, agreedaydatas.size()); + } + + // 同时插入到agreement_details表 for (int i = 0; i < agreedaydatas.size(); i++) { com.alibaba.fastjson.JSONObject agreeItem = agreedaydatas.getJSONObject(i); AgreementDetails agreementDetails = new AgreementDetails(); @@ -1754,6 +1777,9 @@ public class UserShipperApplicationService { } else { log.info("赊销额度查询无agreedaydatas返回,跳过协议明细同步,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode); } + + // 保存更新后的orgCode数组(统一在最后保存) + userShipperEntity1.setOrgCode(orgCodeArray.toJSONString()); } else { log.info("赊销额度查询无data返回,跳过更新,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode); } @@ -1905,19 +1931,19 @@ public class UserShipperApplicationService { // 根据查询结果同步数据 com.alibaba.fastjson.JSONObject dataJson = resultJson.getJSONObject("data"); if (dataJson != null) { + // 解析现有的orgCode数组(提到外面,limitdatas和agreedaydatas共用) + com.alibaba.fastjson.JSONArray orgCodeArray = new com.alibaba.fastjson.JSONArray(); + if (StringUtils.isNotEmpty(userShipperEntity1.getOrgCode())) { + try { + orgCodeArray = com.alibaba.fastjson.JSONArray.parseArray(userShipperEntity1.getOrgCode()); + } catch (Exception e) { + log.warn("解析现有orgCode失败,将创建新的数组,shipperId={}", userShipperEntity1.getShipperId()); + } + } + // 同步额度数据(limitdatas) com.alibaba.fastjson.JSONArray limitdatas = dataJson.getJSONArray("limitdatas"); if (limitdatas != null && !limitdatas.isEmpty()) { - // 解析现有的orgCode数组 - com.alibaba.fastjson.JSONArray orgCodeArray = new com.alibaba.fastjson.JSONArray(); - if (StringUtils.isNotEmpty(userShipperEntity1.getOrgCode())) { - try { - orgCodeArray = com.alibaba.fastjson.JSONArray.parseArray(userShipperEntity1.getOrgCode()); - } catch (Exception e) { - log.warn("解析现有orgCode失败,将创建新的数组,shipperId={}", userShipperEntity1.getShipperId()); - } - } - // 将limitdatas按orgcode值合并到orgCode数组中 for (int i = 0; i < limitdatas.size(); i++) { com.alibaba.fastjson.JSONObject limitItem = limitdatas.getJSONObject(i); @@ -1951,9 +1977,6 @@ public class UserShipperApplicationService { } } - // 保存更新后的orgCode数组 - userShipperEntity1.setOrgCode(orgCodeArray.toJSONString()); - // 使用limitdatas中的数据更新额度字段 com.alibaba.fastjson.JSONObject firstLimitData = limitdatas.getJSONObject(0); userShipperEntity1.setLimitTime(new Date()); @@ -1977,6 +2000,32 @@ public class UserShipperApplicationService { log.info("第一次循环,删除货主所有协议明细,shipperId={}", userShipperEntity1.getShipperId()); } + // 将agreedaydatas保存到orgCode数组中,与code同一级别 + String currentOrgCodeStr = String.valueOf(orgCode); + boolean foundOrg = false; + for (int j = 0; j < orgCodeArray.size(); j++) { + com.alibaba.fastjson.JSONObject orgItem = orgCodeArray.getJSONObject(j); + String orgItemCode = orgItem.getString("code"); + + // 找到当前组织,将agreedaydatas添加到该组织对象中 + if (currentOrgCodeStr.equals(orgItemCode)) { + orgItem.put("agreedaydatas", agreedaydatas); + foundOrg = true; + log.info("将agreedaydatas添加到code={}的组织中,共{}条", orgItemCode, agreedaydatas.size()); + break; + } + } + + // 如果没找到,创建新组织对象 + if (!foundOrg) { + com.alibaba.fastjson.JSONObject newOrgItem = new com.alibaba.fastjson.JSONObject(); + newOrgItem.put("code", orgCode); + newOrgItem.put("agreedaydatas", agreedaydatas); + orgCodeArray.add(newOrgItem); + log.info("创建新组织并添加agreedaydatas,code={},共{}条", orgCode, agreedaydatas.size()); + } + + // 同时插入到agreement_details表 for (int i = 0; i < agreedaydatas.size(); i++) { com.alibaba.fastjson.JSONObject agreeItem = agreedaydatas.getJSONObject(i); AgreementDetails agreementDetails = new AgreementDetails(); @@ -1994,6 +2043,9 @@ public class UserShipperApplicationService { } else { log.info("赊销额度查询无agreedaydatas返回,跳过协议明细同步,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode); } + + // 保存更新后的orgCode数组(统一在最后保存) + userShipperEntity1.setOrgCode(orgCodeArray.toJSONString()); } else { log.info("赊销额度查询无data返回,跳过更新,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode); }