作者 唐旭辉

登录相关 完成

@@ -39,7 +39,7 @@ func (adminPermissionSrv AdminPermissionService) ListAdminPermission(queryOption @@ -39,7 +39,7 @@ func (adminPermissionSrv AdminPermissionService) ListAdminPermission(queryOption
39 } else { 39 } else {
40 permissionRepository = value 40 permissionRepository = value
41 } 41 }
42 - permissions, err = permissionRepository.Find(map[string]interface{}{}) 42 + permissions, err = permissionRepository.Find(domain.PermissionFindOption{})
43 if err != nil { 43 if err != nil {
44 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 44 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
45 } 45 }
@@ -13,7 +13,7 @@ type SaveAdminUserCommand struct { @@ -13,7 +13,7 @@ type SaveAdminUserCommand struct {
13 //密码 13 //密码
14 Password string `json:"password"` 14 Password string `json:"password"`
15 // 员工角色 15 // 员工角色
16 - PermissionId []int `json:"PermissionId"` 16 + PermissionId []int64 `json:"PermissionId"`
17 17
18 IsUsable bool `json:"isUsable"` 18 IsUsable bool `json:"isUsable"`
19 } 19 }
@@ -87,8 +87,8 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi @@ -87,8 +87,8 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi
87 } else { 87 } else {
88 permissionRepository = value 88 permissionRepository = value
89 } 89 }
90 - permissions, err = permissionRepository.Find(map[string]interface{}{  
91 - "IdsIn": saveUserCmd.PermissionId, 90 + permissions, err = permissionRepository.Find(domain.PermissionFindOption{
  91 + Ids: saveUserCmd.PermissionId,
92 }) 92 })
93 if err != nil { 93 if err != nil {
94 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 94 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  1 +package query
  2 +
  3 +type ValidatePermissionQuery struct {
  4 + PermissionCode string
  5 + UserId int64
  6 + CompanyId int64
  7 +}
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 5
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/query"
8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/serviceGateway" 10 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/serviceGateway"
10 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 11 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
@@ -56,8 +57,8 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom @@ -56,8 +57,8 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom
56 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 57 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
57 } 58 }
58 //检索本系统的公司数据判断公司权限 59 //检索本系统的公司数据判断公司权限
59 - companyData, err = companyRespository.FindOne(map[string]interface{}{  
60 - "Id": loginResp.Data.Muid, 60 + companyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
  61 + Id: loginResp.Data.Muid,
61 }) 62 })
62 if err != nil { 63 if err != nil {
63 e := fmt.Sprintf("获取公司(id=%d)数据失败:%s", loginResp.Data.Muid, err.Error()) 64 e := fmt.Sprintf("获取公司(id=%d)数据失败:%s", loginResp.Data.Muid, err.Error())
@@ -67,9 +68,9 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom @@ -67,9 +68,9 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom
67 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限") 68 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限")
68 } 69 }
69 //检索本系统的用户数据 70 //检索本系统的用户数据
70 - usersData, err = userRespository.FindOne(map[string]interface{}{  
71 - "OpenId": loginResp.Data.Id,  
72 - "CompanyId": companyData.Id, 71 + usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
  72 + OpenId: loginResp.Data.Id,
  73 + CompanyId: companyData.Id,
73 }) 74 })
74 if err != nil { 75 if err != nil {
75 e := fmt.Sprintf("获取用户(OpenId=%d;CompanyId=%d)数据失败:%s", 76 e := fmt.Sprintf("获取用户(OpenId=%d;CompanyId=%d)数据失败:%s",
@@ -81,17 +82,136 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom @@ -81,17 +82,136 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom
81 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "用户被禁用") 82 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "用户被禁用")
82 } 83 }
83 err = transactionContext.CommitTransaction() 84 err = transactionContext.CommitTransaction()
  85 + newJwt := lib.NewMyToken(usersData.Id, usersData.Id)
  86 + newToken, err := newJwt.CreateJWTToken()
84 //生成token 87 //生成token
85 -  
86 - return nil, nil 88 + returnData := map[string]interface{}{
  89 + "access": map[string]interface{}{
  90 + "accessToken": newToken,
  91 + "expiresIn": lib.JWtExpiresSecond,
  92 + },
  93 + }
  94 + return returnData, nil
