|
@@ -37,14 +37,14 @@ public class MovieRankPushServiceImpl implements IMovieRankPushService {
|
|
|
public void send() {
|
|
public void send() {
|
|
|
List<String> userIds = Arrays.asList(
|
|
List<String> userIds = Arrays.asList(
|
|
|
"44fbaed6"
|
|
"44fbaed6"
|
|
|
- ,"ebeeced9" //yumeng
|
|
|
|
|
- ,"265g9ef1" //wangshu
|
|
|
|
|
- ,"c5f6b59d" //yuyang
|
|
|
|
|
- ,"58e7a98a" //xsq
|
|
|
|
|
- ,"11a45882" //chenglitong
|
|
|
|
|
- ,"97db2de8" //anjuejia
|
|
|
|
|
- ,"fbgd2d2f" //xuweiwei
|
|
|
|
|
- ,"ff93g2ee" //zhangxiaofeng
|
|
|
|
|
|
|
+ , "ebeeced9" //yumeng
|
|
|
|
|
+ , "265g9ef1" //wangshu
|
|
|
|
|
+ , "c5f6b59d" //yuyang
|
|
|
|
|
+ , "58e7a98a" //xsq
|
|
|
|
|
+ , "11a45882" //chenglitong
|
|
|
|
|
+ , "97db2de8" //anjuejia
|
|
|
|
|
+ , "fbgd2d2f" //xuweiwei
|
|
|
|
|
+ , "ff93g2ee" //zhangxiaofeng
|
|
|
);
|
|
);
|
|
|
List<String> chatIds = Arrays.asList(
|
|
List<String> chatIds = Arrays.asList(
|
|
|
|
|
|
|
@@ -52,85 +52,90 @@ public class MovieRankPushServiceImpl implements IMovieRankPushService {
|
|
|
send(userIds, chatIds);
|
|
send(userIds, chatIds);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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"));
|
|
|
|
|
- int lastHour = hour -1;
|
|
|
|
|
- int lastLastHour = hour -2;
|
|
|
|
|
-
|
|
|
|
|
- List<JSONObject> t1 = reportsAdPushMapper.movieTop(todayLong, lastHour, 1, "IAP");
|
|
|
|
|
- List<JSONObject> t2 = reportsAdPushMapper.movieTop(todayLong, lastHour, 1, "IAA");
|
|
|
|
|
- List<JSONObject> t3 = reportsAdPushMapper.movieTop(todayLong, lastHour, 4, "IAP");
|
|
|
|
|
- List<JSONObject> t4 = reportsAdPushMapper.movieTop(todayLong, lastHour, 4, "IAA");
|
|
|
|
|
-
|
|
|
|
|
- JSONObject template_variables = new JSONObject();
|
|
|
|
|
- template_variables.put("thisHour", String.valueOf(hour));
|
|
|
|
|
- template_variables.put("lastHour", String.valueOf(lastHour));
|
|
|
|
|
- template_variables.put("table_raw_array_1", buildFeishuTable(t1));
|
|
|
|
|
- template_variables.put("table_raw_array_2", buildFeishuTable(t2));
|
|
|
|
|
- template_variables.put("table_raw_array_3", buildFeishuTable(t3));
|
|
|
|
|
- template_variables.put("table_raw_array_4", buildFeishuTable(t4));
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- List<JSONObject> users = reportsAdPushMapper.selectOptimizerList();
|
|
|
|
|
- List<String> mobiles = users.stream().map(user -> user.getString("phonenumber"))
|
|
|
|
|
- .filter(s -> s != null && s.length() == 11)
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- String token;
|
|
|
|
|
- Map<String, String> mobileMap;
|
|
|
|
|
|
|
+ private void send(List<String> userIds, List<String> chatIds) {
|
|
|
try {
|
|
try {
|
|
|
- token = FeishuRobotUtil.getFsZtTenantToken();
|
|
|
|
|
- mobileMap = FeishuRobotUtil.getFsUserIds(token, mobiles); //mobile -> userId
|
|
|
|
|
- }catch (IOException e){
|
|
|
|
|
- log.error("获取飞书token失败", e);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- System.out.println(mobileMap);
|
|
|
|
|
|
|
+ String today = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
|
|
+ Long todayLong = Long.parseLong(today.replaceAll("-", ""));
|
|
|
|
|
+ int hour = Integer.parseInt(DateUtils.getNowDate("H"));
|
|
|
|
|
+ int lastHour = hour - 1;
|
|
|
|
|
+ int lastLastHour = hour - 2;
|
|
|
|
|
+
|
|
|
|
|
+ List<JSONObject> t1 = reportsAdPushMapper.movieTop(todayLong, lastHour, 1, "IAP");
|
|
|
|
|
+ List<JSONObject> t2 = reportsAdPushMapper.movieTop(todayLong, lastHour, 1, "IAA");
|
|
|
|
|
+ List<JSONObject> t3 = reportsAdPushMapper.movieTop(todayLong, lastHour, 4, "IAP");
|
|
|
|
|
+ List<JSONObject> t4 = reportsAdPushMapper.movieTop(todayLong, lastHour, 4, "IAA");
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject template_variables = new JSONObject();
|
|
|
|
|
+ template_variables.put("thisHour", String.valueOf(hour));
|
|
|
|
|
+ template_variables.put("lastHour", String.valueOf(lastHour));
|
|
|
|
|
+ template_variables.put("table_raw_array_1", buildFeishuTable(t1));
|
|
|
|
|
+ template_variables.put("table_raw_array_2", buildFeishuTable(t2));
|
|
|
|
|
+ template_variables.put("table_raw_array_3", buildFeishuTable(t3));
|
|
|
|
|
+ template_variables.put("table_raw_array_4", buildFeishuTable(t4));
|
|
|
|
|
+ List<JSONObject> users = reportsAdPushMapper.selectOptimizerList();
|
|
|
|
|
+ List<String> mobiles = users.stream().map(user -> user.getString("phonenumber"))
|
|
|
|
|
+ .filter(s -> s != null && s.length() == 11)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ String token;
|
|
|
|
|
+ Map<String, String> mobileMap;
|
|
|
|
|
+ try {
|
|
|
|
|
+ token = FeishuRobotUtil.getFsZtTenantToken();
|
|
|
|
|
+ mobileMap = FeishuRobotUtil.getFsUserIds(token, mobiles); //mobile -> userId
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("获取飞书token失败", e);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for (String userId : userIds) {
|
|
|
|
|
- sendToFeishu(token, template_variables, userId);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ System.out.println(mobileMap);
|
|
|
|
|
|
|
|
- for (String userId : mobileMap.values()){
|
|
|
|
|
- if (userIds.contains(userId)){
|
|
|
|
|
- continue;//重复的跳过
|
|
|
|
|
|
|
+ for (String userId : userIds) {
|
|
|
|
|
+ sendToFeishu(token, template_variables, userId);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ for (String userId : mobileMap.values()) {
|
|
|
|
|
+ if (userIds.contains(userId)) {
|
|
|
|
|
+ continue;//重复的跳过
|
|
|
|
|
+ }
|
|
|
// System.out.println("发送给:"+userId);
|
|
// System.out.println("发送给:"+userId);
|
|
|
- sendToFeishu(token, template_variables, userId);
|
|
|
|
|
|
|
+ sendToFeishu(token, template_variables, userId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("剧单发送失败: {}", e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private JSONArray buildFeishuTable(List<JSONObject> t1){
|
|
|
|
|
- JSONArray table_raw_array_1 = new JSONArray();
|
|
|
|
|
- for (JSONObject t : t1){
|
|
|
|
|
|
|
+ private JSONArray buildFeishuTable(List<JSONObject> t1) {
|
|
|
|
|
+ JSONArray table_raw_array_1 = new JSONArray();
|
|
|
|
|
+ for (JSONObject t : t1) {
|
|
|
JSONObject row = new JSONObject();
|
|
JSONObject row = new JSONObject();
|
|
|
Double hourSpeed = t.getDouble("cost_hour_number");
|
|
Double hourSpeed = t.getDouble("cost_hour_number");
|
|
|
- if (hourSpeed>=20000.0){
|
|
|
|
|
- row.put("movie_name", "<font color='red'>"+ t.getString("standard_movie_name")+"(起量)</font>");
|
|
|
|
|
- }else {
|
|
|
|
|
|
|
+ if (hourSpeed >= 20000.0) {
|
|
|
|
|
+ row.put("movie_name", "<font color='red'>" + t.getString("standard_movie_name") + "(起量)</font>");
|
|
|
|
|
+ } else {
|
|
|
row.put("movie_name", t.getString("standard_movie_name"));
|
|
row.put("movie_name", t.getString("standard_movie_name"));
|
|
|
}
|
|
}
|
|
|
String projectSource = t.getString("project_source");
|
|
String projectSource = t.getString("project_source");
|
|
|
String projectAdStep = t.getString("project_ad_step");
|
|
String projectAdStep = t.getString("project_ad_step");
|
|
|
StringBuffer sb = new StringBuffer();
|
|
StringBuffer sb = new StringBuffer();
|
|
|
- sb.append("<text_tag color='blue'>"+projectSource+"</text_tag>");
|
|
|
|
|
- sb.append("<text_tag color='green'>"+projectAdStep+"</text_tag>");
|
|
|
|
|
|
|
+ sb.append("<text_tag color='blue'>" + projectSource + "</text_tag>");
|
|
|
|
|
+ sb.append("<text_tag color='green'>" + projectAdStep + "</text_tag>");
|
|
|
row.put("project_type", sb.toString());
|
|
row.put("project_type", sb.toString());
|
|
|
row.put("cost_hour", t.getString("cost_hour"));
|
|
row.put("cost_hour", t.getString("cost_hour"));
|
|
|
row.put("cost_today", t.getString("cost_today"));
|
|
row.put("cost_today", t.getString("cost_today"));
|
|
|
row.put("cost_history", t.getString("cost_history"));
|
|
row.put("cost_history", t.getString("cost_history"));
|
|
|
table_raw_array_1.add(row);
|
|
table_raw_array_1.add(row);
|
|
|
}
|
|
}
|
|
|
- return table_raw_array_1;
|
|
|
|
|
|
|
+ return table_raw_array_1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void sendToFeishu(String token, JSONObject template_variable, String receive_id) {
|
|
private void sendToFeishu(String token, JSONObject template_variable, String receive_id) {
|
|
|
JSONObject content = new JSONObject();
|
|
JSONObject content = new JSONObject();
|
|
|
JSONObject contentData = new JSONObject();
|
|
JSONObject contentData = new JSONObject();
|
|
|
- contentData.put("template_id",TEMPLATE_ID);
|
|
|
|
|
|
|
+ contentData.put("template_id", TEMPLATE_ID);
|
|
|
contentData.put("template_version_name", TEMPLATE_VERSION);
|
|
contentData.put("template_version_name", TEMPLATE_VERSION);
|
|
|
contentData.put("template_variable", template_variable);
|
|
contentData.put("template_variable", template_variable);
|
|
|
content.put("type", "template");
|
|
content.put("type", "template");
|
|
@@ -141,15 +146,15 @@ public class MovieRankPushServiceImpl implements IMovieRankPushService {
|
|
|
request.put("msg_type", "interactive");
|
|
request.put("msg_type", "interactive");
|
|
|
request.put("content", content.toJSONString());
|
|
request.put("content", content.toJSONString());
|
|
|
//发送
|
|
//发送
|
|
|
- try (CloseableHttpClient client = HttpClients.createDefault()){
|
|
|
|
|
|
|
+ try (CloseableHttpClient client = HttpClients.createDefault()) {
|
|
|
HttpPost httpPost = new HttpPost("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=user_id");
|
|
HttpPost httpPost = new HttpPost("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=user_id");
|
|
|
- httpPost.setHeader("Authorization", "Bearer "+token);
|
|
|
|
|
|
|
+ httpPost.setHeader("Authorization", "Bearer " + token);
|
|
|
HttpEntity entity = new StringEntity(request.toJSONString(), "UTF-8");
|
|
HttpEntity entity = new StringEntity(request.toJSONString(), "UTF-8");
|
|
|
httpPost.setEntity(entity);
|
|
httpPost.setEntity(entity);
|
|
|
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
|
CloseableHttpResponse respon = client.execute(httpPost);
|
|
CloseableHttpResponse respon = client.execute(httpPost);
|
|
|
- System.out.println("发送结果: "+ EntityUtils.toString(respon.getEntity(), "UTF-8"));
|
|
|
|
|
- }catch (IOException e){
|
|
|
|
|
|
|
+ log.info("剧单发送结果:{}", EntityUtils.toString(respon.getEntity(), "UTF-8"));
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
log.error("发送飞书消息失败", e);
|
|
log.error("发送飞书消息失败", e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|