...
|
...
|
@@ -198,13 +198,12 @@ func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanys |
|
|
}
|
|
|
|
|
|
//切换公司
|
|
|
func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) {
|
|
|
func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.UserInfoResponse, err error) {
|
|
|
var (
|
|
|
company *models.UserCompany
|
|
|
userCompany *models.UserCompany
|
|
|
auth *models.UserAuth
|
|
|
)
|
|
|
rsp = &protocol.SwitchCompanyResponse{}
|
|
|
if company, err = repository.UserCompany.GetUserCompanyByUserId(header.Uid, int64(request.CompanyId)); err != nil {
|
|
|
if userCompany, err = repository.UserCompany.GetUserCompanyByUserId(header.Uid, int64(request.CompanyId)); err != nil {
|
|
|
log.Error(err)
|
|
|
err = protocol.NewErrWithMessage(4201) //找不到这家公司
|
|
|
return
|
...
|
...
|
@@ -215,9 +214,16 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa |
|
|
}
|
|
|
if auth.CurrentCompanyId == request.CompanyId {
|
|
|
log.Error(fmt.Sprintf("uid:%v 当前公司已经是:%v", header.Uid, request.CompanyId))
|
|
|
//return
|
|
|
} else {
|
|
|
if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{"CurrentCompanyId": userCompany.CompanyId, "CurrentUserCompanyId": userCompany.Id}); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{"CurrentCompanyId": company.CompanyId, "CurrentCompanyUserId": company.Id}); err != nil {
|
|
|
header.CompanyId = userCompany.CompanyId
|
|
|
header.UserId = userCompany.Id
|
|
|
}
|
|
|
if rsp, err = UserInfo(header, &protocol.UserInfoRequest{}); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -229,51 +235,70 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) |
|
|
var (
|
|
|
companyId = header.CompanyId
|
|
|
userCompany *models.UserCompany
|
|
|
baseInfo *protocol.BaseUserInfo
|
|
|
userAuth *models.UserAuth
|
|
|
user *models.User
|
|
|
userBaseAgg *protocol.UserBaseInfoAggregation
|
|
|
companys []*models.Company
|
|
|
)
|
|
|
|
|
|
if companyId == 0 {
|
|
|
if userCompany, err = models.GetUserCompanyFirst(header.Uid); err != nil {
|
|
|
if userCompany, err = models.GetUserCompanys(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if userAuth, err = models.GetUserAuthByUserId(header.Uid, 1); err != nil {
|
|
|
if companyId == 0 {
|
|
|
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 {
|
|
|
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 user, err = models.GetUsersById(header.Uid); err != nil {
|
|
|
if companys, err = models.GetCompanyByPermission(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if baseInfo, err = agg.GetUserBaseInfo(header.UserId, companyId); err != nil {
|
|
|
log.Error(err)
|
|
|
if userBaseAgg, err = agg.GetUserBaseInfoAggregation(header.UserId, companyId); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.UserInfoResponse{
|
|
|
User: protocol.User{
|
|
|
UserId: baseInfo.UserId,
|
|
|
Name: baseInfo.NickName,
|
|
|
Phone: user.Phone,
|
|
|
UserId: header.UserId,
|
|
|
Name: userBaseAgg.User.NickName,
|
|
|
Phone: userBaseAgg.User.Phone,
|
|
|
Image: protocol.Picture{
|
|
|
Path: user.Icon,
|
|
|
Path: userBaseAgg.User.Icon,
|
|
|
//TODO:图片裁剪
|
|
|
H: 0,
|
|
|
W: 0,
|
|
|
},
|
|
|
Department: baseInfo.Department,
|
|
|
Position: baseInfo.Position,
|
|
|
ImToken: user.ImToken,
|
|
|
ImToken: userBaseAgg.User.ImToken,
|
|
|
CompanyId: int(companyId),
|
|
|
Company: baseInfo.CompanyName,
|
|
|
Company: protocol.Company{
|
|
|
Id: userBaseAgg.Company.Id,
|
|
|
Name: userBaseAgg.Company.Name,
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
for i := range companys {
|
|
|
rsp.User.Companys = append(rsp.User.Companys, protocol.Company{
|
|
|
Id: companys[i].Id,
|
|
|
Name: companys[i].Name,
|
|
|
})
|
|
|
}
|
|
|
if topDep := agg.GetTopDepartment(userBaseAgg.Department); topDep.DepartmentId != 0 {
|
|
|
rsp.User.Department = protocol.Dep{
|
|
|
Id: topDep.DepartmentId,
|
|
|
Name: topDep.Name,
|
|
|
}
|
|
|
}
|
|
|
if topPos := agg.GetTopPosition(userBaseAgg.Position); topPos.PositionId != 0 {
|
|
|
rsp.User.Position = protocol.Job{
|
|
|
Id: topPos.PositionId,
|
|
|
Name: topPos.Name,
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|