审查视图

pkg/port/beego/controllers/evaluation_project_controller.go 4.1 KB
郑周 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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
}
郑周 authored
15
func (controller *ProjectController) CreateProject() {
郑周 authored
16 17 18 19 20
	ruService := service.NewEvaluationProjectService()
	in := &command.CreateProjectCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
21 22 23
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		in.CreatorId = ua.UserId
郑周 authored
24 25 26 27 28 29 30 31 32 33
		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 {
郑周 authored
34 35
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
郑周 authored
36 37 38 39 40 41 42 43 44 45
		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 {
郑周 authored
46 47
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
郑周 authored
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
		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 + "%"
		}
郑周 authored
83 84
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
郑周 authored
85 86 87 88
		controller.Response(ruService.List(in))
	}
}
郑周 authored
89
func (controller *ProjectController) ActivateProject() {
郑周 authored
90
	ruService := service.NewEvaluationProjectService()
郑周 authored
91
	in := &command.ActivateProjectCommand{}
郑周 authored
92 93 94
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
95
		controller.Response(ruService.Activate(in))
郑周 authored
96 97 98 99 100 101 102 103 104
	}
}

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 {
郑周 authored
105 106
		ua := middlewares.GetUser(controller.Ctx)
		in.CreatorId = ua.UserId
郑周 authored
107 108 109
		controller.Response(ruService.Copy(in))
	}
}
110
郑周 authored
111
func (controller *ProjectController) CheckRecipients() {
112
	ruService := service.NewEvaluationProjectService()
郑周 authored
113
	in := &command.CheckRecipientCommand{}
114 115 116
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
117 118
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
郑周 authored
119
		controller.Response(ruService.CheckRecipients(in))
120 121
	}
}