作者 tangxvhui

优化

@@ -597,18 +597,31 @@ type TaskData4 struct { @@ -597,18 +597,31 @@ type TaskData4 struct {
597 597
598 // TaskStageAnomalyAll 获取所有异常的里程碑任务, 598 // TaskStageAnomalyAll 获取所有异常的里程碑任务,
599 func (d TaskDao) TaskStageAnomalyAll() ([]TaskData4, error) { 599 func (d TaskDao) TaskStageAnomalyAll() ([]TaskData4, error) {
600 - sqlStr := `select distinct 600 + // sqlStr := `select distinct
  601 + // task.id as task_id,
  602 + // task."name" as task_name ,
  603 + // task.alias as task_alias,
  604 + // task.leader ->>'id' as leader_id,
  605 + // task.leader ->>'name' as leader_name
  606 + // from task
  607 + // join task_stage on task.id=task_stage.task_id
  608 + // where 1=1
  609 + // and task_stage.real_completed_at=0
  610 + // and task_stage.plan_completed_at<extract(epoch from now())
  611 + // `
  612 + sqlStr := `select
601 task.id as task_id, 613 task.id as task_id,
602 task."name" as task_name , 614 task."name" as task_name ,
603 task.alias as task_alias, 615 task.alias as task_alias,
604 task.leader ->>'id' as leader_id, 616 task.leader ->>'id' as leader_id,
605 task.leader ->>'name' as leader_name 617 task.leader ->>'name' as leader_name
606 - from task  
607 - join task_stage on task.id=task_stage.task_id  
608 - where 1=1  
609 - and task_stage.real_completed_at=0  
610 - and task_stage.plan_completed_at<extract(epoch from now())  
611 - ` 618 +from task where 1=1
  619 +and task.deleted_at isnull
  620 +and (
  621 + task.last_stage ->>'planCompletedAt'< task.last_stage ->>'realCompletedAt'
  622 + or
  623 + cast(COALESCE(task.current_stage ->>'plan_completed_at','0') as int) between 1 and floor(extract(epoch from now()))
  624 +) `
612 result := []TaskData4{} 625 result := []TaskData4{}
613 tx := d.transactionContext.PgTx 626 tx := d.transactionContext.PgTx
614 _, err := tx.Query(&result, sqlStr) 627 _, err := tx.Query(&result, sqlStr)