Browse Source

违规广告 入库+发微信消息

zhaoxian 1 year ago
parent
commit
3020643f87
20 changed files with 405 additions and 20 deletions
  1. 2 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/MailLogMapper.java
  2. 2 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java
  3. 3 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/WexinConfigMapper.java
  4. 25 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/MailLogMapper.xml
  5. 12 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml
  6. 5 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/WexinConfigMapper.xml
  7. 2 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java
  8. 4 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/ISendMessageService.java
  9. 2 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java
  10. 4 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IWexinConfigService.java
  11. 17 3
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java
  12. 20 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/SendMessageServiceImpl.java
  13. 5 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java
  14. 7 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/WexinConfigServiceImpl.java
  15. 87 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/utils/CorpIllegalWexinUtils.java
  16. 39 15
      jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceVideoInfoController.java
  17. 5 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/ByteDanceVideoInfoMapper.java
  18. 44 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/xml/ByteDanceVideoInfoMapper.xml
  19. 4 0
      jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceVideoInfoService.java
  20. 116 2
      jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceVideoInfoServiceImpl.java

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

@@ -29,4 +29,6 @@ public interface MailLogMapper extends BaseMapper<MailLog> {
     JSONObject getWeChatByMail(@Param("mail") String mail);
 
     List<JSONObject> getWChatIdByAccountId(@Param("accountId") Long accountId);
+
+    List<JSONObject> getIllegalWChatId(@Param("accountId") Long accountId, @Param("userId") String userId);
 }

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

@@ -79,4 +79,6 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     JSONObject getProductInfo(@Param("accountId") Long accountId);
 
     List<JSONObject> getAccountInfoByProjectId(@Param("projectId") Long projectId);
+
+    JSONObject getAccountInfoByAccountId(@Param("accountId") Long accountId);
 }

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

@@ -3,6 +3,8 @@ package cn.com.ctop.common.module.mapper;
 import cn.com.ctop.common.module.entity.WexinConfig;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import java.util.List;
+
 /**
  * 企业微信配置信息
  *
@@ -12,4 +14,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface WexinConfigMapper extends BaseMapper<WexinConfig> {
 
+    List<WexinConfig> getIllegalWexinConfig();
 }

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

@@ -74,6 +74,31 @@
 
     </select>
 
+
+    <select id="getIllegalWChatId" resultType="com.alibaba.fastjson.JSONObject">
+        select t.*
+        from (
+                 select wexin_name,wexin_id, corp_id
+                 from ctop_corp_wexin_user
+                 where user_id = (select ctop_user_allocation.user_id
+                                  from ctop_user_allocation
+                                  where account_id = #{accountId} limit 1)
+        union all
+        select wexin_name,wexin_id, corp_id
+        from ctop_corp_wexin_user
+        where user_id = (select leader_id
+                         from sys_user
+                         where id = (SELECT ctop_user_allocation.user_id
+                                     FROM ctop_user_allocation
+                                     WHERE account_id = #{accountId}
+            LIMIT 1))
+        union all
+        select wexin_name,wexin_id, corp_id
+        from ctop_corp_wexin_user
+        where user_id = #{userId})  t
+        group by t.wexin_id
+    </select>
+
     <select id="getUserNameByUserId" resultType="java.lang.String">
     select
     realname

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

@@ -374,5 +374,17 @@ ORDER BY
         AND t1.account_status = 0
     </select>
 
+    <select id="getAccountInfoByAccountId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.user_id,
+               t1.account_id as 'accountId',
+               t1.auth_name as 'accountName',
+               t1.project_id as 'projectId',
+               t2.project_name as 'projectName'
+        FROM ctop_user_allocation t1
+                 LEFT JOIN ctop_project t2 ON t1.project_id = t2.id
+        WHERE t1.account_id = #{accountId}
+          AND t1.account_status = 0
+    </select>
+
 
 </mapper>

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

@@ -2,4 +2,9 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.common.module.mapper.WexinConfigMapper">
 
+    <select id="getIllegalWexinConfig" resultType="cn.com.ctop.common.module.entity.WexinConfig">
+        SELECT *
+        FROM ctop_illegal_wexin_config
+    </select>
+
 </mapper>

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

@@ -106,4 +106,6 @@ public interface IMessageTemplate {
     String getFinancePaymentApplicationCWRechargeRefuseMessage(JSONObject data);
 
     String getFinancePaymentApplicationMJRechargeRefuseMessage(JSONObject data);
+
+    String getIllegalADInfo(JSONObject data);
 }

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

@@ -1,7 +1,11 @@
 package cn.com.ctop.common.module.service;
 
+import com.alibaba.fastjson.JSONObject;
+
 public interface ISendMessageService {
     void sendMessage(String id, String text);
 
     void sendMessageByAccountId(Long accountId, String text);
+
+    void illegalSendMessage(JSONObject info);
 }

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

@@ -80,4 +80,6 @@ public interface IUserAllocationService extends IService<UserAllocation> {
     JSONObject getProductInfo(Long accountId);
 
     List<JSONObject> getAccountInfoByProjectId(Long projectId);
+
+    JSONObject getAccountInfoByAccountId(Long advertiserId);
 }

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

@@ -3,6 +3,8 @@ package cn.com.ctop.common.module.service;
 import cn.com.ctop.common.module.entity.WexinConfig;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * 企业微信配置信息
  *
@@ -13,4 +15,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IWexinConfigService extends IService<WexinConfig> {
 
     WexinConfig getInfoByCorpId(String corpId);
+
+    List<WexinConfig> getIllegalWexinConfig();
 }

+ 17 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java

@@ -289,7 +289,7 @@ public class MessageTemplateImpl implements IMessageTemplate {
 //                .append("类型:").append("1".equals(data.getString("rechargeType")) ? "充值" : "自运营充值").append("<br/>")
                 .append("充值现金金额:").append(data.getBigDecimal("totalAmount")).append("<br/>")
                 .append("充值账显金额:").append(data.getBigDecimal("displayAmount")).append("<br/>")
-                .append("是否后补:").append("1".equals(data.getString("amends"))?"是":"否").append("<br/>")
+                .append("是否后补:").append("1".equals(data.getString("amends")) ? "是" : "否").append("<br/>")
                 .append("请及时登录有腾助手平台进行审核");
         return text.toString();
     }
@@ -335,7 +335,7 @@ public class MessageTemplateImpl implements IMessageTemplate {
                 .append("账户ID:").append(data.getString("accountIds")).append("<br/>")
                 .append("充值现金金额:").append(data.getBigDecimal("totalAmount")).append("<br/>")
                 .append("充值账显金额:").append(data.getBigDecimal("displayAmount")).append("<br/>")
-                .append("是否后补:").append("1".equals(data.getString("amends"))?"是":"否").append("<br/>")
+                .append("是否后补:").append("1".equals(data.getString("amends")) ? "是" : "否").append("<br/>")
                 .append("请及时登录有腾助手平台进行充值");
         return text.toString();
     }
@@ -367,7 +367,7 @@ public class MessageTemplateImpl implements IMessageTemplate {
                 .append("账户ID:").append(data.getString("accountIds")).append("<br/>")
                 .append("充值现金金额:").append(data.getBigDecimal("totalAmount")).append("<br/>")
                 .append("充值账显金额:").append(data.getBigDecimal("displayAmount")).append("<br/>")
-                .append("是否后补:").append("1".equals(data.getString("amends"))?"是":"否").append("<br/>")
+                .append("是否后补:").append("1".equals(data.getString("amends")) ? "是" : "否").append("<br/>")
                 .append("已充值完成");
         return text.toString();
     }
@@ -397,5 +397,19 @@ public class MessageTemplateImpl implements IMessageTemplate {
         return text.toString();
     }
 
+    @Override
+    public String getIllegalADInfo(JSONObject data) {
+        StringBuilder text = new StringBuilder();
+        text.append("违规广告通知").append("<br/>")
+                .append("项目:").append(data.getString("projectName")).append("<br/>")
+                .append("运营:").append(data.getString("userName")).append("<br/>")
+                .append("账户ID:").append(data.getString("accountId")).append("<br/>")
+                .append("素材ID:").append(data.getString("materialId")).append("<br/>")
+                .append("计划ID:").append(data.getString("promotionId")).append("<br/>")
+                .append("违规原因:").append(data.getString("riskContent")).append("<br/>")
+                .append("请及时查看并做相应处理!");
+        return text.toString();
+    }
+
 
 }

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

@@ -3,12 +3,17 @@ package cn.com.ctop.common.module.service.impl;
 import cn.com.ctop.common.module.mapper.MailLogMapper;
 import cn.com.ctop.common.module.service.ISendMessageService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.CorpIllegalWexinUtils;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import lombok.val;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Slf4j
@@ -18,6 +23,8 @@ public class SendMessageServiceImpl implements ISendMessageService {
     private MailLogMapper mailLogMapper;
     @Autowired
     private CorpWexinUtils corpWexinUtils;
+    @Autowired
+    private CorpIllegalWexinUtils illegalWexinUtils;
 
     @Override
     public void sendMessage(String userId, String text) {
@@ -35,4 +42,17 @@ public class SendMessageServiceImpl implements ISendMessageService {
             corpWexinUtils.sendMessageByWeChatId(jsonObject, text);
         }
     }
+
+    @Override
+    public void illegalSendMessage(JSONObject info) {
+        Long accountId = info.getLong("accountId");
+        String userId = info.getString("userId");
+        String text = info.getString("sendContent");
+        List<JSONObject> list = mailLogMapper.getIllegalWChatId(accountId, userId);
+        ArrayList<Object> collect = CollectionUtils.collect(list, row -> row.getString("wexin_name"), new ArrayList<>());
+        for (JSONObject jsonObject : list) {
+            illegalWexinUtils.sendMessageByWeChatId(jsonObject, text);
+        }
+        info.put("userIds", StringUtils.join(collect.iterator(), ","));
+    }
 }

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

@@ -355,5 +355,10 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
         return userAllocationMapper.getAccountInfoByProjectId(projectId);
     }
 
+    @Override
+    public JSONObject getAccountInfoByAccountId(Long advertiserId) {
+        return userAllocationMapper.getAccountInfoByAccountId(advertiserId);
+    }
+
 
 }

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

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 企业微信配置信息
  *
@@ -25,4 +27,9 @@ public class WexinConfigServiceImpl extends ServiceImpl<WexinConfigMapper, Wexin
         queryWrapper.last("limit 1");
         return this.getOne(queryWrapper);
     }
+
+    @Override
+    public List<WexinConfig> getIllegalWexinConfig() {
+        return baseMapper.getIllegalWexinConfig();
+    }
 }

+ 87 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/utils/CorpIllegalWexinUtils.java

@@ -0,0 +1,87 @@
+package cn.com.ctop.common.module.utils;
+
+import cn.com.ctop.common.module.entity.WexinConfig;
+import cn.com.ctop.common.module.service.IWexinConfigService;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import lombok.val;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
+import me.chanjar.weixin.cp.bean.WxCpMessage;
+import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class CorpIllegalWexinUtils {
+    @Autowired
+    private IWexinConfigService wexinConfigService;
+    private static Map<String, WexinConfig> configMap = new HashMap<>();
+
+    private Map<String, WexinConfig> getConfigMap() {
+        List<WexinConfig> list = wexinConfigService.getIllegalWexinConfig();
+        for (WexinConfig config : list) {
+            WxCpService wxCpService = new WxCpServiceImpl();
+            val configStorage = new WxCpDefaultConfigImpl();
+            configStorage.setCorpId(config.getCorpId());
+            configStorage.setAgentId(config.getAgentId());
+            configStorage.setCorpSecret(config.getCorpSecret());
+            configStorage.setToken(config.getToken());
+            configStorage.setAesKey(config.getAesKey());
+            wxCpService.setWxCpConfigStorage(configStorage);
+            config.setWxCpService(wxCpService);
+            configMap.put(config.getCorpId(), config);
+        }
+        return configMap;
+    }
+
+    public void sendMessage(List<JSONObject> wxUserList, String content) {
+        if (Check.isNullMap(configMap)) {
+            getConfigMap();
+        }
+        if (wxUserList != null && wxUserList.size() > 0) {
+            for (JSONObject userInfo : wxUserList) {
+                try {
+                    WxCpMessage message = new WxCpMessage();
+                    WexinConfig config = configMap.get(userInfo.getString("corp_id"));
+                    message.setAgentId(config.getAgentId());
+                    message.setMsgType("text");
+                    message.setContent(content);
+                    message.setToUser(userInfo.getString("wexin_id"));
+                    WxCpService wxCpService = config.getWxCpService();
+                    wxCpService.messageSend(message);
+                } catch (WxErrorException e) {
+                    log.error("发送信息失败,userId:{}", userInfo.getString("wexin_id"));
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    public void sendMessageByWeChatId(JSONObject weChatInfo, String content) {
+        if (Check.isNullMap(configMap)) {
+            this.getConfigMap();
+        }
+        if (!Check.isNull(weChatInfo)) {
+            try {
+                WxCpMessage message = new WxCpMessage();
+                WexinConfig config = configMap.get(weChatInfo.getString("corp_id"));
+                message.setAgentId(config.getAgentId());
+                message.setMsgType("text");
+                message.setContent(content);
+                message.setToUser(weChatInfo.getString("wexin_id"));
+                WxCpService wxCpService = config.getWxCpService();
+                wxCpService.messageSend(message);
+            } catch (WxErrorException e) {
+                log.error("发送信息失败,userId:{}", weChatInfo.getString("wexin_id"));
+                e.printStackTrace();
+            }
+        }
+    }
+}

+ 39 - 15
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceVideoInfoController.java

@@ -1,10 +1,12 @@
 package cn.com.ctop.toutiao.modules.material.controller;
 
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.toutiao.modules.material.entity.ByteDanceVideoInfo;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceVideoInfoService;
 import cn.com.ctop.toutiao.modules.tool.callback.AuthTokenUtil;
 import cn.com.ctop.toutiao.modules.tool.callback.BaseResponse;
 import cn.com.ctop.toutiao.modules.tool.callback.CallbackResponse;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -184,24 +186,46 @@ public class ByteDanceVideoInfoController {
     public CallbackResponse illegalVideosPush(HttpServletRequest request,
                                               @RequestParam(value = "challenge", defaultValue = "0") int challenge,
                                               @RequestParam(value = "event", defaultValue = "") String event) throws IOException {
-        log.info("广告违规素材推送--------------------------challenge= " + challenge + ";event= " + event);
-        // 处理 verify 事件
-        if (null != event && event.equals("verify_webhook")) {
-            return new CallbackResponse(BaseResponse.ok(), challenge);
-        }
+        try {
+            log.info("广告违规素材推送--------------------------challenge= " + challenge + ";event= " + event);
+            // 处理 verify 事件
+            if (null != event && event.equals("verify_webhook")) {
+                return new CallbackResponse(BaseResponse.ok(), challenge);
+            }
 
-        // 订阅任务配置页面的 "验证密钥"
-        String secretKey = "156a5d76ad354b43865ef57e5e416ca7";
-        // 数据接收,验证消息
-        AuthTokenUtil.InputStreamCacher cacher = new AuthTokenUtil.InputStreamCacher(request.getInputStream());
-        boolean isValidToken = AuthTokenUtil.isValidToken(secretKey, cacher, request.getHeader("X-Open-Signature"));
-        log.info("isValidToken=" + isValidToken);
-        if (!isValidToken) {
-            return new CallbackResponse(new BaseResponse(400, "invalid token"), 0);
+            // 订阅任务配置页面的 "验证密钥"
+            String secretKey = "156a5d76ad354b43865ef57e5e416ca7";
+            // 数据接收,验证消息
+            AuthTokenUtil.InputStreamCacher cacher = new AuthTokenUtil.InputStreamCacher(request.getInputStream());
+            boolean isValidToken = AuthTokenUtil.isValidToken(secretKey, cacher, request.getHeader("X-Open-Signature"));
+            log.info("isValidToken=" + isValidToken);
+            if (!isValidToken) {
+                return new CallbackResponse(new BaseResponse(400, "invalid token"), 0);
+            }
+            JSONObject result = JSONObject.parseObject(new String(AuthTokenUtil.readAsBytes(cacher)));
+            log.info("结果:" + result);
+            if (!Check.isNull(result)) {
+                JSONObject content = result.getJSONObject("data").getJSONObject("content");
+                if (!Check.isNull(content)) {
+                    Long agentId = content.getLong("agent_id");
+                    JSONArray illegalMaterialIds = content.getJSONArray("illegal_material_ids");//违规素材集合
+                    Long promotionId = content.getLong("promotion_id");//计划id
+                    byteDanceVideoInfoService.getIllegalVideosPushInfo(agentId, illegalMaterialIds, promotionId);
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
         }
-        JSONObject result = JSONObject.parseObject(new String(AuthTokenUtil.readAsBytes(cacher)));
-        System.out.println("返回结果:" + result.toJSONString());
         // 数据处理流程...
         return new CallbackResponse(BaseResponse.ok(), 0);
     }
+
+
+    /**
+     * 获取广告违规素材详情
+     */
+    @RequestMapping(value = "/getIllegalVideosPushInfo")
+    public void getIllegalVideosPushInfo(Long agentId,@RequestBody JSONArray illegalMaterialIds, Long promotionId) {
+        byteDanceVideoInfoService.getIllegalVideosPushInfo(agentId, illegalMaterialIds, promotionId);
+    }
 }

