1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package userAnalysis
- import (
- "context"
- "fmt"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/util/gconv"
- "strings"
- )
- type (
- UserAnalysis struct {
- UserMapping map[string]BaseUserId //职位id、mongouserId对应的baseUserId
- BinPhone, BindMail map[BaseUserId]bool
- Vip, Vip15, Vip30 map[BaseUserId]bool
- Member, MemberExpire map[BaseUserId]bool
- }
- BaseUserId int64
- AnalysisRes struct {
- Name, Code string //标签名字
- Data map[BaseUserId]bool //数据
- }
- )
- func (ar *AnalysisRes) UpdateTag(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))
- }
- execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapBuild([%v]) WHERE code = '%v';`, strings.Join(list, ","), ar.Code)
- if _, err := g.DB().Exec(ctx, execSql); err != nil {
- g.Log().Errorf(ctx, "更新标签%s异常 %v", ar.Code, err)
- }
- }
- func NewManager() *UserAnalysis {
- return &UserAnalysis{
- UserMapping: map[string]BaseUserId{},
- BinPhone: map[BaseUserId]bool{},
- BindMail: map[BaseUserId]bool{},
- Vip: map[BaseUserId]bool{},
- Vip15: map[BaseUserId]bool{},
- Vip30: map[BaseUserId]bool{},
- Member: map[BaseUserId]bool{},
- MemberExpire: map[BaseUserId]bool{},
- }
- }
- func (ua *UserAnalysis) LoadMapping() error {
- data, err := g.DB().Query(ctx, "SELECT mgoUserId,positionId,baseUserId FROM dwd_mgo_position")
- if err != nil {
- return err
- }
- newMapping := map[string]BaseUserId{}
- for _, m := range data.List() {
- var (
- mgoUserId = gconv.String(m["mgoUserId"])
- positionId = gconv.String(m["positionId"])
- baseUserId = BaseUserId(gconv.Int64(m["baseUserId"]))
- )
- newMapping[mgoUserId] = baseUserId
- newMapping[positionId] = baseUserId
- }
- ua.UserMapping = newMapping
- return nil
- }
|