作者 郑周

模板业务功能提交(增删改查、复制、状态变更)

@@ -8,7 +8,7 @@ type CreateTemplateCommand struct { @@ -8,7 +8,7 @@ type CreateTemplateCommand struct {
8 CompanyId int64 `cname:"公司ID" json:"companyId"` 8 CompanyId int64 `cname:"公司ID" json:"companyId"`
9 CreatorId int64 `cname:"创建人ID" json:"creatorId"` 9 CreatorId int64 `cname:"创建人ID" json:"creatorId"`
10 Name string `cname:"模板名称" json:"name" valid:"Required"` 10 Name string `cname:"模板名称" json:"name" valid:"Required"`
11 - Describe string `cname:"模板描述" json:"remark"` 11 + Describe string `cname:"模板描述" json:"describe"`
12 } 12 }
13 13
14 func (in *CreateTemplateCommand) Valid(validation *validation.Validation) { 14 func (in *CreateTemplateCommand) Valid(validation *validation.Validation) {
@@ -25,4 +25,9 @@ func (in *CreateTemplateCommand) Valid(validation *validation.Validation) { @@ -25,4 +25,9 @@ func (in *CreateTemplateCommand) Valid(validation *validation.Validation) {
25 validation.SetError("name", "模板名称最大长度40个字符") 25 validation.SetError("name", "模板名称最大长度40个字符")
26 return 26 return
27 } 27 }
  28 +
  29 + if len(in.Describe) > 100 {
  30 + validation.SetError("describe", "备注最大长度100个字符")
  31 + return
  32 + }
28 } 33 }
@@ -6,12 +6,15 @@ import ( @@ -6,12 +6,15 @@ import (
6 ) 6 )
7 7
8 type StateTemplateCommand struct { 8 type StateTemplateCommand struct {
9 - Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`  
10 - State int `cname:"模板状态" json:"state"` 9 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  10 + Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
  11 + State int `cname:"模板状态" json:"state"`
11 } 12 }
12 13
13 type CopyTemplateCommand struct { 14 type CopyTemplateCommand struct {
14 - Id int64 `cname:"模板ID" json:"id,string" valid:"Required"` 15 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  16 + CreatorId int64 `cname:"创建人ID" json:"creatorId"`
  17 + Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
15 } 18 }
16 19
17 func (in *StateTemplateCommand) Valid(validation *validation.Validation) { 20 func (in *StateTemplateCommand) Valid(validation *validation.Validation) {
1 package command 1 package command
2 2
3 -import "github.com/beego/beego/v2/core/validation" 3 +import (
  4 + "github.com/beego/beego/v2/core/validation"
  5 + "time"
  6 +)
4 7
5 type QueryTemplateCommand struct { 8 type QueryTemplateCommand struct {
6 - CompanyId int64 `cname:"公司ID" json:"companyId"`  
7 - Name string `cname:"模板名称" json:"name"`  
8 - PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`  
9 - PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"` 9 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  10 + Name string `cname:"模板名称" json:"name"`
  11 + State int `cname:"模板状态" json:"state"`
  12 + CreatedAt *time.Time `cname:"创建时间" json:"createdAt"`
  13 + PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
  14 + PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
10 } 15 }
11 16
12 func (in *QueryTemplateCommand) Valid(validation *validation.Validation) { 17 func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
@@ -16,14 +21,14 @@ func (in *QueryTemplateCommand) Valid(validation *validation.Validation) { @@ -16,14 +21,14 @@ func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
16 } 21 }
17 } 22 }
18 23
19 -// AllEnableTemplateCommand 查询所有已启用的模板  
20 -type AllEnableTemplateCommand struct {  
21 - CompanyId int64 `cname:"公司ID" json:"companyId"`  
22 -}  
23 -  
24 -func (in *AllEnableTemplateCommand) Valid(validation *validation.Validation) {  
25 - if in.CompanyId == 0 {  
26 - validation.SetError("companyId", "公司ID无效")  
27 - return  
28 - }  
29 -} 24 +//// AllEnableTemplateCommand 查询所有已启用的模板
  25 +//type AllEnableTemplateCommand struct {
  26 +// CompanyId int64 `cname:"公司ID" json:"companyId"`
  27 +//}
  28 +//
  29 +//func (in *AllEnableTemplateCommand) Valid(validation *validation.Validation) {
  30 +// if in.CompanyId == 0 {
  31 +// validation.SetError("companyId", "公司ID无效")
  32 +// return
  33 +// }
  34 +//}
