作者 tangxvhui

更新 task结构

@@ -91,6 +91,7 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont @@ -91,6 +91,7 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
91 } 91 }
92 leaderData := leaderList[0] 92 leaderData := leaderList[0]
93 nowTime := time.Now() 93 nowTime := time.Now()
  94 + nowEndTime := dayEndTime(nowTime)
94 newTask := domain.Task{ 95 newTask := domain.Task{
95 Id: 0, 96 Id: 0,
96 CreatedAt: time.Time{}, 97 CreatedAt: time.Time{},
@@ -116,7 +117,6 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont @@ -116,7 +117,6 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
116 if err != nil { 117 if err != nil {
117 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) 118 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
118 } 119 }
119 - nowEndTime := dayEndTime(nowTime)  
120 newTaskStage := []*domain.TaskStage{ 120 newTaskStage := []*domain.TaskStage{
121 { 121 {
122 Id: 0, 122 Id: 0,
@@ -143,11 +143,15 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont @@ -143,11 +143,15 @@ func (srv TaskService) CreateTask(transactionContext application.TransactionCont
143 RealCompletedAt: 0, 143 RealCompletedAt: 0,
144 }, 144 },
145 } 145 }
146 -  
147 err = taskStageRepo.Save(newTaskStage) 146 err = taskStageRepo.Save(newTaskStage)
148 if err != nil { 147 if err != nil {
149 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error()) 148 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "创建任务失败:"+err.Error())
150 } 149 }
  150 + newTask.CurrentStage = *newTaskStage[0]
  151 + err = taskRepo.Save(&newTask)
  152 + if err != nil {
  153 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务失败:"+err.Error())
  154 + }
151 return nil 155 return nil
152 } 156 }
153 157
@@ -282,11 +286,17 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string] @@ -282,11 +286,17 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
282 } 286 }
283 } 287 }
284 } 288 }
285 - 289 + //更新当前 执行的里程碑
286 err = taskStageRepo.Save(stageList) 290 err = taskStageRepo.Save(stageList)
287 if err != nil { 291 if err != nil {
288 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 292 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
289 } 293 }
  294 + for _, val := range stageList {
  295 + if val.RealCompletedAt == 0 {
  296 + taskData.CurrentStage = *val
  297 + break
  298 + }
  299 + }
290 err = taskRepo.Save(taskData) 300 err = taskRepo.Save(taskData)
291 if err != nil { 301 if err != nil {
292 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 302 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -770,6 +780,7 @@ func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]i @@ -770,6 +780,7 @@ func (srv TaskService) ListTask2(param *command.SearchTaskCommand) (map[string]i
770 case 5: 780 case 5:
771 taskData.StageE = stage 781 taskData.StageE = stage
772 } 782 }
  783 +
773 } 784 }
774 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult) 785 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
775 result["taskStageAnomaly"] = taskStageAnomalyCnt 786 result["taskStageAnomaly"] = taskStageAnomalyCnt
@@ -896,38 +907,43 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction @@ -896,38 +907,43 @@ func (srv TaskService) ReplyTaskStage(transactionContext application.Transaction
896 taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{ 907 taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
897 "transactionContext": transactionContext, 908 "transactionContext": transactionContext,
898 }) 909 })
899 - var taskList []*domain.Task  
900 - var taskStages []*domain.TaskStage  
901 for _, val := range param { 910 for _, val := range param {
902 taskData, err := taskRepo.FindOne(map[string]interface{}{"id": val.TaskId}) 911 taskData, err := taskRepo.FindOne(map[string]interface{}{"id": val.TaskId})
903 if err != nil { 912 if err != nil {
904 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "找不到任务数据"+err.Error()) 913 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "找不到任务数据"+err.Error())
905 } 914 }
906 - _, stageList, err := taskStageRepo.Find(map[string]interface{}{"ids": []int{val.TaskStageCheck.Id}}) 915 + _, stageList, err := taskStageRepo.Find(map[string]interface{}{"taskId": []int{val.TaskId}})
907 if err != nil { 916 if err != nil {
908 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "找不到任务里程碑数据"+err.Error()) 917 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "找不到任务里程碑数据"+err.Error())
909 } 918 }
910 if val.AnomalyState == domain.AnomalyState1 { 919 if val.AnomalyState == domain.AnomalyState1 {
911 taskData.Anomaly = 0 920 taskData.Anomaly = 0
912 } 921 }
913 - if len(stageList) > 0 {  
914 - stageList[0].RealCompletedAt = val.TaskStageCheck.RealCompletedAt  
915 - taskStages = append(taskStages, stageList[0])  
916 - if stageList[0].PlanCompletedAt < stageList[0].RealCompletedAt { 922 + for _, val2 := range stageList {
  923 + if val2.Id == val.TaskStageCheck.Id {
  924 + continue
  925 + }
  926 + val2.RealCompletedAt = val.TaskStageCheck.RealCompletedAt
  927 + if val2.PlanCompletedAt < val2.RealCompletedAt {
917 taskData.WarnFlag = domain.TaskWarn 928 taskData.WarnFlag = domain.TaskWarn
918 } else { 929 } else {
919 taskData.WarnFlag = domain.TaskWarnNull 930 taskData.WarnFlag = domain.TaskWarnNull
920 } 931 }
  932 + break
921 } 933 }
922 -  
923 - taskList = append(taskList, taskData) 934 + taskData.CurrentStage = domain.TaskStage{}
  935 + //设置下一个 待执行的里程碑
  936 + for _, val2 := range stageList {
  937 + if val2.RealCompletedAt == 0 {
  938 + taskData.CurrentStage = *val2
  939 + break
924 } 940 }
925 - err := taskStageRepo.Save(taskStages) 941 + }
  942 + err = taskStageRepo.Save(stageList)
