正在显示
12 个修改的文件
包含
72 行增加
和
28 行删除
| @@ -12,7 +12,7 @@ cname ="https://media.fjmaimaimai.com/" | @@ -12,7 +12,7 @@ cname ="https://media.fjmaimaimai.com/" | ||
| 12 | 12 | ||
| 13 | #数据库相关 | 13 | #数据库相关 |
| 14 | MYSQL_USER = "${MYSQL_USER||root1}" | 14 | MYSQL_USER = "${MYSQL_USER||root1}" |
| 15 | -MYSQL_PASSWORD = "${MYSQL_PASSWORD||sutianxia20181}" | ||
| 16 | -MYSQL_HOST = "${MYSQL_HOST||101.37.68.231}" | ||
| 17 | -MYSQL_PORT = "${MYSQL_PORT||33061}" | ||
| 18 | -MYSQL_DB_NAME = "${MYSQL_DB_NAME||mmm_open_test1}" | ||
| 15 | +MYSQL_PASSWORD = "${MYSQL_PASSWORD||sutianxia2018}" | ||
| 16 | +MYSQL_HOST = "${MYSQL_HOST||101.37.68.23}" | ||
| 17 | +MYSQL_PORT = "${MYSQL_PORT||3306}" | ||
| 18 | +MYSQL_DB_NAME = "${MYSQL_DB_NAME||mmm_open_test}" |
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | +import _ "openapi/pkg/log" | ||
| 4 | + | ||
| 3 | import ( | 5 | import ( |
| 4 | "github.com/astaxie/beego" | 6 | "github.com/astaxie/beego" |
| 5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 7 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
| 6 | - "openapi/pkg/constant" | 8 | + |
| 7 | _ "openapi/pkg/infrastructure/bgorm" | 9 | _ "openapi/pkg/infrastructure/bgorm" |
| 8 | - _ "openapi/pkg/log" | ||
| 9 | _ "openapi/pkg/port/beego" | 10 | _ "openapi/pkg/port/beego" |
| 10 | ) | 11 | ) |
| 11 | 12 | ||
| @@ -14,6 +15,6 @@ func main() { | @@ -14,6 +15,6 @@ func main() { | ||
| 14 | log.Info("server on stop!") | 15 | log.Info("server on stop!") |
| 15 | }() | 16 | }() |
| 16 | log.Info("server on start!") | 17 | log.Info("server on start!") |
| 17 | - constant.DebugConfig() | 18 | + //constant.DebugConfig() |
| 18 | beego.Run() | 19 | beego.Run() |
| 19 | } | 20 | } |
| @@ -32,7 +32,10 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | @@ -32,7 +32,10 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | ||
| 32 | err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectKey)) | 32 | err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectKey)) |
| 33 | return | 33 | return |
| 34 | } | 34 | } |
| 35 | - if deviceList, err = repDevice.Find(map[string]interface{}{"receivers": request.Receivers}); err != nil { | 35 | + if deviceList, err = repDevice.Find( |
| 36 | + map[string]interface{}{ | ||
| 37 | + "receivers": request.Receivers, "project_master_key": appInfo.ProjectMasterKey}, | ||
| 38 | + ); err != nil { | ||
| 36 | log.Error(err) | 39 | log.Error(err) |
| 37 | err = nil | 40 | err = nil |
| 38 | return | 41 | return |
| @@ -117,20 +120,22 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice | @@ -117,20 +120,22 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice | ||
| 117 | ) | 120 | ) |
| 118 | rsp = &protocol.UpdateDeviceResponse{} | 121 | rsp = &protocol.UpdateDeviceResponse{} |
| 119 | rep, _ := repository.NewPushDeviceRepository(nil) | 122 | rep, _ := repository.NewPushDeviceRepository(nil) |
| 120 | - if _, err = rep.FindOne(map[string]interface{}{"uid": request.Muid}); err != nil { | 123 | + |
| 124 | + if _, err = rep.FindOne(map[string]interface{}{ | ||
| 125 | + "uid": request.Muid, | ||
| 126 | + "project_master_key": request.ProjectKey, | ||
| 127 | + }); err != nil { | ||
| 121 | if err == protocol.ERR_DB_NOT_FOUND { | 128 | if err == protocol.ERR_DB_NOT_FOUND { |
| 122 | - err = nil | ||
| 123 | - rep.Save(request) | 129 | + err = rep.Save(request) |
| 130 | + if err != nil { | ||
| 131 | + log.Error(err) | ||
| 132 | + } | ||
| 124 | return | 133 | return |
| 125 | } | 134 | } |
| 126 | log.Error(err) | 135 | log.Error(err) |
| 127 | return | 136 | return |
| 128 | } | 137 | } |
| 129 | - //if device.ClientId == strings.TrimSpace(request.ClientId) && device.DeviceToken == strings.TrimSpace(request.DeviceToken) && device.IsActive==1{ | ||
| 130 | - // err = protocol.NewSuccessWithMessage("更新成功") | ||
| 131 | - // return | ||
| 132 | - //} | ||
| 133 | - if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken); err != nil { | 138 | + if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken, request.ProjectKey); err != nil { |
| 134 | log.Error(err) | 139 | log.Error(err) |
| 135 | } | 140 | } |
| 136 | err = protocol.NewSuccessWithMessage("更新成功") | 141 | err = protocol.NewSuccessWithMessage("更新成功") |
| @@ -31,6 +31,7 @@ type PushInfoRequest struct { | @@ -31,6 +31,7 @@ type PushInfoRequest struct { | ||
| 31 | 31 | ||
| 32 | /*UpdateDevice 更新设备*/ | 32 | /*UpdateDevice 更新设备*/ |
| 33 | type UpdateDeviceRequest struct { | 33 | type UpdateDeviceRequest struct { |
| 34 | + ProjectKey string `json:"projectKey"` //项目编号 | ||
| 34 | Muid int64 `json:"muid" valid:"Required;"` //企业平台中的用户 UID | 35 | Muid int64 `json:"muid" valid:"Required;"` //企业平台中的用户 UID |
| 35 | ClientId string `json:"clientId" valid:"Required"` | 36 | ClientId string `json:"clientId" valid:"Required"` |
| 36 | DeviceToken string `json:"deviceToken"` | 37 | DeviceToken string `json:"deviceToken"` |
| @@ -52,6 +53,7 @@ type AppInfo struct { | @@ -52,6 +53,7 @@ type AppInfo struct { | ||
| 52 | AppKey string | 53 | AppKey string |
| 53 | AppMasterSecret string | 54 | AppMasterSecret string |
| 54 | AppId string | 55 | AppId string |
| 55 | - ProjectName string | ||
| 56 | - ProjectKey string | 56 | + ProjectName string //子项目名称 |
| 57 | + ProjectKey string //包含在主项目内-子项目编码 worth | ||
| 58 | + ProjectMasterKey string //主项目编码 ability | ||
| 57 | } | 59 | } |
| @@ -12,7 +12,7 @@ import ( | @@ -12,7 +12,7 @@ import ( | ||
| 12 | func init() { | 12 | func init() { |
| 13 | aliasName := "default" | 13 | aliasName := "default" |
| 14 | if err := orm.RegisterDataBase(aliasName, "mysql", constant.MYSQL_DATA_SOURCE); err != nil { | 14 | if err := orm.RegisterDataBase(aliasName, "mysql", constant.MYSQL_DATA_SOURCE); err != nil { |
| 15 | - log.Error(fmt.Sprintf("【MYSQL】注册数据库失败:%v source:%v", err, constant.MYSQL_DATA_SOURCE)) | 15 | + log.Error(fmt.Sprintf("【MYSQL】注册数据库失败:%v", err)) |
| 16 | return | 16 | return |
| 17 | } | 17 | } |
| 18 | orm.SetMaxIdleConns(aliasName, constant.MYSQL_MAX_IDLE) | 18 | orm.SetMaxIdleConns(aliasName, constant.MYSQL_MAX_IDLE) |
| @@ -16,6 +16,7 @@ type PushAppInfo struct { | @@ -16,6 +16,7 @@ type PushAppInfo struct { | ||
| 16 | AppId string `orm:"column(app_id);size(255);null" description:"推送应用编号"` | 16 | AppId string `orm:"column(app_id);size(255);null" description:"推送应用编号"` |
| 17 | ProjectName string `orm:"column(project_name);size(255);null" description:"项目名称 能力展示"` | 17 | ProjectName string `orm:"column(project_name);size(255);null" description:"项目名称 能力展示"` |
| 18 | ProjectKey string `orm:"column(project_key);size(255);null" description:"项目唯一标识 ability"` | 18 | ProjectKey string `orm:"column(project_key);size(255);null" description:"项目唯一标识 ability"` |
| 19 | + ProjectMasterKey string `orm:"column(project_master_key);size(50);null" description:"主项目唯一标识 ability"` | ||
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | func (t *PushAppInfo) TableName() string { | 22 | func (t *PushAppInfo) TableName() string { |
| @@ -14,6 +14,7 @@ type PushDeviceInfo struct { | @@ -14,6 +14,7 @@ type PushDeviceInfo struct { | ||
| 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 | IsActive int `orm:"column(is_active);null" description:"是否在活动 1:在线 0:离线(解绑,切换账号)"` |
| 17 | + ProjectMasterKey string `orm:"column(project_master_key);size(50);null" description:"主项目唯一标识 ability"` | ||
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | func (t *PushDeviceInfo) TableName() string { | 20 | func (t *PushDeviceInfo) TableName() string { |
| @@ -35,7 +35,7 @@ func TestGetui(t *testing.T) { | @@ -35,7 +35,7 @@ func TestGetui(t *testing.T) { | ||
| 35 | if err != nil { | 35 | if err != nil { |
| 36 | t.Fatal(err) | 36 | t.Fatal(err) |
| 37 | } | 37 | } |
| 38 | - err = notification.Send(param) | 38 | + _, err = notification.Send(param) |
| 39 | if err != nil { | 39 | if err != nil { |
| 40 | t.Fatal(err) | 40 | t.Fatal(err) |
| 41 | } | 41 | } |
| @@ -72,7 +72,7 @@ func TestGetuiPrd(t *testing.T) { | @@ -72,7 +72,7 @@ func TestGetuiPrd(t *testing.T) { | ||
| 72 | if err != nil { | 72 | if err != nil { |
| 73 | t.Fatal(err) | 73 | t.Fatal(err) |
| 74 | } | 74 | } |
| 75 | - err = notification.Send(param) | 75 | + _, err = notification.Send(param) |
| 76 | if err != nil { | 76 | if err != nil { |
| 77 | t.Fatal(err) | 77 | t.Fatal(err) |
| 78 | } | 78 | } |
| @@ -4,8 +4,11 @@ import ( | @@ -4,8 +4,11 @@ import ( | ||
| 4 | "github.com/astaxie/beego/orm" | 4 | "github.com/astaxie/beego/orm" |
| 5 | "openapi/pkg/domain" | 5 | "openapi/pkg/domain" |
| 6 | "openapi/pkg/infrastructure/bgorm/model" | 6 | "openapi/pkg/infrastructure/bgorm/model" |
| 7 | + "sync" | ||
| 7 | ) | 8 | ) |
| 8 | 9 | ||
| 10 | +var Cache sync.Map | ||
| 11 | + | ||
| 9 | type AppInfoRepository struct { | 12 | type AppInfoRepository struct { |
| 10 | } | 13 | } |
| 11 | 14 | ||
| @@ -17,7 +20,14 @@ func (repository *AppInfoRepository) FindOne(queryOptions map[string]interface{} | @@ -17,7 +20,14 @@ func (repository *AppInfoRepository) FindOne(queryOptions map[string]interface{} | ||
| 17 | if err != nil { | 20 | if err != nil { |
| 18 | return nil, err | 21 | return nil, err |
| 19 | } | 22 | } |
| 20 | - return repository.transformBgormModelToDomainModel(model) | 23 | + var appInfo *domain.AppInfo |
| 24 | + var ok bool | ||
| 25 | + if appInfo, ok = getCache(queryOptions["project_key"]); ok { | ||
| 26 | + return appInfo, nil | ||
| 27 | + } | ||
| 28 | + appInfo, err = repository.transformBgormModelToDomainModel(model) | ||
| 29 | + setCache(queryOptions["project_key"], appInfo) | ||
| 30 | + return appInfo, err | ||
| 21 | } | 31 | } |
| 22 | 32 | ||
| 23 | func (repository *AppInfoRepository) Find(queryOptions map[string]interface{}) (rsp []*domain.AppInfo, err error) { | 33 | func (repository *AppInfoRepository) Find(queryOptions map[string]interface{}) (rsp []*domain.AppInfo, err error) { |
| @@ -32,6 +42,7 @@ func (repository *AppInfoRepository) transformBgormModelToDomainModel(model *mod | @@ -32,6 +42,7 @@ func (repository *AppInfoRepository) transformBgormModelToDomainModel(model *mod | ||
| 32 | AppId: model.AppId, | 42 | AppId: model.AppId, |
| 33 | ProjectName: model.ProjectName, | 43 | ProjectName: model.ProjectName, |
| 34 | ProjectKey: model.ProjectKey, | 44 | ProjectKey: model.ProjectKey, |
| 45 | + ProjectMasterKey: model.ProjectMasterKey, | ||
| 35 | }, nil | 46 | }, nil |
| 36 | } | 47 | } |
| 37 | 48 | ||
| @@ -42,3 +53,20 @@ func NewAppInfoRepository(transactionContext interface{}) (*AppInfoRepository, e | @@ -42,3 +53,20 @@ func NewAppInfoRepository(transactionContext interface{}) (*AppInfoRepository, e | ||
| 42 | return &AppInfoRepository{}, nil | 53 | return &AppInfoRepository{}, nil |
| 43 | } | 54 | } |
| 44 | } | 55 | } |
| 56 | + | ||
| 57 | +//设置缓存 | ||
| 58 | +func setCache(key interface{}, value interface{}) { | ||
| 59 | + Cache.Store(key, value) | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +//设置缓存 | ||
| 63 | +func getCache(key interface{}) (*domain.AppInfo, bool) { | ||
| 64 | + v, ok := Cache.Load(key) | ||
| 65 | + if !ok { | ||
| 66 | + return nil, false | ||
| 67 | + } | ||
| 68 | + if appInfo, ok := v.(*domain.AppInfo); ok { | ||
| 69 | + return appInfo, true | ||
| 70 | + } | ||
| 71 | + return nil, false | ||
| 72 | +} |
| @@ -21,6 +21,7 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) | @@ -21,6 +21,7 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) | ||
| 21 | DeviceToken: strings.TrimSpace(device.DeviceToken), | 21 | DeviceToken: strings.TrimSpace(device.DeviceToken), |
| 22 | CreateAt: time.Now(), | 22 | CreateAt: time.Now(), |
| 23 | UpdateAt: time.Now(), | 23 | UpdateAt: time.Now(), |
| 24 | + ProjectMasterKey: device.ProjectKey, | ||
| 24 | } | 25 | } |
| 25 | _, err := o.Insert(m) | 26 | _, err := o.Insert(m) |
| 26 | return err | 27 | return err |
| @@ -29,7 +30,9 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) | @@ -29,7 +30,9 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) | ||
| 29 | func (repository *PushDeviceRepository) FindOne(queryOptions map[string]interface{}) (*domain.Device, error) { | 30 | func (repository *PushDeviceRepository) FindOne(queryOptions map[string]interface{}) (*domain.Device, error) { |
| 30 | o := orm.NewOrm() | 31 | o := orm.NewOrm() |
| 31 | model := new(models.PushDeviceInfo) | 32 | model := new(models.PushDeviceInfo) |
| 32 | - qs := o.QueryTable(model.TableName()).Filter("uid", queryOptions["uid"]) | 33 | + qs := o.QueryTable(model.TableName()). |
| 34 | + Filter("uid", queryOptions["uid"]). | ||
| 35 | + Filter("project_master_key", queryOptions["project_master_key"]) | ||
| 33 | err := qs.One(model) | 36 | err := qs.One(model) |
| 34 | if err != nil { | 37 | if err != nil { |
| 35 | if err == orm.ErrNoRows { | 38 | if err == orm.ErrNoRows { |
| @@ -44,7 +47,7 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | @@ -44,7 +47,7 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | ||
| 44 | o := orm.NewOrm() | 47 | o := orm.NewOrm() |
| 45 | model := new(models.PushDeviceInfo) | 48 | model := new(models.PushDeviceInfo) |
| 46 | var ms []*models.PushDeviceInfo | 49 | var ms []*models.PushDeviceInfo |
| 47 | - qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"]).Filter("is_active", 1) | 50 | + qs := o.QueryTable(model.TableName()).Filter("uid__in", queryOptions["receivers"]).Filter("is_active", 1).Filter("project_master_key", queryOptions["project_master_key"]) |
| 48 | qs.All(&ms) | 51 | qs.All(&ms) |
| 49 | if len(ms) == 0 { | 52 | if len(ms) == 0 { |
| 50 | return | 53 | return |
| @@ -56,17 +59,17 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | @@ -56,17 +59,17 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | ||
| 56 | return | 59 | return |
| 57 | } | 60 | } |
| 58 | 61 | ||
| 59 | -func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string) error { | 62 | +func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string, projectKey string) error { |
| 60 | o := orm.NewOrm() | 63 | o := orm.NewOrm() |
| 61 | o.Begin() | 64 | o.Begin() |
| 62 | //更新其他绑定这个client_id的设备 is_active=0 | 65 | //更新其他绑定这个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() | 66 | + _, err := o.Raw("UPDATE push_device_info SET update_at=now(),is_active=0 where client_id=? and is_active=1 and project_master_key=?", clientId, projectKey).Exec() |
| 64 | if err != nil { | 67 | if err != nil { |
| 65 | o.Rollback() | 68 | o.Rollback() |
| 66 | return err | 69 | return err |
| 67 | } | 70 | } |
| 68 | 71 | ||
| 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() | 72 | + _, err = o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now(),is_active=1 where uid=? and project_master_key=?", clientId, deviceToken, uid, projectKey).Exec() |
| 70 | if err != nil { | 73 | if err != nil { |
| 71 | o.Rollback() | 74 | o.Rollback() |
| 72 | return err | 75 | return err |
| @@ -74,6 +74,9 @@ func (this *PushController) UpdateDevice() { | @@ -74,6 +74,9 @@ func (this *PushController) UpdateDevice() { | ||
| 74 | msg = m | 74 | msg = m |
| 75 | return | 75 | return |
| 76 | } | 76 | } |
| 77 | + if request.ProjectKey == "" { | ||
| 78 | + request.ProjectKey = "ability" //默认能力展示项目 | ||
| 79 | + } | ||
| 77 | header := controllers.GetRequestHeader(this.Ctx) | 80 | header := controllers.GetRequestHeader(this.Ctx) |
| 78 | msg = protocol.NewReturnResponse(push.UpdateDevice(header, request)) | 81 | msg = protocol.NewReturnResponse(push.UpdateDevice(header, request)) |
| 79 | } | 82 | } |
| @@ -14,6 +14,6 @@ func init() { | @@ -14,6 +14,6 @@ func init() { | ||
| 14 | beego.NSNamespace("vod", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{})), | 14 | beego.NSNamespace("vod", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{})), |
| 15 | beego.NSNamespace("push", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.PushController{})), | 15 | beego.NSNamespace("push", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.PushController{})), |
| 16 | ) | 16 | ) |
| 17 | - beego.SetStaticPath("/log", constant.LogFilePath) | 17 | + beego.SetStaticPath("/log/NIONkenfieldon", constant.LogFilePath) |
| 18 | beego.AddNamespace(nsV1) | 18 | beego.AddNamespace(nsV1) |
| 19 | } | 19 | } |
-
请 注册 或 登录 后发表评论