update_task_and_subtask.sql 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. CREATE OR REPLACE PROCEDURE update_task_and_subtask(
  2. IN p_biz_id INT,
  3. IN p_bizType VARCHAR
  4. )
  5. LANGUAGE plpgsql
  6. AS $$
  7. BEGIN
  8. IF p_bizType = 'dataProcess' THEN
  9. -- 检查 subtask 状态 --失败场景暂时不更新上层任务
  10. -- PERFORM 1 FROM algorithm_biz_process WHERE subtaskId = p_biz_id AND status = '3';
  11. -- IF FOUND THEN
  12. -- 如果有一个状态是3(失败),更新 algorithm_subtask 表为3(失败)
  13. -- UPDATE algorithm_subtask
  14. -- SET status = 3
  15. -- WHERE id = p_biz_id;
  16. -- ELSE
  17. -- 如果algorithm_biz_process所有状态都是2(成功),更新 algorithm_subtask 表为2(成功)
  18. PERFORM 1 FROM algorithm_biz_process WHERE status <> '2' AND sub_task_id = ( SELECT sub_task_id FROM algorithm_biz_process WHERE id = p_biz_id) ;
  19. IF NOT FOUND THEN
  20. UPDATE algorithm_subtask
  21. SET status = '2'
  22. WHERE id = ( SELECT sub_task_id FROM algorithm_biz_process WHERE id = p_biz_id);
  23. END IF;
  24. -- 如果algorithm_subtask表所有状态都是2(成功),更新 algorithm_task 表为2(成功)
  25. PERFORM 1 FROM algorithm_subtask WHERE status <> '2' AND task_id = (select task_id FROM algorithm_subtask WHERE id = (SELECT sub_task_id FROM algorithm_biz_process WHERE id = p_biz_id));
  26. IF NOT FOUND THEN
  27. UPDATE algorithm_task
  28. SET status = '2'
  29. WHERE id = (SELECT task_id FROM algorithm_subtask WHERE id = (SELECT sub_task_id FROM algorithm_biz_process WHERE id = p_biz_id));
  30. END IF;
  31. --END IF;
  32. ELSIF p_bizType = 'dataBizProcess' THEN
  33. -- 如果algorithm_data_process所有状态都是2(成功),更新 algorithm_subtask 表为2(成功)
  34. PERFORM 1 FROM algorithm_data_process WHERE status <> '2' AND sub_task_id = ( SELECT sub_task_id FROM algorithm_biz_process WHERE id = p_biz_id);
  35. IF NOT FOUND THEN
  36. UPDATE algorithm_subtask
  37. SET status = '2'
  38. WHERE id = ( SELECT sub_task_id FROM algorithm_biz_process WHERE id = p_biz_id);
  39. END IF;
  40. -- 如果algorithm_subtask表所有状态都是2(成功),更新 algorithm_task 表为2(成功)
  41. PERFORM 1 FROM algorithm_subtask WHERE status <> '2' AND task_id = (SELECT task_id FROM algorithm_subtask WHERE id = (SELECT sub_task_id FROM algorithm_data_process WHERE id = p_biz_id));
  42. IF NOT FOUND THEN
  43. UPDATE algorithm_task
  44. SET status = '2'
  45. WHERE id = (SELECT task_id FROM algorithm_subtask WHERE id = (SELECT sub_task_id FROM algorithm_data_process WHERE id = p_biz_id));
  46. END IF;
  47. END IF;
  48. END;
  49. $$;