Bläddra i källkod

第三方监测链接预警

yangzian 3 år sedan
förälder
incheckning
aa9a60a790
13 ändrade filer med 478 tillägg och 0 borttagningar
  1. 4 0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  2. 39 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/MonitorBytedanceActionTrackUrlMapper.java
  3. 48 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/xml/MonitorBytedanceActionTrackUrlMapper.xml
  4. 15 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/IMonitorBytedanceService.java
  5. 71 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/MonitorBytedanceServiceImpl.java
  6. 23 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/vo/MonitorBytedanceAdVo.java
  7. 86 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/entity/WexinConfig.java
  8. 15 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/WexinConfigMapper.java
  9. 5 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/xml/WexinConfigMapper.xml
  10. 16 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/IWexinConfigService.java
  11. 28 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/impl/WexinConfigServiceImpl.java
  12. 91 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/utils/CorpWexinUtils.java
  13. 37 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/bytedance/advertise/controller/BytedancePlanJobController.java

+ 4 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -146,6 +146,10 @@ public class ShiroConfig {
 
         filterChainDefinitionMap.put("/advertiser/bytedanceReportController/updateADCpaBid","anon");//
 
+        filterChainDefinitionMap.put("/ad/bytedancePlanJobController/**","anon");
+
+
+
         //性能监控  TODO 存在安全漏洞泄露TOEKN(durid连接池也有)
         filterChainDefinitionMap.put("/actuator/**", "anon");
 

+ 39 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/MonitorBytedanceActionTrackUrlMapper.java

@@ -0,0 +1,39 @@
+package org.jeecg.modules.bytedance.advertise.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.bytedance.advertise.vo.MonitorBytedanceAdVo;
+
+import java.util.List;
+
+/**
+ * 头条 监测预警
+ * @author: zian Y
+ * @date:   2021-12-28
+ * @cersion: V1.0
+ */
+public interface MonitorBytedanceActionTrackUrlMapper {
+
+
+    /**
+     * 获取头条自动配置中的账户 以及 点击监测链接
+     * @return
+     */
+    List<MonitorBytedanceAdVo> getBytedancStrategyAcctionId();
+
+    /**
+     * 根据账户id 查询该账户下的计划中的 点击监测链接
+     * @param accountId
+     * @return
+     */
+    List<MonitorBytedanceAdVo> getBytedancPlanActionTrackUrl(Long accountId);
+
+
+    /**
+     * 获取用户微信id
+     * @param responsibleId
+     * @return
+     */
+    JSONObject getWChatIdByUserId(@Param("userId") String responsibleId);
+
+}

+ 48 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/xml/MonitorBytedanceActionTrackUrlMapper.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.bytedance.advertise.mapper.MonitorBytedanceActionTrackUrlMapper">
+
+
+<!-- 获取头条自动配置中的账户 以及 点击监测链接-->
+    <select id="getBytedancStrategyAcctionId" resultType="org.jeecg.modules.bytedance.advertise.vo.MonitorBytedanceAdVo">
+        SELECT
+            stra.account_id accountId,
+            stra.creative_action_track_url actionTrackUrl,
+            ua.auth_name accountName,
+            ua.user_id operateUserid,
+            ua.user_name operateUserName
+        FROM
+            ctop_ai_bytedance_advertiser_strategy stra
+                LEFT JOIN ctop_user_allocation ua on stra.account_id = ua.account_id
+        WHERE
+            stra.status = 0
+        ORDER BY
+            stra.create_time DESC
+    </select>
+
+
+    <!-- 根据账户id 查询该账户下的计划中的 点击监测链接 -->
+    <select id="getBytedancPlanActionTrackUrl" resultType="org.jeecg.modules.bytedance.advertise.vo.MonitorBytedanceAdVo">
+        SELECT
+            DISTINCT
+            action_track_url actionTrackUrl
+        FROM
+            ctop_bytedance_advertise_plan
+        WHERE
+            account_id = #{accountId}
+          and DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
+    </select>
+
+
+    <!-- 获取用户微信id -->
+    <select id="getWChatIdByUserId" resultType="com.alibaba.fastjson.JSONObject">
+        select t1.wexin_id,corp_id
+        from ctop_corp_wexin_user t1
+                 left join  sys_user t2
+                            on  t1.user_id = t2.id
+        where  t1.user_id = #{userId}
+          and t2.`status` = 1
+
+    </select>
+
+</mapper>

+ 15 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/IMonitorBytedanceService.java

@@ -0,0 +1,15 @@
+package org.jeecg.modules.bytedance.advertise.service;
+
+import org.jeecg.common.api.vo.Result;
+
+/**
+ * @Description: 规则账户清洗数据
+ * @Author: jeecg-boot
+ * @Date: 2020-11-16
+ * @Version: V1.0
+ */
+public interface IMonitorBytedanceService{
+
+
+    Result monitorBytedanceActionTrackUrl();
+}

+ 71 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/MonitorBytedanceServiceImpl.java

@@ -0,0 +1,71 @@
+package org.jeecg.modules.bytedance.advertise.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.bytedance.advertise.mapper.MonitorBytedanceActionTrackUrlMapper;
+import org.jeecg.modules.bytedance.advertise.service.IMonitorBytedanceService;
+import org.jeecg.modules.bytedance.advertise.vo.MonitorBytedanceAdVo;
+import org.jeecg.modules.bytedance.common.utils.Check;
+import org.jeecg.modules.bytedance.common.utils.CorpWexinUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.text.MessageFormat;
+import java.util.List;
+
+/**
+ * 规则账户清洗数据
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-16
+ */
+@Service
+public class MonitorBytedanceServiceImpl implements IMonitorBytedanceService {
+    @Resource
+    private MonitorBytedanceActionTrackUrlMapper monitorBytedanceActionTrackUrlMapper;
+
+    @Resource
+    private CorpWexinUtils corpWexinUtils;
+
+    /**
+     * @description: 监测预警-点击监测链接
+     * @param
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2021/12/28
+     */
+    public Result monitorBytedanceActionTrackUrl(){
+        //查询 头条自动投放配置 中的账户 和 点击监测链接
+        List<MonitorBytedanceAdVo> accountList = monitorBytedanceActionTrackUrlMapper.getBytedancStrategyAcctionId();
+        accountList.forEach(accountInfo ->{
+            //根据账户 查询头条计划中的 点击监测链接
+            List<MonitorBytedanceAdVo> actionTrackUrlList = monitorBytedanceActionTrackUrlMapper.getBytedancPlanActionTrackUrl(accountInfo.getAccountId());
+            if (!Check.isNull(actionTrackUrlList)){
+                for (MonitorBytedanceAdVo actiontrackUrl : actionTrackUrlList) {
+                    //账户配置中的 点击监测链接 != 创建计划中的 点击监测链接
+                    if (!StringUtils.equals(accountInfo.getActionTrackUrl(),actiontrackUrl.getActionTrackUrl())){
+                        //发送预警消息
+                        sendEnterpriseWeiXinMessage(accountInfo);
+                        break;
+                    }
+                }
+            }
+        });
+        return Result.successMsg("成功。",null);
+    }
+    /**
+     * 发送 点击监测链接 预警消息
+     */
+    public void sendEnterpriseWeiXinMessage(MonitorBytedanceAdVo accountInfo){
+        String message =  "{0},您好!您的账户:{1},账户ID:{2},点击监测链接配置有差异,请及时检查账户配置!";
+        //发送微信通知
+        JSONObject jsonObject =  monitorBytedanceActionTrackUrlMapper.getWChatIdByUserId("80e747cdea6f41dbbc8cde23046fd4e0");
+        String msg = MessageFormat.format(message,accountInfo.getOperateUserName(),accountInfo.getAccountName(),String.valueOf(accountInfo.getAccountId()));
+        corpWexinUtils.sendMessageByWeChatId(jsonObject,msg);
+    }
+
+
+
+}

+ 23 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/vo/MonitorBytedanceAdVo.java

@@ -0,0 +1,23 @@
+package org.jeecg.modules.bytedance.advertise.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author zianY
+ * 头条广告计划--预警
+ */
+@Data
+public class MonitorBytedanceAdVo implements Serializable {
+    //账户id
+    private long accountId;
+    //点击监测链接
+    private String actionTrackUrl;
+    //账户名称
+    private String accountName;
+    //运营人员id
+    private String operateUserid;
+    //运营人员名称
+    private String operateUserName;
+}

+ 86 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/entity/WexinConfig.java

@@ -0,0 +1,86 @@
+package org.jeecg.modules.bytedance.common.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import me.chanjar.weixin.cp.api.WxCpService;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 企业微信配置信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-06-17
+ */
+@Data
+@TableName("ctop_wexin_config")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_wexin_config对象", description = "企业微信配置信息")
+public class WexinConfig {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.UUID)
+    @ApiModelProperty(value = "id")
+    private Integer id;
+    /**
+     * corpId
+     */
+    @Excel(name = "corpId", width = 15)
+    @ApiModelProperty(value = "corpId")
+    private String corpId;
+    /**
+     * agentId
+     */
+    @Excel(name = "agentId", width = 15)
+    @ApiModelProperty(value = "agentId")
+    private Integer agentId;
+    /**
+     * corpSecret
+     */
+    @Excel(name = "corpSecret", width = 15)
+    @ApiModelProperty(value = "corpSecret")
+    private String corpSecret;
+    /**
+     * aesKey
+     */
+    @Excel(name = "aesKey", width = 15)
+    @ApiModelProperty(value = "aesKey")
+    private String aesKey;
+    /**
+     * token
+     */
+    @Excel(name = "token", width = 15)
+    @ApiModelProperty(value = "token")
+    private String token;
+    /**
+     * remarks
+     */
+    @Excel(name = "remarks", width = 15)
+    @ApiModelProperty(value = "remarks")
+    private String remarks;
+    /**
+     * createTime
+     */
+    @ApiModelProperty(value = "createTime")
+    private Date createTime;
+    /**
+     * updateTime
+     */
+    @ApiModelProperty(value = "updateTime")
+    private Date updateTime;
+
+    @TableField(exist = false)
+    private WxCpService wxCpService;
+}

