|
@@ -4,17 +4,19 @@ import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "log"
|
|
|
"models"
|
|
|
"qfw/util"
|
|
|
"qfw/util/elastic"
|
|
|
"regexp"
|
|
|
sql "sqlmodel"
|
|
|
"strings"
|
|
|
+ "sync"
|
|
|
"time"
|
|
|
|
|
|
// "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
-
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
+ es "gopkg.in/olivere/elastic.v1"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -70,6 +72,8 @@ func UtilEsSaveData(sdataid string, datas *[]map[string]interface{}) error {
|
|
|
//客户规则
|
|
|
func UtilEsFind1(tags map[string]interface{}) (error, int64) {
|
|
|
defer util.Catch()
|
|
|
+ ch := make(chan bool, 20)
|
|
|
+ wg := &sync.WaitGroup{}
|
|
|
sdataid := util.ObjToString(tags["s_dataid"])
|
|
|
esquery := util.ObjToString(tags["s_esquery"])
|
|
|
if len(esquery) < 1 || len(sdataid) < 1 {
|
|
@@ -106,108 +110,106 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
|
|
|
datas := make([]map[string]interface{}, 0)
|
|
|
util.Debug("es查询到的数量:", searchResult.Hits.TotalHits)
|
|
|
for _, v := range searchResult.Hits.Hits {
|
|
|
- item := make(map[string]interface{})
|
|
|
- if json.Unmarshal(*v.Source, &item) == nil {
|
|
|
- delete(item, "_id")
|
|
|
- item["appid"] = tags["appid"]
|
|
|
- item["info_id"] = v.Id
|
|
|
- item["s_dataid"] = sdataid
|
|
|
- item["s_jyhref"] = fmt.Sprintf(Url, util.CommonEncodeArticle("content", v.Id))
|
|
|
- item["i_createtime"] = time.Now().Unix()
|
|
|
- var d *DFA = &DFA{}
|
|
|
- var analyKeys []string //找到的关键词
|
|
|
- var matchType []string //匹配方式
|
|
|
- for _, math := range maths {
|
|
|
- fileds := strsToArr(math["s_keymatch"], "field")
|
|
|
- d.AddWord(strings.Split(math["s_matchkey"], ",")...)
|
|
|
- mkMap := make(map[string]interface{})
|
|
|
- tmpMap := make(map[string]interface{})
|
|
|
- for _, mk := range strings.Split(math["s_matchkey"], ",") {
|
|
|
- if strings.Contains(mk, "&&") {
|
|
|
- arr := strings.Split(mk, "&&")
|
|
|
- for _, s := range arr {
|
|
|
- if s != "" {
|
|
|
- tmpMap[s] = mk
|
|
|
- if b, _ := regexp.MatchString("[A-Z]", s); b {
|
|
|
- mkMap[strings.ToLower(s)] = s
|
|
|
- d.AddWord(strings.ToLower(s))
|
|
|
- } else {
|
|
|
- d.AddWord(s)
|
|
|
+ wg.Add(1)
|
|
|
+ ch <- true
|
|
|
+ go func(tmpHit *es.SearchHit) {
|
|
|
+ defer func() {
|
|
|
+ <-ch
|
|
|
+ wg.Done()
|
|
|
+ }()
|
|
|
+ item := make(map[string]interface{})
|
|
|
+ if json.Unmarshal(*tmpHit.Source, &item) == nil {
|
|
|
+ delete(item, "_id")
|
|
|
+ item["appid"] = tags["appid"]
|
|
|
+ item["info_id"] = v.Id
|
|
|
+ item["s_dataid"] = sdataid
|
|
|
+ item["s_jyhref"] = fmt.Sprintf(Url, util.CommonEncodeArticle("content", v.Id))
|
|
|
+ item["i_createtime"] = time.Now().Unix()
|
|
|
+ var d *DFA = &DFA{}
|
|
|
+ var analyKeys []string //找到的关键词
|
|
|
+ var matchType []string //匹配方式
|
|
|
+ for _, math := range maths {
|
|
|
+ fileds := strsToArr(math["s_keymatch"], "field")
|
|
|
+ d.AddWord(strings.Split(math["s_matchkey"], ",")...)
|
|
|
+ mkMap := make(map[string]interface{})
|
|
|
+ tmpMap := make(map[string]interface{})
|
|
|
+ for _, mk := range strings.Split(math["s_matchkey"], ",") {
|
|
|
+ if strings.Contains(mk, "&&") {
|
|
|
+ arr := strings.Split(mk, "&&")
|
|
|
+ for _, s := range arr {
|
|
|
+ if s != "" {
|
|
|
+ tmpMap[s] = mk
|
|
|
+ if b, _ := regexp.MatchString("[A-Z]", s); b {
|
|
|
+ mkMap[strings.ToLower(s)] = s
|
|
|
+ d.AddWord(strings.ToLower(s))
|
|
|
+ } else {
|
|
|
+ d.AddWord(s)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- } else {
|
|
|
- if b, _ := regexp.MatchString("[A-Z]", mk); b {
|
|
|
- mkMap[strings.ToLower(mk)] = mk
|
|
|
- d.AddWord(strings.ToLower(mk))
|
|
|
} else {
|
|
|
- d.AddWord(mk)
|
|
|
+ if b, _ := regexp.MatchString("[A-Z]", mk); b {
|
|
|
+ mkMap[strings.ToLower(mk)] = mk
|
|
|
+ d.AddWord(strings.ToLower(mk))
|
|
|
+ } else {
|
|
|
+ d.AddWord(mk)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- for _, filed := range fileds {
|
|
|
- filed1 := strings.ToLower(util.ObjToString(item[filed]))
|
|
|
- ddds := d.Analy(filed1)
|
|
|
- analyKeys = append(analyKeys, ddds...)
|
|
|
- }
|
|
|
- if len(analyKeys) > 0 {
|
|
|
- matchType = append(matchType, strings.Join(fileds, ","))
|
|
|
- for k, v := range analyKeys {
|
|
|
- if tmpMap[v] != "" && tmpMap[v] != nil {
|
|
|
- analyKeys[k] = util.ObjToString(tmpMap[v])
|
|
|
- }
|
|
|
+ for _, filed := range fileds {
|
|
|
+ filed1 := strings.ToLower(util.ObjToString(item[filed]))
|
|
|
+ ddds := d.Analy(filed1)
|
|
|
+ analyKeys = append(analyKeys, ddds...)
|
|
|
}
|
|
|
- for _, v1 := range analyKeys {
|
|
|
- if mkMap[v1] != "" && mkMap[v1] != nil {
|
|
|
- analyKeys = deleteSlice(analyKeys, v1)
|
|
|
- analyKeys = append(analyKeys, util.ObjToString(mkMap[v1]))
|
|
|
+ if len(analyKeys) > 0 {
|
|
|
+ matchType = append(matchType, strings.Join(fileds, ","))
|
|
|
+ for k, v := range analyKeys {
|
|
|
+ if tmpMap[v] != "" && tmpMap[v] != nil {
|
|
|
+ analyKeys[k] = util.ObjToString(tmpMap[v])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v1 := range analyKeys {
|
|
|
+ if mkMap[v1] != "" && mkMap[v1] != nil {
|
|
|
+ analyKeys = deleteSlice(analyKeys, v1)
|
|
|
+ analyKeys = append(analyKeys, util.ObjToString(mkMap[v1]))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ d.Clear()
|
|
|
}
|
|
|
- d.Clear()
|
|
|
- }
|
|
|
- //去重
|
|
|
- ssavekey := make(map[string]bool)
|
|
|
- for _, v := range analyKeys {
|
|
|
- ssavekey[v] = true
|
|
|
- }
|
|
|
- ssavekeys := []string{}
|
|
|
- for k := range ssavekey {
|
|
|
- ssavekeys = append(ssavekeys, k)
|
|
|
- }
|
|
|
- item["s_matchkey"] = GetMactchKey(maths, item)
|
|
|
- item["s_matchtype"] = strings.Join(matchType, ",")
|
|
|
- findwinner := strings.TrimSpace(util.ObjToString(item["winner"]))
|
|
|
- if findwinner != "" {
|
|
|
- finddata := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": findwinner})
|
|
|
- if finddata != nil {
|
|
|
- if legal_person := util.ObjToString(finddata["legal_person"]); legal_person != "" {
|
|
|
- item["legal_person"] = legal_person
|
|
|
- }
|
|
|
- if email := util.ObjToString(finddata["company_email"]); email != "" {
|
|
|
- item["company_email"] = email
|
|
|
- }
|
|
|
- if phone := util.ObjToString(finddata["company_phone"]); phone != "" {
|
|
|
- item["company_phone"] = phone
|
|
|
+ //去重
|
|
|
+ ssavekey := make(map[string]bool)
|
|
|
+ for _, v := range analyKeys {
|
|
|
+ ssavekey[v] = true
|
|
|
+ }
|
|
|
+ ssavekeys := []string{}
|
|
|
+ for k := range ssavekey {
|
|
|
+ ssavekeys = append(ssavekeys, k)
|
|
|
+ }
|
|
|
+ item["s_matchkey"] = GetMactchKey(maths, item)
|
|
|
+ item["s_matchtype"] = strings.Join(matchType, ",")
|
|
|
+ findwinner := strings.TrimSpace(util.ObjToString(item["winner"]))
|
|
|
+ if findwinner != "" {
|
|
|
+ finddata := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": findwinner})
|
|
|
+ if finddata != nil {
|
|
|
+ if legal_person := util.ObjToString(finddata["legal_person"]); legal_person != "" {
|
|
|
+ item["legal_person"] = legal_person
|
|
|
+ }
|
|
|
+ if email := util.ObjToString(finddata["company_email"]); email != "" {
|
|
|
+ item["company_email"] = email
|
|
|
+ }
|
|
|
+ if phone := util.ObjToString(finddata["company_phone"]); phone != "" {
|
|
|
+ item["company_phone"] = phone
|
|
|
+ }
|
|
|
+ item["qyk"] = finddata
|
|
|
}
|
|
|
- //从最新年报中获取 中标单位联系电话、中标单位邮箱
|
|
|
- // if annual_reports, ok := finddata["annual_reports"].(primitive.A); ok && len(annual_reports) > 0 {
|
|
|
- // report_year := Sort_year_report(annual_reports) //最新年报
|
|
|
- // if len(report_year) > 0 {
|
|
|
- // if email := util.ObjToString(report_year["company_email"]); email != "" {
|
|
|
- // item["company_email"] = email
|
|
|
- // }
|
|
|
- // if phone := util.ObjToString(report_year["company_phone"]); phone != "" {
|
|
|
- // item["company_phone"] = phone
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- item["qyk"] = finddata
|
|
|
}
|
|
|
+ datas = append(datas, item)
|
|
|
+ log.Println("id", item["info_id"])
|
|
|
}
|
|
|
- datas = append(datas, item)
|
|
|
- }
|
|
|
+ }(v)
|
|
|
}
|
|
|
+ wg.Wait()
|
|
|
Mgo.Update("entniche_rule", bson.M{"_id": tags["_id"]}, bson.M{
|
|
|
"$set": bson.M{
|
|
|
"i_estotal": searchResult.Hits.TotalHits,
|
|
@@ -276,46 +278,6 @@ func Utiltags(tag map[string]interface{}) string {
|
|
|
Lt: tab.Iendtime,
|
|
|
}}})
|
|
|
}
|
|
|
- /*if tab.Sbudget != "" {
|
|
|
- if strings.Contains(tab.Sbudget, "大于") && strings.Contains(tab.Sbudget, "小于") {
|
|
|
- arr := strings.Split(tab.Sbudget, ",")
|
|
|
- limit := &sql.BudgetOrBidamount{
|
|
|
- Gte: util.Float64All(strings.Replace(arr[0], "大于", "", -1)),
|
|
|
- Lt: util.Float64All(strings.Replace(arr[1], "小于", "", -1)),
|
|
|
- }
|
|
|
- ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}})
|
|
|
- } else if strings.Contains(tab.Sbudget, "大于") {
|
|
|
- limit := &sql.BudgetOrBidamount{
|
|
|
- Gte: util.Float64All(strings.Replace(tab.Sbudget, "大于", "", -1)),
|
|
|
- }
|
|
|
- ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}})
|
|
|
- } else if strings.Contains(tab.Sbudget, "小于") {
|
|
|
- limit := &sql.BudgetOrBidamount{
|
|
|
- Lt: util.Float64All(strings.Replace(tab.Sbudget, "小于", "", -1)),
|
|
|
- }
|
|
|
- ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}})
|
|
|
- }
|
|
|
- }*/
|
|
|
- /*if tab.Sbidamount != "" {
|
|
|
- if strings.Contains(tab.Sbidamount, "大于") && strings.Contains(tab.Sbidamount, "小于") {
|
|
|
- arr := strings.Split(tab.Sbidamount, ",")
|
|
|
- limit := &sql.BudgetOrBidamount{
|
|
|
- Gte: util.Float64All(strings.Replace(arr[0], "大于", "", -1)),
|
|
|
- Lt: util.Float64All(strings.Replace(arr[1], "小于", "", -1)),
|
|
|
- }
|
|
|
- ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}})
|
|
|
- } else if strings.Contains(tab.Sbidamount, "大于") {
|
|
|
- limit := &sql.BudgetOrBidamount{
|
|
|
- Gte: util.Float64All(strings.Replace(tab.Sbidamount, "大于", "", -1)),
|
|
|
- }
|
|
|
- ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}})
|
|
|
- } else if strings.Contains(tab.Sbidamount, "小于") {
|
|
|
- limit := &sql.BudgetOrBidamount{
|
|
|
- Lt: util.Float64All(strings.Replace(tab.Sbidamount, "小于", "", -1)),
|
|
|
- }
|
|
|
- ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}})
|
|
|
- }
|
|
|
- }*/
|
|
|
if tab.Sglobalbuyerclass != "" {
|
|
|
if len(tab.Sglobalbuyerclass) > 0 {
|
|
|
buyerclass := sql.BuyerclassObject{
|