+ 5 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/ByteDanceVideoInfoMapper.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.toutiao.modules.material.mapper;
 
 import cn.com.ctop.toutiao.modules.material.entity.ByteDanceVideoInfo;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -15,4 +16,8 @@ import java.util.List;
 public interface ByteDanceVideoInfoMapper extends BaseMapper<ByteDanceVideoInfo> {
 
     void replaceBatch(@Param(value = "videoList") List<ByteDanceVideoInfo> videoInfoList);
+
+    void replaceBatchIllegalBytedanceMaterialInfo(@Param(value = "list") List<JSONObject> list);
+
+    void insertIllegalBytedanceSendRecord(@Param(value = "info") JSONObject info);
 }

+ 44 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/xml/ByteDanceVideoInfoMapper.xml

@@ -55,4 +55,48 @@
             )
         </foreach>
     </insert>
+
+    <insert id="replaceBatchIllegalBytedanceMaterialInfo">
+        replace into illegal_bytedance_material_info(
+        material_id,
+        project_id,
+        project_name,
+        account_id,
+        account_name,
+        promotion_id,
+        risk_content
+        )
+        values
+        <foreach collection="list" item="info" separator=",">
+            (
+            #{info.materialId},
+            #{info.projectId},
+            #{info.projectName},
+            #{info.accountId},
+            #{info.accountName},
+            #{info.promotionId},
+            #{info.riskContent}
+            )
+        </foreach>
+    </insert>
+
+    <insert id="insertIllegalBytedanceSendRecord">
+        insert into illegal_bytedance_send_record(
+        material_id,
+        project_id,
+        account_id,
+        promotion_id,
+        user_ids,
+        send_content
+        )
+        values
+            (
+            #{info.materialId},
+            #{info.projectId},
+            #{info.accountId},
+            #{info.promotionId},
+            #{info.userIds},
+            #{info.sendContent}
+            )
+    </insert>
 </mapper>

