Sfoglia il codice sorgente

修复 标签排除词 bug

wcc 2 anni fa
parent
commit
eb36034964
2 ha cambiato i file con 78 aggiunte e 64 eliminazioni
  1. BIN
      proposed_project/proposed_project
  2. 78 64
      proposed_project/tagTask.go

BIN
proposed_project/proposed_project


+ 78 - 64
proposed_project/tagTask.go

@@ -21,7 +21,10 @@ var TagField = map[string]string{
 }
 
 var (
-	MatchArr []TagMatching
+	//MatchArr []TagMatching
+
+	//不同标签 规则
+	ruleMatch = make(map[string][]TagMatching, 0)
 
 	SelectF = make(map[string]int)
 )
@@ -69,9 +72,14 @@ func InitRule() {
 		if v := util.ObjToString(m["qlword"]); v != "" {
 			tag.clearKey = strings.Split(util.ObjToString(m["qlword"]), ",")
 		}
-		MatchArr = append(MatchArr, tag)
+
+		rules, _ := ruleMatch[tag.tagName]
+		rules = append(rules, tag)
+		ruleMatch[tag.tagName] = rules
+	}
+	for K, v := range ruleMatch {
+		log.Info("InitRule", zap.Int(K, len(v)))
 	}
-	log.Info("InitRule", zap.Int("MatchArr", len(MatchArr)))
 }
 
 func taskRun() {
@@ -97,6 +105,7 @@ func taskRun() {
 			}()
 			tag := taskFuc(tmp)
 			update := make(map[string]interface{})
+			//项目性质
 			if tag["nature"] != "" {
 				update["nature_code"] = tag["nature"]
 				tmp["nature_code"] = tag["nature"]
@@ -104,6 +113,7 @@ func taskRun() {
 				update["nature_code"] = "00"
 				tmp["nature_code"] = "00"
 			}
+			//项目阶段
 			if tag["project_stage"] != "" {
 				update["project_stage_code"] = tag["project_stage"]
 				tmp["project_stage_code"] = tag["project_stage"]
@@ -111,6 +121,7 @@ func taskRun() {
 				update["project_stage_code"] = "00"
 				tmp["project_stage_code"] = "00"
 			}
+			//业主类型
 			if tag["owner"] != "" {
 				update["ownerclass_code"] = tag["owner"]
 				tmp["ownerclass_code"] = tag["owner"]
@@ -118,6 +129,7 @@ func taskRun() {
 				update["ownerclass_code"] = "00"
 				tmp["ownerclass_code"] = "00"
 			}
+			//项目类别
 			if tag["sub_category"] != "" {
 				update["category_code"] = tag["sub_category"]
 				tmp["category_code"] = tag["sub_category"]
@@ -146,91 +158,93 @@ func taskRun() {
 
 func taskFuc(tmp map[string]interface{}) map[string]string {
 	tag := make(map[string]string) // 打上的标签
-L:
-	for _, v := range MatchArr {
-		// 同个类型的标签如果存在,就不需要再打
-		if tag[v.tagName] != "" {
-			continue
-		}
 
-		// 排除词
-		if len(v.excludeField) > 0 && len(v.excludeKeyReg) > 0 {
-			for _, f := range v.excludeField {
-				if val := util.ObjToString(tmp[f]); val != "" {
-					for _, e1 := range v.excludeKeyReg {
-						if e1.regs != nil && e1.regs.MatchString(val) {
-							break L
-						} else {
-							// && 特殊处理
-							if strings.Contains(e1.keyStr, "&&") {
-								flag := true
-								for _, s := range strings.Split(e1.keyStr, "&&") {
-									if !strings.Contains(val, s) {
-										flag = false
-										break
+	for _, MatchArr := range ruleMatch {
+		for _, v := range MatchArr {
+			// 同个类型的标签如果存在,就不需要再打
+			if tag[v.tagName] != "" {
+				continue
+			}
+			// 排除词
+			if len(v.excludeField) > 0 && len(v.excludeKeyReg) > 0 {
+				for _, f := range v.excludeField {
+					if val := util.ObjToString(tmp[f]); val != "" {
+						for _, e1 := range v.excludeKeyReg {
+							flag := false
+							if e1.regs != nil && e1.regs.MatchString(val) {
+								flag = true
+							} else {
+								// && 特殊处理
+								if strings.Contains(e1.keyStr, "&&") {
+									for _, s := range strings.Split(e1.keyStr, "&&") {
+										if strings.Contains(val, s) {
+											flag = true
+											break
+										}
 									}
 								}
-								if flag {
-									break L
-								}
+							}
+							if flag {
+								goto L
 							}
 						}
 					}
 				}
 			}
-		}
-		// 清理词
-		if len(v.clearKey) > 0 && len(v.matchField) > 0 {
-			for _, s := range v.clearKey {
-				for _, f := range v.matchField {
-					if val := util.ObjToString(tmp[f]); val != "" {
-						tmp[f] = strings.ReplaceAll(val, s, "")
+			// 清理词
+			if len(v.clearKey) > 0 && len(v.matchField) > 0 {
+				for _, s := range v.clearKey {
+					for _, f := range v.matchField {
+						if val := util.ObjToString(tmp[f]); val != "" {
+							tmp[f] = strings.ReplaceAll(val, s, "")
+						}
 					}
 				}
 			}
-		}
-		// 关键词
-		if len(v.matchField) > 0 && len(v.matchKeyReg) > 0 {
-			for _, f := range v.matchField {
-				if val := util.ObjToString(tmp[f]); val != "" {
-					for _, r1 := range v.matchKeyReg {
-						if r1.regs.MatchString(val) {
-							if len(v.addField) > 0 && len(v.addKeyReg) > 0 {
-								// 匹配附加词
-								isCt := false
-								for _, f1 := range v.addField {
-									if v1 := util.ObjToString(tmp[f1]); v1 != "" {
-										for _, r2 := range v.addKeyReg {
-											if r2.regs != nil && r2.regs.MatchString(v1) {
-												isCt = true
-											} else {
-												// && 特殊处理
-												if strings.Contains(r2.keyStr, "&&") {
-													flag := true
-													for _, s := range strings.Split(r2.keyStr, "&&") {
-														if !strings.Contains(v1, s) {
-															flag = false
-															break
+			// 关键词
+			if len(v.matchField) > 0 && len(v.matchKeyReg) > 0 {
+				for _, f := range v.matchField {
+					if val := util.ObjToString(tmp[f]); val != "" {
+						for _, r1 := range v.matchKeyReg {
+							if r1.regs.MatchString(val) {
+								if len(v.addField) > 0 && len(v.addKeyReg) > 0 {
+									// 匹配附加词
+									isCt := false
+									for _, f1 := range v.addField {
+										if v1 := util.ObjToString(tmp[f1]); v1 != "" {
+											for _, r2 := range v.addKeyReg {
+												if r2.regs != nil && r2.regs.MatchString(v1) {
+													isCt = true
+												} else {
+													// && 特殊处理
+													if strings.Contains(r2.keyStr, "&&") {
+														flag := true
+														for _, s := range strings.Split(r2.keyStr, "&&") {
+															if !strings.Contains(v1, s) {
+																flag = false
+																break
+															}
+														}
+														if flag {
+															isCt = true
 														}
-													}
-													if flag {
-														isCt = true
 													}
 												}
 											}
 										}
 									}
-								}
-								if isCt {
+									if isCt {
+										tag[v.tagName] = v.tagCode
+									}
+								} else {
 									tag[v.tagName] = v.tagCode
 								}
-							} else {
-								tag[v.tagName] = v.tagCode
 							}
 						}
 					}
 				}
 			}
+		L:
 		}
 	}
 	return tag