yumeng 8 月之前
父節點
當前提交
5cb17172a5

+ 11 - 0
pom.xml

@@ -70,6 +70,17 @@
             <artifactId>lombok</artifactId>
             <artifactId>lombok</artifactId>
         </dependency>
         </dependency>
 
 
+        <!--mongodb-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-mongodb</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mongodb</groupId>
+            <artifactId>mongodb-driver-sync</artifactId>
+            <version>4.10.2</version>
+        </dependency>
+
         <!-- mybatis-plus -->
         <!-- mybatis-plus -->
         <dependency>
         <dependency>
             <groupId>com.baomidou</groupId>
             <groupId>com.baomidou</groupId>

+ 60 - 5
src/main/java/cn/com/ctop/track/controller/TrackController.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.track.controller;
 package cn.com.ctop.track.controller;
 
 
+import cn.com.ctop.track.entity.TrackRta;
 import cn.com.ctop.track.service.ClickInfoService;
 import cn.com.ctop.track.service.ClickInfoService;
 import cn.com.ctop.track.service.ConvertInfoService;
 import cn.com.ctop.track.service.ConvertInfoService;
 import cn.com.ctop.track.service.TaobaoNoticeService;
 import cn.com.ctop.track.service.TaobaoNoticeService;
@@ -7,8 +8,13 @@ import cn.com.ctop.track.utils.Check;
 import cn.com.ctop.track.utils.HttpUtils;
 import cn.com.ctop.track.utils.HttpUtils;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 
