客商修改

This commit is contained in:
赵辉
2026-07-11 11:48:35 +08:00
parent 762c9d4bf4
commit 226360ef3a
11 changed files with 141 additions and 71 deletions
@@ -18,7 +18,7 @@ import java.util.Set;
/**
* bms财务结算系统feign调用接口
*/
@FeignClient(contextId = "BmsService", value = ServiceNameConstants.BMS_SERVICE, url = "http://10.102.192.3:8019",fallbackFactory = RemoteBmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "BmsService", value = ServiceNameConstants.BMS_SERVICE, url = "http://10.33.0.109:8019",fallbackFactory = RemoteBmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
public interface BmsServiceFeign {
@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@FeignClient(contextId = "OmsService", value = ServiceNameConstants.OMS_SERVICE,url = "http://10.102.192.4:8017", fallbackFactory = RemoteOmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "OmsService", value = ServiceNameConstants.OMS_SERVICE,url = "http://10.33.0.99:8017", fallbackFactory = RemoteOmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
public interface OmsServiceFeign {
@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@FeignClient(contextId = "commonWlhyServiceFeign",value = ServiceNameConstants.WLHY_SERVICE,url = "http://10.102.192.30:8014",configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "commonWlhyServiceFeign",value = ServiceNameConstants.WLHY_SERVICE,url = "http://10.33.0.129:8014",configuration = FeignAutoConfiguration.class)
public interface WlhyServiceFeign {
/**
@@ -21,7 +21,7 @@ import java.util.Map;
* @description: TODO
* @date 2024/5/10 8:58
**/
@FeignClient(contextId = "remoteWmsServiceFeign",value = ServiceNameConstants.WMS_SERVICE, url = "http://10.102.192.3:8016", fallbackFactory = RemoteWmsFallbackFactory.class, configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "remoteWmsServiceFeign",value = ServiceNameConstants.WMS_SERVICE, fallbackFactory = RemoteWmsFallbackFactory.class, configuration = FeignAutoConfiguration.class)
public interface WmsServiceFeign {
/**
@@ -9,7 +9,7 @@ import com.mhd.system.api.feign.FeignAutoConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(contextId = "YmsService", value = ServiceNameConstants.YMS_SERVICE,fallbackFactory = RemoteBmsFeignFallbackFactory.class,url = "http://10.102.192.4:8018", configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "YmsService", value = ServiceNameConstants.YMS_SERVICE,fallbackFactory = RemoteBmsFeignFallbackFactory.class,url = "http://10.33.0.99:8018", configuration = FeignAutoConfiguration.class)
public interface YmsServiceFeign {
/**
@@ -46,6 +46,9 @@ public class MdmMerchantRecordDTO implements Serializable {
@ApiModelProperty("电子邮件")
private String desc16;
@ApiModelProperty("nc编码")
private String desc17;
@ApiModelProperty("身份证号")
private String desc23;
@@ -1349,6 +1349,82 @@ public class UserShipperApplicationService {
organizationId);
}
/**
* 按公司名跨组织查询第一个未删除的委托方(包含 orgCode)。
* 用于 MDM 同步时:同公司名可能在不同组织下 nc 编码不同,但本地是同一条委托方记录。
*/
public UserShipperEntity findFirstByShipperEnterpriseNameAcrossOrgs(String shipperEnterpriseName) {
if (StringUtils.isEmpty(shipperEnterpriseName)) {
return null;
}
return userShipperMapper.findFirstByShipperEnterpriseNameAcrossOrgs(shipperEnterpriseName.trim());
}
/**
* 在已存在的同公司名委托方(可能属于其他组织)的 orgCode JSON 数组中追加当前组织信息。
* 若目标组织已存在于数组中则跳过(不重复追加)。
*
* @param existingShipper 本地已存在的同公司名委托方
* @param targetOrganizationId 当前同步组织 ID
* @param targetOrganizationName 当前同步组织名称
* @param ncCustomerCode MDM 客商 code(作为该组织下的 ncCustomer 记录)
* @param loginUser 登录用户(用于写入 updateBy)
* @return true 表示实际写入(新增组织或已存在都返回 true,方便调用方统计),false 表示参数无效
*/
public boolean appendOrganizationToExistingShipper(UserShipperEntity existingShipper,
Long targetOrganizationId, String targetOrganizationName,
String ncCustomerCode, LoginUser loginUser) {
if (existingShipper == null) {
return false;
}
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 != null && 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", ncCustomerCode);
newOrgItem.put("names", targetOrganizationId);
orgCodeArray.add(newOrgItem);
// 更新委托方的orgCode字段
existingShipper.setOrgCode(orgCodeArray.toJSONString());
if (loginUser != null && loginUser.getUserPo() != null) {
existingShipper.setUpdateBy(loginUser.getUserPo().getUserId());
existingShipper.setUpdateByName(loginUser.getUserPo().getUserName());
}
existingShipper.setUpdateTime(new Date());
userShipperMapper.updateById(existingShipper);
log.info("委托方已存在,添加新组织到orgCodecustomerNcCode={},新增组织code={}name={}",
ncCustomerCode, targetOrganizationId, targetOrganizationName);
} else {
log.info("委托方已存在且已包含该组织,跳过添加,customerNcCode={},组织code={}",
ncCustomerCode, targetOrganizationId);
}
return true;
}
public static String buildMasterDataMatchKey(String ncCode, String companyName) {
return normalizeMasterDataKey(ncCode) + "|" + normalizeMasterDataKey(companyName);
}
@@ -1374,61 +1450,8 @@ public class UserShipperApplicationService {
throw new ServiceException("获取组织配置失败");
}
// 检查是否已存在相同customerNcCode的委托方(可能在不同组织)
List<UserShipperEntity> existingShippers = userShipperMapper.selectList(
new LambdaQueryWrapper<UserShipperEntity>()
.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("委托方已存在,添加新组织到orgCodecustomerNcCode={},新增组织code={}name={}",
record.getCode(), targetOrganizationId, targetOrganizationName);
} else {
log.info("委托方已存在且已包含该组织,跳过添加,customerNcCode={},组织code={}",
record.getCode(), targetOrganizationId);
}
return; // 不新增,直接返回
}
// 按公司名跨组织匹配已存在委托方的逻辑已迁移到 doSync 层(先调用 appendOrganizationToExistingShipper),
// 走到这里说明按 ncCode+companyName 与公司名均未匹配到,本方法只负责"新增"。
// 不存在相同的委托方,执行新增逻辑
UserShipperDO userShipperDO = buildShipperDOFromMasterData(record, loginUser,
targetOrganizationId, targetOrganizationName, targetTopOrganizationId);
@@ -13,6 +13,7 @@ import com.mhd.common.core.utils.StringUtils;
import com.mhd.common.redis.service.RedisLock;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.model.LoginUser;
import com.mhd.user.domain.userAggregate.entity.UserShipperEntity;
import com.mhd.user.domain.userAggregate.repository.po.UserShipperPo;
import com.mhd.user.domain.userShipperMdmSync.entity.UserShipperMdmSyncEntity;
import com.mhd.user.domain.userShipperMdmSync.mapper.UserShipperMdmSyncMapper;
@@ -176,7 +177,7 @@ public class UserShipperMasterDataSyncService {
continue;
}
try {
String ncCode = trimToEmpty(record.getCode());
String ncCode = trimToEmpty(record.getDesc17());
String companyName = trimToEmpty(record.getDesc1());
String matchKey = UserShipperApplicationService.buildMasterDataMatchKey(ncCode, companyName);
Long targetOrganizationId = MdmMerchantSyncFilter.resolveSaveOrganizationId(record, organizationId);
@@ -184,14 +185,31 @@ public class UserShipperMasterDataSyncService {
targetOrganizationId, organizationId, topOrganizationId, loginUser);
UserShipperPo existing = existingMap.get(matchKey);
if (existing == null) {
userShipperApplicationService.addEnterpriseShipperFromMasterData(
record, loginUser, saveTarget.getOrganizationId(),
saveTarget.getOrganizationName(), saveTarget.getTopOrganizationId());
resultVo.setAddCount(resultVo.getAddCount() + 1);
UserShipperPo added = userShipperApplicationService.findByCustomerNcCodeAndCompanyName(
ncCode, companyName, saveTarget.getOrganizationId());
if (added != null) {
existingMap.put(matchKey, added);
// 按 ncCode+companyName 未匹配到时,再按公司名跨组织查询已存在的同公司名委托方。
// 同一个客商在 MDM 中可能属于不同组织(nc 编码不同),但本地是同一条委托方记录。
// 如果匹配到的委托方属于“另外的组织”(非当前同步组织),则不新增,
// 而是在其 orgCode 上追加当前同步组织的信息(连同本组织下的 ncCustomer)。
UserShipperEntity existingByName = userShipperApplicationService
.findFirstByShipperEnterpriseNameAcrossOrgs(companyName);
if (existingByName != null
&& saveTarget.getOrganizationId() != null
&& !saveTarget.getOrganizationId().equals(existingByName.getOrganizationId())) {
userShipperApplicationService.appendOrganizationToExistingShipper(
existingByName, saveTarget.getOrganizationId(),
saveTarget.getOrganizationName(), ncCode, loginUser);
resultVo.setLinkCount(resultVo.getLinkCount() + 1);
log.info("MDM同步按公司名跨组织合并:customerNcCode={}companyName={},本组织code={},已存在委托方shipperId={}(其他组织)",
ncCode, companyName, saveTarget.getOrganizationId(), existingByName.getShipperId());
} else {
userShipperApplicationService.addEnterpriseShipperFromMasterData(
record, loginUser, saveTarget.getOrganizationId(),
saveTarget.getOrganizationName(), saveTarget.getTopOrganizationId());
resultVo.setAddCount(resultVo.getAddCount() + 1);
UserShipperPo added = userShipperApplicationService.findByCustomerNcCodeAndCompanyName(
ncCode, companyName, saveTarget.getOrganizationId());
if (added != null) {
existingMap.put(matchKey, added);
}
}
} else {
userShipperApplicationService.updateEnterpriseShipperFromMasterData(
@@ -261,8 +279,9 @@ public class UserShipperMasterDataSyncService {
entity.setLastSyncTime(syncTime);
entity.setSyncStatus(resultVo.getFailCount() > 0 ? 2 : 1);
String syncMessage = String.format(
"新增%d,更新%d,跳过%d,失败%d;组织NC=%s;跳过明细[组织不匹配:%d,非客户:%d,内部单位:%d,停用:%d,其他:%d]",
resultVo.getAddCount(), resultVo.getUpdateCount(), resultVo.getSkipCount(), resultVo.getFailCount(),
"新增%d,更新%d关联%d跳过%d,失败%d;组织NC=%s;跳过明细[组织不匹配:%d,非客户:%d,内部单位:%d,停用:%d,其他:%d]",
resultVo.getAddCount(), resultVo.getUpdateCount(), resultVo.getLinkCount(),
resultVo.getSkipCount(), resultVo.getFailCount(),
orgNcCode, skipOrgMismatch, skipNotCustomer, skipInternalOrg, skipDisabled, skipOther);
if (resultVo.getFailCount() > 0 && !resultVo.getErrorMessages().isEmpty()) {
syncMessage += "" + resultVo.getErrorMessages().get(0);
@@ -52,5 +52,11 @@ public interface UserShipperMapper extends BaseMapper<UserShipperEntity> {
@Param("companyName") String companyName,
@Param("organizationId") Long organizationId);
/**
* 按公司名跨组织查询第一个未删除的委托方(包含 orgCode 字段)。
* 用于 MDM 同步时按"公司名"匹配已存在的委托方(可能是其他组织的),以便在其 orgCode 上追加新组织。
*/
UserShipperEntity findFirstByShipperEnterpriseNameAcrossOrgs(@Param("shipperEnterpriseName") String shipperEnterpriseName);
String getOrgNcCode(Long organizationId);
}
@@ -18,6 +18,9 @@ public class ShipperMasterDataSyncResultVo {
@ApiModelProperty("更新条数")
private int updateCount;
@ApiModelProperty("关联到已存在委托方条数(按公司名跨组织匹配到同公司名委托方,仅在 orgCode 上追加新组织,不新增委托方)")
private int linkCount;
@ApiModelProperty("跳过条数")
private int skipCount;
@@ -629,6 +629,22 @@
AND a.organization_id = #{organizationId}
LIMIT 1
</select>
<!-- 按公司名跨组织查询第一个未删除的委托方(包含 orgCode),用于 MDM 同步时按"公司名"匹配已存在委托方 -->
<select id="findFirstByShipperEnterpriseNameAcrossOrgs" resultType="com.mhd.user.domain.userAggregate.entity.UserShipperEntity">
SELECT b.shipper_id,
b.user_id,
b.customer_nc_code,
b.data_source,
b.shipper_enterprise_name,
b.user_name_shipper,
b.org_code
FROM user_shipper b
WHERE b.del_flag = 1
AND b.shipper_enterprise_name = #{shipperEnterpriseName}
ORDER BY b.shipper_id ASC
LIMIT 1
</select>
<select id="getOrgNcCode" resultType="java.lang.String">
select NC_CODE from NGWL_TEST_PRODUCT.SYS_ORGANIZATION where ORGANIZATION_ID = #{organizationId}
</select>