作者 tangxvhui

调整 异常的判定逻辑

... ... @@ -895,9 +895,7 @@ func (srv TaskService) ListTaskRecord(param *command.ListTaskRecordCommand) (map
_ = transactionContext.RollbackTransaction()
}()
taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext})
//assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//})
cnt, taskRecordList, err := taskRecordRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"taskId": param.TaskId,
... ... @@ -1194,6 +1192,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
nowDay := xtime.DayEndTime(time.Now()).Unix()
for _, val := range taskListData {
tk := adapter.TaskItem{
Id: val.TaskId,
... ... @@ -1237,14 +1236,15 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
if val.WarnFlag > 0 {
tk.WarnFlag = 1
}
if val.LastStage.Id > 0 && val.LastStage.PlanCompletedAt < val.LastStage.RealCompletedAt {
//上一个里程碑超期完成
tk.WarnFlag = 1
}
if val.CurrentStage.Id == 0 {
//里程碑已全部完成
tk.WarnFlag = 0
if val.LastStage.Id > 0 && val.LastStage.RealCompletedAt < nowDay {
if val.LastStage.Id > 0 &&
val.LastStage.PlanCompletedAt < val.LastStage.RealCompletedAt &&
val.CurrentStage.Id > 0 {
//上一个里程碑超期完成,标红
tk.WarnFlag = 1
}
}
_, stageList, err := taskStageRepo.Find(map[string]interface{}{
"taskId": val.TaskId,
})
... ... @@ -1539,14 +1539,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
if tk.WarnFlag > 0 {
tk.WarnFlag = 1
}
if val.LastStage.Id > 0 && val.LastStage.PlanCompletedAt < val.LastStage.RealCompletedAt {
//上一个里程碑超期完成
tk.WarnFlag = 1
}
if val.CurrentStage.Id == 0 {
//里程已全部完成
tk.WarnFlag = 0
}
_, stageList, err := taskStageRepo.Find(map[string]interface{}{
"taskId": val.TaskId,
})
... ... @@ -1794,7 +1786,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
// nowDay := xtime.DayEndTime(time.Now()).Unix()
for _, val := range taskListData {
tk := adapter.TaskItem{
Id: val.TaskId,
... ... @@ -1830,20 +1822,11 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
if val.CurrentStage.RealCompletedAt > 0 {
tk.CurrentStage.RealCompletedAt = time.Unix(int64(val.CurrentStage.RealCompletedAt), 0).Local().Format("2006-01-02")
}
// if val.LastStage.Id > 0 && val.LastStage.PlanCompletedAt < val.LastStage.RealCompletedAt {
// // tk.WarnFlag = int(domain.TaskWarn)
// tk.WarnFlag = 1
// }
// if val.CurrentStage.Id > 0 && val.CurrentStage.PlanCompletedAt < nowTime {
// // tk.WarnFlag = int(domain.TaskWarn)
// tk.WarnFlag = 1
// }
if tk.WarnFlag > 0 {
tk.WarnFlag = 1
}
if val.CurrentStage.Id == 0 {
tk.WarnFlag = 0
}
_, stageList, err := taskStageRepo.Find(map[string]interface{}{
"taskId": val.TaskId,
})
... ...
... ... @@ -5,6 +5,8 @@ import (
"sort"
"strings"
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils/xtime"
)
type TaskState int
... ... @@ -179,18 +181,25 @@ func (t *Task) Copy() Task {
// 检查每日任务是否异常,并记录异常情况
func (t *Task) CheckAndRecordAnomaly(taskRecordData *TaskRecord) {
nowTime := time.Now().Unix()
nowTime := xtime.DayZeroTime(time.Now()).Unix()
// 检查是否是里程碑异常
{
if taskRecordData.TaskStageCheck.Id > 0 {
if taskRecordData.TaskStageCheck.RealCompletedAt == 0 && taskRecordData.TaskStageCheck.PlanCompletedAt < nowTime {
// 超期未完成
t.WarnFlag += 1
} else if taskRecordData.TaskStageCheck.RealCompletedAt > 0 {
// 里程碑完成, 重置计数
if taskRecordData.TaskStageCheck.PlanCompletedAt >= taskRecordData.TaskStageCheck.RealCompletedAt {
//正常逾期
t.WarnFlag = 0
}
} else {
if taskRecordData.TaskStageCheck.PlanCompletedAt < nowTime && taskRecordData.TaskStageCheck.RealCompletedAt == 0 {
//逾期未完成
t.WarnFlag += 1
} else if taskRecordData.TaskStageCheck.PlanCompletedAt < taskRecordData.TaskStageCheck.RealCompletedAt {
//逾期完成
t.WarnFlag += 1
}
}
//里程碑已全部完成
if t.CurrentStage.Id == 0 {
t.WarnFlag = 0
}
}
... ... @@ -210,12 +219,16 @@ func (t *Task) CheckAndRecordAnomaly(taskRecordData *TaskRecord) {
// 检查辅导异常
{
taskRecordData.AssistContent = strings.TrimSpace(taskRecordData.AssistContent)
if t.Anomaly == 0 && t.WarnFlag == 0 {
//里程碑正常,反馈正常, 设定为已辅导
t.AssistFlag = 0
} else {
//里程碑和反馈 其中一个不正常,记录一次辅导异常
t.AssistFlag += 1
t.AssistFlag += 1
if t.Anomaly == 0 {
//反馈正常
if t.CurrentStage.Id == 0 {
//里程碑全部完成
t.AssistFlag = 0
} else if t.CurrentStage.PlanCompletedAt > nowTime {
//里程碑还未过期
t.AssistFlag = 0
}
}
if taskRecordData.AssistLevel != AssistLevel1 &&
!(taskRecordData.AssistContent == "无" || len(taskRecordData.AssistContent) == 0) {
... ...
... ... @@ -16,6 +16,29 @@ ALTER TABLE public.task_record
COMMENT ON COLUMN public.task_record.assist_state IS '辅导异常状态';
-- 创建新表 task_anomaly 异常的任务记录
CREATE TABLE public.task_anomaly(
id bigserial NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
company_id int8 NOT NULL,
task_id int8 NOT NULL,
category int8 NOT NULL,
current_stage jsonb NOT NULL,
last_stage jsonb NOT NULL,
task_stage_check jsonb NOT NULL,
assess_flag int8 NOT NULL DEFAULT 0,
warn_flag int8 NOT NULL DEFAULT 0,
assist_flag int8 NOT NULL DEFAULT 0,
is_last int8 NOT NULL DEFAULT 1,
record_begin int8 NOT NULL DEFAULT 0,
notice_who jsonb NOT NULL,
marks jsonb NOT NULL,
task_record_id int8 NOT NULL DEFAULT 0,
remark text NOT NULL DEFAULT ''::text,
CONSTRAINT task_anomaly_pkey PRIMARY KEY (id)
);
-- task_record 处理旧数据
WITH t_taff_assess_content AS (
SELECT
... ...