Browse Source

Merge branch 'dev1.3' of http://192.168.3.207:10080/qmx/datatag into dev1.3

jiaojiao7 4 năm trước cách đây
mục cha
commit
3bf7ca8fed

+ 115 - 0
src/history/historytask.go

@@ -20,6 +20,7 @@ type HistoryData struct {
 	historyClone    xweb.Mapper `xweb:"/service/historyClone/(.*)"`
 	historyRuleEdit xweb.Mapper `xweb:"/service/historyRule/edit"`
 	productData     xweb.Mapper `xweb:"/service/history/produce"` //历史数据生成预览数据
+	dataTest        xweb.Mapper `xweb:"/service/dataTest/(.*)"`
 }
 
 func (this *HistoryData) HistoryTask(history_id string) {
@@ -238,3 +239,117 @@ func (this *HistoryData) ProductData() {
 		})
 	}
 }
+
+func (this *HistoryData) DataTest(id string) {
+	log.Println("测试数据是否匹配开始...")
+	dataId := this.GetString("id")
+	log.Println("id", id)
+	log.Println("dataId", dataId)
+	//加载一个客户
+	customer, _ := Mgo.Find("cuserdepartrule", map[string]interface{}{"_id": mongoutil.StringTOBsonId(id)}, nil, nil, false, -1, -1)
+	if len(*customer) == 1 {
+		c := (*customer)[0]
+		tmps := Es.GetByIdField(Index, Itype, dataId, "")
+		tmp := map[string]interface{}{}
+		if tmps != nil {
+			tmp = *tmps
+		}
+		if len(tmp) == 0 {
+			this.ServeJson(map[string]interface{}{
+				"result": false,
+				"info":   "没有查到此数据",
+			})
+			return
+		}
+		s_globaladdkey := qu.ObjToString(c["s_globaladdkey"])
+		s_globaladdkeymatch := qu.ObjToString(c["s_globaladdkeymatch"])
+		s_globalnotkey := qu.ObjToString(c["s_globalnotkey"])
+		s_globalnotkeymatch := qu.ObjToString(c["s_globalnotkeymatch"])
+		// s_globalclearkey := qu.ObjToString(c["s_globalclearkey"])
+		// s_globalclearkeymatch := qu.ObjToString(c["s_globalclearkeymatch"])
+		o_rule, ok := c["o_rules"].([]interface{})
+		if !ok {
+			o_rule = []interface{}{}
+		}
+		o_rules := qu.ObjArrToMapArr(o_rule)
+		matchKey := ""
+		//
+		if s_globaladdkey != "" {
+			gKey := TestMactchKeys(s_globaladdkeymatch, s_globaladdkey, tmp)
+			if gKey == "" {
+				this.ServeJson(map[string]interface{}{
+					"result": false,
+					"info":   "全局附加词没有匹配成功",
+				})
+				return
+			} else {
+				matchKey = gKey
+			}
+		}
+		if s_globalnotkey != "" {
+			gNKey := TestMactchKeys(s_globalnotkeymatch, s_globalnotkey, tmp)
+			if gNKey != "" {
+				this.ServeJson(map[string]interface{}{
+					"result":        false,
+					"allexcluedKey": gNKey,
+				})
+				return
+			}
+		}
+		for _, v := range o_rules {
+			key := qu.ObjToString(v["s_matchkey"])
+			keymatch := qu.ObjToString(v["s_keymatch"])
+			addkey := qu.ObjToString(v["s_addkey"])
+			addkeymatch := qu.ObjToString(v["s_addkeymatch"])
+			notkey := qu.ObjToString(v["s_notkey"])
+			notkeymatch := qu.ObjToString(v["s_notkeymatch"])
+			if notkey != "" {
+				nKey := TestMactchKeys(notkeymatch, notkey, tmp)
+				if nKey != "" {
+					this.ServeJson(map[string]interface{}{
+						"result":     false,
+						"excluedKey": nKey,
+					})
+					return
+				}
+			}
+			if key != "" {
+				sKey := TestMactchKeys(keymatch, key, tmp)
+				aKey := ""
+				if addkey != "" {
+					aKey = TestMactchKeys(addkeymatch, addkey, tmp)
+					if aKey != "" && sKey != "" {
+						if matchKey != "" {
+							matchKey += ","
+						}
+						matchKey = aKey + "," + sKey
+						break
+					}
+				} else {
+					if sKey != "" {
+						if matchKey != "" {
+							matchKey += ","
+						}
+						matchKey = sKey
+						break
+					}
+				}
+			}
+		}
+		if matchKey == "" {
+			this.ServeJson(map[string]interface{}{
+				"result": false,
+				"info":   "没有匹配成功",
+			})
+		} else {
+			this.ServeJson(map[string]interface{}{
+				"result":   true,
+				"matchKey": matchKey,
+			})
+		}
+		return
+	} else {
+		log.Println("初始化客户信息失败")
+	}
+	log.Println("测试数据是否匹配结束...")
+}

