作者 yangfu

角色服务修改

{"F:\\go\\src\\allied-creation\\allied-creation-gateway\\pkg\\port\\beego\\routers":1627552127430848800}
\ No newline at end of file
{"F:\\go\\src\\allied-creation\\allied-creation-gateway\\pkg\\port\\beego\\routers":1627631911600010400}
\ No newline at end of file
... ...
... ... @@ -10,7 +10,7 @@ import (
type RoleRemoveCommand struct {
//操作人
Operator domain.Operator `json:"-"`
RoleId []string `json:"roleId"`
RoleIds []string `json:"roleIds"`
}
func (roleRemoveCommand *RoleRemoveCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -11,7 +11,7 @@ type RoleMenuBeforeEditQuery struct {
// 操作人
Operator domain.Operator `json:"-"`
// 角色ID
RoleId int64 `json:"roleId" valid:"Required"`
RoleId string `json:"roleId" valid:"Required"`
}
func (roleMenuBeforeEditQuery *RoleMenuBeforeEditQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -11,7 +11,7 @@ type RoleUserBeforeEditQuery struct {
// 操作人
Operator domain.Operator `json:"-"`
// 角色ID
RoleId string `json:"roleId"`
RoleId string `json:"roleId" valid:"Required"`
}
func (roleUserBeforeEditQuery *RoleUserBeforeEditQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -106,8 +106,8 @@ func (rolesService *RolesService) RoleList(roleListQuery *query.RoleListQuery) (
result := []dto.RoleItem{}
for _, v := range roleList.Roles {
result = append(result, dto.RoleItem{
RoleId: strconv.Itoa(v.RoleID),
OrgId: strconv.Itoa(v.OrgID),
RoleId: strconv.Itoa(int(v.RoleID)),
OrgId: strconv.Itoa(int(v.OrgID)),
RoleName: v.RoleName,
Describe: v.Desc,
OrgName: v.Ext.OrgName,
... ... @@ -121,6 +121,19 @@ func (rolesService *RolesService) RoleList(roleListQuery *query.RoleListQuery) (
// 编辑角色关联权限菜单的前置准备数据
func (rolesService *RolesService) RoleMenuBeforeEdit(roleMenuBeforeEditQuery *query.RoleMenuBeforeEditQuery) (interface{}, error) {
//creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
// roleMenuBeforeEditQuery.Operator.CompanyId,
// roleMenuBeforeEditQuery.Operator.OrgId,
// roleMenuBeforeEditQuery.Operator.UserId)
//roleId, _ := strconv.Atoi(roleMenuBeforeEditQuery.RoleId)
//roles, err := creationUserGateway.RoleSearch(allied_creation_user.ReqRoleSearch{
// OrgId: roleMenuBeforeEditQuery.Operator.OrgId,
// Limit: 999,
// RoleType: 1,
//})
//if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
return nil, nil
}
... ... @@ -131,11 +144,10 @@ func (rolesService *RolesService) RoleUserBeforeEdit(roleUserBeforeEditQuery *qu
roleUserBeforeEditQuery.Operator.CompanyId,
roleUserBeforeEditQuery.Operator.OrgId,
roleUserBeforeEditQuery.Operator.UserId)
//roleId, _ := strconv.Atoi(roleUserBeforeEditQuery.RoleId)
roleId, _ := strconv.Atoi(roleUserBeforeEditQuery.RoleId)
roles, err := creationUserGateway.RoleSearch(allied_creation_user.ReqRoleSearch{
OrgId: roleUserBeforeEditQuery.Operator.OrgId,
Limit: 100,
Limit: 999,
RoleType: 1,
})
if err != nil {
... ... @@ -151,6 +163,19 @@ func (rolesService *RolesService) RoleUserBeforeEdit(roleUserBeforeEditQuery *qu
"orgs": orgs.Orgs,
"roles": roles.Roles,
}
// 有传入角色ID才返回关联角色用户数据
if roleId > 0 {
relatedUser, err := creationUserGateway.RoleGetRelatedUser(allied_creation_user.ReqRoleGetRelatedUser{
RoleId: int64(roleId),
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
result["notInRoleUser"] = relatedUser.NotInRoleUser
result["roleUser"] = relatedUser.RoleUser
}
return result, nil
}
... ... @@ -186,14 +211,14 @@ func (rolesService *RolesService) RoleRemove(roleRemoveCommand *command.RoleRemo
roleRemoveCommand.Operator.UserId)
var roleIds []int64
for _, v := range roleRemoveCommand.RoleId {
for _, v := range roleRemoveCommand.RoleIds {
id, err := strconv.Atoi(v)
if err == nil {
roleIds = append(roleIds, int64(id))
}
}
_, err := creationUserGateway.RoleRemove(allied_creation_user.ReqRoleRemove{
//TODO 修改 为 切片类型
roleIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -220,7 +245,7 @@ func (rolesService *RolesService) RoleUserAdd(roleUserAddCommand *command.RoleUs
UserIds: userIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return roleUserAddCommand, err
}
... ... @@ -244,15 +269,27 @@ func (rolesService *RolesService) RoleUserDelete(roleUserDeleteCommand *command.
UserIds: userIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return roleUserDeleteCommand, err
}
// 角色下关联用户的数据
// 角色下关联用户的数据 (暂时不需要这个)
func (rolesService *RolesService) RoleUserInfo(roleUserInfoQuery *query.RoleUserInfoQuery) (interface{}, error) {
//TODO
return nil, nil
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
roleUserInfoQuery.Operator.CompanyId,
roleUserInfoQuery.Operator.OrgId,
roleUserInfoQuery.Operator.UserId)
relatedUser, err := creationUserGateway.RoleGetRelatedUser(allied_creation_user.ReqRoleGetRelatedUser{
RoleId: roleUserInfoQuery.RoleId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var result = make(map[string]interface{})
result["notInRoleUser"] = relatedUser.NotInRoleUser
result["roleUser"] = relatedUser.RoleUser
return result, nil
}
func NewRolesService(options map[string]interface{}) *RolesService {
... ...
... ... @@ -439,7 +439,7 @@ func (usersService *UsersService) SelectorCompanyRole(selectorQuery *query.Compa
)
for _, v := range result.Roles {
item = dto.UserRole{
RoleID: strconv.Itoa(v.RoleID),
RoleID: strconv.Itoa(int(v.RoleID)),
RoleName: v.RoleName,
OrgName: v.Ext.OrgName,
Descript: v.Desc,
... ...
... ... @@ -200,8 +200,8 @@ func (gateway HttplibAlliedCreationUser) RoleUpdate(param ReqRoleUpdate) (*DataR
// RoleRemove 移除角色
func (gateway HttplibAlliedCreationUser) RoleRemove(param ReqRoleRemove) (*DataRoleRemove, error) {
urlStr := gateway.baseUrL + "/role/" + strconv.FormatInt(param.RoleId, 10)
method := "delete"
urlStr := gateway.baseUrL + "/role/batch-delete"
method := "post"
req := gateway.CreateRequest(urlStr, method)
log.Logger.Debug("向用户模块请求数据:移除角色。", map[string]interface{}{
"api": method + ":" + urlStr,
... ...
... ... @@ -43,7 +43,7 @@ type (
DataOrgGetSubDepartment struct {
Orgs []struct {
OrgID int `json:"orgId"`
OrgID Int64String `json:"orgId"`
//CompanyID int `json:"companyId"`
//CreatedAt time.Time `json:"createdAt"`
//UpdatedAt time.Time `json:"updatedAt"`
... ...
package allied_creation_user
import (
"fmt"
"strconv"
)
//################角色模块##################
type Int64String int64
func (t Int64String) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf(`"%d"`, t)
return []byte(stamp), nil
}
func (t Int64String) UnMarshalJSON(data []byte) error {
v, err := strconv.ParseInt(string(data), 10, 64)
t = Int64String(v)
return err
}
//搜索角色列表
type (
... ... @@ -22,10 +38,10 @@ type (
DataRoleSearch struct {
Count int64
Roles []struct {
AccessMenus []int `json:"accessMenus"`
CompanyID int `json:"companyId"`
CreatedAt string `json:"createdAt"`
Desc string `json:"desc"`
AccessMenus []int `json:"accessMenus"`
CompanyID Int64String `json:"companyId"`
CreatedAt string `json:"createdAt"`
Desc string `json:"desc"`
Ext struct {
DepName string `json:"depName"`
OrgName string `json:"orgName"`
... ... @@ -33,11 +49,11 @@ type (
Phone string `json:"phone"`
UserName string `json:"userName"`
} `json:"ext"`
OrgID int `json:"orgId"`
RoleID int `json:"roleId"`
RoleName string `json:"roleName"`
RoleType int `json:"roleType"`
UpdatedAt string `json:"updatedAt"`
OrgID Int64String `json:"orgId"`
RoleID Int64String `json:"roleId"`
RoleName string `json:"roleName"`
RoleType int `json:"roleType"`
UpdatedAt string `json:"updatedAt"`
} `json:"roles"`
}
)
... ... @@ -121,7 +137,7 @@ type (
//移除角色
type (
ReqRoleRemove struct {
RoleId int64 `json:"roleId"`
RoleIds []int64 `json:"roleIds"`
}
DataRoleRemove struct {
... ... @@ -138,14 +154,18 @@ type (
DataRoleGetRelatedUser struct {
NotInRoleUser []struct {
DepartmentName string `json:"departmentName"`
UserID int `json:"userId"`
UserName string `json:"userName"`
DepartmentId Int64String `json:"departmentId"`
DepartmentName string `json:"departmentName"`
UserID Int64String `json:"userId"`
UserName string `json:"userName"`
UserCode string `json:"userCode"`
} `json:"notInRoleUser"`
RoleUser []struct {
DepartmentName string `json:"departmentName"`
UserID int `json:"userId"`
UserName string `json:"userName"`
DepartmentId Int64String `json:"departmentId"`
DepartmentName string `json:"departmentName"`
UserID Int64String `json:"userId"`
UserName string `json:"userName"`
UserCode string `json:"userCode"`
} `json:"roleUser"`
}
)
... ...
... ... @@ -81,6 +81,8 @@ func (controller *RolesController) RoleUserBeforeEdit() {
rolesService := service.NewRolesService(nil)
roleUserBeforeEditQuery := &query.RoleUserBeforeEditQuery{}
roleUserBeforeEditQuery.Operator = controller.GetOperator()
roleId := controller.GetString("roleId")
roleUserBeforeEditQuery.RoleId = roleId
data, err := rolesService.RoleUserBeforeEdit(roleUserBeforeEditQuery)
controller.Response(data, err)
}
... ... @@ -89,6 +91,7 @@ func (controller *RolesController) RoleMenuBeforeEdit() {
rolesService := service.NewRolesService(nil)
roleMenuBeforeEditQuery := &query.RoleMenuBeforeEditQuery{}
roleMenuBeforeEditQuery.Operator = controller.GetOperator()
controller.Unmarshal(roleMenuBeforeEditQuery)
data, err := rolesService.RoleMenuBeforeEdit(roleMenuBeforeEditQuery)
controller.Response(data, err)
}
... ... @@ -103,3 +106,12 @@ func (controller *RolesController) RoleMenuEdit() {
data, err := rolesService.RoleMenuEdit(roleMenuEditQuery)
controller.Response(data, err)
}
func (controller *RolesController) RoleDelete() {
rolesService := service.NewRolesService(nil)
roleRemoveCommand := &command.RoleRemoveCommand{}
controller.Unmarshal(roleRemoveCommand)
roleRemoveCommand.Operator = controller.GetOperator()
data, err := rolesService.RoleRemove(roleRemoveCommand)
controller.Response(data, err)
}
... ...
... ... @@ -11,9 +11,10 @@ func init() {
web.Router("/v1/web/roles/search", &web_client.RolesController{}, "Post:RoleList")
web.Router("/v1/web/roles/:roleId", &web_client.RolesController{}, "Get:RoleGet")
web.Router("/v1/web/roles/role-user/:roleId", &web_client.RolesController{}, "Get:RoleUserInfo")
web.Router("/v1/web/roles/role-user", &web_client.RolesController{}, "Post:RoleUserAdd")
web.Router("/v1/web/roles/role-user", &web_client.RolesController{}, "Delete:RoleUserDelete")
web.Router("/v1/web/roles/role-user/assign", &web_client.RolesController{}, "Post:RoleUserAdd")
web.Router("/v1/web/roles/role-user/unassign", &web_client.RolesController{}, "Post:RoleUserDelete")
web.Router("/v1/web/roles/role-user/before-edit", &web_client.RolesController{}, "Get:RoleUserBeforeEdit")
web.Router("/v1/web/roles/role-menu/before-edit", &web_client.RolesController{}, "Get:RoleMenuBeforeEdit")
web.Router("/v1/web/roles/role-menu/:roleId", &web_client.RolesController{}, "Put:RoleMenuEdit")
web.Router("/v1/web/roles/batch-delete", &web_client.RolesController{}, "Post:RoleDelete")
}
... ...