正在显示
4 个修改的文件
包含
23 行增加
和
9 行删除
| @@ -8,7 +8,6 @@ import ( | @@ -8,7 +8,6 @@ import ( | ||
| 8 | "openapi/pkg/infrastructure/push/getui" | 8 | "openapi/pkg/infrastructure/push/getui" |
| 9 | "openapi/pkg/infrastructure/repository" | 9 | "openapi/pkg/infrastructure/repository" |
| 10 | "openapi/pkg/infrastructure/utils" | 10 | "openapi/pkg/infrastructure/utils" |
| 11 | - "strings" | ||
| 12 | ) | 11 | ) |
| 13 | 12 | ||
| 14 | //推送信息 | 13 | //推送信息 |
| @@ -112,11 +111,11 @@ func NotificationOriginal(header *protocol.RequestHeader, request *protocol.Push | @@ -112,11 +111,11 @@ func NotificationOriginal(header *protocol.RequestHeader, request *protocol.Push | ||
| 112 | //更新设备信息 | 111 | //更新设备信息 |
| 113 | func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) { | 112 | func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) { |
| 114 | var ( | 113 | var ( |
| 115 | - device *protocol.Device | 114 | + //device *protocol.Device |
| 116 | ) | 115 | ) |
| 117 | rsp = &protocol.UpdateDeviceResponse{} | 116 | rsp = &protocol.UpdateDeviceResponse{} |
| 118 | rep, _ := repository.NewPushDeviceRepository(nil) | 117 | rep, _ := repository.NewPushDeviceRepository(nil) |
| 119 | - if device, err = rep.FindOne(map[string]interface{}{"uid": request.Muid}); err != nil { | 118 | + if _, err = rep.FindOne(map[string]interface{}{"uid": request.Muid}); err != nil { |
| 120 | if err == protocol.ERR_DB_NOT_FOUND { | 119 | if err == protocol.ERR_DB_NOT_FOUND { |
| 121 | err = nil | 120 | err = nil |
| 122 | rep.Save(request) | 121 | rep.Save(request) |
| @@ -125,10 +124,10 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice | @@ -125,10 +124,10 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice | ||
| 125 | log.Error(err) | 124 | log.Error(err) |
| 126 | return | 125 | return |
| 127 | } | 126 | } |
| 128 | - if device.ClientId == strings.TrimSpace(request.ClientId) && device.DeviceToken == strings.TrimSpace(request.DeviceToken) { | ||
| 129 | - err = protocol.NewSuccessWithMessage("更新成功") | ||
| 130 | - return | ||
| 131 | - } | 127 | + //if device.ClientId == strings.TrimSpace(request.ClientId) && device.DeviceToken == strings.TrimSpace(request.DeviceToken) && device.IsActive==1{ |
| 128 | + // err = protocol.NewSuccessWithMessage("更新成功") | ||
| 129 | + // return | ||
| 130 | + //} | ||
| 132 | if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken); err != nil { | 131 | if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken); err != nil { |
| 133 | log.Error(err) | 132 | log.Error(err) |
| 134 | } | 133 | } |
| @@ -13,6 +13,7 @@ type PushDeviceInfo struct { | @@ -13,6 +13,7 @@ type PushDeviceInfo struct { | ||
| 13 | DeviceToken string `orm:"column(device_token);size(100);null" description:"设备识别码 推送标识"` | 13 | DeviceToken string `orm:"column(device_token);size(100);null" description:"设备识别码 推送标识"` |
| 14 | CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | 14 | CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` |
| 15 | UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | 15 | UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` |
| 16 | + IsActive int `orm:"column(is_active);null" description:"是否在活动 1:在线 0:离线(解绑,切换账号)"` | ||
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | func (t *PushDeviceInfo) TableName() string { | 19 | func (t *PushDeviceInfo) TableName() string { |
| @@ -32,7 +32,9 @@ func (repository *PushDeviceRepository) FindOne(queryOptions map[string]interfac | @@ -32,7 +32,9 @@ func (repository *PushDeviceRepository) FindOne(queryOptions map[string]interfac | ||
| 32 | qs := o.QueryTable(model.TableName()).Filter("uid", queryOptions["uid"]) | 32 | qs := o.QueryTable(model.TableName()).Filter("uid", queryOptions["uid"]) |
| 33 | err := qs.One(model) | 33 | err := qs.One(model) |
| 34 | if err != nil { | 34 | if err != nil { |
| 35 | + if err == orm.ErrNoRows { | ||
| 35 | err = domain.ERR_DB_NOT_FOUND | 36 | err = domain.ERR_DB_NOT_FOUND |
| 37 | + } | ||
| 36 | return nil, err | 38 | return nil, err |
| 37 | } | 39 | } |
| 38 | return repository.transformBgormModelToDomainModel(model) | 40 | return repository.transformBgormModelToDomainModel(model) |
| @@ -42,7 +44,7 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | @@ -42,7 +44,7 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | ||
| 42 | o := orm.NewOrm() | 44 | o := orm.NewOrm() |
| 43 | model := new(models.PushDeviceInfo) | 45 | model := new(models.PushDeviceInfo) |
| 44 | var ms []*models.PushDeviceInfo | 46 | var ms []*models.PushDeviceInfo |
| 45 | - qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"]) | 47 | + qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"]).Filter("is_active", 1) |
| 46 | qs.All(&ms) | 48 | qs.All(&ms) |
| 47 | if len(ms) == 0 { | 49 | if len(ms) == 0 { |
| 48 | return | 50 | return |
| @@ -56,10 +58,20 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | @@ -56,10 +58,20 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | ||
| 56 | 58 | ||
| 57 | func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string) error { | 59 | func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string) error { |
| 58 | o := orm.NewOrm() | 60 | o := orm.NewOrm() |
| 59 | - _, err := o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now() where uid=?", clientId, deviceToken, uid).Exec() | 61 | + o.Begin() |
| 62 | + //更新其他绑定这个client_id的设备 is_active=0 | ||
| 63 | + _, err := o.Raw("UPDATE push_device_info SET update_at=now(),is_active=0 where client_id=? and is_active=1", clientId).Exec() | ||
| 64 | + if err != nil { | ||
| 65 | + o.Rollback() | ||
| 66 | + return err | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + _, err = o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now(),is_active=1 where uid=?", clientId, deviceToken, uid).Exec() | ||
| 60 | if err != nil { | 70 | if err != nil { |
| 71 | + o.Rollback() | ||
| 61 | return err | 72 | return err |
| 62 | } | 73 | } |
| 74 | + o.Commit() | ||
| 63 | return nil | 75 | return nil |
| 64 | } | 76 | } |
| 65 | 77 | ||
| @@ -97,6 +109,7 @@ func (repository *PushDeviceRepository) transformBgormModelToDomainModel(model * | @@ -97,6 +109,7 @@ func (repository *PushDeviceRepository) transformBgormModelToDomainModel(model * | ||
| 97 | Uid: model.Uid, | 109 | Uid: model.Uid, |
| 98 | ClientId: model.ClientId, | 110 | ClientId: model.ClientId, |
| 99 | DeviceToken: model.DeviceToken, | 111 | DeviceToken: model.DeviceToken, |
| 112 | + IsActive: model.IsActive, | ||
| 100 | }, nil | 113 | }, nil |
| 101 | } | 114 | } |
| 102 | 115 |
-
请 注册 或 登录 后发表评论