客商主数据查询BUG修改
This commit is contained in:
+30
-44
@@ -6,6 +6,7 @@ import com.mhd.common.core.constant.Constants;
|
||||
import com.mhd.common.core.domain.thirdparty.MdmMerchantQueryDTO;
|
||||
import com.mhd.common.core.domain.thirdparty.MdmMerchantQueryResultDTO;
|
||||
import com.mhd.common.core.domain.thirdparty.MdmMerchantRecordDTO;
|
||||
import com.mhd.common.core.domain.thirdparty.MdmMerchantSyncFilter;
|
||||
import com.mhd.common.core.exception.ServiceException;
|
||||
import com.mhd.common.core.feign.ThirdPartyServiceFeign;
|
||||
import com.mhd.common.core.utils.StringUtils;
|
||||
@@ -36,8 +37,6 @@ public class UserShipperMasterDataSyncService {
|
||||
/** MDM 单页条数,不宜过大以免 MDM/Feign 超时 */
|
||||
private static final int PAGE_SIZE = 100;
|
||||
private static final long SYNC_LOCK_MINUTES = 30;
|
||||
/** MDM desc3:是否客户 */
|
||||
private static final String MDM_FLAG_YES = "1";
|
||||
|
||||
@Resource
|
||||
private ThirdPartyServiceFeign thirdPartyServiceFeign;
|
||||
@@ -135,6 +134,10 @@ public class UserShipperMasterDataSyncService {
|
||||
|
||||
Map<String, UserShipperPo> existingMap = userShipperApplicationService.loadMasterDataSyncShipperMap(organizationId);
|
||||
String maxModifyTime = lastModifyRecordTime;
|
||||
int skipOrgMismatch = 0;
|
||||
int skipNotCustomer = 0;
|
||||
int skipDisabled = 0;
|
||||
int skipOther = 0;
|
||||
int currentPage = 1;
|
||||
Integer totalPages = null;
|
||||
do {
|
||||
@@ -144,17 +147,28 @@ public class UserShipperMasterDataSyncService {
|
||||
break;
|
||||
}
|
||||
for (MdmMerchantRecordDTO record : pageData.getDataInfo()) {
|
||||
if (!shouldSyncRecord(record, orgNcCode)) {
|
||||
MdmMerchantSyncFilter.SkipReason skipReason = MdmMerchantSyncFilter.resolveSkipReason(record, orgNcCode);
|
||||
if (skipReason != null) {
|
||||
resultVo.setSkipCount(resultVo.getSkipCount() + 1);
|
||||
switch (skipReason) {
|
||||
case ORG_MISMATCH:
|
||||
skipOrgMismatch++;
|
||||
break;
|
||||
case NOT_CUSTOMER:
|
||||
skipNotCustomer++;
|
||||
break;
|
||||
case DISABLED:
|
||||
skipDisabled++;
|
||||
break;
|
||||
default:
|
||||
skipOther++;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
String ncCode = trimToEmpty(record.getCode());
|
||||
String companyName = trimToEmpty(record.getDesc1());
|
||||
if (StringUtils.isEmpty(ncCode) || StringUtils.isEmpty(companyName)) {
|
||||
resultVo.setSkipCount(resultVo.getSkipCount() + 1);
|
||||
continue;
|
||||
}
|
||||
String matchKey = UserShipperApplicationService.buildMasterDataMatchKey(ncCode, companyName);
|
||||
UserShipperPo existing = existingMap.get(matchKey);
|
||||
if (existing == null) {
|
||||
@@ -186,7 +200,8 @@ public class UserShipperMasterDataSyncService {
|
||||
|
||||
Date now = new Date();
|
||||
resultVo.setLastSyncTime(now);
|
||||
saveSyncWatermark(organizationId, maxModifyTime, now, resultVo);
|
||||
saveSyncWatermark(organizationId, orgNcCode, maxModifyTime, now, resultVo,
|
||||
skipOrgMismatch, skipNotCustomer, skipDisabled, skipOther);
|
||||
return resultVo;
|
||||
}
|
||||
|
||||
@@ -208,31 +223,9 @@ public class UserShipperMasterDataSyncService {
|
||||
return response.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步过滤:MDM 查询侧 DESC24 无法精确过滤,必须在应用侧严格筛选。
|
||||
*/
|
||||
private boolean shouldSyncRecord(MdmMerchantRecordDTO record, String orgNcCode) {
|
||||
if (record == null || StringUtils.isEmpty(record.getCode())) {
|
||||
return false;
|
||||
}
|
||||
// 仅同步客户(desc3=是否客户)
|
||||
if (!MDM_FLAG_YES.equals(trimToEmpty(record.getDesc3()))) {
|
||||
return false;
|
||||
}
|
||||
// 对应组织编码必须等于当前组织 NC,空值不同步
|
||||
String recordOrgNc = trimToEmpty(record.getDesc24());
|
||||
if (StringUtils.isEmpty(recordOrgNc) || !orgNcCode.equals(recordOrgNc)) {
|
||||
return false;
|
||||
}
|
||||
// 跳过本组织主体(code 与组织 NC 相同,多为内部单位而非外部客商)
|
||||
if (orgNcCode.equals(trimToEmpty(record.getCode()))) {
|
||||
return false;
|
||||
}
|
||||
return !isDisabled(record);
|
||||
}
|
||||
|
||||
private void saveSyncWatermark(Long organizationId, String maxModifyTime, Date syncTime,
|
||||
ShipperMasterDataSyncResultVo resultVo) {
|
||||
private void saveSyncWatermark(Long organizationId, String orgNcCode, String maxModifyTime, Date syncTime,
|
||||
ShipperMasterDataSyncResultVo resultVo,
|
||||
int skipOrgMismatch, int skipNotCustomer, int skipDisabled, int skipOther) {
|
||||
UserShipperMdmSyncEntity entity = userShipperMdmSyncMapper.selectByOrganizationId(organizationId);
|
||||
if (entity == null) {
|
||||
entity = new UserShipperMdmSyncEntity();
|
||||
@@ -244,8 +237,10 @@ public class UserShipperMasterDataSyncService {
|
||||
}
|
||||
entity.setLastSyncTime(syncTime);
|
||||
entity.setSyncStatus(resultVo.getFailCount() > 0 ? 2 : 1);
|
||||
entity.setSyncMessage(String.format("新增%d,更新%d,跳过%d,失败%d",
|
||||
resultVo.getAddCount(), resultVo.getUpdateCount(), resultVo.getSkipCount(), resultVo.getFailCount()));
|
||||
entity.setSyncMessage(String.format(
|
||||
"新增%d,更新%d,跳过%d,失败%d;组织NC=%s;跳过明细[组织不匹配:%d,非客户:%d,停用:%d,其他:%d]",
|
||||
resultVo.getAddCount(), resultVo.getUpdateCount(), resultVo.getSkipCount(), resultVo.getFailCount(),
|
||||
orgNcCode, skipOrgMismatch, skipNotCustomer, skipDisabled, skipOther));
|
||||
entity.setUpdateTime(syncTime);
|
||||
if (entity.getId() == null) {
|
||||
userShipperMdmSyncMapper.insert(entity);
|
||||
@@ -269,15 +264,6 @@ public class UserShipperMasterDataSyncService {
|
||||
return orgJson.has("ncCode") ? orgJson.getString("ncCode") : null;
|
||||
}
|
||||
|
||||
private boolean isDisabled(MdmMerchantRecordDTO record) {
|
||||
if (StringUtils.isEmpty(record.getDesc30())) {
|
||||
return false;
|
||||
}
|
||||
String status = record.getDesc30().trim();
|
||||
// 2=启用;0/3/否/停用 视为停用(结合 MDM 样例数据)
|
||||
return "否".equals(status) || "停用".equals(status) || "0".equals(status) || "3".equals(status);
|
||||
}
|
||||
|
||||
private String trimToEmpty(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user