作者 tangxvhui

日常保存

@@ -470,7 +470,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task @@ -470,7 +470,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
470 ParentId: leaderData.ParentId, 470 ParentId: leaderData.ParentId,
471 }, 471 },
472 Status: int(taskData.Status), 472 Status: int(taskData.Status),
473 - StatusDescription: taskData.StatusDescription(), 473 + StatusDescription: taskData.Status.Named(),
474 // Level: taskData.Level, 474 // Level: taskData.Level,
475 LevelName: taskData.LevelName, 475 LevelName: taskData.LevelName,
476 SortBy: int(taskData.SortBy), 476 SortBy: int(taskData.SortBy),
@@ -14,6 +14,18 @@ const ( @@ -14,6 +14,18 @@ const (
14 TaskStop TaskState = 3 //任务停止 14 TaskStop TaskState = 3 //任务停止
15 ) 15 )
16 16
  17 +func (t TaskState) Named() string {
  18 + switch t {
  19 + case TaskWait:
  20 + return "待启动"
  21 + case TaskRunning:
  22 + return "启动中"
  23 + case TaskStop:
  24 + return "停止"
  25 + }
  26 + return ""
  27 +}
  28 +
17 type TaskWarnFlag int 29 type TaskWarnFlag int
18 30
19 const ( 31 const (
@@ -88,17 +100,6 @@ func (t *Task) ApplyLevelName(name string) { @@ -88,17 +100,6 @@ func (t *Task) ApplyLevelName(name string) {
88 } 100 }
89 101
90 // StatusDescript 102 // StatusDescript
91 -func (t *Task) StatusDescription() string {  
92 - switch t.Status {  
93 - case TaskWait:  
94 - return "待启动"  
95 - case TaskRunning:  
96 - return "启动中"  
97 - case TaskStop:  
98 - return "停止"  
99 - }  
100 - return ""  
101 -}  
102 103
103 // 记录待执行的里程碑,和上一个执行的里程碑 104 // 记录待执行的里程碑,和上一个执行的里程碑
104 func (t *Task) SetCurrentStage(stageList []*TaskStage) { 105 func (t *Task) SetCurrentStage(stageList []*TaskStage) {
@@ -108,6 +109,7 @@ func (t *Task) SetCurrentStage(stageList []*TaskStage) { @@ -108,6 +109,7 @@ func (t *Task) SetCurrentStage(stageList []*TaskStage) {
108 sort.Slice(stageList, func(i, j int) bool { 109 sort.Slice(stageList, func(i, j int) bool {
109 return stageList[i].SortBy < stageList[j].SortBy 110 return stageList[i].SortBy < stageList[j].SortBy
110 }) 111 })
  112 + t.LastStage = TaskStage{}
111 t.CurrentStage = TaskStage{} 113 t.CurrentStage = TaskStage{}
112 for _, val := range stageList { 114 for _, val := range stageList {
113 if val.DeletedAt != nil { 115 if val.DeletedAt != nil {
@@ -119,6 +121,10 @@ func (t *Task) SetCurrentStage(stageList []*TaskStage) { @@ -119,6 +121,10 @@ func (t *Task) SetCurrentStage(stageList []*TaskStage) {
119 break 121 break
120 } 122 }
121 } 123 }
  124 + if t.CurrentStage.RealCompletedAt > 0 {
  125 + t.LastStage = t.CurrentStage
  126 + t.CurrentStage = TaskStage{}
  127 + }
122 } 128 }
123 129
124 // 设置优先级的值 130 // 设置优先级的值
@@ -133,6 +139,29 @@ func (t *Task) SetSortBy(a int) error { @@ -133,6 +139,29 @@ func (t *Task) SetSortBy(a int) error {
133 return nil 139 return nil
134 } 140 }
135 141
  142 +func (t *Task) DescriptTaskStatus() string {
  143 + statusNamed := ""
  144 + if t.Status == TaskRunning {
  145 + statusNamed = "进行中"
  146 + }
  147 + if t.CurrentStage.Id == 0 && t.LastStage.PlanCompletedAt < t.LastStage.RealCompletedAt {
  148 + statusNamed = "逾期完成"
  149 + }
  150 + if t.CurrentStage.Id == 0 && t.LastStage.PlanCompletedAt >= t.LastStage.RealCompletedAt {
  151 + statusNamed = "如期完成"
  152 + }
  153 + if t.Status == TaskStop {
  154 + statusNamed = "已停止"
  155 + }
  156 + if t.WarnFlag == TaskWarn {
  157 + statusNamed = "里程碑异常"
  158 + }
  159 + if t.Anomaly > 0 {
  160 + statusNamed = "反馈异常"
  161 + }
  162 + return statusNamed
  163 +}
  164 +
136 type TaskRepository interface { 165 type TaskRepository interface {
137 Save(param *Task) error 166 Save(param *Task) error
138 Remove(id int) error 167 Remove(id int) error