作者 郑周

增加环节顺序,

消息发送优化
@@ -177,12 +177,12 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp @@ -177,12 +177,12 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
177 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 177 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
178 } 178 }
179 179
180 - // FIXME 启动时,需要激活定时任务  
181 - if in.Activate == 1 {  
182 - if len(in.Recipients) == 0 {  
183 - return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")  
184 - }  
185 - project.State = domain.ProjectStateEnable 180 + if cycleTemplate == nil || cycleTemplate.Template == nil {
  181 + return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板")
  182 + }
  183 +
  184 + if len(in.Recipients) == 0 {
  185 + return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
186 } 186 }
187 187
188 start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local) 188 start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
@@ -209,6 +209,14 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp @@ -209,6 +209,14 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
209 return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间") 209 return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间")
210 } 210 }
211 211
  212 + //// FIXME 启动时,需要激活定时任务
  213 + //if in.Activate == 1 {
  214 + // project.State = domain.ProjectStateEnable
  215 + //} else {
  216 + // project.State = domain.ProjectStateWaitActive
  217 + //}
  218 + project.State = domain.ProjectStateWaitActive
  219 +
212 project.Recipients = in.Recipients 220 project.Recipients = in.Recipients
213 project.Template = cycleTemplate.Template 221 project.Template = cycleTemplate.Template
214 for i := range project.Template.LinkNodes { 222 for i := range project.Template.LinkNodes {
@@ -348,7 +356,9 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) @@ -348,7 +356,9 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
348 if len(project.Recipients) == 0 { 356 if len(project.Recipients) == 0 {
349 return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人") 357 return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
350 } 358 }
351 - 359 + if project.State == domain.TemplateStateEnable {
  360 + return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动")
  361 + }
352 //cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": project.CycleId}) 362 //cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": project.CycleId})
353 //if err != nil { 363 //if err != nil {
354 // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 364 // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -378,6 +388,7 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) @@ -378,6 +388,7 @@ func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand)
378 NodeType: node.Type, 388 NodeType: node.Type,
379 NodeName: node.Name, 389 NodeName: node.Name,
380 NodeDescribe: node.Describe, 390 NodeDescribe: node.Describe,
  391 + NodeSort: i + 1,
381 TimeStart: node.TimeStart, 392 TimeStart: node.TimeStart,
382 TimeEnd: node.TimeEnd, 393 TimeEnd: node.TimeEnd,
383 KpiCycle: node.KpiCycle, 394 KpiCycle: node.KpiCycle,
@@ -39,9 +39,6 @@ func (rs *NodeTaskService) SendEvaluationNode() error { @@ -39,9 +39,6 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
39 projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext}) 39 projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
40 cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext}) 40 cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
41 41
42 - //ttaffAssessRepository := factory.CreateStaffAssessTaskRepository(map[string]interface{}{"transactionContext": transactionContext})  
43 - //  
44 -  
45 projectIdsMap := map[int64]*domain.EvaluationProject{} 42 projectIdsMap := map[int64]*domain.EvaluationProject{}
46 cycleIdsMap := map[int64]*domain.EvaluationCycle{} 43 cycleIdsMap := map[int64]*domain.EvaluationCycle{}
47 for i := range tasks { 44 for i := range tasks {
@@ -74,7 +71,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error { @@ -74,7 +71,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
74 cycleIdsMap[cycles[i].Id] = cycles[i] 71 cycleIdsMap[cycles[i].Id] = cycles[i]
75 } 72 }
76 73
77 - staffAssessTaskMap := map[int64]*command.CreateStaffAssessTask{} 74 + staffAssessService := service.NewStaffAssessServeice()
78 for i := range tasks { 75 for i := range tasks {
79 task := tasks[i] 76 task := tasks[i]
80 // 项目 77 // 项目
@@ -108,47 +105,44 @@ func (rs *NodeTaskService) SendEvaluationNode() error { @@ -108,47 +105,44 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
108 fmCycleStartTime := cycleTimeStart.Format("2006-1-2 15:04:05") 105 fmCycleStartTime := cycleTimeStart.Format("2006-1-2 15:04:05")
109 fmCycleTimeEnd := cycleTimeEnd.Format("2006-1-2 15:04:05") 106 fmCycleTimeEnd := cycleTimeEnd.Format("2006-1-2 15:04:05")
110 107
111 - var csat, staffOk = staffAssessTaskMap[task.ProjectId]  
112 - if !staffOk {  
113 - csat = &command.CreateStaffAssessTask{  
114 - CompanyId: int(project.CompanyId),  
115 - EvaluationProjectId: int(project.Id),  
116 - EvaluationProjectName: project.Name,  
117 - CycleId: project.CycleId,  
118 - }  
119 -  
120 - // 周期名称  
121 - if cycle, ok := cycleIdsMap[project.CycleId]; ok {  
122 - csat.CycleName = cycle.Name  
123 - }  
124 -  
125 - // 接收人  
126 - csat.ExecutorId = make([]int, 0)  
127 - for rIndex := range project.Recipients {  
128 - vInt, _ := strconv.Atoi(project.Recipients[rIndex])  
129 - csat.ExecutorId = append(csat.ExecutorId, vInt)  
130 - }  
131 -  
132 - // FIXME 这里设置时间可能会有歧义,目前原型设计时间均一致,所以直接选取第一个获取到的周期时间,作为本周期的起止和截止时间  
133 - csat.BeginTime = fmCycleStartTime  
134 - csat.EndTime = fmCycleTimeEnd  
135 -  
136 - staffAssessTaskMap[task.ProjectId] = csat 108 + csat := &command.CreateStaffAssessTask{
  109 + CompanyId: int(project.CompanyId),
  110 + EvaluationProjectId: int(project.Id),
  111 + EvaluationProjectName: project.Name,
  112 + CycleId: project.CycleId,
  113 + StepList: make([]command.AssessTaskStep, 0),
  114 + }
  115 +
  116 + // 周期名称
  117 + if cycle, ok := cycleIdsMap[project.CycleId]; ok {
  118 + csat.CycleName = cycle.Name
137 } 119 }
138 120
139 - if csat.StepList == nil {  
140 - csat.StepList = make([]command.AssessTaskStep, 0) 121 + // 接收人
  122 + csat.ExecutorId = make([]int, 0)
  123 + for rIndex := range project.Recipients {
  124 + vInt, _ := strconv.Atoi(project.Recipients[rIndex])
  125 + csat.ExecutorId = append(csat.ExecutorId, vInt)
141 } 126 }
  127 +
  128 + csat.BeginTime = fmCycleStartTime
  129 + csat.EndTime = fmCycleTimeEnd
142 csat.StepList = append(csat.StepList, command.AssessTaskStep{ 130 csat.StepList = append(csat.StepList, command.AssessTaskStep{
143 - SortBy: i, 131 + SortBy: task.NodeSort,
144 LinkNodeId: int(task.NodeId), 132 LinkNodeId: int(task.NodeId),
145 LinkNodeName: task.NodeName, 133 LinkNodeName: task.NodeName,
146 LinkNodeType: task.NodeType, 134 LinkNodeType: task.NodeType,
147 BeginTime: fmCycleStartTime, 135 BeginTime: fmCycleStartTime,
148 EndTime: fmCycleTimeEnd, 136 EndTime: fmCycleTimeEnd,
149 }) 137 })
  138 +
  139 + // 创建发送任务
  140 + _, err := staffAssessService.CreateStaffAssessTask(transactionContext, csat)
  141 + if err != nil {
  142 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  143 + }
150 } else { 144 } else {
151 - task.NextSentAt = nil 145 + task.NextSentAt = nil // 项目不存在,取消周期任务发送
152 } 146 }
153 147
154 task, err := taskRepository.Insert(task) 148 task, err := taskRepository.Insert(task)
@@ -157,15 +151,6 @@ func (rs *NodeTaskService) SendEvaluationNode() error { @@ -157,15 +151,6 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
157 } 151 }
158 } 152 }
159 153
160 - staffAssessService := service.NewStaffAssessServeice()  
161 - for i := range staffAssessTaskMap {  
162 - staffAssessTask := staffAssessTaskMap[i]  
163 - _, err := staffAssessService.CreateStaffAssessTask(transactionContext, staffAssessTask)  
164 - if err != nil {  
165 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
166 - }  
167 - }  
168 -  
169 if err := transactionContext.CommitTransaction(); err != nil { 154 if err := transactionContext.CommitTransaction(); err != nil {
170 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 155 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
171 } 156 }
@@ -13,6 +13,7 @@ type NodeTask struct { @@ -13,6 +13,7 @@ type NodeTask struct {
13 NodeType int `json:"nodeType" comment:"环节类型"` 13 NodeType int `json:"nodeType" comment:"环节类型"`
14 NodeName string `json:"nodeName" comment:"环节名称"` 14 NodeName string `json:"nodeName" comment:"环节名称"`
15 NodeDescribe string `json:"nodeDescribe" comment:"环节描述"` 15 NodeDescribe string `json:"nodeDescribe" comment:"环节描述"`
  16 + NodeSort int `json:"nodeSort" comment:"环节顺序"`
16 TimeStart *time.Time `json:"timeStart" comment:"起始时间"` 17 TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
17 TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"` 18 TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
18 KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"` 19 KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
@@ -14,6 +14,7 @@ type NodeTask struct { @@ -14,6 +14,7 @@ type NodeTask struct {
14 NodeType int `comment:"环节类型"` 14 NodeType int `comment:"环节类型"`
15 NodeName string `comment:"环节名称"` 15 NodeName string `comment:"环节名称"`
16 NodeDescribe string `comment:"环节描述"` 16 NodeDescribe string `comment:"环节描述"`
  17 + NodeSort int `comment:"环节顺序"`
17 TimeStart *time.Time `comment:"起始时间"` 18 TimeStart *time.Time `comment:"起始时间"`
18 TimeEnd *time.Time `comment:"截至时间"` 19 TimeEnd *time.Time `comment:"截至时间"`
19 KpiCycle int `comment:"考核周期(1日、2周、3月)"` 20 KpiCycle int `comment:"考核周期(1日、2周、3月)"`
@@ -123,6 +123,10 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{}) @@ -123,6 +123,10 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
123 query.Where("name LIKE ?", v) 123 query.Where("name LIKE ?", v)
124 } 124 }
125 125
  126 + if v, ok := queryOptions["ids"]; ok {
  127 + query.Where("id in (?)", pg.In(v))
  128 + }
  129 +
126 if v, ok := queryOptions["companyId"]; ok { 130 if v, ok := queryOptions["companyId"]; ok {
127 query.Where("company_id = ?", v) 131 query.Where("company_id = ?", v)
128 } 132 }
@@ -131,6 +131,10 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{ @@ -131,6 +131,10 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{
131 query.ExcludeColumn(excludeColumns...) 131 query.ExcludeColumn(excludeColumns...)
132 } 132 }
133 133
  134 + if v, ok := queryOptions["ids"]; ok {
  135 + query.Where("id in (?)", pg.In(v))
  136 + }
  137 +
134 if v, ok := queryOptions["name"].(string); ok && len(v) > 0 { 138 if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
135 query.Where("name = ?", v) 139 query.Where("name = ?", v)
136 } 140 }
@@ -30,6 +30,7 @@ func (repo *NodeTaskRepository) TransformToDomain(m *models.NodeTask) domain.Nod @@ -30,6 +30,7 @@ func (repo *NodeTaskRepository) TransformToDomain(m *models.NodeTask) domain.Nod
30 NodeType: m.NodeType, 30 NodeType: m.NodeType,
31 NodeName: m.NodeName, 31 NodeName: m.NodeName,
32 NodeDescribe: m.NodeDescribe, 32 NodeDescribe: m.NodeDescribe,
  33 + NodeSort: m.NodeSort,
