generate_qw_task_sys_job_seed.py 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding: utf-8 -*-
  2. """Generate fs_qw_task_sys_job_seed.sql from original fs-qw-task @Scheduled config."""
  3. from pathlib import Path
  4. # (job_name, invoke_target, cron_expression, remark)
  5. # cron from git HEAD fs-qw-task before migration to fs-task
  6. QW_JOBS = [
  7. ("企微-SOP规则检查", "qwTask.qwCheckSopRuleTime()", "0 10 1 * * ?", "原 qwTask @Scheduled 0 10 1 * * ?"),
  8. ("企微-客户打标签", "qwTask.addTag()", "0 0/20 * * * ?", "原 qwTask @Scheduled 0 0/20 * * * ?"),
  9. ("企微-营期生成SOP日志", "qwTask.selectSopUserLogsListByTime()", "0 5 * * * ?", "原 qwTask @Scheduled 0 5 * * * ?"),
  10. ("企微-微信SOP处理", "qwTask.wxSop()", "0 5 * * * ?", "原 qwTask @Scheduled 0 5 * * * ?"),
  11. ("企微-官方接口群发(单链)", "qwTask.SendQwApiSopLogTimer()", "0 20 1 * * ?", "原 qwTask @Scheduled 0 20 1 * * ?"),
  12. ("企微-官方接口群发(新版)", "qwTask.SendQwApiSopLogTimerNew()", "0 10 0,1 * * ?", "原 qwTask @Scheduled 0 10 0,1 * * ?"),
  13. ("企微-获取群发结果", "qwTask.GetQwApiSopLogResultTimerNew()", "0 0 8 * * ?", "原 qwTask @Scheduled 0 0 8 * * ?"),
  14. ("企微-客户群发处理", "qwTask.sendQwGroupMsgTask()", "0 0/10 * * * ?", "原 qwTask @Scheduled 0 0/10 * * * ?"),
  15. ("企微-发送转换消息", "qwTask.sendQwBySop()", "0 0 8 * * ?", "原 qwTask @Scheduled 0 0 8 * * ?"),
  16. ("企微-标签备注补偿", "qwTask.qwExternalErrRetryTimer()", "0 0/3 * * * ?", "原 qwTask @Scheduled 0 0/3 * * * ?"),
  17. ("企微-补发过期完课消息", "qwTask.updateQwSopLogsByCancel()", "0 0 * * * ?", "原 qwTask @Scheduled 0 0 * * * ?"),
  18. ("企微-批量处理过期消息", "qwTask.batchProcessingExpiredMessages()", "0 0/8 * * * ?", "原 qwTask @Scheduled 0 0/8 * * * ?"),
  19. ("企微-清理历史SOP日志", "qwTask.deleteQwSopLogsByDate()", "0 10 0 * * ?", "原 qwTask @Scheduled 0 10 0 * * ?"),
  20. ("企微-修复营期异常数据", "qwTask.processRepairQwSopLogsTimer()", "0 30 0/3 * * ?", "原 qwTask @Scheduled 0 30 0/3 * * ?"),
  21. ("企微-E级未看课恢复", "qwTask.processSopUserLogsInfoByIsDaysNotStudy()", "0 35 2 * * ?", "原 qwTask @Scheduled 0 35 2 * * ?"),
  22. ("企微-客户分级评级", "qwTask.processQwSopExternalContactRatingTimer()", "0 45 3 * * ?", "原 qwTask @Scheduled 0 45 3 * * ?"),
  23. ("企微-超7天未看课标E级", "qwTask.processQwSopExternalContactRatingMoreSevenDaysTimer()", "0 30 3 * * ?", "原 qwTask @Scheduled 0 30 3 * * ?"),
  24. ("企微-更新前一天待发送", "qwTask.updateQwSopLogsDayBefore()", "0 3 0 * * ?", "原 qwTask @Scheduled 0 3 0 * * ?"),
  25. ("企微-同步外部联系人UnionId", "qwTask.updateQwExternalContactUnionid()", "0 1 0 */2 * ?", "原 qwTask @Scheduled 0 1 0 */2 * ?"),
  26. ("企微-自动拉人进群", "qwTask.autoPullGroup()", "0 0 16 * * ?", "原 qwTask @Scheduled 0 0 16 * * ?"),
  27. ("看课-检查看课状态", "courseWatchLogScheduler.checkWatchStatus()", "0 0/1 * * * ?", "原 fixedRate 60000,用 cron 近似每分钟"),
  28. ("看课-创建完课消息", "courseWatchLogScheduler.createCourseFinishMsg()", "0 0/5 * * * ?", "原 fixedRate 300000,用 cron 近似每5分钟"),
  29. ("看课-删除过期短链", "courseWatchLogScheduler.delCourseExpireLink()", "0 0 0 * * ?", "原 CourseWatchLogScheduler @Scheduled 0 0 0 * * ?"),
  30. ("企微-同步企微员工", "qwUserAsyncTask.syncQwUserAsync()", "0 0 0/3 * * ?", "原 QwUserAsyncTask @Scheduled 0 0 0/3 * * ?"),
  31. ("看课-会员看课统计", "userCourseWatchCountTask.userCourseCountTask()", "0 */20 * * * ?", "原 UserCourseWatchCountTask @Scheduled 0 */20 * * * ?"),
  32. ("看课-刷新课程配置缓存", "sopLogsTaskServiceImpl.refreshCourseConfig()", "0 0/1 * * * ?", "原 SopLogsTaskServiceImpl fixedDelay 60000"),
  33. ("企微-刷新评级配置", "qwExternalContactRatingServiceImpl.refreshRatingConfig()", "0 50 0/6 * * ?", "原 QwExternalContactRatingServiceImpl @Scheduled"),
  34. ("企微-刷新超7天评级配置", "qwExternalContactRatingMoreSevenDaysServiceImpl.refreshRatingConfig()", "0 50 0/6 * * ?", "原 QwExternalContactRatingMoreSevenDaysServiceImpl @Scheduled"),
  35. ]
  36. HEADER = (
  37. "-- fs-qw-task 迁移至 fs-task 后的 sys_job 种子数据\n"
  38. "-- job_group=QW_TASK;status=0 启用,status=1 暂停(默认暂停)\n"
  39. "-- invoke_target 须与 fs-task 模块 Spring Bean 方法一致\n\n"
  40. )
  41. def render_job(job_name, invoke_target, cron, remark):
  42. return (
  43. "INSERT INTO sys_job (job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark)\n"
  44. f"SELECT '{job_name}', 'QW_TASK', '{invoke_target}', '{cron}', '3', '1', '1', 'admin', NOW(), '{remark}'\n"
  45. f"WHERE NOT EXISTS (SELECT 1 FROM sys_job WHERE invoke_target = '{invoke_target}');\n"
  46. )
  47. def main():
  48. lines = [HEADER]
  49. for job in QW_JOBS:
  50. lines.append(render_job(*job))
  51. lines.append("\n")
  52. lines.append(
  53. "-- 备注:selectChatSopUserLogsListByTime 原 @Scheduled 已注释,未写入\n"
  54. "-- 备注:checkFsUserWatchStatus(fixedRate 30s) 未迁移至 fs-task,未写入\n"
  55. )
  56. out = Path(__file__).resolve().parent / "fs_qw_task_sys_job_seed.sql"
  57. out.write_text("".join(lines), encoding="utf-8")
  58. print("OK", out, "jobs=", len(QW_JOBS))
  59. if __name__ == "__main__":
  60. main()