+ 15 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/WexinConfigMapper.java

@@ -0,0 +1,15 @@
+package org.jeecg.modules.bytedance.common.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.bytedance.common.entity.WexinConfig;
+
+/**
+ * 企业微信配置信息
+ *
+ * @author jeecg-boot
+ * 2021-06-17
+ * @version V1.0
+ */
+public interface WexinConfigMapper extends BaseMapper<WexinConfig> {
+
+}

+ 5 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/xml/WexinConfigMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.bytedance.common.entity.WexinConfig">
+
+</mapper>

+ 16 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/IWexinConfigService.java

@@ -0,0 +1,16 @@
+package org.jeecg.modules.bytedance.common.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.bytedance.common.entity.WexinConfig;
+
+/**
+ * 企业微信配置信息
+ *
+ * @author jeecg-boot
+ * 2021-06-17
+ * @version V1.0
+ */
+public interface IWexinConfigService extends IService<WexinConfig> {
+
+    WexinConfig getInfoByCorpId(String corpId);
+}

+ 28 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/impl/WexinConfigServiceImpl.java

@@ -0,0 +1,28 @@
+package org.jeecg.modules.bytedance.common.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.modules.bytedance.common.entity.WexinConfig;
+import org.jeecg.modules.bytedance.common.mapper.WexinConfigMapper;
+import org.jeecg.modules.bytedance.common.service.IWexinConfigService;
+import org.springframework.stereotype.Service;
+
+/**
+ * 企业微信配置信息
+ *
+ * @author jeecg-boot
+ * 2021-06-17
+ * @version V1.0
+ */
+@Service
+public class WexinConfigServiceImpl extends ServiceImpl<WexinConfigMapper, WexinConfig> implements IWexinConfigService {
+
+    @Override
+    public WexinConfig getInfoByCorpId(String corpId) {
+        QueryWrapper<WexinConfig> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("corp_id", corpId);
+        queryWrapper.orderByDesc("create_time");
+        queryWrapper.last("limit 1");
+        return this.getOne(queryWrapper);
+    }
+}

