作者 tangxuhui
/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":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) {
... ...
... ... @@ -5,13 +5,15 @@ 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"` //角色类型 1.普通角色 1024:超级管理员
Ext Ext `json:"ext"`
}
type RoleUser struct {
DepartmentName string `json:"departmentName"`
UserId string `json:"userId"`
type Ext struct {
DepName string `json:"depName"`
OrgName string `json:"orgName"`
ParentDepName string `json:"parentDepName"`
Phone string `json:"phone"`
UserName string `json:"userName"`
}
... ...
... ... @@ -2,13 +2,16 @@ 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"`
RoleId string `json:"roleId" valid:"Required"`
}
func (roleMenuBeforeEditQuery *RoleMenuBeforeEditQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -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" valid:"Required"`
}
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
}
... ... @@ -93,12 +106,13 @@ 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,
RoleType: v.RoleType,
Ext: v.Ext,
})
}
var cnt int64 = roleList.Count
... ... @@ -107,14 +121,62 @@ 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
}
// 编辑角色关联用户的前置准备数据
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: 999,
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,
}
// 有传入角色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
}
// 角色编辑关联菜单权限
... ... @@ -149,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.RoleBatchRemove(allied_creation_user.ReqRoleBatchRemove{
RoleIds: roleIds,
_, err := creationUserGateway.RoleRemove(allied_creation_user.ReqRoleRemove{
roleIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -183,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
}
... ... @@ -207,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,
... ...
... ... @@ -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") != "" {
... ...
... ... @@ -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,
... ...
... ... @@ -42,6 +42,22 @@ type (
}
DataOrgGetSubDepartment struct {
Orgs []struct {
OrgID Int64String `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"`
}
)
... ...
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 (
... ... @@ -9,21 +25,21 @@ 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"`
InOrgIds []int `json:"inOrgIds"`
OrgId int
// 组织ID
OrgId int64 `json:"orgId"`
}
DataRoleSearch struct {
Count int64
Roles []struct {
AccessMenus []int `json:"accessMenus"`
CompanyID int `json:"companyId"`
CompanyID Int64String `json:"companyId"`
CreatedAt string `json:"createdAt"`
Desc string `json:"desc"`
Ext struct {
... ... @@ -33,12 +49,12 @@ type (
Phone string `json:"phone"`
UserName string `json:"userName"`
} `json:"ext"`
OrgID int `json:"orgId"`
RoleID int `json:"roleId"`
OrgID Int64String `json:"orgId"`
RoleID Int64String `json:"roleId"`
RoleName string `json:"roleName"`
RoleType int `json:"roleType"` //角色类型 1.普通角色 1024:超级管理员
RoleType int `json:"roleType"`
UpdatedAt string `json:"updatedAt"`
} `json:"role"`
} `json:"roles"`
}
)
... ... @@ -49,11 +65,10 @@ type (
}
DataRoleGet struct {
Role struct {
AccessMenus []int `json:"accessMenus"`
CompanyID int `json:"companyId"`
CreatedAt string `json:"createdAt"`
Desc int `json:"desc"`
Desc string `json:"desc"`
Ext struct {
DepName string `json:"depName"`
OrgName string `json:"orgName"`
... ... @@ -66,7 +81,6 @@ type (
RoleName string `json:"roleName"`
RoleType int `json:"roleType"`
UpdatedAt string `json:"updatedAt"`
} `json:"role"`
}
)
... ... @@ -123,7 +137,7 @@ type (
//移除角色
type (
ReqRoleRemove struct {
RoleId int64 `json:"roleId"`
RoleIds []int64 `json:"roleIds"`
}
DataRoleRemove struct {
... ... @@ -150,14 +164,18 @@ type (
DataRoleGetRelatedUser struct {
NotInRoleUser []struct {
DepartmentId Int64String `json:"departmentId"`
DepartmentName string `json:"departmentName"`
UserID int `json:"userId"`
UserID Int64String `json:"userId"`
UserName string `json:"userName"`
UserCode string `json:"userCode"`
} `json:"notInRoleUser"`
RoleUser []struct {
DepartmentId Int64String `json:"departmentId"`
DepartmentName string `json:"departmentName"`
UserID int `json:"userId"`
UserID Int64String `json:"userId"`
UserName string `json:"userName"`
UserCode string `json:"userCode"`
} `json:"roleUser"`
}
)
... ... @@ -169,6 +187,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))
}
... ...
... ... @@ -13,7 +13,7 @@ func (controller *baseController) returnPageListData(count int64, data interface
dataMap := map[string]interface{}{
"grid": map[string]interface{}{
"total": count,
"pageNumber": pageNumber,
//"pageNumber": pageNumber,
"list": data,
},
}
... ... @@ -38,9 +38,9 @@ func (controller *baseController) GetOrgId() int64 {
func (controller *baseController) GetOperator() domain.Operator {
return domain.Operator{
UserId: 1,
CompanyId: 1,
OrgId: 1,
UserId: 9,
CompanyId: 23,
OrgId: 45,
UserBaseId: 1,
}
}
... ...
... ... @@ -80,6 +80,9 @@ func (controller *RolesController) RoleUserDelete() {
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)
}
... ... @@ -87,6 +90,8 @@ func (controller *RolesController) RoleUserBeforeEdit() {
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)
}
... ... @@ -101,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")
}
... ...