|
@@ -1,6 +1,7 @@
|
|
package history
|
|
package history
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "context"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"log"
|
|
"log"
|
|
mongoutil "qfw/mongodb"
|
|
mongoutil "qfw/mongodb"
|
|
@@ -9,15 +10,19 @@ import (
|
|
. "sqlmodel"
|
|
. "sqlmodel"
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
|
|
+ "time"
|
|
. "util"
|
|
. "util"
|
|
|
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
|
|
|
// "go.mongodb.org/mongo-driver/bson/primitive"
|
|
// "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
+ esv "es"
|
|
|
|
+
|
|
|
|
+ esV7 "github.com/olivere/elastic"
|
|
es "gopkg.in/olivere/elastic.v1"
|
|
es "gopkg.in/olivere/elastic.v1"
|
|
)
|
|
)
|
|
|
|
|
|
-//获取客户打标签规则
|
|
|
|
|
|
+// 获取客户打标签规则
|
|
func (c *Customer) GetTagRules(tagRules []map[string]interface{}) {
|
|
func (c *Customer) GetTagRules(tagRules []map[string]interface{}) {
|
|
log.Println("开始加载标签规则...")
|
|
log.Println("开始加载标签规则...")
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
@@ -53,7 +58,7 @@ func (c *Customer) GetTagRules(tagRules []map[string]interface{}) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//获取部门信息
|
|
|
|
|
|
+// 获取部门信息
|
|
func (c *Customer) GetDepartments(stype string, departments []map[string]interface{}) {
|
|
func (c *Customer) GetDepartments(stype string, departments []map[string]interface{}) {
|
|
log.Println("开始获取部门信息...")
|
|
log.Println("开始获取部门信息...")
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
@@ -89,12 +94,24 @@ func (c *Customer) GetDepartments(stype string, departments []map[string]interfa
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//获取数据
|
|
|
|
|
|
+// 获取数据
|
|
func (c *Customer) GetData(stype string, dataSource int) {
|
|
func (c *Customer) GetData(stype string, dataSource int) {
|
|
log.Println("开始匹配数据...")
|
|
log.Println("开始匹配数据...")
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
- client := Es.GetEsConn()
|
|
|
|
- defer Es.DestoryEsConn(client)
|
|
|
|
|
|
+ esConfig := Sysconfig["es"].(map[string]interface{})
|
|
|
|
+ esversion := qu.ObjToString(esConfig["version"])
|
|
|
|
+ if esversion == "v1" {
|
|
|
|
+ esCon := esv.VarEs.(*esv.EsV1)
|
|
|
|
+ c.EsConGetDataV1(stype, dataSource, esCon)
|
|
|
|
+ } else {
|
|
|
|
+ esCon := esv.VarEs.(*esv.EsV7)
|
|
|
|
+ c.EsConGetDataV7(stype, dataSource, esCon)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (c *Customer) EsConGetDataV1(stype string, dataSource int, esCon *esv.EsV1) {
|
|
|
|
+ client := esCon.GetEsConn()
|
|
|
|
+ defer esCon.DestoryEsConn(client)
|
|
for _, dm := range c.Departments {
|
|
for _, dm := range c.Departments {
|
|
for _, sr := range dm.Rules {
|
|
for _, sr := range dm.Rules {
|
|
ch := make(chan bool, 10)
|
|
ch := make(chan bool, 10)
|
|
@@ -400,7 +417,336 @@ func (c *Customer) GetData(stype string, dataSource int) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//数据去重
|
|
|
|
|
|
+type MySource struct {
|
|
|
|
+ Querys string
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m *MySource) Source() (interface{}, error) {
|
|
|
|
+ mp := make(map[string]interface{})
|
|
|
|
+ json.Unmarshal([]byte(m.Querys), &mp)
|
|
|
|
+ return mp["query"], nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *esv.EsV7) {
|
|
|
|
+ client := esCon.GetEsConn()
|
|
|
|
+ defer esCon.DestoryEsConn(client)
|
|
|
|
+ ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
|
|
|
|
+ for _, dm := range c.Departments {
|
|
|
|
+ for _, sr := range dm.Rules {
|
|
|
|
+ ch := make(chan bool, 10)
|
|
|
|
+ wg := &sync.WaitGroup{}
|
|
|
|
+ esIndex := Index
|
|
|
|
+ if dataSource == 2 {
|
|
|
|
+ esIndex = EsAllIndex
|
|
|
|
+ }
|
|
|
|
+ escount := Es.Count(esIndex, Itype, sr.EsQuery)
|
|
|
|
+ log.Println("index", esIndex, "type", Itype)
|
|
|
|
+ log.Println("查询总数:", escount, "规则ID:", sr.ID, "EsQuery:", sr.EsQuery)
|
|
|
|
+ if escount == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ //查询条件类型转换
|
|
|
|
+ // var q esV7.Query
|
|
|
|
+ // tmpQuery := esV7.BoolQuery{
|
|
|
|
+ // QueryStrings: sr.EsQuery,
|
|
|
|
+ // }
|
|
|
|
+ // q = tmpQuery
|
|
|
|
+ cc := &MySource{
|
|
|
|
+ Querys: sr.EsQuery,
|
|
|
|
+ }
|
|
|
|
+ //游标查询,index不支持别名,只能写索引库的名称
|
|
|
|
+ res, err := client.Scroll(esIndex).Query(cc).Size(200).Do(ctx) //查询一条获取游标
|
|
|
|
+ if err == nil {
|
|
|
|
+ numDocs := 0
|
|
|
|
+ scrollId := res.ScrollId
|
|
|
|
+ count := 1
|
|
|
|
+ for {
|
|
|
|
+ if scrollId == "" {
|
|
|
|
+ log.Println("ScrollId Is Error")
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ var searchResult *esV7.SearchResult
|
|
|
|
+ var err error
|
|
|
|
+ if count == 1 {
|
|
|
|
+ searchResult = res
|
|
|
|
+ } else {
|
|
|
|
+ searchResult, err = client.Scroll(esIndex).Size(200).ScrollId(scrollId).Do(ctx) //查询
|
|
|
|
+ if err != nil {
|
|
|
|
+ if err.Error() == "EOS" { //迭代完毕
|
|
|
|
+ log.Println("Es Search Data Over:", err)
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("Es Search Data Error:", err)
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ log.Println("此次处理条数 ", len(searchResult.Hits.Hits))
|
|
|
|
+ for _, hit := range searchResult.Hits.Hits {
|
|
|
|
+ //开始处理数据
|
|
|
|
+ wg.Add(1)
|
|
|
|
+ ch <- true
|
|
|
|
+ go func(tmpHit *esV7.SearchHit) {
|
|
|
|
+ defer func() {
|
|
|
|
+ <-ch
|
|
|
|
+ wg.Done()
|
|
|
|
+ }()
|
|
|
|
+ tmp := make(map[string]interface{})
|
|
|
|
+ if json.Unmarshal(tmpHit.Source, &tmp) == nil {
|
|
|
|
+ if stype != "history" {
|
|
|
|
+ if !SkipData(tmp) {
|
|
|
|
+ qu.Debug("跳过该条数据,发布时间在入库时间7天之前,", qu.ObjToString(tmp["_id"]))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ id := qu.ObjToString(tmp["id"])
|
|
|
|
+ //亚信
|
|
|
|
+ if CheckBidOpenAppidMap[c.AppId] {
|
|
|
|
+ if tmp["bidopentime"] != nil {
|
|
|
|
+ bidopentime := qu.Int64All(tmp["bidopentime"])
|
|
|
|
+ comeintime := qu.Int64All(tmp["comeintime"])
|
|
|
|
+ if bidopentime-comeintime <= 7*24*60*60 {
|
|
|
|
+ qu.Debug("跳过该条数据,开标时间-入库时间<=7天,", id)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //河南移动,过滤掉中国移动采购网招标数据
|
|
|
|
+ if CheckBidHrefRuleIdMap[dm.ID] {
|
|
|
|
+ if strings.Contains(qu.ObjToString(tmp["href"]), "b2b.10086.cn") {
|
|
|
|
+ qu.Debug("跳过该条数据,公告原网址中包含 b2b.10086.cn,", id)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //
|
|
|
|
+ tmp["id"] = id //记录数据原有id
|
|
|
|
+ delete(tmp, "_id")
|
|
|
|
+ if sr.ExtFieldType == 2 {
|
|
|
|
+ findwinner := ""
|
|
|
|
+ s_winner := strings.Split(qu.ObjToString(tmp["s_winner"]), ",")
|
|
|
|
+ if len(s_winner) > 0 {
|
|
|
|
+ for i := 0; i < len(s_winner); i++ {
|
|
|
|
+ findwinners := strings.TrimSpace(s_winner[i])
|
|
|
|
+ if findwinners != "" {
|
|
|
|
+ for _, v := range Sysconfig["s_winner_filter"].([]interface{}) {
|
|
|
|
+ strings.ReplaceAll(findwinners, v.(string), "")
|
|
|
|
+ }
|
|
|
|
+ if findwinners != "" {
|
|
|
|
+ findwinner = findwinners
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // findwinner := strings.TrimSpace(qu.ObjToString(tmp["winner"]))
|
|
|
|
+ if findwinner != "" {
|
|
|
|
+ finddata := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": findwinner})
|
|
|
|
+ if finddata != nil {
|
|
|
|
+ if legal_person := qu.ObjToString(finddata["legal_person"]); legal_person != "" {
|
|
|
|
+ tmp["legal_person"] = legal_person
|
|
|
|
+ }
|
|
|
|
+ if email := qu.ObjToString(finddata["company_email"]); email != "" {
|
|
|
|
+ tmp["company_email"] = email
|
|
|
|
+ }
|
|
|
|
+ if phone := qu.ObjToString(finddata["company_phone"]); phone != "" {
|
|
|
|
+ tmp["company_phone"] = phone
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ matchKey := map[string]bool{} //记录所有匹配上的关键词
|
|
|
|
+ matchKeyType := map[string]bool{} //记录关键词对应的匹配方式
|
|
|
|
+ //先获取用到的所有字段值
|
|
|
|
+ fieldText := map[string]interface{}{}
|
|
|
|
+ for field, _ := range sr.Fields {
|
|
|
|
+ text := qu.ObjToString(tmp[field])
|
|
|
|
+ text = ProcessData(text) //处理文本(字母转大写,删除一些符号)
|
|
|
|
+ fieldText[field] = text
|
|
|
|
+ }
|
|
|
|
+ //清理词清理
|
|
|
|
+ for _, cwm := range sr.GCW.MatchType {
|
|
|
|
+ if text := qu.ObjToString(fieldText[cwm]); text != "" {
|
|
|
|
+ for _, gcw_reg := range sr.GCW.KeyReg {
|
|
|
|
+ text = gcw_reg.ReplaceAllString(text, "")
|
|
|
|
+ }
|
|
|
|
+ fieldText[cwm] = text
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //精准筛选规则2022-10-19
|
|
|
|
+ if c.Exact == 1 && sr.ExactRule != "" {
|
|
|
|
+ nameArr := []string{}
|
|
|
|
+ data, ok := Mgo.Find("groups", map[string]interface{}{"ruleId": sr.ID}, nil, nil, false, -1, -1)
|
|
|
|
+ if ok && data != nil && len(*data) > 0 {
|
|
|
|
+ for _, v := range *data {
|
|
|
|
+ nameArr = append(nameArr, qu.ObjToString(v["name"]))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ exactResult := exactMatchs(sr.ExactRule, qu.ObjToString(tmp["title"]), qu.ObjToString(tmp["detail"]), sr.Maths, nameArr)
|
|
|
|
+ qu.Debug("-------------------精准匹配", id, exactResult)
|
|
|
|
+ if !exactResult {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //
|
|
|
|
+ /*
|
|
|
|
+ 因为要记录所有匹配上的关键词,所有优先匹配附加词,在匹配关键词
|
|
|
|
+ */
|
|
|
|
+ //1.附加词匹配
|
|
|
|
+ IsMatch := false
|
|
|
|
+ // qu.Debug("sr.AW---", len(sr.AW))
|
|
|
|
+ for i, aw := range sr.AW {
|
|
|
|
+ // qu.Debug("-------------------------开始附加词匹配--------------------------")
|
|
|
|
+ IsMatchAddKey := RegMatch(fieldText, aw.MatchType, aw.KeyReg, nil, nil, false, true)
|
|
|
|
+ // qu.Debug(IsMatchAddKey, "------------------------------------------------------------")
|
|
|
|
+
|
|
|
|
+ //2.关键词匹配
|
|
|
|
+ if IsMatchAddKey {
|
|
|
|
+ kw := sr.KW[i]
|
|
|
|
+ // qu.Debug("-------------------------开始关键词匹配--------------------------")
|
|
|
|
+ IsMatchKey := RegMatch(fieldText, kw.MatchType, kw.KeyReg, matchKey, matchKeyType, true, false)
|
|
|
|
+ // qu.Debug(IsMatchKey, "------------------------------------------------------------")
|
|
|
|
+ if IsMatchKey {
|
|
|
|
+ IsMatch = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if len(sr.AW) == 0 {
|
|
|
|
+ IsMatch = true
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ 到此已经匹配完数据
|
|
|
|
+ */
|
|
|
|
+ qu.Debug("---------------------", id, IsMatch)
|
|
|
|
+ if IsMatch { //匹配成功,数据上新增规则id,matchKey,item并临时保存数据
|
|
|
|
+ // tmpMatchKey := MapDataToArr(matchKey)
|
|
|
|
+ tmpMatchKeyType := MapDataToArr(matchKeyType)
|
|
|
|
+ tmp["matchkey"] = GetMactchKeys(sr.Maths, tmp)
|
|
|
|
+ tmp["matchtype"] = strings.Join(tmpMatchKeyType, ",")
|
|
|
|
+ tmp["ruleid"] = sr.ID
|
|
|
|
+ tmp["rulename"] = sr.Name
|
|
|
|
+ tmpBuyerClass := qu.ObjToString(tmp["buyerclass"])
|
|
|
|
+
|
|
|
|
+ //开始打标签
|
|
|
|
+ //qu.Debug("c.IsTagRule+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
|
|
|
|
+ if c.IsTagRule {
|
|
|
|
+ tagNameMap := map[string]bool{}
|
|
|
|
+ tagIdMap := map[string]bool{}
|
|
|
|
+ //qu.Debug("c.TagRules---", len(c.TagRules))
|
|
|
|
+ for _, tr := range c.TagRules {
|
|
|
|
+ if tr.DepartRuleIds[sr.ID] {
|
|
|
|
+ //先获取用到的所有字段值
|
|
|
|
+ for field, _ := range tr.Fields {
|
|
|
|
+ if fieldText[field] == nil { //补充fieldText
|
|
|
|
+ text := qu.ObjToString(tmp[field])
|
|
|
|
+ text = ProcessData(text) //处理文本(字母转大写,删除一些符号)
|
|
|
|
+ fieldText[field] = text
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ matchKeyTag := map[string]bool{} //记录所有标签里的匹配上的关键词
|
|
|
|
+ matchKeyTypeTag := map[string]bool{} //记录标签里的关键词对应的匹配方式
|
|
|
|
+
|
|
|
|
+ //qu.Debug("-------------------------开始排除词匹配--------------------------")
|
|
|
|
+ //qu.Debug("tr.NW---", len(tr.NW))
|
|
|
|
+ for j, tag_nw := range tr.NW { //排除词匹配
|
|
|
|
+ IsMatchNotKey := RegMatch(fieldText, tag_nw.MatchType, tag_nw.KeyReg, nil, nil, false, false)
|
|
|
|
+ //qu.Debug(IsMatchNotKey, "------------------------------------------------------------")
|
|
|
|
+ if !IsMatchNotKey { //排除词未匹配,匹配附加词关键词
|
|
|
|
+ if RegMatch(fieldText, tr.AW[j].MatchType, tr.AW[j].KeyReg, nil, nil, false, true) && RegMatch(fieldText, tr.KW[j].MatchType, tr.KW[j].KeyReg, matchKeyTag, matchKeyTypeTag, true, false) {
|
|
|
|
+ tagname := tr.TagNames[j]
|
|
|
|
+ tagBuyerClass := tr.BuyerClass[j]
|
|
|
|
+ if tagBuyerClass != "" {
|
|
|
|
+ if strings.Contains(tagBuyerClass, tmpBuyerClass) {
|
|
|
|
+ if tagname == "" {
|
|
|
|
+ tempList := []string{}
|
|
|
|
+ for k, _ := range matchKeyTag {
|
|
|
|
+ tempList = append(tempList, k)
|
|
|
|
+ }
|
|
|
|
+ tagname = strings.Join(tempList, ",")
|
|
|
|
+ log.Println("=====tagname为空取匹配词为标签名称", tagname)
|
|
|
|
+ }
|
|
|
|
+ //qu.Debug("tagname-----", tagname)
|
|
|
|
+ tagNameMap[tagname] = true
|
|
|
|
+ tagIdMap[tr.ID] = true
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if tagname == "" {
|
|
|
|
+ tempList := []string{}
|
|
|
|
+ for k, _ := range matchKeyTag {
|
|
|
|
+ tempList = append(tempList, k)
|
|
|
|
+ }
|
|
|
|
+ tagname = strings.Join(tempList, ",")
|
|
|
|
+ log.Println("=====tagname为空取匹配词为标签名称", tagname)
|
|
|
|
+ }
|
|
|
|
+ //qu.Debug("tagname-----", tagname)
|
|
|
|
+ tagNameMap[tagname] = true
|
|
|
|
+ tagIdMap[tr.ID] = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //tagname
|
|
|
|
+ tagNameArr := MapDataToArr(tagNameMap)
|
|
|
|
+ tagIdArr := MapDataToArr(tagIdMap)
|
|
|
|
+ if len(tagNameArr) > 0 {
|
|
|
|
+ tmp["tagname"] = strings.Join(tagNameArr, ",")
|
|
|
|
+ if DisPackageAppidMap[c.AppId] {
|
|
|
|
+ tmp["buyer_type"] = strings.Join(tagNameArr, ",")
|
|
|
|
+ }
|
|
|
|
+ if c.PushModel == 2 {
|
|
|
|
+ tmp["item"] = strings.Join(tagNameArr, ",")
|
|
|
|
+ }
|
|
|
|
+ tmp["tagid"] = strings.Join(tagIdArr, ",")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //item
|
|
|
|
+ switch c.PushModel {
|
|
|
|
+ case 0:
|
|
|
|
+ tmp["item"] = "数据"
|
|
|
|
+ case 1:
|
|
|
|
+ tmp["item"] = dm.Name
|
|
|
|
+ case 2:
|
|
|
|
+ //tmp["item"] = sr.Name
|
|
|
|
+ case 3:
|
|
|
|
+ tmp["item"] = dm.Name + "_" + sr.Name
|
|
|
|
+ case 4:
|
|
|
|
+ tmp["item"] = sr.Name
|
|
|
|
+ }
|
|
|
|
+ //appid
|
|
|
|
+ tmp["appid"] = c.AppId
|
|
|
|
+ //部门名称
|
|
|
|
+ tmp["departname"] = dm.Name
|
|
|
|
+ tmp["departid"] = dm.ID
|
|
|
|
+ //存储数据
|
|
|
|
+ dm.DataLock.Lock()
|
|
|
|
+ //qu.Debug("tmp---", tmp)
|
|
|
|
+ tmpMap := map[string]interface{}{id: tmp}
|
|
|
|
+ dm.DepartmentData[sr.ID] = append(dm.DepartmentData[sr.ID], tmpMap)
|
|
|
|
+ dm.DataLock.Unlock()
|
|
|
|
+ } else {
|
|
|
|
+ // qu.Debug("------------", id, IsMatch)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }(hit)
|
|
|
|
+ numDocs += 1
|
|
|
|
+ if numDocs%500 == 0 {
|
|
|
|
+ log.Println("Current:", numDocs)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ scrollId = searchResult.ScrollId
|
|
|
|
+ count++
|
|
|
|
+ }
|
|
|
|
+ wg.Wait()
|
|
|
|
+ client.ClearScroll().ScrollId(scrollId).Do(ctx) //清理游标
|
|
|
|
+ log.Println("SearchRule ID", sr.ID, "Result Data Count:", numDocs)
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("Customer:", c.Name, "Departmnet", dm.Name, "TagName", sr.Name, "Es Search Data Error,Tag ID:", sr.ID)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 数据去重
|
|
func (c *Customer) RemoveRepeatData() {
|
|
func (c *Customer) RemoveRepeatData() {
|
|
log.Println("开始数据去重...")
|
|
log.Println("开始数据去重...")
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
@@ -452,7 +798,7 @@ func (c *Customer) RemoveRepeatData() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//组装保存数据
|
|
|
|
|
|
+// 组装保存数据
|
|
func (c *Customer) AssembelAndSaveData(historyId string, isFilter, noticeFilter, dataTable, entId, i_contact int, xlsxData *XlsxData) {
|
|
func (c *Customer) AssembelAndSaveData(historyId string, isFilter, noticeFilter, dataTable, entId, i_contact int, xlsxData *XlsxData) {
|
|
log.Println("开始组装保存数据...")
|
|
log.Println("开始组装保存数据...")
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
@@ -525,7 +871,7 @@ func (c *Customer) AssembelAndSaveData(historyId string, isFilter, noticeFilter,
|
|
log.Println("数据保存完毕... Save Number:", n)
|
|
log.Println("数据保存完毕... Save Number:", n)
|
|
}
|
|
}
|
|
|
|
|
|
-//获取用户所有规则
|
|
|
|
|
|
+// 获取用户所有规则
|
|
func (d *Department) GetSearchRules(cid, stype string, idRange bson.M, searchRules []map[string]interface{}) {
|
|
func (d *Department) GetSearchRules(cid, stype string, idRange bson.M, searchRules []map[string]interface{}) {
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
if len(searchRules) > 0 {
|
|
if len(searchRules) > 0 {
|
|
@@ -586,16 +932,16 @@ func (d *Department) GetSearchRules(cid, stype string, idRange bson.M, searchRul
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//获取转换后的es语句
|
|
|
|
|
|
+// 获取转换后的es语句
|
|
func (sr *SearchRule) GetEs(department, esquery string, tmpRange bson.M) {
|
|
func (sr *SearchRule) GetEs(department, esquery string, tmpRange bson.M) {
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
query := map[string]*QueryObjecct{}
|
|
query := map[string]*QueryObjecct{}
|
|
if json.Unmarshal([]byte(esquery), &query) == nil {
|
|
if json.Unmarshal([]byte(esquery), &query) == nil {
|
|
qb := query["query"]
|
|
qb := query["query"]
|
|
- filter := qb.Filtered.Filter
|
|
|
|
- if filter != nil && filter.Bool != nil { //有filter
|
|
|
|
|
|
+ filter := qb.Bool
|
|
|
|
+ if filter != nil { //有filter
|
|
index := -1 //记录range的位置
|
|
index := -1 //记录range的位置
|
|
- for i, m := range filter.Bool.Must {
|
|
|
|
|
|
+ for i, m := range filter.Must {
|
|
mMap := m.(map[string]interface{})
|
|
mMap := m.(map[string]interface{})
|
|
if esRange, ok := mMap["range"].(map[string]interface{}); ok && esRange != nil { //有range
|
|
if esRange, ok := mMap["range"].(map[string]interface{}); ok && esRange != nil { //有range
|
|
if esRange["publishtime"] != nil {
|
|
if esRange["publishtime"] != nil {
|
|
@@ -605,17 +951,17 @@ func (sr *SearchRule) GetEs(department, esquery string, tmpRange bson.M) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if index > -1 {
|
|
if index > -1 {
|
|
- filter.Bool.Must[index] = tmpRange
|
|
|
|
|
|
+ filter.Must[index] = tmpRange
|
|
} else {
|
|
} else {
|
|
- filter.Bool.Must = append(filter.Bool.Must, tmpRange)
|
|
|
|
|
|
+ filter.Must = append(filter.Must, tmpRange)
|
|
}
|
|
}
|
|
} else { //无filter则添加
|
|
} else { //无filter则添加
|
|
bo := &BoolObject{}
|
|
bo := &BoolObject{}
|
|
bo.Must = append(bo.Must, tmpRange)
|
|
bo.Must = append(bo.Must, tmpRange)
|
|
- tmpFilter := &Filter{
|
|
|
|
- Bool: bo,
|
|
|
|
- }
|
|
|
|
- qb.Filtered.Filter = tmpFilter
|
|
|
|
|
|
+ // tmpFilter := &Filter{
|
|
|
|
+ // Bool: bo,
|
|
|
|
+ // }
|
|
|
|
+ qb.Bool = bo
|
|
}
|
|
}
|
|
strquery, err := json.Marshal(query)
|
|
strquery, err := json.Marshal(query)
|
|
if err == nil {
|
|
if err == nil {
|
|
@@ -628,7 +974,7 @@ func (sr *SearchRule) GetEs(department, esquery string, tmpRange bson.M) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//全局清理词处理
|
|
|
|
|
|
+// 全局清理词处理
|
|
func (sr *SearchRule) GetClearWord(key, match string) {
|
|
func (sr *SearchRule) GetClearWord(key, match string) {
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
//匹配方式
|
|
//匹配方式
|
|
@@ -655,7 +1001,7 @@ func (sr *SearchRule) GetClearWord(key, match string) {
|
|
sr.GCW = cw
|
|
sr.GCW = cw
|
|
}
|
|
}
|
|
|
|
|
|
-//关键词、附加词处理
|
|
|
|
|
|
+// 关键词、附加词处理
|
|
func (sr *SearchRule) GetKeyAddWord(o_rules []map[string]interface{}) {
|
|
func (sr *SearchRule) GetKeyAddWord(o_rules []map[string]interface{}) {
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
kw, aw, _, _, _ := GetNotkeyAndKeyAddWord(o_rules, sr.Fields, false)
|
|
kw, aw, _, _, _ := GetNotkeyAndKeyAddWord(o_rules, sr.Fields, false)
|
|
@@ -664,7 +1010,7 @@ func (sr *SearchRule) GetKeyAddWord(o_rules []map[string]interface{}) {
|
|
//sr.Fields = fields
|
|
//sr.Fields = fields
|
|
}
|
|
}
|
|
|
|
|
|
-//排除词、关键词、附加词处理
|
|
|
|
|
|
+// 排除词、关键词、附加词处理
|
|
func (tr *TagRule) GetKeyAddNotKeyWord(o_list []map[string]interface{}) {
|
|
func (tr *TagRule) GetKeyAddNotKeyWord(o_list []map[string]interface{}) {
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
kw, aw, nkw, tagnames, buyerclass := GetNotkeyAndKeyAddWord(o_list, tr.Fields, true)
|
|
kw, aw, nkw, tagnames, buyerclass := GetNotkeyAndKeyAddWord(o_list, tr.Fields, true)
|