作者 郑周

时间格式化

@@ -2,7 +2,6 @@ package command @@ -2,7 +2,6 @@ package command
2 2
3 import ( 3 import (
4 "github.com/beego/beego/v2/core/validation" 4 "github.com/beego/beego/v2/core/validation"
5 - "time"  
6 ) 5 )
7 6
8 type UpdateProjectCommand struct { 7 type UpdateProjectCommand struct {
@@ -17,16 +16,16 @@ type UpdateProjectCommand struct { @@ -17,16 +16,16 @@ type UpdateProjectCommand struct {
17 } 16 }
18 17
19 type UpdateProjectTemplateCommand struct { 18 type UpdateProjectTemplateCommand struct {
20 - CompanyId int64 `cname:"公司ID" json:"companyId"`  
21 - CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`  
22 - Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`  
23 - TemplateId int64 `cname:"模板ID" json:"templateId,string"`  
24 - Recipients []string `cname:"被评估人ID" json:"recipients"`  
25 - TimeStart *time.Time `cname:"自评起始时间" json:"timeStart" valid:"Required"`  
26 - TimeEnd *time.Time `cname:"自评截止时间" json:"timeEnd" valid:"Required"`  
27 - KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`  
28 - KpiResultStart *time.Time `cname:"绩效结果开始查看时间" json:"kpiResultStart"`  
29 - Activate int `cname:"启动项目" json:"activate"` 19 + CompanyId int64 `cname:"公司ID" json:"companyId"`
  20 + CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
  21 + Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
  22 + TemplateId int64 `cname:"模板ID" json:"templateId,string"`
  23 + Recipients []string `cname:"被评估人ID" json:"recipients"`
  24 + TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"`
  25 + TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"`
  26 + KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`
  27 + KpiResultStart string `cname:"绩效结果开始查看时间" json:"kpiResultStart"`
  28 + Activate int `cname:"启动项目" json:"activate"`
30 } 29 }
31 30
32 type CheckRecipientCommand struct { 31 type CheckRecipientCommand struct {
@@ -48,4 +47,13 @@ func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation) @@ -48,4 +47,13 @@ func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation)
48 validation.SetError("recipients", "请添加被评估人") 47 validation.SetError("recipients", "请添加被评估人")
49 return 48 return
50 } 49 }
  50 + if len(in.TimeStart) == 0 {
  51 + validation.SetError("timeEnd", "请选择开始时间")
  52 + return
  53 + }
  54 + if len(in.TimeEnd) == 0 {
  55 + validation.SetError("timeEnd", "请选择结束时间")
  56 + return
  57 + }
  58 +
51 } 59 }
@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
11 "strconv" 11 "strconv"
  12 + "time"
12 ) 13 )
13 14
14 type EvaluationProjectService struct { 15 type EvaluationProjectService struct {
@@ -177,18 +178,31 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp @@ -177,18 +178,31 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
177 project.State = domain.ProjectStateEnable 178 project.State = domain.ProjectStateEnable
178 } 179 }
179 180
  181 + start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
  182 + if err != nil {
  183 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  184 + }
  185 + end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
  186 + if err != nil {
  187 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  188 + }
  189 + kpiStart, err := time.ParseInLocation("2006-01-02 15:04:05", in.KpiResultStart, time.Local)
  190 + if err != nil {
  191 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  192 + }
  193 +
180 project.Recipients = in.Recipients 194 project.Recipients = in.Recipients
181 project.Template = cycleTemplate.Template 195 project.Template = cycleTemplate.Template
182 for i := range project.Template.LinkNodes { 196 for i := range project.Template.LinkNodes {
183 node := project.Template.LinkNodes[i] 197 node := project.Template.LinkNodes[i]
184 node.KpiCycle = in.KpiCycle // 设置周期 198 node.KpiCycle = in.KpiCycle // 设置周期
185 if node.Type == domain.LinkNodeViewResult { 199 if node.Type == domain.LinkNodeViewResult {
186 - if in.KpiResultStart != nil {  
187 - node.TimeStart = in.KpiResultStart 200 + if len(in.KpiResultStart) > 0 {
  201 + node.TimeStart = &kpiStart
188 } 202 }
189 } else { 203 } else {
190 - node.TimeStart = in.TimeStart  
191 - node.TimeEnd = in.TimeEnd 204 + node.TimeStart = &start
  205 + node.TimeEnd = &end
192 } 206 }
193 } 207 }
194 208