@@ -9,7 +9,7 @@ type UpdateTemplateCommand struct { @@ -9,7 +9,7 @@ type UpdateTemplateCommand struct {
9 Id int64 `cname:"模板ID" json:"id,string" valid:"Required"` 9 Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
10 CompanyId int64 `cname:"公司ID" json:"companyId"` 10 CompanyId int64 `cname:"公司ID" json:"companyId"`
11 Name string `cname:"模板名称" json:"name" valid:"Required"` 11 Name string `cname:"模板名称" json:"name" valid:"Required"`
12 - Describe string `cname:"模板描述" json:"remark"` 12 + Describe string `cname:"模板描述" json:"describe"`
13 LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"` 13 LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
14 } 14 }
15 15
@@ -24,6 +24,11 @@ func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) { @@ -24,6 +24,11 @@ func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
24 return 24 return
25 } 25 }
26 26
  27 + if len(in.Describe) > 100 {
  28 + validation.SetError("describe", "备注最大长度100个字符")
  29 + return
  30 + }
  31 +
27 if len(in.LinkNodes) == 0 { 32 if len(in.LinkNodes) == 0 {
28 validation.SetError("linkNodes", "评估模板流程不能为空") 33 validation.SetError("linkNodes", "评估模板流程不能为空")
29 return 34 return
@@ -188,29 +188,10 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int @@ -188,29 +188,10 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int
188 if err != nil { 188 if err != nil {
189 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 189 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
190 } 190 }
191 - return tool_funs.SimpleWrapGridMap(total, templates), nil  
192 -}  
193 -  
194 -func (rs *EvaluationTemplateService) ListForEnable(in *command.AllEnableTemplateCommand) (interface{}, error) {  
195 - transactionContext, err := factory.StartTransaction()  
196 - if err != nil {  
197 - return nil, err  
198 - }  
199 - defer func() {  
200 - transactionContext.RollbackTransaction()  
201 - }()  
202 - templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})  
203 -  
204 - count, templates, err := templateRepository.Find(map[string]interface{}{  
205 - "companyId": in.CompanyId,  
206 - "state": domain.TemplateStateEnable,  
207 - "offset": 0,  
208 - "limit": 9999999,  
209 - }, "linkNodes")  
210 - if err != nil {  
211 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 191 + if err := transactionContext.CommitTransaction(); err != nil {
  192 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
212 } 193 }
213 - return tool_funs.SimpleWrapGridMap(count, templates), nil 194 + return tool_funs.SimpleWrapGridMap(total, templates), nil
214 } 195 }
215 196
216 func (rs *EvaluationTemplateService) State(in *command.StateTemplateCommand) (interface{}, error) { 197 func (rs *EvaluationTemplateService) State(in *command.StateTemplateCommand) (interface{}, error) {
@@ -255,10 +236,20 @@ func (rs *EvaluationTemplateService) Copy(in *command.CopyTemplateCommand) (inte @@ -255,10 +236,20 @@ func (rs *EvaluationTemplateService) Copy(in *command.CopyTemplateCommand) (inte
255 } 236 }
256 // ID重置 237 // ID重置
257 template.Id = 0 238 template.Id = 0
  239 + template.Name = template.Name + " 副本"
  240 + template.CreatorId = in.CreatorId
  241 +
258 // 如果拷贝已经启用的模板,默认先设置为待启用 242 // 如果拷贝已经启用的模板,默认先设置为待启用
259 if template.State == domain.TemplateStateEnable { 243 if template.State == domain.TemplateStateEnable {
260 template.State = domain.TemplateStateWaitActive 244 template.State = domain.TemplateStateWaitActive
261 } 245 }
  246 +
  247 + // 流程环节ID重置
  248 + sid, _ := utils.NewSnowflakeId()
  249 + for i := range template.LinkNodes {
  250 + template.LinkNodes[i].Id = sid + int64(i+1)
  251 + }
  252 +
262 template, err = templateRepository.Insert(template) 253 template, err = templateRepository.Insert(template)
263 if err != nil { 254 if err != nil {
264 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 255 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -25,9 +25,13 @@ const ( @@ -25,9 +25,13 @@ const (
25 ) 25 )
26 26
27 const ( 27 const (
28 - KpiCycleDay int = 1 // 考核周期-日  
29 - KpiCycleWeek int = 2 // 考核周期-周  
30 - KpiCycleMonth int = 3 // 考核周期-月 28 + KpiCycleDay int = 1 // 考核周期-日
  29 + KpiCycleWeek int = 2 // 考核周期-周
  30 + KpiCycleOneMonth int = 3 // 考核周期-月
  31 + KpiCycleTwoMonth int = 4 // 考核周期-双月
  32 + KpiCycleThreeMonth int = 5 // 考核周期-季度
  33 + KpiCycleSixMonth int = 6 // 考核周期-半年
  34 + KpiCycleYear int = 7 // 考核周期-年
31 ) 35 )
32 36
33 type EntryItem struct { 37 type EntryItem struct {
@@ -39,17 +43,17 @@ type EntryItem struct { @@ -39,17 +43,17 @@ type EntryItem struct {
39 type NodeContent struct { 43 type NodeContent struct {
40 Category string `json:"category" comment:"类别"` 44 Category string `json:"category" comment:"类别"`
41 Name string `json:"name" comment:"名称"` 45 Name string `json:"name" comment:"名称"`
42 - RuleId int64 `json:"ruleId" comment:"评估规则ID"` 46 + RuleId string `json:"ruleId" comment:"评估规则ID"`
43 PromptTitle string `json:"promptTitle" comment:"提示项标题"` 47 PromptTitle string `json:"promptTitle" comment:"提示项标题"`
44 PromptText string `json:"promptText" comment:"提示项正文"` 48 PromptText string `json:"promptText" comment:"提示项正文"`
45 EntryItems []*EntryItem `json:"entryItems" comment:"填写项"` 49 EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
46 } 50 }
47 51
48 -// NodeAllInvite 360°邀请  
49 -type NodeAllInvite struct {  
50 - ParentDifferentIds []int64 `json:"parentDifferentIds" comment:"不同上级同事ID"`  
51 - ParentSameIds []int64 `json:"parentSameIds" comment:"相同上级同事ID"`  
52 -} 52 +//// NodeAllInvite 360°邀请
  53 +//type NodeAllInvite struct {
  54 +// ParentDifferentIds []string `json:"parentDifferentIds" comment:"不同上级同事ID"`
  55 +// ParentSameIds []string `json:"parentSameIds" comment:"相同上级同事ID"`
  56 +//}
53 57
54 //// NodeKpiResult 绩效结果查看 58 //// NodeKpiResult 绩效结果查看
55 //type NodeKpiResult struct { 59 //type NodeKpiResult struct {
@@ -57,15 +61,16 @@ type NodeAllInvite struct { @@ -57,15 +61,16 @@ type NodeAllInvite struct {
57 61
58 // 评估流程、环节 62 // 评估流程、环节
59 type LinkNode struct { 63 type LinkNode struct {
60 - Id int64 `json:"id,string" comment:"环节ID"`  
61 - Type int `json:"type" comment:"环节类型"`  
62 - Name string `json:"name" comment:"环节名称"`  
63 - Describe string `json:"describe" comment:"环节描述"`  
64 - NodeContents []*NodeContent `json:"nodeContents" comment:"环节-评估内容"`  
65 - NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"360°邀请人员"`  
66 - TimeStart *time.Time `json:"timeStart" comment:"起始时间"`  
67 - TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`  
68 - KpiCycle int `json:"state" comment:"考核周期(1日、2周、3月)"` 64 + Id int64 `json:"id,string" comment:"环节ID"`
  65 + Type int `json:"type" comment:"环节类型"`
  66 + Name string `json:"name" comment:"环节名称"`
  67 + Describe string `json:"describe" comment:"环节描述"`
  68 + NodeContents []*NodeContent `json:"nodeContents" comment:"环节-评估内容"`
  69 + TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
  70 + TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
  71 + KpiCycle int `json:"state" comment:"考核周期(1日、2周、3月)"`
  72 + //NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"360°邀请人员"`
  73 +
69 } 74 }
70 75
71 // 评估模板 76 // 评估模板
@@ -125,6 +125,10 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface @@ -125,6 +125,10 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
125 query.Where("id in(?)", pg.In(v)) 125 query.Where("id in(?)", pg.In(v))
126 } 126 }
127 127
  128 + if v, ok := queryOptions["notId"]; ok {
  129 + query.Where("id != ?", v)
  130 + }
  131 +
128 if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 { 132 if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 {
129 query.Where("name LIKE ?", v) 133 query.Where("name LIKE ?", v)
130 } 134 }
@@ -133,10 +137,14 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface @@ -133,10 +137,14 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
133 query.Where("company_id = ?", v) 137 query.Where("company_id = ?", v)
134 } 138 }
135 139
136 - if v, ok := queryOptions["state"]; ok { 140 + if v, ok := queryOptions["state"]; ok && v.(int) >= 0 {
137 query.Where("state = ?", v) 141 query.Where("state = ?", v)
138 } 142 }
139 143
  144 + if v, ok := queryOptions["createdAt"]; ok {
  145 + query.Where("created_at = ?", v)
  146 + }
  147 +
140 if v, ok := queryOptions["limit"].(int); ok { 148 if v, ok := queryOptions["limit"].(int); ok {
141 query.Limit(v) 149 query.Limit(v)
142 } 150 }
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "github.com/linmadan/egglib-go/web/beego" 5 "github.com/linmadan/egglib-go/web/beego"
6 service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template" 6 service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_template/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
9 ) 10 )
10 11
@@ -59,6 +60,7 @@ func (controller *TemplateController) RemoveTemplate() { @@ -59,6 +60,7 @@ func (controller *TemplateController) RemoveTemplate() {
59 func (controller *TemplateController) ListTemplate() { 60 func (controller *TemplateController) ListTemplate() {
60 ruService := service.NewEvaluationTemplateService() 61 ruService := service.NewEvaluationTemplateService()
61 in := &command.QueryTemplateCommand{} 62 in := &command.QueryTemplateCommand{}
  63 + in.State = -1
62 if err := controller.Unmarshal(in); err != nil { 64 if err := controller.Unmarshal(in); err != nil {
63 controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) 65 controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
64 } else { 66 } else {
@@ -72,12 +74,15 @@ func (controller *TemplateController) ListTemplate() { @@ -72,12 +74,15 @@ func (controller *TemplateController) ListTemplate() {
72 74
73 func (controller *TemplateController) ListEnableTemplate() { 75 func (controller *TemplateController) ListEnableTemplate() {
74 ruService := service.NewEvaluationTemplateService() 76 ruService := service.NewEvaluationTemplateService()
75 - in := &command.AllEnableTemplateCommand{} 77 + in := &command.QueryTemplateCommand{}
  78 + in.State = domain.TemplateStateEnable
  79 + in.PageNumber = 1
  80 + in.PageSize = 999999
76 if err := controller.Unmarshal(in); err != nil { 81 if err := controller.Unmarshal(in); err != nil {
77 controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) 82 controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
78 } else { 83 } else {
79 in.CompanyId = middlewares.GetCompanyId(controller.Ctx) 84 in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
80 - controller.Response(ruService.ListForEnable(in)) 85 + controller.Response(ruService.List(in))
81 } 86 }
82 } 87 }
83 88
@@ -87,6 +92,7 @@ func (controller *TemplateController) StateTemplate() { @@ -87,6 +92,7 @@ func (controller *TemplateController) StateTemplate() {
87 if err := controller.Unmarshal(in); err != nil { 92 if err := controller.Unmarshal(in); err != nil {
88 controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) 93 controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
89 } else { 94 } else {
  95 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
90 controller.Response(ruService.State(in)) 96 controller.Response(ruService.State(in))
91 } 97 }
92 } 98 }
@@ -97,6 +103,8 @@ func (controller *TemplateController) CopyTemplate() { @@ -97,6 +103,8 @@ func (controller *TemplateController) CopyTemplate() {
97 if err := controller.Unmarshal(in); err != nil { 103 if err := controller.Unmarshal(in); err != nil {
98 controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) 104 controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
99 } else { 105 } else {
  106 + in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
  107 + in.CreatorId = middlewares.GetUserId(controller.Ctx)
100 controller.Response(ruService.Copy(in)) 108 controller.Response(ruService.Copy(in))
101 } 109 }
102 } 110 }
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "github.com/linmadan/egglib-go/web/beego/filters"
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
  8 +)
  9 +
  10 +func init() {
  11 + ns := web.NewNamespace("/v1/evaluation-template",
  12 + web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
  13 + web.NSRouter("/", &controllers.TemplateController{}, "Post:CreateTemplate"),
  14 + web.NSRouter("/", &controllers.TemplateController{}, "Put:UpdateTemplate"),
  15 + web.NSRouter("/", &controllers.TemplateController{}, "Delete:RemoveTemplate"),
  16 + web.NSRouter("/:Id", &controllers.TemplateController{}, "Get:GetTemplate"),
  17 + web.NSRouter("/list", &controllers.TemplateController{}, "Post:ListTemplate"),
  18 + web.NSRouter("/list-enable", &controllers.TemplateController{}, "Post:ListEnableTemplate"),
  19 + )
  20 + web.AddNamespace(ns)
  21 +}