+ 4 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceVideoInfoService.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.toutiao.modules.material.service;
 
 import cn.com.ctop.toutiao.modules.material.entity.ByteDanceVideoInfo;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
@@ -16,4 +17,7 @@ public interface IByteDanceVideoInfoService extends IService<ByteDanceVideoInfo>
     void replaceBatch(List<ByteDanceVideoInfo> videoInfoList);
 
     ByteDanceVideoInfo getOneByParams(Long materialId);
+
+    void getIllegalVideosPushInfo(Long agentId, JSONArray illegalMaterialIds,Long promotionId);
+
 }

+ 116 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceVideoInfoServiceImpl.java

@@ -1,16 +1,28 @@
 package cn.com.ctop.toutiao.modules.material.service.impl;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IMessageTemplate;
+import cn.com.ctop.common.module.service.ISendMessageService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.toutiao.modules.material.entity.ByteDanceVideoInfo;
 import cn.com.ctop.toutiao.modules.material.mapper.ByteDanceVideoInfoMapper;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceVideoInfoService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 今日头条视频素材信息
@@ -22,6 +34,14 @@ import java.util.List;
 public class ByteDanceVideoInfoServiceImpl extends ServiceImpl<ByteDanceVideoInfoMapper, ByteDanceVideoInfo> implements IByteDanceVideoInfoService {
     @Resource
     private ByteDanceVideoInfoMapper videoInfoMapper;
+    @Autowired
+    IUserAllocationService userAllocationService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    private ISendMessageService sendMessageService;
+    @Autowired
+    private IMessageTemplate messageTemplate;
 
     @Override
     public void replaceBatch(List<ByteDanceVideoInfo> videoInfoList) {
@@ -31,8 +51,102 @@ public class ByteDanceVideoInfoServiceImpl extends ServiceImpl<ByteDanceVideoInf
     @Override
     public ByteDanceVideoInfo getOneByParams(Long materialId) {
         QueryWrapper<ByteDanceVideoInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("material_id",materialId);
+        queryWrapper.eq("material_id", materialId);
         queryWrapper.last("limit 1");
         return this.getOne(queryWrapper);
     }
+
+    @Override
+    public void getIllegalVideosPushInfo(Long agentId, JSONArray illegalMaterialIds, Long promotionId) {
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(73970348172l);
+        String url = "https://api.oceanengine.com/open_api/2/agent/query/risk_promotion_list/";
+        Map<String, Object> param = new HashMap<>();
+        param.put("agent_id", agentId);
+        param.put("business_type", "AD");
+        String today = DateUtils.date2Str();
+        String yesterday = DateUtils.getLastDay(today, 1);
+        param.put("start_date", yesterday);
+        param.put("end_date", today);
+
+        JSONObject filtering = new JSONObject();
+//        JSONArray arr = new JSONArray();
+//        arr.add(7361676756829896740l);
+        filtering.put("illegal_material_ids", illegalMaterialIds);
+        param.put("filtering", filtering);
+
+        Map<String, String> header = new HashMap<>();
+        header.put("Access-Token", token.getAccessToken());
+
+        JSONObject result = JSONObject.parseObject(HttpUtils.httpGet(url, param, header));
+        if (!Check.isNull(result)) {
+            String code = result.getString("code");
+            if ("0".equals(code)) {
+                //违规信息入库
+                storageIllegalInfo(result.getJSONObject("data").getJSONArray("data"), promotionId);
+            } else {
+                log.error("查询违规广告列表失败,原因:" + result.getString("message"));
+            }
+        }
+    }
+
+    //违规信息入库
+    private void storageIllegalInfo(JSONArray array, Long promotionId) {
+        try {
+            JSONObject project = null;
+            List<JSONObject> list = new ArrayList<>();
+            for (int i = 0; i < array.size(); i++) {
+                JSONObject data = array.getJSONObject(i);
+                Long advertiserId = data.getLong("advertiser_id");
+                if (Check.isNull(project)) {
+                    //获取项目消息
+                    project = userAllocationService.getAccountInfoByAccountId(advertiserId);
+                }
+                data.put("projectId", project.getLong("projectId"));
+                data.put("projectName", project.getString("projectName"));
+                data.put("userId", project.getString("user_id"));
+                //计划ID
+                Long promotion_id = data.getLong("promotion_id");
+                //违规素材列表,包含广告下投前+投中拒审的素材信息
+                JSONArray materialList = data.getJSONArray("material_list");
+                for (int j = 0; j < materialList.size(); j++) {
+                    JSONObject materialObj = materialList.getJSONObject(j);
+                    JSONObject info = getmaterialData(data, materialObj);
+                    list.add(info);
+                    if (promotionId.equals(promotion_id)) {
+                        //发送企业微信提醒  obj
+                        sendMsg(info);
+                    }
+                }
+            }
+
+            if (!Check.isNull(list)) {
+                videoInfoMapper.replaceBatchIllegalBytedanceMaterialInfo(list);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    //违规素材列表 数据整理
+    private JSONObject getmaterialData(JSONObject data, JSONObject material) {
+        JSONObject info = new JSONObject();
+        info.put("agentId", data.getLong("agent_id"));
+        info.put("projectId", data.getLong("projectId"));
+        info.put("projectName", data.getString("projectName"));
+        info.put("accountId", data.getLong("advertiser_id"));
+        info.put("accountName", data.getString("advertiser_name"));
+        info.put("promotionId", data.getLong("promotion_id"));
+        info.put("materialId", material.getLong("id"));
+        info.put("riskContent", material.getString("risk_content"));
+        info.put("userId", data.getString("userId"));
+        info.put("userName", data.getString("optimizer_name"));
+        return info;
+    }
+
+    private void sendMsg(JSONObject info) {
+        String text = messageTemplate.getIllegalADInfo(info);
+        info.put("sendContent", text);
+        sendMessageService.illegalSendMessage(info);
+        videoInfoMapper.insertIllegalBytedanceSendRecord(info);
+    }
 }