Kaynağa Gözat

账户交易流水

zhouzeyu@c-top.com.cn 3 yıl önce
ebeveyn
işleme
f136da2da3

+ 45 - 8
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/controller/AgentManagementController.java

@@ -1,17 +1,15 @@
 package cn.com.ctop.toutiao.modules.agent.controller;
 
+
 import cn.com.ctop.toutiao.modules.agent.service.AgentManagementService;
-import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.annotations.Param;
 import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.ArrayList;
-
-import java.util.List;
-import java.util.stream.Collectors;
+import java.text.ParseException;
 
 @RestController
 @RequestMapping("/agent")
@@ -21,10 +19,49 @@ public class AgentManagementController {
     @Autowired
     AgentManagementService agentManagementService;
 
+
     @RequestMapping("/queryAccountTransactionDetails")
-    public void  getList(){
-        Result recharge = agentManagementService.synchronousAccountTransactionDetails();
-        log.info("123");
+    public void getList(@Param("starDate") String startDate, @Param("endDate") String endDate) {
+        Result recharge = agentManagementService.synchronousAccountTransactionDetails(startDate, endDate);
 
     }
+
+    @RequestMapping("/synchronousAccount")
+    public void synchronousAccount() {
+        Result recharge = agentManagementService.synchronousAccount();
+    }
+
+
+    @RequestMapping("/synchronousAccountTransactionDay")
+    public void synchronousAccountTransactionDay(@Param("starDate") String startDate, @Param("endDate") String endDate) {
+        Result recharge = agentManagementService.synchronousAccountTransactionDay(startDate, endDate);
+    }
+
+
+    @RequestMapping("/synchronous")
+    public void synchronous() throws ParseException {
+        String date1 = "2021-05-01";
+        String date2 = "2021-05-31";
+        String date3 = "2021-06-01";
+        String date4 = "2021-06-30";
+        String date5 = "2021-07-01";
+        String date6 = "2021-07-31";
+        String date7 = "2021-08-01";
+        String date8 = "2021-08-31";
+        agentManagementService.synchronousAccount();
+        //5月份
+        agentManagementService.synchronousAccountTransactionDetails(date1, date2);
+        agentManagementService.synchronousAccountTransactionDay(date1, date2);
+        //6月份
+        agentManagementService.synchronousAccountTransactionDetails(date3, date4);
+        agentManagementService.synchronousAccountTransactionDay(date3, date4);
+        //7月份
+        agentManagementService.synchronousAccountTransactionDetails(date5, date6);
+        agentManagementService.synchronousAccountTransactionDay(date5, date6);
+        //8月份
+        agentManagementService.synchronousAccountTransactionDetails(date7, date8);
+        agentManagementService.synchronousAccountTransactionDay(date7, date8);
+    }
+
+
 }

+ 33 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/entity/TransactionDay.java

@@ -0,0 +1,33 @@
+package cn.com.ctop.toutiao.modules.agent.entity;
+
+import lombok.Data;
+
+@Data
+public class TransactionDay {
+    //
+    private String id;
+    //广告主ID
+    private String advertiserId;
+    //日期
+    private String date;
+    //日终结余(单位元)
+    private String balance;
+    //现金支出(单位元)
+    private String cashCost;
+    //总支出(单位元)
+    private String cost;
+    //冻结(单位元)
+    private String frozen;
+    //总存入(单位元)
+    private String income;
+    //赠款支出(单位元)
+    private String rewardCost;
+    //共享钱包支出(单位元)
+    private String sharedWalletCost;
+    //总转入(单位元)
+    private String transferIn;
+    //总转出(单位元)
+    private String transferOut;
+    //创建时间
+    private String createTime;
+}

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

@@ -0,0 +1,16 @@
+package cn.com.ctop.toutiao.modules.agent.mapper;
+
+import cn.com.ctop.toutiao.modules.agent.entity.TransactionDay;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface CtopAccountTransactionDayMapper {
+
+    List<String> getAdvertiserIdByDate(@Param("date") String date, @Param("advertiserId") String advertiserId);
+
+    void saveAccountTransactionDay(@Param("list") List<TransactionDay> list, @Param("date") String date);
+
+}

+ 3 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/mapper/CtopAccountTransactionDetailsMapper.java

@@ -9,7 +9,8 @@ import java.util.List;
 @Mapper
 public interface CtopAccountTransactionDetailsMapper {
     //保存交易记录
-    public void saveAccountTransactionDetails(@Param("list") List<TransactionDetails> list, @Param("date")String date);
+    public void saveAccountTransactionDetails(@Param("list") List<TransactionDetails> list, @Param("date") String date);
+
     //根据日期查询当日所有交易订单号
-    public List<String> getTransactionSeq( @Param("date")String date);
+    public List<String> getTransactionSeq(@Param("date") String date);
 }

+ 13 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/mapper/CtopAgentAccountMapper.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.toutiao.modules.agent.mapper;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -9,8 +10,18 @@ import java.util.List;
 public interface CtopAgentAccountMapper {
     //获取所有账户
     public List<String> getAllAccountId();
+
     //根据账户id修改账户状态
-    public void updateAccountState(@Param("list")List<String> list,@Param("state")int state);
+    public void updateAccountState(@Param("list") List<String> list, @Param("state") int state);
+
     //批量插入新增数据
-    public void insertAccountData(@Param("list") List<String> list,@Param("agent_id")String agent_id,@Param("create_time")String create_time);
+    public void insertAccountData(@Param("list") List<String> list, @Param("agent_id") String agent_id, @Param("create_time") String create_time);
+
+    /**
+     * 根据accountId查询
+     *
+     * @param accountId
+     * @return
+     */
+    CtopOauthToken selectByAccountId(Long accountId);
 }

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

@@ -0,0 +1,30 @@
+<?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="cn.com.ctop.toutiao.modules.agent.mapper.CtopAccountTransactionDayMapper">
+    <!-- 批量插入新增数据-->
+    <insert id="saveAccountTransactionDay">
+        insert 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},
+            #{date}
+            )
+        </foreach>
+    </insert>
+
+    <select id="getAdvertiserIdByDate" parameterType="String" resultType="String">
+        select t.advertiser_id from ctop_account_transaction_day t where t.date=#{date} and t.advertiser_id=#{advertiserId}
+    </select>
+
+</mapper>

