Commit a1f7661b authored by hujiebin's avatar hujiebin

势力等级即将过期

parent a80e1c20
...@@ -3,6 +3,7 @@ package group_cron ...@@ -3,6 +3,7 @@ package group_cron
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron" "github.com/robfig/cron"
"hilo-group/domain/event/group_power_ev"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
) )
...@@ -26,5 +27,11 @@ func GroupPowerExpClear() { ...@@ -26,5 +27,11 @@ func GroupPowerExpClear() {
model.Log.Errorf("ClearGroupPowerGrade fail:%v", err) model.Log.Errorf("ClearGroupPowerGrade fail:%v", err)
} }
}) })
// 每月20号发家族即将过期通知
spec = "0 0 0 20 * ?"
_ = c.AddFunc(spec, func() {
var model = domain.CreateModelNil()
_ = group_power_ev.PublishGroupPowerExpireNotice(model, &group_power_ev.GroupPowerExpireNoticeEvent{})
})
c.Start() c.Start()
} }
package group_power_ev
import (
"git.hilo.cn/hilo-common/domain"
)
//注册监听
var groupPowerExpireNoticeListen = new(domain.EventBase)
type GroupPowerExpireNoticeEvent struct {
}
//添加领域事件,在每个领域模型中init中添加,因为这是静态业务,非动态的。
func AddGroupPowerExpireNoticeSync(callback func(model *domain.Model, event interface{}) error) {
domain.AddEventSync(groupPowerExpireNoticeListen, callback)
}
//加入到异步操作中
func AddGroupPowerExpireNoticeAsync(callback func(model *domain.Model, event interface{}) error) {
domain.AddEventAsync(groupPowerExpireNoticeListen, callback)
}
//领域事件发布
func PublishGroupPowerExpireNotice(model *domain.Model, event interface{}) error {
return domain.PublishEvent(groupPowerExpireNoticeListen, model, event)
}
...@@ -3,6 +3,7 @@ package groupPower_m ...@@ -3,6 +3,7 @@ package groupPower_m
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"hilo-group/_const/enum/groupPower_e"
) )
type GroupPowerInfo struct { type GroupPowerInfo struct {
...@@ -55,3 +56,14 @@ func GetGroupPowerUser(model *domain.Model, groupPowerId mysql.ID) ([]*GroupPowe ...@@ -55,3 +56,14 @@ func GetGroupPowerUser(model *domain.Model, groupPowerId mysql.ID) ([]*GroupPowe
} }
return m[groupPowerId], nil return m[groupPowerId], nil
} }
// 获取所有家族的主
func GetAllGroupPowerOwners(model *domain.Model) ([]mysql.ID, error) {
var userIds []mysql.ID
if err := model.DB().Model(GroupPowerUser{}).Select("user_id").
Where("role = ?", groupPower_e.GroupPowerUserRoleMgr).Find(&userIds).Error; err != nil {
model.Log.Errorf("GetAllGroupPowerOwners fail:%v", err)
return userIds, err
}
return userIds, nil
}
...@@ -191,6 +191,28 @@ func GroupPowerEvents() { ...@@ -191,6 +191,28 @@ func GroupPowerEvents() {
} }
return nil return nil
}) })
// 势力等级即将过期
group_power_ev.AddGroupPowerExpireNoticeAsync(func(model *domain.Model, e interface{}) error {
model.Log.Infof("msg AddGroupPowerExpireNoticeAsync")
powerOwners, err := groupPower_m.GetAllGroupPowerOwners(model)
if err != nil {
model.Log.Errorf("AddGroupPowerExpireNoticeAsync fail:%v", err)
return err
}
userMaps, err := user_m.GetUserMapByIds(model, powerOwners)
if err != nil {
return err
}
for uid, u := range userMaps {
if err := msg_m.NewUserRecord(model, uid, msg_e.GroupPowerExpireNotice, "", 0, "", "", "", "", "").Persistent(); err != nil {
model.Log.Errorf("msg AddGroupPowerExpireNoticeAsync NewUserRecord err:%v", err)
return nil
}
msg_m.SendEmasMsgAssistant(model, u.ExternalId, u.DeviceType)
}
return nil
})
} }
func GroupEvents() { func GroupEvents() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment