作者 tangxvhui

Merge branch 'dev-tangxvhui' into test

1 package adapter 1 package adapter
2 2
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  5 +)
  6 +
3 type TaskItem struct { 7 type TaskItem struct {
4 Id int `json:"id,string"` 8 Id int `json:"id,string"`
5 Name string `json:"name"` // 任务名称 9 Name string `json:"name"` // 任务名称
6 Alias string `json:"alias"` // 任务别名 10 Alias string `json:"alias"` // 任务别名
7 Leader string `json:"leader"` // 任务负责人 11 Leader string `json:"leader"` // 任务负责人
8 Status int `json:"status"` // 任务的状态 12 Status int `json:"status"` // 任务的状态
9 - Level int `json:"level"` // 优先级,值越小优先级越高  
10 - LevelName string `json:"levelName"` // 优先级名称 13 + StatusDescript string `json:"statusDescript"` //任务的整体状态描述
  14 + SortBy int `json:"level"` // 优先级,值越小优先级越高
  15 + LevelName string `json:"levelName"` // 任务分类名称
11 StageA TaskStage `json:"stageA"` // 里程碑1 16 StageA TaskStage `json:"stageA"` // 里程碑1
12 StageB TaskStage `json:"stageB"` // 里程碑2 17 StageB TaskStage `json:"stageB"` // 里程碑2
13 StageC TaskStage `json:"stageC"` // 里程碑3 18 StageC TaskStage `json:"stageC"` // 里程碑3
@@ -19,3 +24,26 @@ type TaskItem struct { @@ -19,3 +24,26 @@ type TaskItem struct {
19 Anomaly int `json:"anomaly"` //异常反馈情况 24 Anomaly int `json:"anomaly"` //异常反馈情况
20 WarnFlag int `json:"warnFlag"` //里程碑完成时间异常标记 0:正常 1标记为异常 25 WarnFlag int `json:"warnFlag"` //里程碑完成时间异常标记 0:正常 1标记为异常
21 } 26 }
  27 +
  28 +func (t *TaskItem) GenStatusDescript() {
  29 + statusNamed := ""
  30 + if domain.TaskState(t.Status) == domain.TaskRunning {
  31 + statusNamed = "进行中"
  32 + }
  33 + if t.CurrentStage.Id == 0 && t.LastStage.PlanCompletedAt < t.LastStage.RealCompletedAt {
  34 + statusNamed = "逾期完成"
  35 + }
  36 + if t.CurrentStage.Id == 0 && t.LastStage.PlanCompletedAt >= t.LastStage.RealCompletedAt {
  37 + statusNamed = "如期完成"
  38 + }
  39 + if domain.TaskState(t.Status) == domain.TaskStop {
  40 + statusNamed = "已停止"
  41 + }
  42 + if domain.TaskWarnFlag(t.WarnFlag) == domain.TaskWarn {
  43 + statusNamed = "里程碑异常"
  44 + }
  45 + if t.Anomaly > 0 {
  46 + statusNamed = "反馈异常"
  47 + }
  48 + t.StatusDescript = statusNamed
  49 +}
@@ -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),
@@ -655,7 +655,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte @@ -655,7 +655,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte
655 Alias: val.Alias, 655 Alias: val.Alias,
656 Leader: val.Leader.Name, 656 Leader: val.Leader.Name,
657 Status: int(val.Status), 657 Status: int(val.Status),
658 - Level: val.Level, 658 + SortBy: int(val.SortBy),
659 LevelName: val.LevelName, 659 LevelName: val.LevelName,
660 Anomaly: val.Anomaly, 660 Anomaly: val.Anomaly,
661 WarnFlag: int(val.WarnFlag), 661 WarnFlag: int(val.WarnFlag),
@@ -1069,7 +1069,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i @@ -1069,7 +1069,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
1069 Alias: val.Alias, 1069 Alias: val.Alias,
1070 Leader: val.LeaderName, 1070 Leader: val.LeaderName,
1071 Status: val.Status, 1071 Status: val.Status,
1072 - Level: val.Level, 1072 + SortBy: val.SortBy,
1073 LevelName: val.LevelName, 1073 LevelName: val.LevelName,
1074 UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"), 1074 UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
1075 Anomaly: val.Anomaly, 1075 Anomaly: val.Anomaly,
@@ -1135,6 +1135,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i @@ -1135,6 +1135,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
1135 tk.StageE = stage 1135 tk.StageE = stage
1136 } 1136 }
1137 } 1137 }
  1138 + tk.GenStatusDescript()
