审查视图

pkg/port/beego/controllers/evaluation_project_controller.go 5.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
	}
}
郑周 authored
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
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))
	}
}
郑周 authored
119 120 121 122 123 124
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
125 126
		ua := middlewares.GetUser(controller.Ctx)
		in.CreatorId = ua.UserId
郑周 authored
127 128 129
		controller.Response(ruService.Copy(in))
	}
}
130
郑周 authored
131
func (controller *ProjectController) CheckRecipients() {
132
	ruService := service.NewEvaluationProjectService()
郑周 authored
133
	in := &command.CheckRecipientCommand{}
134 135 136
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
137 138
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
郑周 authored
139
		controller.Response(ruService.CheckRecipients(in))
140 141
	}
}
142 143 144 145 146 147 148 149 150 151

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