+ 91 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/utils/CorpWexinUtils.java

@@ -0,0 +1,91 @@
+package org.jeecg.modules.bytedance.common.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+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.jeecg.modules.bytedance.common.entity.WexinConfig;
+import org.jeecg.modules.bytedance.common.service.IWexinConfigService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class CorpWexinUtils {
+    @Resource
+    private IWexinConfigService wexinConfigService;
+
+    private static Map<String, WexinConfig> configMap = new HashMap<>();
+
+    private Map<String, WexinConfig> getConfigMap() {
+        QueryWrapper<WexinConfig> queryWrapper = new QueryWrapper<>();
+        queryWrapper.orderByDesc("create_time");
+        List<WexinConfig> list = wexinConfigService.list(queryWrapper);
+        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) {
+                WxCpMessage message = new WxCpMessage();
+                message.setMsgType("text");
+                message.setContent(content);
+                message.setAgentId(1000002);
+                message.setToUser(userInfo.getString("wexin_id"));
+                try {
+                    WexinConfig config = configMap.get(userInfo.getString("corp_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)) {
+            WxCpMessage message = new WxCpMessage();
+            message.setMsgType("text");
+            message.setContent(content);
+            message.setAgentId(1000002);
+            message.setToUser(weChatInfo.getString("wexin_id"));
+            try {
+                WexinConfig config = configMap.get(weChatInfo.getString("corp_id"));
+                WxCpService wxCpService = config.getWxCpService();
+                wxCpService.messageSend(message);
+            } catch (WxErrorException e) {
+                log.error("发送信息失败,userId:{}", weChatInfo.getString("wexin_id"));
+                e.printStackTrace();
+            }
+        }
+    }
+}

+ 37 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/bytedance/advertise/controller/BytedancePlanJobController.java

@@ -0,0 +1,37 @@
+package org.jeecg.modules.bytedance.advertise.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.bytedance.advertise.service.IMonitorBytedanceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 头条定时任务
+ * @author zian Y
+ * @date   2021-12-28
+ * @version V1.0
+ */
+@RestController
+@RequestMapping("/ad/bytedancePlanJobController")
+@Api(tags="头条定时任务")
+@Slf4j
+public class BytedancePlanJobController {
+
+	@Autowired
+	private IMonitorBytedanceService monitorBytedanceService;
+
+
+	@ApiOperation(value = "监测预警-点击监测链接", notes = "监测预警-点击监测链接")
+	@GetMapping(value = "/monitorBytedanceActionTrackUrl")
+	public Result monitorBytedanceActionTrackUrl() {
+		return monitorBytedanceService.monitorBytedanceActionTrackUrl();
+	}
+
+
+
+}