作者 yangfu

角色服务修改

/go.sum
/*.exe
.idea
\ No newline at end of file
... ...
{"D:\\workspaceGo\\src\\allied-creation-gateway\\pkg\\port\\beego":1627550783476629200}
\ No newline at end of file
{"F:\\go\\src\\allied-creation\\allied-creation-gateway\\pkg\\port\\beego\\routers":1627552127430848800}
\ No newline at end of file
... ...
... ... @@ -5,7 +5,16 @@ type RoleItem struct {
RoleId string `json:"roleId"`
OrgId string `json:"orgId"`
RoleName string `json:"roleName"`
Describe string `json:"describe"`
Describe string `json:"desc"`
OrgName string `json:"orgName"`
RoleType int `json:"roleType"`
Ext Ext `json:"ext"`
}
type Ext struct {
DepName string `json:"depName"`
OrgName string `json:"orgName"`
ParentDepName string `json:"parentDepName"`
Phone string `json:"phone"`
UserName string `json:"userName"`
}
... ...
... ... @@ -2,11 +2,14 @@ package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type RoleMenuBeforeEditQuery struct {
// 操作人
Operator domain.Operator `json:"-"`
// 角色ID
RoleId int64 `json:"roleId" valid:"Required"`
}
... ...
... ... @@ -2,15 +2,20 @@ package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type RoleUserBeforeEditQuery struct {
// 操作人
Operator domain.Operator `json:"-"`
// 角色ID
RoleId string `json:"roleId"`
}
func (roleUserBeforeEditQuery *RoleUserBeforeEditQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (roleUserBeforeEditQuery *RoleUserBeforeEditQuery) ValidateQuery() error {
... ...
... ... @@ -66,11 +66,24 @@ func (rolesService *RolesService) RoleGet(roleGetQuery *query.RoleGetQuery) (int
RoleId: int64(roleId),
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
accessMenus, err := creationUserGateway.RoleGetAccessMenus(allied_creation_user.ReqRoleGetAccessMenus{
RoleId: int64(roleId),
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
relatedUser, err := creationUserGateway.RoleGetRelatedUser(allied_creation_user.ReqRoleGetRelatedUser{
RoleId: int64(roleId),
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
//TODO 补充字段 :权限数据,关联用户数据
result := map[string]interface{}{
"role": roleData.Role,
"role": roleData,
"menus": accessMenus.Menus,
"users": relatedUser.RoleUser,
}
return result, nil
}
... ... @@ -99,6 +112,7 @@ func (rolesService *RolesService) RoleList(roleListQuery *query.RoleListQuery) (
Describe: v.Desc,
OrgName: v.Ext.OrgName,
RoleType: v.RoleType,
Ext: v.Ext,
})
}
var cnt int64 = roleList.Count
... ... @@ -113,8 +127,31 @@ func (rolesService *RolesService) RoleMenuBeforeEdit(roleMenuBeforeEditQuery *qu
// 编辑角色关联用户的前置准备数据
func (rolesService *RolesService) RoleUserBeforeEdit(roleUserBeforeEditQuery *query.RoleUserBeforeEditQuery) (interface{}, error) {
//TODO
return nil, nil
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
roleUserBeforeEditQuery.Operator.CompanyId,
roleUserBeforeEditQuery.Operator.OrgId,
roleUserBeforeEditQuery.Operator.UserId)
//roleId, _ := strconv.Atoi(roleUserBeforeEditQuery.RoleId)
roles, err := creationUserGateway.RoleSearch(allied_creation_user.ReqRoleSearch{
OrgId: roleUserBeforeEditQuery.Operator.OrgId,
Limit: 100,
RoleType: 1,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
orgs, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{
OrgId: roleUserBeforeEditQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
result := map[string]interface{}{
"orgs": orgs.Orgs,
"roles": roles.Roles,
}
return result, nil
}
// 角色编辑关联菜单权限
... ...
... ... @@ -8,7 +8,7 @@ var LOG_LEVEL = "debug"
var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080"
var ALLIED_CREATION_USER_HOST = "http://localhost:8080"
var ALLIED_CREATION_USER_HOST = "http://localhost:8081"
func init() {
if os.Getenv("LOG_LEVEL") != "" {
... ...
... ... @@ -42,6 +42,22 @@ type (
}
DataOrgGetSubDepartment struct {
Orgs []struct {
OrgID int `json:"orgId"`
//CompanyID int `json:"companyId"`
//CreatedAt time.Time `json:"createdAt"`
//UpdatedAt time.Time `json:"updatedAt"`
//DeletedAt time.Time `json:"deletedAt"`
//OrgCode string `json:"orgCode"`
OrgName string `json:"orgName"`
//IsOrg int `json:"isOrg"`
//OrgStatus int `json:"orgStatus"`
//ParentID int `json:"parentId"`
//Ext struct {
// OrgName string `json:"orgName"`
// ParentDepName string `json:"parentDepName"`
//} `json:"ext,omitempty"`
} `json:"orgs"`
}
)
... ...
... ... @@ -9,10 +9,14 @@ type (
Offset int `json:"offset"`
// 查询限制
Limit int `json:"limit"`
// 角色类型 1.普通角色 1024:超级管理员
RoleType int `cname:"角色类型 1.普通角色 1024:超级管理员" json:"roleType,omitempty"`
//组织名称
OrgName string `json:"orgName"`
//角色码名称
RoleName string `json:"roleName"`
// 组织ID
OrgId int64 `json:"orgId"`
}
DataRoleSearch struct {
... ... @@ -34,7 +38,7 @@ type (
RoleName string `json:"roleName"`
RoleType int `json:"roleType"`
UpdatedAt string `json:"updatedAt"`
} `json:"role"`
} `json:"roles"`
}
)
... ... @@ -45,24 +49,22 @@ type (
}
DataRoleGet struct {
Role struct {
AccessMenus []int `json:"accessMenus"`
CompanyID int `json:"companyId"`
CreatedAt string `json:"createdAt"`
Desc int `json:"desc"`
Ext struct {
DepName string `json:"depName"`
OrgName string `json:"orgName"`
ParentDepName string `json:"parentDepName"`
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"`
} `json:"role"`
AccessMenus []int `json:"accessMenus"`
CompanyID int `json:"companyId"`
CreatedAt string `json:"createdAt"`
Desc string `json:"desc"`
Ext struct {
DepName string `json:"depName"`
OrgName string `json:"orgName"`
ParentDepName string `json:"parentDepName"`
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"`
}
)
... ... @@ -135,6 +137,16 @@ type (
}
DataRoleGetRelatedUser struct {
NotInRoleUser []struct {
DepartmentName string `json:"departmentName"`
UserID int `json:"userId"`
UserName string `json:"userName"`
} `json:"notInRoleUser"`
RoleUser []struct {
DepartmentName string `json:"departmentName"`
UserID int `json:"userId"`
UserName string `json:"userName"`
} `json:"roleUser"`
}
)
... ... @@ -145,6 +157,22 @@ type (
}
DataRoleGetAccessMenus struct {
Menus []struct {
MenuID int `json:"menuId"`
ParentID int `json:"parentId"`
MenuName string `json:"menuName"`
MenuAlias string `json:"menuAlias"`
Code string `json:"code"`
AccessCode string `json:"accessCode,omitempty"`
MenuType string `json:"menuType"`
Icon string `json:"icon"`
Sort int `json:"sort"`
Remark string `json:"remark,omitempty"`
Category string `json:"category"`
IsPublish int `json:"isPublish"`
EnableStatus int `json:"enableStatus"`
ParentPath string `json:"parentPath,omitempty"`
} `json:"menus"`
}
)
... ...
... ... @@ -17,7 +17,7 @@ func init() {
web.BConfig.RunMode = "dev"
web.BConfig.Listen.HTTPPort = 8080
web.BConfig.Listen.EnableAdmin = false
web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego"
web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers"
if os.Getenv("RUN_MODE") != "" {
web.BConfig.RunMode = os.Getenv("RUN_MODE")
}
... ... @@ -27,7 +27,7 @@ func init() {
web.BConfig.Listen.HTTPPort = port
}
}
web.InsertFilter("/*", web.BeforeExec, filters.AllowCors())
web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors())
web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(log.Logger))
web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(log.Logger), web.WithReturnOnOutput(false))
}
... ...
... ... @@ -80,6 +80,7 @@ func (controller *RolesController) RoleUserDelete() {
func (controller *RolesController) RoleUserBeforeEdit() {
rolesService := service.NewRolesService(nil)
roleUserBeforeEditQuery := &query.RoleUserBeforeEditQuery{}
roleUserBeforeEditQuery.Operator = controller.GetOperator()
data, err := rolesService.RoleUserBeforeEdit(roleUserBeforeEditQuery)
controller.Response(data, err)
}
... ... @@ -87,6 +88,7 @@ func (controller *RolesController) RoleUserBeforeEdit() {
func (controller *RolesController) RoleMenuBeforeEdit() {
rolesService := service.NewRolesService(nil)
roleMenuBeforeEditQuery := &query.RoleMenuBeforeEditQuery{}
roleMenuBeforeEditQuery.Operator = controller.GetOperator()
data, err := rolesService.RoleMenuBeforeEdit(roleMenuBeforeEditQuery)
controller.Response(data, err)
}
... ...