org_controller.go 3.3 KB
package controllers

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

type OrgController struct {
	beego.BaseController
}

func (controller *OrgController) CreateOrg() {
	orgService := service.NewOrgService(nil)
	createOrgCommand := &command.CreateOrgCommand{}
	controller.Unmarshal(createOrgCommand)
	createOrgCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := orgService.CreateOrg(createOrgCommand)
	controller.Response(data, err)
}

func (controller *OrgController) UpdateOrg() {
	orgService := service.NewOrgService(nil)
	updateOrgCommand := &command.UpdateOrgCommand{}
	controller.Unmarshal(updateOrgCommand)
	orgId, _ := controller.GetInt64(":orgId")
	updateOrgCommand.OrgId = orgId
	updateOrgCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := orgService.UpdateOrg(updateOrgCommand)
	controller.Response(data, err)
}

func (controller *OrgController) GetOrg() {
	orgService := service.NewOrgService(nil)
	getOrgQuery := &query.GetOrgQuery{}
	orgId, _ := controller.GetInt64(":orgId")
	getOrgQuery.OrgId = orgId
	getOrgQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := orgService.GetOrg(getOrgQuery)
	controller.Response(data, err)
}

func (controller *OrgController) RemoveOrg() {
	orgService := service.NewOrgService(nil)
	removeOrgCommand := &command.RemoveOrgCommand{}
	controller.Unmarshal(removeOrgCommand)
	orgId, _ := controller.GetInt64(":orgId")
	removeOrgCommand.OrgId = orgId
	removeOrgCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := orgService.RemoveOrg(removeOrgCommand)
	controller.Response(data, err)
}

func (controller *OrgController) ListOrg() {
	orgService := service.NewOrgService(nil)
	listOrgQuery := &query.ListOrgQuery{}
	listOrgQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := orgService.ListOrg(listOrgQuery)
	controller.Response(data, err)
}

func (controller *OrgController) GetOrgSubDepartment() {
	orgService := service.NewOrgService(nil)
	getOrgSubDepartmentQuery := &query.GetOrgSubDepartmentQuery{}
	orgId, _ := controller.GetInt64(":orgId")
	getOrgSubDepartmentQuery.OrgId = orgId
	childFlag, _ := controller.GetInt("childFlag")
	getOrgSubDepartmentQuery.ChildFlag = childFlag
	getOrgSubDepartmentQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := orgService.GetOrgSubDepartment(getOrgSubDepartmentQuery)
	controller.Response(data, err)
}

func (controller *OrgController) EnableOrg() {
	orgService := service.NewOrgService(nil)
	enableOrgCommand := &command.EnableOrgCommand{}
	controller.Unmarshal(enableOrgCommand)
	enableOrgCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := orgService.EnableOrg(enableOrgCommand)
	controller.Response(data, err)
}

func (controller *OrgController) SearchOrg() {
	orgService := service.NewOrgService(nil)
	listOrgQuery := &query.ListOrgQuery{}
	Must(controller.Unmarshal(listOrgQuery))
	listOrgQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := orgService.ListOrg(listOrgQuery)
	controller.Response(data, err)
}