87 } 95 }
88 96
89 //GetAdminpPofile 登录后获取用户的权限配置数据 97 //GetAdminpPofile 登录后获取用户的权限配置数据
90 -func (service UsersService) GetAdminpPofile() (interface{}, error) {  
91 - return nil, nil 98 +func (service UsersService) GetUserPofile(userId int64) (interface{}, error) {
  99 + var (
  100 + transactionContext, _ = factory.CreateTransactionContext(nil)
  101 + err error
  102 + )
  103 + if err = transactionContext.StartTransaction(); err != nil {
  104 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  105 + }
  106 + defer func() {
  107 + transactionContext.RollbackTransaction()
  108 + }()
  109 + var (
  110 + userRespository domain.UsersRepository
  111 + usersData domain.Users
  112 + permissionRepository domain.AdminPermissionRepository
  113 + permissionList []domain.AdminPermission
  114 + )
  115 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  116 + "transactionContext": transactionContext,
  117 + }); err != nil {
  118 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  119 + }
  120 + if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
  121 + "transactionContext": transactionContext,
  122 + }); err != nil {
  123 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  124 + }
  125 + usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
  126 + Id: userId,
  127 + })
  128 + if err != nil {
  129 + e := fmt.Sprintf("获取用户(Id=%d)数据失败:%s",
  130 + userId, err.Error())
  131 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  132 + }
  133 + var permissionQuery domain.PermissionFindOption
  134 + permissionList, err = permissionRepository.Find(permissionQuery)
  135 + if err != nil {
  136 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  137 + }
  138 + err = transactionContext.CommitTransaction()
  139 + returnData := service.buildUserPofile(usersData, permissionList)
  140 + return returnData, nil
  141 +}
  142 +
  143 +//buildUserPofile 组装前端需要的数据 ,用户登录后获取的配置
  144 +func (service UsersService) buildUserPofile(userData domain.Users, permissionList []domain.AdminPermission) map[string]interface{} {
  145 + menus := make([]map[string]interface{}, len(permissionList))
  146 + for _, v := range permissionList {
  147 + m := map[string]interface{}{
  148 + "code": v.Code,
  149 + "icon": v.Icon,
  150 + "parentId": v.ParentId,
  151 + "sort": v.Sort,
  152 + "name": v.Name,
  153 + "id": v.Id,
  154 + "status": 0, //状态 1-启用 0-禁用,前端需要
  155 + }
  156 + for _, p := range userData.Permission {
  157 + if p.Id == v.Id {
  158 + m["status"] = 1
  159 + break
  160 + }
  161 + if p.Id == v.ParentId {
  162 + m["status"] = 1
  163 + break
  164 + }
  165 + }
  166 + menus = append(menus, m)
  167 + }
  168 + user := map[string]string{
  169 + "id": fmt.Sprint(userData.Id),
  170 + "name": userData.Name,
  171 + "adminType": "2", // 前端需要的管理员类型 1-超级管理员 2-子管理员
  172 + }
  173 + if userData.IsSuperAdmin() {
  174 + user["adminType"] = "1"
  175 + }
  176 + respData := map[string]interface{}{
  177 + "user": user,
  178 + "menus": menus,
  179 + }
  180 + return respData
92 } 181 }
93 182
94 //ValidateAdminpPermission 校验用户的操作权限 183 //ValidateAdminpPermission 校验用户的操作权限
95 -func (service UsersService) ValidateAdminpPermission() (interface{}, error) {  
96 - return nil, nil 184 +func (service UsersService) ValidateAdminpPermission(queryOption query.ValidatePermissionQuery) (bool, error) {
  185 + var (
  186 + transactionContext, _ = factory.CreateTransactionContext(nil)
  187 + err error
  188 + )
  189 + if err = transactionContext.StartTransaction(); err != nil {
  190 + return false, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  191 + }
  192 + defer func() {
  193 + transactionContext.RollbackTransaction()
  194 + }()
  195 + var (
  196 + userRespository domain.UsersRepository
  197 + usersData domain.Users
  198 + )
  199 +
  200 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  201 + "transactionContext": transactionContext,
  202 + }); err != nil {
  203 + return false, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  204 + }
  205 + usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
  206 + Id: queryOption.UserId,
  207 + })
  208 + if err != nil {
  209 + return false, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  210 + }
  211 + if !usersData.IsUsable() {
  212 + return false, nil
  213 + }
  214 + err = transactionContext.CommitTransaction()
  215 + ok := usersData.HasPermissionByCode(queryOption.PermissionCode)
  216 + return ok, nil
