...
|
...
|
@@ -32,7 +32,9 @@ func (repository *PushDeviceRepository) FindOne(queryOptions map[string]interfac |
|
|
qs := o.QueryTable(model.TableName()).Filter("uid", queryOptions["uid"])
|
|
|
err := qs.One(model)
|
|
|
if err != nil {
|
|
|
err = domain.ERR_DB_NOT_FOUND
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = domain.ERR_DB_NOT_FOUND
|
|
|
}
|
|
|
return nil, err
|
|
|
}
|
|
|
return repository.transformBgormModelToDomainModel(model)
|
...
|
...
|
@@ -42,7 +44,7 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} |
|
|
o := orm.NewOrm()
|
|
|
model := new(models.PushDeviceInfo)
|
|
|
var ms []*models.PushDeviceInfo
|
|
|
qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"])
|
|
|
qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"]).Filter("is_active", 1)
|
|
|
qs.All(&ms)
|
|
|
if len(ms) == 0 {
|
|
|
return
|
...
|
...
|
@@ -56,10 +58,20 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} |
|
|
|
|
|
func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string) error {
|
|
|
o := orm.NewOrm()
|
|
|
_, err := o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now() where uid=?", clientId, deviceToken, uid).Exec()
|
|
|
o.Begin()
|
|
|
//更新其他绑定这个client_id的设备 is_active=0
|
|
|
_, err := o.Raw("UPDATE push_device_info SET update_at=now(),is_active=0 where client_id=? and is_active=1", clientId).Exec()
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
_, err = o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now(),is_active=1 where uid=?", clientId, deviceToken, uid).Exec()
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -97,6 +109,7 @@ func (repository *PushDeviceRepository) transformBgormModelToDomainModel(model * |
|
|
Uid: model.Uid,
|
|
|
ClientId: model.ClientId,
|
|
|
DeviceToken: model.DeviceToken,
|
|
|
IsActive: model.IsActive,
|
|
|
}, nil
|
|
|
}
|
|
|
|
...
|
...
|
|