xuzhiheng před 5 roky
rodič
revize
ebf0faed93

+ 4 - 3
customerdata/src/datamodel.go

@@ -1,10 +1,10 @@
 package main
 
 import (
-	"gopkg.in/mgo.v2/bson"
 	"regexp"
 	"sync"
-	
+
+	"gopkg.in/mgo.v2/bson"
 )
 
 //客户模型
@@ -38,7 +38,7 @@ type Department struct {
 type SearchRule struct { //一条查询规则
 	ID           string
 	Name         string
-	ExtFieldType int					//规则1、标准字段包,2、高级字段包
+	ExtFieldType int                    //规则1、标准字段包,2、高级字段包
 	CustomerID   string                 //所属客户id
 	DepartmentID string                 //所属部门id
 	EsQuery      string                 //客户所有标签的es语句
@@ -46,6 +46,7 @@ type SearchRule struct { //一条查询规则
 	GCW          *ClearWord             //全局清理词
 	KW           []*KeyWord             //多组关键词(与附加词一一对应)
 	AW           []*AddWord             //多组附加词(与关键词一一对应)
+	Maths        []map[string]string
 	//RuleData     *sync.Map              //key:规则id;val:某个规则查出的数据
 }
 

+ 88 - 2
customerdata/src/task.go

@@ -319,9 +319,9 @@ func (c *Customer) GetData(stype string) {
 								*/
 								qu.Debug("---------------------", id, IsMatch, matchKey)
 								if IsMatch { //匹配成功,数据上新增规则id,matchKey,item并临时保存数据
-									tmpMatchKey := MapDataToArr(matchKey)
+									// tmpMatchKey := MapDataToArr(matchKey)
 									tmpMatchKeyType := MapDataToArr(matchKeyType)
-									tmp["matchkey"] = strings.Join(tmpMatchKey, ",")
+									tmp["matchkey"] = GetMactchKeys(sr.Maths, tmp)
 									tmp["matchtype"] = strings.Join(tmpMatchKeyType, ",")
 									tmp["ruleid"] = sr.ID
 									tmp["rulename"] = sr.Name
@@ -560,6 +560,23 @@ func (d *Department) GetSearchRules(cid, stype string, idRange bson.M) {
 			//获取全局清理词
 			SR.GetClearWord(clearKey, clearKeyMatch)
 			d.Rules = append(d.Rules, SR)
+			//
+			if orules1, ok := sr["o_rules"].([]interface{}); ok {
+				for _, v := range orules1 {
+					orule, _ := v.(map[string]interface{})
+					SR.Maths = append(SR.Maths, map[string]string{
+						"s_matchkey": qu.ObjToString(orule["s_matchkey"]),
+						"s_keymatch": qu.ObjToString(orule["s_keymatch"]),
+					})
+				}
+			} else if orules2, ok := sr["o_rules"].([]map[string]interface{}); ok {
+				for _, v := range orules2 {
+					SR.Maths = append(SR.Maths, map[string]string{
+						"s_matchkey": qu.ObjToString(v["s_matchkey"]),
+						"s_keymatch": qu.ObjToString(v["s_keymatch"]),
+					})
+				}
+			}
 		}
 	}
 }
@@ -652,3 +669,72 @@ func (tr *TagRule) GetKeyAddNotKeyWord(o_list primitive.A) {
 	//tr.Fields = fields
 	tr.TagNames = tagnames
 }
+
+func GetMactchKeys(match []map[string]string, data map[string]interface{}) string {
+	keyWord := []string{}
+	for _, keys := range match {
+		types := keys["s_keymatch"]
+		key := keys["s_matchkey"]
+		if strings.Contains(types, "1") {
+			title := qu.ObjToString(data["title"])
+			keyWord = KeyWordToDatas(types, title, key, keyWord)
+		}
+		if strings.Contains(types, "2") {
+			detail := qu.ObjToString(data["detail"])
+			keyWord = KeyWordToDatas(types, detail, key, keyWord)
+		}
+		if strings.Contains(types, "3") {
+			purchasing := qu.ObjToString(data["purchasing"])
+			keyWord = KeyWordToDatas(types, purchasing, key, keyWord)
+		}
+		if strings.Contains(types, "4") {
+			filetext := qu.ObjToString(data["filetext"])
+			keyWord = KeyWordToDatas(types, filetext, key, keyWord)
+		}
+		if strings.Contains(types, "5") {
+			projectname := qu.ObjToString(data["projectname"])
+			keyWord = KeyWordToDatas(types, projectname, key, keyWord)
+		}
+		if strings.Contains(types, "6") || strings.Contains(types, "8") {
+			buyer := qu.ObjToString(data["buyer"])
+			keyWord = KeyWordToDatas(types, buyer, key, keyWord)
+		}
+		if strings.Contains(types, "7") || strings.Contains(types, "9") {
+			winner := qu.ObjToString(data["s_winner"])
+			keyWord = KeyWordToDatas(types, winner, key, keyWord)
+		}
+	}
+	keyMap := map[string]bool{}
+	keyArr := []string{}
+	for _, key := range keyWord {
+		keyMap[key] = true
+	}
+	for k, _ := range keyMap {
+		keyArr = append(keyArr, k)
+	}
+	return strings.Join(keyArr, ",")
+}
+
+func KeyWordToDatas(types, item, key string, keyWord []string) []string {
+	for _, mk := range strings.Split(key, ",") {
+		if strings.Contains(mk, "&&") {
+			arr := strings.Split(mk, "&&")
+			isok := true
+			for _, s := range arr {
+				if s != "" {
+					if !strings.Contains(item, s) {
+						isok = false
+					}
+				}
+			}
+			if isok {
+				keyWord = append(keyWord, mk)
+			}
+		} else {
+			if strings.Contains(item, mk) {
+				keyWord = append(keyWord, mk)
+			}
+		}
+	}
+	return keyWord
+}

+ 1 - 1
src/history/datamodel.go

@@ -119,7 +119,7 @@ type SearchRule struct { //一条查询规则
 	GCW          *ClearWord             //全局清理词
 	KW           []*KeyWord             //多组关键词(与附加词一一对应)
 	AW           []*AddWord             //多组附加词(与关键词一一对应)
-	//RuleData     *sync.Map              //key:规则id;val:某个规则查出的数据
+	Maths        []map[string]string
 }
 
 //打标签规则模型

+ 89 - 3
src/history/task.go

@@ -97,7 +97,6 @@ func (c *Customer) GetData(stype string) {
 	defer Es.DestoryEsConn(client)
 	for _, dm := range c.Departments {
 		for _, sr := range dm.Rules {
-
 			//测试
 			// MgoDataTest(sr, dm, c)
 			// return
@@ -260,9 +259,10 @@ func (c *Customer) GetData(stype string) {
 								*/
 								qu.Debug("---------------------", id, IsMatch)
 								if IsMatch { //匹配成功,数据上新增规则id,matchKey,item并临时保存数据
-									tmpMatchKey := MapDataToArr(matchKey)
+									// tmpMatchKey := MapDataToArr(matchKey)
 									tmpMatchKeyType := MapDataToArr(matchKeyType)
-									tmp["matchkey"] = strings.Join(tmpMatchKey, ",")
+									tmp["matchkey"] = GetMactchKeys(sr.Maths, tmp)
+									log.Println("matchkey", tmp["matchkey"])
 									tmp["matchtype"] = strings.Join(tmpMatchKeyType, ",")
 									tmp["ruleid"] = sr.ID
 									tmp["rulename"] = sr.Name
@@ -502,6 +502,23 @@ func (d *Department) GetSearchRules(cid, stype string, idRange bson.M, searchRul
 			//获取全局清理词
 			SR.GetClearWord(clearKey, clearKeyMatch)
 			d.Rules = append(d.Rules, SR)
+			//
+			if orules1, ok := sr["o_rules"].([]interface{}); ok {
+				for _, v := range orules1 {
+					orule, _ := v.(map[string]interface{})
+					SR.Maths = append(SR.Maths, map[string]string{
+						"s_matchkey": qu.ObjToString(orule["s_matchkey"]),
+						"s_keymatch": qu.ObjToString(orule["s_keymatch"]),
+					})
+				}
+			} else if orules2, ok := sr["o_rules"].([]map[string]interface{}); ok {
+				for _, v := range orules2 {
+					SR.Maths = append(SR.Maths, map[string]string{
+						"s_matchkey": qu.ObjToString(v["s_matchkey"]),
+						"s_keymatch": qu.ObjToString(v["s_keymatch"]),
+					})
+				}
+			}
 		}
 	}
 }
@@ -594,3 +611,72 @@ func (tr *TagRule) GetKeyAddNotKeyWord(o_list []map[string]interface{}) {
 	//tr.Fields = fields
 	tr.TagNames = tagnames
 }
+
+func GetMactchKeys(match []map[string]string, data map[string]interface{}) string {
+	keyWord := []string{}
+	for _, keys := range match {
+		types := keys["s_keymatch"]
+		key := keys["s_matchkey"]
+		if strings.Contains(types, "1") {
+			title := qu.ObjToString(data["title"])
+			keyWord = KeyWordToDatas(types, title, key, keyWord)
+		}
+		if strings.Contains(types, "2") {
+			detail := qu.ObjToString(data["detail"])
+			keyWord = KeyWordToDatas(types, detail, key, keyWord)
+		}
+		if strings.Contains(types, "3") {
+			purchasing := qu.ObjToString(data["purchasing"])
+			keyWord = KeyWordToDatas(types, purchasing, key, keyWord)
+		}
+		if strings.Contains(types, "4") {
+			filetext := qu.ObjToString(data["filetext"])
+			keyWord = KeyWordToDatas(types, filetext, key, keyWord)
+		}
+		if strings.Contains(types, "5") {
+			projectname := qu.ObjToString(data["projectname"])
+			keyWord = KeyWordToDatas(types, projectname, key, keyWord)
+		}
+		if strings.Contains(types, "6") || strings.Contains(types, "8") {
+			buyer := qu.ObjToString(data["buyer"])
+			keyWord = KeyWordToDatas(types, buyer, key, keyWord)
+		}
+		if strings.Contains(types, "7") || strings.Contains(types, "9") {
+			winner := qu.ObjToString(data["s_winner"])
+			keyWord = KeyWordToDatas(types, winner, key, keyWord)
+		}
+	}
+	keyMap := map[string]bool{}
+	keyArr := []string{}
+	for _, key := range keyWord {
+		keyMap[key] = true
+	}
+	for k, _ := range keyMap {
+		keyArr = append(keyArr, k)
+	}
+	return strings.Join(keyArr, ",")
+}
+
+func KeyWordToDatas(types, item, key string, keyWord []string) []string {
+	for _, mk := range strings.Split(key, ",") {
+		if strings.Contains(mk, "&&") {
+			arr := strings.Split(mk, "&&")
+			isok := true
+			for _, s := range arr {
+				if s != "" {
+					if !strings.Contains(item, s) {
+						isok = false
+					}
+				}
+			}
+			if isok {
+				keyWord = append(keyWord, mk)
+			}
+		} else {
+			if strings.Contains(item, mk) {
+				keyWord = append(keyWord, mk)
+			}
+		}
+	}
+	return keyWord
+}

+ 6 - 2
src/util/utiltag.go

@@ -679,13 +679,17 @@ func KeyWordToData(types, item, key string, keyWord []string) []string {
 	for _, mk := range strings.Split(key, ",") {
 		if strings.Contains(mk, "&&") {
 			arr := strings.Split(mk, "&&")
+			isok := true
 			for _, s := range arr {
 				if s != "" {
-					if strings.Contains(item, s) {
-						keyWord = append(keyWord, s)
+					if !strings.Contains(item, s) {
+						isok = false
 					}
 				}
 			}
+			if isok {
+				keyWord = append(keyWord, mk)
+			}
 		} else {
 			if strings.Contains(item, mk) {
 				keyWord = append(keyWord, mk)