ソースを参照

优化 任务逻辑

lqc 4 年 前
コミット
fe91dc2d3e

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

@@ -68,7 +68,7 @@ public class FosterwxCashScheduleTaskListController extends BaseController<Foste
     @PostMapping("/reCreate")
     @ApiOperation("重新生成")
     public Object reCreate(FosterwxCashScheduleTaskList fosterwxCashScheduleTaskList) {
-        fosterwxCashScheduleTaskListService.reCreate(fosterwxCashScheduleTaskList);
+        fosterwxCashScheduleTaskListService.create(fosterwxCashScheduleTaskList);
 
         return AjaxResult.success("重新生成成功");
     }

+ 2 - 0
src/main/java/com/mokamrp/privates/mapper/pangu/FosterwxCashScheduleTaskListMapper.java

@@ -19,4 +19,6 @@ import java.util.List;
 @Component
 public interface FosterwxCashScheduleTaskListMapper extends BaseMapper<FosterwxCashScheduleTaskList> {
     public List<FosterwxCashScheduleTaskList> getList(@Param("ew") LambdaQueryWrapper<FosterwxCashScheduleTaskList> fosterwxCashScheduleTaskListLambdaQueryWrapper, @Param("limit") Integer page, @Param("offset") Integer offset);
+
+    List<FosterwxCashScheduleTaskList> getBannedGhid();
 }

+ 11 - 0
src/main/java/com/mokamrp/privates/mapper/pangu/FosterwxCashScheduleTaskListMapper.xml

@@ -11,6 +11,7 @@
         <result column="task_type" property="taskType" />
         <result column="remark" property="remark" />
         <result column="task_content" property="taskContent" />
+        <result column="gh_id" property="ghId" />
         <result column="status" property="status" />
         <result column="type" property="type" />
         <result column="err_info" property="errInfo" />
@@ -48,4 +49,14 @@
         order by task_list.id desc
         limit #{limit} offset #{offset}
     </select>
+    <select id="getBannedGhid" resultType="com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashScheduleTaskList">
+        SELECT
+            task_list.*
+        FROM
+            pan_fosterwx_cash_schedule_task_list task_list
+                LEFT JOIN pan_fosterwx_cash_oas_box box ON task_list.gh_id = box.gh_id
+        WHERE
+            box.fobidden_status = 2
+            AND task_list.`status` = 4
+    </select>
 </mapper>

+ 15 - 1
src/main/java/com/mokamrp/privates/mapper/pangu/pojo/FosterwxCashScheduleTaskList.java

@@ -52,11 +52,16 @@ public class FosterwxCashScheduleTaskList extends Model<FosterwxCashScheduleTask
     private String remark;
 
     /**
-     * 任务名称
+     * 任务详情
      */
     private String taskContent;
 
     /**
+     * gh_id
+     */
+    private String ghId;
+
+    /**
      * 状态(1、待生成;2、已生成;3、生成失败;4、待发送;5、已发送;6、已取消)
      */
     private Integer status;
@@ -159,6 +164,14 @@ public class FosterwxCashScheduleTaskList extends Model<FosterwxCashScheduleTask
         this.taskContent = taskContent;
     }
 
+    public String getGhId() {
+        return ghId;
+    }
+
+    public void setGhId(String ghId) {
+        this.ghId = ghId;
+    }
+
     public Integer getStatus() {
         return status;
     }
@@ -246,6 +259,7 @@ public class FosterwxCashScheduleTaskList extends Model<FosterwxCashScheduleTask
         ", taskType=" + taskType +
         ", remark=" + remark +
         ", taskContent=" + taskContent +
+        ", ghId=" + ghId +
         ", status=" + status +
         ", type=" + type +
         ", errInfo=" + errInfo +

+ 8 - 2
src/main/java/com/mokamrp/privates/service/pangu/FosterwxCashScheduleTaskListService.java

@@ -28,8 +28,14 @@ public interface FosterwxCashScheduleTaskListService extends IService<FosterwxCa
     void cancelTask(Integer id, Integer userId);
 
     /**
-     * 重新生成任务  生成失败|检测到公众号封禁重新生成链接
+     * 生成任务 正常生成 | 生成失败|检测到公众号封禁重新生成链接
      * @param fosterwxCashScheduleTaskList
      */
-    void reCreate(FosterwxCashScheduleTaskList fosterwxCashScheduleTaskList);
+    void create(FosterwxCashScheduleTaskList fosterwxCashScheduleTaskList);
+
+    /**
+     * 获取被封禁的任务
+     * @return
+     */
+    List<FosterwxCashScheduleTaskList> getBannedGhid();
 }

+ 8 - 0
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxCashAccountScheduleServiceImpl.java

@@ -10,6 +10,7 @@ import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashAccountSchedule;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashScheduleTaskList;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashTaskList;
 import com.mokamrp.privates.service.pangu.FosterwxCashAccountScheduleService;