97 } 217 }
@@ -12,20 +12,30 @@ const ( @@ -12,20 +12,30 @@ const (
12 ) 12 )
13 13
14 type AdminPermissionBase struct { 14 type AdminPermissionBase struct {
15 - Id int `json:"id"` 15 + Id int64 `json:"id"`
16 Code string `json:"code"` 16 Code string `json:"code"`
17 } 17 }
18 18
19 // 权限结构 19 // 权限结构
20 type AdminPermission struct { 20 type AdminPermission struct {
21 - Id int `json:"id"`  
22 - ParentId int `json:"parentId"` 21 + Id int64 `json:"id"`
  22 + ParentId int64 `json:"parentId"`
23 Code string `json:"code"` 23 Code string `json:"code"`
24 Name string `json:"name"` 24 Name string `json:"name"`
25 Sort int `json:"sort"` 25 Sort int `json:"sort"`
26 Icon string `json:"icon"` 26 Icon string `json:"icon"`
27 } 27 }
28 28
  29 +type PermissionFindOption struct {
  30 + Ids []int64
  31 +}
  32 +
  33 +type PermissionFindOneOption struct {
  34 + Id int64
  35 + Code string
  36 +}
  37 +
29 type AdminPermissionRepository interface { 38 type AdminPermissionRepository interface {
30 - Find(map[string]interface{}) ([]AdminPermission, error) 39 + Find(PermissionFindOption) ([]AdminPermission, error)
  40 + FindOne(PermissionFindOneOption) (AdminPermission, error)
31 } 41 }
@@ -50,15 +50,27 @@ func (u Users) IsUsable() bool { @@ -50,15 +50,27 @@ func (u Users) IsUsable() bool {
50 return u.Status == userStatusUsable 50 return u.Status == userStatusUsable
51 } 51 }
52 52
53 -//IsCharge 用户是否是主管  
54 -func (u Users) IsCharge() bool {  
55 - return u.ChargeStatus == UserIsCompanyCharge 53 +//IsSuperAdmin 用户是否是负责人
  54 +func (u Users) IsSuperAdmin() bool {
  55 + return u.AdminType == UserIsAdmin
56 } 56 }
57 57
58 func (u Users) InCompany(companyid int64) bool { 58 func (u Users) InCompany(companyid int64) bool {
59 return u.CompanyId == companyid 59 return u.CompanyId == companyid
60 } 60 }
61 61
  62 +func (u Users) HasPermissionByCode(code string) bool {
  63 + if u.IsSuperAdmin() {
  64 + return true
  65 + }
  66 + for _, v := range u.Permission {
  67 + if v.Code == code {
  68 + return true
  69 + }
  70 + }
  71 + return false
  72 +}
  73 +
