Commit e3f6f9b6 by ThomasAdv

更新模型数据处理

1 parent c84a0173
......@@ -39,7 +39,7 @@ public class ModelFieldMapping implements Serializable {
* 合并规则 (1-非空优先2-最后一次入库优先3-第一次入库优先4-时间最小5-时间最大)
*/
@Column(name = "union_rule")
private Integer unionRule;
private Byte unionRule;
/**
* 模型识别标识:1
......
......@@ -63,7 +63,6 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
<scope>provided</scope>
</dependency>
<dependency>
......
package cn.com.glsx.cdp.common.constant;
public class ModelFieldConstants {
public final static String ORGID = "orgId";
public final static String ADD_WAY = "addWay";
public final static String ORGID = "org_id";
public final static String ADD_WAY = "add_way";
public final static String EX_JSON = "ex_json";
}
package cn.com.glsx.cdp.modules.enums;
public enum ModelFieldUnionRuleEnum {
LAST_PRO((byte)1, "最后一次入库优先"),
FIRST_PRO((byte)2,"第一次入库优先"),
MIN_TIME_PRO((byte)3,"时间最小优先"),
MAX_TIME_PRO((byte)4, "时间最大优先");
private final Byte value;
private final String displayText;
ModelFieldUnionRuleEnum(Byte value, String displayText){
this.value = value;
this.displayText = displayText;
}
public Byte getValue() {
return value;
}
public String getDisplayText() {
return displayText;
}
public static ModelFieldUnionRuleEnum getByValue(Byte value){
if (value != null) {
for (ModelFieldUnionRuleEnum modelFieldUnionRuleEnum : ModelFieldUnionRuleEnum.values()) {
if (modelFieldUnionRuleEnum.getValue().equals(value)) {
return modelFieldUnionRuleEnum;
}
}
}
return null;
}
}
......@@ -8,6 +8,7 @@ import lombok.ToString;
import lombok.experimental.SuperBuilder;
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
......
......@@ -2,6 +2,7 @@ package cn.com.glsx.cdp.modules.queue;
import cn.com.glsx.cdp.common.constant.ModelFieldConstants;
import cn.com.glsx.cdp.config.RabbitMQConfig;
import cn.com.glsx.cdp.modules.enums.ModelFieldUnionRuleEnum;
import cn.com.glsx.cdp.modules.enums.OneIdBelongEnum;
import cn.com.glsx.cdp.modules.model.ModelDTO;
import cn.com.glsx.cdp.modules.model.ModelFieldMappingDTO;
......@@ -128,8 +129,103 @@ public class DataReportRabbitMQConsumer {
* @date 2023年09月15日 17:24:15
*/
private Map<String, Object> mergeModelData(ModelDTO modelDTO, Map<String, Object> existModelData) {
//TODO 合并模型数据
return null;
Map<String, ModelFieldMappingDTO> newDataMap = getNewDataMap(modelDTO);
Map<String, Object> mergeResultMap = new HashMap<>();
for (Map.Entry<String, ModelFieldMappingDTO> newDataMapEntry : newDataMap.entrySet()) {
String fieldName = newDataMapEntry.getKey();
mergeResultMap.put(fieldName, mergeField(newDataMapEntry.getValue(), existModelData.get(fieldName)));
}
return mergeResultMap;
}
/**
* 合并字段
*
* @param newDataModelFieldMapping
* @param oldValue
* @return java.lang.Object
* @author caiym
* @date 2023年09月19日 19:57:08
*/
private Object mergeField(ModelFieldMappingDTO newDataModelFieldMapping, Object oldValue) {
if (newDataModelFieldMapping == null) {
return oldValue;
}
ModelFieldUnionRuleEnum modelFieldUnionRuleEnum = ModelFieldUnionRuleEnum.getByValue(newDataModelFieldMapping.getUnionRule());
return mergeField(modelFieldUnionRuleEnum, oldValue, newDataModelFieldMapping.getFieldValue());
}
/**
* 合并字段
*
* @param unionRuleEnum
* @param oldValue
* @param newValue
* @return java.lang.Object
* @author caiym
* @date 2023年09月19日 19:57:19
*/
private Object mergeField(ModelFieldUnionRuleEnum unionRuleEnum, Object oldValue, Object newValue) {
if (unionRuleEnum != null) {
switch (unionRuleEnum) {
case FIRST_PRO:
return oldValue;
case LAST_PRO:
return newValue == null? oldValue: newValue;
case MAX_TIME_PRO:
if (oldValue instanceof Date && newValue instanceof Date) {
if (((Date) oldValue).after((Date) newValue)) {
return oldValue;
}else{
return newValue;
}
}
case MIN_TIME_PRO:
if (oldValue instanceof Date && newValue instanceof Date) {
if (((Date) oldValue).after((Date) newValue)) {
return newValue;
}else{
return oldValue;
}
}
default:
}
}
if (newValue instanceof String) {
return ((String) newValue).isEmpty() ? oldValue : newValue;
} else {
return newValue == null ? oldValue : newValue;
}
}
/**
* 获取新数据map
*
* @param modelDTO
* @return java.util.Map<java.lang.String,cn.com.glsx.cdp.modules.model.ModelFieldMappingDTO>
* @author caiym
* @date 2023年09月19日 19:57:43
*/
private static Map<String, ModelFieldMappingDTO> getNewDataMap(ModelDTO modelDTO) {
Map<String, ModelFieldMappingDTO> newDataMap = new HashMap<>();
JSONObject exJson = new JSONObject();
for (ModelFieldMappingDTO modelFieldMapping : modelDTO.getModelFieldMappings()) {
if (modelFieldMapping.getExpandFlag() != null && modelFieldMapping.getExpandFlag()) {
exJson.put(modelFieldMapping.getFieldName(), modelFieldMapping.getFieldValue());
}else {
newDataMap.put(modelFieldMapping.getFieldName(), modelFieldMapping);
}
}
if (exJson.size() > 0) {
ModelFieldMappingDTO modelFieldMapping = ModelFieldMappingDTO.builder().unionRule(ModelFieldUnionRuleEnum.LAST_PRO.getValue()).fieldName(ModelFieldConstants.EX_JSON).fieldValue(exJson.toJSONString()).build();
newDataMap.put(ModelFieldConstants.EX_JSON, modelFieldMapping);
}
return newDataMap;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!