...
|
...
|
@@ -4,6 +4,7 @@ import ( |
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -53,7 +54,7 @@ func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface |
|
|
"companyId": company.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据失败")
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户数据失败")
|
|
|
}
|
|
|
if user.Status != domain.UserStatusEnable {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户被禁用")
|
...
|
...
|
@@ -81,9 +82,8 @@ func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
//手机端登录 ,来源于能力展示app
|
|
|
|
|
|
func (service *AuthService) MobileLogin(param command.AuthorizeCommand) (map[string]interface{}, error) {
|
|
|
// 员工绩效 手机端登录,来源于能力展示app
|
|
|
func (service *AuthService) MobileLogin(param *command.MobileLoginCommand) (map[string]interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -94,13 +94,61 @@ func (service *AuthService) MobileLogin(param command.AuthorizeCommand) (map[str |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 统一用户中心登录
|
|
|
authCodeReply, err := factory.UCenterApi().AppAuthCode(param.Credentials, param.Cuid, param.Cid)
|
|
|
if err != nil || !authCodeReply.IsOk() {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统一用户中心认证失败")
|
|
|
}
|
|
|
// 用户权限校验
|
|
|
// 登录平台ID,28-绩效管理后台 29-员工绩效
|
|
|
userAuthReply, err := factory.BusinessAdminApi().GetUserAuth(authCodeReply.Data.MUid, constant.IdPlatformUser)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户鉴权失败")
|
|
|
}
|
|
|
if !userAuthReply.IsOk() {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, userAuthReply.Message())
|
|
|
}
|
|
|
//获取公司数据
|
|
|
companyRepository := factory.CreateCompanyRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
company, err := companyRepository.FindOne(map[string]interface{}{
|
|
|
"id": authCodeReply.Data.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据失败")
|
|
|
}
|
|
|
userRepository := factory.CreateUserRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
user, err := userRepository.FindOne(map[string]interface{}{
|
|
|
"id": authCodeReply.Data.MUid,
|
|
|
"companyId": company.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户数据失败")
|
|
|
}
|
|
|
if user.Status != domain.UserStatusEnable {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户被禁用")
|
|
|
}
|
|
|
userAuth := &domain.UserAuth{
|
|
|
UserId: user.Id,
|
|
|
CompanyId: user.CompanyId,
|
|
|
Phone: user.Account,
|
|
|
PlatformId: constant.IdPlatformUser,
|
|
|
Name: user.Name,
|
|
|
AdminType: user.AdminType,
|
|
|
}
|
|
|
accessToken, err := userAuth.CreateAccessToken()
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
result := map[string]interface{}{
|
|
|
"access": map[string]interface{}{
|
|
|
"accessToken": "",
|
|
|
"accessToken": accessToken,
|
|
|
"expiresIn": domain.JWTExpiresSecond,
|
|
|
},
|
|
|
}
|
...
|
...
|
|