2026-07-18-001-fix-auto-completed-article-status.sql 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. -- 修复无需人工审批、已自动完成的文章流程被错误保留为“审核中”。
  2. -- 可重复执行:仅处理最新文章流程已结束、且文章仍为在用待审的数据。
  3. SET NAMES utf8mb4;
  4. USE sp_gzhx_apps;
  5. UPDATE article a
  6. JOIN (
  7. SELECT table_key_value AS articleid, MAX(applyid) AS latest_applyid
  8. FROM apply
  9. WHERE dcode <> 72
  10. AND table_name = 'article'
  11. AND table_key = 'articleid'
  12. GROUP BY table_key_value
  13. ) latest ON latest.articleid = a.articleid
  14. JOIN apply ap ON ap.applyid = latest.latest_applyid
  15. SET a.dcode = 61
  16. WHERE a.dcode = 31
  17. AND a.ascode = 10010
  18. AND ap.ascode IN (41, 51)
  19. AND ap.end_time IS NOT NULL;
  20. SELECT COUNT(*) AS remaining_inconsistent_articles
  21. FROM article a
  22. JOIN (
  23. SELECT table_key_value AS articleid, MAX(applyid) AS latest_applyid
  24. FROM apply
  25. WHERE dcode <> 72
  26. AND table_name = 'article'
  27. AND table_key = 'articleid'
  28. GROUP BY table_key_value
  29. ) latest ON latest.articleid = a.articleid
  30. JOIN apply ap ON ap.applyid = latest.latest_applyid
  31. WHERE a.dcode = 31
  32. AND a.ascode = 10010
  33. AND ap.ascode IN (41, 51)
  34. AND ap.end_time IS NOT NULL;