|
@@ -23,7 +23,7 @@ import (
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- SaveFields = []string{"_id", "area", "bidamount", "bidopentime", "budget", "buyer", "otitle", "projectname", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "winner"}
|
|
|
+ SaveFields = []string{"_id", "area", "city", "bidamount", "bidopentime", "budget", "buyer", "buyerclass", "projectname", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "winner"}
|
|
|
MailReg = regexp.MustCompile(SysConfig.MailReg)
|
|
|
)
|
|
|
|
|
@@ -53,12 +53,10 @@ func (p *Pjob) CreateDaf() {
|
|
|
}
|
|
|
|
|
|
type MatchUser struct {
|
|
|
- User *UserInfo
|
|
|
Keys []string
|
|
|
}
|
|
|
type MatchJob struct {
|
|
|
datas *[]map[string]interface{} //本次加载的数据
|
|
|
- users *map[string]*UserInfo //所有用户
|
|
|
matchPool chan bool
|
|
|
eachInfoWaitGroup *sync.WaitGroup
|
|
|
saveWaitGroup *sync.WaitGroup
|
|
@@ -99,24 +97,12 @@ func (m *MatchJob) Execute() {
|
|
|
user_batch_index := 0
|
|
|
for {
|
|
|
user_batch_index++
|
|
|
- user_batch_size := m.OnceUserBatch(user_batch_index)
|
|
|
+ user_batch_size, vipUser, freeUser := m.OnceUserBatch(user_batch_index)
|
|
|
if user_batch_size == 0 {
|
|
|
break
|
|
|
}
|
|
|
- a_key_user := make(map[string]*[]*UserInfo)
|
|
|
- a_notkey_user := make(map[string]*[]*UserInfo)
|
|
|
- //开启智能订阅的用户
|
|
|
- //s_key_user := make(map[string]*[]*UserInfo)
|
|
|
- //s_notkey_user := make(map[string]*[]*UserInfo)
|
|
|
- for _, v := range *m.users {
|
|
|
- m.MakeKeyUser(v.Keys, v, &a_key_user)
|
|
|
- m.MakeKeyUser(v.NotKeys, v, &a_notkey_user)
|
|
|
- // if v.SmartSet == 1 {
|
|
|
- // m.MakeKeyUser(v.Keys, v, &s_key_user)
|
|
|
- // m.MakeKeyUser(v.NotKeys, v, &s_notkey_user)
|
|
|
- // }
|
|
|
- }
|
|
|
- m.ToMatch(user_batch_index, a_key_user, a_notkey_user, nil, nil)
|
|
|
+ m.ToMatch(user_batch_index, vipUser)
|
|
|
+ m.ToMatch(user_batch_index, freeUser)
|
|
|
if user_batch_size < SysConfig.UserBatch {
|
|
|
break
|
|
|
}
|
|
@@ -127,35 +113,14 @@ func (m *MatchJob) Execute() {
|
|
|
TaskConfig.LastId = newId
|
|
|
TaskConfig.StartTime = util.FormatDateWithObj(&comeintime, util.Date_Full_Layout)
|
|
|
m.datas = &[]map[string]interface{}{}
|
|
|
- m.users = &map[string]*UserInfo{}
|
|
|
}
|
|
|
-func (m *MatchJob) ToMatch(batchIndex int, a_key_user, a_notkey_user, s_key_user, s_notkey_user map[string]*[]*UserInfo) {
|
|
|
+func (m *MatchJob) ToMatch(batchIndex int, matcher Matcher) {
|
|
|
logger.Info("开始匹配第", batchIndex, "批用户")
|
|
|
- a_p := &Pjob{
|
|
|
- Key_user: &a_key_user,
|
|
|
- Notkey_user: &a_notkey_user,
|
|
|
- }
|
|
|
- a_p.CreateDaf()
|
|
|
- //
|
|
|
- s_p := &Pjob{
|
|
|
- Key_user: &s_key_user,
|
|
|
- Notkey_user: &s_notkey_user,
|
|
|
- }
|
|
|
- s_p.CreateDaf()
|
|
|
- m.Save(a_p, s_p)
|
|
|
- a_key_user = make(map[string]*[]*UserInfo)
|
|
|
- a_notkey_user = make(map[string]*[]*UserInfo)
|
|
|
- //开启智能订阅的用户
|
|
|
- s_key_user = make(map[string]*[]*UserInfo)
|
|
|
- s_notkey_user = make(map[string]*[]*UserInfo)
|
|
|
+ userMap := m.EachAllBidInfo(matcher)
|
|
|
logger.Info("第", batchIndex, "批用户匹配结束")
|
|
|
-}
|
|
|
-func (m *MatchJob) Save(a_p, s_p *Pjob) {
|
|
|
logger.Info("开始保存到pushmail_temp表")
|
|
|
- userMap := m.EachAllBidInfo(a_p, s_p)
|
|
|
- //加锁,保存数据和转移数据不能同时进行
|
|
|
index := 0
|
|
|
- for openid, listInfos := range *userMap {
|
|
|
+ for user, listInfos := range *userMap {
|
|
|
var pushArray = make(SortList, 0)
|
|
|
for e := listInfos.Front(); e != nil; e = e.Next() {
|
|
|
matchInfo := *(e.Value.(*MatchInfo))
|
|
@@ -182,34 +147,32 @@ func (m *MatchJob) Save(a_p, s_p *Pjob) {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- user := (*m.users)[openid]
|
|
|
m.saveBatch = append(m.saveBatch, map[string]interface{}{
|
|
|
- "s_m_openid": user.S_m_openid,
|
|
|
- "a_m_openid": user.A_m_openid,
|
|
|
- "phone": user.Phone,
|
|
|
- "jpushid": user.Jpushid,
|
|
|
- "opushid": user.Opushid,
|
|
|
- "appphonetype": user.AppPhoneType,
|
|
|
- "userid": user.Id,
|
|
|
- "ratemode": user.RateMode,
|
|
|
- "wxpush": user.WxPush,
|
|
|
- "apppush": user.AppPush,
|
|
|
- "mailpush": user.MailPush,
|
|
|
- "pchelperpush": user.PchelperPush,
|
|
|
- //"smartset": user.SmartSet,
|
|
|
- "usertype": user.UserType,
|
|
|
- "email": user.Email,
|
|
|
- //"dataexport": user.DataExport,
|
|
|
+ "s_m_openid": user.S_m_openid,
|
|
|
+ "a_m_openid": user.A_m_openid,
|
|
|
+ "phone": user.Phone,
|
|
|
+ "jpushid": user.Jpushid,
|
|
|
+ "opushid": user.Opushid,
|
|
|
+ "appphonetype": user.AppPhoneType,
|
|
|
+ "userid": user.Id,
|
|
|
+ "ratemode": user.RateMode,
|
|
|
+ "wxpush": user.WxPush,
|
|
|
+ "apppush": user.AppPush,
|
|
|
+ "mailpush": user.MailPush,
|
|
|
+ "pchelperpush": user.PchelperPush,
|
|
|
+ "usertype": user.UserType,
|
|
|
+ "email": user.Email,
|
|
|
"list": array,
|
|
|
"size": size,
|
|
|
"subscribe": user.Subscribe,
|
|
|
"applystatus": user.ApplyStatus,
|
|
|
- "words": user.OriginalKeys,
|
|
|
+ "words": user.Keys,
|
|
|
"modifydate": user.ModifyDate,
|
|
|
"mergeorder": user.MergeOrder,
|
|
|
"timestamp": time.Now().Unix(),
|
|
|
"nickname": user.NickName,
|
|
|
"firstpushtime": user.FirstPushTime,
|
|
|
+ "vipstatus": user.VipStatus,
|
|
|
})
|
|
|
if len(m.saveBatch) == BulkSize {
|
|
|
mongodb.SaveBulk("pushspace_temp", m.saveBatch...)
|
|
@@ -289,9 +252,8 @@ func (m *MatchJob) LoadBidding(lastId, newId string, lastTime int64) bool {
|
|
|
}
|
|
|
|
|
|
//初始化用户缓存
|
|
|
-func (m *MatchJob) OnceUserBatch(user_batch_index int) int {
|
|
|
+func (m *MatchJob) OnceUserBatch(user_batch_index int) (int, *VipUser, *FreeUser) {
|
|
|
defer util.Catch()
|
|
|
- m.users = &map[string]*UserInfo{}
|
|
|
//遍历用户
|
|
|
q := map[string]interface{}{
|
|
|
"i_appid": 2,
|
|
@@ -312,6 +274,8 @@ func (m *MatchJob) OnceUserBatch(user_batch_index int) int {
|
|
|
query := session.DB(DbName).C("user").Find(&q).Select(&map[string]interface{}{
|
|
|
"_id": 1,
|
|
|
"o_jy": 1,
|
|
|
+ "o_vipjy": 1,
|
|
|
+ "i_vipstatus": 1,
|
|
|
"s_m_openid": 1,
|
|
|
"a_m_openid": 1,
|
|
|
"s_phone": 1,
|
|
@@ -325,10 +289,19 @@ func (m *MatchJob) OnceUserBatch(user_batch_index int) int {
|
|
|
"a_mergeorder": 1,
|
|
|
"s_nickname": 1,
|
|
|
"l_firstpushtime": 1,
|
|
|
- //"i_dataexport": 1,
|
|
|
- //"i_smartset":1,
|
|
|
}).Iter()
|
|
|
n := 0
|
|
|
+ freeUser := NewFreeUser() //免费所有用户
|
|
|
+ vipUser := NewVipUser() //vip所有用户
|
|
|
+ //vip标题匹配
|
|
|
+ vip_title_key_user := make(map[string]*[]*UserInfo)
|
|
|
+ vip_title_notkey_user := make(map[string]*[]*UserInfo)
|
|
|
+ //vip正文匹配
|
|
|
+ vip_detail_key_user := make(map[string]*[]*UserInfo)
|
|
|
+ vip_detail_notkey_user := make(map[string]*[]*UserInfo)
|
|
|
+ //免费用户
|
|
|
+ title_key_user := make(map[string]*[]*UserInfo)
|
|
|
+ title_notkey_user := make(map[string]*[]*UserInfo)
|
|
|
for temp := make(map[string]interface{}); query.Next(temp); {
|
|
|
s_m_openid := util.ObjToString(temp["s_m_openid"])
|
|
|
a_m_openid := util.ObjToString(temp["a_m_openid"])
|
|
@@ -352,7 +325,13 @@ func (m *MatchJob) OnceUserBatch(user_batch_index int) int {
|
|
|
}
|
|
|
}
|
|
|
applystatus := util.IntAll(temp["i_applystatus"])
|
|
|
- o_msgset, _ := temp["o_jy"].(map[string]interface{})
|
|
|
+ vipStatus := util.IntAll(temp["i_vipstatus"])
|
|
|
+ var o_msgset map[string]interface{}
|
|
|
+ if !IsVipUser(vipStatus) {
|
|
|
+ o_msgset, _ = temp["o_jy"].(map[string]interface{})
|
|
|
+ } else {
|
|
|
+ o_msgset, _ = temp["o_vipjy"].(map[string]interface{})
|
|
|
+ }
|
|
|
wxpush, apppush, mailpush := mutil.ModeTransform(userType, o_msgset)
|
|
|
email := strings.TrimSpace(util.ObjToString(o_msgset["s_email"]))
|
|
|
if !MailReg.MatchString(email) {
|
|
@@ -361,78 +340,95 @@ func (m *MatchJob) OnceUserBatch(user_batch_index int) int {
|
|
|
if wxpush != 1 && apppush != 1 && mailpush != 1 {
|
|
|
continue
|
|
|
}
|
|
|
- var allkeysTemp []elastic.KeyConfig
|
|
|
- _bs, err := json.Marshal(o_msgset["a_key"])
|
|
|
- if err == nil {
|
|
|
- json.Unmarshal(_bs, &allkeysTemp)
|
|
|
- }
|
|
|
- allkeys := []elastic.KeyConfig{}
|
|
|
- if len(allkeysTemp) > 0 {
|
|
|
- //一个字或者配置文件中的词,不推送
|
|
|
- for _, vs := range allkeysTemp {
|
|
|
- isFilter := false
|
|
|
- vskey := strings.Replace(strings.Join(vs.Keys, ""), " ", "", -1)
|
|
|
- if len([]rune(vskey)) == 1 {
|
|
|
- continue
|
|
|
- }
|
|
|
- for _, fv := range SysConfig.FilterWords {
|
|
|
- if fv == vskey {
|
|
|
- isFilter = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if !isFilter {
|
|
|
- allkeys = append(allkeys, vs)
|
|
|
+ userId := fmt.Sprintf("%x", string(temp["_id"].(bson.ObjectId)))
|
|
|
+ var allKeySet []*KeySet
|
|
|
+ var err error
|
|
|
+ if !IsVipUser(vipStatus) {
|
|
|
+ allKeySet, err = m.GetKeySet(o_msgset["a_key"])
|
|
|
+ } else {
|
|
|
+ vip_items, _ := o_msgset["a_items"].([]interface{})
|
|
|
+ for _, v := range vip_items {
|
|
|
+ vip_item, _ := v.(map[string]interface{})
|
|
|
+ var vip_keySet []*KeySet
|
|
|
+ vip_keySet, err = m.GetKeySet(vip_item["a_key"])
|
|
|
+ if err != nil {
|
|
|
+ break
|
|
|
}
|
|
|
+ allKeySet = append(allKeySet, vip_keySet...)
|
|
|
}
|
|
|
}
|
|
|
- ////////////////
|
|
|
- if len(allkeys) == 0 {
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取用户关键词错误!", userId, err)
|
|
|
continue
|
|
|
}
|
|
|
- userId := fmt.Sprintf("%x", string(temp["_id"].(bson.ObjectId)))
|
|
|
- //smartset := util.IntAll(temp["i_smartset"])
|
|
|
- //dataExport := util.IntAll(temp["i_dataexport"])
|
|
|
rateMode := util.IntAllDef(o_msgset["i_ratemode"], 2)
|
|
|
- logger.Info("第", user_batch_index, "批用户,userid", userId, "s_m_openid", s_m_openid, "a_m_openid", a_m_openid, "s_phone", s_phone, "jpushid", jpushid, "opushid", opushid, "applystatus", applystatus, "email", email, "rateMode", rateMode, "wxpush", wxpush, "apppush", apppush, "mailpush", mailpush)
|
|
|
+ logger.Info("第", user_batch_index, "批用户,userid", userId, "s_m_openid", s_m_openid, "a_m_openid", a_m_openid, "s_phone", s_phone, "jpushid", jpushid, "opushid", opushid, "applystatus", applystatus, "email", email, "rateMode", rateMode, "wxpush", wxpush, "apppush", apppush, "mailpush", mailpush, "vipstatus", vipStatus)
|
|
|
keys := []string{} //过滤后的关键词
|
|
|
notkeys := []string{} //排除词
|
|
|
key_notkey := map[string]map[string]bool{} //关键词所对应的排除词
|
|
|
key_area := map[string]map[string]bool{} //关键词所对应的信息范围
|
|
|
key_infotype := map[string]map[string]bool{} //关键词所对应的信息类型
|
|
|
- for _, vs := range allkeys {
|
|
|
- key := strings.Join(vs.Keys, "+")
|
|
|
+ originalKeys := []string{} //原始关键词
|
|
|
+ ////////////////
|
|
|
+ for _, vs := range allKeySet {
|
|
|
+ var vs_keys []string
|
|
|
+ for _, vs_v := range [][]string{vs.Keys, vs.AppendKeys} {
|
|
|
+ for _, vs_vv := range vs_v {
|
|
|
+ vs_vv = strings.TrimSpace(vs_vv)
|
|
|
+ if vs_vv == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ vs_keys = append(vs_keys, vs_vv)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(vs_keys) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ key := strings.Join(vs_keys, "+")
|
|
|
+ originalKeys = append(originalKeys, key)
|
|
|
+ //一个字或者配置文件中的词,不推送
|
|
|
+ //if len([]rune(key)) == 1 {
|
|
|
+ //continue
|
|
|
+ //}
|
|
|
+ isFilter := false
|
|
|
+ for _, fv := range SysConfig.FilterWords {
|
|
|
+ if fv == key {
|
|
|
+ isFilter = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if isFilter {
|
|
|
+ continue
|
|
|
+ }
|
|
|
keys = append(keys, key)
|
|
|
notkeys = append(notkeys, vs.NotKeys...)
|
|
|
//转大写
|
|
|
- keyTemp := strings.ToUpper(key)
|
|
|
+ upperKey := strings.ToUpper(key)
|
|
|
//建立与排除词的对应关系
|
|
|
for _, notkey := range vs.NotKeys {
|
|
|
- notkeyTemp := strings.ToUpper(notkey)
|
|
|
- if key_notkey[keyTemp] == nil {
|
|
|
- key_notkey[keyTemp] = map[string]bool{}
|
|
|
+ upperNotkey := strings.ToUpper(notkey)
|
|
|
+ if key_notkey[upperKey] == nil {
|
|
|
+ key_notkey[upperKey] = map[string]bool{}
|
|
|
}
|
|
|
- key_notkey[keyTemp][notkeyTemp] = true
|
|
|
+ key_notkey[upperKey][upperNotkey] = true
|
|
|
}
|
|
|
//建立与信息范围的对应关系
|
|
|
for _, area := range vs.Areas {
|
|
|
- if key_area[keyTemp] == nil {
|
|
|
- key_area[keyTemp] = map[string]bool{}
|
|
|
+ if key_area[upperKey] == nil {
|
|
|
+ key_area[upperKey] = map[string]bool{}
|
|
|
}
|
|
|
- key_area[keyTemp][area] = true
|
|
|
+ key_area[upperKey][area] = true
|
|
|
}
|
|
|
//建立与信息类型的对应关系
|
|
|
for _, infotype := range vs.InfoTypes {
|
|
|
- if key_infotype[keyTemp] == nil {
|
|
|
- key_infotype[keyTemp] = map[string]bool{}
|
|
|
+ if key_infotype[upperKey] == nil {
|
|
|
+ key_infotype[upperKey] = map[string]bool{}
|
|
|
}
|
|
|
- key_infotype[keyTemp][infotype] = true
|
|
|
+ key_infotype[upperKey][infotype] = true
|
|
|
}
|
|
|
}
|
|
|
- //
|
|
|
- keysTemp := []string{} //原始关键词
|
|
|
- for _, vs := range allkeysTemp {
|
|
|
- keysTemp = append(keysTemp, strings.Join(vs.Keys, "+"))
|
|
|
+ if !IsVipUser(vipStatus) && len(originalKeys) == 0 {
|
|
|
+ continue
|
|
|
}
|
|
|
modifydate := ""
|
|
|
md, _ := o_msgset["l_modifydate"].(int64)
|
|
@@ -445,12 +441,8 @@ func (m *MatchJob) OnceUserBatch(user_batch_index int) int {
|
|
|
}
|
|
|
user := &UserInfo{
|
|
|
Id: userId,
|
|
|
- OriginalKeys: keysTemp,
|
|
|
- Keys: keys, //原始关键词
|
|
|
- NotKeys: notkeys,
|
|
|
+ Keys: originalKeys,
|
|
|
Key_notkey: key_notkey,
|
|
|
- Key_area: key_area,
|
|
|
- Key_infotype: key_infotype,
|
|
|
WxPush: wxpush,
|
|
|
AppPush: apppush,
|
|
|
MailPush: mailpush,
|
|
@@ -463,17 +455,81 @@ func (m *MatchJob) OnceUserBatch(user_batch_index int) int {
|
|
|
Opushid: opushid,
|
|
|
UserType: userType,
|
|
|
RateMode: rateMode,
|
|
|
- AllKeys: allkeysTemp, //原始关键词
|
|
|
ModifyDate: modifydate,
|
|
|
AppPhoneType: appPhoneType,
|
|
|
ApplyStatus: applystatus,
|
|
|
Subscribe: isPush,
|
|
|
+ MatchType: util.IntAllDef(o_msgset["i_matchway"], 1),
|
|
|
MergeOrder: temp["a_mergeorder"],
|
|
|
NickName: util.ObjToString(temp["s_nickname"]),
|
|
|
- //SmartSet: smartset,
|
|
|
- //DataExport: dataExport,
|
|
|
+ VipStatus: vipStatus,
|
|
|
+ }
|
|
|
+ /***************start*****************/
|
|
|
+ if !IsVipUser(vipStatus) {
|
|
|
+ user.O_jy = &O_jy{
|
|
|
+ Area: key_area,
|
|
|
+ Infotype: key_infotype,
|
|
|
+ }
|
|
|
+ m.MakeKeyUser(keys, user, &title_key_user)
|
|
|
+ m.MakeKeyUser(notkeys, user, &title_notkey_user)
|
|
|
+ } else {
|
|
|
+ //vip付费-采购单位行业
|
|
|
+ vip_buyerclass, _ := o_msgset["a_buyerclass"].([]interface{})
|
|
|
+ if len(vip_buyerclass) == 0 {
|
|
|
+ vipUser.Add("", user, &vipUser.BuyerclassUsers)
|
|
|
+ } else {
|
|
|
+ for _, v := range vip_buyerclass {
|
|
|
+ s_v, _ := v.(string)
|
|
|
+ if s_v == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ vipUser.Add(s_v, user, &vipUser.BuyerclassUsers)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //vip付费-区域
|
|
|
+ vip_area, _ := o_msgset["o_area"].(map[string]interface{})
|
|
|
+ if len(vip_area) == 0 {
|
|
|
+ vipUser.Add("", user, &vipUser.AreaUsers)
|
|
|
+ } else {
|
|
|
+ for k, v := range vip_area {
|
|
|
+ if k == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ vs, _ := v.([]interface{})
|
|
|
+ if len(vs) == 0 {
|
|
|
+ vipUser.Add(k, user, &vipUser.AreaUsers)
|
|
|
+ } else {
|
|
|
+ for _, vv := range vs {
|
|
|
+ s_vv, _ := vv.(string)
|
|
|
+ if s_vv == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ vipUser.Add(s_vv, user, &vipUser.CityUsers)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //vip付费-信息类型
|
|
|
+ vip_infotype, _ := o_msgset["a_infotype"].([]interface{})
|
|
|
+ if len(vip_infotype) == 0 {
|
|
|
+ vipUser.Add("", user, &vipUser.InfoTypeUsers)
|
|
|
+ } else {
|
|
|
+ for _, v := range vip_infotype {
|
|
|
+ s_v, _ := v.(string)
|
|
|
+ if s_v == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ vipUser.Add(s_v, user, &vipUser.InfoTypeUsers)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ m.MakeKeyUser(keys, user, &vip_title_key_user)
|
|
|
+ m.MakeKeyUser(notkeys, user, &vip_title_notkey_user)
|
|
|
+ if user.MatchType == 2 {
|
|
|
+ m.MakeKeyUser(keys, user, &vip_detail_key_user)
|
|
|
+ m.MakeKeyUser(notkeys, user, &vip_detail_notkey_user)
|
|
|
+ }
|
|
|
}
|
|
|
- (*m.users)[user.Id] = user
|
|
|
+ /***************end*****************/
|
|
|
m.lastUserId = user.Id
|
|
|
temp = make(map[string]interface{})
|
|
|
n++
|
|
@@ -481,8 +537,38 @@ func (m *MatchJob) OnceUserBatch(user_batch_index int) int {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
+ //
|
|
|
+ vip_title_pjob := &Pjob{
|
|
|
+ Key_user: &vip_title_key_user,
|
|
|
+ Notkey_user: &vip_title_notkey_user,
|
|
|
+ }
|
|
|
+ vip_title_pjob.CreateDaf()
|
|
|
+ vip_detail_pjob := &Pjob{
|
|
|
+ Key_user: &vip_detail_key_user,
|
|
|
+ Notkey_user: &vip_detail_notkey_user,
|
|
|
+ }
|
|
|
+ vip_detail_pjob.CreateDaf()
|
|
|
+ vipUser.Title_Pjob = vip_title_pjob
|
|
|
+ vipUser.Detail_Pjob = vip_detail_pjob
|
|
|
+ //
|
|
|
+ title_pjob := &Pjob{
|
|
|
+ Key_user: &title_key_user,
|
|
|
+ Notkey_user: &title_notkey_user,
|
|
|
+ }
|
|
|
+ title_pjob.CreateDaf()
|
|
|
+ freeUser.Title_Pjob = title_pjob
|
|
|
logger.Info("第", user_batch_index, "批用户加载结束", n)
|
|
|
- return n
|
|
|
+ return n, vipUser, freeUser
|
|
|
+}
|
|
|
+
|
|
|
+//得到用户的关键词
|
|
|
+func (m *MatchJob) GetKeySet(a_key interface{}) ([]*KeySet, error) {
|
|
|
+ var keySet []*KeySet
|
|
|
+ _bs, err := json.Marshal(a_key)
|
|
|
+ if err == nil {
|
|
|
+ err = json.Unmarshal(_bs, &keySet)
|
|
|
+ }
|
|
|
+ return keySet, err
|
|
|
}
|
|
|
|
|
|
//把用户挂在词下面
|
|
@@ -494,23 +580,20 @@ func (m *MatchJob) MakeKeyUser(keys []string, user *UserInfo, key_user *map[stri
|
|
|
continue
|
|
|
}
|
|
|
mp[v] = true
|
|
|
- var arr *[]*UserInfo
|
|
|
- if nil == (*key_user)[v] {
|
|
|
+ arr := (*key_user)[v]
|
|
|
+ if arr == nil {
|
|
|
arr = &[]*UserInfo{}
|
|
|
- (*key_user)[v] = arr
|
|
|
- } else {
|
|
|
- arr = (*key_user)[v]
|
|
|
- (*key_user)[v] = arr
|
|
|
}
|
|
|
*arr = append(*arr, user)
|
|
|
+ (*key_user)[v] = arr
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//遍历数据并执行推送操作
|
|
|
-func (m *MatchJob) EachAllBidInfo(a_p *Pjob, s_p *Pjob) *map[string]*list.List {
|
|
|
+func (m *MatchJob) EachAllBidInfo(matcher Matcher) *map[*UserInfo]*list.List {
|
|
|
defer util.Catch()
|
|
|
logger.Info("开始遍历数据。。。")
|
|
|
- userMap := &map[string]*list.List{}
|
|
|
+ userMap := map[*UserInfo]*list.List{}
|
|
|
var count int
|
|
|
for _, temp := range *m.datas {
|
|
|
m.matchPool <- true
|
|
@@ -521,39 +604,9 @@ func (m *MatchJob) EachAllBidInfo(a_p *Pjob, s_p *Pjob) *map[string]*list.List {
|
|
|
m.eachInfoWaitGroup.Done()
|
|
|
<-m.matchPool
|
|
|
}()
|
|
|
- title := util.ObjToString(info["title"])
|
|
|
- if title == "" {
|
|
|
- return
|
|
|
- }
|
|
|
- titleTemp := strings.ToUpper(title)
|
|
|
- area := util.ObjToString(info["area"])
|
|
|
- toptype := util.ObjToString(info["toptype"])
|
|
|
- //订阅词
|
|
|
- keys := a_p.InterestDfa.Analy(titleTemp)
|
|
|
- //排除词
|
|
|
- notkeys := a_p.NotInterestDfa.Analy(titleTemp)
|
|
|
- users := m.GetFinalUser(keys, notkeys, a_p.Key_user, area, toptype, true)
|
|
|
- //开启智能匹配的用户,匹配projectscope
|
|
|
- if s_p != nil {
|
|
|
- projectscope := util.ObjToString(info["projectscope"])
|
|
|
- if projectscope == "" {
|
|
|
- projectscope = util.ObjToString(info["detail"])
|
|
|
- }
|
|
|
- if projectscope != "" {
|
|
|
- projectscopeTemp := strings.ToUpper(projectscope)
|
|
|
- keys = s_p.InterestDfa.Analy(projectscopeTemp)
|
|
|
- notkeys = s_p.NotInterestDfa.Analy(projectscopeTemp)
|
|
|
- s_users := m.GetFinalUser(keys, notkeys, s_p.Key_user, area, toptype, false)
|
|
|
- for _, s_u := range *s_users {
|
|
|
- if (*users)[s_u.User.Id] != nil {
|
|
|
- continue
|
|
|
- }
|
|
|
- (*users)[s_u.User.Id] = s_u
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ users := matcher.Match(&info)
|
|
|
if len(*users) > 0 {
|
|
|
- m.EachInfoToUser(users, &info, userMap)
|
|
|
+ m.EachInfoToUser(users, &info, &userMap)
|
|
|
}
|
|
|
}(temp)
|
|
|
if count%500 == 0 {
|
|
@@ -562,70 +615,11 @@ func (m *MatchJob) EachAllBidInfo(a_p *Pjob, s_p *Pjob) *map[string]*list.List {
|
|
|
}
|
|
|
m.eachInfoWaitGroup.Wait()
|
|
|
logger.Info("数据遍历完成!")
|
|
|
- return userMap
|
|
|
-}
|
|
|
-
|
|
|
-//获取最终的用户,排除词、信息范围、信息类型之后的
|
|
|
-//返回匹配上的用户和没有匹配到的用户
|
|
|
-func (m *MatchJob) GetFinalUser(keys, notkeys []string, key_user *map[string]*[]*UserInfo, area, toptype string, flag bool) *map[string]*MatchUser {
|
|
|
- keyMap := map[string]bool{}
|
|
|
- for _, v := range keys {
|
|
|
- keyMap[v] = true
|
|
|
- }
|
|
|
- y_users := map[string]*MatchUser{} //匹配到用户
|
|
|
- //遍历所有用户
|
|
|
- for k, us := range *key_user {
|
|
|
- if !keyMap[k] { //改关键词没有匹配到的用户
|
|
|
- continue
|
|
|
- }
|
|
|
- for _, u := range *us {
|
|
|
- //获取该词下面所有的用户
|
|
|
- //遍历我的排除词,如果存在的话,排除自己
|
|
|
- isContinue := false
|
|
|
- for _, notkey := range notkeys {
|
|
|
- if u.Key_notkey[k][notkey] {
|
|
|
- isContinue = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if isContinue {
|
|
|
- continue
|
|
|
- }
|
|
|
- //遍历我的信息范围,看该信息是不是在我的信息范围中
|
|
|
- if len(u.Key_area[k]) > 0 && !u.Key_area[k][area] {
|
|
|
- continue
|
|
|
- }
|
|
|
- //遍历我的信息类型,看该信息是不是在我的信息类型中
|
|
|
- if len(u.Key_infotype[k]) > 0 && !u.Key_infotype[k][toptype] {
|
|
|
- continue
|
|
|
- }
|
|
|
- matchUser := y_users[u.Id]
|
|
|
- if matchUser == nil {
|
|
|
- matchUser = &MatchUser{
|
|
|
- User: u,
|
|
|
- Keys: []string{},
|
|
|
- }
|
|
|
- }
|
|
|
- matchUser.Keys = append(matchUser.Keys, k)
|
|
|
- y_users[u.Id] = matchUser
|
|
|
- }
|
|
|
- }
|
|
|
- //获取最终没有匹配到的用户,进行正文或者范围匹配
|
|
|
- users := map[string]*MatchUser{}
|
|
|
- for k, v := range *m.users {
|
|
|
- if y_users[k] == nil {
|
|
|
- continue
|
|
|
- }
|
|
|
- users[v.Id] = &MatchUser{
|
|
|
- User: v,
|
|
|
- Keys: y_users[k].Keys,
|
|
|
- }
|
|
|
- }
|
|
|
- return &users
|
|
|
+ return &userMap
|
|
|
}
|
|
|
|
|
|
//遍历用户加入到此条信息上
|
|
|
-func (m *MatchJob) EachInfoToUser(users *map[string]*MatchUser, info *map[string]interface{}, userMap *map[string]*list.List) {
|
|
|
+func (m *MatchJob) EachInfoToUser(users *map[*UserInfo]*MatchUser, info *map[string]interface{}, userMap *map[*UserInfo]*list.List) {
|
|
|
defer m.userMapLock.Unlock()
|
|
|
m.userMapLock.Lock()
|
|
|
for k, v := range *users {
|