+import com.mokamrp.privates.service.pangu.FosterwxCashScheduleTaskListService;
 import com.mokamrp.privates.service.pangu.FosterwxCashTaskTemplateService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -37,6 +38,9 @@ public class FosterwxCashAccountScheduleServiceImpl extends ServiceImpl<Fosterwx
     @Autowired
     public FosterwxCashScheduleTaskListMapper fosterwxCashScheduleTaskListMapper;
 
+    @Autowired
+    public FosterwxCashScheduleTaskListService fosterwxCashScheduleTaskListService;
+
     /**
      * 获取数据列表 支持分页
      * @param handle
@@ -80,6 +84,7 @@ public class FosterwxCashAccountScheduleServiceImpl extends ServiceImpl<Fosterwx
             ResHandle<List<FosterwxCashTaskList>> resHandle = fosterwxCashTaskTemplateService.getTaskByTemplateId(fosterwxCashAccountSchedule.getId());
 
             resHandle.getList().forEach(fosterwxCashTaskList -> {
+                // 创建任务
                 FosterwxCashScheduleTaskList fosterwxCashScheduleTaskList = new FosterwxCashScheduleTaskList();
                 fosterwxCashScheduleTaskList.setScheduleId(fosterwxCashAccountSchedule.getId());
                 fosterwxCashScheduleTaskList.setTemplateId(fosterwxCashAccountSchedule.getTemplateId());
@@ -97,6 +102,9 @@ public class FosterwxCashAccountScheduleServiceImpl extends ServiceImpl<Fosterwx
                 fosterwxCashScheduleTaskList.setUpdateAt(LocalDateTime.now());
 
                 fosterwxCashScheduleTaskListMapper.insert(fosterwxCashScheduleTaskList);
+
+                // 调用typer生成链接
+                fosterwxCashScheduleTaskListService.create(fosterwxCashScheduleTaskList);
             });
 
             // 任务列表创建完成后 账号排期状态设置成正常

+ 14 - 2
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxCashScheduleTaskListServiceImpl.java

@@ -75,11 +75,11 @@ public class FosterwxCashScheduleTaskListServiceImpl extends ServiceImpl<Fosterw
     }
 
     /**
-     * 重新生成任务  生成失败|检测到公众号封禁重新生成链接
+     * 生成任务 正常生成 | 生成失败|检测到公众号封禁重新生成链接
      * @param fosterwxCashScheduleTaskList
      */
     @Override
-    public void reCreate(FosterwxCashScheduleTaskList fosterwxCashScheduleTaskList) {
+    public void create(FosterwxCashScheduleTaskList fosterwxCashScheduleTaskList) {
         // 状态
         fosterwxCashScheduleTaskList.setStatus(1);
         // 失败原因
@@ -90,4 +90,16 @@ public class FosterwxCashScheduleTaskListServiceImpl extends ServiceImpl<Fosterw
 
 
     }
+
+    /**
+     * 获取被封禁的任务
+     * @return
+     */
+    @Override
+    public List<FosterwxCashScheduleTaskList> getBannedGhid() {
+        // 获取被封禁的任务
+        List<FosterwxCashScheduleTaskList> fosterwxCashScheduleTaskLists = fosterwxCashScheduleTaskListMapper.getBannedGhid();
+
+        return fosterwxCashScheduleTaskLists;
+    }
 }

+ 81 - 20
src/main/java/com/mokamrp/privates/task/pangu/SyncCreateCashTask.java

@@ -6,7 +6,9 @@ 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.FosterwxCashScheduleTaskList;
 import com.mokamrp.privates.service.pangu.FosterwxCashAccountScheduleService;