1138 taskResult = append(taskResult, &tk) 1139 taskResult = append(taskResult, &tk)
1139 } 1140 }
1140 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult) 1141 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
@@ -1216,7 +1217,7 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s @@ -1216,7 +1217,7 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
1216 Alias: val.Alias, 1217 Alias: val.Alias,
1217 Leader: val.LeaderName, 1218 Leader: val.LeaderName,
1218 Status: val.Status, 1219 Status: val.Status,
1219 - Level: val.Level, 1220 + SortBy: val.SortBy,
1220 LevelName: val.LevelName, 1221 LevelName: val.LevelName,
1221 UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"), 1222 UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
1222 Anomaly: val.Anomaly, 1223 Anomaly: val.Anomaly,
@@ -1228,7 +1229,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s @@ -1228,7 +1229,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
1228 SortBy: val.LastStage.SortBy, 1229 SortBy: val.LastStage.SortBy,
1229 PlanCompletedAt: time.Unix(int64(val.LastStage.PlanCompletedAt), 0).Local().Format("2006-01-02"), 1230 PlanCompletedAt: time.Unix(int64(val.LastStage.PlanCompletedAt), 0).Local().Format("2006-01-02"),
1230 RealCompletedAt: "", 1231 RealCompletedAt: "",
1231 - IsRef: false,  
1232 }, 1232 },
1233 CurrentStage: adapter.TaskStage{ 1233 CurrentStage: adapter.TaskStage{
1234 Id: val.CurrentStage.Id, 1234 Id: val.CurrentStage.Id,
@@ -1237,7 +1237,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s @@ -1237,7 +1237,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
1237 SortBy: val.CurrentStage.SortBy, 1237 SortBy: val.CurrentStage.SortBy,
1238 PlanCompletedAt: time.Unix(int64(val.CurrentStage.PlanCompletedAt), 0).Local().Format("2006-01-02"), 1238 PlanCompletedAt: time.Unix(int64(val.CurrentStage.PlanCompletedAt), 0).Local().Format("2006-01-02"),
1239 RealCompletedAt: "", 1239 RealCompletedAt: "",
1240 - IsRef: false,  
1241 }, 1240 },
1242 } 1241 }
1243 if val.LastStage.RealCompletedAt > 0 { 1242 if val.LastStage.RealCompletedAt > 0 {
@@ -1283,6 +1282,7 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s @@ -1283,6 +1282,7 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
1283 tk.StageE = stage 1282 tk.StageE = stage
1284 } 1283 }
1285 } 1284 }
  1285 + tk.GenStatusDescript()
1286 taskResult = append(taskResult, &tk) 1286 taskResult = append(taskResult, &tk)
1287 } 1287 }
1288 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult) 1288 result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
@@ -1388,7 +1388,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result @@ -1388,7 +1388,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
1388 Alias: val.Alias, 1388 Alias: val.Alias,
1389 Leader: val.LeaderName, 1389 Leader: val.LeaderName,
1390 Status: val.Status, 1390 Status: val.Status,
1391 - Level: val.Level, 1391 + SortBy: val.SortBy,
1392 LevelName: val.LevelName, 1392 LevelName: val.LevelName,
1393 UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"), 1393 UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
1394 Anomaly: val.Anomaly, 1394 Anomaly: val.Anomaly,
@@ -1400,7 +1400,6 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result @@ -1400,7 +1400,6 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
1400 SortBy: val.LastStage.SortBy, 1400 SortBy: val.LastStage.SortBy,
1401 PlanCompletedAt: time.Unix(int64(val.LastStage.PlanCompletedAt), 0).Local().Format("2006-01-02"), 1401 PlanCompletedAt: time.Unix(int64(val.LastStage.PlanCompletedAt), 0).Local().Format("2006-01-02"),
1402 RealCompletedAt: "", 1402 RealCompletedAt: "",
1403 - IsRef: false,  
1404 }, 1403 },
1405 CurrentStage: adapter.TaskStage{ 1404 CurrentStage: adapter.TaskStage{
1406 Id: val.CurrentStage.Id, 1405 Id: val.CurrentStage.Id,
@@ -1409,7 +1408,6 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result @@ -1409,7 +1408,6 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
1409 SortBy: val.CurrentStage.SortBy, 1408 SortBy: val.CurrentStage.SortBy,
1410 PlanCompletedAt: time.Unix(int64(val.CurrentStage.PlanCompletedAt), 0).Local().Format("2006-01-02"), 1409 PlanCompletedAt: time.Unix(int64(val.CurrentStage.PlanCompletedAt), 0).Local().Format("2006-01-02"),
1411 RealCompletedAt: "", 1410 RealCompletedAt: "",
1412 - IsRef: false,  
1413 }, 1411 },
1414 } 1412 }
1415 if val.LastStage.RealCompletedAt > 0 { 1413 if val.LastStage.RealCompletedAt > 0 {
@@ -1455,6 +1453,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result @@ -1455,6 +1453,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
1455 tk.StageE = stage 1453 tk.StageE = stage
1456 } 1454 }
1457 } 1455 }
  1456 + tk.GenStatusDescript()
1458 taskResult = append(taskResult, &tk) 1457 taskResult = append(taskResult, &tk)
1459 } 1458 }
1460 1459
@@ -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