...
|
...
|
@@ -248,6 +248,10 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa |
|
|
err = protocol.NewErrWithMessage(4201) //找不到这家公司
|
|
|
return
|
|
|
}
|
|
|
if hasAuth := agg.CheckUserModuleAuth(userCompany.Id); !hasAuth {
|
|
|
err = protocol.NewErrWithMessage(2002) //找不到这家公司
|
|
|
return
|
|
|
}
|
|
|
if auth, err = models.GetUserAuthByUserId(header.Uid, protocol.DeviceType); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
...
|
...
|
@@ -372,6 +376,130 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) |
|
|
return
|
|
|
}
|
|
|
|
|
|
//用户信息
|
|
|
func UserInfoV3(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
|
|
|
var (
|
|
|
companyId int64
|
|
|
userCompany *models.UserCompany
|
|
|
userAuth *models.UserAuth
|
|
|
userBaseAgg *protocol.UserBaseInfoAggregation
|
|
|
companys []*models.Company
|
|
|
userCompanys []*models.UserCompany
|
|
|
tmpCompanys []*models.Company = make([]*models.Company, 0)
|
|
|
defaultUserId int64
|
|
|
)
|
|
|
if companys, err = models.GetCompanyByPermission(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if userCompanys, err = models.GetUserAllCompany(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
for i := range userCompanys {
|
|
|
if hasAuth := agg.CheckUserModuleAuth(userCompanys[i].Id); !hasAuth {
|
|
|
log.Debug("检查公司权限:", userCompanys[i].Id, userCompanys[i].CompanyId, "无模块权限")
|
|
|
continue
|
|
|
}
|
|
|
if companyId == 0 { //取默认一个有权限的公司
|
|
|
companyId = userCompanys[i].CompanyId
|
|
|
defaultUserId = userCompanys[i].Id
|
|
|
}
|
|
|
for j := 0; j < len(companys); j++ {
|
|
|
if userCompanys[i].CompanyId == companys[j].Id {
|
|
|
tmpCompanys = append(tmpCompanys, companys[j])
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if userCompanys[i].Id == header.UserId && userCompanys[i].CompanyId == header.CompanyId {
|
|
|
companyId = header.CompanyId
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
//公司列表是所有有权限的公司,企业平台
|
|
|
companys = tmpCompanys
|
|
|
if len(companys) == 0 {
|
|
|
err = protocol.NewErrWithMessage(2002, err) //账号不存在
|
|
|
return
|
|
|
}
|
|
|
if companyId == 0 {
|
|
|
if userCompany, err = models.GetUserCompanysFirst(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if userAuth, err = models.GetUserAuthByUserId(header.Uid, protocol.DeviceType); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(&models.UserAuth{Id: userAuth.Id}, map[string]interface{}{
|
|
|
"CurrentCompanyId": userCompany.CompanyId, "CurrentUserCompanyId": userCompany.Id}); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
companyId = int64(userCompany.CompanyId)
|
|
|
header.UserId = userCompany.Id
|
|
|
}
|
|
|
if header.UserId == 0 {
|
|
|
header.UserId = defaultUserId
|
|
|
}
|
|
|
if userBaseAgg, err = agg.GetUserBaseInfoAggregation(header.UserId, companyId); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.UserInfoResponse{
|
|
|
User: protocol.User{
|
|
|
UserId: header.UserId,
|
|
|
Name: userBaseAgg.User.NickName,
|
|
|
Phone: userBaseAgg.User.Phone,
|
|
|
Image: protocol.Picture{
|
|
|
Path: userBaseAgg.User.Icon,
|
|
|
H: 0,
|
|
|
W: 0,
|
|
|
},
|
|
|
ImToken: userBaseAgg.User.ImToken,
|
|
|
CompanyId: int(companyId),
|
|
|
Company: protocol.Company{
|
|
|
Id: userBaseAgg.Company.Id,
|
|
|
Name: userBaseAgg.Company.Name,
|
|
|
CId: userBaseAgg.Company.UserCenterId,
|
|
|
},
|
|
|
Departments: make([]protocol.Dep, 0),
|
|
|
Positions: make([]protocol.Job, 0),
|
|
|
},
|
|
|
}
|
|
|
for i := range companys {
|
|
|
rsp.User.Companys = append(rsp.User.Companys, protocol.Company{
|
|
|
Id: companys[i].Id,
|
|
|
Name: companys[i].Name,
|
|
|
CId: companys[i].UserCenterId,
|
|
|
})
|
|
|
}
|
|
|
newDep := func(item *protocol.Department) protocol.Dep {
|
|
|
return protocol.Dep{
|
|
|
Id: item.DepartmentId,
|
|
|
Name: item.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
|
|
|
}
|
|
|
|
|
|
//用户中心-统计信息
|
|
|
func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatisticsRequest) (rsp *protocol.UserStatisticsResponse, err error) {
|
|
|
var (
|
...
|
...
|
|