wangkaiyue 10 月之前
父节点
当前提交
ba41988844
共有 2 个文件被更改,包括 20 次插入0 次删除
  1. 4 0
      userSign/main.go
  2. 16 0
      userSign/userAnalysis/analysisManager.go

+ 4 - 0
userSign/main.go

@@ -44,4 +44,8 @@ func runOnce(ctx context.Context) {
 			allRes = append(allRes, &userAnalysis.AnalysisRes{Name: fmt.Sprintf("%d天未活跃用户", day), Code: "hasPay", Data: res})
 		}
 	}
+
+	for _, re := range allRes {
+		re.Save(ctx)
+	}
 }

+ 16 - 0
userSign/userAnalysis/analysisManager.go

@@ -1,8 +1,11 @@
 package userAnalysis
 
 import (
+	"context"
+	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/util/gconv"
+	"strings"
 )
 
 type (
@@ -21,6 +24,19 @@ type (
 	}
 )
 
+func (ar *AnalysisRes) Save(ctx context.Context) {
+	list := make([]string, 0, len(ar.Data))
+	for id, ok := range ar.Data {
+		if !ok {
+			continue
+		}
+		list = append(list, fmt.Sprintf("toUInt64(%d)", id))
+	}
+	if _, err := g.DB().Exec(ctx, fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapBuild([%v]) WHERE code = %v;`, strings.Join(list, ","), ar.Code)); err != nil {
+		g.Log().Errorf(ctx, "更新标签%s异常 %v", ar.Code, err)
+	}
+}
+
 func NewManager() *UserAnalysis {
 	return &UserAnalysis{
 		UserMapping:  map[string]BaseUserId{},