Преглед на файлове

头条-账户流水添加新的数据获取接口new

yangzian преди 2 години
родител
ревизия
bc3e3ac095

+ 28 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/SynchronousAccountTransactionJob.java

@@ -4,12 +4,14 @@ import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
 import cn.com.ctop.toutiao.modules.agent.service.AgentManagementService;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
 
 @Component
 @Slf4j
@@ -42,4 +44,30 @@ public class SynchronousAccountTransactionJob {
         }
 
     }
+
+    /**
+     * 同步头条账户交易流水
+     * 获取前3天数据
+     */
+    @XxlJob("synchronousAccountTransactionNew")
+    public void synchronousAccountTransactionNew() throws Exception {
+
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+
+        String yesterda1 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+        String yesterda2 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -2);
+        String yesterda3 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -3);
+
+        try {
+            agentManagementService.synchronousAccount();
+
+            agentManagementService.synchronousAccountTransactionDayNew(yesterda1,yesterda1,1,1000);
+            agentManagementService.synchronousAccountTransactionDayNew(yesterda2,yesterda2,1,1000);
+            agentManagementService.synchronousAccountTransactionDayNew(yesterda3,yesterda3,1,1000);
+
+        } catch (Exception e) {
+            log.info("同步完成");
+        }
+
+    }
 }

+ 1 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/mapper/CtopAccountTransactionDayMapper.java

@@ -13,5 +13,6 @@ public interface CtopAccountTransactionDayMapper {
     void deleteAccountTransactionById( @Param("id") String id);
 
     void saveAccountTransactionDay(@Param("list") List<TransactionDay> list, @Param("date") String date);
+    void replaceAccountTransactionDay(@Param("list") List<TransactionDay> list);
 
 }

+ 22 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/mapper/xml/CtopAccountTransactionDayMapper.xml

@@ -18,7 +18,28 @@
             #{item.sharedWalletCost},
             #{item.transferIn},
             #{item.transferOut},
-            #{date}
+            NOW()
+            )
+        </foreach>
+    </insert>
+ <!-- 批量插入新增数据-->
+    <insert id="replaceAccountTransactionDay">
+        REPLACE into ctop_account_transaction_day (advertiser_id,date,balance,cash_cost,cost,frozen,income,reward_cost,
+        shared_wallet_cost,transfer_in,transfer_out,create_time) values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (
+            #{item.advertiserId},
+            #{item.date},
+            #{item.balance},
+            #{item.cashCost},
+            #{item.cost},
+            #{item.frozen},
+            #{item.income},
+            #{item.rewardCost},
+            #{item.sharedWalletCost},
+            #{item.transferIn},
+            #{item.transferOut},
+            NOW()
             )
         </foreach>
     </insert>

+ 1 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/service/AgentManagementService.java

@@ -25,4 +25,5 @@ public interface AgentManagementService {
 
     //同步账户日流水
     public Result synchronousAccountTransactionDay(String startDate, String endDate);
+    public void synchronousAccountTransactionDayNew(String startDate, String endDate,int pageNum, int pageSize);
 }

+ 57 - 3
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/service/impl/AgentManagementServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.toutiao.modules.agent.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.toutiao.modules.agent.entity.TransactionDay;
 import cn.com.ctop.toutiao.modules.agent.entity.TransactionDetails;
 import cn.com.ctop.toutiao.modules.agent.mapper.CtopAccountTransactionDayMapper;
@@ -8,7 +9,9 @@ import cn.com.ctop.toutiao.modules.agent.mapper.CtopAccountTransactionDetailsMap
 import cn.com.ctop.toutiao.modules.agent.mapper.CtopAgentAccountMapper;
 import cn.com.ctop.toutiao.modules.agent.service.AgentManagementService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import javafx.beans.binding.When;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -268,9 +271,9 @@ public class AgentManagementServiceImpl implements AgentManagementService {
         ca.add(Calendar.DATE, -1);
 
         try {
-//            List<String> accountIdList = ctopAgentAccountMapper.getAllAccountId();
-            List<String> accountIdList = new ArrayList<>();
-            accountIdList.add("1744115510360071");
+            List<String> accountIdList = ctopAgentAccountMapper.getAllAccountId();
+//            List<String> accountIdList = new ArrayList<>();
+            //accountIdList.add("1744115510360071");
             if (!accountIdList.isEmpty()) {
                 accountIdList.stream().forEach(str -> {
                     List<TransactionDay> transactionDetailsList = new ArrayList<>();
@@ -353,6 +356,57 @@ public class AgentManagementServiceImpl implements AgentManagementService {
 
 
         return result;
+    } /**
+     * 同步账户日流水
+     *
+     * @author zzy
+     * @create: 2021-07-15
+     */
+    @Override
+    public void synchronousAccountTransactionDayNew(String startDate, String endDate,int page, int pageSize) {
+
+        List<TransactionDay> list = new ArrayList<>();
+        List<String> accountIdList = ctopAgentAccountMapper.getAllAccountId();
+
+//        List<String> accountIdList = new ArrayList<>();
+//        accountIdList.add("1735775204994062");
+//        accountIdList.add("1744114166675533");
+//        accountIdList.add("1744114166069261");
+
+        for (String accountId : accountIdList) {
+            log.info("同步头条账户流水信息{}:开始时间{},结束时间{},第{}页" ,accountId,startDate,endDate,page);
+            JSONObject jsonObject = queryAccountTransactionDay(accountId, 1, 1000, startDate, endDate);
+            JSONObject data = null;
+            int code = 1;
+            if (jsonObject != null) {
+                data = (JSONObject) jsonObject.get("data");
+                code = (int) jsonObject.get("code");
+            } else {
+                log.info("返回数据jsonObject为null:");
+                continue;
+            }
+            if (code != 0) {
+                log.info("返回数据:" + jsonObject.toJSONString() + ":" + accountId);
+                continue;
+            }
+            if (data != null) {
+                List<Object> dataList = (List<Object>) data.get("list");
+                if (dataList != null && !dataList.isEmpty()) {
+                    dataList.stream().forEach(ob -> {
+                        TransactionDay transactionDay = JSONObject.toJavaObject((JSON) ob, TransactionDay.class);
+                        list.add(transactionDay);
+                    });
+                }
+            }
+            ctopAccountTransactionDayMapper.replaceAccountTransactionDay(list);
+
+            page++;
+            int totalPage = jsonObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
+            if (page <= totalPage) {
+                synchronousAccountTransactionDayNew(startDate, endDate, page, 1000);
+            }
+        }
+
     }
 
     /**