|
@@ -2,6 +2,8 @@ package history
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "fmt"
|
|
|
+
|
|
|
"log"
|
|
|
mongoutil "qfw/mongodb"
|
|
|
qu "qfw/util"
|
|
@@ -239,27 +241,158 @@ 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("测试数据是否匹配结束...")
|
|
|
+//}
|
|
|
func (this *HistoryData) DataTest(id string) {
|
|
|
+ //获取数据
|
|
|
+ title := this.GetString("title")
|
|
|
+ detail := this.GetString("detail")
|
|
|
+ fmt.Println(title,detail)
|
|
|
+ if title == "" && detail == "" {
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "status":false,
|
|
|
+ "data":"",
|
|
|
+ "message":"标题和正文至少要有一个",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ article :=map[string]interface{}{
|
|
|
+ "title":title,
|
|
|
+ "detail":detail,
|
|
|
+ }
|
|
|
+
|
|
|
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
|
|
|
- }
|
|
|
+ //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"])
|
|
@@ -272,13 +405,19 @@ func (this *HistoryData) DataTest(id string) {
|
|
|
}
|
|
|
o_rules := qu.ObjArrToMapArr(o_rule)
|
|
|
matchKey := ""
|
|
|
- //
|
|
|
+
|
|
|
if s_globaladdkey != "" {
|
|
|
- gKey := TestMactchKeys(s_globaladdkeymatch, s_globaladdkey, tmp)
|
|
|
+ gKey := TestMactchKeys(s_globaladdkeymatch, s_globaladdkey, article)
|
|
|
if gKey == "" {
|
|
|
this.ServeJson(map[string]interface{}{
|
|
|
- "result": false,
|
|
|
- "info": "全局附加词没有匹配成功",
|
|
|
+ "status":true,
|
|
|
+ "data":map[string]interface{}{
|
|
|
+ "result": false,
|
|
|
+ "info": "全局附加词没有匹配成功",
|
|
|
+ "data": s_globaladdkey,
|
|
|
+ },
|
|
|
+ "message":"测试成功",
|
|
|
+
|
|
|
})
|
|
|
return
|
|
|
} else {
|
|
@@ -286,69 +425,135 @@ func (this *HistoryData) DataTest(id string) {
|
|
|
}
|
|
|
}
|
|
|
if s_globalnotkey != "" {
|
|
|
- gNKey := TestMactchKeys(s_globalnotkeymatch, s_globalnotkey, tmp)
|
|
|
+ gNKey := TestMactchKeys(s_globalnotkeymatch, s_globalnotkey, article)
|
|
|
if gNKey != "" {
|
|
|
this.ServeJson(map[string]interface{}{
|
|
|
- "result": false,
|
|
|
- "allexcluedKey": gNKey,
|
|
|
+ "status":true,
|
|
|
+ "data":map[string]interface{}{
|
|
|
+ "result": false,
|
|
|
+ "info":"被全局排除词排除",
|
|
|
+ "data": gNKey,
|
|
|
+ },
|
|
|
+ "message":"测试成功",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ var resultList []interface{}
|
|
|
for _, v := range o_rules {
|
|
|
+ matchKey=""
|
|
|
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"])
|
|
|
+ var tempData = map[string]interface{}{
|
|
|
+ "key":key,
|
|
|
+ "keymatch":keymatch,
|
|
|
+ "addkey":addkey,
|
|
|
+ "addkeymatch":addkeymatch,
|
|
|
+ "notkey":notkey,
|
|
|
+ "notkeymatch":notkeymatch,
|
|
|
+ }
|
|
|
if notkey != "" {
|
|
|
- nKey := TestMactchKeys(notkeymatch, notkey, tmp)
|
|
|
+ nKey := TestMactchKeys(notkeymatch, notkey, article)
|
|
|
if nKey != "" {
|
|
|
- this.ServeJson(map[string]interface{}{
|
|
|
- "result": false,
|
|
|
- "excluedKey": nKey,
|
|
|
- })
|
|
|
- return
|
|
|
+ tempData["status"] = false
|
|
|
+ tempData["info"] = "排除词排除"
|
|
|
+ tempData["data"] = nKey
|
|
|
+ resultList = append(resultList,tempData)
|
|
|
+ continue
|
|
|
+ //this.ServeJson(map[string]interface{}{
|
|
|
+ // "status":true,
|
|
|
+ // "data":map[string]interface{}{
|
|
|
+ // "result": false,
|
|
|
+ // "data": nKey,
|
|
|
+ // "info":"被排除词排除",
|
|
|
+ // },
|
|
|
+ // "message":"测试成功",
|
|
|
+ //})
|
|
|
+ //return
|
|
|
}
|
|
|
}
|
|
|
if key != "" {
|
|
|
- sKey := TestMactchKeys(keymatch, key, tmp)
|
|
|
+ sKey := TestMactchKeys(keymatch, key, article)
|
|
|
aKey := ""
|
|
|
if addkey != "" {
|
|
|
- aKey = TestMactchKeys(addkeymatch, addkey, tmp)
|
|
|
+ aKey = TestMactchKeys(addkeymatch, addkey, article)
|
|
|
if aKey != "" && sKey != "" {
|
|
|
- if matchKey != "" {
|
|
|
- matchKey += ","
|
|
|
- }
|
|
|
matchKey = aKey + "," + sKey
|
|
|
- break
|
|
|
+ tempData["status"] = true
|
|
|
+ tempData["info"] = "匹配成功"
|
|
|
+ tempData["data"] = matchKey
|
|
|
+ resultList = append(resultList,tempData)
|
|
|
+
|
|
|
+
|
|
|
+ }else if aKey == "" {
|
|
|
+ tempData["status"] = false
|
|
|
+ tempData["info"] = "附加词匹配失败"
|
|
|
+ tempData["data"] = ""
|
|
|
+ resultList = append(resultList,tempData)
|
|
|
+
|
|
|
+ }else if sKey == "" {
|
|
|
+ tempData["status"] = false
|
|
|
+ tempData["info"] = "关键词匹配失败"
|
|
|
+ tempData["data"] = ""
|
|
|
+ resultList = append(resultList,tempData)
|
|
|
+
|
|
|
}
|
|
|
} else {
|
|
|
if sKey != "" {
|
|
|
- if matchKey != "" {
|
|
|
- matchKey += ","
|
|
|
- }
|
|
|
matchKey = sKey
|
|
|
- break
|
|
|
+ tempData["status"] = true
|
|
|
+ tempData["info"] = "匹配成功"
|
|
|
+ tempData["data"] = matchKey
|
|
|
+ resultList = append(resultList,tempData)
|
|
|
+
|
|
|
+ }else {
|
|
|
+
|
|
|
+ matchKey = sKey
|
|
|
+ tempData["status"] = false
|
|
|
+ tempData["info"] = "关键词匹配失败"
|
|
|
+ tempData["data"] = matchKey
|
|
|
+ resultList = append(resultList,tempData)
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if matchKey == "" {
|
|
|
+ if resultList == nil{
|
|
|
this.ServeJson(map[string]interface{}{
|
|
|
- "result": false,
|
|
|
- "info": "没有匹配成功",
|
|
|
+ "status":true,
|
|
|
+ "data":map[string]interface{}{
|
|
|
+ "result": true,
|
|
|
+ "info":"全局附加词匹配成功"+matchKey,
|
|
|
+ "data": "",
|
|
|
+ },
|
|
|
+ "message":"测试成功",
|
|
|
})
|
|
|
+ return
|
|
|
+
|
|
|
} else {
|
|
|
this.ServeJson(map[string]interface{}{
|
|
|
- "result": true,
|
|
|
- "matchKey": matchKey,
|
|
|
+ "status": true,
|
|
|
+ "data": resultList,
|
|
|
+ "message": "测试成功",
|
|
|
})
|
|
|
}
|
|
|
return
|
|
|
} else {
|
|
|
+
|
|
|
+
|
|
|
log.Println("初始化客户信息失败")
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "status":true,
|
|
|
+ "data":"",
|
|
|
+ "message":"初始化客户信息失败",
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
log.Println("测试数据是否匹配结束...")
|
|
|
-}
|
|
|
+}
|