+ 41 - 0
src/history/task.go

@@ -687,3 +687,44 @@ func KeyWordToDatas(types, item, key string, keyWord []string) []string {
 	}
 	return keyWord
 }
+
+func TestMactchKeys(types, key string, data map[string]interface{}) string {
+	keyWord := []string{}
+	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, ",")
+}

+ 22 - 0
src/web/templates/com/modal.html

@@ -255,6 +255,28 @@
     </div><!-- /.modal -->
 </div>
 
+<div class="modal fade" id="modal-dataTest" tabindex="-1" role="dialog" aria-hidden="true">
+    <div class="modal-dialog" style="width: 30%">
+        <div class="modal-content">
+            <div class="modal-header">
+                <div class="modal-header">
+                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">数据ID</label>
+                        <div class="col-sm-10">
+                            <input class="form-control" style="max-width: 100%" placeholder="请输入数据ID"
+                                      id="dataTest-txt"></div>
+                        
+                    </div>
+                </div>
+                <div class="modal-footer">
+                    <input type="button" onclick="dataTests()" class="btn btn-primary saveBtn" value="确定">
+                </div>
+            </div>
+        </div>
+    </div><!-- /.modal -->
+</div>
+
 <script>
     //通用标签列表
     function importcomrule() {

+ 36 - 0
src/web/templates/private/cuser_rule_create.html

@@ -28,6 +28,8 @@
                 </button>
                 <button class="btn btn-danger btn-sm" onclick="archive()"><i class="fa fa-fw fa-save fa-lg"></i>存档
                 </button>
+                <button class="btn tn-info btn-sm" onclick="dataTest()"><i class="fa fa-fw fa-save fa-lg"></i>测试数据
+                </button>
             </small>
         </h1>
         <ol class="breadcrumb">
@@ -1873,4 +1875,38 @@
         }
         return {flag: flag, v1: v1, v2: v2}
     }
+    
+    function dataTest() {
+        $("#modal-dataTest").modal('show');
+    }
+    function dataTests() {
+        var val = $("#dataTest-txt").val()
+        $.ajax({
+            url: "/service/dataTest/"+ dataMap["id"],
+            type: "post",
+            data: {"id": val},
+            success: function (r) {
+                if (r.result) {
+                    showTip("匹配成功,匹配词 " + r.matchKey, 6000);
+                } else {
+                    var str = "";
+                    if (r.info != "" && r.info != null && r.info != undefined){
+                        str = r.info
+                        showTip(str, 6000);
+                        return
+                    }
+                    if (r.allexcluedKey != "") {
+                        str = "匹配失败,被全局排除词 "+ r.allexcluedKey + " 排除";
+                        showTip(str, 6000);
+                        return 
+                    }
+                    if (r.excluedKey != "") {
+                        str = "匹配失败,被排除词 "+ r.excluedKey + " 排除";
+                        showTip(str, 6000);
+                        return
+                    }
+                }
+            }
+        })
+    }
 </script>

+ 36 - 0
src/web/templates/private/cuser_rule_edit.html

@@ -24,6 +24,8 @@
                 </button>
                 <button class="btn btn-danger btn-sm" onclick="archive()"><i class="fa fa-fw fa-save fa-lg"></i>存档
                 </button>
+                <button class="btn tn-info btn-sm" onclick="dataTest()"><i class="fa fa-fw fa-save fa-lg"></i>测试数据
+                </button>
             </small>
         </h1>
         <ol class="breadcrumb">
@@ -1936,4 +1938,38 @@
         }
         return {flag: flag, v1: v1, v2: v2}
     }
+    
+    function dataTest() {
+        $("#modal-dataTest").modal('show');
+    }
+    function dataTests() {
+        var val = $("#dataTest-txt").val()
+        $.ajax({
+            url: "/service/dataTest/"+ dataMap["id"],
+            type: "post",
+            data: {"id": val},
+            success: function (r) {
+                if (r.result) {
+                    showTip("匹配成功,匹配词 " + r.matchKey, 6000);
+                } else {
+                    var str = "";
+                    if (r.info != "" && r.info != null && r.info != undefined){
+                        str = r.info
+                        showTip(str, 6000);
+                        return
+                    }
+                    if (r.allexcluedKey != "") {
+                        str = "匹配失败,被全局排除词 "+ r.allexcluedKey + " 排除";
+                        showTip(str, 6000);
+                        return 
+                    }
+                    if (r.excluedKey != "") {
+                        str = "匹配失败,被排除词 "+ r.excluedKey + " 排除";
+                        showTip(str, 6000);
+                        return
+                    }
+                }
+            }
+        })
+    }
 </script>