作者 yangfu

用户信息增加部门列表 职位列表

@@ -81,7 +81,9 @@ func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) { @@ -81,7 +81,9 @@ func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) {
81 sql := ` 81 sql := `
82 select a.department_id,b.name,b.parent_id,b.managers,b.relation,b.create_at create_time 82 select a.department_id,b.name,b.parent_id,b.managers,b.relation,b.create_at create_time
83 from user_department a INNER JOIN department b on a.department_id = b.id 83 from user_department a INNER JOIN department b on a.department_id = b.id
84 -where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0` 84 +where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0
  85 +order by b.parent_id,b.id
  86 +`
85 if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil { 87 if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
86 return 88 return
87 } 89 }
@@ -80,7 +80,9 @@ func GetUserPositions(id int64, companyId int64, v interface{}) (err error) { @@ -80,7 +80,9 @@ func GetUserPositions(id int64, companyId int64, v interface{}) (err error) {
80 sql := ` 80 sql := `
81 select a.position_id,b.name,b.relation,b.create_at create_time 81 select a.position_id,b.name,b.relation,b.create_at create_time
82 from user_position a INNER JOIN position b on a.position_id = b.id 82 from user_position a INNER JOIN position b on a.position_id = b.id
83 -where a.user_company_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1` 83 +where a.user_company_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1
  84 +order by b.parent_id,b.id
  85 +`
84 if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil { 86 if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
85 return 87 return
86 } 88 }
@@ -11,8 +11,8 @@ import ( @@ -11,8 +11,8 @@ import (
11 type UserBaseInfoAggregation struct { 11 type UserBaseInfoAggregation struct {
12 User *models.User 12 User *models.User
13 Company *models.Company 13 Company *models.Company
14 - Department []*Department  
15 - Position []*Position 14 + Departments []*Department
  15 + Positions []*Position
16 UserCompany *models.UserCompany 16 UserCompany *models.UserCompany
17 } 17 }
18 18
@@ -73,9 +73,11 @@ type User struct { @@ -73,9 +73,11 @@ type User struct {
73 ImToken string `json:"imToken"` 73 ImToken string `json:"imToken"`
74 74
75 //companys 75 //companys
76 - CompanyId int `json:"companyId"`  
77 - Company Company `json:"company"` //公司名称  
78 - Companys []Company `json:"companys"` 76 + CompanyId int `json:"companyId"`
  77 + Company Company `json:"company"` //公司名称
  78 + Companys []Company `json:"companys"`
  79 + Departments []Dep `json:"deps"`
  80 + Positions []Job `json:"jobs"`
79 } 81 }
80 82
81 //公司 83 //公司
@@ -40,7 +40,7 @@ func GetUserBaseInfoAggregation(id int64, companyId int64) (v *protocol.UserBase @@ -40,7 +40,7 @@ func GetUserBaseInfoAggregation(id int64, companyId int64) (v *protocol.UserBase
40 40
41 go func() { 41 go func() {
42 defer wg.Done() 42 defer wg.Done()
43 - if err = models.GetUserDepartments(id, companyId, &v.Department); err != nil { 43 + if err = models.GetUserDepartments(id, companyId, &v.Departments); err != nil {
44 log.Error(err) 44 log.Error(err)
45 return 45 return
46 } 46 }
@@ -48,7 +48,7 @@ func GetUserBaseInfoAggregation(id int64, companyId int64) (v *protocol.UserBase @@ -48,7 +48,7 @@ func GetUserBaseInfoAggregation(id int64, companyId int64) (v *protocol.UserBase
48 48
49 go func() { 49 go func() {
50 defer wg.Done() 50 defer wg.Done()
51 - if err = models.GetUserPositions(id, companyId, &v.Position); err != nil { 51 + if err = models.GetUserPositions(id, companyId, &v.Positions); err != nil {
52 log.Error(err) 52 log.Error(err)
53 return 53 return
54 } 54 }
@@ -70,8 +70,8 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err @@ -70,8 +70,8 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err
70 } 70 }
71 71
72 func SetBaseInfoFrom(agg *protocol.UserBaseInfoAggregation) (v *protocol.BaseUserInfo) { 72 func SetBaseInfoFrom(agg *protocol.UserBaseInfoAggregation) (v *protocol.BaseUserInfo) {
73 - dep := GetTopDepartment(agg.Department)  
74 - job := GetTopPosition(agg.Position) 73 + dep := GetTopDepartment(agg.Departments)
  74 + job := GetTopPosition(agg.Positions)
75 v = &protocol.BaseUserInfo{ 75 v = &protocol.BaseUserInfo{
76 UserId: agg.UserCompany.Id, 76 UserId: agg.UserCompany.Id,
77 NickName: agg.User.NickName, 77 NickName: agg.User.NickName,
@@ -326,9 +326,8 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) @@ -326,9 +326,8 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
326 Phone: userBaseAgg.User.Phone, 326 Phone: userBaseAgg.User.Phone,
327 Image: protocol.Picture{ 327 Image: protocol.Picture{
328 Path: userBaseAgg.User.Icon, 328 Path: userBaseAgg.User.Icon,
329 - //TODO:图片裁剪  
330 - H: 0,  
331 - W: 0, 329 + H: 0,
  330 + W: 0,
332 }, 331 },
333 ImToken: userBaseAgg.User.ImToken, 332 ImToken: userBaseAgg.User.ImToken,
334 CompanyId: int(companyId), 333 CompanyId: int(companyId),
@@ -337,6 +336,8 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) @@ -337,6 +336,8 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
337 Name: userBaseAgg.Company.Name, 336 Name: userBaseAgg.Company.Name,
338 CId: userBaseAgg.Company.UserCenterId, 337 CId: userBaseAgg.Company.UserCenterId,
339 }, 338 },
  339 + Departments: make([]protocol.Dep, 0),
  340 + Positions: make([]protocol.Job, 0),
340 }, 341 },
341 } 342 }
342 for i := range companys { 343 for i := range companys {
@@ -346,18 +347,30 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) @@ -346,18 +347,30 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
346 CId: companys[i].UserCenterId, 347 CId: companys[i].UserCenterId,
347 }) 348 })
348 } 349 }
349 - if topDep := agg.GetTopDepartment(userBaseAgg.Department); topDep.DepartmentId != 0 {  
350 - rsp.User.Department = protocol.Dep{  
351 - Id: topDep.DepartmentId,  
352 - Name: topDep.Name, 350 + newDep := func(item *protocol.Department) protocol.Dep {
  351 + return protocol.Dep{
  352 + Id: item.DepartmentId,
  353 + Name: item.Name,
353 } 354 }
354 } 355 }
355 - if topPos := agg.GetTopPosition(userBaseAgg.Position); topPos.PositionId != 0 {  
356 - rsp.User.Position = protocol.Job{  
357 - Id: topPos.PositionId,  
358 - Name: topPos.Name, 356 + newPos := func(item *protocol.Position) protocol.Job {
  357 + return protocol.Job{
  358 + Id: item.PositionId,
  359 + Name: item.Name,
359 } 360 }
360 } 361 }
  362 + for i := range userBaseAgg.Departments {
  363 + rsp.User.Departments = append(rsp.User.Departments, newDep(userBaseAgg.Departments[i]))
  364 + }
  365 + for i := range userBaseAgg.Positions {
  366 + rsp.User.Positions = append(rsp.User.Positions, newPos(userBaseAgg.Positions[i]))
  367 + }
  368 + if topDep := agg.GetTopDepartment(userBaseAgg.Departments); topDep.DepartmentId != 0 {
  369 + rsp.User.Department = newDep(topDep)
  370 + }
  371 + if topPos := agg.GetTopPosition(userBaseAgg.Positions); topPos.PositionId != 0 {
  372 + rsp.User.Position = newPos(topPos)
  373 + }
361 return 374 return
362 } 375 }
363 376