Răsfoiți Sursa

wip:客户-数据验证页面-精准筛选

fuwencai 1 an în urmă
părinte
comite
bba9f1bf00

+ 85 - 14
CMPlatform/client/customerRule.go

@@ -9,6 +9,7 @@ import (
 	"cmplatform/util"
 	"cmplatform/util"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	"github.com/antonmedv/expr"
 	"github.com/lauyoume/gopinyin"
 	"github.com/lauyoume/gopinyin"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.uber.org/zap"
 	"go.uber.org/zap"
@@ -315,12 +316,14 @@ func (this *CustomerRule) DataTest(id string) {
 	//获取数据
 	//获取数据
 	title := this.GetString("title")
 	title := this.GetString("title")
 	detail := this.GetString("detail")
 	detail := this.GetString("detail")
-	fmt.Println(title, detail)
+	exactRule, exactResult := "", false
 	if title == "" && detail == "" {
 	if title == "" && detail == "" {
 		this.ServeJson(map[string]interface{}{
 		this.ServeJson(map[string]interface{}{
-			"status":  false,
-			"data":    "",
-			"message": "标题和正文至少要有一个",
+			"status":      false,
+			"data":        "",
+			"message":     "标题和正文至少要有一个",
+			"exactResult": exactResult,
+			"exactRule":   exactRule,
 		})
 		})
 		return
 		return
 	}
 	}
@@ -340,6 +343,7 @@ func (this *CustomerRule) DataTest(id string) {
 		s_globalnotkeymatch := common.ObjToString(c["s_globalnotkeymatch"])
 		s_globalnotkeymatch := common.ObjToString(c["s_globalnotkeymatch"])
 		s_globalclearkey := common.ObjToString(c["s_globalclearkey"])
 		s_globalclearkey := common.ObjToString(c["s_globalclearkey"])
 		s_globalclearkeymatch := common.ObjToString(c["s_globalclearkeymatch"])
 		s_globalclearkeymatch := common.ObjToString(c["s_globalclearkeymatch"])
+		exactRule = common.ObjToString(c["s_exactRule"])
 
 
 		//清理词匹配方式
 		//清理词匹配方式
 		cwmArr := []string{}
 		cwmArr := []string{}
@@ -384,7 +388,9 @@ func (this *CustomerRule) DataTest(id string) {
 						"info":   "全局附加词没有匹配成功",
 						"info":   "全局附加词没有匹配成功",
 						"data":   s_globaladdkey,
 						"data":   s_globaladdkey,
 					},
 					},
-					"message": "测试成功",
+					"message":     "测试成功",
+					"exactResult": exactResult,
+					"exactRule":   exactRule,
 				})
 				})
 				return
 				return
 			} else {
 			} else {
@@ -401,13 +407,15 @@ func (this *CustomerRule) DataTest(id string) {
 						"info":   "被全局排除词排除",
 						"info":   "被全局排除词排除",
 						"data":   gNKey,
 						"data":   gNKey,
 					},
 					},
-					"message": "测试成功",
+					"message":     "测试成功",
+					"exactResult": exactResult,
+					"exactRule":   exactRule,
 				})
 				})
 				return
 				return
 			}
 			}
 		}
 		}
 
 
