123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package service
- import (
- "app.yhyue.com/moapp/jybase/common"
- "fmt"
- IC "jyBXSubscribe/rpc/init"
- "jyBXSubscribe/rpc/type/bxsubscribe"
- "jyBXSubscribe/rpc/util"
- )
- type PushSetService struct {
- UserId string //mongodb 的用户id
- PositionType int64
- EntId int64
- EntUserId int64
- }
- func (this *PushSetService) Update(item, setType, pushType string, ratemode, pushValue int64, times []string) bool {
- set := map[string]interface{}{}
- switch setType {
- case "pushRoute":
- set = map[string]interface{}{
- fmt.Sprintf("o_pushset.%s.%s", item, pushType): pushValue,
- }
- break
- default:
- switch pushType {
- case "":
- set = map[string]interface{}{
- fmt.Sprintf("o_pushset.%s.a_times", item): times,
- }
- break
- case "ratemode":
- set = map[string]interface{}{
- fmt.Sprintf("o_pushset.%s.i_ratemode", item): ratemode,
- }
- break
- }
- }
- update := false
- if this.PositionType == 0 {
- update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
- "$set": set,
- })
- } else {
- update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
- "$set": set,
- }, true, false)
- }
- return update
- }
- func (this *PushSetService) Find() map[string]*bxsubscribe.PushSet {
- pushSetList := &map[string]interface{}{}
- if this.PositionType == 0 {
- pushSetList, _ = IC.Mgo.FindById(util.USER, this.UserId, `{"o_pushset":":1}`)
- } else {
- pushSetList, _ = IC.Mgo.FindOne(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId})
- }
- pushSet := map[string]*bxsubscribe.PushSet{}
- if pushSetList != nil && len(*pushSetList) > 0 {
- o_pushset, _ := (*pushSetList)["o_pushset"].(map[string]interface{})
- fool, o_subset := pushSetMontage(o_pushset["o_subset"])
- if fool {
- pushSet["o_subset"] = o_subset
- }
- fool, o_week_report := pushSetMontage(o_pushset["o_week_report"])
- if fool {
- pushSet["o_week_report"] = o_week_report
- }
- fool, o_month_report := pushSetMontage(o_pushset["o_month_report"])
- if fool {
- pushSet["o_month_report"] = o_month_report
- }
- fool, o_newproject_forecast := pushSetMontage(o_pushset["o_newproject_forecast"])
- if fool {
- pushSet["o_newproject_forecast"] = o_newproject_forecast
- }
- fool, o_entinfo := pushSetMontage(o_pushset["o_entinfo"])
- if fool {
- pushSet["o_entinfo"] = o_entinfo
- }
- fool, o_follow_project := pushSetMontage(o_pushset["o_follow_project"])
- if fool {
- pushSet["o_follow_project"] = o_follow_project
- }
- fool, o_follow_ent := pushSetMontage(o_pushset["o_follow_ent"])
- if fool {
- pushSet["o_entinfo"] = o_follow_ent
- }
- }
- return pushSet
- }
- func pushSetMontage(in interface{}) (bool, *bxsubscribe.PushSet) {
- data := common.ObjToMap(in)
- if data == nil || len(*data) == 0 {
- return false, nil
- }
- a_times := []string{}
- if (*data)["a_times"] != nil {
- a_times = common.ObjArrToStringArr((*data)["a_times"].([]interface{}))
- }
- return true, &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: common.Int64All((*data)["i_apppush"]),
- IWxpush: common.Int64All((*data)["i_wxpush"]),
- IMailpush: common.Int64All((*data)["i_mailpush"]),
- IRatemode: common.Int64All((*data)["i_ratemode"]),
- }
- }
- func (this *PushSetService) SetUser(mail string) bool {
- set := map[string]interface{}{
- "o_pushset.s_email": mail,
- }
- update := false
- if this.PositionType == 0 {
- update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
- "$set": set,
- })
- } else {
- update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
- "$set": set,
- }, true, false)
- }
- return update
- }
|