|
@@ -40,142 +40,125 @@ type MatchJob struct {
|
|
//定时任务,匹配数据,存库
|
|
//定时任务,匹配数据,存库
|
|
func (m *MatchJob) Execute() {
|
|
func (m *MatchJob) Execute() {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
- logger.Info("开始匹配数据任务。。。", TaskConfig.LastId, TaskConfig.LastTime)
|
|
|
|
- datas, endId, endTime := LoadBidding(Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Mongodb.Bidding.Collection, TaskConfig.LastId, TaskConfig.LastTime, true)
|
|
|
|
|
|
+ logger.Info("开始匹配数据任务。。。", TaskConfig.Pici)
|
|
|
|
+ datas, endTime := LoadBidding(Mgo_Bidding, DbConf.Mongodb.Bidding.DbName, DbConf.Mongodb.Bidding.Collection, TaskConfig.Pici, true)
|
|
if datas == nil || len(*datas) == 0 {
|
|
if datas == nil || len(*datas) == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
m.Start(datas)
|
|
m.Start(datas)
|
|
m.relationproject.AllProject = &sync.Map{}
|
|
m.relationproject.AllProject = &sync.Map{}
|
|
- TaskConfig.LastTime = endTime
|
|
|
|
- TaskConfig.LastId = endId
|
|
|
|
- logger.Info("匹配数据任务结束。。。", TaskConfig.LastId, TaskConfig.LastTime)
|
|
|
|
|
|
+ TaskConfig.Pici = endTime
|
|
|
|
+ logger.Info("匹配数据任务结束。。。", TaskConfig.Pici)
|
|
}
|
|
}
|
|
|
|
|
|
func (m *MatchJob) Start(datas *[]map[string]interface{}) {
|
|
func (m *MatchJob) Start(datas *[]map[string]interface{}) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
defer ClearEnt()
|
|
defer ClearEnt()
|
|
- InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName)
|
|
|
|
- subSet := m.LoadSubSet()
|
|
|
|
- if subSet != nil && len(subSet.Users) > 0 {
|
|
|
|
- m.ToMatch(subSet, datas)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (m *MatchJob) LoadSubSet() *PayUser {
|
|
|
|
- defer util.Catch()
|
|
|
|
- payUser := NewPayUser()
|
|
|
|
|
|
+ _, _, entEpu, epus := LoadEntProductUsers(Mysql)
|
|
|
|
+ InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName, Config.TestQuery, entEpu)
|
|
|
|
+ allSubSet := NewPayUser()
|
|
//标题匹配
|
|
//标题匹配
|
|
title_key := make(map[string]*[]*UserInfo)
|
|
title_key := make(map[string]*[]*UserInfo)
|
|
title_notkey := make(map[string]*[]*UserInfo)
|
|
title_notkey := make(map[string]*[]*UserInfo)
|
|
|
|
+ title_pjob := &KeyDfa{
|
|
|
|
+ Key_user: &title_key,
|
|
|
|
+ Notkey_user: &title_notkey,
|
|
|
|
+ }
|
|
//正文匹配
|
|
//正文匹配
|
|
detail_key := make(map[string]*[]*UserInfo)
|
|
detail_key := make(map[string]*[]*UserInfo)
|
|
detail_notkey := make(map[string]*[]*UserInfo)
|
|
detail_notkey := make(map[string]*[]*UserInfo)
|
|
|
|
+ detail_pjob := &KeyDfa{
|
|
|
|
+ Key_user: &detail_key,
|
|
|
|
+ Notkey_user: &detail_notkey,
|
|
|
|
+ }
|
|
|
|
+ m.LoadMySubSet(entEpu, allSubSet, title_pjob, detail_pjob)
|
|
|
|
+ for k, _ := range LoadEntProductSubSet(Mgo, Config.LoadEntProductUsersPoolSize, epus) {
|
|
|
|
+ m.InitSubSet(allSubSet, k, title_pjob, detail_pjob)
|
|
|
|
+ }
|
|
//
|
|
//
|
|
|
|
+ title_pjob.CreateDaf()
|
|
|
|
+ detail_pjob.CreateDaf()
|
|
|
|
+ allSubSet.Title_KeyDfa = title_pjob
|
|
|
|
+ allSubSet.Detail_KeyDfa = detail_pjob
|
|
|
|
+ //
|
|
|
|
+ m.ToMatch(allSubSet, datas)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//商机管理产品我的订阅设置
|
|
|
|
+func (m *MatchJob) LoadMySubSet(epu map[int]*Entniche, allSubSet *PayUser, title_pjob, detail_pjob *KeyDfa) {
|
|
|
|
+ defer util.Catch()
|
|
sess := Mgo.GetMgoConn()
|
|
sess := Mgo.GetMgoConn()
|
|
defer Mgo.DestoryMongoConn(sess)
|
|
defer Mgo.DestoryMongoConn(sess)
|
|
query := map[string]interface{}{}
|
|
query := map[string]interface{}{}
|
|
if len(Config.TestQuery) > 0 {
|
|
if len(Config.TestQuery) > 0 {
|
|
- for k, v := range Config.TestQuery {
|
|
|
|
- query[k] = v
|
|
|
|
- }
|
|
|
|
|
|
+ query = Config.TestQuery
|
|
}
|
|
}
|
|
- logger.Info("加载订阅设置", query)
|
|
|
|
|
|
+ logger.Info("商机管理产品我的订阅设置", query)
|
|
it := sess.DB(DbConf.Mongodb.Main.DbName).C(Entniche_rule).Find(query).Select(map[string]interface{}{
|
|
it := sess.DB(DbConf.Mongodb.Main.DbName).C(Entniche_rule).Find(query).Select(map[string]interface{}{
|
|
"i_entid": 1,
|
|
"i_entid": 1,
|
|
"i_deptid": 1,
|
|
"i_deptid": 1,
|
|
"i_userid": 1,
|
|
"i_userid": 1,
|
|
"o_entniche": 1,
|
|
"o_entniche": 1,
|
|
}).Iter()
|
|
}).Iter()
|
|
- for _temp := make(map[string]interface{}); it.Next(&_temp); {
|
|
|
|
- func(temp map[string]interface{}) {
|
|
|
|
- entId := util.IntAll(temp["i_entid"])
|
|
|
|
- deptId := util.IntAll(temp["i_deptid"])
|
|
|
|
- userId := util.IntAll(temp["i_userid"])
|
|
|
|
- if entId == 0 || (deptId == 0 && userId == 0) {
|
|
|
|
- return
|
|
|
|
- } else if Ents[entId] == nil {
|
|
|
|
- logger.Info("没有找到该企业", entId)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- entName := Ents[entId].Name
|
|
|
|
- if deptId > 0 && EntDepts[deptId] == nil {
|
|
|
|
- logger.Info("没有找到该部门", entName, entId, deptId)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- deptName := ""
|
|
|
|
- if EntDepts[deptId] != nil {
|
|
|
|
- deptName = EntDepts[deptId].Name
|
|
|
|
|
|
+ for temp := make(map[string]interface{}); it.Next(&temp); {
|
|
|
|
+ entId := util.IntAll(temp["i_entid"])
|
|
|
|
+ deptId := util.IntAll(temp["i_deptid"])
|
|
|
|
+ userId := util.IntAll(temp["i_userid"])
|
|
|
|
+ if entId == 0 || (deptId != 0 && userId != 0) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ var entName string
|
|
|
|
+ if deptId == 0 && userId == 0 {
|
|
|
|
+ if epu[entId] == nil {
|
|
|
|
+ logger.Info("没有购买企业产品,过滤掉", entId)
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
- subSet, _ := temp["o_entniche"].(map[string]interface{})
|
|
|
|
- if subSet == nil || len(subSet) == 0 {
|
|
|
|
- logger.Info("订阅设置为空,过滤掉", entName, entId, deptName, deptId, userId)
|
|
|
|
- return
|
|
|
|
|
|
+ entName = epu[entId].EntName
|
|
|
|
+ } else {
|
|
|
|
+ if Ents[entId] == nil {
|
|
|
|
+ logger.Info("没有找到该企业,过滤掉", entId)
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
- //
|
|
|
|
- if deptId > 0 { //部门订阅
|
|
|
|
- if Ents[entId].Model != 1 {
|
|
|
|
- logger.Info("不是统一订阅模式,过滤掉", entName, entId, deptName, deptId)
|
|
|
|
- return
|
|
|
|
- } else if EntDepts[deptId] == nil {
|
|
|
|
- logger.Info("没有找到该部门,过滤掉", entName, entId, deptName, deptId)
|
|
|
|
- return
|
|
|
|
- } else if EntDepts[deptId].Subdis == 0 {
|
|
|
|
- logger.Info("该部门的订阅分发没有开启,过滤掉", entName, entId, deptName, deptId)
|
|
|
|
- return
|
|
|
|
- } else if EntDepts[deptId].Nodiff == 0 && EntDeptDis[deptId] == nil {
|
|
|
|
- logger.Info("该部门开启了订阅分发,没有开启全员无差别接收,但是没有分发规则,过滤掉", entName, entId, deptName, deptId)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- //如果我的上级部门打开了订阅分发,并且开启了全员无差别接收,本部门规则无效
|
|
|
|
- for _, dept := range EntParentDept[deptId] {
|
|
|
|
- if EntDepts[dept.Pid].Subdis == 1 && EntDepts[dept.Pid].Nodiff == 1 {
|
|
|
|
- logger.Info("我的上级部门", dept.Pid, "开启了订阅分发和全员无差别,过滤掉", entName, entId, deptName, deptId)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ entName = Ents[entId].Name
|
|
|
|
+ if deptId != 0 {
|
|
|
|
+ if EntDepts[deptId] == nil {
|
|
|
|
+ logger.Info("没有找到该部门,过滤掉", entName, entId, deptId)
|
|
|
|
+ continue
|
|
|
|
+ } else if Ents[entId].Model != 1 || Ents[entId].DeptSubscribe != 1 || EntDepts[deptId].Subdis != 1 || EntDepts[deptId].Nodiff != 0 {
|
|
|
|
+ logger.Info("不符合部门自己订阅,过滤掉", entName, entId, deptId)
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
- } else if userId > 0 { //个人订阅
|
|
|
|
- if Ents[entId].Model != 2 {
|
|
|
|
- logger.Info("不是个人订阅模式,过滤掉", entName, entId, userId)
|
|
|
|
- return
|
|
|
|
- } else if EntUsers[userId] == nil {
|
|
|
|
|
|
+ } else if userId != 0 {
|
|
|
|
+ if EntUsers[userId] == nil {
|
|
logger.Info("没有找到该用户,过滤掉", entName, entId, userId)
|
|
logger.Info("没有找到该用户,过滤掉", entName, entId, userId)
|
|
- return
|
|
|
|
|
|
+ continue
|
|
} else if EntUsers[userId].Power == 0 {
|
|
} else if EntUsers[userId].Power == 0 {
|
|
logger.Info("该用户没有权限,过滤掉", entName, entId, userId)
|
|
logger.Info("该用户没有权限,过滤掉", entName, entId, userId)
|
|
- return
|
|
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- user := &UserInfo{
|
|
|
|
- Entniche: &Entniche{
|
|
|
|
- EntId: entId,
|
|
|
|
- EntName: entName,
|
|
|
|
- DeptId: deptId,
|
|
|
|
- DeptName: deptName,
|
|
|
|
- UserId: userId,
|
|
|
|
- IsNew: Ents[entId].IsNew,
|
|
|
|
- },
|
|
|
|
- SubSet: GetSubSet(false, fmt.Sprint(userId), subSet),
|
|
|
|
- }
|
|
|
|
- user.SubSet.AppPush = util.IntAllDef(subSet["i_apppush"], 1)
|
|
|
|
- user.SubSet.MailPush = util.IntAll(subSet["i_mailpush"])
|
|
|
|
- user.SubSet.RateMode = util.IntAllDef(subSet["i_ratemode"], 2)
|
|
|
|
- user.SubSet.MatchWay = util.IntAllDef(subSet["i_matchway"], 1)
|
|
|
|
- logger.Info("加载订阅设置", "entId", entId, "entName", entName, "deptId", deptId, "deptName", deptName, "userId", userId, "appPush", user.SubSet.AppPush, "mailPush", user.SubSet.MailPush, "rateMode", user.SubSet.RateMode, "matchWay", user.SubSet.MatchWay)
|
|
|
|
- if m.InitSubSet(payUser, user, &title_key, &title_notkey, &detail_key, &detail_notkey) {
|
|
|
|
- payUser.Users[user] = true
|
|
|
|
- }
|
|
|
|
- if deptId <= 0 {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- //分发规则
|
|
|
|
- if EntDepts[deptId].Nodiff == 1 {
|
|
|
|
- logger.Info("该部门开启了全员无差别,分发规则无效", entName, entId, deptName, deptId)
|
|
|
|
- return
|
|
|
|
- } else if EntDeptDis[deptId] == nil {
|
|
|
|
- logger.Info("该部门没有分发规则", entName, entId, deptName, deptId)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ subSet, _ := temp["o_entniche"].(map[string]interface{})
|
|
|
|
+ if subSet == nil || len(subSet) == 0 {
|
|
|
|
+ logger.Info("商机管理产品我的订阅设置为空,过滤掉", entName, entId, deptId, userId)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ user := &UserInfo{
|
|
|
|
+ Entniche: &Entniche{
|
|
|
|
+ EntId: entId,
|
|
|
|
+ EntName: entName,
|
|
|
|
+ DeptId: deptId,
|
|
|
|
+ UserId: userId,
|
|
|
|
+ IsNew: Ents[entId].IsNew,
|
|
|
|
+ },
|
|
|
|
+ SubSet: GetSubSet(false, fmt.Sprint(userId), subSet),
|
|
|
|
+ }
|
|
|
|
+ logger.Info("加载商机管理产品我的订阅设置", "entId", entId, "entName", entName, "userId", userId, "wxPush", user.SubSet.WxPush, "appPush", user.SubSet.AppPush, "mailPush", user.SubSet.MailPush, "rateMode", user.SubSet.RateMode, "matchWay", user.SubSet.MatchWay)
|
|
|
|
+ if userId != 0 { //个人订阅
|
|
|
|
+ user.Entniche.Phone = EntUsers[user.Entniche.UserId].Phone
|
|
|
|
+ m.InitSubSet(allSubSet, user, title_pjob, detail_pjob)
|
|
|
|
+ allSubSet.Users[user] = true
|
|
|
|
+ } else { //企业/部门订阅
|
|
itemMap := map[string]interface{}{}
|
|
itemMap := map[string]interface{}{}
|
|
items, _ := subSet["a_items"].([]interface{})
|
|
items, _ := subSet["a_items"].([]interface{})
|
|
for _, v := range items {
|
|
for _, v := range items {
|
|
@@ -189,7 +172,17 @@ func (m *MatchJob) LoadSubSet() *PayUser {
|
|
}
|
|
}
|
|
itemMap[item_name] = item
|
|
itemMap[item_name] = item
|
|
}
|
|
}
|
|
- for _, dis := range EntDeptDis[deptId] {
|
|
|
|
|
|
+ var diss []*EntDistribute
|
|
|
|
+ if deptId == 0 {
|
|
|
|
+ diss = EntDis[entId]
|
|
|
|
+ } else {
|
|
|
|
+ diss = EntDeptDis[deptId]
|
|
|
|
+ }
|
|
|
|
+ if diss == nil || len(diss) == 0 {
|
|
|
|
+ logger.Info("该订阅规则没有分发规则,过滤掉", entId, deptId)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ for _, dis := range diss {
|
|
child_items := []interface{}{}
|
|
child_items := []interface{}{}
|
|
for _, item_name := range dis.Items {
|
|
for _, item_name := range dis.Items {
|
|
if itemMap[item_name] == nil {
|
|
if itemMap[item_name] == nil {
|
|
@@ -212,54 +205,42 @@ func (m *MatchJob) LoadSubSet() *PayUser {
|
|
}
|
|
}
|
|
child_user := &UserInfo{
|
|
child_user := &UserInfo{
|
|
Entniche: &Entniche{
|
|
Entniche: &Entniche{
|
|
- EntId: user.Entniche.EntId,
|
|
|
|
- EntName: user.Entniche.EntName,
|
|
|
|
- DeptId: user.Entniche.DeptId,
|
|
|
|
- DeptName: user.Entniche.DeptName,
|
|
|
|
- DisId: dis.Id,
|
|
|
|
- IsNew: user.Entniche.IsNew,
|
|
|
|
|
|
+ EntId: user.Entniche.EntId,
|
|
|
|
+ EntName: user.Entniche.EntName,
|
|
|
|
+ DeptId: user.Entniche.DeptId,
|
|
|
|
+ DisId: dis.Id,
|
|
|
|
+ IsNew: user.Entniche.IsNew,
|
|
|
|
+ PowerSource: user.Entniche.PowerSource,
|
|
|
|
+ ProductType: user.Entniche.ProductType,
|
|
|
|
+ Phone: user.Entniche.Phone,
|
|
},
|
|
},
|
|
SubSet: GetSubSet(false, dis.Id, child_subSet),
|
|
SubSet: GetSubSet(false, dis.Id, child_subSet),
|
|
}
|
|
}
|
|
|
|
+ child_user.SubSet.WxPush = user.SubSet.WxPush
|
|
child_user.SubSet.AppPush = user.SubSet.AppPush
|
|
child_user.SubSet.AppPush = user.SubSet.AppPush
|
|
child_user.SubSet.MailPush = user.SubSet.MailPush
|
|
child_user.SubSet.MailPush = user.SubSet.MailPush
|
|
child_user.SubSet.RateMode = user.SubSet.RateMode
|
|
child_user.SubSet.RateMode = user.SubSet.RateMode
|
|
child_user.SubSet.MatchWay = user.SubSet.MatchWay
|
|
child_user.SubSet.MatchWay = user.SubSet.MatchWay
|
|
child_user.SubSet.MaxPushSize = user.SubSet.MaxPushSize
|
|
child_user.SubSet.MaxPushSize = user.SubSet.MaxPushSize
|
|
child_user.SubSet.MaxMailSize = user.SubSet.MaxMailSize
|
|
child_user.SubSet.MaxMailSize = user.SubSet.MaxMailSize
|
|
- if m.InitSubSet(payUser, child_user, &title_key, &title_notkey, &detail_key, &detail_notkey) {
|
|
|
|
- payUser.Users[child_user] = true
|
|
|
|
- }
|
|
|
|
|
|
+ m.InitSubSet(allSubSet, child_user, title_pjob, detail_pjob)
|
|
|
|
+ allSubSet.Users[child_user] = true
|
|
}
|
|
}
|
|
- }(_temp)
|
|
|
|
- _temp = make(map[string]interface{})
|
|
|
|
- }
|
|
|
|
- //
|
|
|
|
- title_pjob := &KeyDfa{
|
|
|
|
- Key_user: &title_key,
|
|
|
|
- Notkey_user: &title_notkey,
|
|
|
|
- }
|
|
|
|
- title_pjob.CreateDaf()
|
|
|
|
- detail_pjob := &KeyDfa{
|
|
|
|
- Key_user: &detail_key,
|
|
|
|
- Notkey_user: &detail_notkey,
|
|
|
|
|
|
+ }
|
|
|
|
+ temp = make(map[string]interface{})
|
|
}
|
|
}
|
|
- detail_pjob.CreateDaf()
|
|
|
|
- payUser.Title_KeyDfa = title_pjob
|
|
|
|
- payUser.Detail_KeyDfa = detail_pjob
|
|
|
|
- return payUser
|
|
|
|
}
|
|
}
|
|
-func (m *MatchJob) InitSubSet(payUser *PayUser, user *UserInfo, title_key_user, title_notkey_user, detail_key_user, detail_notkey_user *map[string]*[]*UserInfo) bool {
|
|
|
|
- user.AddBuyerclass(&payUser.BuyerclassUsers)
|
|
|
|
- user.AddAreaCity(&payUser.AreaUsers, &payUser.CityUsers)
|
|
|
|
- user.AddSbuype(&payUser.SubtypeUsers)
|
|
|
|
- user.MakeKeyUser(user.SubSet.Keys, title_key_user)
|
|
|
|
- user.MakeKeyUser(user.SubSet.Notkeys, title_notkey_user)
|
|
|
|
|
|
+
|
|
|
|
+func (m *MatchJob) InitSubSet(allSubSet *PayUser, user *UserInfo, title_pjob, detail_pjob *KeyDfa) {
|
|
|
|
+ user.AddBuyerclass(&allSubSet.BuyerclassUsers)
|
|
|
|
+ user.AddAreaCity(&allSubSet.AreaUsers, &allSubSet.CityUsers)
|
|
|
|
+ user.AddSbuype(&allSubSet.SubtypeUsers)
|
|
|
|
+ user.MakeKeyUser(user.SubSet.Keys, title_pjob.Key_user)
|
|
|
|
+ user.MakeKeyUser(user.SubSet.Notkeys, title_pjob.Notkey_user)
|
|
if user.SubSet.MatchWay == 2 {
|
|
if user.SubSet.MatchWay == 2 {
|
|
- user.MakeKeyUser(user.SubSet.Keys, detail_key_user)
|
|
|
|
- user.MakeKeyUser(user.SubSet.Notkeys, detail_notkey_user)
|
|
|
|
|
|
+ user.MakeKeyUser(user.SubSet.Keys, detail_pjob.Key_user)
|
|
|
|
+ user.MakeKeyUser(user.SubSet.Notkeys, detail_pjob.Notkey_user)
|
|
}
|
|
}
|
|
- return true
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//遍历数据并执行推送操作
|
|
//遍历数据并执行推送操作
|
|
@@ -329,14 +310,9 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
|
|
logger.Info("开始保存客户和项目。。。")
|
|
logger.Info("开始保存客户和项目。。。")
|
|
customerMap := &sync.Map{}
|
|
customerMap := &sync.Map{}
|
|
for k, v := range *entRuleMap {
|
|
for k, v := range *entRuleMap {
|
|
- //分发规则,跳过
|
|
|
|
- if k.Entniche.DeptId == 0 || EntDepts[k.Entniche.DeptId] == nil || EntDepts[k.Entniche.DeptId].Subdis == 0 || k.Entniche.DisId != "" {
|
|
|
|
|
|
+ if k.Entniche.IsNew == 1 || k.Entniche.PowerSource == 1 {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- //没有开全员无差别的话,此规则不进行推送
|
|
|
|
- if EntDepts[k.Entniche.DeptId].Nodiff == 0 {
|
|
|
|
- delete(*entRuleMap, k)
|
|
|
|
- }
|
|
|
|
savePool <- true
|
|
savePool <- true
|
|
saveWaitGroup.Add(1)
|
|
saveWaitGroup.Add(1)
|
|
go func(user *UserInfo, infos *SortList) {
|
|
go func(user *UserInfo, infos *SortList) {
|
|
@@ -345,9 +321,6 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
|
|
<-savePool
|
|
<-savePool
|
|
saveWaitGroup.Done()
|
|
saveWaitGroup.Done()
|
|
}()
|
|
}()
|
|
- if user.Entniche.IsNew == 1 {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
isLimit := Mysql.CountBySql(`select count(1) as count from entniche_customer where ent_id=?`, user.Entniche.EntId) > Config.MaxCustomer
|
|
isLimit := Mysql.CountBySql(`select count(1) as count from entniche_customer where ent_id=?`, user.Entniche.EntId) > Config.MaxCustomer
|
|
nowFormat := util.NowFormat(util.Date_Full_Layout)
|
|
nowFormat := util.NowFormat(util.Date_Full_Layout)
|
|
customer_count, update_customer_count := 0, 0
|
|
customer_count, update_customer_count := 0, 0
|
|
@@ -523,7 +496,7 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
|
|
<-savePool
|
|
<-savePool
|
|
saveWaitGroup.Done()
|
|
saveWaitGroup.Done()
|
|
}()
|
|
}()
|
|
- logger.Info("entId", user.Entniche.EntId, "entName", user.Entniche.EntName, "deptId", user.Entniche.DeptId, "deptName", user.Entniche.DeptName, "userId", user.Entniche.UserId, user.Id, "本轮匹配上了", len(*infos), "条")
|
|
|
|
|
|
+ logger.Info("entId", user.Entniche.EntId, "entName", user.Entniche.EntName, "deptId", user.Entniche.DeptId, "userId", user.Entniche.UserId, user.Id, "本轮匹配上了", len(*infos), "条")
|
|
//取最新的
|
|
//取最新的
|
|
sort.Sort(infos)
|
|
sort.Sort(infos)
|
|
array := &SortList{}
|
|
array := &SortList{}
|
|
@@ -557,7 +530,7 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
|
|
}
|
|
}
|
|
if size == maxPushSize {
|
|
if size == maxPushSize {
|
|
if k2 < len(*infos)-1 {
|
|
if k2 < len(*infos)-1 {
|
|
- logger.Info("entId", user.Entniche.EntId, "entName", user.Entniche.EntName, "deptId", user.Entniche.DeptId, "deptName", user.Entniche.DeptName, "userId", user.Entniche.UserId, user.Id, "匹配上", len(*infos), "超过限制数", size, "丢弃", len(*infos)-size)
|
|
|
|
|
|
+ logger.Info("entId", user.Entniche.EntId, "entName", user.Entniche.EntName, "deptId", user.Entniche.DeptId, "userId", user.Entniche.UserId, user.Id, "匹配上", len(*infos), "超过限制数", size, "丢弃", len(*infos)-size)
|
|
}
|
|
}
|
|
break
|
|
break
|
|
}
|
|
}
|
|
@@ -565,117 +538,86 @@ func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
|
|
if size == 0 {
|
|
if size == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ wxtplmsg_keyword, wxtplmsg_area := GetWxTplMsg(user.SubSet)
|
|
lock.Lock()
|
|
lock.Lock()
|
|
defer lock.Unlock()
|
|
defer lock.Unlock()
|
|
unique := GetUnique(user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Entniche.DisId)
|
|
unique := GetUnique(user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, user.Entniche.DisId)
|
|
myMatchId[unique] = matchId
|
|
myMatchId[unique] = matchId
|
|
//
|
|
//
|
|
- var staffIds map[int]bool
|
|
|
|
- if user.Entniche.DeptId > 0 {
|
|
|
|
- user.Entniche.DeptName = EntDepts[user.Entniche.DeptId].Name
|
|
|
|
- staffIds = GetDeptUserIds(&UserInfo{
|
|
|
|
- Entniche: &Entniche{
|
|
|
|
- EntId: user.Entniche.EntId,
|
|
|
|
- EntName: user.Entniche.EntName,
|
|
|
|
- DeptId: user.Entniche.DeptId,
|
|
|
|
- DeptName: user.Entniche.DeptName,
|
|
|
|
- DisId: user.Entniche.DisId,
|
|
|
|
- },
|
|
|
|
- })
|
|
|
|
- if staffIds == nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- } else if user.Entniche.UserId > 0 {
|
|
|
|
- staffIds = map[int]bool{user.Entniche.UserId: true}
|
|
|
|
- } else {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
saveUnique := GetUnique(user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, "")
|
|
saveUnique := GetUnique(user.Entniche.EntId, user.Entniche.DeptId, user.Entniche.UserId, "")
|
|
- for staffId, _ := range staffIds {
|
|
|
|
- uis := NewUserInfo(Mgo, &UserInfo{
|
|
|
|
- Entniche: &Entniche{
|
|
|
|
- EntId: user.Entniche.EntId,
|
|
|
|
- EntName: user.Entniche.EntName,
|
|
|
|
- DeptId: user.Entniche.DeptId,
|
|
|
|
- DeptName: user.Entniche.DeptName,
|
|
|
|
- UserId: staffId,
|
|
|
|
- DisId: user.Entniche.DisId,
|
|
|
|
- },
|
|
|
|
- SubSet: user.SubSet,
|
|
|
|
- Id: user.Id,
|
|
|
|
- })
|
|
|
|
- if uis == nil {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- onlypush := 0
|
|
|
|
- jpushidMap, opushidMap, mailMap := map[string]bool{}, map[string]bool{}, map[string]bool{}
|
|
|
|
- for _, ui_v := range uis {
|
|
|
|
- if ui_v.SubSet.AppPush == 1 && (ui_v.Jpushid != "" && jpushidMap[ui_v.Jpushid]) || (ui_v.Opushid != "" && opushidMap[ui_v.Opushid]) {
|
|
|
|
- ui_v.SubSet.AppPush = 0
|
|
|
|
- ui_v.Jpushid = ""
|
|
|
|
- ui_v.Opushid = ""
|
|
|
|
- }
|
|
|
|
- if ui_v.SubSet.MailPush == 1 && ui_v.SubSet.Email != "" && mailMap[ui_v.SubSet.Email] {
|
|
|
|
- ui_v.SubSet.MailPush = 0
|
|
|
|
- ui_v.SubSet.Email = ""
|
|
|
|
- }
|
|
|
|
- if ui_v.Jpushid != "" {
|
|
|
|
- jpushidMap[ui_v.Jpushid] = true
|
|
|
|
- }
|
|
|
|
- if ui_v.Opushid != "" {
|
|
|
|
- opushidMap[ui_v.Opushid] = true
|
|
|
|
- }
|
|
|
|
- if ui_v.SubSet.Email != "" {
|
|
|
|
- mailMap[ui_v.SubSet.Email] = true
|
|
|
|
- }
|
|
|
|
- if onlypush == 1 {
|
|
|
|
- if ui_v.SubSet.AppPush == 1 && ui_v.SubSet.MailPush == 1 {
|
|
|
|
- if ui_v.Jpushid == "" && ui_v.Opushid == "" && ui_v.SubSet.Email == "" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- } else if ui_v.SubSet.AppPush == 1 {
|
|
|
|
- if ui_v.Jpushid == "" && ui_v.Opushid == "" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- } else if ui_v.SubSet.MailPush == 1 {
|
|
|
|
- if ui_v.SubSet.Email == "" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- continue
|
|
|
|
|
|
+ uis := UisSortByRateMode{}
|
|
|
|
+ if user.Entniche.VipStatus == 1 || user.Entniche.MemberStatus == 1 {
|
|
|
|
+ uis = append(uis, user)
|
|
|
|
+ } else {
|
|
|
|
+ disUsers := []*UserInfo{}
|
|
|
|
+ if user.Entniche.DisId != "" {
|
|
|
|
+ if dus := GetDisUser(user.Entniche); dus != nil {
|
|
|
|
+ for duk, duv := range dus {
|
|
|
|
+ disUsers = append(disUsers, &UserInfo{
|
|
|
|
+ Entniche: &Entniche{
|
|
|
|
+ EntId: user.Entniche.EntId,
|
|
|
|
+ EntName: user.Entniche.EntName,
|
|
|
|
+ DeptId: user.Entniche.DeptId,
|
|
|
|
+ UserId: duk,
|
|
|
|
+ DisId: user.Entniche.DisId,
|
|
|
|
+ Phone: duv.Phone,
|
|
|
|
+ },
|
|
|
|
+ SubSet: user.SubSet,
|
|
|
|
+ Id: user.Id,
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- SortListSplit(array, func(list interface{}) {
|
|
|
|
- saveBatch = append(saveBatch, map[string]interface{}{
|
|
|
|
- "entid": ui_v.Entniche.EntId,
|
|
|
|
- "entname": ui_v.Entniche.EntName,
|
|
|
|
- "deptid": ui_v.Entniche.DeptId,
|
|
|
|
- "userid": ui_v.Entniche.UserId,
|
|
|
|
- "mid": ui_v.Id,
|
|
|
|
- "unique": saveUnique,
|
|
|
|
- "distributeid": ui_v.Entniche.DisId,
|
|
|
|
- "jpushid": ui_v.Jpushid,
|
|
|
|
- "opushid": ui_v.Opushid,
|
|
|
|
- "appphonetype": ui_v.AppPhoneType,
|
|
|
|
- "ratemode": ui_v.SubSet.RateMode,
|
|
|
|
- "apppush": ui_v.SubSet.AppPush,
|
|
|
|
- "mailpush": ui_v.SubSet.MailPush,
|
|
|
|
- "email": ui_v.SubSet.Email,
|
|
|
|
- "list": list,
|
|
|
|
- "words": ui_v.SubSet.Keys,
|
|
|
|
- "maxpushsize": ui_v.SubSet.MaxPushSize,
|
|
|
|
- "maxmailsize": ui_v.SubSet.MaxMailSize,
|
|
|
|
- "timestamp": time.Now().Unix(),
|
|
|
|
- "onlypush": onlypush,
|
|
|
|
- })
|
|
|
|
- if len(saveBatch) == Mgo_BulkSize {
|
|
|
|
- Mgo_Log.SaveBulk(Pushspace_temp, saveBatch...)
|
|
|
|
- saveBatch = []map[string]interface{}{}
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- onlypush = 1
|
|
|
|
|
|
+ } else if user.Entniche.UserId > 0 {
|
|
|
|
+ disUsers = append(disUsers, user)
|
|
|
|
+ } else {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, disUser := range disUsers {
|
|
|
|
+ if newUis := NewUserInfo(Mgo, disUser); newUis != nil {
|
|
|
|
+ uis = append(uis, newUis...)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ for _, ui_v := range uis {
|
|
|
|
+ SortListSplit(array, func(list interface{}) {
|
|
|
|
+ saveBatch = append(saveBatch, map[string]interface{}{
|
|
|
|
+ "entid": ui_v.Entniche.EntId,
|
|
|
|
+ "entname": ui_v.Entniche.EntName,
|
|
|
|
+ "deptid": ui_v.Entniche.DeptId,
|
|
|
|
+ "userid": ui_v.Entniche.UserId,
|
|
|
|
+ "mid": ui_v.Id,
|
|
|
|
+ "unique": saveUnique,
|
|
|
|
+ "distributeid": ui_v.Entniche.DisId,
|
|
|
|
+ "jpushid": ui_v.Jpushid,
|
|
|
|
+ "opushid": ui_v.Opushid,
|
|
|
|
+ "appphonetype": ui_v.AppPhoneType,
|
|
|
|
+ "ratemode": ui_v.SubSet.RateMode,
|
|
|
|
+ "wxpush": ui_v.SubSet.WxPush,
|
|
|
|
+ "apppush": ui_v.SubSet.AppPush,
|
|
|
|
+ "mailpush": ui_v.SubSet.MailPush,
|
|
|
|
+ "email": ui_v.SubSet.Email,
|
|
|
|
+ "list": list,
|
|
|
|
+ "words": ui_v.SubSet.Keys,
|
|
|
|
+ "maxpushsize": ui_v.SubSet.MaxPushSize,
|
|
|
|
+ "maxmailsize": ui_v.SubSet.MaxMailSize,
|
|
|
|
+ "timestamp": time.Now().Unix(),
|
|
|
|
+ "onlypush": ui_v.Entniche.OnlyPush,
|
|
|
|
+ "vipstatus": ui_v.Entniche.VipStatus,
|
|
|
|
+ "memberstatus": ui_v.Entniche.MemberStatus,
|
|
|
|
+ "s_m_openid": ui_v.S_m_openid,
|
|
|
|
+ "subscribe": ui_v.Subscribe,
|
|
|
|
+ "applystatus": ui_v.ApplyStatus,
|
|
|
|
+ "wxtplmsg": map[string]interface{}{
|
|
|
|
+ "key": wxtplmsg_keyword,
|
|
|
|
+ "area": wxtplmsg_area,
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+ if len(saveBatch) == Mgo_BulkSize {
|
|
|
|
+ Mgo_Log.SaveBulk(Pushspace_temp, saveBatch...)
|
|
|
|
+ saveBatch = []map[string]interface{}{}
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}(k, v)
|
|
}(k, v)
|
|
index++
|
|
index++
|
|
if index%500 == 0 {
|
|
if index%500 == 0 {
|
|
@@ -724,7 +666,6 @@ func (m *MatchJob) UpdateCustomer(array *[]int64) {
|
|
ws = append(ws, "?")
|
|
ws = append(ws, "?")
|
|
args = append(args, v)
|
|
args = append(args, v)
|
|
}
|
|
}
|
|
-
|
|
|
|
Mysql.UpdateOrDeleteBySql(`update entniche_customer set updatetime=? where id in (`+strings.Join(ws, ",")+`)`, args...)
|
|
Mysql.UpdateOrDeleteBySql(`update entniche_customer set updatetime=? where id in (`+strings.Join(ws, ",")+`)`, args...)
|
|
*array = []int64{}
|
|
*array = []int64{}
|
|
}
|
|
}
|