作者 yangfu

配置修改

@@ -90,6 +90,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader { @@ -90,6 +90,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
90 h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64) 90 h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64)
91 } 91 }
92 h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-cid"), 10, 64) 92 h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-cid"), 10, 64)
  93 + h.UserId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-id"), 10, 64)
93 log.Debug(common.AssertJson(h)) 94 log.Debug(common.AssertJson(h))
94 return h 95 return h
95 } 96 }
@@ -103,7 +104,7 @@ func FilterComm(ctx *context.Context) { @@ -103,7 +104,7 @@ func FilterComm(ctx *context.Context) {
103 //统计 104 //统计
104 MetricCounter(ctx) 105 MetricCounter(ctx)
105 106
106 - if beego.BConfig.RunMode == "dev" && (ctx.Input.Header("x-mmm-uid")!="" || ctx.Input.Header("uid")!=""){ 107 + if beego.BConfig.RunMode == "dev" && (ctx.Input.Header("x-mmm-uid") != "" || ctx.Input.Header("uid") != "") {
107 return 108 return
108 } 109 }
109 //1.检查签名 110 //1.检查签名
@@ -160,10 +161,10 @@ func CheckToken(ctx *context.Context) (result bool) { @@ -160,10 +161,10 @@ func CheckToken(ctx *context.Context) (result bool) {
160 msg *protocol.ResponseMessage 161 msg *protocol.ResponseMessage
161 ) 162 )
162 token := ctx.Input.Header("x-mmm-accesstoken") 163 token := ctx.Input.Header("x-mmm-accesstoken")
163 - if token==""{ 164 + if token == "" {
164 if strings.HasSuffix(ctx.Request.RequestURI, "login") || 165 if strings.HasSuffix(ctx.Request.RequestURI, "login") ||
165 - strings.HasSuffix(ctx.Request.RequestURI, "accessToken") ||  
166 - strings.HasSuffix(ctx.Request.RequestURI, "refreshToken") { 166 + strings.HasSuffix(ctx.Request.RequestURI, "accessToken") ||
  167 + strings.HasSuffix(ctx.Request.RequestURI, "refreshToken") {
167 return true 168 return true
168 } 169 }
169 } 170 }
@@ -183,6 +184,7 @@ func CheckToken(ctx *context.Context) (result bool) { @@ -183,6 +184,7 @@ func CheckToken(ctx *context.Context) (result bool) {
183 //设置附加数据 184 //设置附加数据
184 ctx.Request.Header.Add("x-mmm-uid", fmt.Sprintf("%v", rsp.UserInfo.UserId)) 185 ctx.Request.Header.Add("x-mmm-uid", fmt.Sprintf("%v", rsp.UserInfo.UserId))
185 ctx.Request.Header.Add("x-mmm-cid", fmt.Sprintf("%v", rsp.UserInfo.CurrentCompanyId)) 186 ctx.Request.Header.Add("x-mmm-cid", fmt.Sprintf("%v", rsp.UserInfo.CurrentCompanyId))
  187 + ctx.Request.Header.Add("x-mmm-id", fmt.Sprintf("%v", rsp.UserInfo.CurrentUserCompanyId))
186 } 188 }
187 } 189 }
188 return 190 return
@@ -11,20 +11,21 @@ import ( @@ -11,20 +11,21 @@ import (
11 ) 11 )
12 12
13 type UserAuth struct { 13 type UserAuth struct {
14 - Id int `orm:"column(id);auto" description:"唯一编号"`  
15 - UserId int64 `orm:"column(user_id)" description:"表user.id "`  
16 - RefreshToken string `orm:"column(refresh_token);size(64)" description:"refresh token "`  
17 - RefreshTokenExp time.Time `orm:"column(refresh_token_exp);type(timestamp)" description:"refresh token 过期时间"`  
18 - AccessToken string `orm:"column(access_token);size(64)" description:"access_token "`  
19 - AccessTokenExp time.Time `orm:"column(access_token_exp);type(timestamp)" description:"access token 过期时间"`  
20 - AuthCode string `orm:"column(auth_code);size(64)" description:"auth_code"`  
21 - AuthCodeExp time.Time `orm:"column(auth_code_exp);type(timestamp)" description:"auth_code过期时间"`  
22 - DeviceType int8 `orm:"column(device_type)" description:"设备类型 0:ios 1:安卓 2:web "`  
23 - ClientId string `orm:"column(client_id);size(100)" description:"设备识别码 推送标识"`  
24 - DeviceToken string `orm:"column(device_token);size(100)" description:"设备识别码 推送标识"`  
25 - CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`  
26 - UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`  
27 - CurrentCompanyId int64 `orm:"column(current_company_id)" description:"当前登录的公司id "` 14 + Id int `orm:"column(id);auto" description:"唯一编号"`
  15 + UserId int64 `orm:"column(user_id)" description:"表user.id "`
  16 + RefreshToken string `orm:"column(refresh_token);size(64)" description:"refresh token "`
  17 + RefreshTokenExp time.Time `orm:"column(refresh_token_exp);type(timestamp)" description:"refresh token 过期时间"`
  18 + AccessToken string `orm:"column(access_token);size(64)" description:"access_token "`
  19 + AccessTokenExp time.Time `orm:"column(access_token_exp);type(timestamp)" description:"access token 过期时间"`
  20 + AuthCode string `orm:"column(auth_code);size(64)" description:"auth_code"`
  21 + AuthCodeExp time.Time `orm:"column(auth_code_exp);type(timestamp)" description:"auth_code过期时间"`
  22 + DeviceType int8 `orm:"column(device_type)" description:"设备类型 0:ios 1:安卓 2:web "`
  23 + ClientId string `orm:"column(client_id);size(100)" description:"设备识别码 推送标识"`
  24 + DeviceToken string `orm:"column(device_token);size(100)" description:"设备识别码 推送标识"`
  25 + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
  26 + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
  27 + CurrentCompanyId int64 `orm:"column(current_company_id)" description:"当前登录的公司id "`
  28 + CurrentUserCompanyId int64 `orm:"column(current_user_company_id)" description:"当前登录的公司 user_company.id "`
28 } 29 }
29 30
30 func (t *UserAuth) TableName() string { 31 func (t *UserAuth) TableName() string {
@@ -180,10 +181,10 @@ func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) { @@ -180,10 +181,10 @@ func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
180 return nil, err 181 return nil, err
181 } 182 }
182 183
183 -func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) { 184 +func GetUserAuthByToken(token string) (v *UserAuth, err error) {
184 o := orm.NewOrm() 185 o := orm.NewOrm()
185 sql := "select * from user_auth where access_token=? and access_token_exp >= Now()" 186 sql := "select * from user_auth where access_token=? and access_token_exp >= Now()"
186 - if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil { 187 + if err = o.Raw(sql, token).QueryRow(&v); err == nil {
187 return v, nil 188 return v, nil
188 } 189 }
189 return nil, err 190 return nil, err
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 ) 8 )
9 9
10 type UserCompany struct { 10 type UserCompany struct {
11 - Id int `orm:"column(id);auto" description:"唯一标识"` 11 + Id int64 `orm:"column(id)" description:"唯一标识"`
12 CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"` 12 CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
13 UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` 13 UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
14 DepartmentId int `orm:"column(department_id)" description:"部门id"` 14 DepartmentId int `orm:"column(department_id)" description:"部门id"`
@@ -37,7 +37,7 @@ func AddUserCompany(m *UserCompany) (id int64, err error) { @@ -37,7 +37,7 @@ func AddUserCompany(m *UserCompany) (id int64, err error) {
37 37
38 // GetUserCompanyById retrieves UserCompany by Id. Returns error if 38 // GetUserCompanyById retrieves UserCompany by Id. Returns error if
39 // Id doesn't exist 39 // Id doesn't exist
40 -func GetUserCompanyById(id int) (v *UserCompany, err error) { 40 +func GetUserCompanyById(id int64) (v *UserCompany, err error) {
41 o := orm.NewOrm() 41 o := orm.NewOrm()
42 v = &UserCompany{Id: id} 42 v = &UserCompany{Id: id}
43 if err = o.Read(v); err == nil { 43 if err = o.Read(v); err == nil {
@@ -63,7 +63,7 @@ func UpdateUserCompanyById(m *UserCompany) (err error) { @@ -63,7 +63,7 @@ func UpdateUserCompanyById(m *UserCompany) (err error) {
63 63
64 // DeleteUserCompany deletes UserCompany by Id and returns error if 64 // DeleteUserCompany deletes UserCompany by Id and returns error if
65 // the record to be deleted doesn't exist 65 // the record to be deleted doesn't exist
66 -func DeleteUserCompany(id int) (err error) { 66 +func DeleteUserCompany(id int64) (err error) {
67 o := orm.NewOrm() 67 o := orm.NewOrm()
68 v := UserCompany{Id: id} 68 v := UserCompany{Id: id}
69 // ascertain id exists in the database 69 // ascertain id exists in the database
@@ -94,4 +94,4 @@ func GetUserCompanyFirst(uid int64) (v *UserCompany, err error) { @@ -94,4 +94,4 @@ func GetUserCompanyFirst(uid int64) (v *UserCompany, err error) {
94 return v, nil 94 return v, nil
95 } 95 }
96 return nil, err 96 return nil, err
97 -}  
  97 +}
@@ -7,8 +7,8 @@ const ( @@ -7,8 +7,8 @@ const (
7 LoginTypeSmdcode = "signInCaptcha" 7 LoginTypeSmdcode = "signInCaptcha"
8 ) 8 )
9 9
10 -const(  
11 - DeviceType =1 10 +const (
  11 + DeviceType = 1
12 ) 12 )
13 13
14 const TokenExpire = 3600 14 const TokenExpire = 3600
@@ -24,8 +24,9 @@ type RequestHeader struct { @@ -24,8 +24,9 @@ type RequestHeader struct {
24 DeviceType int 24 DeviceType int
25 AppProject string 25 AppProject string
26 AccessToken string 26 AccessToken string
27 - Uid int64 27 + Uid int64 //用户基本信息Id
28 CompanyId int64 28 CompanyId int64
  29 + UserId int64 //UserId 唯一标识,唯一关联所有用户信息(=user_company.id)
29 } 30 }
30 31
31 /*Login */ 32 /*Login */
@@ -15,18 +15,18 @@ import ( @@ -15,18 +15,18 @@ import (
15 func GetUserBaseInfoAggregation(uid int64, companyId int64) (v *protocol.UserBaseInfoAggregation, err error) { 15 func GetUserBaseInfoAggregation(uid int64, companyId int64) (v *protocol.UserBaseInfoAggregation, err error) {
16 v = &protocol.UserBaseInfoAggregation{} 16 v = &protocol.UserBaseInfoAggregation{}
17 var wg sync.WaitGroup 17 var wg sync.WaitGroup
18 - if v.User, err = repository.User.GetUsersById(uid); err != nil { 18 + if v.UserCompany, err = models.GetUserCompanyByUserId(uid, companyId); err != nil {
19 log.Error(err) 19 log.Error(err)
20 return 20 return
21 } 21 }
22 - if v.UserCompany, err = repository.UserCompany.GetUserCompanyByUserId(uid, companyId); err != nil { 22 + if v.User, err = models.GetUsersById(v.UserCompany.UserId); err != nil {
23 log.Error(err) 23 log.Error(err)
24 return 24 return
25 } 25 }
26 wg.Add(3) 26 wg.Add(3)
27 go func() { 27 go func() {
28 defer wg.Done() 28 defer wg.Done()
29 - if v.Company, err = repository.Company.GetCompanyById(int64(v.UserCompany.CompanyId)); err != nil { 29 + if v.Company, err = models.GetCompanyById(int64(v.UserCompany.CompanyId)); err != nil {
30 log.Error(err) 30 log.Error(err)
31 return 31 return
32 } 32 }
@@ -34,7 +34,7 @@ func GetUserBaseInfoAggregation(uid int64, companyId int64) (v *protocol.UserBas @@ -34,7 +34,7 @@ func GetUserBaseInfoAggregation(uid int64, companyId int64) (v *protocol.UserBas
34 34
35 go func() { 35 go func() {
36 defer wg.Done() 36 defer wg.Done()
37 - if err = repository.UserDepartment.GetUserDepartment(uid, companyId, &v.Department); err != nil { 37 + if err = models.GetUserDepartments(uid, companyId, &v.Department); err != nil {
38 log.Error(err) 38 log.Error(err)
39 return 39 return
40 } 40 }
@@ -42,7 +42,7 @@ func GetUserBaseInfoAggregation(uid int64, companyId int64) (v *protocol.UserBas @@ -42,7 +42,7 @@ func GetUserBaseInfoAggregation(uid int64, companyId int64) (v *protocol.UserBas
42 42
43 go func() { 43 go func() {
44 defer wg.Done() 44 defer wg.Done()
45 - if err = repository.UserPosition.GetUserPositions(uid, companyId, &v.Position); err != nil { 45 + if err = models.GetUserPositions(uid, companyId, &v.Position); err != nil {
46 log.Error(err) 46 log.Error(err)
47 return 47 return
48 } 48 }
@@ -41,7 +41,7 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) @@ -41,7 +41,7 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
41 } 41 }
42 newComment := &models.Comment{ 42 newComment := &models.Comment{
43 Id: idgen.Next(), 43 Id: idgen.Next(),
44 - UserId: header.Uid, 44 + UserId: header.UserId,
45 SourceType: int8(request.SourceType), 45 SourceType: int8(request.SourceType),
46 Content: request.Content, 46 Content: request.Content,
47 CreateAt: time.Now(), 47 CreateAt: time.Now(),
@@ -74,7 +74,7 @@ func IComments(header *protocol.RequestHeader, request *protocol.ICommentsReques @@ -74,7 +74,7 @@ func IComments(header *protocol.RequestHeader, request *protocol.ICommentsReques
74 baseUserInfo *protocol.BaseUserInfo 74 baseUserInfo *protocol.BaseUserInfo
75 total int 75 total int
76 ) 76 )
77 - if comments, total, err = repository.Comment.GetComments(header.Uid, protocol.SourceType_Chance, 0, request.LastId, request.PageSize); err != nil { 77 + if comments, total, err = repository.Comment.GetComments(header.UserId, protocol.SourceType_Chance, 0, request.LastId, request.PageSize); err != nil {
78 log.Error(err) 78 log.Error(err)
79 return 79 return
80 } 80 }
@@ -112,7 +112,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) @@ -112,7 +112,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
112 total int 112 total int
113 exists bool 113 exists bool
114 ) 114 )
115 - if comments, total, err = repository.Comment.GetComments(header.Uid, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil { 115 + if comments, total, err = repository.Comment.GetComments(header.UserId, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil {
116 log.Error(err) 116 log.Error(err)
117 return 117 return
118 } 118 }
@@ -134,7 +134,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) @@ -134,7 +134,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
134 ZanTotal: comment.ZanTotal, 134 ZanTotal: comment.ZanTotal,
135 CommentTotal: comment.CommentTotal, 135 CommentTotal: comment.CommentTotal,
136 } 136 }
137 - if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.Uid, header.CompanyId, comment.Id, protocol.MarkFlag_Zan); exists { 137 + if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlag_Zan); exists {
138 item.IsZan = 1 138 item.IsZan = 1
139 } 139 }
140 rsp.Comments = append(rsp.Comments, item) 140 rsp.Comments = append(rsp.Comments, item)
@@ -167,7 +167,7 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm @@ -167,7 +167,7 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm
167 ZanTotal: comment.ZanTotal, 167 ZanTotal: comment.ZanTotal,
168 CommentTotal: comment.CommentTotal, 168 CommentTotal: comment.CommentTotal,
169 } 169 }
170 - if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.Uid, header.CompanyId, comment.Id, protocol.MarkFlag_Zan); exists { 170 + if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlag_Zan); exists {
171 rsp.Comment.IsZan = 1 171 rsp.Comment.IsZan = 1
172 } 172 }
173 return 173 return
@@ -183,15 +183,15 @@ func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanys @@ -183,15 +183,15 @@ func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanys
183 companys []*models.Company 183 companys []*models.Company
184 ) 184 )
185 rsp = &protocol.UserCompanysResponse{} 185 rsp = &protocol.UserCompanysResponse{}
186 - if companys,err =models.GetCompanyByPermission(header.Uid);err!=nil{ 186 + if companys, err = models.GetCompanyByPermission(header.Uid); err != nil {
187 log.Error(err) 187 log.Error(err)
188 err = protocol.NewErrWithMessage(4201) //找不到这家公司 188 err = protocol.NewErrWithMessage(4201) //找不到这家公司
189 return 189 return
190 } 190 }
191 - for i:=range companys{  
192 - rsp.Companys =append(rsp.Companys,protocol.Company{  
193 - Id:companys[i].Id,  
194 - Name:companys[i].Name, 191 + for i := range companys {
  192 + rsp.Companys = append(rsp.Companys, protocol.Company{
  193 + Id: companys[i].Id,
  194 + Name: companys[i].Name,
195 }) 195 })
196 } 196 }
197 return 197 return
@@ -213,11 +213,11 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa @@ -213,11 +213,11 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
213 log.Error(err) 213 log.Error(err)
214 return 214 return
215 } 215 }
216 - if auth.CurrentCompanyId == request.CompanyId{  
217 - log.Error(fmt.Sprintf("uid:%v 当前公司已经是:%v",header.Uid,request.CompanyId)) 216 + if auth.CurrentCompanyId == request.CompanyId {
  217 + log.Error(fmt.Sprintf("uid:%v 当前公司已经是:%v", header.Uid, request.CompanyId))
218 return 218 return
219 } 219 }
220 - if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{"CurrentCompanyId": company.CompanyId}); err != nil { 220 + if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{"CurrentCompanyId": company.CompanyId, "CurrentCompanyUserId": company.Id}); err != nil {
221 log.Error(err) 221 log.Error(err)
222 return 222 return
223 } 223 }
@@ -227,15 +227,15 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa @@ -227,15 +227,15 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
227 //用户信息 227 //用户信息
228 func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) { 228 func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
229 var ( 229 var (
230 - companyId = header.CompanyId  
231 - company *models.UserCompany  
232 - baseInfo *protocol.BaseUserInfo  
233 - userAuth *models.UserAuth  
234 - user *models.User 230 + companyId = header.CompanyId
  231 + userCompany *models.UserCompany
  232 + baseInfo *protocol.BaseUserInfo
  233 + userAuth *models.UserAuth
  234 + user *models.User
235 ) 235 )
236 236
237 if companyId == 0 { 237 if companyId == 0 {
238 - if company, err = models.GetUserCompanyFirst(header.Uid); err != nil { 238 + if userCompany, err = models.GetUserCompanyFirst(header.Uid); err != nil {
239 log.Error(err) 239 log.Error(err)
240 return 240 return
241 } 241 }
@@ -243,17 +243,17 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) @@ -243,17 +243,17 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
243 log.Error(err) 243 log.Error(err)
244 return 244 return
245 } 245 }
246 - if err = utils.UpdateTableByMap(&models.UserAuth{Id: userAuth.Id}, map[string]interface{}{"CurrentCompanyId": companyId}); err != nil { 246 + if err = utils.UpdateTableByMap(&models.UserAuth{Id: userAuth.Id}, map[string]interface{}{"CurrentCompanyId": userCompany.CompanyId, "CurrentUserCompanyId": userCompany.Id}); err != nil {
247 log.Error(err) 247 log.Error(err)
248 return 248 return
249 } 249 }
250 - companyId = int64(company.Id) 250 + companyId = int64(userCompany.CompanyId)
251 } 251 }
252 if user, err = models.GetUsersById(header.Uid); err != nil { 252 if user, err = models.GetUsersById(header.Uid); err != nil {
253 log.Error(err) 253 log.Error(err)
254 return 254 return
255 } 255 }
256 - if baseInfo, err = agg.GetUserBaseInfo(header.Uid, companyId); err != nil { 256 + if baseInfo, err = agg.GetUserBaseInfo(header.UserId, companyId); err != nil {
257 log.Error(err) 257 log.Error(err)
258 return 258 return
259 } 259 }