作者 tangxvhui

调整 异常的判定逻辑

@@ -895,9 +895,7 @@ func (srv TaskService) ListTaskRecord(param *command.ListTaskRecordCommand) (map @@ -895,9 +895,7 @@ func (srv TaskService) ListTaskRecord(param *command.ListTaskRecordCommand) (map
895 _ = transactionContext.RollbackTransaction() 895 _ = transactionContext.RollbackTransaction()
896 }() 896 }()
897 taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext}) 897 taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext})
898 - //assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{  
899 - // "transactionContext": transactionContext,  
900 - //}) 898 +
901 cnt, taskRecordList, err := taskRecordRepo.Find(map[string]interface{}{ 899 cnt, taskRecordList, err := taskRecordRepo.Find(map[string]interface{}{
902 "companyId": param.CompanyId, 900 "companyId": param.CompanyId,
903 "taskId": param.TaskId, 901 "taskId": param.TaskId,
@@ -1194,6 +1192,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i @@ -1194,6 +1192,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
1194 taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{ 1192 taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
1195 "transactionContext": transactionContext, 1193 "transactionContext": transactionContext,
1196 }) 1194 })
  1195 + nowDay := xtime.DayEndTime(time.Now()).Unix()
1197 for _, val := range taskListData { 1196 for _, val := range taskListData {
1198 tk := adapter.TaskItem{ 1197 tk := adapter.TaskItem{
1199 Id: val.TaskId, 1198 Id: val.TaskId,
@@ -1237,14 +1236,15 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i @@ -1237,14 +1236,15 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
1237 if val.WarnFlag > 0 { 1236 if val.WarnFlag > 0 {
1238 tk.WarnFlag = 1 1237 tk.WarnFlag = 1
1239 } 1238 }
1240 - if val.LastStage.Id > 0 && val.LastStage.PlanCompletedAt < val.LastStage.RealCompletedAt {  
1241 - //上一个里程碑超期完成 1239 + if val.LastStage.Id > 0 && val.LastStage.RealCompletedAt < nowDay {
  1240 + if val.LastStage.Id > 0 &&
  1241 + val.LastStage.PlanCompletedAt < val.LastStage.RealCompletedAt &&
  1242 + val.CurrentStage.Id > 0 {
  1243 + //上一个里程碑超期完成,标红
1242 tk.WarnFlag = 1 1244 tk.WarnFlag = 1
1243 } 1245 }
1244 - if val.CurrentStage.Id == 0 {  
1245 - //里程碑已全部完成  
1246 - tk.WarnFlag = 0  
1247 } 1246 }
  1247 +
1248 _, stageList, err := taskStageRepo.Find(map[string]interface{}{ 1248 _, stageList, err := taskStageRepo.Find(map[string]interface{}{
1249 "taskId": val.TaskId, 1249 "taskId": val.TaskId,
1250 }) 1250 })
@@ -1539,14 +1539,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s @@ -1539,14 +1539,6 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
1539 if tk.WarnFlag > 0 { 1539 if tk.WarnFlag > 0 {
1540 tk.WarnFlag = 1 1540 tk.WarnFlag = 1
1541 } 1541 }
1542 - if val.LastStage.Id > 0 && val.LastStage.PlanCompletedAt < val.LastStage.RealCompletedAt {  
1543 - //上一个里程碑超期完成  
1544 - tk.WarnFlag = 1  
1545 - }  
1546 - if val.CurrentStage.Id == 0 {  
1547 - //里程已全部完成  
1548 - tk.WarnFlag = 0  
1549 - }  
1550 _, stageList, err := taskStageRepo.Find(map[string]interface{}{ 1542 _, stageList, err := taskStageRepo.Find(map[string]interface{}{
1551 "taskId": val.TaskId, 1543 "taskId": val.TaskId,
1552 }) 1544 })
@@ -1794,7 +1786,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result @@ -1794,7 +1786,7 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
1794 taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{ 1786 taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
1795 "transactionContext": transactionContext, 1787 "transactionContext": transactionContext,
1796 }) 1788 })
1797 - 1789 + // nowDay := xtime.DayEndTime(time.Now()).Unix()
1798 for _, val := range taskListData { 1790 for _, val := range taskListData {
1799 tk := adapter.TaskItem{ 1791 tk := adapter.TaskItem{
1800 Id: val.TaskId, 1792 Id: val.TaskId,
@@ -1830,20 +1822,11 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result @@ -1830,20 +1822,11 @@ func (srv *TaskService) ListTaskIgnore(param *command.SearchTaskCommand) (result
1830 if val.CurrentStage.RealCompletedAt > 0 { 1822 if val.CurrentStage.RealCompletedAt > 0 {
1831 tk.CurrentStage.RealCompletedAt = time.Unix(int64(val.CurrentStage.RealCompletedAt), 0).Local().Format("2006-01-02") 1823 tk.CurrentStage.RealCompletedAt = time.Unix(int64(val.CurrentStage.RealCompletedAt), 0).Local().Format("2006-01-02")
1832 } 1824 }
1833 - // if val.LastStage.Id > 0 && val.LastStage.PlanCompletedAt < val.LastStage.RealCompletedAt {  
1834 - // // tk.WarnFlag = int(domain.TaskWarn)  
1835 - // tk.WarnFlag = 1  
1836 - // }  
1837 - // if val.CurrentStage.Id > 0 && val.CurrentStage.PlanCompletedAt < nowTime {  
1838 - // // tk.WarnFlag = int(domain.TaskWarn)  
1839 - // tk.WarnFlag = 1  
1840 - // } 1825 +
1841 if tk.WarnFlag > 0 { 1826 if tk.WarnFlag > 0 {
1842 tk.WarnFlag = 1 1827 tk.WarnFlag = 1
1843 } 1828 }
1844 - if val.CurrentStage.Id == 0 {  
1845 - tk.WarnFlag = 0  
1846 - } 1829 +
1847 _, stageList, err := taskStageRepo.Find(map[string]interface{}{ 1830 _, stageList, err := taskStageRepo.Find(map[string]interface{}{
1848 "taskId": val.TaskId, 1831 "taskId": val.TaskId,
1849 }) 1832 })
@@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ import (
5 "sort" 5 "sort"
6 "strings" 6 "strings"
7 "time" 7 "time"
  8 +
  9 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils/xtime"
8 ) 10 )
9 11
10 type TaskState int 12 type TaskState int
@@ -179,18 +181,25 @@ func (t *Task) Copy() Task { @@ -179,18 +181,25 @@ func (t *Task) Copy() Task {
179 181
180 // 检查每日任务是否异常,并记录异常情况 182 // 检查每日任务是否异常,并记录异常情况
181 func (t *Task) CheckAndRecordAnomaly(taskRecordData *TaskRecord) { 183 func (t *Task) CheckAndRecordAnomaly(taskRecordData *TaskRecord) {
182 - nowTime := time.Now().Unix() 184 + nowTime := xtime.DayZeroTime(time.Now()).Unix()
183 // 检查是否是里程碑异常 185 // 检查是否是里程碑异常
184 { 186 {
185 if taskRecordData.TaskStageCheck.Id > 0 { 187 if taskRecordData.TaskStageCheck.Id > 0 {
186 - if taskRecordData.TaskStageCheck.RealCompletedAt == 0 && taskRecordData.TaskStageCheck.PlanCompletedAt < nowTime {  
187 - // 超期未完成  
188 - t.WarnFlag += 1  
189 - } else if taskRecordData.TaskStageCheck.RealCompletedAt > 0 {  
190 - // 里程碑完成, 重置计数 188 + if taskRecordData.TaskStageCheck.PlanCompletedAt >= taskRecordData.TaskStageCheck.RealCompletedAt {
  189 + //正常逾期
191 t.WarnFlag = 0 190 t.WarnFlag = 0
192 } 191 }
193 - } else { 192 + if taskRecordData.TaskStageCheck.PlanCompletedAt < nowTime && taskRecordData.TaskStageCheck.RealCompletedAt == 0 {
  193 + //逾期未完成
  194 + t.WarnFlag += 1
  195 + } else if taskRecordData.TaskStageCheck.PlanCompletedAt < taskRecordData.TaskStageCheck.RealCompletedAt {
  196 + //逾期完成
  197 + t.WarnFlag += 1
  198 + }
  199 + }
  200 +
  201 + //里程碑已全部完成
  202 + if t.CurrentStage.Id == 0 {
194 t.WarnFlag = 0 203 t.WarnFlag = 0
195 } 204 }
196 } 205 }
@@ -210,12 +219,16 @@ func (t *Task) CheckAndRecordAnomaly(taskRecordData *TaskRecord) { @@ -210,12 +219,16 @@ func (t *Task) CheckAndRecordAnomaly(taskRecordData *TaskRecord) {
210 // 检查辅导异常 219 // 检查辅导异常
211 { 220 {
212 taskRecordData.AssistContent = strings.TrimSpace(taskRecordData.AssistContent) 221 taskRecordData.AssistContent = strings.TrimSpace(taskRecordData.AssistContent)
213 - if t.Anomaly == 0 && t.WarnFlag == 0 {  
214 - //里程碑正常,反馈正常, 设定为已辅导  
215 - t.AssistFlag = 0  
216 - } else {  
217 - //里程碑和反馈 其中一个不正常,记录一次辅导异常  
218 t.AssistFlag += 1 222 t.AssistFlag += 1
  223 + if t.Anomaly == 0 {
  224 + //反馈正常
  225 + if t.CurrentStage.Id == 0 {
  226 + //里程碑全部完成
  227 + t.AssistFlag = 0
  228 + } else if t.CurrentStage.PlanCompletedAt > nowTime {
  229 + //里程碑还未过期
  230 + t.AssistFlag = 0
  231 + }
219 } 232 }
220 if taskRecordData.AssistLevel != AssistLevel1 && 233 if taskRecordData.AssistLevel != AssistLevel1 &&
221 !(taskRecordData.AssistContent == "无" || len(taskRecordData.AssistContent) == 0) { 234 !(taskRecordData.AssistContent == "无" || len(taskRecordData.AssistContent) == 0) {
@@ -16,6 +16,29 @@ ALTER TABLE public.task_record @@ -16,6 +16,29 @@ ALTER TABLE public.task_record
16 16
17 COMMENT ON COLUMN public.task_record.assist_state IS '辅导异常状态'; 17 COMMENT ON COLUMN public.task_record.assist_state IS '辅导异常状态';
18 18
  19 +-- 创建新表 task_anomaly 异常的任务记录
  20 +CREATE TABLE public.task_anomaly(
  21 + id bigserial NOT NULL,
  22 + created_at timestamptz NOT NULL,
  23 + updated_at timestamptz NOT NULL,
  24 + company_id int8 NOT NULL,
  25 + task_id int8 NOT NULL,
  26 + category int8 NOT NULL,
  27 + current_stage jsonb NOT NULL,
  28 + last_stage jsonb NOT NULL,
  29 + task_stage_check jsonb NOT NULL,
  30 + assess_flag int8 NOT NULL DEFAULT 0,
  31 + warn_flag int8 NOT NULL DEFAULT 0,
  32 + assist_flag int8 NOT NULL DEFAULT 0,
  33 + is_last int8 NOT NULL DEFAULT 1,
  34 + record_begin int8 NOT NULL DEFAULT 0,
  35 + notice_who jsonb NOT NULL,
  36 + marks jsonb NOT NULL,
  37 + task_record_id int8 NOT NULL DEFAULT 0,
  38 + remark text NOT NULL DEFAULT ''::text,
  39 + CONSTRAINT task_anomaly_pkey PRIMARY KEY (id)
  40 +);
  41 +
19 -- task_record 处理旧数据 42 -- task_record 处理旧数据
20 WITH t_taff_assess_content AS ( 43 WITH t_taff_assess_content AS (
21 SELECT 44 SELECT