huangpingkang 1 год назад
Родитель
Сommit
bfae8ea188

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

@@ -29,7 +29,7 @@ public class ChangDuController {
     public void changDuOrder(@RequestParam(required = false) String distributorId,
     public void changDuOrder(@RequestParam(required = false) String distributorId,
                              @RequestParam(required = false) String startDate,
                              @RequestParam(required = false) String startDate,
                              @RequestParam(required = false) String endDate) {
                              @RequestParam(required = false) String endDate) {
-        List<JSONObject> channelList = promoterReportService.getChannelInfoList();
+        List<JSONObject> channelList = channelService.getChannelInfoList();
         for (JSONObject jsonObject : channelList) {
         for (JSONObject jsonObject : channelList) {
             String channelAccountId = jsonObject.getString("channelAccountId");
             String channelAccountId = jsonObject.getString("channelAccountId");
             if (distributorId != null && !distributorId.equals(channelAccountId)) {
             if (distributorId != null && !distributorId.equals(channelAccountId)) {
@@ -68,5 +68,9 @@ public class ChangDuController {
         }
         }
     }
     }
 
 
+    @GetMapping("/distributorConfig")
+    public void distributorConfig() {
+        channelService.getDistributorConfig();
+    }
 
 
 }
 }

+ 31 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/entity/ChangDuAppDistributor.java

@@ -0,0 +1,31 @@
+package cn.com.ctop.job.bytedance.data.entity;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+
+import java.util.Objects;
+
+@Data
+public class ChangDuAppDistributor {
+    private String appId;
+    private String appName;
+    private String distributorId;
+    @JSONField(name = "nick_name")
+    private String distributorName;
+    private String changduAccountId;
+    private Integer channelType;
+    private String remark;
+    private String apiKey;
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || getClass() != o.getClass()) return false;
+        ChangDuAppDistributor that = (ChangDuAppDistributor) o;
+        return Objects.equals(appId, that.appId) && Objects.equals(distributorId, that.distributorId);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(appId, distributorId);
+    }
+}

+ 0 - 2
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/BytedancePromoterReportMapper.java

