Răsfoiți Sursa

fix:活跃用户

duxin 9 luni în urmă
părinte
comite
fd93429442

+ 6 - 0
userSign/config.yaml

@@ -23,3 +23,9 @@ mongodb:
     userName: "jianyu"
     password: "jylog2020_123"
 
+activeCode:
+  pcCode: pc_active
+  wxCode: wx_active
+  appCode: app_active
+  unActive30: unActive30
+  unActive90: unActive90

+ 60 - 0
userSign/lunarActivity/active.go

@@ -0,0 +1,60 @@
+package lunarActivity
+
+import (
+	"context"
+	"fmt"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+	"strings"
+	"time"
+	"workTasks/userSign/match"
+)
+
+var (
+	ctx           = context.TODO()
+	ActiveCodeMap map[string]interface{}
+)
+
+func init() {
+	ActiveCodeMap = g.Cfg().MustGet(ctx, "activeCode.pcCode").Map()
+}
+
+func Active() {
+	var sqlIds, delCode, pcBaseId, wxBaseId, appBaseId []string
+	rPc, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId FROM user_log_byHour WHERE create_time >'%s' AND s_source ='pc';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
+	if err == nil && !rPc.IsEmpty() {
+		for _, m := range rPc.List() {
+			// 插入pc30天活跃用户
+			pcBaseId = append(pcBaseId, gconv.String(m["baseUserId"]))
+		}
+		if len(pcBaseId) > 0 {
+			delCode = append(delCode, gconv.String(ActiveCodeMap["pcCode"]))
+			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["pcCode"], strings.Join(pcBaseId, ",")))
+		}
+	}
+	rWx, err1 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId  FROM user_log_byHour WHERE create_time >'%s' AND s_source ='wx';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
+	if err1 == nil && !rWx.IsEmpty() {
+		for _, m := range rWx.List() {
+			// 插入wx30天活跃用户
+			wxBaseId = append(wxBaseId, gconv.String(m["baseUserId"]))
+		}
+		if len(wxBaseId) > 0 {
+			delCode = append(delCode, gconv.String(ActiveCodeMap["wxCode"]))
+			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["wxCode"], strings.Join(wxBaseId, ",")))
+		}
+	}
+	rApp, err2 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId FROM user_log_byHour WHERE create_time >'%s' AND s_source ='app';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
+	if err2 == nil && !rApp.IsEmpty() {
+		for _, m := range rApp.List() {
+			// 插入app30天活跃用户
+			appBaseId = append(appBaseId, gconv.String(m["baseUserId"]))
+		}
+		if len(appBaseId) > 0 {
+			delCode = append(delCode, gconv.String(ActiveCodeMap["appCode"]))
+			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["appCode"], strings.Join(appBaseId, ",")))
+		}
+	}
+	if len(sqlIds) > 0 {
+		match.SetUserTag(delCode, sqlIds)
+	}
+}

+ 48 - 0
userSign/lunarActivity/unActive.go

@@ -0,0 +1,48 @@
+package lunarActivity
+
+import (
+	"fmt"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+	"strings"
+	"time"
+	"workTasks/userSign/match"
+)
+
+func UnActive() {
+	//30天未活跃
+	var sqlIds, delCode, unActive30, unActive90 []string
+	rMonth, err2 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(dmp.baseUserId) as baseUserId1 FROM dwd_mgo_position dmp
+	left join (	SELECT DISTINCT(baseUserId) as baseUserId
+    FROM user_log_byHour ulbh
+    WHERE create_time > '%s' ) ulog  on  dmp.baseUserId =ulog.baseUserId where ulog.baseUserId=0`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
+	if err2 == nil && !rMonth.IsEmpty() {
+		for _, m := range rMonth.List() {
+			// 插入30天未活跃
+			unActive30 = append(unActive30, gconv.String(m["baseUserId"]))
+		}
+		if len(unActive30) > 0 {
+			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["unActive30"], strings.Join(unActive30, ",")))
+			delCode = append(delCode, gconv.String(ActiveCodeMap["unActive30"]))
+		}
+	}
+
+	//90天未活跃
+	rQuarter, err2 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(dmp.baseUserId) as baseUserId1 FROM dwd_mgo_position dmp
+	left join (	SELECT DISTINCT(baseUserId) as baseUserId
+    FROM user_log_byHour ulbh
+    WHERE create_time > '%s' ) ulog  on  dmp.baseUserId =ulog.baseUserId where ulog.baseUserId=0`, time.Now().AddDate(0, 0, -90).Format(time.DateTime)))
+	if err2 == nil && !rQuarter.IsEmpty() {
+		for _, m := range rQuarter.List() {
+			// 插入90天未活跃
+			unActive90 = append(unActive90, gconv.String(m["baseUserId"]))
+		}
+		if len(unActive90) > 0 {
+			delCode = append(delCode, gconv.String(ActiveCodeMap["unActive30"]))
+			sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["unActive90"], strings.Join(unActive90, ",")))
+		}
+	}
+	if len(sqlIds) > 0 {
+		match.SetUserTag(delCode, sqlIds)
+	}
+}

+ 19 - 0
userSign/match/util.go

@@ -0,0 +1,19 @@
+package match
+
+import (
+	"context"
+	"fmt"
+	"github.com/gogf/gf/v2/frame/g"
+	"strings"
+)
+
+var (
+	ctx = context.TODO()
+)
+
+func SetUserTag(delCode []string, sqlIds []string) {
+	g.DB().Exec(ctx, fmt.Sprintf(`DELETE FROM dwd_d_tag WHERE code in ('%s')`, strings.Join(delCode, `','`)))
+	// `id` UInt64, `code` String, `name` String, `bitobj` AggregateFunction(groupBitmap, UInt64),  `groupid` UInt64, `created_at` DateTime, `created_by` String, `bit_num` UInt64
+	g.DB().Exec(ctx, fmt.Sprintf(`INSERT INTO dwd_d_tag (code, name, bitobj, groupid, created_at, created_by, bit_num)
+VALUES (%s)`, strings.Join(sqlIds, ",")))
+}