-		var resultList []interface{}
+		var resultList []map[string]interface{}
 		for _, v := range o_rules {
 		for _, v := range o_rules {
 			matchKey = ""
 			matchKey = ""
 			key := common.ObjToString(v["s_matchkey"])
 			key := common.ObjToString(v["s_matchkey"])
@@ -416,6 +424,8 @@ func (this *CustomerRule) DataTest(id string) {
 			addkeymatch := common.ObjToString(v["s_addkeymatch"])
 			addkeymatch := common.ObjToString(v["s_addkeymatch"])
 			notkey := common.ObjToString(v["s_notkey"])
 			notkey := common.ObjToString(v["s_notkey"])
 			notkeymatch := common.ObjToString(v["s_notkeymatch"])
 			notkeymatch := common.ObjToString(v["s_notkeymatch"])
+			s_group := common.ObjToString(v["s_group"])
+
 			var tempData = map[string]interface{}{
 			var tempData = map[string]interface{}{
 				"key":         key,
 				"key":         key,
 				"keymatch":    keymatch,
 				"keymatch":    keymatch,
@@ -423,6 +433,7 @@ func (this *CustomerRule) DataTest(id string) {
 				"addkeymatch": addkeymatch,
 				"addkeymatch": addkeymatch,
 				"notkey":      notkey,
 				"notkey":      notkey,
 				"notkeymatch": notkeymatch,
 				"notkeymatch": notkeymatch,
+				"s_group":     s_group,
 			}
 			}
 			if notkey != "" {
 			if notkey != "" {
 				nKey := TestMactchKeys(notkeymatch, notkey, article)
 				nKey := TestMactchKeys(notkeymatch, notkey, article)
@@ -487,25 +498,85 @@ func (this *CustomerRule) DataTest(id string) {
 					"info":   "全局附加词匹配成功" + matchKey,
 					"info":   "全局附加词匹配成功" + matchKey,
 					"data":   "",
 					"data":   "",
 				},
 				},
-				"message": "测试成功",
+				"message":     "测试成功",
+				"exactResult": exactResult,
+				"exactRule":   exactRule,
 			})
 			})
 			return
 			return
 
 
 		} else {
 		} else {
+			nameArr := []string{}
+			data, ok := util.Mgo.Find("groups", map[string]interface{}{"ruleId": id}, nil, nil, false, -1, -1)
+			if ok && data != nil && len(*data) > 0 {
+				for _, v := range *data {
+					nameArr = append(nameArr, common.ObjToString(v["name"]))
+				}
+			}
+			exactResult = exactMatch(exactRule, resultList, nameArr)
 			this.ServeJson(map[string]interface{}{
 			this.ServeJson(map[string]interface{}{
-				"status":  true,
-				"data":    resultList,
-				"message": "测试成功",
+				"status":      true,
+				"data":        resultList,
+				"message":     "测试成功",
+				"exactResult": exactResult,
+				"exactRule":   exactRule,
 			})
 			})
 		}
 		}
 		return
 		return
 	} else {
 	} else {
 		this.ServeJson(map[string]interface{}{
 		this.ServeJson(map[string]interface{}{
-			"status":  true,
-			"data":    "",
-			"message": "初始化客户信息失败",
+			"status":      true,
+			"data":        "",
+			"message":     "初始化客户信息失败",
+			"exactResult": exactResult,
+			"exactRule":   exactRule,
 		})
 		})
 		return
 		return
 	}
 	}
 	log.Debug("测试数据是否匹配结束...")
 	log.Debug("测试数据是否匹配结束...")
 }
 }
+func exactMatch(rule string, data []map[string]interface{}, nameArr []string) bool {
+	realdata := map[string]float64{}
+	for _, v := range nameArr {
+		realdata["title_"+v] = 0
+		realdata["content_"+v] = 0
+	}
+
+	mapping := map[string]string{
+		" and ": " && ",
+		" or ":  " || ",
+		" not ": " ! ",
+	}
+
+	for k, v := range mapping {
+		rule = strings.ReplaceAll(rule, k, v)
+	}
+	//可以将编译后的表达式,存放在缓存中
+	program, err := expr.Compile(rule, expr.Env(realdata))
+	if err != nil {
+		log.Error("表达式错误 ", zap.Error(err))
+		return false
+	}
+
+	for _, v := range data {
+		if v["status"].(bool) {
+			keymatch := common.ObjToString(v["keymatch"])
+			group := common.ObjToString(v["s_group"])
+			markkey := strings.Split(common.ObjToString(v["markkey"]), ",")
+			if group != "" {
+				if strings.Contains(keymatch, "1") {
+					realdata["title_"+group] = realdata["title_"+group] + float64(len(markkey))
+				}
+				if strings.Contains(keymatch, "2") {
+					realdata["content_"+group] = realdata["content_"+group] + float64(len(markkey))
+				}
+			}
+		}
+	}
+	log.Debug("匹配结果 ", zap.Any("realdata", realdata))
+	output, err := expr.Run(program, realdata)
+	if err != nil {
+		log.Error("表达式执行错误 ", zap.Error(err))
+		return false
+	}
+	return output.(bool)
+}

+ 10 - 0
CMPlatform/web/templates/client/cuser_rule_edit.html

@@ -2483,6 +2483,16 @@
                 },
                 },
                 width: "18%"
                 width: "18%"
             },
             },
+            {"data": "s_group", width: "7%", render: function (val) {
+                    if (dataMap.i_exact !== 1) {
+                        return ""
+                    }
+                    if (val == undefined) {
+                        val = ""
+                    }
+                    return val
+                }
+            },
             {"data": "status", width: "7%"},
             {"data": "status", width: "7%"},
             {"data": "info", width: "12%"},
             {"data": "info", width: "12%"},
             {
             {