@@ -18,8 +18,6 @@ public interface BytedancePromoterReportMapper {
 
 
     void replacePromoterReportDailies(@Param("list") List<BytedancePromoterReportDaily> promoterReportDailies);
     void replacePromoterReportDailies(@Param("list") List<BytedancePromoterReportDaily> promoterReportDailies);
 
 
-    List<JSONObject> getChannelInfoList();
-
     void replaceErrorInfo(BytedanceErrorLog errorInfo);
     void replaceErrorInfo(BytedanceErrorLog errorInfo);
 
 
     List<JSONObject> getListBydate(@Param("date") Integer date);
     List<JSONObject> getListBydate(@Param("date") Integer date);

+ 6 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/ChannelMapper.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.job.bytedance.data.mapper;
 package cn.com.ctop.job.bytedance.data.mapper;
 
 
+import cn.com.ctop.job.bytedance.data.entity.ChangDuAppDistributor;
 import cn.com.ctop.job.bytedance.data.entity.ChangDuOrder;
 import cn.com.ctop.job.bytedance.data.entity.ChangDuOrder;
 import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
 import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
@@ -7,8 +8,10 @@ import org.apache.ibatis.annotations.Param;
 
 
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.Set;
 
 
 public interface ChannelMapper {
 public interface ChannelMapper {
+    List<JSONObject> getChannelInfoList();
     void repalceChannels(@Param("adds") List<ChannelChangdunovelInfo> adds);
     void repalceChannels(@Param("adds") List<ChannelChangdunovelInfo> adds);
     Integer getAppType(@Param("appId") String appId);
     Integer getAppType(@Param("appId") String appId);
     List<String> getOrderIds(@Param("startDate")Integer startDate,
     List<String> getOrderIds(@Param("startDate")Integer startDate,
@@ -20,5 +23,7 @@ public interface ChannelMapper {
     String getMovieName(@Param("movieId") String movieId);
     String getMovieName(@Param("movieId") String movieId);
     void insertOrder(List<ChangDuOrder> changDuOrders);
     void insertOrder(List<ChangDuOrder> changDuOrders);
     List<JSONObject> getChangDuRetryJob();
     List<JSONObject> getChangDuRetryJob();
-
+    List<JSONObject> getDistributorKey();
+    void insertChangduDistributorApp(Set<ChangDuAppDistributor> adds);
+    void insertChangduDistributorConfig(Set<ChangDuAppDistributor> adds);
 }
 }

+ 0 - 7
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/BytedancePromoterReportMapper.xml

@@ -14,13 +14,6 @@
                  LEFT JOIN deepthink.bytedance_auth_list t3 ON t2.admin_advertiser_id = t3.admin_advertiser_id
                  LEFT JOIN deepthink.bytedance_auth_list t3 ON t2.admin_advertiser_id = t3.admin_advertiser_id
     </select>
     </select>
 
 
-    <select id="getChannelInfoList" resultType="com.alibaba.fastjson.JSONObject">
-        select channel_account_id as 'channelAccountId',
-                secret_key         as 'secretKey',
-                channel_app_id as 'channelAppId',
-                channel_app_name as 'channelAppName'
-        from deepthink.channel_account_info
-    </select>
     <select id="getListBydate" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Integer">
     <select id="getListBydate" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Integer">
         SELECT t1.advertiser_id AS 'advertiserId', t3.access_token AS 'accessToken'
         SELECT t1.advertiser_id AS 'advertiserId', t3.access_token AS 'accessToken'
         FROM (SELECT advertiser_id
         FROM (SELECT advertiser_id

+ 42 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/ChannelMapper.xml

@@ -9,6 +9,14 @@
         JOIN deepthink.channel_account_info t2 ON t1.advertiser_id = t2.channel_account_id
         JOIN deepthink.channel_account_info t2 ON t1.advertiser_id = t2.channel_account_id
     </select>
     </select>
 
 
+    <select id="getChannelInfoList" resultType="com.alibaba.fastjson.JSONObject">
+        select channel_account_id as 'channelAccountId',
+                secret_key         as 'secretKey',
+                channel_app_id as 'channelAppId',
+                channel_app_name as 'channelAppName'
+        from deepthink.channel_account_info
+    </select>
+
     <insert id="repalceChannels">
     <insert id="repalceChannels">
         replace into deepthink.channel_changdunovel_info (
         replace into deepthink.channel_changdunovel_info (
         distributor_id,
         distributor_id,
@@ -107,4 +115,38 @@
             </trim>
             </trim>
         </foreach>
         </foreach>
     </insert>
     </insert>
+
+    <select id="getDistributorKey" resultType="com.alibaba.fastjson.JSONObject">
+        select changdu_account_id as 'changduAccountId',
+                max(distributor_id) as 'distributorId', max(api_key) as 'apiKey'
+        from deepthink.changdu_distributor_config c
+                 join deepthink.changdu_account_config a
+                      on c.changdu_account_id = a.account_id
+        group by changdu_account_id
+    </select>
+
+    <insert id="insertChangduDistributorApp">
+        insert ignore into deepthink.changdu_distributor_app (distributor_id,app_id)
+        values
+        <foreach collection="collection" item="item" separator=",">
+            (
+            #{item.distributorId},
+            #{item.appId}
+            )
+        </foreach>
+    </insert>
+    <insert id="insertChangduDistributorConfig">
+        insert ignore into deepthink.changdu_distributor_config
+        (distributor_id,distributor_name,changdu_account_id,channel_type,remark)
+        values
+        <foreach collection="collection" item="item" separator=",">
+            (
+            #{item.distributorId},
+            #{item.distributorName},
+            #{item.changduAccountId},
+            #{item.channelType},
+            #{item.remark}
+            )
+        </foreach>
+    </insert>
 </mapper>
 </mapper>

+ 0 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedancePromoterReportService.java

@@ -12,7 +12,6 @@ public interface IBytedancePromoterReportService {
 
 
     void getBytedancePromoterRetryDailyReport(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page,Integer isSend);
     void getBytedancePromoterRetryDailyReport(Long errorId, Long advertiserId, String accessToken, String startDate, String endDate, Integer page,Integer isSend);
 
 
-    List<JSONObject> getChannelInfoList();
 
 
     void getBytedancePromoterHour(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog);
     void getBytedancePromoterHour(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog);
 
 

+ 4 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IChannelService.java

@@ -10,4 +10,8 @@ public interface IChannelService {
     void getOrderList(String startDt, String endDt, String appId, String appName, String distributorId, String secretKey, Integer isLog, Long errId, Integer isSend);
     void getOrderList(String startDt, String endDt, String appId, String appName, String distributorId, String secretKey, Integer isLog, Long errId, Integer isSend);
 
 
     List<JSONObject> getChangDuRetry();
     List<JSONObject> getChangDuRetry();
+
+    void getDistributorConfig();
+
+    List<JSONObject> getChannelInfoList();
 }
 }

+ 1 - 4
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedancePromoterReportServiceImpl.java

@@ -192,10 +192,7 @@ public class BytedancePromoterReportServiceImpl implements IBytedancePromoterRep
         }
         }
     }
     }
 
 
-    @Override
-    public List<JSONObject> getChannelInfoList() {
-        return promoterReportMapper.getChannelInfoList();
-    }
+
 
 
     @Override
     @Override
     public void getBytedancePromoterHour(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog) {
     public void getBytedancePromoterHour(Long advertiserId, String accessToken, String startDate, String endDate, Integer page, Integer isLog) {

+ 109 - 4
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/ChannelServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.job.bytedance.data.service.impl;
 package cn.com.ctop.job.bytedance.data.service.impl;
 
 
 import cn.com.ctop.job.bytedance.data.entity.BytedanceErrorLog;
 import cn.com.ctop.job.bytedance.data.entity.BytedanceErrorLog;
+import cn.com.ctop.job.bytedance.data.entity.ChangDuAppDistributor;
 import cn.com.ctop.job.bytedance.data.entity.ChangDuOrder;
 import cn.com.ctop.job.bytedance.data.entity.ChangDuOrder;
 import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
 import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
 import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
 import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
@@ -17,9 +18,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 @Service
 @Service
 @Slf4j
 @Slf4j
@@ -88,7 +87,108 @@ public class ChannelServiceImpl implements IChannelService {
             e.printStackTrace();
             e.printStackTrace();
 
 
         }
         }
+    }
 
 
+    @Override
+    public void getDistributorConfig() {
+        try {
+            List<JSONObject> distributorApp = getDistributorApp();
+            Set<ChangDuAppDistributor> adds = new HashSet<>();
+            for (JSONObject appDistributor : distributorApp) {
+                String appId = appDistributor.getString("app_id");
+                String apiKey = appDistributor.getString("api_key");
+                String distributorId = appDistributor.getString("distributor_id");
+                String changduAccountId = appDistributor.getString("changdu_account_id");
+                int thisPageIndex = 0;
+                int pageSize = 50;
+                int totalPageIndex = 0;
+                while (thisPageIndex <= totalPageIndex) {
+                    String url = "https://www.changdunovel.com/novelsale/openapi/wx/get_bound_package_list/v1/";
+                    String ts = String.valueOf(System.currentTimeMillis()).substring(0, 10);
+                    String sign = getSign(distributorId, apiKey, ts);
+                    Map<String, Object> params = new JSONObject();
+                    params.put("distributor_id", distributorId);
+                    params.put("ts", ts);
+                    params.put("sign", sign);
+                    params.put("app_id", appId);
+                    params.put("page_index", thisPageIndex);
+                    params.put("page_size", pageSize);
+                    String s = HttpUtils.httpGet(url, params, null);
+                    JSONObject jsonObject = JSONObject.parseObject(s);
+                    if (!Check.isNull(jsonObject)) {
+                        Integer code = jsonObject.getInteger("code");
+                        if (code == 200) {
+                            int total = jsonObject.getIntValue("total");
+                            totalPageIndex = (int) Math.ceil(total * 1.0 / pageSize) - 1;
+                            JSONArray result = jsonObject.getJSONArray("wx_package_info_open_list");
+                            if (!Check.isNull(result)) {
+                                for (int i = 0; i < result.size(); i++) {
+                                    JSONObject resultJson = result.getJSONObject(i);
+                                    ChangDuAppDistributor distributorConfig = JSONObject.parseObject(resultJson.toJSONString(), ChangDuAppDistributor.class);
+                                    distributorConfig.setChangduAccountId(changduAccountId);
+                                    distributorConfig.setChannelType(3);
+                                    log.info("番茄获取小程序绑定的渠道信息 {}", distributorConfig);
+                                    adds.add(distributorConfig);
+                                }
+                            }
+                        } else {
+                            log.error("番茄获取小程序绑定的渠道信息失败,返回信息:{}", jsonObject);
+                        }
+                    } else {
+                        log.error("番茄获取小程序绑定的渠道信息失败,返回信息为空。");
+                    }
+                    thisPageIndex = thisPageIndex + 1;
+                }
+            }
+            if (!Check.isNull(adds)) {
+                channelMapper.insertChangduDistributorApp(adds);
+                channelMapper.insertChangduDistributorConfig(adds);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private List<JSONObject> getDistributorApp() {
+        List<JSONObject> appDistributors = new ArrayList<>();
+        try {
+            List<JSONObject> list = channelMapper.getDistributorKey();
+            for (JSONObject didKey : list) {
+                String changduAccountId = didKey.getString("changduAccountId");
+                String distributorId = didKey.getString("distributorId");
+                String apiKey = didKey.getString("apiKey");
+                String url = "https://www.changdunovel.com/novelsale/openapi/package_info/v1/";
+                String ts = String.valueOf(System.currentTimeMillis()).substring(0, 10);
+                String sign = getSign(distributorId, apiKey, ts);
+                Map<String, Object> params = new JSONObject();
+                params.put("distributor_id", distributorId);
+                params.put("ts", ts);
+                params.put("sign", sign);
+                String s = HttpUtils.httpGet(url, params, null);
+                JSONObject jsonObject = JSONObject.parseObject(s);
+                if (!Check.isNull(jsonObject)) {
+                    Integer code = jsonObject.getInteger("code");
+                    if (code == 200) {
+                        JSONArray result = jsonObject.getJSONArray("result");
+                        if (!Check.isNull(result)) {
+                            for (int i = 0; i < result.size(); i++) {
+                                JSONObject resultJson = result.getJSONObject(i);
+                                resultJson.put("changdu_account_id", changduAccountId);
+                                resultJson.put("api_key", apiKey);
+                                log.info("番茄获取账户内快应用/公众号列表 {}", resultJson);
+                                appDistributors.add(resultJson);
+                            }
+                        }
+                    } else {
+                        log.error("番茄获取账户内快应用/公众号列表失败,返回信息:{}", jsonObject);
+                    }
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return appDistributors;
     }
     }
 
 
     @Override
     @Override
@@ -196,7 +296,7 @@ public class ChannelServiceImpl implements IChannelService {
                                     order.setMovieName(channelMapper.getMovieName(order.getMovieId()));
                                     order.setMovieName(channelMapper.getMovieName(order.getMovieId()));
                                     order.setDyingMovieId(dyingMovieId);
                                     order.setDyingMovieId(dyingMovieId);
                                     order.setDyingMovieName(dyingMovieName);
                                     order.setDyingMovieName(dyingMovieName);
-                                    log.info("常读order:[{}]",order);
+                                    log.info("常读order:[{}]", order);
                                     adds.add(order);
                                     adds.add(order);
                                 }
                                 }
                             }
                             }
@@ -235,6 +335,11 @@ public class ChannelServiceImpl implements IChannelService {
         return channelMapper.getChangDuRetryJob();
         return channelMapper.getChangDuRetryJob();
     }
     }
 
 
+    @Override
+    public List<JSONObject> getChannelInfoList() {
+        return channelMapper.getChannelInfoList();
+    }
+
     private static String getSign(String distributorId, String secretKey, String ts) {
     private static String getSign(String distributorId, String secretKey, String ts) {
         return SecureUtil.md5(distributorId + secretKey + ts).toLowerCase();
         return SecureUtil.md5(distributorId + secretKey + ts).toLowerCase();
     }
     }

+ 0 - 33
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedancePromoterReportJob.java

@@ -44,39 +44,6 @@ public class BytedancePromoterReportJob {
     private static ExecutorService productDailyRetrExecutor = Executors.newFixedThreadPool(2);
     private static ExecutorService productDailyRetrExecutor = Executors.newFixedThreadPool(2);
 
 
 
 
-    /**
-     * 番茄数据拉取
-     *
-     * @throws Exception
-     */
-    @XxlJob("getPromoterList")
-    public void getPromoterList() throws Exception {
-        List<JSONObject> channelList = promoterReportService.getChannelInfoList();
-        for (int i = 0; i < channelList.size(); i++) {
-            JSONObject jsonObject = channelList.get(i);
-            String channelAccountId = jsonObject.getString("channelAccountId");
-            String secretKey = jsonObject.getString("secretKey");
-            String startDate = DateUtils.getNowAddDate("yyyy-MM-dd", -1);
-            String endDate = DateUtils.getNowDate("yyyy-MM-dd");
-            channelService.getPromotionIdList(startDate, endDate, channelAccountId, secretKey, 0);
-        }
-    }
-
-    @XxlJob("changDuOrder")
-    public void changDuOrder() throws Exception {
-        List<JSONObject> channelList = promoterReportService.getChannelInfoList();
-        for (int i = 0; i < channelList.size(); i++) {
-            JSONObject jsonObject = channelList.get(i);
-            String channelAccountId = jsonObject.getString("channelAccountId");
-            String secretKey = jsonObject.getString("secretKey");
-            String appId = jsonObject.getString("channelAppId");
-            String appName = jsonObject.getString("channelAppName");
-            String date = DateUtils.getNowAddDate("yyyy-MM-dd", -1);
-            channelService.getOrderList(date, date, appId, appName, channelAccountId, secretKey, 1, null, null);
-        }
-    }
-
-
     @XxlJob("yesHourPromoterReport")
     @XxlJob("yesHourPromoterReport")
     public void yesHourPromoterReport() throws Exception {
     public void yesHourPromoterReport() throws Exception {
         String param = XxlJobHelper.getJobParam(); // 执行参数
         String param = XxlJobHelper.getJobParam(); // 执行参数

+ 58 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ChangDuJob.java

@@ -0,0 +1,58 @@
+package cn.com.ctop.job.bytedance.handler;
+
+
+import cn.com.ctop.job.bytedance.data.service.IBytedancePromoterReportService;
+import cn.com.ctop.job.bytedance.data.service.IChannelService;
+import cn.com.ctop.job.bytedance.data.utils.DateUtils;
+import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Slf4j
+@Component
+public class ChangDuJob {
+    @Autowired
+    private IBytedancePromoterReportService promoterReportService;
+    @Autowired
+    private IChannelService channelService;
+
+    /**
+     * 番茄数据拉取
+     */
+    @XxlJob("getPromoterList")
+    public void getPromoterList() throws Exception {
+        List<JSONObject> channelList = channelService.getChannelInfoList();
+        for (int i = 0; i < channelList.size(); i++) {
+            JSONObject jsonObject = channelList.get(i);
+            String channelAccountId = jsonObject.getString("channelAccountId");
+            String secretKey = jsonObject.getString("secretKey");
+            String startDate = DateUtils.getNowAddDate("yyyy-MM-dd", -1);
+            String endDate = DateUtils.getNowDate("yyyy-MM-dd");
+            channelService.getPromotionIdList(startDate, endDate, channelAccountId, secretKey, 0);
+        }
+    }
+
+    @XxlJob("changDuOrder")
+    public void changDuOrder() throws Exception {
+        List<JSONObject> channelList = channelService.getChannelInfoList();
+        for (int i = 0; i < channelList.size(); i++) {
+            JSONObject jsonObject = channelList.get(i);
+            String channelAccountId = jsonObject.getString("channelAccountId");
+            String secretKey = jsonObject.getString("secretKey");
+            String appId = jsonObject.getString("channelAppId");
+            String appName = jsonObject.getString("channelAppName");
+            String date = DateUtils.getNowAddDate("yyyy-MM-dd", -1);
+            channelService.getOrderList(date, date, appId, appName, channelAccountId, secretKey, 1, null, null);
+        }
+    }
+
+    @XxlJob("distributorConfig")
+    public void distributorConfig() {
+        channelService.getDistributorConfig();
+    }
+
+}