Commit bdcb861a by ThomasAdv

数据上报接口代码审查与增加注释

1 parent 1a17bba5
...@@ -42,7 +42,7 @@ public interface UserCenterFeignClient { ...@@ -42,7 +42,7 @@ public interface UserCenterFeignClient {
* 注意: @RequestParam("xx") 注解一定要写,而且属性名xx不能省略 * 注意: @RequestParam("xx") 注解一定要写,而且属性名xx不能省略
*/ */
@GetMapping("/echo") @GetMapping("/echo")
String echo(@RequestParam String message); String echo(@RequestParam("message") String message);
@GetMapping(value = "/info/{id}") @GetMapping(value = "/info/{id}")
UserDTO info(@PathVariable("id") Long id); UserDTO info(@PathVariable("id") Long id);
......
package cn.com.glsx.cdp.common.constant;
public class ModelConstants {
public final static String CUSTOMER_MODEL_NAME = "cdp_customer";
public final static String CAR_MODEL_NAME = "cdp_car";
}
...@@ -37,7 +37,7 @@ public class UserApiController implements UserCenterFeignClient { ...@@ -37,7 +37,7 @@ public class UserApiController implements UserCenterFeignClient {
@Operation(summary = "FeignClient调用") @Operation(summary = "FeignClient调用")
@Override @Override
@GetMapping("/echo") @GetMapping("/echo")
public String echo(@RequestParam String message) { public String echo(@RequestParam("message") String message) {
String echo = echoCenterFeignClient.echo(message); String echo = echoCenterFeignClient.echo(message);
return echo; return echo;
} }
......
package cn.com.glsx.cdp.modules.enums; package cn.com.glsx.cdp.modules.enums;
import org.apache.commons.lang.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public enum OneIdBelongEnum { public enum OneIdBelongEnum {
CUSTOMER((byte)1, "oneId", "客户"), CUSTOMER((byte)1, "oneId", "cdp_customer", "客户"),
CAR((byte)2, "carId", "车"); CAR((byte)2, "carId", "cdp_car", "车");
private final Byte value; private final Byte value;
private final String oneIdFieldName; private final String oneIdFieldName;
private final String modelName;
private final String displayText; private final String displayText;
OneIdBelongEnum(Byte value, String oneIdFieldName, String displayText){ OneIdBelongEnum(Byte value, String oneIdFieldName, String modelName, String displayText){
this.value = value; this.value = value;
this.oneIdFieldName = oneIdFieldName; this.oneIdFieldName = oneIdFieldName;
this.modelName = modelName;
this.displayText = displayText; this.displayText = displayText;
} }
...@@ -22,6 +30,10 @@ public enum OneIdBelongEnum { ...@@ -22,6 +30,10 @@ public enum OneIdBelongEnum {
return oneIdFieldName; return oneIdFieldName;
} }
public String getModelName() {
return modelName;
}
public String getDisplayText() { public String getDisplayText() {
return displayText; return displayText;
} }
...@@ -36,4 +48,19 @@ public enum OneIdBelongEnum { ...@@ -36,4 +48,19 @@ public enum OneIdBelongEnum {
} }
return null; return null;
} }
public static List<String> getModelNames(){
return Arrays.stream(OneIdBelongEnum.values()).map(OneIdBelongEnum::getModelName).collect(Collectors.toList());
}
public static OneIdBelongEnum getByModelName(String modelName){
if (StringUtils.isNotBlank(modelName)) {
for (OneIdBelongEnum oneIdBelongEnum : OneIdBelongEnum.values()) {
if (oneIdBelongEnum.getModelName().equals(modelName)) {
return oneIdBelongEnum;
}
}
}
return null;
}
} }
...@@ -20,7 +20,10 @@ import org.springframework.amqp.core.Message; ...@@ -20,7 +20,10 @@ import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
...@@ -44,6 +47,9 @@ public class DataReportRabbitMQConsumer { ...@@ -44,6 +47,9 @@ public class DataReportRabbitMQConsumer {
private ModelService modelService; private ModelService modelService;
@Autowired @Autowired
private OneIdService oneIdService; private OneIdService oneIdService;
@Lazy
@Autowired
private DataReportRabbitMQConsumer thiz;
/** /**
* 处理数据上报 * 处理数据上报
...@@ -67,9 +73,9 @@ public class DataReportRabbitMQConsumer { ...@@ -67,9 +73,9 @@ public class DataReportRabbitMQConsumer {
Integer addWay = jsonData.getInteger(ModelFieldConstants.ADD_WAY); Integer addWay = jsonData.getInteger(ModelFieldConstants.ADD_WAY);
if (orgId != null && addWay != null) { if (orgId != null && addWay != null) {
List<ModelDTO> matchModels = matchModel(jsonData); List<ModelDTO> matchModels = matchModel(jsonData);
Map<OneIdBelongEnum, String> oneIdMap = getOneId(matchModels, jsonData); Map<OneIdBelongEnum, String> oneIdMap = thiz.getOneId(matchModels, jsonData);
List<ModelDTO> valueModels = compileModelFieldsValue(matchModels, jsonData, oneIdMap); List<ModelDTO> valueModels = compileModelFieldsValue(matchModels, jsonData, oneIdMap);
valueModels.forEach(this::handleModel); valueModels.forEach(thiz::handleModel);
} else { } else {
log.error("data report consume error,orgId or addWay is null"); log.error("data report consume error,orgId or addWay is null");
} }
...@@ -93,7 +99,8 @@ public class DataReportRabbitMQConsumer { ...@@ -93,7 +99,8 @@ public class DataReportRabbitMQConsumer {
* @author caiym * @author caiym
* @date 2023年09月15日 15:45:10 * @date 2023年09月15日 15:45:10
*/ */
private void handleModel(ModelDTO modelDTO) { @Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void handleModel(ModelDTO modelDTO) {
if (CollectionUtils.isNotEmpty(modelDTO.getModelFieldMappings())) { if (CollectionUtils.isNotEmpty(modelDTO.getModelFieldMappings())) {
Map<String, Object> existModelData = getExistModelData(modelDTO); Map<String, Object> existModelData = getExistModelData(modelDTO);
if (existModelData != null) { if (existModelData != null) {
...@@ -116,9 +123,11 @@ public class DataReportRabbitMQConsumer { ...@@ -116,9 +123,11 @@ public class DataReportRabbitMQConsumer {
* @date 2023年09月15日 17:14:42 * @date 2023年09月15日 17:14:42
*/ */
private void updateModelData(ModelDTO modelDTO, Map<String, Object> existModelData) { private void updateModelData(ModelDTO modelDTO, Map<String, Object> existModelData) {
log.info("updateModelData, modelDTO:{}, existModelData:{}", modelDTO, existModelData);
if (CollectionUtils.isNotEmpty(modelDTO.getModelFieldMappings())) { if (CollectionUtils.isNotEmpty(modelDTO.getModelFieldMappings())) {
Map<String, Object> fieldMap = mergeModelData(modelDTO, existModelData); Map<String, Object> fieldMap = mergeModelData(modelDTO, existModelData);
String updateSql = buildUpdateSql(modelDTO, fieldMap); String updateSql = buildUpdateSql(modelDTO, fieldMap);
log.debug("updateModelData, updateSql:{}", updateSql);
modelService.updateTable(updateSql); modelService.updateTable(updateSql);
}else{ }else{
log.warn("model field mapping is empty, model:{}", modelDTO); log.warn("model field mapping is empty, model:{}", modelDTO);
...@@ -140,8 +149,13 @@ public class DataReportRabbitMQConsumer { ...@@ -140,8 +149,13 @@ public class DataReportRabbitMQConsumer {
Map<String, Object> mergeResultMap = new HashMap<>(); Map<String, Object> mergeResultMap = new HashMap<>();
for (Map.Entry<String, ModelFieldMappingDTO> newDataMapEntry : newDataMap.entrySet()) { for (Map.Entry<String, ModelFieldMappingDTO> newDataMapEntry : newDataMap.entrySet()) {
String fieldName = newDataMapEntry.getKey(); String fieldName = newDataMapEntry.getKey();
mergeResultMap.put(fieldName, mergeField(newDataMapEntry.getValue(), existModelData.get(fieldName))); log.debug("mergeModelData, fieldName:{}, oldValue:{}, new Value:{}", fieldName, existModelData.get(fieldName), newDataMapEntry.getValue());
Object mergedField = mergeField(newDataMapEntry.getValue(), existModelData.get(fieldName));
log.debug("mergeModelData, fieldName:{}, oldValue:{}, new Value:{}, result:{}", fieldName, existModelData.get(fieldName),
newDataMapEntry.getValue(), mergedField);
mergeResultMap.put(fieldName, mergedField);
} }
log.debug("mergeModelData, result:{}", mergeResultMap);
return mergeResultMap; return mergeResultMap;
} }
...@@ -270,6 +284,7 @@ public class DataReportRabbitMQConsumer { ...@@ -270,6 +284,7 @@ public class DataReportRabbitMQConsumer {
* @date 2023年09月15日 17:14:29 * @date 2023年09月15日 17:14:29
*/ */
private void addModelData(ModelDTO modelDTO) { private void addModelData(ModelDTO modelDTO) {
log.info("addModelData, modelDTO:{}", modelDTO);
if (CollectionUtils.isNotEmpty(modelDTO.getModelFieldMappings())) { if (CollectionUtils.isNotEmpty(modelDTO.getModelFieldMappings())) {
JSONObject exJson = new JSONObject(); JSONObject exJson = new JSONObject();
List<ModelFieldMappingDTO> normalFields = new ArrayList<>(); List<ModelFieldMappingDTO> normalFields = new ArrayList<>();
...@@ -295,6 +310,7 @@ public class DataReportRabbitMQConsumer { ...@@ -295,6 +310,7 @@ public class DataReportRabbitMQConsumer {
valBuilder.append("now()").append(",now()").append(",0").append(")"); valBuilder.append("now()").append(",now()").append(",0").append(")");
StringBuilder sqlBuilder = new StringBuilder(); StringBuilder sqlBuilder = new StringBuilder();
String insertSql = sqlBuilder.append("insert into ").append(modelDTO.getModelName()).append(fieldBuilder).append(" values ").append(valBuilder).toString(); String insertSql = sqlBuilder.append("insert into ").append(modelDTO.getModelName()).append(fieldBuilder).append(" values ").append(valBuilder).toString();
log.debug("addModelData, insertSql:{}", insertSql);
modelService.insertTable(insertSql); modelService.insertTable(insertSql);
}else{ }else{
log.warn("model field mapping is empty, model:{}", modelDTO); log.warn("model field mapping is empty, model:{}", modelDTO);
...@@ -416,15 +432,23 @@ public class DataReportRabbitMQConsumer { ...@@ -416,15 +432,23 @@ public class DataReportRabbitMQConsumer {
private List<ModelDTO> compileModelFieldsValue(List<ModelDTO> matchModels, JSONObject jsonData, Map<OneIdBelongEnum, String> oneIdMap) { private List<ModelDTO> compileModelFieldsValue(List<ModelDTO> matchModels, JSONObject jsonData, Map<OneIdBelongEnum, String> oneIdMap) {
if (CollectionUtils.isNotEmpty(matchModels) && jsonData != null) { if (CollectionUtils.isNotEmpty(matchModels) && jsonData != null) {
for (ModelDTO model : matchModels) { for (ModelDTO model : matchModels) {
OneIdBelongEnum oneIdBelongEnum = OneIdBelongEnum.getByValue(model.getOneidBelong()); String oneId = null;
String oneId = oneIdMap.get(oneIdBelongEnum); OneIdBelongEnum oneIdBelongEnum;
if (OneIdBelongEnum.getModelNames().contains(model.getModelName())) {
oneIdBelongEnum = OneIdBelongEnum.getByModelName(model.getModelName());
}else{
oneIdBelongEnum = OneIdBelongEnum.getByValue(model.getOneidBelong());
}
log.info("oneIdBelongEnum model:{}", oneIdBelongEnum.getModelName());
oneId = oneIdMap.get(oneIdBelongEnum);
if (StringUtils.isBlank(oneId)) { if (StringUtils.isBlank(oneId)) {
log.error("oneId is blank, stop dealing model field value filling, model:{}, jsonData:{}", model.getModelName(), jsonData); log.error("oneId is blank, stop dealing model field value filling, model:{}, jsonData:{}", model.getModelName(), jsonData);
continue; continue;
} }
if (CollectionUtils.isNotEmpty(model.getModelFieldMappings())) { if (CollectionUtils.isNotEmpty(model.getModelFieldMappings())) {
for (ModelFieldMappingDTO modelFieldMapping : model.getModelFieldMappings()) { for (ModelFieldMappingDTO modelFieldMapping : model.getModelFieldMappings()) {
if (oneIdBelongEnum != null && oneIdBelongEnum.getOneIdFieldName().equals(modelFieldMapping.getFieldName())) { if (oneIdBelongEnum != null
&& oneIdBelongEnum.getOneIdFieldName().equals(modelFieldMapping.getFieldName())) {
modelFieldMapping.setFieldValue(oneId); modelFieldMapping.setFieldValue(oneId);
} }
modelFieldMapping.setFieldValue(jsonData.get(modelFieldMapping.getFieldName())); modelFieldMapping.setFieldValue(jsonData.get(modelFieldMapping.getFieldName()));
...@@ -432,6 +456,7 @@ public class DataReportRabbitMQConsumer { ...@@ -432,6 +456,7 @@ public class DataReportRabbitMQConsumer {
} }
} }
} }
log.debug("compileModelFieldsValue, return:{}", matchModels);
return matchModels; return matchModels;
} }
...@@ -445,22 +470,22 @@ public class DataReportRabbitMQConsumer { ...@@ -445,22 +470,22 @@ public class DataReportRabbitMQConsumer {
* @author caiym * @author caiym
* @date 2023年09月15日 15:00:07 * @date 2023年09月15日 15:00:07
*/ */
private Map<OneIdBelongEnum, String> getOneId(List<ModelDTO> matchModels, JSONObject jsonData) { @Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public Map<OneIdBelongEnum, String> getOneId(List<ModelDTO> matchModels, JSONObject jsonData) {
if (CollectionUtils.isNotEmpty(matchModels) && jsonData != null) { if (CollectionUtils.isNotEmpty(matchModels) && jsonData != null) {
Map<OneIdBelongEnum, String> oneIdBelongEnumStringMap = new HashMap<>(); Map<OneIdBelongEnum, String> oneIdBelongEnumStringMap = new HashMap<>();
Map<Byte, ModelDTO> oneIdBelongGroupModelMap = matchModels.stream().filter(modelDTO -> modelDTO.getOneidBelong() != null).collect(Collectors.toMap(ModelDTO::getOneidBelong, o -> o, (o1, o2) -> o2)); for (ModelDTO matchModel : matchModels) {
for (Byte oneIdBelong : oneIdBelongGroupModelMap.keySet()) { if (OneIdBelongEnum.getModelNames().contains(matchModel.getModelName())) {
if (oneIdBelong != null) { log.info("get model:{} oneId", matchModel.getModelName());
OneIdBelongEnum oneIdBelongEnum = OneIdBelongEnum.getByValue(oneIdBelong); Map<String, Object> oneIdFieldMap = matchModel.getModelFieldMappings().stream()
if (oneIdBelongEnum == null) { .filter(o -> o.getOneidFlag() != null && o.getOneidFlag() && jsonData.get(o.getFieldName()) != null)
throw new RpcServiceException("none or undefined oneIdBelong:"+oneIdBelong); .map(o->{o.setFieldValue(jsonData.get(o.getFieldName()));return o;})
}
Map<String, Object> oneIdFieldMap = oneIdBelongGroupModelMap.get(oneIdBelong).getModelFieldMappings().stream()
.filter(o -> o.getOneidFlag() != null && o.getOneidFlag())
.collect( .collect(
Collectors.toMap(ModelFieldMappingDTO::getFieldName, o -> o.getFieldValue(), (o1, o2) -> o2) Collectors.toMap(ModelFieldMappingDTO::getFieldName, o -> o.getFieldValue(), (o1, o2) -> o2)
); );
FindOrCreateOneIdParam param = FindOrCreateOneIdParam.builder().orgId(jsonData.getString(ModelFieldConstants.ORGID)).businessType(oneIdBelong).oneIdFieldJson(JSONObject.toJSONString(oneIdFieldMap)).build(); OneIdBelongEnum oneIdBelongEnum = OneIdBelongEnum.getByModelName(matchModel.getModelName());
FindOrCreateOneIdParam param = FindOrCreateOneIdParam.builder().orgId(jsonData.getString(ModelFieldConstants.ORGID))
.businessType(oneIdBelongEnum.getValue()).oneIdFieldJson(JSONObject.toJSONString(oneIdFieldMap)).build();
String oneId = oneIdService.findOrCreateOneId(param); String oneId = oneIdService.findOrCreateOneId(param);
oneIdBelongEnumStringMap.put(oneIdBelongEnum, oneId); oneIdBelongEnumStringMap.put(oneIdBelongEnum, oneId);
} }
...@@ -485,11 +510,15 @@ public class DataReportRabbitMQConsumer { ...@@ -485,11 +510,15 @@ public class DataReportRabbitMQConsumer {
for (ModelDTO model : models) { for (ModelDTO model : models) {
// 没有匹配的模型字段则跳过 // 没有匹配的模型字段则跳过
if (hasMatchField(model, jsonData)) { if (hasMatchField(model, jsonData)) {
log.info("未匹配模型:{}任何字段,跳过", model.getModelName());
continue; continue;
} }
List<ModelFieldMappingDTO> modelFieldMappings = model.getModelFieldMappings(); List<ModelFieldMappingDTO> modelFieldMappings = model.getModelFieldMappings();
if (CollectionUtils.isNotEmpty(modelFieldMappings)) { if (CollectionUtils.isNotEmpty(modelFieldMappings)) {
List<ModelFieldMappingDTO> oneIdFields = modelFieldMappings.stream().filter(modelFieldMapping -> modelFieldMapping.getOneidFlag() != null && modelFieldMapping.getOneidFlag()).collect(Collectors.toList()); List<ModelFieldMappingDTO> oneIdFields = modelFieldMappings.stream()
.filter(modelFieldMapping -> modelFieldMapping.getOneidFlag() != null
&& modelFieldMapping.getOneidFlag())
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(oneIdFields)) { if (CollectionUtils.isNotEmpty(oneIdFields)) {
// 匹配oneid字段 // 匹配oneid字段
if (matchOneIdField(oneIdFields, jsonData)) { if (matchOneIdField(oneIdFields, jsonData)) {
...@@ -517,13 +546,19 @@ public class DataReportRabbitMQConsumer { ...@@ -517,13 +546,19 @@ public class DataReportRabbitMQConsumer {
* @date 2023年09月15日 14:32:10 * @date 2023年09月15日 14:32:10
*/ */
private Boolean matchModelFlagField(List<ModelFieldMappingDTO> modelFieldMappings, JSONObject jsonData) { private Boolean matchModelFlagField(List<ModelFieldMappingDTO> modelFieldMappings, JSONObject jsonData) {
List<ModelFieldMappingDTO> modelFlagFields = modelFieldMappings.stream().filter(modelFieldMapping -> modelFieldMapping.getModelFlag() != null && modelFieldMapping.getModelFlag()).collect(Collectors.toList()); List<ModelFieldMappingDTO> modelFlagFields = modelFieldMappings.stream()
.filter(modelFieldMapping -> modelFieldMapping.getModelFlag() != null
&& modelFieldMapping.getModelFlag())
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(modelFlagFields)) { if (CollectionUtils.isNotEmpty(modelFlagFields)) {
for (ModelFieldMappingDTO modelFieldMapping : modelFlagFields) { for (ModelFieldMappingDTO modelFieldMapping : modelFlagFields) {
String fieldName = modelFieldMapping.getFieldName(); String fieldName = modelFieldMapping.getFieldName();
Object fieldValue = jsonData.get(fieldName); Object fieldValue = jsonData.get(fieldName);
if (fieldValue instanceof String && StringUtils.isNotBlank((String) fieldValue) if (fieldValue instanceof String) {
|| fieldValue != null) { if (StringUtils.isNotBlank((String) fieldValue)) {
return true;
}
}else if(fieldValue != null){
return true; return true;
} }
} }
...@@ -545,8 +580,11 @@ public class DataReportRabbitMQConsumer { ...@@ -545,8 +580,11 @@ public class DataReportRabbitMQConsumer {
for (ModelFieldMappingDTO oneIdField : oneIdFields) { for (ModelFieldMappingDTO oneIdField : oneIdFields) {
String fieldName = oneIdField.getFieldName(); String fieldName = oneIdField.getFieldName();
Object fieldValue = jsonData.get(fieldName); Object fieldValue = jsonData.get(fieldName);
if (fieldValue instanceof String && StringUtils.isNotBlank((String) fieldValue) if (fieldValue instanceof String) {
|| fieldValue != null) { if (StringUtils.isNotBlank((String) fieldValue)) {
return true;
}
}else if(fieldValue != null){
return true; return true;
} }
} }
......
...@@ -44,7 +44,10 @@ public class OneIdMappingService { ...@@ -44,7 +44,10 @@ public class OneIdMappingService {
return null; return null;
} }
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void saveOneIdMapping(String oneId, OneIdFieldConfigDTO oneIdFieldConfigDTO){ 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, DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO not be null");
RpcAssert.assertNotNull(oneIdFieldConfigDTO.getOrgId(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getOrgId() not be null"); RpcAssert.assertNotNull(oneIdFieldConfigDTO.getOrgId(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getOrgId() not be null");
RpcAssert.assertNotNull(oneIdFieldConfigDTO.getBusinessType(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getBusinessType() not be null"); RpcAssert.assertNotNull(oneIdFieldConfigDTO.getBusinessType(), DefaultErrorEnum.DATA_NULL,"oneIdFieldConfigDTO.getBusinessType() not be null");
......
...@@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -28,6 +29,9 @@ public class OneIdService { ...@@ -28,6 +29,9 @@ public class OneIdService {
private OneIdMappingService oneIdMappingService; private OneIdMappingService oneIdMappingService;
@Autowired @Autowired
private OneIdFieldConfigService oneIdFieldConfigService; private OneIdFieldConfigService oneIdFieldConfigService;
@Lazy
@Autowired
private OneIdService thiz;
/** /**
...@@ -38,7 +42,9 @@ public class OneIdService { ...@@ -38,7 +42,9 @@ public class OneIdService {
* @author caiym * @author caiym
* @date 2023年09月21日 16:07:51 * @date 2023年09月21日 16:07:51
*/ */
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public String findOrCreateOneId(FindOrCreateOneIdParam param){ public String findOrCreateOneId(FindOrCreateOneIdParam param){
log.info("findOrCreateOneId, param:{}", param);
RpcAssert.assertNotNull(param, DefaultErrorEnum.DATA_NULL,"param not be null"); RpcAssert.assertNotNull(param, DefaultErrorEnum.DATA_NULL,"param not be null");
RpcAssert.assertNotNull(param.getOrgId(), DefaultErrorEnum.DATA_NULL,"param.getOrgId() not be null"); RpcAssert.assertNotNull(param.getOrgId(), DefaultErrorEnum.DATA_NULL,"param.getOrgId() not be null");
RpcAssert.assertNotNull(param.getBusinessType(), DefaultErrorEnum.DATA_NULL,"param.getBusinessType() not be null"); RpcAssert.assertNotNull(param.getBusinessType(), DefaultErrorEnum.DATA_NULL,"param.getBusinessType() not be null");
...@@ -48,7 +54,7 @@ public class OneIdService { ...@@ -48,7 +54,7 @@ public class OneIdService {
String finalOneId = null; String finalOneId = null;
if (CollectionUtils.isNotEmpty(readyMatchOneIdFieldConfigs)) { if (CollectionUtils.isNotEmpty(readyMatchOneIdFieldConfigs)) {
for (OneIdFieldConfigDTO readyMatchOneIdFieldConfig : readyMatchOneIdFieldConfigs) { for (OneIdFieldConfigDTO readyMatchOneIdFieldConfig : readyMatchOneIdFieldConfigs) {
finalOneId = findOrCreateOneId(finalOneId, readyMatchOneIdFieldConfig); finalOneId = thiz.findOrCreateOneId(finalOneId, readyMatchOneIdFieldConfig);
} }
}else{ }else{
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "none match oneId field config, param: " + JSONObject.toJSONString(param)); throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "none match oneId field config, param: " + JSONObject.toJSONString(param));
...@@ -66,11 +72,14 @@ public class OneIdService { ...@@ -66,11 +72,14 @@ public class OneIdService {
* @author caiym * @author caiym
* @date 2023年09月21日 16:53:44 * @date 2023年09月21日 16:53:44
*/ */
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public String findOrCreateOneId(String finalOneId, OneIdFieldConfigDTO readyMatchOneIdFieldConfig){ 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.getOrgId(),
readyMatchOneIdFieldConfig.getBusinessType(), readyMatchOneIdFieldConfig.getFieldName()); readyMatchOneIdFieldConfig.getBusinessType(), readyMatchOneIdFieldConfig.getFieldName());
if (oneIdMapping == null) { if (oneIdMapping == null) {
if (StringUtils.isBlank(finalOneId)) { if (StringUtils.isBlank(finalOneId)) {
log.info("generate new oneId,fieldName:{}", readyMatchOneIdFieldConfig.getFieldName());
//TODO 雪花算法 //TODO 雪花算法
finalOneId = UUID.randomUUID().toString().replace("-", ""); finalOneId = UUID.randomUUID().toString().replace("-", "");
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime" /> <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime" />
<result column="del_flag" jdbcType="INTEGER" property="delFlag" /> <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
</resultMap> </resultMap>
<resultMap id="BOResultMap" type="cn.com.glsx.cdp.modules.model.CustomerSopJourneyBO"> <resultMap id="BOResultMap" type="cn.com.glsx.cdp.modules.model.CustomerSopJourneyBO" extends="BaseResultMap">
<association property="customer" javaType="cn.com.glsx.cdp.modules.model.CustomerBO"> <association property="customer" javaType="cn.com.glsx.cdp.modules.model.CustomerBO">
<result column="org_id" jdbcType="VARCHAR" property="orgId" /> <result column="org_id" jdbcType="VARCHAR" property="orgId" />
<result column="one_id" jdbcType="VARCHAR" property="oneId" /> <result column="one_id" jdbcType="VARCHAR" property="oneId" />
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!