926 if err != nil { 943 if err != nil {
927 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error()) 944 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error())
928 } 945 }
929 - for _, val := range taskList {  
930 - err = taskRepo.Save(val) 946 + err = taskRepo.Save(taskData)
931 if err != nil { 947 if err != nil {
932 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error()) 948 return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务数据"+err.Error())
933 } 949 }
@@ -35,6 +35,7 @@ type Task struct { @@ -35,6 +35,7 @@ type Task struct {
35 StopAt int64 `json:"stopAt"` // 停止的时间戳,秒 35 StopAt int64 `json:"stopAt"` // 停止的时间戳,秒
36 Anomaly int `json:"anomaly"` // 异常反馈的次数 36 Anomaly int `json:"anomaly"` // 异常反馈的次数
37 WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记 37 WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记
  38 + CurrentStage TaskStage `json:"currentStage"` // 当前执行的里程碑
38 } 39 }
39 40
40 type TaskLeader struct { 41 type TaskLeader struct {
@@ -196,6 +196,7 @@ func (d *StaffAssessDao) SearchTargetUserCycleProject(companyId int, targetUserI @@ -196,6 +196,7 @@ func (d *StaffAssessDao) SearchTargetUserCycleProject(companyId int, targetUserI
196 and staff_assess."types" ='self' 196 and staff_assess."types" ='self'
197 and staff_assess_task.deleted_at isnull 197 and staff_assess_task.deleted_at isnull
198 and staff_assess.deleted_at isnull 198 and staff_assess.deleted_at isnull
  199 + and staff_assess.end_time <=now()
199 and staff_assess.target_user ->>'userId'='?' 200 and staff_assess.target_user ->>'userId'='?'
200 and staff_assess.company_id=? 201 and staff_assess.company_id=?
201 ` 202 `
@@ -25,4 +25,5 @@ type Task struct { @@ -25,4 +25,5 @@ type Task struct {
25 StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间 25 StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间
26 Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量 26 Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量
27 WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记 27 WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记
  28 + CurrentStage domain.TaskStage `pg:"current_stage"` // 当前执行的里程碑
28 } 29 }
@@ -42,6 +42,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { @@ -42,6 +42,7 @@ func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
42 StopAt: d.StopAt, 42 StopAt: d.StopAt,
43 Anomaly: d.Anomaly, 43 Anomaly: d.Anomaly,
44 WarnFlag: domain.TaskWarnFlag(d.WarnFlag), 44 WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
  45 + CurrentStage: d.CurrentStage,
45 } 46 }
46 } 47 }
47 48
@@ -67,6 +68,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error { @@ -67,6 +68,7 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
67 StopAt: param.StopAt, 68 StopAt: param.StopAt,
68 Anomaly: param.Anomaly, 69 Anomaly: param.Anomaly,
69 WarnFlag: int(param.WarnFlag), 70 WarnFlag: int(param.WarnFlag),
  71 + CurrentStage: param.CurrentStage,
70 } 72 }
71 db := repo.transactionContext.PgTx 73 db := repo.transactionContext.PgTx
72 if m.Id == 0 { 74 if m.Id == 0 {
@@ -75,28 +75,3 @@ SET @@ -75,28 +75,3 @@ SET
75 WHERE 75 WHERE
76 id IN (18404, 18458); 76 id IN (18404, 18458);
77 77
78 ---  
79 -WITH t1 AS (  
80 - SELECT  
81 - summary_evaluation_value.evaluation_item_id,  
82 - summary_evaluation_value.value,  
83 - summary_evaluation_value.id AS value_id,  
84 - summary_evaluation_value.score,  
85 - summary_evaluation.company_id  
86 - FROM  
87 - summary_evaluation_value  
88 - JOIN summary_evaluation ON summary_evaluation_value.summary_evaluation_id = summary_evaluation.id  
89 - WHERE  
90 - summary_evaluation_value.value = summary_evaluation_value.score  
91 - AND summary_evaluation."types" = 1  
92 - ORDER BY  
93 - summary_evaluation_value.created_at  
94 -)  
95 -SELECT  
96 - t1.value_id,  
97 - cast(evaluation_item_used.weight AS float) AS weight,  
98 - cast(t1.value AS float) AS value,  
99 - cast(t1.value AS float) * cast(evaluation_item_used.weight AS float) AS real_value  
100 -FROM  
101 - evaluation_item_used  
102 - JOIN t1 ON t1.evaluation_item_id = evaluation_item_used.id  
  1 +-- 调整 summary_evaluation_value 数据
  2 +WITH t1 AS (
  3 + SELECT
  4 + summary_evaluation_value.evaluation_item_id,
  5 + summary_evaluation_value.value,
  6 + summary_evaluation_value.id AS value_id,
  7 + summary_evaluation_value.score,
  8 + summary_evaluation.company_id
  9 + FROM
  10 + summary_evaluation_value
  11 + JOIN summary_evaluation ON summary_evaluation_value.summary_evaluation_id = summary_evaluation.id
  12 + JOIN evaluation_item_used ON evaluation_item_used.id = summary_evaluation_value.evaluation_item_id
  13 + WHERE
  14 + summary_evaluation_value.value = summary_evaluation_value.score
  15 + AND summary_evaluation."types" = 1
  16 + AND evaluation_item_used.weight > 0
  17 + ORDER BY
  18 + summary_evaluation_value.created_at
  19 +),
  20 +t2 AS (
  21 + SELECT
  22 + t1.value_id,
  23 + cast(evaluation_item_used.weight AS float) AS weight,
  24 + cast(t1.value AS float) AS value,
  25 + cast(t1.value AS float) * cast(evaluation_item_used.weight AS float) AS real_value
  26 +FROM
  27 + evaluation_item_used
  28 + JOIN t1 ON t1.evaluation_item_id = evaluation_item_used.id)
  29 +UPDATE
  30 + summary_evaluation_value
  31 +SET
  32 + score = t2.real_value
  33 +FROM
  34 + t2
  35 +WHERE
  36 + summary_evaluation_value.id = t2.value_id;
  37 +
  38 +-- 调整summary_evaluation 数据
  39 +WITH t1 AS (
  40 + SELECT
  41 + sum(cast(summary_evaluation_value.score AS float)) AS total_score,
  42 + summary_evaluation_value.summary_evaluation_id
  43 + FROM
  44 + summary_evaluation_value
  45 + JOIN summary_evaluation ON summary_evaluation_value.summary_evaluation_id = summary_evaluation.id
  46 + JOIN evaluation_item_used ON evaluation_item_used.id = summary_evaluation_value.evaluation_item_id
  47 + WHERE
  48 + summary_evaluation."types" = 1
  49 + AND evaluation_item_used.weight > 0
  50 + GROUP BY
  51 + summary_evaluation_value.summary_evaluation_id)
  52 +UPDATE
  53 + summary_evaluation
  54 +SET
  55 + total_score = t1.total_score
  56 +FROM
  57 + t1
  58 +WHERE
  59 + summary_evaluation.id = t1.summary_evaluation_id