Browse Source

飞书定时推送任务生成失败详情

lqc 4 years ago
parent
commit
8fc5564f47

+ 21 - 8
src/main/java/com/mokamrp/privates/task/pangu/SyncCreateCashTask.java

@@ -7,15 +7,16 @@ 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.service.pangu.FosterwxCashAccountScheduleService;
+import lombok.extern.slf4j.Slf4j;
 import net.javacrumbs.shedlock.core.SchedulerLock;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpMethod;
 import org.springframework.scheduling.annotation.Scheduled;
+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;
@@ -23,6 +24,8 @@ import java.util.Map;
 /**
  * 每天五点定时生成第二天的任务列表
  */
+@Component
+@Slf4j
 public class SyncCreateCashTask {
     public static final String FEISHU_ROBOT = "https://open.feishu.cn/open-apis/bot/v2/hook/9bc38791-e7d1-48a1-ae64-0df632e81a36";
     @Autowired
@@ -63,20 +66,30 @@ public class SyncCreateCashTask {
         JSONArray content = new JSONArray();
         res.getList().forEach(fosterwxCashAccountSchedule -> {
             JSONArray rowData = new JSONArray();
-            rowData.add(new ArrayList<JSONObject>() {
+            rowData.add(new JSONObject() {
                 {
                     {
-                        add(new JSONObject() {{
-                            put("tag", "text");
-                            put("text", "排期日期:" + fosterwxCashAccountSchedule.getScheduleDate() + " 账号组" + fosterwxCashAccountSchedule.getGroupName() + " 任务失败数量:" + (fosterwxCashAccountSchedule.getTotalCount() - fosterwxCashAccountSchedule.getCreatedCount()) + "个");
-                        }});
+                        put("tag", "text");
+                        put("text", "排期日期:" + fosterwxCashAccountSchedule.getScheduleDate() + " 账号组: " + fosterwxCashAccountSchedule.getGroupName() + " 任务失败数量:" + (fosterwxCashAccountSchedule.getTotalCount() - fosterwxCashAccountSchedule.getCreatedCount()) + "个");
                     }
                 }
             });
             content.add(rowData);
         });
-        body.put("content", content);
+        JSONObject post = new JSONObject();
+        JSONObject zh_cn = new JSONObject();
+        JSONObject outContent = new JSONObject();
+        zh_cn.put("title", "飞书汇总提醒任务失败详情:");
+        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);
-        JSONObject result = restTemplate.exchange(FEISHU_ROBOT, HttpMethod.POST, httpEntity, JSONObject.class).getBody();
+        if (content.size() > 0) {
+            JSONObject result = restTemplate.exchange(FEISHU_ROBOT, HttpMethod.POST, httpEntity, JSONObject.class).getBody();
+            log.info("{}", result);
+        } else {
+            log.info("没有错误数据");
+        }
     }
 }

+ 9 - 0
src/test/java/com/mokamrp/WebTest.java

@@ -10,6 +10,7 @@ import com.mokamrp.privates.service.pangu.FosterwxMobilePoolService;
 import com.mokamrp.privates.service.pangu.FosterwxMobileService;
 import com.mokamrp.privates.service.pangu.FosterwxMobileTaskTimeListService;
 import com.mokamrp.privates.service.pangu.FosterwxTaskScheduleService;
+import com.mokamrp.privates.task.pangu.SyncCreateCashTask;
 import com.mokamrp.privates.task.pangu.SyncFosterwxMobilePool;
 import com.mokamrp.privates.task.pangu.SyncMobilePoolFans;
 import lombok.extern.slf4j.Slf4j;
@@ -46,6 +47,9 @@ public class WebTest {
     @Autowired
     private SyncMobilePoolFans syncMobilePoolFans;
 
+    @Autowired
+    private SyncCreateCashTask syncCreateCashTask;
+
     @Test
     public void test1() {
         // 清洗数据
@@ -99,4 +103,9 @@ public class WebTest {
             }
         });
     }
+
+    @Test
+    public void test4(){
+        syncCreateCashTask.taskInfoNotify();
+    }
 }