|
@@ -1,8 +1,12 @@
|
|
|
package entity
|
|
|
|
|
|
import (
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "fmt"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
"log"
|
|
|
"regexp"
|
|
|
+ "strings"
|
|
|
"sync"
|
|
|
"telemarketingEtl/config"
|
|
|
"telemarketingEtl/util"
|
|
@@ -137,3 +141,263 @@ func getToday(createtime int64) (start, end string) {
|
|
|
endOfDay := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location())
|
|
|
return startOfDay.Format(date.Date_Full_Layout), endOfDay.Format(date.Date_Full_Layout)
|
|
|
}
|
|
|
+
|
|
|
+type UserVisit struct {
|
|
|
+ userId string
|
|
|
+ uId string
|
|
|
+ vDate string
|
|
|
+ days int
|
|
|
+}
|
|
|
+
|
|
|
+// 近30天最大访问次数
|
|
|
+func CountMaxVisit() {
|
|
|
+
|
|
|
+ var (
|
|
|
+ count = 0
|
|
|
+
|
|
|
+ mArr []*UserVisit
|
|
|
+ mData = make(map[string]*UserVisit)
|
|
|
+ )
|
|
|
+
|
|
|
+ sql := "SELECT x.*, y.uid FROM dwd_f_userbase_visit_info x LEFT JOIN dwd_f_userbase_baseinfo y ON x.userid = y.userid WHERE DATE(`date`) BETWEEN DATE(NOW() - INTERVAL 30 DAY) AND DATE(NOW()) ORDER BY `date` ASC"
|
|
|
+ rows, err := config.JianyuSubjectdb.DB.Query(sql)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("CountMaxVisit---", err)
|
|
|
+ }
|
|
|
+ columns, err := rows.Columns()
|
|
|
+ for rows.Next() {
|
|
|
+ scanArgs := make([]interface{}, len(columns))
|
|
|
+ values := make([]interface{}, len(columns))
|
|
|
+ ret := make(map[string]interface{})
|
|
|
+ for k := range values {
|
|
|
+ scanArgs[k] = &values[k]
|
|
|
+ }
|
|
|
+ err = rows.Scan(scanArgs...)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("CountMaxVisit---", err)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ for i, col := range values {
|
|
|
+ if v, ok := col.([]uint8); ok {
|
|
|
+ ret[columns[i]] = string(v)
|
|
|
+ } else {
|
|
|
+ ret[columns[i]] = col
|
|
|
+ }
|
|
|
+ }
|
|
|
+ count++
|
|
|
+ if count%2000 == 0 {
|
|
|
+ log.Println("current-------", count)
|
|
|
+ }
|
|
|
+ userid := common.ObjToString(ret["userid"])
|
|
|
+ mDate := common.ObjToString(ret["date"])
|
|
|
+ mArr = append(mArr, &UserVisit{
|
|
|
+ userId: userid,
|
|
|
+ uId: common.ObjToString(ret["uid"]),
|
|
|
+ vDate: strings.Split(mDate, " ")[0],
|
|
|
+ })
|
|
|
+ }
|
|
|
+ _ = rows.Close()
|
|
|
+
|
|
|
+ for _, v := range mArr {
|
|
|
+ if mData[v.userId] != nil {
|
|
|
+ v1 := mData[v.userId]
|
|
|
+ if d := VerifyDate(v1.vDate, v.vDate); d == 1 {
|
|
|
+ v1.days++
|
|
|
+ mData[v.userId] = &UserVisit{
|
|
|
+ userId: v.userId,
|
|
|
+ uId: v.uId,
|
|
|
+ vDate: v.vDate,
|
|
|
+ days: v1.days,
|
|
|
+ }
|
|
|
+ } else if d > 1 {
|
|
|
+ mData[v.userId] = &UserVisit{
|
|
|
+ userId: v.userId,
|
|
|
+ uId: v.uId,
|
|
|
+ vDate: v.vDate,
|
|
|
+ days: 1,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mData[v.userId] = &UserVisit{
|
|
|
+ userId: v.userId,
|
|
|
+ uId: v.uId,
|
|
|
+ vDate: v.vDate,
|
|
|
+ days: 1,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range mData {
|
|
|
+ if b := config.JianyuSubjectdb.Update("dwd_f_crm_attribute_label", bson.M{"uid": v.uId}, bson.M{"continuous_visit_day": v.days}); !b {
|
|
|
+ config.JianyuSubjectdb.Insert("dwd_f_crm_attribute_label", map[string]interface{}{
|
|
|
+ "uid": v.days,
|
|
|
+ "members_info": "昨日未浏览",
|
|
|
+ "updatetime": time.Now(),
|
|
|
+ "continuous_visit_day": v.days,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// @Author jianghan
|
|
|
+// @Description 日期相差天数
|
|
|
+// @Date 2024/8/22
|
|
|
+func VerifyDate(d1, d2 string) int {
|
|
|
+ if d1 == d2 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ d11, err := time.Parse(date.Date_Short_Layout, d1)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error parsing d1:", err)
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ d21, err := time.Parse(date.Date_Short_Layout, d2)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error parsing d2:", err)
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ days := int(d21.Sub(d11).Hours() / 24)
|
|
|
+ return days
|
|
|
+}
|
|
|
+
|
|
|
+var (
|
|
|
+ firstLoad2, firstLoad3 = true, true
|
|
|
+
|
|
|
+ mSearchMap = make(map[string]int)
|
|
|
+)
|
|
|
+
|
|
|
+func Count3DaysSearch() {
|
|
|
+ var (
|
|
|
+ sql string
|
|
|
+ count int
|
|
|
+ total int64
|
|
|
+ )
|
|
|
+
|
|
|
+ // 判断当日第一次执行
|
|
|
+ currentDateMx.Lock()
|
|
|
+ if CurrentDate != date.NowFormat(date.Date_Short_Layout) {
|
|
|
+ firstLoad2 = true
|
|
|
+ CurrentDate = date.NowFormat(date.Date_Short_Layout)
|
|
|
+ } else {
|
|
|
+ firstLoad2 = false
|
|
|
+ }
|
|
|
+ currentDateMx.Unlock()
|
|
|
+
|
|
|
+ if firstLoad2 {
|
|
|
+ // 当日首次执行 1、全部归0 search_count
|
|
|
+ config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET search_count = 0")
|
|
|
+ sql = "SELECT v.userid, b.uid, v.date, v.searchnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.base_user_id WHERE DATE(date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW()) ORDER BY date ASC"
|
|
|
+ } else {
|
|
|
+ aTime := time.Now().Add(-1 * time.Hour)
|
|
|
+ sql = "SELECT v.userid, b.uid, v.date, v.searchnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.base_user_id WHERE date >= " + aTime.Format(time.DateTime) + " ORDER BY date ASC"
|
|
|
+ }
|
|
|
+ total = config.JianyuSubjectdb.CountBySql(sql)
|
|
|
+ log.Println("Count3DaysSearch getRecord---", total)
|
|
|
+ if total <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rows, err := config.JianyuSubjectdb.DB.Query(sql)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("Count3DaysSearch---", err)
|
|
|
+ }
|
|
|
+ for rows.Next() {
|
|
|
+ count++
|
|
|
+ if count%2000 == 0 {
|
|
|
+ log.Println("Count3DaysSearch current-------", count)
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ userId string
|
|
|
+ uid string
|
|
|
+ mDate time.Time
|
|
|
+ searchNum int
|
|
|
+ )
|
|
|
+ if err = rows.Scan(&userId, &uid, &mDate, &searchNum); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+ mSearchMap[uid] += searchNum
|
|
|
+ }
|
|
|
+ _ = rows.Close()
|
|
|
+
|
|
|
+ for k, v := range mSearchMap {
|
|
|
+ if b := config.JianyuSubjectdb.Update("dwd_f_crm_attribute_label", bson.M{"uid": k}, bson.M{"search_count": v}); !b {
|
|
|
+ config.JianyuSubjectdb.Insert("dwd_f_crm_attribute_label", map[string]interface{}{
|
|
|
+ "uid": k,
|
|
|
+ "members_info": "昨日未浏览",
|
|
|
+ "updatetime": time.Now(),
|
|
|
+ "search_count": v,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func Count3DaysDetail() {
|
|
|
+ var (
|
|
|
+ sql string
|
|
|
+ count int
|
|
|
+ total int64
|
|
|
+ )
|
|
|
+
|
|
|
+ // 判断当日第一次执行
|
|
|
+ currentDateMx.Lock()
|
|
|
+ if CurrentDate != date.NowFormat(date.Date_Short_Layout) {
|
|
|
+ firstLoad3 = true
|
|
|
+ CurrentDate = date.NowFormat(date.Date_Short_Layout)
|
|
|
+ } else {
|
|
|
+ firstLoad3 = false
|
|
|
+ }
|
|
|
+ currentDateMx.Unlock()
|
|
|
+
|
|
|
+ if firstLoad3 {
|
|
|
+ // 当日首次执行 1、全部归0 click_detail_count
|
|
|
+ config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET click_detail_count = 0")
|
|
|
+ sql = "SELECT v.userid, b.uid, v.date, v.contentnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.base_user_id WHERE DATE(date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW()) ORDER BY date ASC"
|
|
|
+ } else {
|
|
|
+ aTime := time.Now().Add(-1 * time.Hour)
|
|
|
+ sql = "SELECT v.userid, b.uid, v.date, v.contentnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.base_user_id WHERE date >= " + aTime.Format(time.DateTime) + " ORDER BY date ASC"
|
|
|
+ }
|
|
|
+ total = config.JianyuSubjectdb.CountBySql(sql)
|
|
|
+ log.Println("Count3DaysDetail getRecord---", total)
|
|
|
+ if total <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rows, err := config.JianyuSubjectdb.DB.Query(sql)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("Count3DaysDetail---", err)
|
|
|
+ }
|
|
|
+ for rows.Next() {
|
|
|
+ count++
|
|
|
+ if count%2000 == 0 {
|
|
|
+ log.Println("Count3DaysDetail current-------", count)
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ userId string
|
|
|
+ uid string
|
|
|
+ mDate time.Time
|
|
|
+ contentNum int
|
|
|
+ )
|
|
|
+ if err = rows.Scan(&userId, &uid, &mDate, &contentNum); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+ mSearchMap[uid] += contentNum
|
|
|
+ }
|
|
|
+ _ = rows.Close()
|
|
|
+
|
|
|
+ for k, v := range mSearchMap {
|
|
|
+ if b := config.JianyuSubjectdb.Update("dwd_f_crm_attribute_label", bson.M{"uid": k}, bson.M{"click_detail_count": v}); !b {
|
|
|
+ config.JianyuSubjectdb.Insert("dwd_f_crm_attribute_label", map[string]interface{}{
|
|
|
+ "uid": k,
|
|
|
+ "members_info": "昨日未浏览",
|
|
|
+ "updatetime": time.Now(),
|
|
|
+ "click_detail_count": v,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func VipExpire() {
|
|
|
+ now := time.Now()
|
|
|
+ config.JianyuSubjectdb.ExecBySql("update dwd_f_crm_attribute_label set supersub = 0 where supersub = 1")
|
|
|
+ config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_data_equity_info SET supersub = 1 WHERE product_type = '超级订阅' AND endtime > ?", now.Format(date.Date_Short_Layout))
|
|
|
+ config.JianyuSubjectdb.ExecBySql("update dwd_f_crm_attribute_label set areasubpkg = 0 where areasubpkg = 1")
|
|
|
+ config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_data_equity_info SET areasubpkg = 1 WHERE product_type = '省份订阅包' AND endtime > ?", now.Format(date.Date_Short_Layout))
|
|
|
+}
|