作者 yangfu

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

... ... @@ -81,7 +81,9 @@ func GetUserDepartments(id int64, companyId int64, v interface{}) (err error) {
sql := `
select a.department_id,b.name,b.parent_id,b.managers,b.relation,b.create_at create_time
from user_department a INNER JOIN department b on a.department_id = b.id
where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0`
where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0
order by b.parent_id,b.id
`
if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
return
}
... ...
... ... @@ -80,7 +80,9 @@ func GetUserPositions(id int64, companyId int64, v interface{}) (err error) {
sql := `
select a.position_id,b.name,b.relation,b.create_at create_time
from user_position a INNER JOIN position b on a.position_id = b.id
where a.user_company_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1`
where a.user_company_id =? and a.company_id =? and a.enable_status =1 and b.enable_status =1
order by b.parent_id,b.id
`
if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
return
}
... ...
... ... @@ -11,8 +11,8 @@ import (
type UserBaseInfoAggregation struct {
User *models.User
Company *models.Company
Department []*Department
Position []*Position
Departments []*Department
Positions []*Position
UserCompany *models.UserCompany
}
... ...
... ... @@ -73,9 +73,11 @@ type User struct {
ImToken string `json:"imToken"`
//companys
CompanyId int `json:"companyId"`
Company Company `json:"company"` //公司名称
Companys []Company `json:"companys"`
CompanyId int `json:"companyId"`
Company Company `json:"company"` //公司名称
Companys []Company `json:"companys"`
Departments []Dep `json:"deps"`
Positions []Job `json:"jobs"`
}
//公司
... ...
... ... @@ -40,7 +40,7 @@ func GetUserBaseInfoAggregation(id int64, companyId int64) (v *protocol.UserBase
go func() {
defer wg.Done()
if err = models.GetUserDepartments(id, companyId, &v.Department); err != nil {
if err = models.GetUserDepartments(id, companyId, &v.Departments); err != nil {
log.Error(err)
return
}
... ... @@ -48,7 +48,7 @@ func GetUserBaseInfoAggregation(id int64, companyId int64) (v *protocol.UserBase
go func() {
defer wg.Done()
if err = models.GetUserPositions(id, companyId, &v.Position); err != nil {
if err = models.GetUserPositions(id, companyId, &v.Positions); err != nil {
log.Error(err)
return
}
... ... @@ -70,8 +70,8 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err
}
func SetBaseInfoFrom(agg *protocol.UserBaseInfoAggregation) (v *protocol.BaseUserInfo) {
dep := GetTopDepartment(agg.Department)
job := GetTopPosition(agg.Position)
dep := GetTopDepartment(agg.Departments)
job := GetTopPosition(agg.Positions)
v = &protocol.BaseUserInfo{
UserId: agg.UserCompany.Id,
NickName: agg.User.NickName,
... ...
... ... @@ -326,9 +326,8 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
Phone: userBaseAgg.User.Phone,
Image: protocol.Picture{
Path: userBaseAgg.User.Icon,
//TODO:图片裁剪
H: 0,
W: 0,
H: 0,
W: 0,
},
ImToken: userBaseAgg.User.ImToken,
CompanyId: int(companyId),
... ... @@ -337,6 +336,8 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
Name: userBaseAgg.Company.Name,
CId: userBaseAgg.Company.UserCenterId,
},
Departments: make([]protocol.Dep, 0),
Positions: make([]protocol.Job, 0),
},
}
for i := range companys {
... ... @@ -346,18 +347,30 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
CId: companys[i].UserCenterId,
})
}
if topDep := agg.GetTopDepartment(userBaseAgg.Department); topDep.DepartmentId != 0 {
rsp.User.Department = protocol.Dep{
Id: topDep.DepartmentId,
Name: topDep.Name,
newDep := func(item *protocol.Department) protocol.Dep {
return protocol.Dep{
Id: item.DepartmentId,
Name: item.Name,
}
}
if topPos := agg.GetTopPosition(userBaseAgg.Position); topPos.PositionId != 0 {
rsp.User.Position = protocol.Job{
Id: topPos.PositionId,
Name: topPos.Name,
newPos := func(item *protocol.Position) protocol.Job {
return protocol.Job{
Id: item.PositionId,
Name: item.Name,
}
}
for i := range userBaseAgg.Departments {
rsp.User.Departments = append(rsp.User.Departments, newDep(userBaseAgg.Departments[i]))
}
for i := range userBaseAgg.Positions {
rsp.User.Positions = append(rsp.User.Positions, newPos(userBaseAgg.Positions[i]))
}
if topDep := agg.GetTopDepartment(userBaseAgg.Departments); topDep.DepartmentId != 0 {
rsp.User.Department = newDep(topDep)
}
if topPos := agg.GetTopPosition(userBaseAgg.Positions); topPos.PositionId != 0 {
rsp.User.Position = newPos(topPos)
}
return
}
... ...