leon hace 5 años
padre
commit
1399b9732b

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

@@ -33,6 +33,8 @@ public class RedisKey {
     public static final String PanWxFosterMobileSync = "pan_wxfoster_mobile_sync";
     //.盘古 微信养号小程序异步编辑任务
     public static final String PanWxFosterTaskSync = "pan_wxfoster_task_sync";
+    //.盘古 微信养号站点列表
+    public static final String PanWxFosterStationInfo = "pan_wxfoster_station_info";
 
 }
 

+ 2 - 0
src/main/java/com/mokamrp/privates/controller/pangu/FosterwxMobileController.java

@@ -84,6 +84,7 @@ public class FosterwxMobileController extends BaseController<FosterwxMobile> {
     @Transactional(rollbackFor = Exception.class)
     public Object addPro(@Valid @RequestBody AddHandle<FosterwxMobile> addHandle, @AuthUser User authUser) {
         // 新增账号
+        this.onInsert(addHandle.getRaw());
         fosterwxMobileService.save(addHandle.getRaw());
         // 判断开始做任务时间是否设置了
         AjaxResult ajaxResult = null;
@@ -100,6 +101,7 @@ public class FosterwxMobileController extends BaseController<FosterwxMobile> {
     public Object editPro(@Valid @RequestBody EditHandle<FosterwxMobile> editHandle, @AuthUser User authUser) {
         String[] ids = editHandle.getIds().split(",");
         for (String id : ids) {
+            this.onUpdate(editHandle);
             FosterwxMobile fosterwxMobile = editHandle.getRaw();
             FosterwxMobile oldVO = fosterwxMobileService.getById(id);
             // 新增账号

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

@@ -1,9 +1,11 @@
 package com.mokamrp.privates.controller.pangu;
 
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.mokamrp.privates.constant.Constants;
 import com.mokamrp.privates.constant.HttpStatus;
+import com.mokamrp.privates.constant.RedisKey;
 import com.mokamrp.privates.controller.BaseController;
 import com.mokamrp.privates.entity.AddHandle;
 import com.mokamrp.privates.entity.EditHandle;
@@ -16,11 +18,14 @@ import com.mokamrp.privates.mapper.pojo.User;
 import com.mokamrp.privates.service.CoralApiService;
 import com.mokamrp.privates.service.WechatApiService;
 import com.mokamrp.privates.service.pangu.FosterwxStationService;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.List;
 import java.util.Map;
 
 
@@ -45,6 +50,9 @@ public class FosterwxStationController extends BaseController<FosterwxStation> {
     @Autowired
     public WechatApiService wechatApiService;
 
+    @Autowired
+    public StringRedisTemplate stringRedisTemplate;
+
     /*
      * @fast
      * 默认生成的控制器所继承的父类中有index/add/edit/del四个基础方法,均为post json请求
@@ -83,6 +91,7 @@ public class FosterwxStationController extends BaseController<FosterwxStation> {
 
         this.onUpdate(editHandle);
         service.update(editHandle.getRaw(), new QueryWrapper<FosterwxStation>().in("id", editHandle.getIds()));
+        this.sync();
         return AjaxResult.success(Constants.SUCCESS, true);
     }
 
@@ -103,7 +112,6 @@ public class FosterwxStationController extends BaseController<FosterwxStation> {
         if (fosterwxStationService.count(fosterwxStationLambdaQueryWrapper) > 0) {
             return AjaxResult.error("用户名重复");
         }
-
         addHandle.getRaw().setUploadUid(user.getId());
         this.onInsert(addHandle.getRaw());
         Boolean res = fosterwxStationService.save(addHandle.getRaw());
@@ -114,6 +122,7 @@ public class FosterwxStationController extends BaseController<FosterwxStation> {
             fosterwxStation.setBoxShareUrl(qrcodeUrl);
             fosterwxStation.setId(addHandle.getRaw().getId());
             fosterwxStationService.updateById(fosterwxStation);
+            this.sync();
             return AjaxResult.success(Constants.SUCCESS, res);
         } else {
             return AjaxResult.error("新增失败", res);
@@ -141,5 +150,13 @@ public class FosterwxStationController extends BaseController<FosterwxStation> {
         return AjaxResult.success(qrcodeUrl);
     }
 
+    public Boolean sync(){
+        List<FosterwxStation> fosterwxStationList = fosterwxStationService.list();
+        for(FosterwxStation fosterwxStation : fosterwxStationList){
+            stringRedisTemplate.opsForHash().put(RedisKey.PanWxFosterStationInfo,fosterwxStation.getId().toString(), JSONArray.toJSONString(fosterwxStation));
+        }
+        return true;
+    }
+
 }
 

+ 1 - 0
src/main/java/com/mokamrp/privates/entity/pangu/GetForsterwxMobileHandle.java

@@ -6,6 +6,7 @@ import lombok.Data;
 public class GetForsterwxMobileHandle {
     private Integer page;
     private Integer pagesize;
+    private Integer stationId;
     private Integer id;
     private Integer mobileCode;
     private String mobileNo;

+ 1 - 0
src/main/java/com/mokamrp/privates/mapper/pangu/FosterwxMobileMapper.xml

@@ -45,6 +45,7 @@
             <if test="param.mobileOperator != null">and mobile_operator = #{param.mobileOperator}</if>
             <if test="param.wxStatus != null">and wx_status = #{param.wxStatus}</if>
             <if test="param.status != null">and status = #{param.status}</if>
+            <if test="param.stationId != null">and station_id = #{param.stationId}</if>
         </where>
         order by id desc
     </select>

+ 18 - 0
src/main/java/com/mokamrp/privates/tast/pangu/SyncNewFosterwxTask.java

@@ -1,6 +1,7 @@
 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.ResHandle;
 import com.mokamrp.privates.entity.pangu.FosterwxTaskScheduleHandle;
@@ -15,6 +16,8 @@ import org.springframework.stereotype.Component;
 
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -35,10 +38,12 @@ public class SyncNewFosterwxTask {
         System.out.println("[cronjob]:同步微信养号任务到REDIS");
         Integer taskCnt = 60;
         LocalDateTime nowDate = LocalDateTime.now();
+        LocalDateTime startTime = LocalDateTime.of(nowDate.toLocalDate(), LocalTime.MIN);
 //        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
         String dateStr = nowDate.toLocalDate().toString();
         List<FosterwxStation> fosterwxStationList = fosterwxStationService.list();
         for (FosterwxStation fosterwxStation : fosterwxStationList) {
+            List<Integer> tasks = new ArrayList<>();
             Integer stationId = fosterwxStation.getId();
             FosterwxTaskScheduleHandle fosterwxTaskScheduleHandle = new FosterwxTaskScheduleHandle();
             fosterwxTaskScheduleHandle.setStationId(stationId);
@@ -49,6 +54,7 @@ public class SyncNewFosterwxTask {
             ResHandle<List<FosterwxTaskSchedule>> resHandle = fosterwxTaskScheduleService.getList(fosterwxTaskScheduleHandle);
             List<FosterwxTaskSchedule> fosterwxTaskScheduleList = resHandle.getList();
             for (FosterwxTaskSchedule fosterwxTaskSchedule : fosterwxTaskScheduleList) {
+                tasks.add(fosterwxTaskSchedule.getTaskId());
                 FosterwxTaskScheduleHandle handle = new FosterwxTaskScheduleHandle();
                 handle.setTaskId(fosterwxTaskSchedule.getTaskId());
                 handle.setStationId(fosterwxTaskSchedule.getStationId());
@@ -61,6 +67,18 @@ public class SyncNewFosterwxTask {
                 fosterwxTaskSchedule.setComment(taskInfo.getComment());
             }
             stringRedisTemplate.opsForHash().put(RedisKey.PanWxfosterTask + stationId, dateStr, JSON.toJSONString(fosterwxTaskScheduleList));
+            //.任务状态改为 已发送
+            if (tasks.size() > 0){
+                FosterwxTaskSchedule save =  new FosterwxTaskSchedule();
+                save.setTaskSendStatus(1);
+                fosterwxTaskScheduleService.update(save,new QueryWrapper<FosterwxTaskSchedule>()
+                        .eq("station_id",fosterwxStation.getId())
+                        .in("task_id",tasks)
+                        .apply("UNIX_TIMESTAMP(send_time) >= UNIX_TIMESTAMP('" + startTime + "')")
+                        .apply("UNIX_TIMESTAMP(send_time) <= UNIX_TIMESTAMP('" + nowDate + "')")
+                );
+            }
+            tasks.clear();
         }
     }
 }