role_controller.go 5.8 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/role/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/role/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/role/service"
)

type RoleController struct {
	beego.BaseController
}

func (controller *RoleController) CreateRole() {
	roleService := service.NewRoleService(nil)
	createRoleCommand := &command.CreateRoleCommand{}
	Must(controller.Unmarshal(createRoleCommand))
	createRoleCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.CreateRole(createRoleCommand)
	controller.Response(data, err)
}

func (controller *RoleController) UpdateRole() {
	roleService := service.NewRoleService(nil)
	updateRoleCommand := &command.UpdateRoleCommand{}
	controller.Unmarshal(updateRoleCommand)
	roleId, _ := controller.GetInt64(":roleId")
	updateRoleCommand.RoleId = roleId
	updateRoleCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.UpdateRole(updateRoleCommand)
	controller.Response(data, err)
}

func (controller *RoleController) GetRole() {
	roleService := service.NewRoleService(nil)
	getRoleQuery := &query.GetRoleQuery{}
	roleId, _ := controller.GetInt64(":roleId")
	getRoleQuery.RoleId = roleId
	getRoleQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.GetRole(getRoleQuery)
	controller.Response(data, err)
}

func (controller *RoleController) RemoveRole() {
	roleService := service.NewRoleService(nil)
	removeRoleCommand := &command.RemoveRoleCommand{}
	controller.Unmarshal(removeRoleCommand)
	roleId, _ := controller.GetInt64(":roleId")
	removeRoleCommand.RoleId = roleId
	removeRoleCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.RemoveRole(removeRoleCommand)
	controller.Response(data, err)
}

func (controller *RoleController) BatchDeleteRole() {
	roleService := service.NewRoleService(nil)
	removeRoleCommand := &command.BatchDeleteRoleCommand{}
	controller.Unmarshal(removeRoleCommand)
	removeRoleCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.BatchDeleteRole(removeRoleCommand)
	controller.Response(data, err)
}

func (controller *RoleController) ListRole() {
	roleService := service.NewRoleService(nil)
	listRoleQuery := &query.ListRoleQuery{}
	listRoleQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.ListRole(listRoleQuery)
	controller.Response(data, err)
}

func (controller *RoleController) SearchRole() {
	roleService := service.NewRoleService(nil)
	listRoleQuery := &query.ListRoleQuery{}
	Must(controller.Unmarshal(listRoleQuery))
	listRoleQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.ListRole(listRoleQuery)
	controller.Response(data, err)
}

func (controller *RoleController) GetRoleRelatedUsers() {
	roleService := service.NewRoleService(nil)
	getRoleRelatedUsersQuery := &query.GetRoleRelatedUsersQuery{}
	roleId, _ := controller.GetInt64(":roleId")
	getRoleRelatedUsersQuery.RoleId = roleId
	orgId, _ := controller.GetInt64("orgId")
	getRoleRelatedUsersQuery.OrgId = orgId
	departmentId, _ := controller.GetInt64("departmentId")
	getRoleRelatedUsersQuery.DepartmentId = departmentId
	getRoleRelatedUsersQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.GetRoleRelatedUsers(getRoleRelatedUsersQuery)
	controller.Response(data, err)
}

func (controller *RoleController) GetRoleAccessMenus() {
	roleService := service.NewRoleService(nil)
	getRoleAccessMenusQuery := &query.GetRoleAccessMenusQuery{}
	roleId, _ := controller.GetInt64(":roleId")
	getRoleAccessMenusQuery.RoleId = roleId
	getRoleAccessMenusQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.GetRoleAccessMenus(getRoleAccessMenusQuery)
	controller.Response(data, err)
}

func (controller *RoleController) UpdateRoleAccessMenus() {
	roleService := service.NewRoleService(nil)
	updateRoleAccessMenusCommand := &command.UpdateRoleAccessMenusCommand{}
	controller.Unmarshal(updateRoleAccessMenusCommand)
	roleId, _ := controller.GetInt64(":roleId")
	updateRoleAccessMenusCommand.RoleId = roleId
	updateRoleAccessMenusCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.UpdateRoleAccessMenus(updateRoleAccessMenusCommand)
	controller.Response(data, err)
}

func (controller *RoleController) AssginRoleToUsers() {
	roleService := service.NewRoleService(nil)
	assginRoleToUsersCommand := &command.AssginRoleToUsersCommand{}
	controller.Unmarshal(assginRoleToUsersCommand)
	assginRoleToUsersCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.AssginRoleToUsers(assginRoleToUsersCommand)
	controller.Response(data, err)
}

func (controller *RoleController) UnAssginRoleToUsers() {
	roleService := service.NewRoleService(nil)
	unAssginRoleToUsersCommand := &command.UnAssginRoleToUsersCommand{}
	controller.Unmarshal(unAssginRoleToUsersCommand)
	unAssginRoleToUsersCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := roleService.UnAssginRoleToUsers(unAssginRoleToUsersCommand)
	controller.Response(data, err)
}

/*****   1.适配web模块  *****/
func (controller *RoleController) WebSearchRole() {
	roleService := service.NewRoleService(nil)
	listRoleQuery := &query.ListRoleQuery{}
	Must(controller.Unmarshal(listRoleQuery))
	listRoleQuery.Limit = 20
	listRoleQuery.CompanyId = 23
	data, err := roleService.ListRole(listRoleQuery)
	webData := map[string]interface{}{
		"list":  data.(map[string]interface{})["roles"],
		"total": data.(map[string]interface{})["count"],
	}
	ResponseGrid(controller.BaseController, webData, err)
}