123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. CREATE PROCEDURE `pro_resume_work_daily`(IN `lstr_day` varchar(32))
  2. BEGIN
  3. -- 先删除旧的
  4. DELETE t FROM ts_resume_work_form t WHERE t.`name` = lstr_day;
  5. -- 再新增新的
  6. -- 1, 统计总的, 按机构分组
  7. INSERT INTO ts_resume_work_form (statis_id, org_id, st_type, `name`, `value`)
  8. SELECT UUID_SHORT(), t.org_id, 'total', lstr_day, count( 1 )
  9. FROM
  10. ta_resume_work_form t
  11. WHERE DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = lstr_day -- lstr_day 格式 YYYY-MM-DD
  12. AND t.`status` > - 1
  13. GROUP BY t.org_id;
  14. -- 不分组
  15. INSERT INTO ts_resume_work_form (statis_id, org_id, st_type, `name`, `value`)
  16. SELECT UUID_SHORT(), null, 'total', lstr_day, count( 1 )
  17. FROM
  18. ta_resume_work_form t
  19. WHERE DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = lstr_day -- lstr_day 格式 YYYY-MM-DD
  20. AND t.`status` > - 1;
  21. -- 2, 统计正常的,按机构分组
  22. INSERT INTO ts_resume_work_form (statis_id, org_id, st_type, `name`, `value`)
  23. SELECT UUID_SHORT(), t.org_id, 'normal', lstr_day, count( 1 )
  24. FROM
  25. ta_resume_work_form t
  26. WHERE
  27. ( t.nucleic_is_normal is NULL OR t.nucleic_is_normal = 1 )
  28. AND ( t.antigen_is_normal is NULL OR t.antigen_is_normal = 1 )
  29. AND DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = lstr_day -- lstr_day 格式 YYYY-MM-DD
  30. AND t.`status` > - 1
  31. GROUP BY t.org_id;
  32. -- 不分组
  33. INSERT INTO ts_resume_work_form (statis_id, org_id, st_type, `name`, `value`)
  34. SELECT UUID_SHORT(), null, 'normal', lstr_day, count( 1 )
  35. FROM
  36. ta_resume_work_form t
  37. WHERE
  38. ( t.nucleic_is_normal is NULL OR t.nucleic_is_normal = 1 )
  39. AND ( t.antigen_is_normal is NULL OR t.antigen_is_normal = 1 )
  40. AND DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = lstr_day -- lstr_day 格式 YYYY-MM-DD
  41. AND t.`status` > - 1;
  42. -- 3, 统计异常, 按机构分组
  43. INSERT INTO ts_resume_work_form (statis_id, org_id, st_type, `name`, `value`)
  44. SELECT UUID_SHORT(), t.org_id, 'abnormal', lstr_day, count( 1 )
  45. FROM
  46. ta_resume_work_form t
  47. WHERE
  48. ( t.nucleic_is_normal = 0 OR t.antigen_is_normal = 0 )
  49. AND DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = lstr_day -- lstr_day 格式 YYYY-MM-DD
  50. AND t.`status` > - 1
  51. GROUP BY t.org_id;
  52. -- 不分组
  53. INSERT INTO ts_resume_work_form (statis_id, org_id, st_type, `name`, `value`)
  54. SELECT UUID_SHORT(), null, 'abnormal', lstr_day, count( 1 )
  55. FROM
  56. ta_resume_work_form t
  57. WHERE
  58. ( t.nucleic_is_normal = 0 OR t.antigen_is_normal = 0 )
  59. AND DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = lstr_day -- lstr_day 格式 YYYY-MM-DD
  60. AND t.`status` > - 1;
  61. END;;
  62. CREATE EVENT `job_resume_work_daily`
  63. ON SCHEDULE
  64. EVERY '1' DAY STARTS '2022-05-16 01:00:00'
  65. DO call pro_resume_work_daily(DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY), '%Y-%m-%d'));;