Sfoglia il codice sorgente

添加定时任务

liujc 1 anno fa
parent
commit
a7442ed1d9

+ 6 - 0
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/AdminFeignService.java

@@ -151,6 +151,12 @@ public interface AdminFeignService {
     @GetMapping("/task/batchSending")
     HttpResponseResult<Boolean> batchSending();
 
+    /**
+     * 融云消息同步
+     */
+    @GetMapping("/task/rongyunImport")
+    void rongyunImport();
+
 
     @PostMapping("/open/adminClient/unionStudent")
     HttpResponseResult<StudentWrapper.UnionStudentResp> unionStudent(@RequestBody StudentWrapper.UnionStudent info);

+ 8 - 0
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/fallback/AdminFeignServiceFallback.java

@@ -133,6 +133,14 @@ public class AdminFeignServiceFallback implements AdminFeignService {
         return null;
     }
 
+    /**
+     * 融云消息同步
+     */
+    @Override
+    public void rongyunImport() {
+
+    }
+
 
     @Override
     public HttpResponseResult<StudentWrapper.UnionStudentResp> unionStudent(StudentWrapper.UnionStudent info) {

+ 23 - 0
cooleshow-task/src/main/java/com/yonge/cooleshow/task/jobs/RongyunImImport.java

@@ -0,0 +1,23 @@
+package com.yonge.cooleshow.task.jobs;
+
+import com.yonge.cooleshow.api.feign.AdminFeignService;
+import com.yonge.cooleshow.task.core.BaseTask;
+import com.yonge.cooleshow.task.core.TaskException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * 同步消息
+ */
+@Service
+public class RongyunImImport extends BaseTask {
+
+    @Autowired
+    private AdminFeignService adminFeignService;
+
+    @Override
+    public void execute() throws TaskException {
+        adminFeignService.rongyunImport();
+    }
+}

+ 1 - 17
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/ImGroupController.java

@@ -101,29 +101,13 @@ public class ImGroupController extends BaseController {
 
         //按照小时递减
         while (currentDate.after(targetTime)) {
-            RongyunImport(currentDate);
+            imGroupService.getAndSaveImHistoryMessage(DateUtil.format(currentDate, DateUtil.YEAR_MONTH_DAY_HOUR));
             calendar.add(Calendar.HOUR, -1);
             currentDate = calendar.getTime();
         }
 
     }
 
-    private void RongyunImport(Date currentDate) throws Exception {
-        String d = DateUtil.format(DateUtil.addHours(currentDate, 0), DateUtil.YEAR_MONTH_DAY_HOUR);
-        Object o = imGroupService.historyGet(d);
-        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(o));
-        if (jsonObject.get("code").equals(200)) {
-            String url = jsonObject.getString("url");
-            if (!StringUtils.isEmpty(url)) {
-                File file = new File(FileUtils.getTempDirectoryPath() + url.substring(url.lastIndexOf("/")));
-                URL url1 = new URL(url);
-                FileUtils.copyURLToFile(url1, file);
-                imGroupService.saveImHistoryMessage(new File(file.getAbsolutePath()));
-            }
-
-        }
-    }
-
 
 }
 

+ 27 - 12
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/task/TaskController.java

@@ -1,20 +1,12 @@
 package com.yonge.cooleshow.admin.task;
 
-import com.yonge.cooleshow.biz.dal.service.ActivityPlanEvaluationService;
-import com.yonge.cooleshow.biz.dal.service.ActivityPlanService;
-import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
-import com.yonge.cooleshow.biz.dal.service.CustomerServiceBatchSendingService;
-import com.yonge.cooleshow.biz.dal.service.MusicAlbumService;
-import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
-import com.yonge.cooleshow.biz.dal.service.PlatformCashAccountRecordService;
-import com.yonge.cooleshow.biz.dal.service.TeacherStyleVideoService;
-import com.yonge.cooleshow.biz.dal.service.UserAccountRecordService;
-import com.yonge.cooleshow.biz.dal.service.UserBindingTeacherService;
-import com.yonge.cooleshow.biz.dal.service.UserOrderService;
-import com.yonge.cooleshow.biz.dal.service.VideoLessonGroupService;
+import com.alibaba.fastjson.JSONObject;
+import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.common.constant.SysConfigConstant;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.toolset.utils.date.DateUtil;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.redisson.api.RBucket;
 import org.redisson.api.RedissonClient;
@@ -28,6 +20,8 @@ import org.springframework.web.bind.annotation.RestController;
 import springfox.documentation.annotations.ApiIgnore;
 
 import java.io.File;
+import java.net.URL;
+import java.util.Date;
 
 /**
  * @Author: liweifan
@@ -71,6 +65,9 @@ public class TaskController extends BaseController {
     @Autowired
     private CustomerServiceBatchSendingService customerServiceBatchSendingService;
 
+    @Autowired
+    private ImGroupService imGroupService;
+
     /***
      * 轮询用户订单
      * @author liweifan
@@ -183,4 +180,22 @@ public class TaskController extends BaseController {
         return HttpResponseResult.succeed();
     }
 
+
+
+    @GetMapping("/rongyunImport")
+    public void rongyunImport() throws Exception {
+         String currentDate = DateUtil.format(DateUtil.addHours(new Date(),-2), DateUtil.YEAR_MONTH_DAY_HOUR);
+        Object o = imGroupService.historyGet(currentDate);
+        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(o));
+        if (jsonObject.get("code").equals(200)) {
+            String url = jsonObject.getString("url");
+            if (!StringUtils.isEmpty(url)) {
+                File file = new File(FileUtils.getTempDirectoryPath() + url.substring(url.lastIndexOf("/")));
+                URL url1 = new URL(url);
+                FileUtils.copyURLToFile(url1, file);
+                imGroupService.saveImHistoryMessage(new File(file.getAbsolutePath()));
+            }
+
+        }
+    }
 }

+ 1 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/ImGroupService.java

@@ -103,6 +103,7 @@ public interface ImGroupService extends IService<ImGroup> {
     void saveImHistoryMessage(File file);
 
 
+    void getAndSaveImHistoryMessage(String date) throws Exception;
 
 }
 

+ 21 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImGroupServiceImpl.java

@@ -30,12 +30,15 @@ import com.yonge.cooleshow.biz.dal.service.SysUserService;
 import com.yonge.cooleshow.biz.dal.service.TeacherService;
 import com.yonge.toolset.base.exception.BizException;
 import com.yonge.toolset.base.util.ThreadPool;
+import com.yonge.toolset.utils.date.DateUtil;
 import io.rong.RongCloud;
 import io.rong.methods.message.history.History;
 import io.rong.models.Result;
 import io.rong.models.group.GroupMember;
 import io.rong.models.group.GroupModel;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.redisson.api.RBucket;
 import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
@@ -47,6 +50,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.io.*;
+import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.text.MessageFormat;
 import java.util.*;
@@ -455,5 +459,22 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
         }
     }
 
+    @Override
+    public void getAndSaveImHistoryMessage(String date) throws Exception {
+
+        Object o = imGroupService.historyGet(date);
+        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(o));
+        if (jsonObject.get("code").equals(200)) {
+            String url = jsonObject.getString("url");
+            if (!StringUtils.isEmpty(url)) {
+                File file = new File(FileUtils.getTempDirectoryPath() + url.substring(url.lastIndexOf("/")));
+                URL url1 = new URL(url);
+                FileUtils.copyURLToFile(url1, file);
+                imGroupService.saveImHistoryMessage(new File(file.getAbsolutePath()));
+            }
+
+        }
+    }
+
 }