evaluation_project_controller.go 5.1 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_project"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/command"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)

type ProjectController struct {
	beego.BaseController
}

func (controller *ProjectController) CreateProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.CreateProjectCommand{}
	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 *ProjectController) UpdateProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.UpdateProjectCommand{}
	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.Update(in))
	}
}

func (controller *ProjectController) UpdateProjectForTemplate() {
	ruService := service.NewEvaluationProjectService()
	in := &command.UpdateProjectTemplateCommand{}
	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.UpdateTemplate(in))
	}
}

func (controller *ProjectController) GetProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.GetProjectCommand{}
	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 *ProjectController) RemoveProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.DeleteProjectCommand{}
	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 *ProjectController) ListProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.QueryProjectCommand{}
	in.State = -1 // 设置默认状态
	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 *ProjectController) ActivateProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.ActivateProjectCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		controller.Response(ruService.Activate(in))
	}
}

func (controller *ProjectController) PauseProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.ActivateProjectCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		controller.Response(ruService.Pause(in))
	}
}

func (controller *ProjectController) ResumeProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.ActivateProjectCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		controller.Response(ruService.Resume(in))
	}
}

func (controller *ProjectController) CopyProject() {
	ruService := service.NewEvaluationProjectService()
	in := &command.CopyProjectCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		ua := middlewares.GetUser(controller.Ctx)
		in.CreatorId = ua.UserId
		controller.Response(ruService.Copy(in))
	}
}

func (controller *ProjectController) CheckRecipients() {
	ruService := service.NewEvaluationProjectService()
	in := &command.CheckRecipientCommand{}
	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.CheckRecipients(in))
	}
}

func (controller *ProjectController) FixEvaluationItemUsed() {
	ruService := service.NewEvaluationProjectService()
	id, err := controller.GetInt("project_id")
	if err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, "id err"))
	}
	err = ruService.FixEvaluationItemUsed(id)
	controller.Response(nil, err)

}