Эх сурвалжийг харах

Merge branch 'master' of http://192.168.3.207:8080/BaseService/pushpkg into master

zhangxinlei1996 2 жил өмнө
parent
commit
51add154ab
3 өөрчлөгдсөн 75 нэмэгдсэн , 3 устгасан
  1. 1 1
      matcher/matcher.go
  2. 71 1
      matcher/paymatch.go
  3. 3 1
      p/struct.go

+ 1 - 1
matcher/matcher.go

@@ -5,5 +5,5 @@ import (
 )
 
 type Matcher interface {
-	Match(info *map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo)
+	Match(poolSize int, datas *[]map[string]interface{}) (*map[*UserInfo]*SortList, *map[*UserInfo]*[]string)
 }

+ 71 - 1
matcher/paymatch.go

@@ -2,7 +2,10 @@ package matcher
 
 import (
 	"strings"
+	"sync"
 
+	util "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/logger"
 	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 )
 
@@ -28,8 +31,66 @@ func NewPayUser() *PayUser {
 	}
 }
 
+//遍历数据
+func (p *PayUser) Match(poolSize int, datas *[]map[string]interface{}) (*map[*UserInfo]*SortList, *map[*UserInfo]*[]string) {
+	defer util.Catch()
+	logger.Info("开始匹配数据。。。")
+	userMap := map[*UserInfo]*SortList{}
+	projectUserMap := map[*UserInfo]*[]string{}
+	lock := &sync.Mutex{}
+	var index int
+	matchPool := make(chan bool, poolSize)
+	matchWaitGroup := &sync.WaitGroup{}
+	for _, temp := range *datas {
+		matchPool <- true
+		matchWaitGroup.Add(1)
+		go func(info map[string]interface{}) {
+			defer util.Catch()
+			defer func() {
+				matchWaitGroup.Done()
+				<-matchPool
+			}()
+			users, projectUsers := p.ToMatch(&info)
+			lock.Lock()
+			defer lock.Unlock()
+			if users != nil && len(*users) > 0 {
+				for k, v := range *users {
+					l := userMap[k]
+					if l == nil {
+						l = &SortList{}
+					}
+					*l = append(*l, &MatchInfo{
+						Info:      &info,
+						Keys:      v.Keys,
+						Items:     v.Items,
+						MatchWays: v.MatchWays,
+					})
+					userMap[k] = l
+				}
+			}
+			if projectUsers != nil && len(*projectUsers) > 0 {
+				for _, v := range *projectUsers {
+					l := projectUserMap[v]
+					if l == nil {
+						l = &[]string{}
+					}
+					*l = append(*l, util.ObjToString(info["_id"]))
+					projectUserMap[v] = l
+				}
+			}
+		}(temp)
+		index++
+		if index%500 == 0 {
+			logger.Info("匹配数据", index)
+		}
+	}
+	matchWaitGroup.Wait()
+	logger.Info("匹配数据结束。。。", index)
+	return &userMap, &projectUserMap
+}
+
 //
-func (p *PayUser) Match(info *map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo) {
+func (p *PayUser) ToMatch(info *map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo) {
 	buyerclass, _ := (*info)["buyerclass"].(string)
 	area, _ := (*info)["area"].(string)
 	if area == "全国" {
@@ -129,11 +190,20 @@ func (p *PayUser) GetFinalUser(matchWay string, keys, notkeys []string, key_user
 			if matchUser == nil {
 				matchUser = &MatchUser{
 					Keys:      []string{},
+					Items:     []string{},
+					Item:      map[string]bool{},
 					MatchWays: []string{},
 					MatchWay:  map[string]bool{},
 				}
 			}
 			matchUser.Keys = append(matchUser.Keys, k)
+			item := u.SubSet.Key_item[k]
+			if item != "" {
+				if !matchUser.Item[item] {
+					matchUser.Items = append(matchUser.Items, item)
+				}
+				matchUser.Item[item] = true
+			}
 			if !matchUser.MatchWay[matchWay] {
 				matchUser.MatchWays = append(matchUser.MatchWays, matchWay)
 			}

+ 3 - 1
p/struct.go

@@ -207,7 +207,7 @@ func (u *UserInfo) GetPushSet(obj map[string]interface{}) {
 			MailPush: util.IntAll(subSet["i_mailpush"]),
 			RateMode: util.IntAll(subSet["i_ratemode"]),
 			Times:    util.ObjArrToStringArr(times),
-			Nomsgtip: util.IntAllDef(obj["i_nomsgtip"], 1), //默认开启
+			Nomsgtip: util.IntAllDef(subSet["i_nomsgtip"], 1), //默认开启
 		},
 		WeekReport: &PushSetChild{
 			WxPush:   util.IntAllDef(weekReport["i_wxpush"], 1),
@@ -694,6 +694,8 @@ func (p *KeyDfa) CreateDaf() {
 
 type MatchUser struct {
 	Keys      []string
+	Items     []string
+	Item      map[string]bool
 	MatchWays []string
 	MatchWay  map[string]bool
 }