evaluation_project_controller.go
5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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) 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))
}
}