Browse Source

关键词去重

WH01243 2 years ago
parent
commit
5cea67078e
1 changed files with 62 additions and 6 deletions
  1. 62 6
      jyBXSubscribe/rpc/model/push.go

+ 62 - 6
jyBXSubscribe/rpc/model/push.go

@@ -1615,7 +1615,6 @@ func MapToarr(data map[string][]interface{}, userType string) []*bxsubscribe.Key
 			}
 			keyArr = append(keyArr, keys)
 		}
-
 		if userType == SubFreeFlag {
 			k = ""
 		}
@@ -1628,10 +1627,67 @@ func MapToarr(data map[string][]interface{}, userType string) []*bxsubscribe.Key
 }
 
 func MergeArray(dest []interface{}, src []interface{}) (result []interface{}) {
-	result = make([]interface{}, len(dest)+len(src))
-	//将第一个数组传入result
-	copy(result, dest)
-	//将第二个数组接在尾部,也就是 len(dest):
-	copy(result[len(dest):], src)
+	data := map[string]interface{}{}
+	for _, v := range common.ObjArrToMapArr(dest) {
+		notkey := ""
+		key := ""
+		matchway := ""
+		appendkey := ""
+		if v["notkey"] != nil {
+			otkeyArr := common.ObjArrToStringArr(v["notkey"].([]interface{}))
+			for _, keyV := range otkeyArr {
+				notkey += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
+			}
+		}
+		if v["key"] != nil {
+			keyArr := common.ObjArrToStringArr(v["key"].([]interface{}))
+			for _, keyV := range keyArr {
+				key += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
+			}
+		}
+		if v["matchway"] != nil {
+			matchway = common.InterfaceToStr(v["matchway"])
+		}
+		if v["appendkey"] != nil {
+			appendkeyArr := common.ObjArrToStringArr(v["appendkey"].([]interface{}))
+			for _, keyV := range appendkeyArr {
+				appendkey += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
+			}
+		}
+		k := fmt.Sprintf("%s_____%s_____%s_____%s", notkey, key, matchway, appendkey)
+		data[k] = v
+	}
+	for _, v := range common.ObjArrToMapArr(src) {
+		notkey := ""
+		key := ""
+		matchway := ""
+		appendkey := ""
+		if v["notkey"] != nil {
+			otkeyArr := common.ObjArrToStringArr(v["notkey"].([]interface{}))
+			for _, keyV := range otkeyArr {
+				notkey += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
+			}
+		}
+		if v["key"] != nil {
+			keyArr := common.ObjArrToStringArr(v["key"].([]interface{}))
+			for _, keyV := range keyArr {
+				key += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
+			}
+		}
+		if v["matchway"] != nil {
+			matchway = common.InterfaceToStr(v["matchway"])
+		}
+		if v["appendkey"] != nil {
+			appendkeyArr := common.ObjArrToStringArr(v["appendkey"].([]interface{}))
+			for _, keyV := range appendkeyArr {
+				appendkey += fmt.Sprintf(",%s", common.InterfaceToStr(keyV))
+			}
+		}
+		k := fmt.Sprintf("%s_____%s_____%s_____%s", notkey, key, matchway, appendkey)
+		data[k] = v
+	}
+	for _, v := range data {
+		result = append(result, v)
+	}
 	return
 }