作者 tangxuhui

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway into dev

# Conflicts:
#	lastupdate.tmp
/go.sum
/*.exe
.idea
\ No newline at end of file
.idea
/lastupdate.tmp
... ...
{"D:\\workspaceGo\\src\\allied-creation-gateway\\pkg\\port\\beego\\routers":1627895012887669600}
\ No newline at end of file
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type BatchDeleteMenuCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 菜单ID列表
MenuIds []int64 `cname:"菜单ID列表" json:"menuIds,omitempty"`
}
func (batchDeleteMenuCommand *BatchDeleteMenuCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchDeleteMenuCommand *BatchDeleteMenuCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchDeleteMenuCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchDeleteMenuCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type BatchEnableMenuCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 菜单ID列表
MenuIds []int64 `cname:"菜单ID列表" json:"menuIds,omitempty"`
// 菜单状态
Status int `cname:"菜单状态" json:"status,omitempty"`
}
func (batchEnableMenuCommand *BatchEnableMenuCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchEnableMenuCommand *BatchEnableMenuCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchEnableMenuCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchEnableMenuCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type CreateMenuCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 父级id
ParentId int64 `json:"parentId,omitempty"`
// 菜单名称
MenuName string `json:"menuName" valid:"Required"`
// 菜单编码 SYSTEM_USER_EDIT / 100101 (字符编码)
Code string `json:"code" valid:"Required"`
// 权限编码 user:edit
AccessCode string `json:"accessCode"`
// 菜单类型 (目录catalog、菜单menu、按钮button)
MenuType string `json:"menuType" valid:"Required"`
// 菜单图标
Icon string `json:"icon,omitempty"`
// 排序
Sort int `json:"sort" valid:"Required"`
// 菜单说明
Desc string `json:"desc,omitempty"`
// 菜单是否公开状态,[2:隐藏],[1:显示],默认显示
IsPublish int `json:"isPublish" valid:"Required"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus" `
}
func (createMenuCommand *CreateMenuCommand) Valid(validation *validation.Validation) {
}
func (createMenuCommand *CreateMenuCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createMenuCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
//valid := validation.Validation{}
//b, err := valid.Valid(createMenuCommand)
//if err != nil {
// return err
//}
//if !b {
// elem := reflect.TypeOf(createMenuCommand).Elem()
// for _, validErr := range valid.Errors {
// field, isExist := elem.FieldByName(validErr.Field)
// if isExist {
// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
// } else {
// return fmt.Errorf(validErr.Message)
// }
// }
//}
//return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type RemoveMenuCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 菜单编号
MenuId int64 `json:"menuId" valid:"Required"`
}
func (removeMenuCommand *RemoveMenuCommand) Valid(validation *validation.Validation) {
}
func (removeMenuCommand *RemoveMenuCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeMenuCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type UpdateMenuCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 菜单编号
MenuId int64 `json:"menuId" valid:"Required"`
// 父级id
ParentId int64 `json:"parentId,omitempty"`
// 菜单名称
MenuName string `json:"menuName" valid:"Required"`
// 菜单编码 SYSTEM_USER_EDIT / 100101 (字符编码)
Code string `json:"code" valid:"Required"`
// 权限编码 user:edit
AccessCode string `json:"accessCode,omitempty"`
// 菜单类型 (目录catalog、菜单menu、按钮button)
MenuType string `json:"menuType" valid:"Required"`
// 菜单图标
Icon string `json:"icon,omitempty"`
// 排序
Sort int `json:"sort" valid:"Required"`
// 菜单说明
Desc string `json:"desc,omitempty"`
// 菜单是否公开状态,[0:隐藏],[1:显示],默认显示
IsPublish int `json:"isPublish,omitempty"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus"`
}
func (updateMenuCommand *UpdateMenuCommand) Valid(validation *validation.Validation) {
}
func (updateMenuCommand *UpdateMenuCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateMenuCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type GetMenuQuery struct {
//操作人
Operator domain.Operator `json:"-"`
// 菜单编号
MenuId int64 `json:"menuId" valid:"Required"`
}
func (getMenuQuery *GetMenuQuery) Valid(validation *validation.Validation) {
}
func (getMenuQuery *GetMenuQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getMenuQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type ListMenuQuery struct {
//操作人
Operator domain.Operator `json:"-"`
// 菜单类别 web app
MenuCategory string `json:"menuCategory,omitempty"`
// 菜单父级id 0:查询所有 n:parent_id为n的菜单列表
ParentId int64 `json:"parentId,omitempty"`
// 菜单名称过滤
MenuName string `json:"menuName,omitempty"`
// 结构类型 树型:tree 列表型:list
StructType string `json:"structType,omitempty"`
// 查询偏离量
Offset int `json:"offset"`
// 查询限制
Limit int `json:"limit"`
// web分页
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
}
func (listMenuQuery *ListMenuQuery) Valid(validation *validation.Validation) {
if listMenuQuery.PageSize > 0 {
listMenuQuery.Limit = listMenuQuery.PageSize
listMenuQuery.Offset = (listMenuQuery.PageNumber - 1) * listMenuQuery.PageSize
}
}
func (listMenuQuery *ListMenuQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listMenuQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
// 菜单服务
type MenuService struct {
}
// 创建菜单服务
func (menuService *MenuService) CreateMenu(createMenuCommand *command.CreateMenuCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
createMenuCommand.Operator)
result, err := creationUserGateway.MenusCreate(allied_creation_user.ReqMenus{
ParentId: createMenuCommand.ParentId,
MenuName: createMenuCommand.MenuName,
Code: createMenuCommand.Code,
AccessCode: createMenuCommand.AccessCode,
MenuType: createMenuCommand.MenuType,
Icon: createMenuCommand.Icon,
Sort: createMenuCommand.Sort,
Desc: createMenuCommand.Desc,
IsPublish: createMenuCommand.IsPublish,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 返回菜单服务
func (menuService *MenuService) GetMenu(getMenuQuery *query.GetMenuQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
getMenuQuery.Operator)
result, err := creationUserGateway.MenusGet(allied_creation_user.ReqMenusGet{
MenuId: getMenuQuery.MenuId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 返回菜单服务列表
func (menuService *MenuService) ListMenu(listMenuQuery *query.ListMenuQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
listMenuQuery.Operator)
result, err := creationUserGateway.MenusSearch(allied_creation_user.ReqMenusSearch{
MenuCategory: listMenuQuery.MenuCategory,
ParentId: listMenuQuery.ParentId,
MenuName: listMenuQuery.MenuName,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 移除菜单服务
func (menuService *MenuService) RemoveMenu(removeMenuCommand *command.RemoveMenuCommand) (interface{}, error) {
return struct{}{}, nil
}
// 更新菜单服务
func (menuService *MenuService) UpdateMenu(updateMenuCommand *command.UpdateMenuCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
updateMenuCommand.Operator)
result, err := creationUserGateway.MenusUpdate(allied_creation_user.ReqMenusUpdate{
MenuId: updateMenuCommand.MenuId,
ParentId: updateMenuCommand.ParentId,
MenuName: updateMenuCommand.MenuName,
Code: updateMenuCommand.Code,
AccessCode: updateMenuCommand.AccessCode,
MenuType: updateMenuCommand.MenuType,
Icon: updateMenuCommand.Icon,
Sort: updateMenuCommand.Sort,
Desc: updateMenuCommand.Desc,
IsPublish: updateMenuCommand.IsPublish,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 批量删除菜单
func (menuService *MenuService) BatchDeleteMenu(batchDeleteMenu *command.BatchDeleteMenuCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
batchDeleteMenu.Operator)
result, err := creationUserGateway.MenusBatchDelete(allied_creation_user.ReqMenusBatchDelete{
MenuIds: batchDeleteMenu.MenuIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 批量启用菜单
func (menuService *MenuService) BatchEnableMenu(batchEnableMenu *command.BatchEnableMenuCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
batchEnableMenu.Operator)
result, err := creationUserGateway.MenusBatchEnable(allied_creation_user.ReqMenusBatchEnable{
MenuIds: batchEnableMenu.MenuIds,
Status: batchEnableMenu.Status,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
func NewMenuService(options map[string]interface{}) *MenuService {
newMenuService := &MenuService{}
return newMenuService
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type OrgGetSubDepartmentQuery struct {
//操作人
Operator domain.Operator `json:"-"`
// 组织ID
OrgId string `json:"orgId" valid:"Required"`
}
func (orgGetQuery *OrgGetSubDepartmentQuery) Valid(validation *validation.Validation) {
}
func (orgGetQuery *OrgGetSubDepartmentQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(orgGetQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -131,6 +131,22 @@ func (orgsService *OrgsService) OrgUpdate(orgUpdateCommand *command.OrgUpdateCom
return orgUpdateCommand, nil
}
// 返回组织管理
func (orgsService *OrgsService) OrgGetSubDepartment(orgGetQuery *query.OrgGetSubDepartmentQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgGetQuery.Operator)
orgId, _ := strconv.Atoi(orgGetQuery.OrgId)
result, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{
OrgId: int64(orgId),
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"list": result.Orgs,
}, nil
}
func NewOrgsService(options map[string]interface{}) *OrgsService {
newOrgsService := &OrgsService{}
return newOrgsService
... ...
... ... @@ -16,15 +16,15 @@ type CompanyUserInfo struct {
Phone string `json:"phone"`
Avatar string `json:"avatar"`
EnableStatus int `json:"enableStatus"`
UsersCode string `json:"usersCode"`
UsersID string `json:"usersId"`
UsersName string `json:"usersName"`
UsersCode string `json:"userCode"`
UsersID string `json:"userId"`
UsersName string `json:"userName"`
OrgID string `json:"orgId"`
OrgName string `json:"orgName"`
DepartmentID string `json:"departmentId"`
DepartmentName string `json:"departmentName"`
UsersOrg []UserOrg `json:"usersOrg"`
UsersRole []UserRole `json:"usersRole"`
UsersOrg []UserOrg `json:"userOrg"`
UsersRole []UserRole `json:"userRole"`
}
type UserOrg struct {
... ... @@ -35,10 +35,10 @@ type UserOrg struct {
}
type UserRole struct {
RoleID string `json:"roleId"`
RoleName string `json:"roleName"`
OrgName string `json:"orgName"`
Descript string `json:"descript"`
RoleID string `json:"roleId"`
RoleName string `json:"roleName"`
OrgName string `json:"orgName"`
Description string `json:"desc"`
}
type UserMenu struct {
... ...
... ... @@ -31,11 +31,13 @@ func (usersService *UsersService) CompanyUserGet(companyUserGetQuery *query.Comp
UserId: userid,
})
if err != nil {
return nil, err
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{})
resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{
UserId: userid,
})
if err != nil {
return nil, err
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var (
usersOrg []dto.UserOrg
... ... @@ -214,7 +216,7 @@ func (usersService *UsersService) CompanyUserResetPassword(companyUserResetPassw
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return companyUserResetPasswordCommand, err
return "123456", err
}
// 更新公司用户信息
... ... @@ -462,10 +464,10 @@ func (usersService *UsersService) SelectorCompanyRole(selectorQuery *query.Compa
)
for _, v := range result.Roles {
item = dto.UserRole{
RoleID: strconv.Itoa(int(v.RoleID)),
RoleName: v.RoleName,
OrgName: v.Ext.OrgName,
Descript: v.Desc,
RoleID: strconv.Itoa(int(v.RoleID)),
RoleName: v.RoleName,
OrgName: v.Ext.OrgName,
Description: v.Desc,
}
dataList = append(dataList, item)
}
... ...
... ... @@ -42,7 +42,7 @@ func (gateway HttplibAlliedCreationUser) MenusCreate(param ReqMenus) (*DataMenus
// MenusUpdate 更新菜单
func (gateway HttplibAlliedCreationUser) MenusUpdate(param ReqMenusUpdate) (*DataMenusUpdate, error) {
url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.MenusId, 10)
url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.MenuId, 10)
method := "put"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:更新菜单。", map[string]interface{}{
... ... @@ -163,3 +163,65 @@ func (gateway HttplibAlliedCreationUser) MenusSearch(param ReqMenusSearch) (*Dat
err = gateway.GetResponseData(result, &data)
return &data, err
}
// MenusBatchDelete 菜单批量删除
func (gateway HttplibAlliedCreationUser) MenusBatchDelete(param ReqMenusBatchDelete) (*DataMenusBatchDelete, error) {
url := gateway.baseUrL + "/menus/batch-delete"
method := "post"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:菜单批量删除。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("菜单批量删除失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("菜单批量删除失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:菜单批量删除。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析菜单批量删除:%w", err)
}
var data DataMenusBatchDelete
err = gateway.GetResponseData(result, &data)
return &data, err
}
// MenusBatchEnable 菜单批量启用、禁用
func (gateway HttplibAlliedCreationUser) MenusBatchEnable(param ReqMenusBatchEnable) (*DataMenusBatchEnable, error) {
url := gateway.baseUrL + "/menus/batch-enable"
method := "post"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:菜单批量启用、禁用。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("菜单批量启用、禁用失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("菜单批量启用、禁用失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:菜单批量启用、禁用。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析菜单批量启用、禁用:%w", err)
}
var data DataMenusBatchEnable
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
... ... @@ -362,7 +362,7 @@ func (gateway HttplibAlliedCreationUser) UserUpdateBaseInfo(param ReqUserUpdateB
//UserUpdateBaseInfo 返回用户有权限的菜单
func (gateway HttplibAlliedCreationUser) UserAccessMenus(param ReqUserAccessMenus) (*DataUserAccessMenus, error) {
url := fmt.Sprintf("%s%s%d%s", gateway.baseUrL, "/user/", param.UserId, "/base-info")
url := fmt.Sprintf("%s%s%d%s", gateway.baseUrL, "/user/", param.UserId, "/access-menus")
method := "get"
req := gateway.CreateRequest(url, method)
//TODO traceID
... ...
... ... @@ -3,47 +3,189 @@ package allied_creation_user
//创建菜单
type (
ReqMenus struct {
// 父级id
ParentId int64 `json:"parentId,omitempty"`
// 菜单名称
MenuName string `json:"menuName" valid:"Required"`
// 菜单编码 SYSTEM_USER_EDIT / 100101 (字符编码)
Code string `json:"code" valid:"Required"`
// 权限编码 user:edit
AccessCode string `json:"accessCode"`
// 菜单类型 (目录catalog、菜单menu、按钮button)
MenuType string `json:"menuType" valid:"Required"`
// 菜单图标
Icon string `json:"icon,omitempty"`
// 排序
Sort int `json:"sort" valid:"Required"`
// 菜单说明
Desc string `json:"desc,omitempty"`
// 菜单是否公开状态,[2:隐藏],[1:显示],默认显示
IsPublish int `json:"isPublish" valid:"Required"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus" `
}
DataMenus 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"`
MenuType string `json:"menuType"`
Icon string `json:"icon"`
Sort int `json:"sort"`
Category string `json:"category"`
IsPublish int `json:"isPublish"`
ParentMenuName string `json:"parentMenuName"`
}
)
//更新菜单
type (
ReqMenusUpdate struct {
MenusId int64 `json:"menusId"`
// 菜单编号
MenuId int64 `json:"menuId" valid:"Required"`
// 父级id
ParentId int64 `json:"parentId,omitempty"`
// 菜单名称
MenuName string `json:"menuName" valid:"Required"`
// 菜单编码 SYSTEM_USER_EDIT / 100101 (字符编码)
Code string `json:"code" valid:"Required"`
// 权限编码 user:edit
AccessCode string `json:"accessCode,omitempty"`
// 菜单类型 (目录catalog、菜单menu、按钮button)
MenuType string `json:"menuType" valid:"Required"`
// 菜单图标
Icon string `json:"icon,omitempty"`
// 排序
Sort int `json:"sort" valid:"Required"`
// 菜单说明
Desc string `json:"desc,omitempty"`
// 菜单是否公开状态,[0:隐藏],[1:显示],默认显示
IsPublish int `json:"isPublish,omitempty"`
}
DataMenusUpdate 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"`
MenuType string `json:"menuType"`
Icon string `json:"icon"`
Sort int `json:"sort"`
Category string `json:"category"`
IsPublish int `json:"isPublish"`
ParentMenuName string `json:"parentMenuName"`
}
)
//移除菜单
type (
ReqMenusRemove struct {
MenuId int64 `json:"roleId"`
MenuId int64
}
DataMenusRemove 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"`
MenuType string `json:"menuType"`
Icon string `json:"icon"`
Sort int `json:"sort"`
Category string `json:"category"`
IsPublish int `json:"isPublish"`
ParentMenuName string `json:"parentMenuName"`
}
)
//返回菜单
type (
ReqMenusGet struct {
MenuId int64 `json:"menuId"`
MenuId int64
}
DataMenusGet 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"`
MenuType string `json:"menuType"`
Icon string `json:"icon"`
Sort int `json:"sort"`
Category string `json:"category"`
IsPublish int `json:"isPublish"`
ParentMenuName string `json:"parentMenuName"`
}
)
//返回菜单列表
type (
ReqMenusSearch struct {
// 菜单类别 web app
MenuCategory string `json:"menuCategory,omitempty"`
// 菜单父级id 0:查询所有 n:parent_id为n的菜单列表
ParentId int64 `json:"parentId,omitempty"`
// 菜单名称过滤
MenuName string `json:"menuName,omitempty"`
// 结构类型 树型:tree 列表型:list
StructType string `json:"structType,omitempty"`
// 查询偏离量
Offset int `json:"offset"`
// 查询限制
Limit int `json:"limit"`
// web分页
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
}
DataMenusSearch struct {
Count int `json:"count"`
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,omitempty"`
ParentPath string `json:"parentPath,omitempty"`
} `json:"menus"`
}
)
type (
ReqMenusBatchDelete struct {
// 菜单ID列表
MenuIds []int64 `cname:"菜单ID列表" json:"menuIds,omitempty"`
}
DataMenusBatchDelete struct {
}
)
type (
ReqMenusBatchEnable struct {
// 菜单ID列表
MenuIds []int64 `cname:"菜单ID列表" json:"menuIds,omitempty"`
// 菜单状态
Status int `cname:"菜单状态" json:"status,omitempty"`
}
DataMenusBatchEnable struct {
}
)
... ...
package backgroud_client
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type baseController struct {
beego.BaseController
}
func (controller *baseController) returnPageListData(count int64, data interface{}, err error, pageNumber int) {
dataMap := map[string]interface{}{
"grid": map[string]interface{}{
"total": count,
//"pageNumber": pageNumber,
"list": data,
},
}
controller.Response(dataMap, err)
}
func (controller *baseController) GetUserId() int64 {
return 1
}
func (controller *baseController) GetCompanyId() int64 {
return 1
}
func (controller *baseController) GetUserBaseId() int64 {
return 1
}
func (controller *baseController) GetOrgId() int64 {
return 1
}
func (controller *baseController) GetOperator() domain.Operator {
return domain.Operator{
UserId: 9,
CompanyId: 23,
OrgId: 45,
UserBaseId: 1,
}
}
... ...
package backgroud_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/service"
)
type MenuController struct {
baseController
}
func (controller *MenuController) CreateMenu() {
menuService := service.NewMenuService(nil)
createMenuCommand := &command.CreateMenuCommand{}
controller.Unmarshal(createMenuCommand)
createMenuCommand.Operator = controller.GetOperator()
data, err := menuService.CreateMenu(createMenuCommand)
controller.Response(data, err)
}
func (controller *MenuController) UpdateMenu() {
menuService := service.NewMenuService(nil)
updateMenuCommand := &command.UpdateMenuCommand{}
controller.Unmarshal(updateMenuCommand)
Id, _ := controller.GetInt64(":menuId")
updateMenuCommand.MenuId = Id
updateMenuCommand.Operator = controller.GetOperator()
data, err := menuService.UpdateMenu(updateMenuCommand)
controller.Response(data, err)
}
func (controller *MenuController) GetMenu() {
menuService := service.NewMenuService(nil)
getMenuQuery := &query.GetMenuQuery{}
Id, _ := controller.GetInt64(":menuId")
getMenuQuery.MenuId = Id
getMenuQuery.Operator = controller.GetOperator()
data, err := menuService.GetMenu(getMenuQuery)
controller.Response(data, err)
}
func (controller *MenuController) RemoveMenu() {
menuService := service.NewMenuService(nil)
removeMenuCommand := &command.RemoveMenuCommand{}
controller.Unmarshal(removeMenuCommand)
Id, _ := controller.GetInt64(":menuId")
removeMenuCommand.MenuId = Id
removeMenuCommand.Operator = controller.GetOperator()
data, err := menuService.RemoveMenu(removeMenuCommand)
controller.Response(data, err)
}
func (controller *MenuController) ListMenu() {
menuService := service.NewMenuService(nil)
listMenuQuery := &query.ListMenuQuery{}
offset, _ := controller.GetInt("offset")
listMenuQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listMenuQuery.Limit = limit
listMenuQuery.MenuCategory = controller.GetString("menuCategory")
listMenuQuery.ParentId, _ = controller.GetInt64("parentId", 0)
listMenuQuery.MenuName = controller.GetString("menuName")
listMenuQuery.StructType = controller.GetString("structType")
listMenuQuery.Operator = controller.GetOperator()
data, err := menuService.ListMenu(listMenuQuery)
controller.Response(data, err)
}
func (controller *MenuController) SearchMenu() {
menuService := service.NewMenuService(nil)
listMenuQuery := &query.ListMenuQuery{}
controller.Unmarshal(listMenuQuery)
listMenuQuery.Offset = 0
listMenuQuery.Limit = 0
listMenuQuery.Operator = controller.GetOperator()
data, err := menuService.ListMenu(listMenuQuery)
controller.Response(data, err)
}
func (controller *MenuController) BatchDeleteMenu() {
menuService := service.NewMenuService(nil)
batchDeleteMenuCommand := &command.BatchDeleteMenuCommand{}
controller.Unmarshal(batchDeleteMenuCommand)
batchDeleteMenuCommand.Operator = controller.GetOperator()
data, err := menuService.BatchDeleteMenu(batchDeleteMenuCommand)
controller.Response(data, err)
}
func (controller *MenuController) BatchEnableMenu() {
menuService := service.NewMenuService(nil)
batchEnableMenu := &command.BatchEnableMenuCommand{}
controller.Unmarshal(batchEnableMenu)
batchEnableMenu.Operator = controller.GetOperator()
data, err := menuService.BatchEnableMenu(batchEnableMenu)
controller.Response(data, err)
}
... ...
... ... @@ -57,3 +57,12 @@ func (controller *OrgsController) OrgEnable() {
data, err := orgsService.OrgEnable(orgEnableCommand)
controller.Response(data, err)
}
func (controller *OrgsController) OrgGetSubDepartment() {
orgsService := service.NewOrgsService(nil)
orgGetSubDepartmentQuery := &query.OrgGetSubDepartmentQuery{}
controller.Unmarshal(orgGetSubDepartmentQuery)
orgGetSubDepartmentQuery.Operator = controller.GetOperator()
data, err := orgsService.OrgGetSubDepartment(orgGetSubDepartmentQuery)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/backgroud_client"
)
func init() {
web.Router("/v1/background/menus/", &backgroud_client.MenuController{}, "Post:CreateMenu")
web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Put:UpdateMenu")
web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Get:GetMenu")
//web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Delete:RemoveMenu")
//web.Router("/v1/background/menus/search", &backgroud_client.MenuController{}, "Get:ListMenu")
web.Router("/v1/background/menus/search", &backgroud_client.MenuController{}, "Post:SearchMenu")
web.Router("/v1/background/menus/batch-delete", &backgroud_client.MenuController{}, "Post:BatchDeleteMenu")
web.Router("/v1/background/menus/batch-enable", &backgroud_client.MenuController{}, "Post:BatchEnableMenu")
}
... ...
... ... @@ -11,4 +11,5 @@ func init() {
web.Router("/v1/web/orgs/search", &web_client.OrgsController{}, "Post:OrgList")
web.Router("/v1/web/orgs/:orgId", &web_client.OrgsController{}, "Get:OrgGet")
web.Router("/v1/web/orgs/enable", &web_client.OrgsController{}, "Post:OrgEnable")
web.Router("/v1/web/orgs/departments", &web_client.OrgsController{}, "Post:OrgGetSubDepartment")
}
... ...