hpk 10 месяцев назад
Родитель
Сommit
c56e7cf023

+ 1 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/FeishuController.java

@@ -99,7 +99,7 @@ public class FeishuController {
     @PostMapping("/sendUnbind")
     public void sendUnbind(@RequestBody JSONObject obj){
         JSONArray array = obj.getJSONArray("advertiserIds");
-        List<String> list = array.toJavaList(String.class);
+        List<String> list = array == null ? null : array.toJavaList(String.class);
         unbindWarnPushService.send(list, false);
     }
 

+ 39 - 43
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/UnbindWarnPushServiceImpl.java

@@ -29,38 +29,37 @@ import java.util.stream.Collectors;
 @Slf4j
 public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
 
-    private static final String TEMPLATE_VERSION = "1.0.5";
+    private static final String TEMPLATE_VERSION = "1.0.7";
     private static final String TEMPLATE_ID = "AAqRuaOUCifK9";
     @Autowired
     ReportsAdPushMapper reportsPushMapper;
 
     @Override
-    public void send(){
+    public void send() {
         send(null, true);
     }
 
     @Override
     public void send(List<String> advertiserIds, boolean copySend) {
+        String today = DateUtils.getNowDate("yyyy-MM-dd");
+        Long todayLong = Long.parseLong(today.replaceAll("-", ""));
+        String last90Day = DateUtils.getNowAddDate("yyyy-MM-dd", -60);
+        Long last90DayLong = Long.parseLong(last90Day.substring(0, 10).replaceAll("-", ""));
+        List<Map<String, String>> unbindData = reportsPushMapper.unbindData(todayLong, last90DayLong, advertiserIds);
+        if (unbindData.isEmpty()) {
+            log.info("unbindData数:0");
+            return;
+        }
         List<JSONObject> users = reportsPushMapper.selectUserList();
         users.forEach(u -> {
-            if (u.containsKey("remark") && u.getString("remark") != null && u.getString("remark").length() < 2){
+            if (u.containsKey("remark") && u.getString("remark") != null && u.getString("remark").length() < 2) {
                 u.remove("remark");
             }
         });
         List<String> mobiles = users.stream().map(user -> user.getString("phonenumber"))
                 .filter(s -> s != null && s.length() == 11)
                 .collect(Collectors.toList());
-
-        String today = DateUtils.getNowDate("yyyy-MM-dd");
-        Long todayLong = Long.parseLong(today.replaceAll("-", ""));
-        String last30Day = DateUtils.getNowAddDate("yyyy-MM-dd", -30);
-        Long last30DayLong = Long.parseLong(last30Day.substring(0, 10).replaceAll("-", ""));
-        String last90Day = DateUtils.getNowAddDate("yyyy-MM-dd", -60);
-        Long last90DayLong = Long.parseLong(last90Day.substring(0, 10).replaceAll("-", ""));
-
         int unFindCount = 0;
-        List<Map<String, String>> unbindData = reportsPushMapper.unbindData(todayLong, last90DayLong, advertiserIds);
-
         List<Unbind> unbinds = new ArrayList<>();
         List<Map<String, String>> unFindList = new ArrayList<>();
         for (JSONObject user : users) {
@@ -72,7 +71,6 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
         }
         for (Map<String, String> map : unbindData) {
             String advertiserName = map.get("advertiser_name");
-
             boolean sameFlag = false;
             for (Unbind ub : unbinds) {
                 if (same(advertiserName, ub)) {
@@ -83,16 +81,14 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
             }
             if (!sameFlag) {
                 unFindCount++;
-                if (unFindList.size()<20) {
+                if (unFindList.size() < 20) {
                     unFindList.add(map);
                 }
             }
         }
 
         System.out.println(">>>> 未匹配的账户数:" + unFindCount);
-
         String alarm_time = DateUtils.getNowDate("yyyy-MM-dd HH:mm:ss");
-
         String token = null, token2 = null, token3 = null;
         Map<String, String> mobileMap = null;
         try {
@@ -100,24 +96,24 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
             mobileMap = FeishuRobotUtil.getFsUserIds(token, mobiles); //mobile -> userId
             token2 = FeishuRobotUtil.getTenantToken(FeishuRobotUtil.getFsAdlb2Auth());
             token3 = FeishuRobotUtil.getTenantToken(FeishuRobotUtil.getFsAdlb3Auth());
-        }catch (IOException e){
+        } catch (IOException e) {
             log.error("获取飞书token失败", e);
-            if (token == null || mobileMap == null){
+            if (token == null || mobileMap == null) {
                 return;
             }
         }
-        for (Unbind ub : unbinds){
+        for (Unbind ub : unbinds) {
             String userId = mobileMap.get(ub.getPhoneNumber());
-            if (!Check.isNull(userId) && ub.getUnbindNum() > 0){
+            if (!Check.isNull(userId) && ub.getUnbindNum() > 0) {
                 JSONObject template_variable = new JSONObject();
                 template_variable.put("unbindNum", ub.getUnbindNum());
                 template_variable.put("alarm_time", alarm_time);
                 JSONArray object_list_1 = new JSONArray();
-                for (Map<String, String> map : ub.getTop10List()){
+                for (Map<String, String> map : ub.getTop10List()) {
                     JSONObject object = new JSONObject();
                     object.put("advertiserName", map.get("advertiser_name"));
                     object.put("advertiserId", String.valueOf(map.get("advertiser_id")));
-                    object.put("todayCost", String.valueOf(map.getOrDefault("today_cost", "0")));
+                    //object.put("todayCost", String.valueOf(map.getOrDefault("today_cost", "0")));
                     object.put("last30Cost", String.valueOf(map.getOrDefault("last_30_cost", "0")));
                     object_list_1.add(object);
                 }
@@ -125,7 +121,7 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
 
                 JSONObject content = 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_variable", template_variable);
                 content.put("type", "template");
@@ -136,7 +132,7 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
 //                request.put("receive_id", "44fbaed6");
                 request.put("msg_type", "interactive");
                 request.put("content", content.toJSONString());
-                System.out.println("发送给: "+ub.getName());
+                System.out.println("发送给: " + ub.getName());
                 sendToFeishu(token, request);
 
 //                //todo 临时加的
@@ -152,16 +148,16 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
         }
 
         //给指定人员抄送
-        if (copySend){
+        if (copySend) {
             JSONObject template_variable = new JSONObject();
             template_variable.put("unbindNum", unbindData.size());
             template_variable.put("alarm_time", alarm_time);
             JSONArray object_list_1 = new JSONArray();
-            for (Map<String, String> map : unbindData.subList(0, Math.min(10, unbindData.size()))){
+            for (Map<String, String> map : unbindData.subList(0, Math.min(10, unbindData.size()))) {
                 JSONObject object = new JSONObject();
                 object.put("advertiserName", map.get("advertiser_name"));
                 object.put("advertiserId", String.valueOf(map.get("advertiser_id")));
-                object.put("todayCost", String.valueOf(map.getOrDefault("today_cost", "0")));
+                //object.put("todayCost", String.valueOf(map.getOrDefault("today_cost", "0")));
                 object.put("last30Cost", String.valueOf(map.getOrDefault("last_30_cost", "0")));
                 object_list_1.add(object);
             }
@@ -169,7 +165,7 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
 
             JSONObject content = 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_variable", template_variable);
             content.put("type", "template");
@@ -177,44 +173,44 @@ public class UnbindWarnPushServiceImpl implements IUnbindWarnPushService {
 
             List<String> userIds = Arrays.asList(
                     "44fbaed6" //zhaotx
-                    ,"c5f6b59d" //yuyang
-                    ,"d834552b" //hemenghao
-                    ,"a3235a61" //louzijun
-                    ,"ebeeced9" //yumeng
-                    ,"58e7a98a"  //xsq
+                    , "c5f6b59d" //yuyang
+                    , "d834552b" //hemenghao
+                    , "a3235a61" //louzijun
+                    , "ebeeced9" //yumeng
+                    , "58e7a98a"  //xsq
+                    , "43gb7fbc"  //hpk
             );
 
-            for (String userId : userIds){
+            for (String userId : userIds) {
                 JSONObject request = new JSONObject();
                 request.put("receive_id", userId);
                 request.put("msg_type", "interactive");
                 request.put("content", content.toJSONString());
-                System.out.println("发送给: "+userId);
+                System.out.println("发送给: " + userId);
                 sendToFeishu(token, request);
             }
         }
 
 
-
     }
 
-    private void sendToFeishu(String token, JSONObject requestBody){
+    private void sendToFeishu(String token, JSONObject requestBody) {
         //发送
-        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.setHeader("Authorization", "Bearer "+token);
+            httpPost.setHeader("Authorization", "Bearer " + token);
             HttpEntity entity = new StringEntity(requestBody.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"));
+            System.out.println("发送结果: " + EntityUtils.toString(respon.getEntity(), "UTF-8"));
         } catch (IOException e) {
             log.error("发送飞书消息失败", e);
         }
     }
 
-    private boolean same(String advertiserName, Unbind ub){
-        if (advertiserName.contains(ub.getName())){
+    private boolean same(String advertiserName, Unbind ub) {
+        if (advertiserName.contains(ub.getName())) {
             return true;
         }
 //        if (!Check.isNull(ub.getRemark())){