+import com.mokamrp.privates.service.pangu.FosterwxCashScheduleTaskListService;
 import lombok.extern.slf4j.Slf4j;
 import net.javacrumbs.shedlock.core.SchedulerLock;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,8 +34,14 @@ public class SyncCreateCashTask {
     private FosterwxCashAccountScheduleService fosterwxCashAccountScheduleService;
 
     @Autowired
+    private FosterwxCashScheduleTaskListService fosterwxCashScheduleTaskListService;
+
+    @Autowired
     private RestTemplate restTemplate;
 
+    /**
+     * 每天下午五点生成第二天的任务及链接
+     */
     @Scheduled(cron = "0 0 17 * * ?")
     @SchedulerLock(name = "pangu:SyncCreateCashTask", lockAtLeastForString = "PT5S", lockAtMostForString = "PT15M")
     public void syncCreateCashTask() {
@@ -65,31 +73,84 @@ public class SyncCreateCashTask {
         body.put("msg_type", "post");
         JSONArray content = new JSONArray();
         res.getList().forEach(fosterwxCashAccountSchedule -> {
-            JSONArray rowData = new JSONArray();
-            rowData.add(new JSONObject() {
-                {
-                    {
-                        put("tag", "text");
-                        put("text", "排期日期:" + fosterwxCashAccountSchedule.getScheduleDate() + " 账号组: " + fosterwxCashAccountSchedule.getGroupName() + " 任务失败数量:" + (fosterwxCashAccountSchedule.getTotalCount() - fosterwxCashAccountSchedule.getCreatedCount()) + "个");
-                    }
-                }
-            });
-            content.add(rowData);
+            content.add(getJsonArray("排期日期:" + fosterwxCashAccountSchedule.getScheduleDate() + " 账号组: " + fosterwxCashAccountSchedule.getGroupName() + " 任务失败数量:" + (fosterwxCashAccountSchedule.getTotalCount() - fosterwxCashAccountSchedule.getCreatedCount()) + "个"));
+        });
+
+        if (content.size() > 0) {
+            JSONObject post = new JSONObject();
+            JSONObject zh_cn = new JSONObject();
+            JSONObject outContent = new JSONObject();
+            zh_cn.put("title", "飞书汇总提醒任务失败详情:");
+            sendTofeishu(body, content, post, zh_cn, outContent);
+        }
+    }
+
+    /**
+     * 检查微信公众号封禁情况 封禁的情况下 需要重新换公众号重新生成
+     */
+    @Scheduled(cron = "0 */1 * * * ?")
+    @SchedulerLock(name = "pangu:TaskInfoNotify", lockAtLeastForString = "PT5S", lockAtMostForString = "PT15M")
+    public void checkGhidStatus() {
+        // 获取待发送状态的封禁的任务
+        List<FosterwxCashScheduleTaskList> fosterwxCashScheduleTaskLists = fosterwxCashScheduleTaskListService.getBannedGhid();
+
+        Map<String, Object> body = new HashMap<>(1);
+        body.put("msg_type", "post");
+        JSONArray content = new JSONArray();
+
+        fosterwxCashScheduleTaskLists.forEach(fosterwxCashScheduleTaskList -> {
+            // 飞书通知消息设置
+            content.add(getJsonArray("任务ID:" + fosterwxCashScheduleTaskList.getId() + " 公众号: " + fosterwxCashScheduleTaskList.getGhId() + " 发送时间:" + fosterwxCashScheduleTaskList.getSendTime()));
+            // 重新创建
+            fosterwxCashScheduleTaskListService.create(fosterwxCashScheduleTaskList);
         });
-        JSONObject post = new JSONObject();
-        JSONObject zh_cn = new JSONObject();
-        JSONObject outContent = new JSONObject();
-        zh_cn.put("title", "飞书汇总提醒任务失败详情:");
+
+        if (content.size() > 0) {
+            JSONObject post = new JSONObject();
+            JSONObject zh_cn = new JSONObject();
+            JSONObject outContent = new JSONObject();
+            zh_cn.put("title", "飞书汇总公众号封禁任务:");
+
+            // 重新生成提醒
+            content.add(getJsonArray("以上任务已重新生成!"));
+
+            sendTofeishu(body, content, post, zh_cn, outContent);
+        }
+    }
+
+    /**
+     * 发送到飞书
+     * @param body
+     * @param content
+     * @param post
+     * @param zh_cn
+     * @param outContent
+     */
+    private void sendTofeishu(Map<String, Object> body, JSONArray content, JSONObject post, JSONObject zh_cn, JSONObject outContent) {
         zh_cn.put("content", content);
         post.put("zh_cn", zh_cn);
         outContent.put("post", post);
         body.put("content", outContent);
         HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(body, null);
-        if (content.size() > 0) {
-            JSONObject result = restTemplate.exchange(FEISHU_ROBOT, HttpMethod.POST, httpEntity, JSONObject.class).getBody();
-            log.info("{}", result);
-        } else {
-            log.info("没有错误数据");
-        }
+        // 发送飞书提醒
+        restTemplate.exchange(FEISHU_ROBOT, HttpMethod.POST, httpEntity, JSONObject.class);
+    }
+
+    /**
+     * 飞书提醒格式化
+     * @param text
+     * @return
+     */
+    private JSONArray getJsonArray(String text) {
+        JSONArray rowData = new JSONArray();
+        rowData.add(new JSONObject() {
+            {
+                {
+                    put("tag", "text");
+                    put("text", text);
+                }
+            }
+        });
+        return rowData;
     }
 }

+ 1 - 1
src/test/java/com/mokamrp/AutoMPPangu.java

@@ -46,7 +46,7 @@ public class AutoMPPangu {
                 .setColumnNaming(NamingStrategy.underline_to_camel)
                 .setNaming(NamingStrategy.underline_to_camel) // 数据库表映射到实体的命名策略,下划线转驼峰命名
                 .setTablePrefix("pan_") //表名前缀
-                .setInclude("pan_fosterwx_cash_account_schedule").setInclude("pan_fosterwx_cash_schedule_task_list");
+                .setInclude("pan_fosterwx_cash_schedule_task_list");
         //4. 包名策略配置
         PackageConfig pkConfig = new PackageConfig();
         pkConfig.setParent("com.mokamrp.privates")