作者 yangfu

角色服务修改

1 -{"F:\\go\\src\\allied-creation\\allied-creation-gateway\\pkg\\port\\beego\\routers":1627552127430848800}  
  1 +{"F:\\go\\src\\allied-creation\\allied-creation-gateway\\pkg\\port\\beego\\routers":1627631911600010400}
@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 type RoleRemoveCommand struct { 10 type RoleRemoveCommand struct {
11 //操作人 11 //操作人
12 Operator domain.Operator `json:"-"` 12 Operator domain.Operator `json:"-"`
13 - RoleId []string `json:"roleId"` 13 + RoleIds []string `json:"roleIds"`
14 } 14 }
15 15
16 func (roleRemoveCommand *RoleRemoveCommand) Valid(validation *validation.Validation) { 16 func (roleRemoveCommand *RoleRemoveCommand) Valid(validation *validation.Validation) {
@@ -11,7 +11,7 @@ type RoleMenuBeforeEditQuery struct { @@ -11,7 +11,7 @@ type RoleMenuBeforeEditQuery struct {
11 // 操作人 11 // 操作人
12 Operator domain.Operator `json:"-"` 12 Operator domain.Operator `json:"-"`
13 // 角色ID 13 // 角色ID
14 - RoleId int64 `json:"roleId" valid:"Required"` 14 + RoleId string `json:"roleId" valid:"Required"`
15 } 15 }
16 16
17 func (roleMenuBeforeEditQuery *RoleMenuBeforeEditQuery) Valid(validation *validation.Validation) { 17 func (roleMenuBeforeEditQuery *RoleMenuBeforeEditQuery) Valid(validation *validation.Validation) {
@@ -11,7 +11,7 @@ type RoleUserBeforeEditQuery struct { @@ -11,7 +11,7 @@ type RoleUserBeforeEditQuery struct {
11 // 操作人 11 // 操作人
12 Operator domain.Operator `json:"-"` 12 Operator domain.Operator `json:"-"`
13 // 角色ID 13 // 角色ID
14 - RoleId string `json:"roleId"` 14 + RoleId string `json:"roleId" valid:"Required"`
15 } 15 }
16 16
17 func (roleUserBeforeEditQuery *RoleUserBeforeEditQuery) Valid(validation *validation.Validation) { 17 func (roleUserBeforeEditQuery *RoleUserBeforeEditQuery) Valid(validation *validation.Validation) {
@@ -106,8 +106,8 @@ func (rolesService *RolesService) RoleList(roleListQuery *query.RoleListQuery) ( @@ -106,8 +106,8 @@ func (rolesService *RolesService) RoleList(roleListQuery *query.RoleListQuery) (
106 result := []dto.RoleItem{} 106 result := []dto.RoleItem{}
107 for _, v := range roleList.Roles { 107 for _, v := range roleList.Roles {
108 result = append(result, dto.RoleItem{ 108 result = append(result, dto.RoleItem{
109 - RoleId: strconv.Itoa(v.RoleID),  
110 - OrgId: strconv.Itoa(v.OrgID), 109 + RoleId: strconv.Itoa(int(v.RoleID)),
  110 + OrgId: strconv.Itoa(int(v.OrgID)),
111 RoleName: v.RoleName, 111 RoleName: v.RoleName,
112 Describe: v.Desc, 112 Describe: v.Desc,
113 OrgName: v.Ext.OrgName, 113 OrgName: v.Ext.OrgName,
@@ -121,6 +121,19 @@ func (rolesService *RolesService) RoleList(roleListQuery *query.RoleListQuery) ( @@ -121,6 +121,19 @@ func (rolesService *RolesService) RoleList(roleListQuery *query.RoleListQuery) (
121 121
122 // 编辑角色关联权限菜单的前置准备数据 122 // 编辑角色关联权限菜单的前置准备数据
123 func (rolesService *RolesService) RoleMenuBeforeEdit(roleMenuBeforeEditQuery *query.RoleMenuBeforeEditQuery) (interface{}, error) { 123 func (rolesService *RolesService) RoleMenuBeforeEdit(roleMenuBeforeEditQuery *query.RoleMenuBeforeEditQuery) (interface{}, error) {
  124 + //creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
  125 + // roleMenuBeforeEditQuery.Operator.CompanyId,
  126 + // roleMenuBeforeEditQuery.Operator.OrgId,
  127 + // roleMenuBeforeEditQuery.Operator.UserId)
  128 + //roleId, _ := strconv.Atoi(roleMenuBeforeEditQuery.RoleId)
  129 + //roles, err := creationUserGateway.RoleSearch(allied_creation_user.ReqRoleSearch{
  130 + // OrgId: roleMenuBeforeEditQuery.Operator.OrgId,
  131 + // Limit: 999,
  132 + // RoleType: 1,
  133 + //})
  134 + //if err != nil {
  135 + // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  136 + //}
124 137
125 return nil, nil 138 return nil, nil
126 } 139 }
@@ -131,11 +144,10 @@ func (rolesService *RolesService) RoleUserBeforeEdit(roleUserBeforeEditQuery *qu @@ -131,11 +144,10 @@ func (rolesService *RolesService) RoleUserBeforeEdit(roleUserBeforeEditQuery *qu
131 roleUserBeforeEditQuery.Operator.CompanyId, 144 roleUserBeforeEditQuery.Operator.CompanyId,
132 roleUserBeforeEditQuery.Operator.OrgId, 145 roleUserBeforeEditQuery.Operator.OrgId,
133 roleUserBeforeEditQuery.Operator.UserId) 146 roleUserBeforeEditQuery.Operator.UserId)
134 - //roleId, _ := strconv.Atoi(roleUserBeforeEditQuery.RoleId)  
135 - 147 + roleId, _ := strconv.Atoi(roleUserBeforeEditQuery.RoleId)
136 roles, err := creationUserGateway.RoleSearch(allied_creation_user.ReqRoleSearch{ 148 roles, err := creationUserGateway.RoleSearch(allied_creation_user.ReqRoleSearch{
137 OrgId: roleUserBeforeEditQuery.Operator.OrgId, 149 OrgId: roleUserBeforeEditQuery.Operator.OrgId,
138 - Limit: 100, 150 + Limit: 999,
139 RoleType: 1, 151 RoleType: 1,
140 }) 152 })
141 if err != nil { 153 if err != nil {
@@ -151,6 +163,19 @@ func (rolesService *RolesService) RoleUserBeforeEdit(roleUserBeforeEditQuery *qu @@ -151,6 +163,19 @@ func (rolesService *RolesService) RoleUserBeforeEdit(roleUserBeforeEditQuery *qu
151 "orgs": orgs.Orgs, 163 "orgs": orgs.Orgs,
152 "roles": roles.Roles, 164 "roles": roles.Roles,
153 } 165 }
  166 + // 有传入角色ID才返回关联角色用户数据
  167 + if roleId > 0 {
  168 + relatedUser, err := creationUserGateway.RoleGetRelatedUser(allied_creation_user.ReqRoleGetRelatedUser{
  169 + RoleId: int64(roleId),
  170 + })
  171 +
  172 + if err != nil {
  173 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  174 + }
  175 + result["notInRoleUser"] = relatedUser.NotInRoleUser
  176 + result["roleUser"] = relatedUser.RoleUser
  177 + }
  178 +
154 return result, nil 179 return result, nil
155 } 180 }
156 181
@@ -186,14 +211,14 @@ func (rolesService *RolesService) RoleRemove(roleRemoveCommand *command.RoleRemo @@ -186,14 +211,14 @@ func (rolesService *RolesService) RoleRemove(roleRemoveCommand *command.RoleRemo
186 roleRemoveCommand.Operator.UserId) 211 roleRemoveCommand.Operator.UserId)
187 212
188 var roleIds []int64 213 var roleIds []int64
189 - for _, v := range roleRemoveCommand.RoleId { 214 + for _, v := range roleRemoveCommand.RoleIds {
190 id, err := strconv.Atoi(v) 215 id, err := strconv.Atoi(v)
191 if err == nil { 216 if err == nil {
192 roleIds = append(roleIds, int64(id)) 217 roleIds = append(roleIds, int64(id))
193 } 218 }
194 } 219 }
195 _, err := creationUserGateway.RoleRemove(allied_creation_user.ReqRoleRemove{ 220 _, err := creationUserGateway.RoleRemove(allied_creation_user.ReqRoleRemove{
196 - //TODO 修改 为 切片类型 221 + roleIds,
197 }) 222 })
198 if err != nil { 223 if err != nil {
199 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 224 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -220,7 +245,7 @@ func (rolesService *RolesService) RoleUserAdd(roleUserAddCommand *command.RoleUs @@ -220,7 +245,7 @@ func (rolesService *RolesService) RoleUserAdd(roleUserAddCommand *command.RoleUs
220 UserIds: userIds, 245 UserIds: userIds,
221 }) 246 })
222 if err != nil { 247 if err != nil {
223 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 248 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
224 } 249 }
225 return roleUserAddCommand, err 250 return roleUserAddCommand, err
226 } 251 }
@@ -244,15 +269,27 @@ func (rolesService *RolesService) RoleUserDelete(roleUserDeleteCommand *command. @@ -244,15 +269,27 @@ func (rolesService *RolesService) RoleUserDelete(roleUserDeleteCommand *command.
244 UserIds: userIds, 269 UserIds: userIds,
245 }) 270 })
246 if err != nil { 271 if err != nil {
247 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 272 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
248 } 273 }
249 return roleUserDeleteCommand, err 274 return roleUserDeleteCommand, err
250 } 275 }
251 276
252 -// 角色下关联用户的数据 277 +// 角色下关联用户的数据 (暂时不需要这个)
253 func (rolesService *RolesService) RoleUserInfo(roleUserInfoQuery *query.RoleUserInfoQuery) (interface{}, error) { 278 func (rolesService *RolesService) RoleUserInfo(roleUserInfoQuery *query.RoleUserInfoQuery) (interface{}, error) {
254 - //TODO  
255 - return nil, nil 279 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
  280 + roleUserInfoQuery.Operator.CompanyId,
  281 + roleUserInfoQuery.Operator.OrgId,
  282 + roleUserInfoQuery.Operator.UserId)
  283 + relatedUser, err := creationUserGateway.RoleGetRelatedUser(allied_creation_user.ReqRoleGetRelatedUser{
  284 + RoleId: roleUserInfoQuery.RoleId,
  285 + })
  286 + if err != nil {
  287 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  288 + }
  289 + var result = make(map[string]interface{})
  290 + result["notInRoleUser"] = relatedUser.NotInRoleUser
  291 + result["roleUser"] = relatedUser.RoleUser
  292 + return result, nil
256 } 293 }
257 294
258 func NewRolesService(options map[string]interface{}) *RolesService { 295 func NewRolesService(options map[string]interface{}) *RolesService {
@@ -439,7 +439,7 @@ func (usersService *UsersService) SelectorCompanyRole(selectorQuery *query.Compa @@ -439,7 +439,7 @@ func (usersService *UsersService) SelectorCompanyRole(selectorQuery *query.Compa
439 ) 439 )
440 for _, v := range result.Roles { 440 for _, v := range result.Roles {
441 item = dto.UserRole{ 441 item = dto.UserRole{
442 - RoleID: strconv.Itoa(v.RoleID), 442 + RoleID: strconv.Itoa(int(v.RoleID)),
443 RoleName: v.RoleName, 443 RoleName: v.RoleName,
444 OrgName: v.Ext.OrgName, 444 OrgName: v.Ext.OrgName,
445 Descript: v.Desc, 445 Descript: v.Desc,
@@ -200,8 +200,8 @@ func (gateway HttplibAlliedCreationUser) RoleUpdate(param ReqRoleUpdate) (*DataR @@ -200,8 +200,8 @@ func (gateway HttplibAlliedCreationUser) RoleUpdate(param ReqRoleUpdate) (*DataR
200 200
201 // RoleRemove 移除角色 201 // RoleRemove 移除角色
202 func (gateway HttplibAlliedCreationUser) RoleRemove(param ReqRoleRemove) (*DataRoleRemove, error) { 202 func (gateway HttplibAlliedCreationUser) RoleRemove(param ReqRoleRemove) (*DataRoleRemove, error) {
203 - urlStr := gateway.baseUrL + "/role/" + strconv.FormatInt(param.RoleId, 10)  
204 - method := "delete" 203 + urlStr := gateway.baseUrL + "/role/batch-delete"
  204 + method := "post"
205 req := gateway.CreateRequest(urlStr, method) 205 req := gateway.CreateRequest(urlStr, method)
206 log.Logger.Debug("向用户模块请求数据:移除角色。", map[string]interface{}{ 206 log.Logger.Debug("向用户模块请求数据:移除角色。", map[string]interface{}{
207 "api": method + ":" + urlStr, 207 "api": method + ":" + urlStr,
@@ -43,7 +43,7 @@ type ( @@ -43,7 +43,7 @@ type (
43 43
44 DataOrgGetSubDepartment struct { 44 DataOrgGetSubDepartment struct {
45 Orgs []struct { 45 Orgs []struct {
46 - OrgID int `json:"orgId"` 46 + OrgID Int64String `json:"orgId"`
47 //CompanyID int `json:"companyId"` 47 //CompanyID int `json:"companyId"`
48 //CreatedAt time.Time `json:"createdAt"` 48 //CreatedAt time.Time `json:"createdAt"`
49 //UpdatedAt time.Time `json:"updatedAt"` 49 //UpdatedAt time.Time `json:"updatedAt"`
1 package allied_creation_user 1 package allied_creation_user
2 2
  3 +import (
  4 + "fmt"
  5 + "strconv"
  6 +)
  7 +
3 //################角色模块################## 8 //################角色模块##################
  9 +type Int64String int64
  10 +
  11 +func (t Int64String) MarshalJSON() ([]byte, error) {
  12 + stamp := fmt.Sprintf(`"%d"`, t)
  13 + return []byte(stamp), nil
  14 +}
  15 +func (t Int64String) UnMarshalJSON(data []byte) error {
  16 + v, err := strconv.ParseInt(string(data), 10, 64)
  17 + t = Int64String(v)
  18 + return err
  19 +}
4 20
5 //搜索角色列表 21 //搜索角色列表
6 type ( 22 type (
@@ -22,10 +38,10 @@ type ( @@ -22,10 +38,10 @@ type (
22 DataRoleSearch struct { 38 DataRoleSearch struct {
23 Count int64 39 Count int64
24 Roles []struct { 40 Roles []struct {
25 - AccessMenus []int `json:"accessMenus"`  
26 - CompanyID int `json:"companyId"`  
27 - CreatedAt string `json:"createdAt"`  
28 - Desc string `json:"desc"` 41 + AccessMenus []int `json:"accessMenus"`
  42 + CompanyID Int64String `json:"companyId"`
  43 + CreatedAt string `json:"createdAt"`
  44 + Desc string `json:"desc"`
29 Ext struct { 45 Ext struct {
30 DepName string `json:"depName"` 46 DepName string `json:"depName"`
31 OrgName string `json:"orgName"` 47 OrgName string `json:"orgName"`
@@ -33,11 +49,11 @@ type ( @@ -33,11 +49,11 @@ type (
33 Phone string `json:"phone"` 49 Phone string `json:"phone"`
34 UserName string `json:"userName"` 50 UserName string `json:"userName"`
35 } `json:"ext"` 51 } `json:"ext"`
36 - OrgID int `json:"orgId"`  
37 - RoleID int `json:"roleId"`  
38 - RoleName string `json:"roleName"`  
39 - RoleType int `json:"roleType"`  
40 - UpdatedAt string `json:"updatedAt"` 52 + OrgID Int64String `json:"orgId"`
  53 + RoleID Int64String `json:"roleId"`
  54 + RoleName string `json:"roleName"`
  55 + RoleType int `json:"roleType"`
  56 + UpdatedAt string `json:"updatedAt"`
41 } `json:"roles"` 57 } `json:"roles"`
42 } 58 }
43 ) 59 )
@@ -121,7 +137,7 @@ type ( @@ -121,7 +137,7 @@ type (
121 //移除角色 137 //移除角色
122 type ( 138 type (
123 ReqRoleRemove struct { 139 ReqRoleRemove struct {
124 - RoleId int64 `json:"roleId"` 140 + RoleIds []int64 `json:"roleIds"`
125 } 141 }
126 142
127 DataRoleRemove struct { 143 DataRoleRemove struct {
@@ -138,14 +154,18 @@ type ( @@ -138,14 +154,18 @@ type (
138 154
139 DataRoleGetRelatedUser struct { 155 DataRoleGetRelatedUser struct {
140 NotInRoleUser []struct { 156 NotInRoleUser []struct {
141 - DepartmentName string `json:"departmentName"`  
142 - UserID int `json:"userId"`  
143 - UserName string `json:"userName"` 157 + DepartmentId Int64String `json:"departmentId"`
  158 + DepartmentName string `json:"departmentName"`
  159 + UserID Int64String `json:"userId"`
  160 + UserName string `json:"userName"`
  161 + UserCode string `json:"userCode"`
144 } `json:"notInRoleUser"` 162 } `json:"notInRoleUser"`
145 RoleUser []struct { 163 RoleUser []struct {
146 - DepartmentName string `json:"departmentName"`  
147 - UserID int `json:"userId"`  
148 - UserName string `json:"userName"` 164 + DepartmentId Int64String `json:"departmentId"`
  165 + DepartmentName string `json:"departmentName"`
  166 + UserID Int64String `json:"userId"`
  167 + UserName string `json:"userName"`
  168 + UserCode string `json:"userCode"`
149 } `json:"roleUser"` 169 } `json:"roleUser"`
150 } 170 }
151 ) 171 )
@@ -81,6 +81,8 @@ func (controller *RolesController) RoleUserBeforeEdit() { @@ -81,6 +81,8 @@ func (controller *RolesController) RoleUserBeforeEdit() {
81 rolesService := service.NewRolesService(nil) 81 rolesService := service.NewRolesService(nil)
82 roleUserBeforeEditQuery := &query.RoleUserBeforeEditQuery{} 82 roleUserBeforeEditQuery := &query.RoleUserBeforeEditQuery{}
83 roleUserBeforeEditQuery.Operator = controller.GetOperator() 83 roleUserBeforeEditQuery.Operator = controller.GetOperator()
  84 + roleId := controller.GetString("roleId")
  85 + roleUserBeforeEditQuery.RoleId = roleId
84 data, err := rolesService.RoleUserBeforeEdit(roleUserBeforeEditQuery) 86 data, err := rolesService.RoleUserBeforeEdit(roleUserBeforeEditQuery)
85 controller.Response(data, err) 87 controller.Response(data, err)
86 } 88 }
@@ -89,6 +91,7 @@ func (controller *RolesController) RoleMenuBeforeEdit() { @@ -89,6 +91,7 @@ func (controller *RolesController) RoleMenuBeforeEdit() {
89 rolesService := service.NewRolesService(nil) 91 rolesService := service.NewRolesService(nil)
90 roleMenuBeforeEditQuery := &query.RoleMenuBeforeEditQuery{} 92 roleMenuBeforeEditQuery := &query.RoleMenuBeforeEditQuery{}
91 roleMenuBeforeEditQuery.Operator = controller.GetOperator() 93 roleMenuBeforeEditQuery.Operator = controller.GetOperator()
  94 + controller.Unmarshal(roleMenuBeforeEditQuery)
92 data, err := rolesService.RoleMenuBeforeEdit(roleMenuBeforeEditQuery) 95 data, err := rolesService.RoleMenuBeforeEdit(roleMenuBeforeEditQuery)
93 controller.Response(data, err) 96 controller.Response(data, err)
94 } 97 }
@@ -103,3 +106,12 @@ func (controller *RolesController) RoleMenuEdit() { @@ -103,3 +106,12 @@ func (controller *RolesController) RoleMenuEdit() {
103 data, err := rolesService.RoleMenuEdit(roleMenuEditQuery) 106 data, err := rolesService.RoleMenuEdit(roleMenuEditQuery)
104 controller.Response(data, err) 107 controller.Response(data, err)
105 } 108 }
  109 +
  110 +func (controller *RolesController) RoleDelete() {
  111 + rolesService := service.NewRolesService(nil)
  112 + roleRemoveCommand := &command.RoleRemoveCommand{}
  113 + controller.Unmarshal(roleRemoveCommand)
  114 + roleRemoveCommand.Operator = controller.GetOperator()
  115 + data, err := rolesService.RoleRemove(roleRemoveCommand)
  116 + controller.Response(data, err)
  117 +}
@@ -11,9 +11,10 @@ func init() { @@ -11,9 +11,10 @@ func init() {
11 web.Router("/v1/web/roles/search", &web_client.RolesController{}, "Post:RoleList") 11 web.Router("/v1/web/roles/search", &web_client.RolesController{}, "Post:RoleList")
12 web.Router("/v1/web/roles/:roleId", &web_client.RolesController{}, "Get:RoleGet") 12 web.Router("/v1/web/roles/:roleId", &web_client.RolesController{}, "Get:RoleGet")
13 web.Router("/v1/web/roles/role-user/:roleId", &web_client.RolesController{}, "Get:RoleUserInfo") 13 web.Router("/v1/web/roles/role-user/:roleId", &web_client.RolesController{}, "Get:RoleUserInfo")
14 - web.Router("/v1/web/roles/role-user", &web_client.RolesController{}, "Post:RoleUserAdd")  
15 - web.Router("/v1/web/roles/role-user", &web_client.RolesController{}, "Delete:RoleUserDelete") 14 + web.Router("/v1/web/roles/role-user/assign", &web_client.RolesController{}, "Post:RoleUserAdd")
  15 + web.Router("/v1/web/roles/role-user/unassign", &web_client.RolesController{}, "Post:RoleUserDelete")
16 web.Router("/v1/web/roles/role-user/before-edit", &web_client.RolesController{}, "Get:RoleUserBeforeEdit") 16 web.Router("/v1/web/roles/role-user/before-edit", &web_client.RolesController{}, "Get:RoleUserBeforeEdit")
17 web.Router("/v1/web/roles/role-menu/before-edit", &web_client.RolesController{}, "Get:RoleMenuBeforeEdit") 17 web.Router("/v1/web/roles/role-menu/before-edit", &web_client.RolesController{}, "Get:RoleMenuBeforeEdit")
18 web.Router("/v1/web/roles/role-menu/:roleId", &web_client.RolesController{}, "Put:RoleMenuEdit") 18 web.Router("/v1/web/roles/role-menu/:roleId", &web_client.RolesController{}, "Put:RoleMenuEdit")
  19 + web.Router("/v1/web/roles/batch-delete", &web_client.RolesController{}, "Post:RoleDelete")
19 } 20 }