lqc пре 4 година
родитељ
комит
bd52050e8f

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

@@ -125,7 +125,7 @@ public class FosterwxCashAccountScheduleController extends BaseController<Foster
 
     @PostMapping("/immediateCreate")
     @Transactional(rollbackFor = Exception.class)
-    @ApiOperation(value = "立即生成----缺少typer的接口")
+    @ApiOperation(value = "立即生成")
     public Object immediateCreate(FosterwxCashAccountScheduleHandle handle) {
         Arrays.asList(handle.getIds().split(REGEX)).forEach(id -> {
             List<FosterwxCashScheduleTaskList> newsList = fosterwxCashAccountScheduleService.createTask(Integer.valueOf(id));

+ 36 - 4
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxCashScheduleTaskListServiceImpl.java

@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.mokamrp.privates.entity.ResHandle;
 import com.mokamrp.privates.entity.pangu.FosterwxCashScheduleTaskListHandle;
 import com.mokamrp.privates.mapper.pangu.FosterwxCashScheduleTaskListMapper;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashOasBox;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashScheduleTaskList;
+import com.mokamrp.privates.service.pangu.FosterwxCashOasBoxService;
 import com.mokamrp.privates.service.pangu.FosterwxCashScheduleTaskListService;
 import com.mokamrp.privates.service.pangu.FosterwxCashTaskListService;
 import com.mokamrp.privates.utils.pangu.redis.task.TaskRedis;
@@ -14,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -36,6 +39,9 @@ public class FosterwxCashScheduleTaskListServiceImpl extends ServiceImpl<Fosterw
     @Autowired
     public FosterwxCashTaskListService fosterwxCashTaskListService;
 
+    @Autowired
+    public FosterwxCashOasBoxService fosterwxCashOasBoxService;
+
     /**
      * 获取数据列表 支持分页
      * @param handle
@@ -92,20 +98,46 @@ public class FosterwxCashScheduleTaskListServiceImpl extends ServiceImpl<Fosterw
      */
     @Override
     public void create(List<FosterwxCashScheduleTaskList> newsList) {
+        if (newsList.isEmpty()) return;
+
+        String ghid = "";
+        FosterwxCashOasBox fosterwxCashOasBox = fosterwxCashOasBoxService.getRandOas(newsList.get(0).getGroupId());
+        if (null != fosterwxCashOasBox) {
+            ghid = fosterwxCashOasBox.getGhId();
+        }
+        int count = 0;
+        List<FosterwxCashScheduleTaskList> tempList = new ArrayList<>();
         for (int i = 0; i < newsList.size(); i++) {
+            if (count == 8) {
+                fosterwxCashOasBoxService.addSendTextCnt(ghid);
+
+                taskRedis.createUrlByTyper(JSON.toJSONString(tempList));
+                tempList.clear();
+                fosterwxCashOasBox = fosterwxCashOasBoxService.getRandOas(newsList.get(0).getGroupId());
+                if (null != fosterwxCashOasBox) {
+                    ghid = fosterwxCashOasBox.getGhId();
+                }
+                count = 0;
+            }
             FosterwxCashScheduleTaskList fosterwxCashScheduleTaskList = newsList.get(i);
+
             // 状态
             fosterwxCashScheduleTaskList.setStatus(1);
             // 失败原因
             fosterwxCashScheduleTaskList.setErrInfo("");
-            //TODO 传递组id 随机获取ghid
-            fosterwxCashScheduleTaskList.setGhId("");
+            // 分配的公众号
+            fosterwxCashScheduleTaskList.setGhId(ghid);
 
             fosterwxCashScheduleTaskListMapper.updateById(fosterwxCashScheduleTaskList);
             fosterwxCashScheduleTaskList.setFosterwxCashTaskList(fosterwxCashTaskListService.getById(fosterwxCashScheduleTaskList.getTaskId()));
+            tempList.add(fosterwxCashScheduleTaskList);
+            count++;
+            newsList.remove(i);
+            i--;
         }
-
-        taskRedis.createUrlByTyper(JSON.toJSONString(newsList));
+        fosterwxCashOasBoxService.addSendTextCnt(ghid);
+        taskRedis.createUrlByTyper(JSON.toJSONString(tempList));
+        tempList.clear();
     }
 
     /**

+ 25 - 5
src/main/java/com/mokamrp/privates/task/pangu/SyncCreateCashTask.java

@@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.mokamrp.privates.entity.ResHandle;
 import com.mokamrp.privates.entity.pangu.FosterwxCashAccountScheduleHandle;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashAccountSchedule;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashOasBox;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashScheduleTaskList;
 import com.mokamrp.privates.service.pangu.FosterwxCashAccountScheduleService;
+import com.mokamrp.privates.service.pangu.FosterwxCashOasBoxService;
 import com.mokamrp.privates.service.pangu.FosterwxCashScheduleTaskListService;
 import lombok.extern.slf4j.Slf4j;
 import net.javacrumbs.shedlock.core.SchedulerLock;
@@ -19,10 +21,8 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
 
 import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.time.LocalDateTime;
+import java.util.*;
 
 /**
  * 每天五点定时生成第二天的任务列表
@@ -40,12 +40,20 @@ public class SyncCreateCashTask {
     @Autowired
     private RestTemplate restTemplate;
 
+    @Autowired
+    private FosterwxCashOasBoxService fosterwxCashOasBoxService;
+
     /**
      * 每天下午五点生成第二天的任务及链接
      */
     @Scheduled(cron = "0 0 17 * * ?")
     @SchedulerLock(name = "pangu:SyncCreateCashTask", lockAtLeastForString = "PT5S", lockAtMostForString = "PT15M")
     public void syncCreateCashTask() {
+        // 优先清空公众号 小程序使用次数
+        fosterwxCashOasBoxService.update(new FosterwxCashOasBox() {{
+            setUpdateAt(LocalDateTime.now());
+            setSendTextCnt(0);
+        }}, null);
         // 获取明天日期
         LocalDate nextDay = LocalDate.now().plusDays(1);
 
@@ -58,8 +66,20 @@ public class SyncCreateCashTask {
         });
 
         // 由于不能浪费公众号发文为 需要整合起来一起发送
+        // 按照组别组合在一起
+        Map<Integer, List<FosterwxCashScheduleTaskList>> groupList = new HashMap<>();
+        newsList.forEach(fosterwxCashScheduleTaskList -> {
+            Integer groupId = fosterwxCashScheduleTaskList.getGroupId();
+            if (groupList.get(groupId) != null) {
+                groupList.get(groupId).add(fosterwxCashScheduleTaskList);
+            } else {
+                groupList.put(groupId, Collections.singletonList(fosterwxCashScheduleTaskList));
+            }
+        });
         // 调用typer生成链接
-        fosterwxCashScheduleTaskListService.create(newsList);
+        for (Integer id : groupList.keySet()) {
+            fosterwxCashScheduleTaskListService.create(groupList.get(id));
+        }
     }
 
     /**

+ 2 - 0
src/test/java/com/mokamrp/Tests.java

@@ -11,7 +11,9 @@ import java.text.NumberFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Slf4j
 public class Tests {