|
|
@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.ReportsAdPushMapper;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IOptimizerRankPushService;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.DateUtils;
|
|
|
import cn.com.ctop.job.bytedance.utils.FeishuRobotUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
@@ -19,7 +20,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -30,8 +30,8 @@ public class OptimizerRankPushServiceImpl implements IOptimizerRankPushService {
|
|
|
@Autowired
|
|
|
ReportsAdPushMapper reportsPushMapper;
|
|
|
|
|
|
- private static final String TEMPLATE_VERSION = "1.0.8";
|
|
|
- private static final String TEMPLATE_ID = "AAqBGPmrbiJtk";
|
|
|
+ private static final String TEMPLATE_VERSION = "1.0.2";
|
|
|
+ private static final String TEMPLATE_ID = "AAqRUxrkkWuZf";
|
|
|
|
|
|
public void send() {
|
|
|
List<JSONObject> users = reportsPushMapper.selectUserList();
|
|
|
@@ -48,33 +48,15 @@ public class OptimizerRankPushServiceImpl implements IOptimizerRankPushService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- JSONObject template_variable = new JSONObject();
|
|
|
+
|
|
|
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;
|
|
|
- template_variable.put("todaydate", today.substring(5, 10));
|
|
|
- template_variable.put("thisHour", String.valueOf(hour));
|
|
|
- template_variable.put("lastHour", String.valueOf(lastHour));
|
|
|
- template_variable.put("lastLastHour", String.valueOf(lastLastHour));
|
|
|
- JSONArray object_list_4 = new JSONArray();//优化师排名
|
|
|
+
|
|
|
List<Map<String, String>> optimizerCostRank = reportsPushMapper.optimizerCostRank(todayLong, String.valueOf(lastHour));
|
|
|
- for (int i = 0; i < optimizerCostRank.size(); i++) {
|
|
|
- Map<String, String> map = optimizerCostRank.get(i);
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.put("rankRank", String.valueOf(map.getOrDefault("rk", "-")));
|
|
|
- if (mobileMap.containsKey(map.get("phonenumber"))){
|
|
|
- object.put("user_id", Arrays.asList(mobileMap.get(map.get("phonenumber"))));
|
|
|
- }else {
|
|
|
- object.put("user_id", Collections.emptyList());
|
|
|
- }
|
|
|
- object.put("rankTodayData", String.valueOf(map.getOrDefault("cost_amount", "0")));
|
|
|
-// object.put("rankThisHourData", String.valueOf(map.getOrDefault("hour_cost_amount", "0")));
|
|
|
- object.put("rankRealROI", String.valueOf(map.getOrDefault("real_roi", "0")));
|
|
|
- object_list_4.add(object);
|
|
|
- }
|
|
|
- template_variable.put("object_list_4", object_list_4);
|
|
|
+ Map<String, List<Map<String, String>>> deptMap = optimizerCostRank.stream().collect(Collectors.groupingBy(m -> String.valueOf(m.get("dept_id"))));
|
|
|
|
|
|
List<Map<String, String>> todayData = reportsPushMapper.optimizerDateData(todayLong);
|
|
|
List<Map<String, String>> hourData = reportsPushMapper.optimizerHourData(todayLong, String.valueOf(lastHour));
|
|
|
@@ -89,12 +71,39 @@ public class OptimizerRankPushServiceImpl implements IOptimizerRankPushService {
|
|
|
new Pair<>("real_roi", "真实ROI")
|
|
|
);
|
|
|
|
|
|
-// int index = 0;
|
|
|
+
|
|
|
+ int index = 0;
|
|
|
for (Map<String, String> optToday : todayData){
|
|
|
-// if (index++ >= 1){
|
|
|
-// break;
|
|
|
-// }
|
|
|
- JSONArray object_list_5 = new JSONArray();//本人数据
|
|
|
+ if (index++ > 1){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String deptId = String.valueOf(optToday.get("dept_id"));
|
|
|
+ if (deptId.equals("30201")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject template_variable = new JSONObject();
|
|
|
+ template_variable.put("todaydate", today.substring(5, 10));
|
|
|
+ template_variable.put("thisHour", String.valueOf(hour));
|
|
|
+ template_variable.put("lastHour", String.valueOf(lastHour));
|
|
|
+ template_variable.put("lastLastHour", String.valueOf(lastLastHour));
|
|
|
+ List<Map<String, String>> deptUserData = deptMap.get(deptId);
|
|
|
+ if (!Check.isNull(deptUserData)){
|
|
|
+ JSONArray object_list_4 = new JSONArray();
|
|
|
+ for (Map<String, String> deptUser: deptUserData){
|
|
|
+ //rankTodayData, rankRank, rankRealROI, userId
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("rankTodayData", deptUser.get("cost_amount"));
|
|
|
+ object.put("rankRank", deptUser.get("rk"));
|
|
|
+ object.put("rankRealROI", deptUser.get("real_roi"));
|
|
|
+ object.put("userId", Arrays.asList(mobileMap.get(String.valueOf(deptUser.get("phonenumber")))));
|
|
|
+ object_list_4.add(object);
|
|
|
+ }
|
|
|
+ template_variable.put("object_list_4", object_list_4);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ JSONArray object_list_5 = new JSONArray();
|
|
|
Map<String, String> optHour = hourDataMap.get(String.valueOf(optToday.get("user_id")));
|
|
|
Map<String, String> optLastHour = lastHourDataMap.get(String.valueOf(optToday.get("user_id")));
|
|
|
String rank = String.valueOf(optToday.get("rk"));
|
|
|
@@ -117,16 +126,9 @@ public class OptimizerRankPushServiceImpl implements IOptimizerRankPushService {
|
|
|
template_variable.put("object_list_5", object_list_5);
|
|
|
System.out.println("发送目标: nickName: "+nickName+", userId: "+ userId + ", feishuUserId: "+mobileMap.get(phoneNumber)+", rank: "+rank+", costAmount: "+costAmount);
|
|
|
sendToFeishu(token, template_variable, mobileMap.get(phoneNumber));
|
|
|
+// sendToFeishu(token, template_variable, "44fbaed6");
|
|
|
//clear
|
|
|
- template_variable.remove("myRank");
|
|
|
- template_variable.remove("object_list_5");
|
|
|
}
|
|
|
-
|
|
|
- template_variable.put("myRank", "0");
|
|
|
- sendToFeishu(token, template_variable, "44fbaed6");//zhaotx
|
|
|
- sendToFeishu(token, template_variable, "c5f6b59d");//yuyang
|
|
|
- sendToFeishu(token, template_variable, "265g9ef1");//wangshu
|
|
|
- sendToFeishu(token, template_variable, "58e7a98a");//xsq
|
|
|
}
|
|
|
|
|
|
private void sendToFeishu(String token, JSONObject template_variable, String receive_id) {
|
|
|
@@ -140,7 +142,6 @@ public class OptimizerRankPushServiceImpl implements IOptimizerRankPushService {
|
|
|
|
|
|
JSONObject request = new JSONObject();
|
|
|
request.put("receive_id", receive_id);
|
|
|
-// request.put("receive_id", "44fbaed6");
|
|
|
request.put("msg_type", "interactive");
|
|
|
request.put("content", content.toJSONString());
|
|
|
//发送
|