From ce8e340116cc64709567edbfac396ae94c6da36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E8=BE=89?= <2830717623@qq.com> Date: Wed, 24 Jun 2026 16:07:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=A7=94=E6=89=98=E6=96=B9?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserShipperApplicationService.java | 70 +++++++++++++++++-- 1 file changed, 63 insertions(+), 7 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 f0de14140..5700a4cc2 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 @@ -1372,6 +1372,62 @@ public class UserShipperApplicationService { throw new ServiceException("获取组织配置失败"); } + // 检查是否已存在相同customerNcCode的委托方(可能在不同组织) + List existingShippers = userShipperMapper.selectList( + new LambdaQueryWrapper() + .eq(UserShipperEntity::getShipperEnterpriseName, record.getDesc1()) + .eq(UserShipperEntity::getDelFlag, 1)); + + if (CollUtil.isNotEmpty(existingShippers)) { + // 找到已存在的委托方,检查是否已经有该组织 + UserShipperEntity existingShipper = existingShippers.get(0); + String existingOrgCode = existingShipper.getOrgCode(); + + boolean hasOrg = false; + com.alibaba.fastjson.JSONArray orgCodeArray = new com.alibaba.fastjson.JSONArray(); + if (StringUtils.isNotEmpty(existingOrgCode)) { + try { + orgCodeArray = com.alibaba.fastjson.JSONArray.parseArray(existingOrgCode); + // 检查是否已包含当前组织 + for (int i = 0; i < orgCodeArray.size(); i++) { + com.alibaba.fastjson.JSONObject orgItem = orgCodeArray.getJSONObject(i); + Long itemCode = orgItem.getLong("code"); + if (targetOrganizationId.equals(itemCode)) { + hasOrg = true; + break; + } + } + } catch (Exception e) { + log.error("解析orgCode失败,shipperId={}", existingShipper.getShipperId(), e); + } + } + + if (!hasOrg) { + // 添加新组织到orgCode数组 + com.alibaba.fastjson.JSONObject newOrgItem = new com.alibaba.fastjson.JSONObject(); + newOrgItem.put("name", targetOrganizationName); + newOrgItem.put("code", targetOrganizationId); + newOrgItem.put("ncCustomer", record.getCode()); + newOrgItem.put("names", targetOrganizationId); + orgCodeArray.add(newOrgItem); + + // 更新委托方的orgCode字段 + existingShipper.setOrgCode(orgCodeArray.toJSONString()); + existingShipper.setUpdateBy(loginUser.getUserPo().getUserId()); + existingShipper.setUpdateByName(loginUser.getUserPo().getUserName()); + existingShipper.setUpdateTime(new Date()); + userShipperMapper.updateById(existingShipper); + + log.info("委托方已存在,添加新组织到orgCode,customerNcCode={},新增组织code={},name={}", + record.getCode(), targetOrganizationId, targetOrganizationName); + } else { + log.info("委托方已存在且已包含该组织,跳过添加,customerNcCode={},组织code={}", + record.getCode(), targetOrganizationId); + } + return; // 不新增,直接返回 + } + + // 不存在相同的委托方,执行新增逻辑 UserShipperDO userShipperDO = buildShipperDOFromMasterData(record, loginUser, targetOrganizationId, targetOrganizationName, targetTopOrganizationId); userShipperDO.setDataSource(1); @@ -1617,12 +1673,12 @@ public class UserShipperApplicationService { Long organizationId = userShipperEntity1.getOrganizationId(); if (organizationId != null) { orgCodeList.add(organizationId); - log.info("org_code为空,使用organizationId,custcode={},organizationId={}", userShipperEntity.getCustomerNcCode(), organizationId); + log.info("org_code为空,使用organizationId,custcode={},organizationId={}", organizationId); } } if (orgCodeList.isEmpty()) { - log.warn("货主无组织信息,跳过查询,custcode={}", userShipperEntity.getCustomerNcCode()); + log.warn("货主无组织信息,跳过查询,custcode={}"); continue; } @@ -1631,7 +1687,7 @@ public class UserShipperApplicationService { for (Long orgCode : orgCodeList) { String orgcode = userShipperMapper.getOrgNcCode(orgCode); if (StringUtils.isEmpty(orgcode)) { - log.warn("组织NC编码为空,跳过查询,custcode={},orgCode={}", userShipperEntity.getCustomerNcCode(), orgCode); + log.warn("组织NC编码为空,跳过查询,custcode={},orgCode={}", orgCode); orgIndex++; continue; } @@ -1655,7 +1711,7 @@ public class UserShipperApplicationService { } if (StringUtils.isEmpty(ncCustomer)) { - log.warn("未找到组织code={}对应的ncCustomer,跳过查询,custcode={}", orgCode, userShipperEntity.getCustomerNcCode()); + log.warn("未找到组织code={}对应的ncCustomer,跳过查询,custcode={}", orgCode); orgIndex++; continue; } @@ -1664,7 +1720,7 @@ public class UserShipperApplicationService { com.alibaba.fastjson.JSONObject queryParam = new com.alibaba.fastjson.JSONObject(); queryParam.put("custcode", ncCustomer); // 使用当前组织的ncCustomer queryParam.put("orgcode", orgcode); - log.info("调用赊销额度查询接口,custcode={},ncCustomer={},orgcode={}", userShipperEntity.getCustomerNcCode(), ncCustomer, orgcode); + log.info("调用赊销额度查询接口,custcode={},ncCustomer={},orgcode={}", ncCustomer, orgcode); String queryResult = HttpRequest.post(queryUrl) .header("Content-Type", "application/json") @@ -1675,7 +1731,7 @@ public class UserShipperApplicationService { .body(queryParam.toJSONString()) .execute() .body(); - log.info("赊销额度查询接口返回,custcode={},ncCustomer={},orgcode={},result={}", userShipperEntity.getCustomerNcCode(), ncCustomer, orgcode, queryResult); + log.info("赊销额度查询接口返回,custcode={},ncCustomer={},orgcode={},result={}", ncCustomer, orgcode, queryResult); if (StringUtils.isNotEmpty(queryResult)) { com.alibaba.fastjson.JSONObject resultJson = com.alibaba.fastjson.JSONObject.parseObject(queryResult); @@ -1806,7 +1862,7 @@ public class UserShipperApplicationService { log.info("赊销额度查询无data返回,跳过更新,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode); } } else { - log.warn("未找到对应货主,custcode={},orgCode={}", userShipperEntity.getCustomerNcCode(), orgCode); + log.warn("未找到对应货主,custcode={},orgCode={}", orgCode); } } else { log.warn("赊销额度查询返回为空,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode);