|
@@ -18,7 +18,6 @@ import (
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
- "go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
type EventInfo struct {
|
|
type EventInfo struct {
|
|
@@ -126,138 +125,135 @@ func EventInfoAdd(start, end int64) {
|
|
tables := g.Cfg().MustGet(ctx, "logTables").Strings()
|
|
tables := g.Cfg().MustGet(ctx, "logTables").Strings()
|
|
index := g.Cfg().MustGet(ctx, "index").Int()
|
|
index := g.Cfg().MustGet(ctx, "index").Int()
|
|
log.Println("analy tables:", tables)
|
|
log.Println("analy tables:", tables)
|
|
-
|
|
|
|
- th_mgo := util.NewThreads(len(tables))
|
|
|
|
|
|
+ query := map[string]interface{}{
|
|
|
|
+ "_id": map[string]interface{}{
|
|
|
|
+ "$gte": util.MongoId(start),
|
|
|
|
+ "$lt": util.MongoId(end),
|
|
|
|
+ },
|
|
|
|
+ }
|
|
for _, table := range tables {
|
|
for _, table := range tables {
|
|
- th_mgo.Open()
|
|
|
|
- go func(table string) {
|
|
|
|
- defer th_mgo.Close()
|
|
|
|
- of := options.Find()
|
|
|
|
- of.SetProjection(g.Map{"url": 1, "userid": 1, "hour": 1, "month": 1, "day": 1, "date": 1, "client": 1, "refer": 1})
|
|
|
|
- coll := config.MgoLog.C.Database(config.MgoLog.DbName).Collection(table)
|
|
|
|
- cur, err := coll.Find(ctx, g.Map{"_id": g.Map{"$gte": util.MongoId(start), "$lt": util.MongoId(end)}}, of)
|
|
|
|
- if err == nil && cur.Err() == nil {
|
|
|
|
- n := 0
|
|
|
|
- for ; cur.Next(ctx); n++ {
|
|
|
|
- v := g.Map{}
|
|
|
|
- er := cur.Decode(&v)
|
|
|
|
- if er != nil {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- userid := gconv.String(v["userid"])
|
|
|
|
- if userid == "" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- url_ := gconv.String(v["url"])
|
|
|
|
- if !filter(url_) {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- platform := APP
|
|
|
|
- if table == "jy_logs" {
|
|
|
|
- platform = PC
|
|
|
|
- if client := gconv.String(v["client"]); client != "" {
|
|
|
|
- if regWx.MatchString(client) {
|
|
|
|
- platform = WX
|
|
|
|
- }
|
|
|
|
|
|
+ func(table string) {
|
|
|
|
+ session := config.MgoLog.GetMgoConn()
|
|
|
|
+ iter := session.DB("qfw").C(table).Find(query).Iter()
|
|
|
|
+ count := 0
|
|
|
|
+ for thisData := map[string]interface{}{}; iter.Next(&thisData); {
|
|
|
|
+ userid := gconv.String(thisData["userid"])
|
|
|
|
+ if userid == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ url_ := gconv.String(thisData["url"])
|
|
|
|
+ if !filter(url_) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ platform := APP
|
|
|
|
+ if table == "jy_logs" {
|
|
|
|
+ platform = PC
|
|
|
|
+ if client := gconv.String(thisData["client"]); client != "" {
|
|
|
|
+ if regWx.MatchString(client) {
|
|
|
|
+ platform = WX
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //职位id转换userid
|
|
|
|
- if !mongodb.IsObjectIdHex(userid) {
|
|
|
|
- userid = GetUserIdByPositionId(userid)
|
|
|
|
- }
|
|
|
|
- refer := gconv.String(v["refer"]) //用于取分客户监控,客户监控的url地址和采购单位画像是一个
|
|
|
|
- eventtype := ""
|
|
|
|
- name := ""
|
|
|
|
- //根据不同url地址获取 标讯的公告名称、采购单位名称、企业名称
|
|
|
|
- if PcArticleReg.MatchString(url_) || AppArticleReg.MatchString(url_) { //三级页根据加密id获取公告id
|
|
|
|
- eventtype = INFO
|
|
|
|
- //截取id
|
|
|
|
- ur := ArticleId.FindStringSubmatch(url_)
|
|
|
|
- if len(ur) > 1 {
|
|
|
|
- uarr := encrypt.BDecodeArticleId2ByCheck(ur[1], encrypt.SE, encrypt.SE2)
|
|
|
|
- if len(uarr) > 0 {
|
|
|
|
- biddingId := uarr[0]
|
|
|
|
- //获取标讯标题
|
|
|
|
- bdata, ok := config.MgoBid.FindById("bidding", biddingId, `{"title":1}`)
|
|
|
|
- if ok && bdata != nil && len(*bdata) > 0 {
|
|
|
|
- name = gconv.String((*bdata)["title"])
|
|
|
|
|
|
+ }
|
|
|
|
+ //职位id转换userid
|
|
|
|
+ if !mongodb.IsObjectIdHex(userid) {
|
|
|
|
+ userid = GetUserIdByPositionId(userid)
|
|
|
|
+ }
|
|
|
|
+ if userid == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ refer := gconv.String(thisData["refer"]) //用于取分客户监控,客户监控的url地址和采购单位画像是一个
|
|
|
|
+ eventtype := ""
|
|
|
|
+ name := ""
|
|
|
|
+ //根据不同url地址获取 标讯的公告名称、采购单位名称、企业名称
|
|
|
|
+ if PcArticleReg.MatchString(url_) || AppArticleReg.MatchString(url_) { //三级页根据加密id获取公告id
|
|
|
|
+ eventtype = INFO
|
|
|
|
+ //截取id
|
|
|
|
+ ur := ArticleId.FindStringSubmatch(url_)
|
|
|
|
+ if len(ur) > 1 {
|
|
|
|
+ uarr := BDecodeArticleId2ByCheck(ur[1], encrypt.SE, encrypt.SE2)
|
|
|
|
+ if len(uarr) > 0 {
|
|
|
|
+ biddingId := uarr[0]
|
|
|
|
+ //获取标讯标题
|
|
|
|
+ bdata, ok := config.MgoBid.FindById("bidding", biddingId, `{"title":1}`)
|
|
|
|
+ if ok && bdata != nil && len(*bdata) > 0 {
|
|
|
|
+ name = gconv.String((*bdata)["title"])
|
|
|
|
+ if name == "" {
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else if pcBuyPortraitReg.MatchString(url_) && !strings.Contains(refer, "/swordfish/page_big_pc/my_client") {
|
|
|
|
- eventtype = BUYPORTRAIT
|
|
|
|
- na := PcBuyPortraitNameReg.FindStringSubmatch(url_)
|
|
|
|
- if len(na) > 1 {
|
|
|
|
- name = util.Unescape(na[1])
|
|
|
|
- }
|
|
|
|
- } else if AppBuyPortraitReg.MatchString(url_) {
|
|
|
|
- eventtype = BUYPORTRAIT
|
|
|
|
- na := AppBuyPortraitNameReg.FindStringSubmatch(url_)
|
|
|
|
- if len(na) > 1 {
|
|
|
|
- name = util.Unescape(na[1])
|
|
|
|
- }
|
|
|
|
- } else if PcEntIntelligentceMonitorReg.MatchString(url_) && !strings.Contains(refer, "/swordfish/page_big_pc/free/ent_follow") {
|
|
|
|
- eventtype = ENTPORTRAIT
|
|
|
|
- na := PcEntPortraitNameReg.FindStringSubmatch(url_)
|
|
|
|
- if len(na) > 1 {
|
|
|
|
- entId := util.DecodeId(na[1])
|
|
|
|
- name = GetEntNameByEntId(entId)
|
|
|
|
- }
|
|
|
|
- } else if AppEntPortraitReg.MatchString(url_) {
|
|
|
|
- eventtype = ENTPORTRAIT
|
|
|
|
- //app端作为参数拼接过来的。和pc不一样
|
|
|
|
- u, err := url.Parse(url_)
|
|
|
|
- if err == nil {
|
|
|
|
- eId := u.Query().Get("eId")
|
|
|
|
- entId := util.DecodeId(eId)
|
|
|
|
- name = GetEntNameByEntId(entId)
|
|
|
|
- }
|
|
|
|
- } else if ProductIndexReg.MatchString(url_) {
|
|
|
|
- eventtype = PRODUCTINDEX
|
|
|
|
- } else if PcClientReg.MatchString(url_) && strings.Contains(refer, "/swordfish/page_big_pc/my_client") {
|
|
|
|
- eventtype = CLIENT
|
|
|
|
- name = PcClient(url_)
|
|
|
|
- } else if AppClientReg.MatchString(url_) {
|
|
|
|
- eventtype = CLIENT
|
|
|
|
- name = AppClient(url_)
|
|
|
|
- } else if PcProjectMonitorReg.MatchString(url_) {
|
|
|
|
- eventtype = PROJECTPROGRESS
|
|
|
|
- name = ProjectProgress(url_)
|
|
|
|
- } else if PcEntIntelligentceMonitorReg.MatchString(url_) && strings.Contains(refer, "/swordfish/page_big_pc/free/ent_follow") {
|
|
|
|
- eventtype = ENTFOLLOW
|
|
|
|
- name = EntFollow(url_)
|
|
|
|
- } else if PcForecastReg.MatchString(url_) || AppForecastReg.MatchString(url_) {
|
|
|
|
- eventtype = FORECAST
|
|
|
|
- name, _ = Forecast(url_)
|
|
|
|
- } else if PcEntSearchReq.MatchString(url_) {
|
|
|
|
- eventtype = ENTSEARCH
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- createtime := time.Unix(gconv.Int64(v["date"]), 0).Format(date.Date_Full_Layout)
|
|
|
|
- values = append(values, userid, eventtype, name, url_, platform, createtime)
|
|
|
|
- if n%index == 0 {
|
|
|
|
- if len(values) > 0 {
|
|
|
|
- id1, _ := config.JianyuSubjectdb.InsertBatch(DWD_F_USERBASE_EVENT_INFO, fields, values) //id1:数量 id2:开始id索引
|
|
|
|
- if id1 <= 0 {
|
|
|
|
- log.Println(values, "失败")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- values = []interface{}{}
|
|
|
|
|
|
+ } else if pcBuyPortraitReg.MatchString(url_) && !strings.Contains(refer, "/swordfish/page_big_pc/my_client") {
|
|
|
|
+ eventtype = BUYPORTRAIT
|
|
|
|
+ na := PcBuyPortraitNameReg.FindStringSubmatch(url_)
|
|
|
|
+ if len(na) > 1 {
|
|
|
|
+ name = util.Unescape(na[1])
|
|
}
|
|
}
|
|
- if n%200 == 0 {
|
|
|
|
- log.Println("current", table, n)
|
|
|
|
|
|
+ } else if AppBuyPortraitReg.MatchString(url_) {
|
|
|
|
+ eventtype = BUYPORTRAIT
|
|
|
|
+ na := AppBuyPortraitNameReg.FindStringSubmatch(url_)
|
|
|
|
+ if len(na) > 1 {
|
|
|
|
+ name = util.Unescape(na[1])
|
|
}
|
|
}
|
|
|
|
+ } else if PcEntIntelligentceMonitorReg.MatchString(url_) && !strings.Contains(refer, "/swordfish/page_big_pc/free/ent_follow") {
|
|
|
|
+ eventtype = ENTPORTRAIT
|
|
|
|
+ na := PcEntPortraitNameReg.FindStringSubmatch(url_)
|
|
|
|
+ if len(na) > 1 {
|
|
|
|
+ entId := util.DecodeId(na[1])
|
|
|
|
+ name = GetEntNameByEntId(entId)
|
|
|
|
+ }
|
|
|
|
+ } else if AppEntPortraitReg.MatchString(url_) {
|
|
|
|
+ eventtype = ENTPORTRAIT
|
|
|
|
+ //app端作为参数拼接过来的。和pc不一样
|
|
|
|
+ u, err := url.Parse(url_)
|
|
|
|
+ if err == nil {
|
|
|
|
+ eId := u.Query().Get("eId")
|
|
|
|
+ entId := util.DecodeId(eId)
|
|
|
|
+ name = GetEntNameByEntId(entId)
|
|
|
|
+ }
|
|
|
|
+ } else if ProductIndexReg.MatchString(url_) {
|
|
|
|
+ eventtype = PRODUCTINDEX
|
|
|
|
+ } else if PcClientReg.MatchString(url_) && strings.Contains(refer, "/swordfish/page_big_pc/my_client") {
|
|
|
|
+ eventtype = CLIENT
|
|
|
|
+ name = PcClient(url_)
|
|
|
|
+ } else if AppClientReg.MatchString(url_) {
|
|
|
|
+ eventtype = CLIENT
|
|
|
|
+ name = AppClient(url_)
|
|
|
|
+ } else if PcProjectMonitorReg.MatchString(url_) {
|
|
|
|
+ eventtype = PROJECTPROGRESS
|
|
|
|
+ name = ProjectProgress(url_)
|
|
|
|
+ } else if PcEntIntelligentceMonitorReg.MatchString(url_) && strings.Contains(refer, "/swordfish/page_big_pc/free/ent_follow") {
|
|
|
|
+ eventtype = ENTFOLLOW
|
|
|
|
+ name = EntFollow(url_)
|
|
|
|
+ } else if PcForecastReg.MatchString(url_) || AppForecastReg.MatchString(url_) {
|
|
|
|
+ eventtype = FORECAST
|
|
|
|
+ name, _ = Forecast(url_)
|
|
|
|
+ } else if PcEntSearchReq.MatchString(url_) {
|
|
|
|
+ eventtype = ENTSEARCH
|
|
}
|
|
}
|
|
- //
|
|
|
|
- if len(values) > 0 {
|
|
|
|
- id1, _ := config.JianyuSubjectdb.InsertBatch(DWD_F_USERBASE_EVENT_INFO, fields, values) //id1:数量 id2:开始id索引
|
|
|
|
- if id1 <= 0 {
|
|
|
|
- log.Println(values, "失败~")
|
|
|
|
|
|
+ createtime := time.Unix(gconv.Int64(thisData["date"]), 0).Format(date.Date_Full_Layout)
|
|
|
|
+ values = append(values, userid, eventtype, name, url_, platform, createtime)
|
|
|
|
+ count++
|
|
|
|
+ if count%index == 0 {
|
|
|
|
+ if len(values) > 0 {
|
|
|
|
+ id1, _ := config.JianyuSubjectdb.InsertBatch(DWD_F_USERBASE_EVENT_INFO, fields, values) //id1:数量 id2:开始id索引
|
|
|
|
+ if id1 <= 0 {
|
|
|
|
+ log.Println(values, "失败")
|
|
|
|
+ }
|
|
|
|
+ values = []interface{}{}
|
|
}
|
|
}
|
|
- values = []interface{}{}
|
|
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- log.Println(err)
|
|
|
|
|
|
+ if count%50000 == 0 {
|
|
|
|
+ log.Println("current", table, count)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //
|
|
|
|
+ if len(values) > 0 {
|
|
|
|
+ id1, _ := config.JianyuSubjectdb.InsertBatch(DWD_F_USERBASE_EVENT_INFO, fields, values) //id1:数量 id2:开始id索引
|
|
|
|
+ if id1 <= 0 {
|
|
|
|
+ log.Println(values, "失败~")
|
|
|
|
+ }
|
|
|
|
+ values = []interface{}{}
|
|
}
|
|
}
|
|
}(table)
|
|
}(table)
|
|
}
|
|
}
|
|
@@ -417,3 +413,15 @@ func GetInfoByBid(bid string) (string, string) {
|
|
|
|
|
|
return title, href
|
|
return title, href
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//短地址解密,二次解密带校验和
|
|
|
|
+func BDecodeArticleId2ByCheck(id string, s1, s2 *encrypt.SimpleEncrypt) []string {
|
|
|
|
+ if !strings.Contains(id, "+") { //新加密算法解密
|
|
|
|
+ id, _ = url.QueryUnescape(id)
|
|
|
|
+ }
|
|
|
|
+ if len(id) > 2 {
|
|
|
|
+ kstr := s2.DecodeStringByCheck(id[3:])
|
|
|
|
+ return strings.Split(s1.DecodeStringByCheck(kstr), ",")
|
|
|
|
+ }
|
|
|
|
+ return []string{}
|
|
|
|
+}
|