@@ -35,6 +41,8 @@ public class TrackController {
     static ExecutorService click2ExecutorService = Executors.newFixedThreadPool(15);
     static ExecutorService click2ExecutorService = Executors.newFixedThreadPool(15);
     static ExecutorService back1ExecutorService = Executors.newFixedThreadPool(15);
     static ExecutorService back1ExecutorService = Executors.newFixedThreadPool(15);
     static ExecutorService back2ExecutorService = Executors.newFixedThreadPool(15);
     static ExecutorService back2ExecutorService = Executors.newFixedThreadPool(15);
+    @Autowired
+    private MongoTemplate mongoTemplate;
 
 
     // 老链接 屏蔽5
     // 老链接 屏蔽5
     @RequestMapping(value = "/click1")
     @RequestMapping(value = "/click1")
@@ -128,6 +136,12 @@ public class TrackController {
             String action = "click";    // ⾏为类型 // 点击
             String action = "click";    // ⾏为类型 // 点击
             String imei = request.getParameter("imei");
             String imei = request.getParameter("imei");
             String oaidmd5 = request.getParameter("oaidmd5");
             String oaidmd5 = request.getParameter("oaidmd5");
+            if (Check.isNull(oaidmd5) && Check.isNull(imei)) {
+                returnJson.put("code", 500);
+                returnJson.put("success", false);
+                return returnJson;
+            }
+
             String accountid = request.getParameter("accountid");    //⼴告账户ID
             String accountid = request.getParameter("accountid");    //⼴告账户ID
             String adid = request.getParameter("adid");     //⼴告计划ID
             String adid = request.getParameter("adid");     //⼴告计划ID
             String campaignid = request.getParameter("campaignid");      // ⼴告组ID
             String campaignid = request.getParameter("campaignid");      // ⼴告组ID
@@ -139,12 +153,12 @@ public class TrackController {
             params.put("requestFrom", "huichuang");
             params.put("requestFrom", "huichuang");
             params.put("pid", "2088821582878450");
             params.put("pid", "2088821582878450");
             params.put("partnerId", "tab3huichuangapkhuichuang");
             params.put("partnerId", "tab3huichuangapkhuichuang");
-            if (!Check.isNull(imei)) {
-                params.put("imei", imei);
-            }
             if (!Check.isNull(oaidmd5)) {
             if (!Check.isNull(oaidmd5)) {
                 params.put("oaidmd5", oaidmd5);
                 params.put("oaidmd5", oaidmd5);
+            } else if (!Check.isNull(imei)) {
+                params.put("imei", imei);
             }
             }
+
             if (!Check.isNull(accountid)) {
             if (!Check.isNull(accountid)) {
                 params.put("accountid", accountid);
                 params.put("accountid", accountid);
             }
             }
@@ -157,10 +171,19 @@ public class TrackController {
             if (!Check.isNull(cid)) {
             if (!Check.isNull(cid)) {
                 params.put("cid", cid);
                 params.put("cid", cid);
             }
             }
+
+
             if (!Check.isNull(callback)) {
             if (!Check.isNull(callback)) {
                 String callbackUrl = "https://track.tjyourong.com.cn/convert/back2?kuaishouCallback=" + callback;
                 String callbackUrl = "https://track.tjyourong.com.cn/convert/back2?kuaishouCallback=" + callback;
+                if (!Check.isNull(oaidmd5)) {
+                    callbackUrl += "&id=" + oaidmd5;
+                } else if (!Check.isNull(imei)) {
+                    callbackUrl += "&id=" + imei;
+                }
                 params.put("callback", callbackUrl);
                 params.put("callback", callbackUrl);
             }
             }
+
+
             click2ExecutorService.submit(new Runnable() {
             click2ExecutorService.submit(new Runnable() {
                 @Override
                 @Override
                 public void run() {
                 public void run() {
@@ -190,6 +213,15 @@ public class TrackController {
                                 if (isRtaAccount) {
                                 if (isRtaAccount) {
                                     String s = HttpUtils.httpGetRequest(url, headers, params);
                                     String s = HttpUtils.httpGetRequest(url, headers, params);
                                     logger.info("新沉流快手点击监测上报客户返回结果:" + s);
                                     logger.info("新沉流快手点击监测上报客户返回结果:" + s);
+                                    JSONObject mongoVo = new JSONObject();
+                                    if (!Check.isNull(oaidmd5)) {
+                                        mongoVo.put("_id", oaidmd5);
+                                    } else if (!Check.isNull(imei)) {
+                                        mongoVo.put("_id", imei);
+                                    }
+                                    long timestamp = System.currentTimeMillis() / 1000;
+                                    mongoVo.put("timestamp", timestamp);
+                                    mongoTemplate.save(mongoVo, "trackRta");
                                 } else {
                                 } else {
                                     logger.info("新沉流客户rta返回策略列表未命中:tab3xcl,停止上报数据,返回数据:" + json);
                                     logger.info("新沉流客户rta返回策略列表未命中:tab3xcl,停止上报数据,返回数据:" + json);
                                 }
                                 }
@@ -264,6 +296,7 @@ public class TrackController {
         try {
         try {
             String url = request.getParameter("kuaishouCallback");
             String url = request.getParameter("kuaishouCallback");
             String transformtype = request.getParameter("transformtype");
             String transformtype = request.getParameter("transformtype");
+            String id = request.getParameter("id");
             if ("8".equals(transformtype)) {
             if ("8".equals(transformtype)) {
                 returnJson.put("code", 200);
                 returnJson.put("code", 200);
                 returnJson.put("success", true);
                 returnJson.put("success", true);
@@ -276,8 +309,25 @@ public class TrackController {
                 back2ExecutorService.submit(new Runnable() {
                 back2ExecutorService.submit(new Runnable() {
                     @Override
                     @Override
                     public void run() {
                     public void run() {
-                        String s = HttpUtils.backHttpGetRequest(url, headers, event_type);
-                        logger.info("新沉流回传媒体唤起结果返回结果:" + s);
+
+                        Criteria criteria = new Criteria();
+                        criteria = Criteria.where("_id").is(id);
+                        Query query = new Query(criteria);
+                        TrackRta one = mongoTemplate.findOne(query, TrackRta.class);
+                        if (Check.isNull(one)) {
+                            logger.error("客户回传信息未在mongodb中查到,跳过此回传");
+                            return;
+                        }
+                        Long timestamp = one.getTimestamp();
+                        long nowTamp = System.currentTimeMillis() / 1000;
+                        if (nowTamp - timestamp <= 1800) {
+                            String s = HttpUtils.backHttpGetRequest(url, headers, event_type);
+                            logger.info("新沉流回传媒体唤起结果返回结果:" + s);
+                        } else {
+                            logger.error("客户回传信息超过30分钟时限,跳过此回传,返回id:" + id);
+                        }
+
+
                     }
                     }
                 });
                 });
                 returnJson.put("code", 200);
                 returnJson.put("code", 200);
@@ -292,6 +342,11 @@ public class TrackController {
         return returnJson;
         return returnJson;
     }
     }
 
 
+    public static void main(String[] args) {
+        Long timestamp = 1728625744L;
+        long nowTamp = System.currentTimeMillis() / 1000;
+        System.err.println(nowTamp - timestamp);
+    }
 
 
     /*@ResponseBody
     /*@ResponseBody
     @RequestMapping(value = "/convert")
     @RequestMapping(value = "/convert")

+ 21 - 0
src/main/java/cn/com/ctop/track/entity/TrackRta.java

@@ -0,0 +1,21 @@
+package cn.com.ctop.track.entity;
+
+import lombok.Data;
+
+
+@Data
+public class TrackRta {
+
+    private String _id;
+
+    private Long timestamp;
+
+
+    public TrackRta() {
+    }
+
+    public TrackRta(String id, Long timestamp) {
+        this._id = id;
+        this.timestamp = timestamp;
+    }
+}

+ 34 - 10
src/main/resources/application.yml

@@ -20,8 +20,8 @@ spring:
       max-request-size: -1
       max-request-size: -1
   #json 时间戳统一转换
   #json 时间戳统一转换
   jackson:
   jackson:
-    date-format:   yyyy-MM-dd HH:mm:ss
-    time-zone:   GMT+8
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: GMT+8
   aop:
   aop:
     proxy-target-class: true
     proxy-target-class: true
   #配置freemarker
   #配置freemarker
@@ -46,10 +46,10 @@ spring:
   autoconfigure:
   autoconfigure:
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
   datasource:
   datasource:
-#    name: fendo
-#    url: jdbc:mysql://139.186.27.96:3390/track?characterEncoding=UTF-8&useUnicode=true&allowMultiQueries=true&useSSL=false
-#    username: hcst
-#    password: hcst@2020
+    #    name: fendo
+    #    url: jdbc:mysql://139.186.27.96:3390/track?characterEncoding=UTF-8&useUnicode=true&allowMultiQueries=true&useSSL=false
+    #    username: hcst
+    #    password: hcst@2020
     type: com.alibaba.druid.pool.DruidDataSource
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.jdbc.Driver
     driver-class-name: com.mysql.jdbc.Driver
     dynamic:
     dynamic:
@@ -86,10 +86,33 @@ spring:
           driver-class-name: com.mysql.jdbc.Driver
           driver-class-name: com.mysql.jdbc.Driver
           # 多数据源配置
           # 多数据源配置
           #multi-datasource1:
           #multi-datasource1:
-#          url: jdbc:mysql://139.186.27.96:3390/track?characterEncoding=UTF-8&useUnicode=true&allowMultiQueries=true&useSSL=false
-#          username: hcst
-#          password: hcst@2020
-#          driver-class-name: com.mysql.jdbc.Driver
+  #          url: jdbc:mysql://139.186.27.96:3390/track?characterEncoding=UTF-8&useUnicode=true&allowMultiQueries=true&useSSL=false
+  #          username: hcst
+  #          password: hcst@2020
+  #          driver-class-name: com.mysql.jdbc.Driver
+  # mongodb 配置
+  data:
+    mongodb:
+      #      uri: mongodb://root:hcst2024..@192.168.0.99:27017/admin?authSource=admin&readPreference=primaryPreferred&maxpoolsize=100&minpoolsize=10&maxidletimems=0&maxlifetimems=0&maxconnecting=5&waitqueuetimeoutms=120000
+      host: 172.30.0.5
+      port: 27017
+      #root:只在admin数据库中可用。超级账号,超级权限
+      username: root
+      password: hcst2024..
+      database: admin
+      authentication-database: admin
+      #      maxpoolsize: 100 # 池中允许的最大连接数。一旦池耗尽,任何需要连接的操作都将在阻塞队列中等待直到获取到连接, 默认: 100
+      #      minpoolsize: 10 # 池中允许的最小连接数。这些连接在空闲时将保留在池中,并且池将确保它至少包含这个最小数量 默认: 0
+      #      maxidletimems: 0 # 池连接的最大空闲时间。零值表示对空闲时间没有限制。超过其空闲时间的池连接将被关闭并在必要时由新连接替换。单位为毫秒
+      #      maxlifetimems: 0 # 池连接可以存活的最长时间。零值表示寿命没有限制。超过其生命周期的池连接将被关闭并在必要时由新连接替换。单位为毫秒
+      #      maxconnecting: 5 # 同一时刻允许的最大并行连接数。默认值是: 2。
+      #      waitqueuetimeoutms: 120000 # 阻塞队列中请求的最大等待时间,超过这个时间的请求将被拒绝。单位为毫秒,默认为: 120s
+
+      #从连接池获取连接的最大等待时间(毫秒)
+      max-wait-time: 22000
+
+
+
 #mybatis plus 设置
 #mybatis plus 设置
 mybatis-plus:
 mybatis-plus:
   mapper-locations: classpath*:classpath*:cn/com/ctop/**/xml/*Mapper.xml
   mapper-locations: classpath*:classpath*:cn/com/ctop/**/xml/*Mapper.xml
@@ -110,3 +133,4 @@ logging:
     root: info
     root: info
   config: classpath:logback-dev.xml
   config: classpath:logback-dev.xml
 
 
+