62 func (u *Users) Update(m map[string]interface{}) error { 74 func (u *Users) Update(m map[string]interface{}) error {
63 if v, ok := m["CompanyId"]; ok { 75 if v, ok := m["CompanyId"]; ok {
64 u.CompanyId = v.(int64) 76 u.CompanyId = v.(int64)
@@ -3,13 +3,13 @@ package models @@ -3,13 +3,13 @@ package models
3 type AdminPermission struct { 3 type AdminPermission struct {
4 tableName struct{} `pg:"admin_permission,alias:admin_permission"` 4 tableName struct{} `pg:"admin_permission,alias:admin_permission"`
5 //id 5 //id
6 - Id int `pg:",pk"` 6 + Id int64 `pg:",pk"`
7 //权限名称、菜单名称 7 //权限名称、菜单名称
8 Name string 8 Name string
9 //权限编码 9 //权限编码
10 Code string 10 Code string
11 //父级id 11 //父级id
12 - ParentId int 12 + ParentId int64
13 //排序编号 13 //排序编号
14 Sort int 14 Sort int
15 //图标 15 //图标
@@ -33,13 +33,12 @@ func (reponsitory AdminPermissionRepository) transformPgModelToDomainModel(permi @@ -33,13 +33,12 @@ func (reponsitory AdminPermissionRepository) transformPgModelToDomainModel(permi
33 return result, nil 33 return result, nil
34 } 34 }
35 35
36 -func (reponsitory AdminPermissionRepository) Find(queryOptions map[string]interface{}) ([]domain.AdminPermission, error) { 36 +func (reponsitory AdminPermissionRepository) Find(queryOptions domain.PermissionFindOption) ([]domain.AdminPermission, error) {
37 db := reponsitory.transactionContext.PgDd 37 db := reponsitory.transactionContext.PgDd
38 permissionModels := make([]models.AdminPermission, 0) 38 permissionModels := make([]models.AdminPermission, 0)
39 query := db.Model(&permissionModels) 39 query := db.Model(&permissionModels)
40 - if v, ok := queryOptions["IdsIn"]; ok {  
41 - in := v.([]int)  
42 - query = query.WhereIn("id in (?) ", in) 40 + if len(queryOptions.Ids) > 0 {
  41 + query = query.WhereIn("id in (?) ", queryOptions.Ids)
43 } 42 }
44 if err := query.Select(); err != nil { 43 if err := query.Select(); err != nil {
45 return nil, err 44 return nil, err
@@ -51,3 +50,23 @@ func (reponsitory AdminPermissionRepository) Find(queryOptions map[string]interf @@ -51,3 +50,23 @@ func (reponsitory AdminPermissionRepository) Find(queryOptions map[string]interf
51 } 50 }
52 return result, nil 51 return result, nil
53 } 52 }
  53 +
  54 +func (reponsitory AdminPermissionRepository) FindOne(queryOptions domain.PermissionFindOneOption) (domain.AdminPermission, error) {
  55 + db := reponsitory.transactionContext.PgDd
  56 + var permissionModels models.AdminPermission
  57 + query := db.Model(&permissionModels)
  58 + if len(queryOptions.Code) > 0 {
  59 + query = query.Where("code=?", queryOptions.Code)
  60 + }
  61 + if queryOptions.Id > 0 {
  62 + query = query.Where("id=?", queryOptions.Id)
  63 + }
  64 +
  65 + var result domain.AdminPermission
  66 + err := query.First()
  67 + if err != nil {
  68 + return result, err
  69 + }
  70 + result, _ = reponsitory.transformPgModelToDomainModel(&permissionModels)
  71 + return result, nil
  72 +}
@@ -8,12 +8,8 @@ import ( @@ -8,12 +8,8 @@ import (
8 8
9 "github.com/GeeTeam/gt3-golang-sdk/geetest" 9 "github.com/GeeTeam/gt3-golang-sdk/geetest"
10 "github.com/astaxie/beego/logs" 10 "github.com/astaxie/beego/logs"
11 - adminPermissionquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/query"  
12 - adminPermissionService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/service"  
13 - adminuserCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/command"  
14 - adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query"  
15 - adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service"  
16 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 11 + userCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
  12 + userService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/service"
17 ) 13 )
18 14
19 type AdminLoginController struct { 15 type AdminLoginController struct {
@@ -86,36 +82,20 @@ func (c *AdminLoginController) Prepare() { @@ -86,36 +82,20 @@ func (c *AdminLoginController) Prepare() {
86 // } 82 // }
87 83
88 func (c *AdminLoginController) Login() { 84 func (c *AdminLoginController) Login() {
89 - type Paramter struct {  
90 - Username string `json:"username"`  
91 - Password string `json:"password"`  
92 - }  
93 var ( 85 var (
94 - param Paramter  
95 - err error 86 + param userCmd.LoginBySecretKeyCommand
96 ) 87 )
97 - if err = c.BindJsonData(&param); err != nil { 88 + if err := c.BindJsonData(&param); err != nil {
98 c.ResponseError(fmt.Errorf("json解析失败:%s", err)) 89 c.ResponseError(fmt.Errorf("json解析失败:%s", err))
99 return 90 return
100 } 91 }
101 - newAdminuserquery := adminuserquery.GetAdminUserQuery{AdminAccount: param.Username}  
102 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
103 - _ = newAdminuserquery  
104 - _ = newAdminUserService  
105 - newJwt := lib.NewMyToken(0, 0)  
106 - newToken, err := newJwt.CreateJWTToken() 92 + newUserService := userService.NewUsersService(nil)
  93 + resp, err := newUserService.UserLoginBySecretKey(param)
107 if err != nil { 94 if err != nil {
108 - logs.Error("生成jwt数据失败:%s", err)  
109 - c.ResponseError(errors.New("服务异常")) 95 + c.ResponseError(err)
110 return 96 return
111 } 97 }
112 - rspdata := map[string]interface{}{  
113 - "access": map[string]interface{}{  
114 - "accessToken": newToken,  
115 - "expiresIn": lib.JWtExpiresSecond,  
116 - },  
117 - }  
118 - c.ResponseData(rspdata) 98 + c.ResponseData(resp)
119 return 99 return
120 } 100 }
121 101
@@ -145,86 +125,42 @@ func (c *AdminLoginController) CaptchaInit() { @@ -145,86 +125,42 @@ func (c *AdminLoginController) CaptchaInit() {
145 //AdminpPofile 获取登录用户的权限配置 125 //AdminpPofile 获取登录用户的权限配置
146 func (c *AdminLoginController) AdminpPofile() { 126 func (c *AdminLoginController) AdminpPofile() {
147 adminId := c.GetUserId() 127 adminId := c.GetUserId()
148 - newAdminuserquery := adminuserquery.GetAdminUserQuery{Id: adminId}  
149 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
150 - adminuser, err := newAdminUserService.GetAdminUser(&newAdminuserquery) 128 + newUserService := userService.NewUsersService(nil)
  129 + respData, err := newUserService.GetUserPofile(adminId)
151 if err != nil { 130 if err != nil {
152 logs.Error("获取用户数据失败:%s", err) 131 logs.Error("获取用户数据失败:%s", err)
153 c.ResponseError(errors.New("用户不存在")) 132 c.ResponseError(errors.New("用户不存在"))
154 return 133 return
155 } 134 }
156 -  
157 - newPermissionSrv := adminPermissionService.NewAdminPermissionService(nil)  
158 - allPermission, err := newPermissionSrv.ListAdminPermission(adminPermissionquery.ListAdminPermissionQuery{})  
159 - if err != nil {  
160 - logs.Error("获取权限数据失败:%s", err)  
161 - c.ResponseError(errors.New("服务异常"))  
162 - return  
163 - }  
164 - //适配前端的数据格式  
165 - permissionSlice := make([]map[string]interface{}, 0)  
166 - for _, v := range allPermission {  
167 - m := map[string]interface{}{  
168 - "code": v.Code,  
169 - "icon": v.Icon,  
170 - "parentId": v.ParentId,  
171 - "sort": v.Sort,  
172 - "name": v.Name,  
173 - "id": v.Id,  
174 - "status": 0, //状态 1-启用 0-禁用,前端需要  
175 - }  
176 - for _, p := range adminuser.Permission {  
177 - if p.Id == v.Id {  
178 - m["status"] = 1  
179 - break  
180 - }  
181 - if p.Id == v.ParentId {  
182 - m["status"] = 1  
183 - break  
184 - }  
185 - }  
186 - permissionSlice = append(permissionSlice, m)  
187 - }  
188 - userData := map[string]string{  
189 - "id": fmt.Sprint(adminuser.Id),  
190 - "name": adminuser.AdminName,  
191 - "adminType": "2", // 管理员类型 1-超级管理员 2-子管理员  
192 - }  
193 - if adminuser.IsDefault {  
194 - userData["adminType"] = "1"  
195 - }  
196 - respData := map[string]interface{}{  
197 - "user": userData,  
198 - "menus": permissionSlice,  
199 - }  
200 c.ResponseData(respData) 135 c.ResponseData(respData)
201 -}  
202 -  
203 -func (c *AdminLoginController) PwdUpdate() {  
204 - //用与适配前端定义的数据结构  
205 - type Paramater struct {  
206 - Pwd string `json:"pwd"`  
207 - }  
208 - var (  
209 - param Paramater  
210 - err error  
211 - )  
212 - if err = c.BindJsonData(&param); err != nil {  
213 - logs.Error(err)  
214 - c.ResponseError(errors.New("json数据解析失败"))  
215 - return  
216 - }  
217 - uid := c.GetUserId()  
218 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
219 - cmd := adminuserCmd.UpdateAdminUserPwdCommand{  
220 - Id: uid,  
221 - Password: param.Pwd,  
222 - }  
223 - err = newAdminUserService.UpdateAdminPassword(cmd)  
224 - if err != nil {  
225 - c.ResponseError(err)  
226 - return  
227 - }  
228 - c.ResponseData(nil)  
229 return 136 return
230 } 137 }
  138 +
  139 +// func (c *AdminLoginController) PwdUpdate() {
  140 +// //用与适配前端定义的数据结构
  141 +// type Paramater struct {
  142 +// Pwd string `json:"pwd"`
  143 +// }
  144 +// var (
  145 +// param Paramater
  146 +// err error
  147 +// )
  148 +// if err = c.BindJsonData(&param); err != nil {
  149 +// logs.Error(err)
  150 +// c.ResponseError(errors.New("json数据解析失败"))
  151 +// return
  152 +// }
  153 +// uid := c.GetUserId()
  154 +// newAdminUserService := adminuserservice.NewAdminUserService(nil)
  155 +// cmd := adminuserCmd.UpdateAdminUserPwdCommand{
  156 +// Id: uid,
  157 +// Password: param.Pwd,
  158 +// }
  159 +// err = newAdminUserService.UpdateAdminPassword(cmd)
  160 +// if err != nil {
  161 +// c.ResponseError(err)
  162 +// return
  163 +// }
  164 +// c.ResponseData(nil)
  165 +// return
  166 +// }
@@ -29,7 +29,7 @@ func (c *AdminUserController) Prepare() { @@ -29,7 +29,7 @@ func (c *AdminUserController) Prepare() {
29 29
30 type adminDetailParam struct { 30 type adminDetailParam struct {
31 Id int64 `json:"id"` 31 Id int64 `json:"id"`
32 - PermissionType []int `json:"permissionType"` 32 + PermissionType []int64 `json:"permissionType"`
33 Status int `json:"status"` 33 Status int `json:"status"`
34 Account string `json:"account"` 34 Account string `json:"account"`
35 IsAdmin int `json:"isAdmin"` 35 IsAdmin int `json:"isAdmin"`
@@ -149,7 +149,7 @@ func (c *AdminUserController) ListAdminUser() { @@ -149,7 +149,7 @@ func (c *AdminUserController) ListAdminUser() {
149 c.ResponseError(errors.New("服务异常")) 149 c.ResponseError(errors.New("服务异常"))
150 return 150 return
151 } 151 }
152 - permissionMap := map[int]domain.AdminPermission{} 152 + permissionMap := map[int64]domain.AdminPermission{}
153 for i := range allPermission { 153 for i := range allPermission {
154 permissionMap[allPermission[i].Id] = allPermission[i] 154 permissionMap[allPermission[i].Id] = allPermission[i]
155 } 155 }
@@ -11,8 +11,8 @@ import ( @@ -11,8 +11,8 @@ import (
11 "github.com/astaxie/beego" 11 "github.com/astaxie/beego"
12 "github.com/astaxie/beego/logs" 12 "github.com/astaxie/beego/logs"
13 13
14 - adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query"  
15 - adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service" 14 + userQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/query"
  15 + userService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/service"
16 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 16 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
17 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego/protocol" 17 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego/protocol"
18 ) 18 )
@@ -162,27 +162,22 @@ func (controller *BaseController) ValidAdminPermission(permissionCode string, ex @@ -162,27 +162,22 @@ func (controller *BaseController) ValidAdminPermission(permissionCode string, ex
162 controller.ResponseError(errors.New("无操作权限")) 162 controller.ResponseError(errors.New("无操作权限"))
163 return false 163 return false
164 } 164 }
165 - newAdminuserquery := adminuserquery.GetAdminUserQuery{Id: userId}  
166 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
167 - adminuser, err := newAdminUserService.GetAdminUser(&newAdminuserquery) 165 + comanyId := controller.GetUserCompany()
  166 + newQuery := userQuery.ValidatePermissionQuery{
  167 + UserId: userId,
  168 + PermissionCode: permissionCode,
  169 + CompanyId: comanyId,
  170 + }
  171 + newUserService := userService.NewUsersService(nil)
  172 + ok, err := newUserService.ValidateAdminpPermission(newQuery)
168 if err != nil { 173 if err != nil {
169 - logs.Error("获取用户数据失败:%s", err) 174 + logs.Error("用户鉴权失败:%s", err)
170 controller.ResponseError(errors.New("无操作权限")) 175 controller.ResponseError(errors.New("无操作权限"))
171 return false 176 return false
172 } 177 }
173 - if adminuser.IsDefault {  
174 - logs.Debug("用户是超级管理员")  
175 - return true  
176 - }  
177 - if !adminuser.IsUsable {  
178 - controller.ResponseError(errors.New("用户被禁用"))  
179 - return false  
180 - }  
181 - for _, v := range adminuser.Permission {  
182 - if v.Code == permissionCode { 178 + if ok {
183 return true 179 return true
184 } 180 }
185 - }  
186 controller.ResponseError(errors.New("无操作权限")) 181 controller.ResponseError(errors.New("无操作权限"))
187 return false 182 return false
188 } 183 }