evaluation_cycle_controller.go 3.6 KB
package controllers

import (
	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/web/beego"
	service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)

type CycleController struct {
	beego.BaseController
}

func (controller *CycleController) CreateCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.CreateCycleCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		in.CreatorId = ua.UserId
		controller.Response(ruService.Create(in))
	}
}

func (controller *CycleController) UpdateCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.UpdateCycleCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
		controller.Response(ruService.Update(in))
	}
}

func (controller *CycleController) GetCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.GetCycleCommand{}
	if id, err := controller.GetInt64(":Id"); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		in.Id = id
		controller.Response(ruService.Get(in))
	}
}

func (controller *CycleController) RemoveCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.DeleteCycleCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		controller.Response(ruService.Remove(in))
	}
}

func (controller *CycleController) ListCycle() {
	ruService := service.NewEvaluationCycleService()
	in := &command.QueryCycleCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		if len(in.Name) > 0 {
			in.Name = "%" + in.Name + "%"
		}
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		controller.Response(ruService.List(in))
	}
}

func (controller *CycleController) StatisticCycleUser() {
	ruService := service.NewEvaluationCycleService()
	in := &command.StatisticCycleProjectUserCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		controller.Response(ruService.StatisticCycleUser(in))
	}
}

func (controller *CycleController) CycleTemplateList() {
	ruService := service.NewEvaluationCycleService()
	in := &command.CycleTemplateListCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		controller.Response(ruService.CycleTemplateList(in))
	}
}

func (controller *CycleController) CycleTemplate() {
	ruService := service.NewEvaluationCycleService()
	in := &command.CycleTemplateCommand{}
	if id, err := controller.GetInt64(":Id"); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		in.Id = id
		controller.Response(ruService.CycleTemplate(in))
	}
}