Commit 8415a916 by ThomasAdv

修复oneIdMapping orgId取值为-1问题;数据上报含oneId处理:存在则不更新相关模型,不存在则抛出异常停止处理

1 parent 0add4ae3
......@@ -17,4 +17,6 @@ public class OneIdFieldConfigDTO extends OneIdFieldConfig {
private static final long serialVersionUID = 3839452358183537235L;
private String fieldValue;
private String oneIdBelongOrgId;
}
......@@ -12,6 +12,7 @@ import cn.com.glsx.cdp.modules.model.ModelFieldMappingDTO;
import cn.com.glsx.cdp.modules.service.ModelService;
import cn.com.glsx.cdp.modules.service.OneIdService;
import cn.com.glsx.cdp.modules.util.DateUtil;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
......@@ -486,7 +487,7 @@ public class DataReportRabbitMQConsumer {
public Map<OneIdBelongEnum, String> getOneId(List<ModelDTO> matchModels, JSONObject jsonData) {
Map<OneIdBelongEnum, String> oneIdBelongEnumStringMap = new HashMap<>();
List<String> oneIdModelNames = OneIdBelongEnum.getModelNames();
putOneIdByJSONDataField(jsonData, oneIdBelongEnumStringMap, oneIdModelNames);
putOneIdByJSONDataField(matchModels, jsonData, oneIdBelongEnumStringMap, oneIdModelNames);
putOneIdByMatchModel(matchModels, jsonData, oneIdModelNames, oneIdBelongEnumStringMap);
return oneIdBelongEnumStringMap;
}
......@@ -536,7 +537,7 @@ public class DataReportRabbitMQConsumer {
* @author caiym
* @date 2023年09月26日 17:01:25
*/
private void putOneIdByJSONDataField(JSONObject jsonData, Map<OneIdBelongEnum, String> oneIdBelongEnumStringMap, List<String> oneIdModelNames) {
private void putOneIdByJSONDataField(List<ModelDTO> matchModels, JSONObject jsonData, Map<OneIdBelongEnum, String> oneIdBelongEnumStringMap, List<String> oneIdModelNames) {
List<String> oneIdFieldNames = OneIdBelongEnum.getOneIdFieldNames();
for (String oneIdFieldName : oneIdFieldNames) {
if (jsonData.containsKey(oneIdFieldName)
......@@ -548,6 +549,10 @@ public class DataReportRabbitMQConsumer {
log.info("get oneId from model:{}, oneIdFieldName:{}, oneId:{}", oneIdBelongEnum.getModelName(), oneIdFieldName, oneId);
oneIdBelongEnumStringMap.put(oneIdBelongEnum, oneId);
oneIdModelNames.remove(oneIdBelongEnum.getModelName());
log.info("to avoid update by oneId,remove model:{} from matchModels", oneIdBelongEnum.getModelName());
matchModels.stream().filter(o->o.getModelName().equals(oneIdBelongEnum.getModelName())).findFirst().ifPresent(matchModels::remove);
}else{
throw new RpcServiceException(DefaultErrorEnum.DATA_INVALID, "oneId is not exist, oneIdFieldName:" + oneIdFieldName + ", oneId:" + oneId);
}
}
}
......
......@@ -51,12 +51,13 @@ public class OneIdMappingService {
public void saveOneIdMapping(String oneId, OneIdFieldConfigDTO oneIdFieldConfigDTO){
log.info("saveOneIdMapping, oneId:{}, oneIdFieldConfigDTO:{}", oneId, oneIdFieldConfigDTO);
RpcAssert.assertNotNull(oneIdFieldConfigDTO, DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO not be null");
RpcAssert.assertNotNull(oneIdFieldConfigDTO.getOrgId(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getOrgId() not be null");
RpcAssert.assertNotNull(oneIdFieldConfigDTO.getOneIdBelongOrgId(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getOneIdBelongOrgId() not be null");
RpcAssert.assertNotNull(oneIdFieldConfigDTO.getBusinessType(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getBusinessType() not be null");
RpcAssert.assertNotEmpty(oneIdFieldConfigDTO.getFieldName(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getFieldName() not be empty");
RpcAssert.assertNotEmpty(oneIdFieldConfigDTO.getFieldValue(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getFieldValue() not be empty");
RpcAssert.assertNotEmpty(oneId, DefaultErrorEnum.DATA_NULL,"oneId not be empty");
OneIdMappingDTO record = OneIdMappingDTOConvert.INSTANCE.fromOneIdFieldConfig(oneId, oneIdFieldConfigDTO, Constants.DEFAULT_UPDATED_BY);
record.setOrgId(oneIdFieldConfigDTO.getOneIdBelongOrgId());
record.setCreatedTime(new Date());
record.setUpdatedTime(record.getCreatedTime());
try{
......
......@@ -82,7 +82,7 @@ public class OneIdService {
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public String findOrCreateOneId(String finalOneId, OneIdFieldConfigDTO readyMatchOneIdFieldConfig){
log.info("findOrCreateOneId,finalOneId:{},fieldName:{}", readyMatchOneIdFieldConfig.getFieldName());
OneIdMappingDTO oneIdMapping = oneIdMappingService.getOneIdMapping(readyMatchOneIdFieldConfig.getOrgId(),
OneIdMappingDTO oneIdMapping = oneIdMappingService.getOneIdMapping(readyMatchOneIdFieldConfig.getOneIdBelongOrgId(),
readyMatchOneIdFieldConfig.getBusinessType(), readyMatchOneIdFieldConfig.getFieldName(),
readyMatchOneIdFieldConfig.getFieldValue());
if (oneIdMapping == null) {
......@@ -122,6 +122,7 @@ public class OneIdService {
.filter(o -> oneIdField.containsKey(o.getFieldName()))
.map(o -> {
o.setFieldValue(oneIdField.getString(o.getFieldName()));
o.setOneIdBelongOrgId(param.getOrgId());
return o;
})
.sorted(Comparator.comparing(OneIdFieldConfigDTO::getPriority))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!