|
|
@@ -1,4 +1,4 @@
|
|
|
-package com.fs.qw.qwTask;
|
|
|
+package com.fs.app.qwTask;
|
|
|
|
|
|
import com.fs.course.service.IFinishCourseStatisticsSyncService;
|
|
|
import com.fs.course.service.IFsUserCourseService;
|
|
|
@@ -14,7 +14,10 @@ import com.fs.statis.IFsStatisQwWatchService;
|
|
|
import com.fs.statis.service.FsStatisSalerWatchService;
|
|
|
import com.fs.wxwork.dto.WxWorkGetQrCodeDTO;
|
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.time.Duration;
|
|
|
@@ -26,7 +29,8 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
-@Component("qwTask")
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
public class qwTask {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -85,175 +89,213 @@ public class qwTask {
|
|
|
@Autowired
|
|
|
private IFinishCourseStatisticsSyncService finishCourseStatisticsSyncService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TenantTaskRunner tenantTaskRunner;
|
|
|
+
|
|
|
+ @Value("${saas.task.enabled:true}")
|
|
|
+ private boolean saasTaskEnabled;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * SaaS 多租户定时任务执行模板方法。
|
|
|
+ * 如果启用了 SaaS 且非租户执行上下文中,则按租户逐个执行;
|
|
|
+ * 否则直接执行(兼容单库模式或被 TenantTaskRunner 调用时)。
|
|
|
+ */
|
|
|
+ private void runWithSaaSTenant(String taskName, Runnable action) {
|
|
|
+ if (saasTaskEnabled && !TenantTaskRunner.isInTenantExecution()) {
|
|
|
+ tenantTaskRunner.runForEachTenant(taskName, action);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ action.run();
|
|
|
+ }
|
|
|
|
|
|
//正在使用
|
|
|
+ @Scheduled(cron = "0 0 1 * * ?")
|
|
|
public void qwExternalContact()
|
|
|
{
|
|
|
- qwExternalContactService.qwExternalContactSync();
|
|
|
+ runWithSaaSTenant("qwExternalContact", () -> qwExternalContactService.qwExternalContactSync());
|
|
|
}
|
|
|
//正在使用
|
|
|
+ @Scheduled(cron = "1/1 * * * * ?")
|
|
|
public void qwExternalContactAddAndDel()
|
|
|
{
|
|
|
- qwExternalContactService.qwExternalContactSyncAddAndDel();
|
|
|
+ runWithSaaSTenant("qwExternalContactAddAndDel", () -> qwExternalContactService.qwExternalContactSyncAddAndDel());
|
|
|
}
|
|
|
//正在使用
|
|
|
+ @Scheduled(cron = "0 0/5 * * * ?")
|
|
|
public void qwExternalContactSyncAddRedis()
|
|
|
{
|
|
|
- qwExternalContactService.qwExternalContactSyncAddRedis();
|
|
|
+ runWithSaaSTenant("qwExternalContactSyncAddRedis", () -> qwExternalContactService.qwExternalContactSyncAddRedis());
|
|
|
}
|
|
|
//正在使用
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ?")
|
|
|
public void qwExternalContactAddRedis()
|
|
|
{
|
|
|
- qwExternalContactService.qwExternalContactAddRedis();
|
|
|
+ runWithSaaSTenant("qwExternalContactAddRedis", () -> qwExternalContactService.qwExternalContactAddRedis());
|
|
|
}
|
|
|
//正在使用
|
|
|
+ @Scheduled(cron = "0 5/10 * * * ?")
|
|
|
public void qwExternalContactAddAndDelByRedis()
|
|
|
{
|
|
|
- qwExternalContactService.qwExternalContactAddAndDelByRedis();
|
|
|
+ runWithSaaSTenant("qwExternalContactAddAndDelByRedis", () -> qwExternalContactService.qwExternalContactAddAndDelByRedis());
|
|
|
}
|
|
|
//正在使用
|
|
|
+// @Scheduled(cron = "0 0 3 * * ?")
|
|
|
public void qwExternalContactAddTag()
|
|
|
{
|
|
|
- qwExternalContactService.qwExternalContactAddCourseTag();
|
|
|
+ runWithSaaSTenant("qwExternalContactAddTag", () -> qwExternalContactService.qwExternalContactAddCourseTag());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 定时任务 将 qw_sop任务 符合条件的录入到sop_user_Logs(clickHouse)
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 10 1 * * ?")
|
|
|
public void qwCheckSopRuleTime()
|
|
|
{
|
|
|
- qwSopService.checkSopRuleTime();
|
|
|
+ runWithSaaSTenant("qwCheckSopRuleTime", () -> qwSopService.checkSopRuleTime());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 定时任务 将 clickHouse的sopUserLogs(营期表)按每小时的巡回 录入clickHouse的qw_sop_logs(消息发送表)
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 5 * * * ?")
|
|
|
public void selectSopUserLogsListByTime(){
|
|
|
- sopUserLogsService.selectSopUserLogsListByTime();
|
|
|
+ runWithSaaSTenant("selectSopUserLogsListByTime", () -> sopUserLogsService.selectSopUserLogsListByTime());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 定时 发送 通过调用 企业微信接口 发送的 SOP 群发消息
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 20 1 * * ?")
|
|
|
public void SendQwApiSopLogTimer(){
|
|
|
- qwSopLogsService.checkQwSopLogs();
|
|
|
+ runWithSaaSTenant("SendQwApiSopLogTimer", () -> qwSopLogsService.checkQwSopLogs());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 定时获取 通过调用 企业微信接口 发送的 SOP 客户群发消息 的反馈结果
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0 8 * * ?")
|
|
|
public void GetQwApiSopLogResultTimer(){
|
|
|
- qwSopLogsService.qwSopLogsResult();
|
|
|
+ runWithSaaSTenant("GetQwApiSopLogResultTimer", () -> qwSopLogsService.qwSopLogsResult());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 定时群发API接口的 客户/群 群发
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0/5 * * * ?")
|
|
|
public void sendQwGroupMsgTask(){
|
|
|
- qwGroupMsgService.qwGroupMsgTask();
|
|
|
+ runWithSaaSTenant("sendQwGroupMsgTask", () -> qwGroupMsgService.qwGroupMsgTask());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 定时更新 待发送中已经算过期了的不能发的消息
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0/10 * * * ?")
|
|
|
public void updateQwSopLogsBySendStatusTask(){
|
|
|
- qwSopLogsService.updateQwSopLogsBySendStatus();
|
|
|
+ runWithSaaSTenant("updateQwSopLogsBySendStatusTask", () -> qwSopLogsService.updateQwSopLogsBySendStatus());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 2天跑一次 将 课程的封面 上传企业微信 并上传到redis
|
|
|
*/
|
|
|
+ @Scheduled(cron = "0 * * * * ?")
|
|
|
public void processQwSopCourseMaterialTimer() {
|
|
|
-
|
|
|
- iFsUserCourseService.processQwSopCourseMaterialTimer();
|
|
|
-
|
|
|
+ runWithSaaSTenant("processQwSopCourseMaterialTimer", () -> iFsUserCourseService.processQwSopCourseMaterialTimer());
|
|
|
}
|
|
|
/**
|
|
|
* 同步待同步客户
|
|
|
*/
|
|
|
+ @Scheduled(cron = "0 0/15 * * * ?")
|
|
|
public void synchronizeQwExternalContactTask(){
|
|
|
- qwExternalContactService.synchronizeQwExternalContactTask();
|
|
|
+ runWithSaaSTenant("synchronizeQwExternalContactTask", () -> qwExternalContactService.synchronizeQwExternalContactTask());
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 定时解除 已经删除了的销售 绑定的企业微信云主机。或者是没有绑定销售 却绑定了云主机的
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0 2 * * ?")
|
|
|
public void unlockQwUserLoginCodeUrlTask(){
|
|
|
- qwUserService.unlockQwUserLoginCodeUrlTask();
|
|
|
+ runWithSaaSTenant("unlockQwUserLoginCodeUrlTask", () -> qwUserService.unlockQwUserLoginCodeUrlTask());
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 看课统计
|
|
|
*/
|
|
|
- public void watchCourseStatis(String date){
|
|
|
- if("1".equals(date)){
|
|
|
- fsStatisSalerWatchService.writeData(null);
|
|
|
- } else {
|
|
|
- fsStatisSalerWatchService.writeData(date);
|
|
|
- }
|
|
|
+ @Scheduled(cron = "30 0 0 * * ?")
|
|
|
+ public void watchCourseStatis(){
|
|
|
+ runWithSaaSTenant("watchCourseStatis", () -> fsStatisSalerWatchService.writeData(null));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 看课统计昨天
|
|
|
*/
|
|
|
+ @Scheduled(cron = "30 0 0 * * ?")
|
|
|
public void watchCourseStatisPrevious(){
|
|
|
- LocalDate localDate = LocalDate.now().minusDays(1);
|
|
|
- fsStatisSalerWatchService.writeData(localDate.toString());
|
|
|
+ runWithSaaSTenant("watchCourseStatisPrevious", () -> {
|
|
|
+ LocalDate localDate = LocalDate.now().minusDays(1);
|
|
|
+ fsStatisSalerWatchService.writeData(localDate.toString());
|
|
|
+ });
|
|
|
}
|
|
|
/**
|
|
|
* 看课统计-统计当天的-每15分钟统计一次
|
|
|
*/
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ?")
|
|
|
public void watchCourseStatisToday(){
|
|
|
- fsStatisSalerWatchService.writeDataToday();
|
|
|
+ runWithSaaSTenant("watchCourseStatisToday", () -> fsStatisSalerWatchService.writeDataToday());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 进线转化统计
|
|
|
*/
|
|
|
- public void qwWatchCourseStatis(String date){
|
|
|
- if("1".equals(date)){
|
|
|
- fsStatisQwWatchService.writeData(null);
|
|
|
- } else {
|
|
|
- fsStatisQwWatchService.writeData(date);
|
|
|
- }
|
|
|
+ @Scheduled(cron = "30 0 0 * * ?")
|
|
|
+ public void qwWatchCourseStatis(){
|
|
|
+ runWithSaaSTenant("qwWatchCourseStatis", () -> fsStatisQwWatchService.writeData(null));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 进线转化统计
|
|
|
*/
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ?")
|
|
|
public void qwWatchCourseStatisToday(){
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- fsStatisQwWatchService.writeData(today.toString());
|
|
|
+ runWithSaaSTenant("qwWatchCourseStatisToday", () -> {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ fsStatisQwWatchService.writeData(today.toString());
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 每俩天 更新一次 素材库
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0 3 */2 * ?")
|
|
|
public void updateMaterialByTwoDays(){
|
|
|
- iQwMaterialService.updateQwMaterialByQw();
|
|
|
+ runWithSaaSTenant("updateMaterialByTwoDays", () -> iQwMaterialService.updateQwMaterialByQw());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 统计 每天的官方群发统计
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0 1 * * ?")
|
|
|
public void countQwApiAopLogToken(){
|
|
|
- DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- // 获取当前日期(只包含年月日)
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
-
|
|
|
- String todayStr = currentDate.format(dateFormatter);
|
|
|
- qwSopLogsService.countQwApiAopLogToken(todayStr);
|
|
|
-
|
|
|
-
|
|
|
+ runWithSaaSTenant("countQwApiAopLogToken", () -> {
|
|
|
+ DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ // 获取当前日期(只包含年月日)
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+
|
|
|
+ String todayStr = currentDate.format(dateFormatter);
|
|
|
+ qwSopLogsService.countQwApiAopLogToken(todayStr);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 定时清除 占着茅坑不拉屎的ipad 账号
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0 1 * * ?")
|
|
|
public void selectQwUserByUnbindIpad(){
|
|
|
+ runWithSaaSTenant("selectQwUserByUnbindIpad", this::doSelectQwUserByUnbindIpad);
|
|
|
+ }
|
|
|
|
|
|
+ private void doSelectQwUserByUnbindIpad(){
|
|
|
//查询所有状态为 绑定了AI主机的
|
|
|
List<QwUser> list = qwUserMapper.selectQwUserByTest();
|
|
|
for (QwUser qwUser : list) {
|
|
|
@@ -342,7 +384,12 @@ public class qwTask {
|
|
|
/**
|
|
|
* 强制注册-2025-11-12 之后的 更新
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0 5 * * ?")
|
|
|
public void QwExternalContactMandatoryRegistration(){
|
|
|
+ runWithSaaSTenant("QwExternalContactMandatoryRegistration", this::doQwExternalContactMandatoryRegistration);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doQwExternalContactMandatoryRegistration(){
|
|
|
try {
|
|
|
// List<String> longs = qwExternalContactService.selectQwExternalContactMandatoryRegistration();
|
|
|
List<String> longs = iQwCompanyService.selectQwCompanyListFormCorpId();
|
|
|
@@ -355,7 +402,6 @@ public class qwTask {
|
|
|
}catch (Exception e){
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -377,7 +423,8 @@ public class qwTask {
|
|
|
/**
|
|
|
* 特殊处理(木易完课统计数据)
|
|
|
*/
|
|
|
+// @Scheduled(cron = "0 0 6 * * ?")
|
|
|
public void syncMultiDimensionStatistics(){
|
|
|
- finishCourseStatisticsSyncService.syncMultiDimensionStatistics();
|
|
|
+ runWithSaaSTenant("syncMultiDimensionStatistics", () -> finishCourseStatisticsSyncService.syncMultiDimensionStatistics());
|
|
|
}
|
|
|
}
|