作者 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)  
924 - }  
925 - err := taskStageRepo.Save(taskStages)  
926 - if err != nil {  
927 - return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error())  
928 - }  
929 - for _, val := range taskList {  
930 - err = taskRepo.Save(val) 934 + taskData.CurrentStage = domain.TaskStage{}
  935 + //设置下一个 待执行的里程碑
  936 + for _, val2 := range stageList {
  937 + if val2.RealCompletedAt == 0 {
  938 + taskData.CurrentStage = *val2
  939 + break
  940 + }
  941 + }
  942 + err = taskStageRepo.Save(stageList)
  943 + if err != nil {
  944 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务里程碑数据"+err.Error())
  945 + }
  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 }
@@ -19,22 +19,23 @@ const ( @@ -19,22 +19,23 @@ const (
19 19
20 // 任务 20 // 任务
21 type Task struct { 21 type Task struct {
22 - Id int `json:"id"`  
23 - CreatedAt time.Time `json:"createdAt"`  
24 - UpdatedAt time.Time `json:"updatedAt"`  
25 - DeletedAt *time.Time `json:"deletedAt"`  
26 - CompanyId int `json:"companyId,string"`  
27 - Name string `json:"name"` // 任务名称  
28 - Alias string `json:"alias"` // 任务别名  
29 - Leader TaskLeader `json:"leader"` // 任务负责人  
30 - Status TaskState `json:"status"` // 任务的状态  
31 - Level int `json:"level"` // 优先级,值越小优先级越高  
32 - LevelName string `json:"levelName"` // 优先级名称  
33 - RelatedUser []int `json:"relatedUser"` // 相关的员工id  
34 - RunAt int64 `json:"runAt"` // 启动的时间戳,秒  
35 - StopAt int64 `json:"stopAt"` // 停止的时间戳,秒  
36 - Anomaly int `json:"anomaly"` // 异常反馈的次数  
37 - WarnFlag TaskWarnFlag `json:"warnFlag"` // 里程碑异常标记 22 + Id int `json:"id"`
  23 + CreatedAt time.Time `json:"createdAt"`
  24 + UpdatedAt time.Time `json:"updatedAt"`
  25 + DeletedAt *time.Time `json:"deletedAt"`
  26 + CompanyId int `json:"companyId,string"`
  27 + Name string `json:"name"` // 任务名称
  28 + Alias string `json:"alias"` // 任务别名
  29 + Leader TaskLeader `json:"leader"` // 任务负责人
  30 + Status TaskState `json:"status"` // 任务的状态
  31 + Level int `json:"level"` // 优先级,值越小优先级越高
  32 + LevelName string `json:"levelName"` // 优先级名称
  33 + RelatedUser []int `json:"relatedUser"` // 相关的员工id
  34 + RunAt int64 `json:"runAt"` // 启动的时间戳,秒
  35 + StopAt int64 `json:"stopAt"` // 停止的时间戳,秒
  36 + Anomaly int `json:"anomaly"` // 异常反馈的次数
  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 `
@@ -8,21 +8,22 @@ import ( @@ -8,21 +8,22 @@ import (
8 8
9 // 任务 9 // 任务
10 type Task struct { 10 type Task struct {
11 - tableName struct{} `comment:"任务" pg:"task"`  
12 - Id int `pg:"id,pk"` //  
13 - CreatedAt time.Time `pg:"created_at"` //  
14 - UpdatedAt time.Time `pg:"updated_at"` //  
15 - DeletedAt *time.Time `pg:"deleted_at"` //  
16 - Name string `pg:"name"` // 任务名称  
17 - Alias string `pg:"alias"` //  
18 - CompanyId int `pg:"company_id"` //  
19 - Leader domain.TaskLeader `pg:"leader"` // 任务负责人  
20 - Status int `pg:"status,use_zero"` // 任务的状态  
21 - Level int `pg:"level,use_zero"` // 优先级,值越小优先级越高  
22 - LevelName string `pg:"level_name"` // 优先级名称  
23 - RelatedUser []int `pg:"related_user"` //  
24 - RunAt int64 `pg:"run_at,use_zero"` // 启动的时间  
25 - StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间  
26 - Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量  
27 - WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记 11 + tableName struct{} `comment:"任务" pg:"task"`
  12 + Id int `pg:"id,pk"` //
  13 + CreatedAt time.Time `pg:"created_at"` //
  14 + UpdatedAt time.Time `pg:"updated_at"` //
  15 + DeletedAt *time.Time `pg:"deleted_at"` //
  16 + Name string `pg:"name"` // 任务名称
  17 + Alias string `pg:"alias"` //
  18 + CompanyId int `pg:"company_id"` //
  19 + Leader domain.TaskLeader `pg:"leader"` // 任务负责人
  20 + Status int `pg:"status,use_zero"` // 任务的状态
  21 + Level int `pg:"level,use_zero"` // 优先级,值越小优先级越高
  22 + LevelName string `pg:"level_name"` // 优先级名称
  23 + RelatedUser []int `pg:"related_user"` //
  24 + RunAt int64 `pg:"run_at,use_zero"` // 启动的时间
  25 + StopAt int64 `pg:"stop_at,use_zero" ` // 停止的时间
  26 + Anomaly int `pg:"anomaly,use_zero"` // 异常反馈的数量
  27 + WarnFlag int `pg:"warn_flag,use_zero"` // 里程碑异常标记
  28 + CurrentStage domain.TaskStage `pg:"current_stage"` // 当前执行的里程碑
28 } 29 }
@@ -26,22 +26,23 @@ func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) *Ta @@ -26,22 +26,23 @@ func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) *Ta
26 26
27 func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task { 27 func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
28 return &domain.Task{ 28 return &domain.Task{
29 - Id: d.Id,  
30 - CreatedAt: d.CreatedAt,  
31 - UpdatedAt: d.UpdatedAt,  
32 - DeletedAt: d.DeletedAt,  
33 - CompanyId: d.CompanyId,  
34 - Name: d.Name,  
35 - Alias: d.Alias,  
36 - Leader: d.Leader,  
37 - Status: domain.TaskState(d.Status),  
38 - Level: d.Level,  
39 - LevelName: d.LevelName,  
40 - RelatedUser: d.RelatedUser,  
41 - RunAt: d.RunAt,  
42 - StopAt: d.StopAt,  
43 - Anomaly: d.Anomaly,  
44 - WarnFlag: domain.TaskWarnFlag(d.WarnFlag), 29 + Id: d.Id,
  30 + CreatedAt: d.CreatedAt,
  31 + UpdatedAt: d.UpdatedAt,
  32 + DeletedAt: d.DeletedAt,
  33 + CompanyId: d.CompanyId,
  34 + Name: d.Name,
  35 + Alias: d.Alias,
  36 + Leader: d.Leader,
  37 + Status: domain.TaskState(d.Status),
  38 + Level: d.Level,
  39 + LevelName: d.LevelName,
  40 + RelatedUser: d.RelatedUser,
  41 + RunAt: d.RunAt,
  42 + StopAt: d.StopAt,
  43 + Anomaly: d.Anomaly,
  44 + WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
  45 + CurrentStage: d.CurrentStage,
45 } 46 }
46 } 47 }
47 48
@@ -51,22 +52,23 @@ func (repo *TaskRepository) Save(param *domain.Task) error { @@ -51,22 +52,23 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
51 param.CreatedAt = time.Now() 52 param.CreatedAt = time.Now()
52 } 53 }
53 m := models.Task{ 54 m := models.Task{
54 - Id: param.Id,  
55 - CreatedAt: param.CreatedAt,  
56 - UpdatedAt: param.UpdatedAt,  
57 - DeletedAt: param.DeletedAt,  
58 - Name: param.Name,  
59 - Alias: param.Alias,  
60 - CompanyId: param.CompanyId,  
61 - Leader: param.Leader,  
62 - Status: int(param.Status),  
63 - Level: param.Level,  
64 - LevelName: param.LevelName,  
65 - RelatedUser: param.RelatedUser,  
66 - RunAt: param.RunAt,  
67 - StopAt: param.StopAt,  
68 - Anomaly: param.Anomaly,  
69 - WarnFlag: int(param.WarnFlag), 55 + Id: param.Id,
  56 + CreatedAt: param.CreatedAt,
  57 + UpdatedAt: param.UpdatedAt,
  58 + DeletedAt: param.DeletedAt,
  59 + Name: param.Name,
  60 + Alias: param.Alias,
  61 + CompanyId: param.CompanyId,
  62 + Leader: param.Leader,
  63 + Status: int(param.Status),
  64 + Level: param.Level,
  65 + LevelName: param.LevelName,
  66 + RelatedUser: param.RelatedUser,
  67 + RunAt: param.RunAt,
  68 + StopAt: param.StopAt,
  69 + Anomaly: param.Anomaly,
  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