yumeng před 2 týdny
rodič
revize
7ae9bb13df

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/BytedanceProjectMapper.java

@@ -34,4 +34,6 @@ public interface BytedanceProjectMapper {
     String getTokenByAccountId(@Param("advertiserId") Long advertiserId);
 
     void addLog(@Param("accountId") Long accountId, @Param("projectId") Long projectId, @Param("projectStatus") String projectStatus);
+
+    List<JSONObject> getLeaderByAccountId(@Param("accountId") Long accountId);
 }

+ 18 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/BytedanceProjectMapper.xml

@@ -182,6 +182,24 @@
         where account_id = #{advertiserId} limit 1
 
     </select>
+    <select id="getLeaderByAccountId" resultType="com.alibaba.fastjson.JSONObject">
+        select t.*
+        from (select wexin_id, corp_id, wexin_name
+              from `jeecg-boot`.ctop_corp_wexin_user
+              where user_id = (select ctop_user_allocation.user_id
+                               from `jeecg-boot`.ctop_user_allocation
+                               where account_id =  #{accountId})
+              union all
+              select wexin_id, corp_id, wexin_name
+              from `jeecg-boot`.ctop_corp_wexin_user
+              where user_id = (select leader_id
+                               from `jeecg-boot`.sys_user
+                               where id = (SELECT ctop_user_allocation.user_id
+                                           FROM `jeecg-boot`.ctop_user_allocation
+                                           WHERE account_id =  #{accountId}
+                  LIMIT 1))) t
+        group by t.wexin_id
+    </select>
 
 
 </mapper>

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IBytedanceProjectService.java

@@ -15,4 +15,6 @@ public interface IBytedanceProjectService {
     String getTokenByAccountId(Long advertiserId);
 
     void getPromotionList(Long accountId, String token, List<Long> ids, Map<Long, JSONObject> projectMap, int page);
+
+    void sendAuthFailure(Long accountId);
 }

+ 26 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/BytedanceProjectServiceImpl.java

@@ -57,6 +57,11 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
         Integer code = resultObject.getInteger("code");
         if (null == code || !code.equals(0)) {
             log.error("获取广告列表接口异常==》accountId:{},message:{},code{}", accountId, resultObject.getString("message"), code);
+            if (code == 40102 && resultObject.getString("message").equals("access_token已过期")) {
+                sendAuthFailure(accountId);
+            }
+
+
             return;
         }
         JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
@@ -88,6 +93,27 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
         Map<Long, JSONObject> projectInfo = getProjectInfo(accountId, token, projectIds, 1);
         this.check(accountId, token, promotionList, projectInfo);
     }
+    @Override
+    public void sendAuthFailure(Long accountId) {
+        String redisKey = "sendAuthFailure_" + accountId;
+        Object o = redisUtil.get(redisKey);
+        if (!Check.isNull(o)) {
+            log.info("此账户已进行授权失效通知,此次通知跳过。accountId:{}", accountId);
+            return;
+        }
+        StringBuilder text = new StringBuilder();
+        text.append("您的账户ID:");
+        text.append(accountId);
+        text.append("<br/>");
+        text.append("当前授权已失效,无法进行预警和拉取投放数据。");
+        text.append("<br/>");
+        text.append("请及时前往有腾重新进行授权!");
+        List<JSONObject> list = projectListMapper.getLeaderByAccountId(accountId);
+        for (JSONObject object : list) {
+            corpWexinUtils.sendMessageByWeChatId(object, text.toString());
+        }
+        redisUtil.set(redisKey, accountId, 12 * 60 * 60);
+    }
 
 
     private void check(Long accountId, String token, List<JSONObject> promotionList, Map<Long, JSONObject> projectInfo) {

+ 4 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedancePushDataController.java

@@ -90,7 +90,9 @@ public class BytedancePushDataController {
     @RequestMapping(value = "/test", method = {RequestMethod.GET, RequestMethod.POST})
     @ResponseBody
     public void test(HttpServletRequest request, @RequestParam(value = "challenge", defaultValue = "0") int challenge, @RequestParam(value = "event", defaultValue = "") String event, @RequestParam(value = "appId", defaultValue = "") String appId) throws IOException {
-        String token = bytedanceProjectService.getTokenByAccountId(1832252227629066L);
+
+        bytedanceProjectService.sendAuthFailure(1847120413784843L);
+       /* String token = bytedanceProjectService.getTokenByAccountId(1832252227629066L);
 
         List<Long> list = new ArrayList<>();
         list.add(7566848606024794138L);
@@ -104,7 +106,7 @@ public class BytedancePushDataController {
             bytedanceProjectService.getPromotionList(1832252227629066L, token, ids, projectMap, 1);
 
         }
-
+*/
     }