客商主数据查询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();
|
||||
}
|
||||
|
||||
+28
-1
@@ -8,6 +8,7 @@ import com.linke.thirdParty.domain.departInterfaceInfo.repository.mapper.SysDepa
|
||||
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.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -23,6 +24,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 北京三维天地 MDM 客商主数据查询
|
||||
@@ -43,7 +45,32 @@ public class MdmMasterDataApplicationService {
|
||||
log.info("MDM客商查询请求 orgNcCode={}, page={}, lastTime={}",
|
||||
queryDTO.getOrgNcCode(), queryDTO.getCurrentPage(), queryDTO.getLastModifyRecordTime());
|
||||
String responseBody = doPost(config.url, config.usercode, config.password, requestBody);
|
||||
return parseResponse(responseBody);
|
||||
MdmMerchantQueryResultDTO result = parseResponse(responseBody);
|
||||
return applyOrgFilter(queryDTO, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* MDM 对 DESC24 条件未严格过滤,按 orgNcCode 在应用侧二次过滤并修正分页描述。
|
||||
*/
|
||||
private MdmMerchantQueryResultDTO applyOrgFilter(MdmMerchantQueryDTO queryDTO, MdmMerchantQueryResultDTO result) {
|
||||
if (result == null || StringUtils.isEmpty(queryDTO.getOrgNcCode())
|
||||
|| result.getDataInfo() == null || result.getDataInfo().isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
String orgNcCode = queryDTO.getOrgNcCode().trim();
|
||||
int rawCount = result.getDataInfo().size();
|
||||
List<MdmMerchantRecordDTO> filtered = result.getDataInfo().stream()
|
||||
.filter(record -> MdmMerchantSyncFilter.belongsToOrg(record.getDesc24(), orgNcCode))
|
||||
.collect(Collectors.toList());
|
||||
result.setDataInfo(filtered);
|
||||
if (rawCount != filtered.size()) {
|
||||
String note = String.format("(MDM原始%d条,按DESC24=%s过滤后%d条;MDM总条数totalNumber为未过滤全库统计)",
|
||||
rawCount, orgNcCode, filtered.size());
|
||||
result.setDesc(StringUtils.isEmpty(result.getDesc()) ? note : result.getDesc() + note);
|
||||
log.info("MDM客商查询应用侧过滤 orgNcCode={}, rawPageSize={}, filteredPageSize={}, mdmTotalNumber={}",
|
||||
orgNcCode, rawCount, filtered.size(), result.getTotalNumber());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private MdmConfig loadConfig() {
|
||||
|
||||
@@ -69,49 +69,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
and (operators_name IS NULL OR operators_name = '')
|
||||
</sql>
|
||||
|
||||
<!-- 任务大厅 tabType=2:排除 PC 端已处理/已指派的关联业务单(delive_task 作业人仍为空时,业务单可能已在 PC 作业) -->
|
||||
<sql id="deliveTaskHallExcludePcProcessedFilter">
|
||||
and NOT (
|
||||
(task_type = 1 AND EXISTS (
|
||||
SELECT 1 FROM stock_receipt_order biz
|
||||
WHERE biz.receipt_order_number = delive_task.tracking_number AND biz.del_flag = 1
|
||||
AND (biz.status >= 2 OR (biz.operators_by IS NOT NULL AND biz.operators_by != 0))
|
||||
))
|
||||
OR (task_type = 2 AND EXISTS (
|
||||
SELECT 1 FROM stock_shelf_order biz
|
||||
WHERE biz.shelf_order_number = delive_task.tracking_number AND biz.del_flag = 1
|
||||
AND (biz.status >= 2 OR (biz.operators_by IS NOT NULL AND biz.operators_by != 0))
|
||||
))
|
||||
OR (task_type = 3 AND EXISTS (
|
||||
SELECT 1 FROM stock_out_task_order biz
|
||||
WHERE biz.task_number = delive_task.tracking_number AND biz.del_flag = 1
|
||||
AND (biz.status >= 2 OR (biz.operators_by IS NOT NULL AND biz.operators_by != 0))
|
||||
))
|
||||
OR (task_type = 4 AND (
|
||||
EXISTS (
|
||||
SELECT 1 FROM review_order biz
|
||||
WHERE biz.review_order_number = delive_task.tracking_number AND biz.del_flag = 1
|
||||
AND biz.review_status >= 2
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM stock_out_order biz
|
||||
WHERE biz.out_order_number = delive_task.tracking_number AND biz.del_flag = 1
|
||||
AND (biz.check_status >= 2 OR (biz.check_operators_by IS NOT NULL AND biz.check_operators_by != 0))
|
||||
)
|
||||
))
|
||||
OR (task_type = 5 AND EXISTS (
|
||||
SELECT 1 FROM shift_manage biz
|
||||
WHERE biz.shift_number = delive_task.tracking_number AND biz.del_flag = 1
|
||||
AND (biz.shift_status >= 3 OR (biz.operators_by IS NOT NULL AND biz.operators_by != 0))
|
||||
))
|
||||
OR (task_type = 6 AND EXISTS (
|
||||
SELECT 1 FROM investigation_manage biz
|
||||
WHERE biz.investigation_number = delive_task.tracking_number AND biz.del_flag = 1
|
||||
AND (biz.investigation_status >= 3 OR (biz.operators_by IS NOT NULL AND biz.operators_by != 0))
|
||||
))
|
||||
)
|
||||
</sql>
|
||||
|
||||
<sql id="selectDeliveTaskPo1">
|
||||
<where>
|
||||
del_flag = 1
|
||||
@@ -257,7 +214,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tabType != null and tabType==2">
|
||||
<if test="taskType == null or taskType != 7">
|
||||
<include refid="deliveTaskHallUnassignedFilter"/>
|
||||
<include refid="deliveTaskHallExcludePcProcessedFilter"/>
|
||||
</if>
|
||||
</if>
|
||||
<if test="operatorsName != null and operatorsName != ''">
|
||||
@@ -443,7 +399,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
WHERE
|
||||
del_flag = 1
|
||||
<include refid="deliveTaskHallUnassignedFilter"/>
|
||||
<include refid="deliveTaskHallExcludePcProcessedFilter"/>
|
||||
<include refid="selectDeliveTaskPo2"/>
|
||||
) taskSum
|
||||
|
||||
|
||||
Reference in New Issue
Block a user