作者 郑周

1. 优化定时时间,在项目周期截止当天,继续编辑保存当天截止时间,会有重复任务发送!

@@ -187,8 +187,8 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp @@ -187,8 +187,8 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
187 if task.NextSentAt == nil { 187 if task.NextSentAt == nil {
188 // 环节起始和截止本地时间 188 // 环节起始和截止本地时间
189 startLocal := task.TimeStart.Local() 189 startLocal := task.TimeStart.Local()
190 - sYear, sMonth, sDay := startLocal.Date()  
191 - startLocal = time.Date(sYear, sMonth, sDay, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算 190 + sY, sM, sD := startLocal.Date()
  191 + startLocal = time.Date(sY, sM, sD, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算
192 endLocal := task.TimeEnd.Local() 192 endLocal := task.TimeEnd.Local()
193 193
194 // 在当前时间之前,则计算下一个周期时间 194 // 在当前时间之前,则计算下一个周期时间
@@ -198,6 +198,17 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp @@ -198,6 +198,17 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
198 } else { 198 } else {
199 task.NextSentAt = &startLocal 199 task.NextSentAt = &startLocal
200 } 200 }
  201 +
  202 + // 注.最后一次发送时间和重新计算后的时间相同时,继续获取下一个周期
  203 + if task.LastSentAt != nil {
  204 + nextY, nextM, nextD := task.NextSentAt.Local().Date()
  205 + lastY, lastM, lastD := task.LastSentAt.Local().Date()
  206 + if nextY == lastY && nextM == lastM && nextD == lastD {
  207 + nextTime := utils.NextTimeInc(task.NextSentAt.Local(), task.KpiCycle)
  208 + task.NextSentAt = &nextTime
  209 + }
  210 + }
  211 +
201 // 如果超出截至时间,则周期置空 212 // 如果超出截至时间,则周期置空
202 if task.NextSentAt.After(endLocal) { 213 if task.NextSentAt.After(endLocal) {
203 task.NextSentAt = nil 214 task.NextSentAt = nil
@@ -483,8 +494,8 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) @@ -483,8 +494,8 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
483 494
484 // 环节起始和截止本地时间 495 // 环节起始和截止本地时间
485 startLocal := task.TimeStart.Local() 496 startLocal := task.TimeStart.Local()
486 - sYear, sMonth, sDay := startLocal.Date()  
487 - startLocal = time.Date(sYear, sMonth, sDay, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算 497 + sY, sM, sD := startLocal.Date()
  498 + startLocal = time.Date(sY, sM, sD, 0, 0, 0, 0, time.Local) // 开始时间以0点开始计算
488 endLocal := task.TimeEnd.Local() 499 endLocal := task.TimeEnd.Local()
489 500
490 // 在当前时间之前,则计算下一个周期时间 501 // 在当前时间之前,则计算下一个周期时间
@@ -79,6 +79,8 @@ func (rs *NodeTaskService) SendEvaluationNode() error { @@ -79,6 +79,8 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
79 } 79 }
80 80
81 staffAssessService := service.NewStaffAssessServeice() 81 staffAssessService := service.NewStaffAssessServeice()
  82 +
  83 + now := time.Now().Local()
82 for i := range tasks { 84 for i := range tasks {
83 task := tasks[i] 85 task := tasks[i]
84 project, ok := projectIdsMap[task.ProjectId] // 项目 86 project, ok := projectIdsMap[task.ProjectId] // 项目
@@ -86,6 +88,9 @@ func (rs *NodeTaskService) SendEvaluationNode() error { @@ -86,6 +88,9 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
86 // 环节截止时间 88 // 环节截止时间
87 maxTime := task.TimeEnd.Local() 89 maxTime := task.TimeEnd.Local()
88 90
  91 + // 更新任务最后一次的发送时间(取当前时间)
  92 + task.LastSentAt = &now
  93 +
89 // 当前周起始时间和截止时间 94 // 当前周起始时间和截止时间
90 var cycleTimeStart = task.NextSentAt.Local() 95 var cycleTimeStart = task.NextSentAt.Local()
91 var cycleTimeEnd time.Time 96 var cycleTimeEnd time.Time
@@ -18,6 +18,7 @@ type NodeTask struct { @@ -18,6 +18,7 @@ type NodeTask struct {
18 TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"` 18 TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
19 KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"` 19 KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
20 NextSentAt *time.Time `json:"nextSentAt" comment:"下一次发送时间"` 20 NextSentAt *time.Time `json:"nextSentAt" comment:"下一次发送时间"`
  21 + LastSentAt *time.Time `json:"lastSentAt" comment:"最后一次发送时间"`
21 CreatedAt time.Time `json:"createdAt" comment:"创建时间"` 22 CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
22 UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` 23 UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
23 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` 24 DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
@@ -19,6 +19,7 @@ type NodeTask struct { @@ -19,6 +19,7 @@ type NodeTask struct {
19 TimeEnd *time.Time `comment:"截至时间"` 19 TimeEnd *time.Time `comment:"截至时间"`
20 KpiCycle int `comment:"考核周期(1日、2周、3月)"` 20 KpiCycle int `comment:"考核周期(1日、2周、3月)"`
21 NextSentAt *time.Time `comment:"下一次发送时间"` 21 NextSentAt *time.Time `comment:"下一次发送时间"`
  22 + LastSentAt *time.Time `comment:"最后一次发送时间"`
22 CreatedAt time.Time `comment:"创建时间"` 23 CreatedAt time.Time `comment:"创建时间"`
23 UpdatedAt time.Time `comment:"更新时间"` 24 UpdatedAt time.Time `comment:"更新时间"`
24 DeletedAt *time.Time `comment:"删除时间"` 25 DeletedAt *time.Time `comment:"删除时间"`
@@ -35,6 +35,7 @@ func (repo *NodeTaskRepository) TransformToDomain(m *models.NodeTask) domain.Nod @@ -35,6 +35,7 @@ func (repo *NodeTaskRepository) TransformToDomain(m *models.NodeTask) domain.Nod
35 TimeEnd: m.TimeEnd, 35 TimeEnd: m.TimeEnd,
36 KpiCycle: m.KpiCycle, 36 KpiCycle: m.KpiCycle,
37 NextSentAt: m.NextSentAt, 37 NextSentAt: m.NextSentAt,
  38 + LastSentAt: m.LastSentAt,
38 CreatedAt: m.CreatedAt.Local(), 39 CreatedAt: m.CreatedAt.Local(),
39 UpdatedAt: m.UpdatedAt.Local(), 40 UpdatedAt: m.UpdatedAt.Local(),
40 DeletedAt: m.DeletedAt, 41 DeletedAt: m.DeletedAt,
@@ -56,6 +57,7 @@ func (repo *NodeTaskRepository) TransformToModel(d *domain.NodeTask) models.Node @@ -56,6 +57,7 @@ func (repo *NodeTaskRepository) TransformToModel(d *domain.NodeTask) models.Node
56 TimeEnd: d.TimeEnd, 57 TimeEnd: d.TimeEnd,
57 KpiCycle: d.KpiCycle, 58 KpiCycle: d.KpiCycle,
58 NextSentAt: d.NextSentAt, 59 NextSentAt: d.NextSentAt,
  60 + LastSentAt: d.LastSentAt,
59 CreatedAt: d.CreatedAt, 61 CreatedAt: d.CreatedAt,
60 UpdatedAt: d.UpdatedAt, 62 UpdatedAt: d.UpdatedAt,
61 DeletedAt: d.DeletedAt, 63 DeletedAt: d.DeletedAt,
  1 +ALTER TABLE "public"."node_task" ADD COLUMN "last_sent_at" timestamptz(6);
  2 +COMMENT ON COLUMN "public"."node_task"."last_sent_at" IS '最后一次发送时间';