作者 tangxvhui

Merge branch 'dev-tangxvhui' into test

package adapter
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type TaskItem struct {
Id int `json:"id,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader string `json:"leader"` // 任务负责人
Status int `json:"status"` // 任务的状态
Level int `json:"level"` // 优先级,值越小优先级越高
LevelName string `json:"levelName"` // 优先级名称
StageA TaskStage `json:"stageA"` // 里程碑1
StageB TaskStage `json:"stageB"` // 里程碑2
StageC TaskStage `json:"stageC"` // 里程碑3
StageD TaskStage `json:"stageD"` // 里程碑4
StageE TaskStage `json:"stageE"` // 里程碑5
LastStage TaskStage `json:"lastStage"` //
CurrentStage TaskStage `json:"currentStage"` //
UpdatedAt string `json:"updatedAt"` //
Anomaly int `json:"anomaly"` //异常反馈情况
WarnFlag int `json:"warnFlag"` //里程碑完成时间异常标记 0:正常 1标记为异常
Id int `json:"id,string"`
Name string `json:"name"` // 任务名称
Alias string `json:"alias"` // 任务别名
Leader string `json:"leader"` // 任务负责人
Status int `json:"status"` // 任务的状态
StatusDescript string `json:"statusDescript"` //任务的整体状态描述
SortBy int `json:"level"` // 优先级,值越小优先级越高
LevelName string `json:"levelName"` // 任务分类名称
StageA TaskStage `json:"stageA"` // 里程碑1
StageB TaskStage `json:"stageB"` // 里程碑2
StageC TaskStage `json:"stageC"` // 里程碑3
StageD TaskStage `json:"stageD"` // 里程碑4
StageE TaskStage `json:"stageE"` // 里程碑5
LastStage TaskStage `json:"lastStage"` //
CurrentStage TaskStage `json:"currentStage"` //
UpdatedAt string `json:"updatedAt"` //
Anomaly int `json:"anomaly"` //异常反馈情况
WarnFlag int `json:"warnFlag"` //里程碑完成时间异常标记 0:正常 1标记为异常
}
func (t *TaskItem) GenStatusDescript() {
statusNamed := ""
if domain.TaskState(t.Status) == domain.TaskRunning {
statusNamed = "进行中"
}
if t.CurrentStage.Id == 0 && t.LastStage.PlanCompletedAt < t.LastStage.RealCompletedAt {
statusNamed = "逾期完成"
}
if t.CurrentStage.Id == 0 && t.LastStage.PlanCompletedAt >= t.LastStage.RealCompletedAt {
statusNamed = "如期完成"
}
if domain.TaskState(t.Status) == domain.TaskStop {
statusNamed = "已停止"
}
if domain.TaskWarnFlag(t.WarnFlag) == domain.TaskWarn {
statusNamed = "里程碑异常"
}
if t.Anomaly > 0 {
statusNamed = "反馈异常"
}
t.StatusDescript = statusNamed
}
... ...
... ... @@ -470,7 +470,7 @@ func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.Task
ParentId: leaderData.ParentId,
},
Status: int(taskData.Status),
StatusDescription: taskData.StatusDescription(),
StatusDescription: taskData.Status.Named(),
// Level: taskData.Level,
LevelName: taskData.LevelName,
SortBy: int(taskData.SortBy),
... ... @@ -655,7 +655,7 @@ func (srv TaskService) ListTask(param *command.ListTaskCommand) (map[string]inte
Alias: val.Alias,
Leader: val.Leader.Name,
Status: int(val.Status),
Level: val.Level,
SortBy: int(val.SortBy),
LevelName: val.LevelName,
Anomaly: val.Anomaly,
WarnFlag: int(val.WarnFlag),
... ... @@ -1069,7 +1069,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
Alias: val.Alias,
Leader: val.LeaderName,
Status: val.Status,
Level: val.Level,
SortBy: val.SortBy,
LevelName: val.LevelName,
UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
Anomaly: val.Anomaly,
... ... @@ -1135,6 +1135,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
tk.StageE = stage
}
}
tk.GenStatusDescript()
taskResult = append(taskResult, &tk)
}
result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
... ... @@ -1216,7 +1217,7 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
Alias: val.Alias,
Leader: val.LeaderName,
Status: val.Status,
Level: val.Level,
SortBy: val.SortBy,
LevelName: val.LevelName,
UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
Anomaly: val.Anomaly,
... ... @@ -1228,7 +1229,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
SortBy: val.LastStage.SortBy,
PlanCompletedAt: time.Unix(int64(val.LastStage.PlanCompletedAt), 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
IsRef: false,
},
CurrentStage: adapter.TaskStage{
Id: val.CurrentStage.Id,
... ... @@ -1237,7 +1237,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
SortBy: val.CurrentStage.SortBy,
PlanCompletedAt: time.Unix(int64(val.CurrentStage.PlanCompletedAt), 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
IsRef: false,
},
}
if val.LastStage.RealCompletedAt > 0 {
... ... @@ -1283,6 +1282,7 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
tk.StageE = stage
}
}
tk.GenStatusDescript()
taskResult = append(taskResult, &tk)
}
result := tool_funs.SimpleWrapGridMap(int64(taskCount), taskResult)
... ... @@ -1388,7 +1388,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
Alias: val.Alias,
Leader: val.LeaderName,
Status: val.Status,
Level: val.Level,
SortBy: val.SortBy,
LevelName: val.LevelName,
UpdatedAt: val.UpdatedAt.Local().Format("2006-01-02 15:04:05"),
Anomaly: val.Anomaly,
... ... @@ -1400,7 +1400,6 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
SortBy: val.LastStage.SortBy,
PlanCompletedAt: time.Unix(int64(val.LastStage.PlanCompletedAt), 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
IsRef: false,
},
CurrentStage: adapter.TaskStage{
Id: val.CurrentStage.Id,
... ... @@ -1409,7 +1408,6 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
SortBy: val.CurrentStage.SortBy,
PlanCompletedAt: time.Unix(int64(val.CurrentStage.PlanCompletedAt), 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
IsRef: false,
},
}
if val.LastStage.RealCompletedAt > 0 {
... ... @@ -1455,6 +1453,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
tk.StageE = stage
}
}
tk.GenStatusDescript()
taskResult = append(taskResult, &tk)
}
... ...
... ... @@ -14,6 +14,18 @@ const (
TaskStop TaskState = 3 //任务停止
)
func (t TaskState) Named() string {
switch t {
case TaskWait:
return "待启动"
case TaskRunning:
return "启动中"
case TaskStop:
return "停止"
}
return ""
}
type TaskWarnFlag int
const (
... ... @@ -88,17 +100,6 @@ func (t *Task) ApplyLevelName(name string) {
}
// StatusDescript
func (t *Task) StatusDescription() string {
switch t.Status {
case TaskWait:
return "待启动"
case TaskRunning:
return "启动中"
case TaskStop:
return "停止"
}
return ""
}
// 记录待执行的里程碑,和上一个执行的里程碑
func (t *Task) SetCurrentStage(stageList []*TaskStage) {
... ... @@ -108,6 +109,7 @@ func (t *Task) SetCurrentStage(stageList []*TaskStage) {
sort.Slice(stageList, func(i, j int) bool {
return stageList[i].SortBy < stageList[j].SortBy
})
t.LastStage = TaskStage{}
t.CurrentStage = TaskStage{}
for _, val := range stageList {
if val.DeletedAt != nil {
... ... @@ -119,6 +121,10 @@ func (t *Task) SetCurrentStage(stageList []*TaskStage) {
break
}
}
if t.CurrentStage.RealCompletedAt > 0 {
t.LastStage = t.CurrentStage
t.CurrentStage = TaskStage{}
}
}
// 设置优先级的值
... ... @@ -133,6 +139,29 @@ func (t *Task) SetSortBy(a int) error {
return nil
}
func (t *Task) DescriptTaskStatus() string {
statusNamed := ""
if t.Status == TaskRunning {
statusNamed = "进行中"
}
if t.CurrentStage.Id == 0 && t.LastStage.PlanCompletedAt < t.LastStage.RealCompletedAt {
statusNamed = "逾期完成"
}
if t.CurrentStage.Id == 0 && t.LastStage.PlanCompletedAt >= t.LastStage.RealCompletedAt {
statusNamed = "如期完成"
}
if t.Status == TaskStop {
statusNamed = "已停止"
}
if t.WarnFlag == TaskWarn {
statusNamed = "里程碑异常"
}
if t.Anomaly > 0 {
statusNamed = "反馈异常"
}
return statusNamed
}
type TaskRepository interface {
Save(param *Task) error
Remove(id int) error
... ...