|
|
@@ -1,9 +1,10 @@
|
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.FeishuSendObject;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.ReportsAdPushMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IReportsAdPushService;
|
|
|
-import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.DateUtils;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.FeishuSendObjectUtils;
|
|
|
import cn.com.ctop.job.bytedance.utils.FeishuRobotUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -53,7 +54,7 @@ public class ReportsAdPushServiceImpl implements IReportsAdPushService {
|
|
|
,"HR-00704" //段鹏举
|
|
|
,"HR-00642" //孟阳
|
|
|
);
|
|
|
- send(userIds);
|
|
|
+ sendToUserIds(userIds);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -65,11 +66,20 @@ public class ReportsAdPushServiceImpl implements IReportsAdPushService {
|
|
|
// ,"HR-00459" //angaoqi
|
|
|
// ,"HR-00439" //huangpingkang
|
|
|
);
|
|
|
- send(userIds);
|
|
|
+ sendToUserIds(userIds);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void send(List<String> userIds) {
|
|
|
+ @Override
|
|
|
+ public void send(List<FeishuSendObject> sendObjects) {
|
|
|
+ send(FeishuSendObjectUtils.userIds(sendObjects), FeishuSendObjectUtils.chatIds(sendObjects));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendToUserIds(List<String> userIds) {
|
|
|
+ send(userIds, Arrays.asList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void send(List<String> userIds, List<String> chatIds) {
|
|
|
String today = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
Long todayLong = Long.parseLong(today.replaceAll("-", ""));
|
|
|
int hour = Integer.parseInt(DateUtils.getNowDate("H"));
|
|
|
@@ -173,6 +183,9 @@ public class ReportsAdPushServiceImpl implements IReportsAdPushService {
|
|
|
for (String userId : userIds){
|
|
|
sendToFeishu(token, template_variables, userId);
|
|
|
}
|
|
|
+ for (String chatId : chatIds){
|
|
|
+ sendToChatGroup(token, template_variables, chatId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void sendToFeishu(String token, JSONObject template_variable, String receive_id) {
|
|
|
@@ -201,4 +214,30 @@ public class ReportsAdPushServiceImpl implements IReportsAdPushService {
|
|
|
log.error("发送飞书消息失败", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void sendToChatGroup(String token, JSONObject template_variable, String chatId) {
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
+ JSONObject contentData = new JSONObject();
|
|
|
+ contentData.put("template_id",TEMPLATE_ID);
|
|
|
+ contentData.put("template_version_name", TEMPLATE_VERSION);
|
|
|
+ contentData.put("template_variable", template_variable);
|
|
|
+ content.put("type", "template");
|
|
|
+ content.put("data", contentData);
|
|
|
+
|
|
|
+ JSONObject request = new JSONObject();
|
|
|
+ request.put("receive_id", chatId);
|
|
|
+ request.put("msg_type", "interactive");
|
|
|
+ request.put("content", content.toJSONString());
|
|
|
+ try (CloseableHttpClient client = HttpClients.createDefault()){
|
|
|
+ HttpPost httpPost = new HttpPost("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id");
|
|
|
+ httpPost.setHeader("Authorization", "Bearer "+token);
|
|
|
+ HttpEntity entity = new StringEntity(request.toJSONString(), "UTF-8");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
|
+ CloseableHttpResponse respon = client.execute(httpPost);
|
|
|
+ System.out.println("发送结果: "+ EntityUtils.toString(respon.getEntity(), "UTF-8"));
|
|
|
+ }catch (IOException e){
|
|
|
+ log.error("发送飞书消息失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|