user_controller.go 6.4 KB
package controllers

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

type UserController struct {
	beego.BaseController
}

func (controller *UserController) CreateUser() {
	userService := service.NewUserService(nil)
	createUserCommand := &command.CreateUserCommand{}
	Must(controller.Unmarshal(createUserCommand))
	createUserCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.CreateUser(createUserCommand)
	controller.Response(data, err)
}

func (controller *UserController) UpdateUser() {
	userService := service.NewUserService(nil)
	updateUserCommand := &command.UpdateUserCommand{}
	Must(controller.Unmarshal(updateUserCommand))
	userId, _ := controller.GetInt64(":userId")
	updateUserCommand.UserId = userId
	updateUserCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.UpdateUser(updateUserCommand)
	controller.Response(data, err)
}

func (controller *UserController) GetUser() {
	userService := service.NewUserService(nil)
	getUserQuery := &query.GetUserQuery{}
	userId, _ := controller.GetInt64(":userId")
	getUserQuery.UserId = userId
	getUserQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.GetUser(getUserQuery)
	controller.Response(data, err)
}

func (controller *UserController) RemoveUser() {
	userService := service.NewUserService(nil)
	removeUserCommand := &command.RemoveUserCommand{}
	controller.Unmarshal(removeUserCommand)
	userId, _ := controller.GetInt64(":userId")
	removeUserCommand.UserId = userId
	removeUserCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.RemoveUser(removeUserCommand)
	controller.Response(data, err)
}

func (controller *UserController) ListUser() {
	userService := service.NewUserService(nil)
	listUserQuery := &query.ListUserQuery{}
	listUserQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.ListUser(listUserQuery)
	controller.Response(data, err)
}

func (controller *UserController) GetUserAccessMenus() {
	userService := service.NewUserService(nil)
	getUserAccessMenusQuery := &query.GetUserAccessMenusQuery{}
	userId, _ := controller.GetInt64(":userId")
	getUserAccessMenusQuery.UserId = userId
	menuCategory := controller.GetString("menuCategory")
	getUserAccessMenusQuery.MenuCategory = menuCategory
	getUserAccessMenusQuery.OrgId, _ = controller.GetInt64("orgId", 0)
	getUserAccessMenusQuery.ALLDisableMenu, _ = controller.GetInt("allDisableMenu", 0)
	getUserAccessMenusQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.GetUserAccessMenus(getUserAccessMenusQuery)
	controller.Response(data, err)
}

func (controller *UserController) GetUserProfile() {
	userService := service.NewUserService(nil)
	getUserProfileQuery := &query.GetUserProfileQuery{}
	userId, _ := controller.GetInt64(":userId")
	getUserProfileQuery.UserId = userId
	getUserProfileQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.GetUserProfile(getUserProfileQuery)
	controller.Response(data, err)
}

func (controller *UserController) BatchAdd() {
	userService := service.NewUserService(nil)
	batchAddCommand := &command.BatchAddCommand{}
	Must(controller.Unmarshal(batchAddCommand))
	batchAddCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.BatchAdd(batchAddCommand)
	controller.Response(data, err)
}

func (controller *UserController) BatchAdd2() {
	userService := service.NewUserService(nil)
	batchAddCommand := &command.BatchAdd2Command{}
	Must(controller.Unmarshal(batchAddCommand))
	batchAddCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.BatchAdd2(batchAddCommand)
	controller.Response(data, err)
}

func (controller *UserController) BatchEnable() {
	userService := service.NewUserService(nil)
	batchEnableCommand := &command.BatchEnableCommand{}
	controller.Unmarshal(batchEnableCommand)
	batchEnableCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.BatchEnable(batchEnableCommand)
	controller.Response(data, err)
}

func (controller *UserController) BatchResetPassword() {
	userService := service.NewUserService(nil)
	batchResetPasswordCommand := &command.BatchResetPasswordCommand{}
	controller.Unmarshal(batchResetPasswordCommand)
	batchResetPasswordCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.BatchResetPassword(batchResetPasswordCommand)
	controller.Response(data, err)
}

func (controller *UserController) UpdateUsersBase() {
	userService := service.NewUserService(nil)
	updateUsersBaseCommand := &command.UpdateUsersBaseCommand{}
	controller.Unmarshal(updateUsersBaseCommand)
	userId, _ := controller.GetInt64(":userId")
	updateUsersBaseCommand.UserId = userId
	updateUsersBaseCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.UpdateUsersBase(updateUsersBaseCommand)
	controller.Response(data, err)
}

func (controller *UserController) CreateCooperator() {
	userService := service.NewUserService(nil)
	createCooperatorCommand := &command.CreateCooperatorCommand{}
	Must(controller.Unmarshal(createCooperatorCommand))
	createCooperatorCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.CreateCooperator(createCooperatorCommand)
	controller.Response(data, err)
}

func (controller *UserController) UpdateCooperator() {
	userService := service.NewUserService(nil)
	updateCooperatorCommand := &command.UpdateCooperatorCommand{}
	controller.Unmarshal(updateCooperatorCommand)
	userId, _ := controller.GetInt64(":userId")
	updateCooperatorCommand.UserId = userId
	updateCooperatorCommand.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.UpdateCooperator(updateCooperatorCommand)
	controller.Response(data, err)
}

func (controller *UserController) SearchUser() {
	userService := service.NewUserService(nil)
	listUserQuery := &query.ListUserQuery{}
	Must(controller.Unmarshal(listUserQuery))
	listUserQuery.OperateInfo = ParseOperateInfo(controller.BaseController)
	data, err := userService.ListUser(listUserQuery)
	controller.Response(data, err)
}