作者 yangfu

1.推送修改 :同一设备,不同做账号,解绑

... ... @@ -8,7 +8,6 @@ import (
"openapi/pkg/infrastructure/push/getui"
"openapi/pkg/infrastructure/repository"
"openapi/pkg/infrastructure/utils"
"strings"
)
//推送信息
... ... @@ -112,11 +111,11 @@ func NotificationOriginal(header *protocol.RequestHeader, request *protocol.Push
//更新设备信息
func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) {
var (
device *protocol.Device
//device *protocol.Device
)
rsp = &protocol.UpdateDeviceResponse{}
rep, _ := repository.NewPushDeviceRepository(nil)
if device, err = rep.FindOne(map[string]interface{}{"uid": request.Muid}); err != nil {
if _, err = rep.FindOne(map[string]interface{}{"uid": request.Muid}); err != nil {
if err == protocol.ERR_DB_NOT_FOUND {
err = nil
rep.Save(request)
... ... @@ -125,10 +124,10 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice
log.Error(err)
return
}
if device.ClientId == strings.TrimSpace(request.ClientId) && device.DeviceToken == strings.TrimSpace(request.DeviceToken) {
err = protocol.NewSuccessWithMessage("更新成功")
return
}
//if device.ClientId == strings.TrimSpace(request.ClientId) && device.DeviceToken == strings.TrimSpace(request.DeviceToken) && device.IsActive==1{
// err = protocol.NewSuccessWithMessage("更新成功")
// return
//}
if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken); err != nil {
log.Error(err)
}
... ...
... ... @@ -40,6 +40,7 @@ type Device struct {
Uid int64
ClientId string
DeviceToken string
IsActive int
}
//应用信息
... ...
... ... @@ -13,6 +13,7 @@ type PushDeviceInfo struct {
DeviceToken string `orm:"column(device_token);size(100);null" description:"设备识别码 推送标识"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
IsActive int `orm:"column(is_active);null" description:"是否在活动 1:在线 0:离线(解绑,切换账号)"`
}
func (t *PushDeviceInfo) TableName() string {
... ...
... ... @@ -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
}
... ...