33 TimeStart: m.TimeStart, 34 TimeStart: m.TimeStart,
34 TimeEnd: m.TimeEnd, 35 TimeEnd: m.TimeEnd,
35 KpiCycle: m.KpiCycle, 36 KpiCycle: m.KpiCycle,
@@ -50,6 +51,7 @@ func (repo *NodeTaskRepository) TransformToModel(d *domain.NodeTask) models.Node @@ -50,6 +51,7 @@ func (repo *NodeTaskRepository) TransformToModel(d *domain.NodeTask) models.Node
50 NodeType: d.NodeType, 51 NodeType: d.NodeType,
51 NodeName: d.NodeName, 52 NodeName: d.NodeName,
52 NodeDescribe: d.NodeDescribe, 53 NodeDescribe: d.NodeDescribe,
  54 + NodeSort: d.NodeSort,
53 TimeStart: d.TimeStart, 55 TimeStart: d.TimeStart,
54 TimeEnd: d.TimeEnd, 56 TimeEnd: d.TimeEnd,
55 KpiCycle: d.KpiCycle, 57 KpiCycle: d.KpiCycle,
@@ -43,7 +43,7 @@ func NextTime(now0 time.Time, start *time.Time, kpiCycle int) time.Time { @@ -43,7 +43,7 @@ func NextTime(now0 time.Time, start *time.Time, kpiCycle int) time.Time {
43 var nextTime time.Time 43 var nextTime time.Time
44 switch kpiCycle { 44 switch kpiCycle {
45 case domain.KpiCycleDay: 45 case domain.KpiCycleDay:
46 - nextTime = timeconv.AddDate(now0, 0, 0, 1) // 当前时间的下一天开始发送 46 + nextTime = timeconv.AddDate(now0, 0, 0, 1) // 当前时间的下一天0点开始发送
47 break 47 break
48 case domain.KpiCycleWeek: 48 case domain.KpiCycleWeek:
49 offsetSeconds := int64(now0.Sub(start0).Seconds()) 49 offsetSeconds := int64(now0.Sub(start0).Seconds())