同步委托方修改
This commit is contained in:
+63
-7
@@ -1372,6 +1372,62 @@ public class UserShipperApplicationService {
|
|||||||
throw new ServiceException("获取组织配置失败");
|
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("委托方已存在,添加新组织到orgCode,customerNcCode={},新增组织code={},name={}",
|
||||||
|
record.getCode(), targetOrganizationId, targetOrganizationName);
|
||||||
|
} else {
|
||||||
|
log.info("委托方已存在且已包含该组织,跳过添加,customerNcCode={},组织code={}",
|
||||||
|
record.getCode(), targetOrganizationId);
|
||||||
|
}
|
||||||
|
return; // 不新增,直接返回
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不存在相同的委托方,执行新增逻辑
|
||||||
UserShipperDO userShipperDO = buildShipperDOFromMasterData(record, loginUser,
|
UserShipperDO userShipperDO = buildShipperDOFromMasterData(record, loginUser,
|
||||||
targetOrganizationId, targetOrganizationName, targetTopOrganizationId);
|
targetOrganizationId, targetOrganizationName, targetTopOrganizationId);
|
||||||
userShipperDO.setDataSource(1);
|
userShipperDO.setDataSource(1);
|
||||||
@@ -1617,12 +1673,12 @@ public class UserShipperApplicationService {
|
|||||||
Long organizationId = userShipperEntity1.getOrganizationId();
|
Long organizationId = userShipperEntity1.getOrganizationId();
|
||||||
if (organizationId != null) {
|
if (organizationId != null) {
|
||||||
orgCodeList.add(organizationId);
|
orgCodeList.add(organizationId);
|
||||||
log.info("org_code为空,使用organizationId,custcode={},organizationId={}", userShipperEntity.getCustomerNcCode(), organizationId);
|
log.info("org_code为空,使用organizationId,custcode={},organizationId={}", organizationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orgCodeList.isEmpty()) {
|
if (orgCodeList.isEmpty()) {
|
||||||
log.warn("货主无组织信息,跳过查询,custcode={}", userShipperEntity.getCustomerNcCode());
|
log.warn("货主无组织信息,跳过查询,custcode={}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1631,7 +1687,7 @@ public class UserShipperApplicationService {
|
|||||||
for (Long orgCode : orgCodeList) {
|
for (Long orgCode : orgCodeList) {
|
||||||
String orgcode = userShipperMapper.getOrgNcCode(orgCode);
|
String orgcode = userShipperMapper.getOrgNcCode(orgCode);
|
||||||
if (StringUtils.isEmpty(orgcode)) {
|
if (StringUtils.isEmpty(orgcode)) {
|
||||||
log.warn("组织NC编码为空,跳过查询,custcode={},orgCode={}", userShipperEntity.getCustomerNcCode(), orgCode);
|
log.warn("组织NC编码为空,跳过查询,custcode={},orgCode={}", orgCode);
|
||||||
orgIndex++;
|
orgIndex++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1655,7 +1711,7 @@ public class UserShipperApplicationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isEmpty(ncCustomer)) {
|
if (StringUtils.isEmpty(ncCustomer)) {
|
||||||
log.warn("未找到组织code={}对应的ncCustomer,跳过查询,custcode={}", orgCode, userShipperEntity.getCustomerNcCode());
|
log.warn("未找到组织code={}对应的ncCustomer,跳过查询,custcode={}", orgCode);
|
||||||
orgIndex++;
|
orgIndex++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1664,7 +1720,7 @@ public class UserShipperApplicationService {
|
|||||||
com.alibaba.fastjson.JSONObject queryParam = new com.alibaba.fastjson.JSONObject();
|
com.alibaba.fastjson.JSONObject queryParam = new com.alibaba.fastjson.JSONObject();
|
||||||
queryParam.put("custcode", ncCustomer); // 使用当前组织的ncCustomer
|
queryParam.put("custcode", ncCustomer); // 使用当前组织的ncCustomer
|
||||||
queryParam.put("orgcode", orgcode);
|
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)
|
String queryResult = HttpRequest.post(queryUrl)
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
@@ -1675,7 +1731,7 @@ public class UserShipperApplicationService {
|
|||||||
.body(queryParam.toJSONString())
|
.body(queryParam.toJSONString())
|
||||||
.execute()
|
.execute()
|
||||||
.body();
|
.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)) {
|
if (StringUtils.isNotEmpty(queryResult)) {
|
||||||
com.alibaba.fastjson.JSONObject resultJson = com.alibaba.fastjson.JSONObject.parseObject(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);
|
log.info("赊销额度查询无data返回,跳过更新,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("未找到对应货主,custcode={},orgCode={}", userShipperEntity.getCustomerNcCode(), orgCode);
|
log.warn("未找到对应货主,custcode={},orgCode={}", orgCode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("赊销额度查询返回为空,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode);
|
log.warn("赊销额度查询返回为空,custcode={},orgcode={}", userShipperEntity1.getCustomerNcCode(), orgcode);
|
||||||
|
|||||||
Reference in New Issue
Block a user