leon 5 anni fa
parent
commit
cde19d06a9

+ 17 - 0
src/main/java/com/mokamrp/privates/config/TaskConfig.java

@@ -0,0 +1,17 @@
+package com.mokamrp.privates.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.TaskScheduler;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+
+@Configuration
+public class TaskConfig {
+    @Bean
+    public TaskScheduler taskScheduler() {
+        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
+        // 设置scheduler执行线程为3个
+        scheduler.setPoolSize(1);
+        return scheduler;
+    }
+}

+ 2 - 0
src/main/java/com/mokamrp/privates/constant/RedisKey.java

@@ -31,6 +31,8 @@ public class RedisKey {
     public static final String PanWxFosterMobileInfo = "pan_wxfoster_mobile_info:";
     //.盘古 微信养号账号修改异步操作
     public static final String PanWxFosterMobileSync = "pan_wxfoster_mobile_sync";
+    //.盘古 微信养号小程序异步编辑任务
+    public static final String PanWxFosterTaskSync = "pan_wxfoster_task_sync";
 
 }
 

+ 0 - 3
src/main/java/com/mokamrp/privates/mapper/pangu/pojo/FosterwxMobile.java

@@ -140,9 +140,6 @@ public class FosterwxMobile extends Model<FosterwxMobile> {
     @TableField(exist = false)
     private List<FosterwxMobileWxfriend> friend;
 
-    @TableField(exist = false)
-    private Object friends;
-
     /**
      * 任务开始时间
      */

+ 9 - 6
src/main/java/com/mokamrp/privates/tast/pangu/SyncFosterwxEdit.java

@@ -1,6 +1,7 @@
 package com.mokamrp.privates.tast.pangu;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.mokamrp.privates.constant.RedisKey;
 import com.mokamrp.privates.entity.pangu.AddFosterwxMobileHandle;
@@ -40,17 +41,17 @@ public class SyncFosterwxEdit {
 
     public List<FosterwxMobileWxfriend> fosterwxMobileWxfriendList;
 
-    @Scheduled(cron = "* */1 * * * ?")
+    @Scheduled(cron = "*/1 * * * * ?")
     public void execute() {
         System.out.println("[cronjob]:异步执行微信养号账号信息修改/新增操作");
         Integer cnt = 1;
         while (true){
             cnt ++;
-            if (cnt > 1000){
+            if (cnt > 20){
                 break;
             }
             try {
-                Thread.sleep(200);
+                Thread.sleep(100);
                 String info = stringRedisTemplate.opsForList().rightPop(RedisKey.PanWxFosterMobileSync);
                 if (info == null || info.isEmpty()){
                     continue;
@@ -80,9 +81,11 @@ public class SyncFosterwxEdit {
                     mobileIds.add(obj.getId());
                 }
                 this.fosterwxMobileWxfriendList = fosterwxMobileWxfriendService.list(new QueryWrapper<FosterwxMobileWxfriend>().in("mobile_id",mobileIds));
-                List<FosterwxMobileWxfriend> friends = this.getMobileWxfriendByMobileId(fosterwxMobile.getId());
-                fosterwxMobile.setFriend(friends);
-                stringRedisTemplate.opsForValue().set(RedisKey.PanWxFosterMobileInfo+fosterwxMobile.getStationId(),JSON.toJSONString(fosterwxMobileList));
+                for (FosterwxMobile obj : fosterwxMobileList){
+                    List<FosterwxMobileWxfriend> friends = this.getMobileWxfriendByMobileId(obj.getId());
+                    obj.setFriend(friends);
+                }
+                stringRedisTemplate.opsForValue().set(RedisKey.PanWxFosterMobileInfo+fosterwxMobile.getStationId(), JSONObject.toJSONString(fosterwxMobileList));
             } catch (InterruptedException ie) {
                 Thread.currentThread().interrupt();
             }

+ 13 - 11
src/main/java/com/mokamrp/privates/tast/pangu/SyncFosterwxMobile.java

@@ -1,6 +1,8 @@
 package com.mokamrp.privates.tast.pangu;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.mokamrp.privates.constant.RedisKey;
 import com.mokamrp.privates.entity.ResHandle;
@@ -51,29 +53,29 @@ public class SyncFosterwxMobile {
         this.fosterwxMobileList = fosterwxMobileService.list();
         //.查询所有账号下微信好友
         this.fosterwxMobileWxfriendList = fosterwxMobileWxfriendService.list();
-        Map<String,List<FosterwxMobile>> add = new HashMap<>();
-        for (FosterwxMobile fosterwxMobile : this.fosterwxMobileList){
+        Map<String, List<FosterwxMobile>> add = new HashMap<>();
+        for (FosterwxMobile fosterwxMobile : this.fosterwxMobileList) {
             Integer stationId = fosterwxMobile.getStationId();
             List<FosterwxMobile> data = new ArrayList<>();
-            if (add.get(stationId.toString()) == null || add.get(stationId.toString()).isEmpty()){
+            if (add.get(stationId.toString()) == null || add.get(stationId.toString()).isEmpty()) {
                 data = new ArrayList<FosterwxMobile>();
-            }else{
+            } else {
                 data = add.get(stationId.toString());
             }
             List<FosterwxMobileWxfriend> friends = this.getMobileWxfriendByMobileId(fosterwxMobile.getId());
-            fosterwxMobile.setFriends(friends);
+            fosterwxMobile.setFriend(friends);
             data.add(fosterwxMobile);
-            add.put(stationId.toString(),data);
+            add.put(stationId.toString(), data);
         }
-        for(Map.Entry<String,List<FosterwxMobile>> entry : add.entrySet()){
-            stringRedisTemplate.opsForValue().set(RedisKey.PanWxFosterMobileInfo+entry.getKey(),JSON.toJSONString(entry.getValue()));
+        for (Map.Entry<String, List<FosterwxMobile>> entry : add.entrySet()) {
+            stringRedisTemplate.opsForValue().set(RedisKey.PanWxFosterMobileInfo + entry.getKey(), JSONArray.toJSONString(entry.getValue()));
         }
     }
 
-    public List<FosterwxMobileWxfriend> getMobileWxfriendByMobileId(Integer mobileId){
+    public List<FosterwxMobileWxfriend> getMobileWxfriendByMobileId(Integer mobileId) {
         List<FosterwxMobileWxfriend> res = new ArrayList<FosterwxMobileWxfriend>();
-        for (FosterwxMobileWxfriend fosterwxMobileWxfriend : this.fosterwxMobileWxfriendList){
-            if (fosterwxMobileWxfriend.getMobileId().equals(mobileId)){
+        for (FosterwxMobileWxfriend fosterwxMobileWxfriend : this.fosterwxMobileWxfriendList) {
+            if (fosterwxMobileWxfriend.getMobileId().equals(mobileId)) {
                 res.add(fosterwxMobileWxfriend);
             }
         }

+ 70 - 0
src/main/java/com/mokamrp/privates/tast/pangu/SyncFosterwxTaskEdit.java

@@ -0,0 +1,70 @@
+package com.mokamrp.privates.tast.pangu;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.mokamrp.privates.constant.RedisKey;
+import com.mokamrp.privates.entity.pangu.AddFosterwxMobileHandle;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobile;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobileWxfriend;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxTaskSchedule;
+import com.mokamrp.privates.service.pangu.FosterwxMobileService;
+import com.mokamrp.privates.service.pangu.FosterwxMobileWxfriendService;
+import com.mokamrp.privates.service.pangu.FosterwxStationService;
+import com.mokamrp.privates.service.pangu.FosterwxTaskScheduleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+public class SyncFosterwxTaskEdit {
+
+    @Autowired
+    public FosterwxTaskScheduleService fosterwxTaskScheduleService;
+
+    @Autowired
+    public FosterwxStationService fosterwxStationService;
+
+    @Autowired
+    public FosterwxMobileService fosterwxMobileService;
+
+    @Autowired
+    public FosterwxMobileWxfriendService fosterwxMobileWxfriendService;
+
+    @Autowired
+    public StringRedisTemplate stringRedisTemplate;
+
+
+    @Scheduled(cron = "*/1 * * * * ?")
+    public void execute() {
+        System.out.println("[cronjob]:异步执行微信养号任务信息修改/新增操作");
+        Integer cnt = 1;
+        while (true) {
+            cnt++;
+            if (cnt > 20) {
+                break;
+            }
+            try {
+                Thread.sleep(100);
+                String info = stringRedisTemplate.opsForList().rightPop(RedisKey.PanWxFosterTaskSync);
+                if (info == null || info.isEmpty()) {
+                    continue;
+                }
+                FosterwxTaskSchedule fosterwxTaskSchedule = JSON.parseObject(info, FosterwxTaskSchedule.class);
+                if (fosterwxTaskSchedule.getStationId().equals(0)) {
+                    continue;
+                }
+                //.更新
+                fosterwxTaskScheduleService.update(fosterwxTaskSchedule, new QueryWrapper<FosterwxTaskSchedule>()
+                        .eq("station_id", fosterwxTaskSchedule.getStationId())
+                        .eq("task_id", fosterwxTaskSchedule.getTaskId())
+                );
+            } catch (InterruptedException ie) {
+                Thread.currentThread().interrupt();
+            }
+        }
+    }
+}