作者 tangxvhui

优化

... ... @@ -597,18 +597,31 @@ type TaskData4 struct {
// TaskStageAnomalyAll 获取所有异常的里程碑任务,
func (d TaskDao) TaskStageAnomalyAll() ([]TaskData4, error) {
sqlStr := `select distinct
// sqlStr := `select distinct
// task.id as task_id,
// task."name" as task_name ,
// task.alias as task_alias,
// task.leader ->>'id' as leader_id,
// task.leader ->>'name' as leader_name
// from task
// join task_stage on task.id=task_stage.task_id
// where 1=1
// and task_stage.real_completed_at=0
// and task_stage.plan_completed_at<extract(epoch from now())
// `
sqlStr := `select
task.id as task_id,
task."name" as task_name ,
task.alias as task_alias,
task.leader ->>'id' as leader_id,
task.leader ->>'name' as leader_name
from task
join task_stage on task.id=task_stage.task_id
where 1=1
and task_stage.real_completed_at=0
and task_stage.plan_completed_at<extract(epoch from now())
`
from task where 1=1
and task.deleted_at isnull
and (
task.last_stage ->>'planCompletedAt'< task.last_stage ->>'realCompletedAt'
or
cast(COALESCE(task.current_stage ->>'plan_completed_at','0') as int) between 1 and floor(extract(epoch from now()))
) `
result := []TaskData4{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr)
... ...