Ver Fonte

Merge remote-tracking branch 'origin/master'

lqc há 5 anos atrás
pai
commit
f55a1408a4

+ 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";
 
 }
 

+ 1 - 1
src/main/java/com/mokamrp/privates/controller/pangu/FosterwxStationController.java

@@ -59,7 +59,7 @@ public class FosterwxStationController extends BaseController<FosterwxStation> {
         this.onUpdate(editHandle);
         String boxShareUrl = editHandle.getRaw().getBoxShareUrl();
         if (boxShareUrl != null && !boxShareUrl.isEmpty()){
-            editHandle.getRaw().setBoxShareUrl(fosterwxStationService.makeBoxShareUrl(boxShareUrl,editHandle.getIds()));
+            editHandle.getRaw().setBoxShareUrl(fosterwxStationService.makeBoxShareUrl(boxShareUrl,editHandle.getIds(),editHandle.getRaw().getStationName()));
         }
         service.update(editHandle.getRaw(), new QueryWrapper<FosterwxStation>().in("id", editHandle.getIds()));
         return AjaxResult.success(Constants.SUCCESS, true);

+ 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;
-
     /**
      * 任务开始时间
      */

+ 1 - 1
src/main/java/com/mokamrp/privates/service/pangu/FosterwxStationService.java

@@ -24,5 +24,5 @@ public interface FosterwxStationService extends IService<FosterwxStation> {
     //.@Leon 通过站点ID和TOKEN获取用户登录信息
     public FosterwxStation getAuthInfo(String token);
     //.@leon 加密小程序分享链接
-    public String makeBoxShareUrl(String boxShareUrl,String stationId);
+    public String makeBoxShareUrl(String boxShareUrl,String stationId,String stationName);
 }

+ 4 - 2
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxStationServiceImpl.java

@@ -19,6 +19,8 @@ import com.mokamrp.privates.entity.PostBasePageHandle;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 
 /**
@@ -105,10 +107,10 @@ public class FosterwxStationServiceImpl extends ServiceImpl<FosterwxStationMappe
      * @param stationId
      * @return
      */
-    public String makeBoxShareUrl(String boxShareUrl,String stationId){
+    public String makeBoxShareUrl(String boxShareUrl,String stationId,String stationName){
         String key = StringUtils.getRandomString(10)+stationId+StringUtils.getRandomString(5);
         byte[] keyB = key.getBytes();
-        String newBoxShareUrl = boxShareUrl + "?station="+ Base64.encode(keyB);
+        String newBoxShareUrl = boxShareUrl + "?station="+ Base64.encode(keyB)+"&stationName="+Base64.encode(stationName.getBytes(StandardCharsets.UTF_8));
         return newBoxShareUrl;
     }
 }

+ 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);
             }
         }

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

@@ -22,7 +22,9 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.List;
 
@@ -45,10 +47,10 @@ public class SyncFosterwxTask {
         Date nowDate = new Date();
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
         List<FosterwxStation> fosterwxStationList = fosterwxStationService.list();
-        for (FosterwxStation fosterwxStation : fosterwxStationList){
-            for (Integer i =0;i<=60;i++){
+        for (FosterwxStation fosterwxStation : fosterwxStationList) {
+            for (Integer i = 0; i <= 60; i++) {
                 String nextDate = df.format(nowDate);
-                if (!i.equals(0)){
+                if (!i.equals(0)) {
                     nextDate = df.format(new Date(nowDate.getTime() + 1000 * 60 * 60 * 24 * i));
                 }
                 Integer stationId = fosterwxStation.getId();
@@ -59,18 +61,19 @@ public class SyncFosterwxTask {
                 fosterwxTaskScheduleHandle.setPagesize(99999);
                 ResHandle<List<FosterwxTaskSchedule>> resHandle = fosterwxTaskScheduleService.getList(fosterwxTaskScheduleHandle);
                 List<FosterwxTaskSchedule> fosterwxTaskScheduleList = resHandle.getList();
-                for (FosterwxTaskSchedule fosterwxTaskSchedule : fosterwxTaskScheduleList){
+                for (FosterwxTaskSchedule fosterwxTaskSchedule : fosterwxTaskScheduleList) {
                     FosterwxTaskScheduleHandle handle = new FosterwxTaskScheduleHandle();
                     handle.setTaskId(fosterwxTaskSchedule.getTaskId());
                     handle.setStationId(fosterwxTaskSchedule.getStationId());
+                    handle.setSendDate(fosterwxTaskSchedule.getSendDate());
                     FosterwxTaskSchedule taskInfo = fosterwxTaskScheduleService.getInfo(handle);
-                    if(taskInfo == null){
+                    if (taskInfo == null) {
                         continue;
                     }
                     fosterwxTaskSchedule.setMobileCount(taskInfo.getMobileCount());
                     fosterwxTaskSchedule.setComment(taskInfo.getComment());
                 }
-                stringRedisTemplate.opsForHash().put(RedisKey.PanWxfosterTask+stationId,nextDate, JSON.toJSONString(fosterwxTaskScheduleList));
+                stringRedisTemplate.opsForHash().put(RedisKey.PanWxfosterTask + stationId, nextDate, JSON.toJSONString(fosterwxTaskScheduleList));
             }
         }
     }

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

@@ -0,0 +1,75 @@
+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;
+                }
+                FosterwxTaskSchedule save = new FosterwxTaskSchedule();
+                save.setErrMsg(fosterwxTaskSchedule.getErrMsg());
+                if (!fosterwxTaskSchedule.getTaskStatus().equals(0)){
+                    save.setTaskStatus(fosterwxTaskSchedule.getTaskStatus());
+                }
+                //.更新
+                fosterwxTaskScheduleService.update(save, new QueryWrapper<FosterwxTaskSchedule>()
+                        .eq("station_id", fosterwxTaskSchedule.getStationId())
+                        .eq("task_id", fosterwxTaskSchedule.getTaskId())
+                );
+            } catch (InterruptedException ie) {
+                Thread.currentThread().interrupt();
+            }
+        }
+    }
+}