...
|
...
|
@@ -5,6 +5,7 @@ import ( |
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/query"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/serviceGateway"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
...
|
...
|
@@ -56,8 +57,8 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom |
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//检索本系统的公司数据判断公司权限
|
|
|
companyData, err = companyRespository.FindOne(map[string]interface{}{
|
|
|
"Id": loginResp.Data.Muid,
|
|
|
companyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
|
|
|
Id: loginResp.Data.Muid,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取公司(id=%d)数据失败:%s", loginResp.Data.Muid, err.Error())
|
...
|
...
|
@@ -67,9 +68,9 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom |
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限")
|
|
|
}
|
|
|
//检索本系统的用户数据
|
|
|
usersData, err = userRespository.FindOne(map[string]interface{}{
|
|
|
"OpenId": loginResp.Data.Id,
|
|
|
"CompanyId": companyData.Id,
|
|
|
usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
|
|
|
OpenId: loginResp.Data.Id,
|
|
|
CompanyId: companyData.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取用户(OpenId=%d;CompanyId=%d)数据失败:%s",
|
...
|
...
|
@@ -81,17 +82,136 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom |
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "用户被禁用")
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
newJwt := lib.NewMyToken(usersData.Id, usersData.Id)
|
|
|
newToken, err := newJwt.CreateJWTToken()
|
|
|
//生成token
|
|
|
|
|
|
return nil, nil
|
|
|
returnData := map[string]interface{}{
|
|
|
"access": map[string]interface{}{
|
|
|
"accessToken": newToken,
|
|
|
"expiresIn": lib.JWtExpiresSecond,
|
|
|
},
|
|
|
}
|
|
|
return returnData, nil
|
|
|
}
|
|
|
|
|
|
//GetAdminpPofile 登录后获取用户的权限配置数据
|
|
|
func (service UsersService) GetAdminpPofile() (interface{}, error) {
|
|
|
return nil, nil
|
|
|
func (service UsersService) GetUserPofile(userId int64) (interface{}, error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
userRespository domain.UsersRepository
|
|
|
usersData domain.Users
|
|
|
permissionRepository domain.AdminPermissionRepository
|
|
|
permissionList []domain.AdminPermission
|
|
|
)
|
|
|
if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
|
|
|
Id: userId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取用户(Id=%d)数据失败:%s",
|
|
|
userId, err.Error())
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
var permissionQuery domain.PermissionFindOption
|
|
|
permissionList, err = permissionRepository.Find(permissionQuery)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
returnData := service.buildUserPofile(usersData, permissionList)
|
|
|
return returnData, nil
|
|
|
}
|
|
|
|
|
|
//buildUserPofile 组装前端需要的数据 ,用户登录后获取的配置
|
|
|
func (service UsersService) buildUserPofile(userData domain.Users, permissionList []domain.AdminPermission) map[string]interface{} {
|
|
|
menus := make([]map[string]interface{}, len(permissionList))
|
|
|
for _, v := range permissionList {
|
|
|
m := map[string]interface{}{
|
|
|
"code": v.Code,
|
|
|
"icon": v.Icon,
|
|
|
"parentId": v.ParentId,
|
|
|
"sort": v.Sort,
|
|
|
"name": v.Name,
|
|
|
"id": v.Id,
|
|
|
"status": 0, //状态 1-启用 0-禁用,前端需要
|
|
|
}
|
|
|
for _, p := range userData.Permission {
|
|
|
if p.Id == v.Id {
|
|
|
m["status"] = 1
|
|
|
break
|
|
|
}
|
|
|
if p.Id == v.ParentId {
|
|
|
m["status"] = 1
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
menus = append(menus, m)
|
|
|
}
|
|
|
user := map[string]string{
|
|
|
"id": fmt.Sprint(userData.Id),
|
|
|
"name": userData.Name,
|
|
|
"adminType": "2", // 前端需要的管理员类型 1-超级管理员 2-子管理员
|
|
|
}
|
|
|
if userData.IsSuperAdmin() {
|
|
|
user["adminType"] = "1"
|
|
|
}
|
|
|
respData := map[string]interface{}{
|
|
|
"user": user,
|
|
|
"menus": menus,
|
|
|
}
|
|
|
return respData
|
|
|
}
|
|
|
|
|
|
//ValidateAdminpPermission 校验用户的操作权限
|
|
|
func (service UsersService) ValidateAdminpPermission() (interface{}, error) {
|
|
|
return nil, nil
|
|
|
func (service UsersService) ValidateAdminpPermission(queryOption query.ValidatePermissionQuery) (bool, error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return false, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
userRespository domain.UsersRepository
|
|
|
usersData domain.Users
|
|
|
)
|
|
|
|
|
|
if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return false, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
|
|
|
Id: queryOption.UserId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return false, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if !usersData.IsUsable() {
|
|
|
return false, nil
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
ok := usersData.HasPermissionByCode(queryOption.PermissionCode)
|
|
|
return ok, nil
|
|
|
} |
...
|
...
|
|