+ 4 - 3
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/mapper/xml/CtopAccountTransactionDetailsMapper.xml

@@ -1,9 +1,10 @@
 <?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="cn.com.ctop.toutiao.modules.agent.mapper.CtopAccountTransactionDetailsMapper">
-   <!-- 批量插入新增数据-->
+    <!-- 批量插入新增数据-->
     <insert id="saveAccountTransactionDetails">
-        insert  into ctop_account_transaction_details (advertiser_id,transaction_type,data_time,amount,cash,grant_amount,return_goods,transaction_seq,
+        insert into ctop_account_transaction_details
+        (advertiser_id,transaction_type,data_time,amount,cash,grant_amount,return_goods,transaction_seq,
         remitter,payee,dealbase,create_time) values
         <foreach collection="list" item="item" index="index" separator=",">
             (
@@ -24,7 +25,7 @@
     </insert>
 
     <select id="getTransactionSeq" parameterType="String" resultType="String">
-        select t.transaction_seq from ctop_account_transaction_details t where t.create_time=#{date}
+        select t.transaction_seq from ctop_account_transaction_details t
     </select>
 
 </mapper>

+ 31 - 4
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/mapper/xml/CtopAgentAccountMapper.xml

@@ -1,20 +1,38 @@
 <?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="cn.com.ctop.toutiao.modules.agent.mapper.CtopAgentAccountMapper">
+    <resultMap id="BaseResultMap" type="cn.com.ctop.common.module.entity.CtopOauthToken">
+        <result column="id" property="id" jdbcType="BIGINT"/>
+        <result column="media_id" property="mediaId" jdbcType="VARCHAR"/>
+        <result column="advertiser_id" property="advertiserId" jdbcType="VARCHAR"/>
+        <result column="account_id" property="accountId" jdbcType="BIGINT"/>
+        <result column="access_token" property="accessToken" jdbcType="VARCHAR"/>
+        <result column="refresh_token" property="refreshToken" jdbcType="VARCHAR"/>
+        <result column="access_token_expires_in" property="accessTokenExpiresIn" jdbcType="TIMESTAMP"/>
+        <result column="refresh_token_expires_in" property="refreshTokenExpiresIn" jdbcType="TIMESTAMP"/>
+        <result column="agent_type" property="agentType" jdbcType="INTEGER"/>
+        <result column="app_id" property="appId" jdbcType="BIGINT"/>
+        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
+        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,media_id,advertiser_id,account_id,access_token,refresh_token,access_token_expires_in,refresh_token_expires_in,agent_type,app_id,create_time,update_time
+   </sql>
     <!--获取所有账户-->
     <select id="getAllAccountId" resultType="String">
         select account_id from ctop_agent_account where state=0
     </select>
-   <!-- 根据账户id修改账户状态-->
+    <!-- 根据账户id修改账户状态-->
     <update id="updateAccountState">
         update ctop_agent_account set state=#{state} where account_id in
-        <foreach item="item" index="index" collection="list" open="("  close=")" separator=",">
+        <foreach item="item" index="index" collection="list" open="(" close=")" separator=",">
             #{item}
         </foreach>
     </update>
-   <!-- 批量插入新增数据-->
+    <!-- 批量插入新增数据-->
     <insert id="insertAccountData">
-        insert  into ctop_agent_account (account_id,agent_id,state,create_time) values
+        insert into ctop_agent_account (account_id,agent_id,state,create_time) values
         <foreach collection="list" item="item" index="index" separator=",">
             (
             #{item},
@@ -25,4 +43,13 @@
         </foreach>
     </insert>
 
+    <select id="selectByAccountId" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from ctop_oauth_token
+        where account_id = #{accountId}
+        order by create_time desc
+        limit 1
+    </select>
+
 </mapper>

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

@@ -8,15 +8,21 @@ public interface AgentManagementService {
     public String getToken();
 
     //查询代理商下账户
-    public  JSONObject selectAgentAdvertiser(int pageNum,int pageSize);
+    public  JSONObject selectAgentAdvertiser(int pageNum, int pageSize);
 
 
     //查询账号流水
-    public JSONObject queryAccountTransactionDetails(String AccountId,String transaction_type, int pageNum, int pageSize);
+    public JSONObject queryAccountTransactionDetails(String AccountId, String transaction_type, int pageNum, int pageSize, String startDate, String endDate);
+
+    //查询账号流水
+    public JSONObject queryAccountTransactionDay(String AccountId, int pageNum, int pageSize, String startDate, String endDate);
 
     //同步代理商账户入库
     public Result synchronousAccount();
 
     //同步账户交易流水
-    public Result synchronousAccountTransactionDetails();
+    public Result synchronousAccountTransactionDetails(String startDate, String endDate);
+
+    //同步账户日流水
+    public Result synchronousAccountTransactionDay(String startDate, String endDate);
 }

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

@@ -1,8 +1,9 @@
 package cn.com.ctop.toutiao.modules.agent.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
+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;
 import cn.com.ctop.toutiao.modules.agent.mapper.CtopAccountTransactionDetailsMapper;
 import cn.com.ctop.toutiao.modules.agent.mapper.CtopAgentAccountMapper;
 import cn.com.ctop.toutiao.modules.agent.service.AgentManagementService;
@@ -42,17 +43,19 @@ public class AgentManagementServiceImpl implements AgentManagementService {
     private final String OPEN_API_URL_PREFIX = "https://ad.oceanengine.com/open_api/2/";
     private final String ACCOUNT_LIST_URL = "agent/advertiser/select/";
     private final String ACCOUNT_TRANSACTION_DETAILS_URL = "advertiser/fund/transaction/get/";
+    private final String ACCOUNT_TRANSACTION_DAY_URL = "advertiser/fund/daily_stat/";
     private final String ADVERTISER_ID = "73970348172";
     private final String RECHARGE = "RECHARGE";
     private final String TRANSFER = "TRANSFER";
-    @Resource
-    CtopOauthTokenMapper ctopOauthTokenMapper;
 
     @Resource
     CtopAgentAccountMapper ctopAgentAccountMapper;
     @Resource
     CtopAccountTransactionDetailsMapper ctopAccountTransactionDetailsMapper;
 
+    @Resource
+    CtopAccountTransactionDayMapper ctopAccountTransactionDayMapper;
+
     /**
      * 同步代理商下账号
      *
@@ -121,8 +124,9 @@ public class AgentManagementServiceImpl implements AgentManagementService {
      * @create: 2021-07-15
      */
     @Override
-    public Result synchronousAccountTransactionDetails() {
+    public Result synchronousAccountTransactionDetails(String startDate, String endDate) {
         log.info("开始同步账号交易流水");
+        Result result = new Result();
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
         List<TransactionDetails> transactionDetailsList = new ArrayList<>();
         try {
@@ -132,70 +136,88 @@ public class AgentManagementServiceImpl implements AgentManagementService {
                 accountIdList.stream().forEach(str -> {
                     if (!str.isEmpty()) {
                         //查询账号下充值的交易流水
-                        JSONObject jsonObject = queryAccountTransactionDetails(str, RECHARGE, 1, 1000);
+                        JSONObject jsonObject = queryAccountTransactionDetails(str, RECHARGE, 1, 1000, startDate, endDate);
+                        int code = (int) jsonObject.get("code");
+                        if (code != 0) {
+                            result.setMessage((String) jsonObject.get("message"));
+                            log.info((String) jsonObject.get("message"));
+                            return;
+                        }
                         JSONObject data = (JSONObject) jsonObject.get("data");
-                        List<Object> dataList = (List<Object>) data.get("list");
-                        if (!dataList.isEmpty()) {
-                            //充值类存在记录
-                            //保存第一页数据
-                            dataList.stream().forEach(ob -> {
-                                TransactionDetails transactionDetails = JSONObject.toJavaObject((JSON) ob, TransactionDetails.class);
-                                //订单号不存在
-                                if (transactionSeqList.isEmpty() || !transactionSeqList.contains(transactionDetails.getTransaction_seq())) {
-                                    transactionDetailsList.add(transactionDetails);
-                                }
+                        if (data != null) {
+                            List<Object> dataList = (List<Object>) data.get("list");
+                            if (dataList != null && !dataList.isEmpty()) {
+                                //充值类存在记录
+                                //保存第一页数据
+                                dataList.stream().forEach(ob -> {
+                                    TransactionDetails transactionDetails = JSONObject.toJavaObject((JSON) ob, TransactionDetails.class);
+                                    //订单号不存在
+                                    if (transactionSeqList.isEmpty() || !transactionSeqList.contains(transactionDetails.getTransaction_seq())) {
+                                        transactionDetailsList.add(transactionDetails);
+                                    }
 
-                            });
-                            JSONObject page_info = (JSONObject) data.get("page_info");
-                            int total_page = (int) page_info.get("total_page");
-                            //查询其他页数据
-                            if (total_page > 1) {
-                                for (int i = 2; i <= total_page; i++) {
-                                    JSONObject jo = queryAccountTransactionDetails(str, RECHARGE, i, 1000);
-                                    JSONObject accountData = (JSONObject) jo.get("data");
-                                    List<Object> rechargeList = (List<Object>) accountData.get("list");
-                                    rechargeList.stream().forEach(transactionDetails -> {
-                                        TransactionDetails transactionDetailsOther = JSONObject.toJavaObject((JSON) transactionDetails, TransactionDetails.class);
-                                        //订单号不存在
-                                        if (transactionSeqList.isEmpty() || !transactionSeqList.contains(transactionDetailsOther.getTransaction_seq())) {
-                                            transactionDetailsList.add(transactionDetailsOther);
-                                        }
-                                    });
+                                });
+                                JSONObject page_info = (JSONObject) data.get("page_info");
+                                int total_page = (int) page_info.get("total_page");
+                                //查询其他页数据
+                                if (total_page > 1) {
+                                    for (int i = 2; i <= total_page; i++) {
+                                        JSONObject jo = queryAccountTransactionDetails(str, RECHARGE, i, 1000, startDate, endDate);
+                                        JSONObject accountData = (JSONObject) jo.get("data");
+                                        List<Object> rechargeList = (List<Object>) accountData.get("list");
+                                        rechargeList.stream().forEach(transactionDetails -> {
+                                            TransactionDetails transactionDetailsOther = JSONObject.toJavaObject((JSON) transactionDetails, TransactionDetails.class);
+                                            //订单号不存在
+                                            if (transactionSeqList.isEmpty() || !transactionSeqList.contains(transactionDetailsOther.getTransaction_seq())) {
+                                                transactionDetailsList.add(transactionDetailsOther);
+                                            }
+                                        });
+                                    }
                                 }
                             }
                         }
+
                         //查询账号下转账的交易流水
-                        JSONObject transferJsonObject = queryAccountTransactionDetails(str, TRANSFER, 1, 1000);
+                        JSONObject transferJsonObject = queryAccountTransactionDetails(str, TRANSFER, 1, 1000, startDate, endDate);
                         JSONObject transferData = (JSONObject) transferJsonObject.get("data");
-                        List<Object> transferDataList = (List<Object>) transferData.get("list");
-                        if (!transferDataList.isEmpty()) {
-                            //转账类存在记录
-                            //保存第一页数据
-                            transferDataList.stream().forEach(ob -> {
-                                TransactionDetails transactionDetails = JSONObject.toJavaObject((JSON) ob, TransactionDetails.class);
-                                //订单号不存在
-                                if (transactionSeqList.isEmpty() || !transactionSeqList.contains(transactionDetails.getTransaction_seq())) {
-                                    transactionDetailsList.add(transactionDetails);
-                                }
-                            });
-                            JSONObject transferPageInfo = (JSONObject) transferData.get("page_info");
-                            int transferTotalPage = (int) transferPageInfo.get("total_page");
-                            //查询其他页数据
-                            if (transferTotalPage > 1) {
-                                for (int i = 2; i <= transferTotalPage; i++) {
-                                    JSONObject jo = queryAccountTransactionDetails(str, TRANSFER, i, 1000);
-                                    JSONObject accountData = (JSONObject) jo.get("data");
-                                    List<Object> rechargeList = (List<Object>) accountData.get("list");
-                                    rechargeList.stream().forEach(transactionDetails -> {
-                                        TransactionDetails transactionDetailsOther = JSONObject.toJavaObject((JSON) transactionDetails, TransactionDetails.class);
-                                        //订单号不存在
-                                        if (transactionSeqList.isEmpty() || !transactionSeqList.contains(transactionDetailsOther.getTransaction_seq())) {
-                                            transactionDetailsList.add(transactionDetailsOther);
-                                        }
-                                    });
+                        int code1 = (int) jsonObject.get("code");
+                        if (code1 != 0) {
+                            result.setMessage((String) jsonObject.get("message"));
+                            log.info((String) jsonObject.get("message"));
+                            return;
+                        }
+                        if (transferData != null) {
+                            List<Object> transferDataList = (List<Object>) transferData.get("list");
+                            if (!transferDataList.isEmpty()) {
+                                //转账类存在记录
+                                //保存第一页数据
+                                transferDataList.stream().forEach(ob -> {
+                                    TransactionDetails transactionDetails = JSONObject.toJavaObject((JSON) ob, TransactionDetails.class);
+                                    //订单号不存在
+                                    if (transactionSeqList.isEmpty() || !transactionSeqList.contains(transactionDetails.getTransaction_seq())) {
+                                        transactionDetailsList.add(transactionDetails);
+                                    }
+                                });
+                                JSONObject transferPageInfo = (JSONObject) transferData.get("page_info");
+                                int transferTotalPage = (int) transferPageInfo.get("total_page");
+                                //查询其他页数据
+                                if (transferTotalPage > 1) {
+                                    for (int i = 2; i <= transferTotalPage; i++) {
+                                        JSONObject jo = queryAccountTransactionDetails(str, TRANSFER, i, 1000, startDate, endDate);
+                                        JSONObject accountData = (JSONObject) jo.get("data");
+                                        List<Object> rechargeList = (List<Object>) accountData.get("list");
+                                        rechargeList.stream().forEach(transactionDetails -> {
+                                            TransactionDetails transactionDetailsOther = JSONObject.toJavaObject((JSON) transactionDetails, TransactionDetails.class);
+                                            //订单号不存在
+                                            if (transactionSeqList.isEmpty() || !transactionSeqList.contains(transactionDetailsOther.getTransaction_seq())) {
+                                                transactionDetailsList.add(transactionDetailsOther);
+                                            }
+                                        });
+                                    }
                                 }
                             }
                         }
+
                     }
                 });
             }
@@ -204,17 +226,111 @@ public class AgentManagementServiceImpl implements AgentManagementService {
                 ctopAccountTransactionDetailsMapper.saveAccountTransactionDetails(transactionDetailsList, df.format(new Date()));
                 log.info("新增交易记录:{}条", transactionDetailsList.size());
             }
+            result.setSuccess(true);
+            result.setMessage("success");
         } catch (Exception e) {
             e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage("error");
             log.info("同步失败:{}", e.toString());
         }
 
 
-        return null;
+        return result;
+    }
+
+    /**
+     * 同步账户日流水
+     *
+     * @author zzy
+     * @create: 2021-07-15
+     */
+    @Override
+    public Result synchronousAccountTransactionDay(String startDate, String endDate) {
+        log.info("开始同步账号日流水");
+        Result result = new Result();
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
+        Calendar ca = Calendar.getInstance();
+        ca.setTime(new Date());
+        ca.add(Calendar.DATE, -1);
+        List<TransactionDay> transactionDetailsList = new ArrayList<>();
+        try {
+            List<String> accountIdList = ctopAgentAccountMapper.getAllAccountId();
+            if (!accountIdList.isEmpty()) {
+                accountIdList.stream().forEach(str -> {
+                    if (!str.isEmpty()) {
+                        //查询账号下充值的交易流水
+                        JSONObject jsonObject = queryAccountTransactionDay(str, 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:");
+                        }
+                        if (code != 0) {
+                            result.setMessage((String) jsonObject.get("message"));
+                            log.info("返回数据:" + jsonObject.toJSONString() + ":" + str);
+                        }
+                        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<String> advertiserIdList = ctopAccountTransactionDayMapper.getAdvertiserIdByDate(transactionDay.getDate(), transactionDay.getAdvertiserId());
+                                    //订单号不存在
+                                    if (advertiserIdList.isEmpty() || advertiserIdList.size() <= 0) {
+                                        transactionDetailsList.add(transactionDay);
+                                    }
+
+                                });
+                                JSONObject page_info = (JSONObject) data.get("page_info");
+                                int total_page = (int) page_info.get("total_page");
+                                //查询其他页数据
+                                if (total_page > 1) {
+                                    for (int i = 2; i <= total_page; i++) {
+                                        JSONObject jo = queryAccountTransactionDay(str, i, 1000, startDate, endDate);
+                                        JSONObject accountData = (JSONObject) jo.get("data");
+                                        List<Object> rechargeList = (List<Object>) accountData.get("list");
+                                        rechargeList.stream().forEach(obj -> {
+                                            TransactionDay transactionDay = JSONObject.toJavaObject((JSON) obj, TransactionDay.class);
+                                            List<String> advertiserIdList = ctopAccountTransactionDayMapper.getAdvertiserIdByDate(transactionDay.getDate(), transactionDay.getAdvertiserId());
+
+                                            //订单号不存在
+                                            if (advertiserIdList.isEmpty() || advertiserIdList.size() <= 0) {
+                                                transactionDetailsList.add(transactionDay);
+                                            }
+                                        });
+                                    }
+                                }
+                            }
+                        }
+                    }
+                });
+            }
+            //保存数据
+            if (!transactionDetailsList.isEmpty()) {
+                ctopAccountTransactionDayMapper.saveAccountTransactionDay(transactionDetailsList, df.format(new Date()));
+                log.info("新增日流水记录:{}条", transactionDetailsList.size());
+            }
+            result.setSuccess(true);
+            result.setMessage("success");
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage("error");
+            log.info("同步失败:{}", e.toString());
+        }
+
+
+        return result;
     }
 
     /**
-     * 查询账号流水
+     * 查询账号流水明细
      *
      * @return
      * @author zzy
@@ -222,7 +338,31 @@ public class AgentManagementServiceImpl implements AgentManagementService {
      * @create: 2021-07-14
      */
     @Override
-    public JSONObject queryAccountTransactionDetails(String AccountId, String transaction_type, int pageNum, int pageSize) {
+    public JSONObject queryAccountTransactionDetails(String AccountId, String transaction_type, int pageNum, int pageSize, String startDate, String endDate) {
+        // 请求参数
+        Map data = new HashMap() {
+            {
+                put("advertiser_id", AccountId);
+                put("start_date", startDate);
+                put("end_date", endDate);
+                put("transaction_type", transaction_type);
+                put("page", pageNum);
+                put("page_size", pageSize);
+            }
+        };
+        return sendHttpRequest(data, ACCOUNT_TRANSACTION_DETAILS_URL);
+    }
+
+    /**
+     * 查询账号日流水
+     *
+     * @return
+     * @author zzy
+     * @Param AccountId 账户id       pageNum 当前页    pageSize 每页显示数量
+     * @create: 2021-07-14
+     */
+    @Override
+    public JSONObject queryAccountTransactionDay(String AccountId, int pageNum, int pageSize, String startDate, String endDate) {
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
         Calendar ca = Calendar.getInstance();
         ca.setTime(new Date());
@@ -231,14 +371,15 @@ public class AgentManagementServiceImpl implements AgentManagementService {
         Map data = new HashMap() {
             {
                 put("advertiser_id", AccountId);
-                put("start_date", df.format(ca.getTime()));
-                put("end_date", df.format(ca.getTime()));
-                put("transaction_type", transaction_type);
+                put("start_date", startDate);
+                put("end_date", endDate);
                 put("page", pageNum);
                 put("page_size", pageSize);
             }
         };
-        return sendHttpRequest(data, ACCOUNT_TRANSACTION_DETAILS_URL);
+        return sendHttpRequest(data, ACCOUNT_TRANSACTION_DAY_URL);
+
+
     }
 
 
@@ -250,7 +391,7 @@ public class AgentManagementServiceImpl implements AgentManagementService {
      */
     @Override
     public String getToken() {
-        CtopOauthToken ctopOauthToken = ctopOauthTokenMapper.selectByAccountId(Long.parseLong(ADVERTISER_ID));
+        CtopOauthToken ctopOauthToken = ctopAgentAccountMapper.selectByAccountId(Long.parseLong(ADVERTISER_ID));
         if (ctopOauthToken != null) {
             return ctopOauthToken.getAccessToken();
         } else {