|
@@ -1,26 +1,27 @@
|
|
package history
|
|
package history
|
|
|
|
|
|
import (
|
|
import (
|
|
- "app.yhyue.com/moapp/jybase/common"
|
|
|
|
- elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/log"
|
|
|
|
- "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
|
"cmplatform/util"
|
|
"cmplatform/util"
|
|
sql "cmplatform/util/sqlmodel"
|
|
sql "cmplatform/util/sqlmodel"
|
|
"context"
|
|
"context"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
- esV7 "github.com/olivere/elastic/v7"
|
|
|
|
- "go.mongodb.org/mongo-driver/bson"
|
|
|
|
|
|
+ "log"
|
|
"regexp"
|
|
"regexp"
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
"time"
|
|
"time"
|
|
|
|
+
|
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
|
+ esV7 "github.com/olivere/elastic/v7"
|
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
)
|
|
|
|
|
|
// 获取客户打标签规则
|
|
// 获取客户打标签规则
|
|
func (c *Customer) GetTagRules(tagRules, tagRules2, tagRules3 []map[string]interface{}) {
|
|
func (c *Customer) GetTagRules(tagRules, tagRules2, tagRules3 []map[string]interface{}) {
|
|
- log.Debug("开始加载标签规则...")
|
|
|
|
|
|
+ log.Println("开始加载标签规则...")
|
|
defer common.Catch()
|
|
defer common.Catch()
|
|
if len(tagRules) > 0 {
|
|
if len(tagRules) > 0 {
|
|
c.IsTagRule = true //查到打标签规则,表示打标签
|
|
c.IsTagRule = true //查到打标签规则,表示打标签
|
|
@@ -116,7 +117,7 @@ func (c *Customer) GetTagRules(tagRules, tagRules2, tagRules3 []map[string]inter
|
|
|
|
|
|
// 获取部门信息
|
|
// 获取部门信息
|
|
func (c *Customer) GetDepartments(stype string, departments []map[string]interface{}) {
|
|
func (c *Customer) GetDepartments(stype string, departments []map[string]interface{}) {
|
|
- log.Debug("开始获取部门信息...")
|
|
|
|
|
|
+ log.Println("开始获取部门信息...")
|
|
defer common.Catch()
|
|
defer common.Catch()
|
|
if len(departments) > 0 {
|
|
if len(departments) > 0 {
|
|
departMap := map[string]interface{}{}
|
|
departMap := map[string]interface{}{}
|
|
@@ -152,7 +153,7 @@ 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.Debug("开始匹配数据...")
|
|
|
|
|
|
+ log.Println("开始匹配数据...")
|
|
defer common.Catch()
|
|
defer common.Catch()
|
|
esConfig := util.Sysconfig["es"].(map[string]interface{})
|
|
esConfig := util.Sysconfig["es"].(map[string]interface{})
|
|
esversion := common.ObjToString(esConfig["version"])
|
|
esversion := common.ObjToString(esConfig["version"])
|
|
@@ -162,10 +163,10 @@ func (c *Customer) GetData(stype string, dataSource int) {
|
|
for {
|
|
for {
|
|
listLen := redis.GetInt("session", "es_status")
|
|
listLen := redis.GetInt("session", "es_status")
|
|
if listLen == 0 {
|
|
if listLen == 0 {
|
|
- log.Debug("es空闲!")
|
|
|
|
|
|
+ log.Println("es空闲!")
|
|
break
|
|
break
|
|
} else if listLen == 1 || listLen == 2 {
|
|
} else if listLen == 1 || listLen == 2 {
|
|
- log.Debug("es繁忙,", listLen)
|
|
|
|
|
|
+ log.Println("es繁忙,", listLen)
|
|
}
|
|
}
|
|
time.Sleep(5 * time.Second)
|
|
time.Sleep(5 * time.Second)
|
|
}
|
|
}
|
|
@@ -177,7 +178,7 @@ func (c *Customer) GetData(stype string, dataSource int) {
|
|
redis.LPOP("datag", "jyqyfw_es_query")
|
|
redis.LPOP("datag", "jyqyfw_es_query")
|
|
break
|
|
break
|
|
} else {
|
|
} else {
|
|
- log.Debug("企业级服务es进程数过多,", listLens)
|
|
|
|
|
|
+ log.Println("企业级服务es进程数过多,", listLens)
|
|
}
|
|
}
|
|
time.Sleep(5 * time.Second)
|
|
time.Sleep(5 * time.Second)
|
|
}
|
|
}
|
|
@@ -197,8 +198,8 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
esIndex = util.EsAllIndex
|
|
esIndex = util.EsAllIndex
|
|
}
|
|
}
|
|
escount := esCon.Count(esIndex, "", sr.EsQuery)
|
|
escount := esCon.Count(esIndex, "", sr.EsQuery)
|
|
- log.Debug("index", esIndex, "type")
|
|
|
|
- log.Debug("查询总数:", escount, "规则ID:", sr.ID, "EsQuery:", sr.EsQuery)
|
|
|
|
|
|
+ log.Println("index", esIndex, "type")
|
|
|
|
+ log.Println("查询总数:", escount, "规则ID:", sr.ID, "EsQuery:", sr.EsQuery)
|
|
if escount == 0 {
|
|
if escount == 0 {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
@@ -219,7 +220,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
count := 1
|
|
count := 1
|
|
for {
|
|
for {
|
|
if scrollId == "" {
|
|
if scrollId == "" {
|
|
- log.Debug("ScrollId Is Error")
|
|
|
|
|
|
+ log.Println("ScrollId Is Error")
|
|
break
|
|
break
|
|
}
|
|
}
|
|
var searchResult *esV7.SearchResult
|
|
var searchResult *esV7.SearchResult
|
|
@@ -230,14 +231,14 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
searchResult, err = client.Scroll(esIndex).Size(200).ScrollId(scrollId).Do(ctx) //查询
|
|
searchResult, err = client.Scroll(esIndex).Size(200).ScrollId(scrollId).Do(ctx) //查询
|
|
if err != nil {
|
|
if err != nil {
|
|
if err.Error() == "EOS" { //迭代完毕
|
|
if err.Error() == "EOS" { //迭代完毕
|
|
- log.Debug("Es Search Data Over:", err)
|
|
|
|
|
|
+ log.Println("Es Search Data Over:", err)
|
|
} else {
|
|
} else {
|
|
- log.Debug("Es Search Data Error:", err)
|
|
|
|
|
|
+ log.Println("Es Search Data Error:", err)
|
|
}
|
|
}
|
|
break
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- log.Debug("此次处理条数 ", len(searchResult.Hits.Hits))
|
|
|
|
|
|
+ log.Println("此次处理条数 ", len(searchResult.Hits.Hits))
|
|
for _, hit := range searchResult.Hits.Hits {
|
|
for _, hit := range searchResult.Hits.Hits {
|
|
//开始处理数据
|
|
//开始处理数据
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
@@ -251,7 +252,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
if json.Unmarshal(tmpHit.Source, &tmp) == nil {
|
|
if json.Unmarshal(tmpHit.Source, &tmp) == nil {
|
|
if stype != "history" {
|
|
if stype != "history" {
|
|
if !SkipData(tmp) {
|
|
if !SkipData(tmp) {
|
|
- log.Debug("跳过该条数据,发布时间在入库时间7天之前,", common.ObjToString(tmp["_id"]))
|
|
|
|
|
|
+ log.Println("跳过该条数据,发布时间在入库时间7天之前,", common.ObjToString(tmp["_id"]))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -262,7 +263,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
bidopentime := common.Int64All(tmp["bidopentime"])
|
|
bidopentime := common.Int64All(tmp["bidopentime"])
|
|
comeintime := common.Int64All(tmp["comeintime"])
|
|
comeintime := common.Int64All(tmp["comeintime"])
|
|
if bidopentime-comeintime <= 7*24*60*60 {
|
|
if bidopentime-comeintime <= 7*24*60*60 {
|
|
- log.Debug("跳过该条数据,开标时间-入库时间<=7天,", id)
|
|
|
|
|
|
+ log.Println("跳过该条数据,开标时间-入库时间<=7天,", id)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -270,7 +271,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
//河南移动,过滤掉中国移动采购网招标数据
|
|
//河南移动,过滤掉中国移动采购网招标数据
|
|
if CheckBidHrefRuleIdMap[dm.ID] {
|
|
if CheckBidHrefRuleIdMap[dm.ID] {
|
|
if strings.Contains(common.ObjToString(tmp["href"]), "b2b.10086.cn") {
|
|
if strings.Contains(common.ObjToString(tmp["href"]), "b2b.10086.cn") {
|
|
- log.Debug("跳过该条数据,公告原网址中包含 b2b.10086.cn,", id)
|
|
|
|
|
|
+ log.Println("跳过该条数据,公告原网址中包含 b2b.10086.cn,", id)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -338,7 +339,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exactResult := exactMatchs(sr.ExactRule, common.ObjToString(tmp["title"]), common.ObjToString(tmp["detail"]), sr.Maths, nameArr)
|
|
exactResult := exactMatchs(sr.ExactRule, common.ObjToString(tmp["title"]), common.ObjToString(tmp["detail"]), sr.Maths, nameArr)
|
|
- log.Debug("-------------------精准匹配", id, exactResult)
|
|
|
|
|
|
+ log.Println("-------------------精准匹配", id, exactResult)
|
|
if !exactResult {
|
|
if !exactResult {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -372,7 +373,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
/*
|
|
/*
|
|
到此已经匹配完数据
|
|
到此已经匹配完数据
|
|
*/
|
|
*/
|
|
- log.Debug("---------------------", id, IsMatch)
|
|
|
|
|
|
+ log.Println("---------------------", id, IsMatch)
|
|
if IsMatch { //匹配成功,数据上新增规则id,matchKey,item并临时保存数据
|
|
if IsMatch { //匹配成功,数据上新增规则id,matchKey,item并临时保存数据
|
|
// tmpMatchKey := MapDataToArr(matchKey)
|
|
// tmpMatchKey := MapDataToArr(matchKey)
|
|
tmpMatchKeyType := MapDataToArr(matchKeyType)
|
|
tmpMatchKeyType := MapDataToArr(matchKeyType)
|
|
@@ -414,7 +415,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
tempList = append(tempList, k)
|
|
tempList = append(tempList, k)
|
|
}
|
|
}
|
|
tagname = strings.Join(tempList, ",")
|
|
tagname = strings.Join(tempList, ",")
|
|
- log.Debug("=====tagname为空取匹配词为标签名称", tagname)
|
|
|
|
|
|
+ log.Println("=====tagname为空取匹配词为标签名称", tagname)
|
|
}
|
|
}
|
|
tagNameMap[tagname] = true
|
|
tagNameMap[tagname] = true
|
|
tagIdMap[tr.ID] = true
|
|
tagIdMap[tr.ID] = true
|
|
@@ -426,7 +427,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
tempList = append(tempList, k)
|
|
tempList = append(tempList, k)
|
|
}
|
|
}
|
|
tagname = strings.Join(tempList, ",")
|
|
tagname = strings.Join(tempList, ",")
|
|
- log.Debug("=====tagname为空取匹配词为标签名称", tagname)
|
|
|
|
|
|
+ log.Println("=====tagname为空取匹配词为标签名称", tagname)
|
|
}
|
|
}
|
|
tagNameMap[tagname] = true
|
|
tagNameMap[tagname] = true
|
|
tagIdMap[tr.ID] = true
|
|
tagIdMap[tr.ID] = true
|
|
@@ -467,7 +468,6 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
matchKeyTypeTag := map[string]bool{} //记录标签里的关键词对应的匹配方式
|
|
matchKeyTypeTag := map[string]bool{} //记录标签里的关键词对应的匹配方式
|
|
//common.Debug("-------------------------开始排除词匹配--------------------------")
|
|
//common.Debug("-------------------------开始排除词匹配--------------------------")
|
|
for j, tag_nw := range tr.NW { //排除词匹配
|
|
for j, tag_nw := range tr.NW { //排除词匹配
|
|
- log.Debug("打标签2222tag_nw ", tag_nw, fieldText)
|
|
|
|
IsMatchNotKey := RegMatch(fieldText, tag_nw.MatchType, tag_nw.KeyReg, nil, nil, false, false)
|
|
IsMatchNotKey := RegMatch(fieldText, tag_nw.MatchType, tag_nw.KeyReg, nil, nil, false, false)
|
|
if !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) {
|
|
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) {
|
|
@@ -481,7 +481,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
tempList = append(tempList, k)
|
|
tempList = append(tempList, k)
|
|
}
|
|
}
|
|
tagname = strings.Join(tempList, ",")
|
|
tagname = strings.Join(tempList, ",")
|
|
- log.Debug("=====tagname为空取匹配词为标签名称", tagname)
|
|
|
|
|
|
+ log.Println("=====tagname为空取匹配词为标签名称", tagname)
|
|
}
|
|
}
|
|
tagNameMap[tagname] = true
|
|
tagNameMap[tagname] = true
|
|
tagIdMap[tr.ID] = true
|
|
tagIdMap[tr.ID] = true
|
|
@@ -493,7 +493,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
tempList = append(tempList, k)
|
|
tempList = append(tempList, k)
|
|
}
|
|
}
|
|
tagname = strings.Join(tempList, ",")
|
|
tagname = strings.Join(tempList, ",")
|
|
- log.Debug("=====tagname为空取匹配词为标签名称", tagname)
|
|
|
|
|
|
+ log.Println("=====tagname为空取匹配词为标签名称", tagname)
|
|
}
|
|
}
|
|
tagNameMap[tagname] = true
|
|
tagNameMap[tagname] = true
|
|
tagIdMap[tr.ID] = true
|
|
tagIdMap[tr.ID] = true
|
|
@@ -547,7 +547,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
tempList = append(tempList, k)
|
|
tempList = append(tempList, k)
|
|
}
|
|
}
|
|
tagname = strings.Join(tempList, ",")
|
|
tagname = strings.Join(tempList, ",")
|
|
- log.Debug("=====tagname为空取匹配词为标签名称", tagname)
|
|
|
|
|
|
+ log.Println("=====tagname为空取匹配词为标签名称", tagname)
|
|
}
|
|
}
|
|
tagNameMap[tagname] = true
|
|
tagNameMap[tagname] = true
|
|
tagIdMap[tr.ID] = true
|
|
tagIdMap[tr.ID] = true
|
|
@@ -559,7 +559,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
tempList = append(tempList, k)
|
|
tempList = append(tempList, k)
|
|
}
|
|
}
|
|
tagname = strings.Join(tempList, ",")
|
|
tagname = strings.Join(tempList, ",")
|
|
- log.Debug("=====tagname为空取匹配词为标签名称", tagname)
|
|
|
|
|
|
+ log.Println("=====tagname为空取匹配词为标签名称", tagname)
|
|
}
|
|
}
|
|
tagNameMap[tagname] = true
|
|
tagNameMap[tagname] = true
|
|
tagIdMap[tr.ID] = true
|
|
tagIdMap[tr.ID] = true
|
|
@@ -614,7 +614,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
}(hit)
|
|
}(hit)
|
|
numDocs += 1
|
|
numDocs += 1
|
|
if numDocs%500 == 0 {
|
|
if numDocs%500 == 0 {
|
|
- log.Debug("Current:", numDocs)
|
|
|
|
|
|
+ log.Println("Current:", numDocs)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
scrollId = searchResult.ScrollId
|
|
scrollId = searchResult.ScrollId
|
|
@@ -622,9 +622,9 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
}
|
|
}
|
|
wg.Wait()
|
|
wg.Wait()
|
|
client.ClearScroll().ScrollId(scrollId).Do(ctx) //清理游标
|
|
client.ClearScroll().ScrollId(scrollId).Do(ctx) //清理游标
|
|
- log.Debug("SearchRule ID", sr.ID, "Result Data Count:", numDocs)
|
|
|
|
|
|
+ log.Println("SearchRule ID", sr.ID, "Result Data Count:", numDocs)
|
|
} else {
|
|
} else {
|
|
- log.Debug("Customer:", c.Name, "Departmnet", dm.Name, "TagName", sr.Name, "Es Search Data Error,Tag ID:", sr.ID)
|
|
|
|
|
|
+ log.Println("Customer:", c.Name, "Departmnet", dm.Name, "TagName", sr.Name, "Es Search Data Error,Tag ID:", sr.ID)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -632,7 +632,7 @@ func (c *Customer) EsConGetDataV7(stype string, dataSource int, esCon *elastic.E
|
|
|
|
|
|
// 数据去重
|
|
// 数据去重
|
|
func (c *Customer) RemoveRepeatData() {
|
|
func (c *Customer) RemoveRepeatData() {
|
|
- log.Debug("开始数据去重...")
|
|
|
|
|
|
+ log.Println("开始数据去重...")
|
|
defer common.Catch()
|
|
defer common.Catch()
|
|
for _, dm := range c.Departments {
|
|
for _, dm := range c.Departments {
|
|
for _, dataMapArr := range dm.DepartmentData { //一个部门的所有数据
|
|
for _, dataMapArr := range dm.DepartmentData { //一个部门的所有数据
|
|
@@ -684,7 +684,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.Debug("开始组装保存数据...")
|
|
|
|
|
|
+ log.Println("开始组装保存数据...")
|
|
defer common.Catch()
|
|
defer common.Catch()
|
|
ch := make(chan bool, 10)
|
|
ch := make(chan bool, 10)
|
|
wg := &sync.WaitGroup{}
|
|
wg := &sync.WaitGroup{}
|
|
@@ -705,7 +705,7 @@ func (c *Customer) AssembelAndSaveData(historyId string, isFilter, noticeFilter,
|
|
}(tmp)
|
|
}(tmp)
|
|
n++
|
|
n++
|
|
if n%500 == 0 {
|
|
if n%500 == 0 {
|
|
- log.Debug("Current:", n)
|
|
|
|
|
|
+ log.Println("Current:", n)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
wg.Wait()
|
|
wg.Wait()
|
|
@@ -726,7 +726,7 @@ func (c *Customer) AssembelAndSaveData(historyId string, isFilter, noticeFilter,
|
|
}(tmp)
|
|
}(tmp)
|
|
n++
|
|
n++
|
|
if n%500 == 0 {
|
|
if n%500 == 0 {
|
|
- log.Debug("Current:", n)
|
|
|
|
|
|
+ log.Println("Current:", n)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -752,7 +752,7 @@ func (c *Customer) AssembelAndSaveData(historyId string, isFilter, noticeFilter,
|
|
}
|
|
}
|
|
wg.Wait()
|
|
wg.Wait()
|
|
}*/
|
|
}*/
|
|
- log.Debug("数据保存完毕... Save Number:", n)
|
|
|
|
|
|
+ log.Println("数据保存完毕... Save Number:", n)
|
|
}
|
|
}
|
|
|
|
|
|
// 获取用户所有规则
|
|
// 获取用户所有规则
|
|
@@ -851,10 +851,10 @@ func (sr *SearchRule) GetEs(department, esquery string, tmpRange bson.M) {
|
|
if err == nil {
|
|
if err == nil {
|
|
sr.EsQuery = string(strquery)
|
|
sr.EsQuery = string(strquery)
|
|
} else {
|
|
} else {
|
|
- log.Debug("Department:", department, "Es Error,Tag ID:", sr.ID)
|
|
|
|
|
|
+ log.Println("Department:", department, "Es Error,Tag ID:", sr.ID)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- log.Debug("Department:", department, "Es Error,Tag ID:", sr.ID)
|
|
|
|
|
|
+ log.Println("Department:", department, "Es Error,Tag ID:", sr.ID)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|