Ver código fonte

查询账户转账余额相关接口

zhaoxian 1 ano atrás
pai
commit
ad1b5af150

+ 85 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/controller/BytedancAccountTransferBalanceController.java

@@ -0,0 +1,85 @@
+package cn.com.ctop.toutiao.modules.material.controller;
+
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceTransferBalanceService;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 转账余额
+ */
+@Slf4j
+@RestController
+@RequestMapping("/bytedance/transfer")
+public class BytedancAccountTransferBalanceController {
+    @Resource
+    private IByteDanceTransferBalanceService balanceService;
+
+    /**
+     * 查询账户转账余额
+     */
+    @RequestMapping(value = "/getTransferBalance")
+    public Result getTransferBalance(@RequestBody List<Long> accountIdList) {
+        try {
+            return balanceService.getTransferBalance(accountIdList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 获取最大可转余额
+     *
+     * @param data 入参格式
+     *             {"account_id":8485602,"transfer_direction":"TRANSFER_IN","target_account_id_list":[1111111111111111]}
+     */
+    @RequestMapping(value = "/getCanTransferBalance")
+    public Result getCanTransferBalance(@RequestBody JSONObject data) {
+        try {
+            return balanceService.getCanTransferBalance(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 发起转账
+     *
+     * @param data 入参格式
+     *             {"account_id":8485602,"transfer_direction":"TRANSFER_IN","target_account_detail_list":[{"account_id":8485602,"transfer_capital_detail_list":[{"capital_type":"CREDIT_GENERAL","transfer_amount":50000}]}]}
+     */
+    @RequestMapping(value = "/createTransfer")
+    public Result createTransfer(@RequestBody JSONObject data) {
+        try {
+            return balanceService.createTransfer(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 查询转账单信息(代理)
+     *
+     * @param transferNo 转账单号
+     */
+    @RequestMapping(value = "/queryTransferDetail")
+    public Result queryTransferDetail(String transferNo) {
+        try {
+            return balanceService.queryTransferDetail(transferNo);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error(e.getMessage());
+        }
+    }
+
+
+}

+ 13 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/ByteDanceTransferBalanceMapper.java

@@ -0,0 +1,13 @@
+package cn.com.ctop.toutiao.modules.material.mapper;
+
+import cn.com.ctop.toutiao.modules.material.entity.ByteDanceAdvertiser;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface ByteDanceTransferBalanceMapper  {
+
+    void replaceBatch(@Param("list") List<JSONObject> list);
+}

+ 31 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/xml/ByteDanceTransferBalanceMapper.xml

@@ -0,0 +1,31 @@
+<?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.material.mapper.ByteDanceTransferBalanceMapper">
+
+
+    <insert id="replaceBatch">
+        replace into bytedanc_account_transfer_balance(
+        project_id,
+        project_name,
+        account_id,
+        account_name,
+        deposit_amount,
+        total_transfer_amount,
+        capital_detail_list
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.projectId},
+            #{li.projectName},
+            #{li.account_id},
+            #{li.accountName},
+            #{li.deposit_amount},
+            #{li.total_transfer_amount},
+            #{li.capitalDetailList}
+            )
+        </foreach>
+    </insert>
+
+
+</mapper>

+ 18 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceTransferBalanceService.java

@@ -0,0 +1,18 @@
+package cn.com.ctop.toutiao.modules.material.service;
+
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.api.vo.Result;
+
+import java.util.List;
+
+public interface IByteDanceTransferBalanceService {
+
+
+    Result getTransferBalance(List<Long> accountIdList);
+
+    Result getCanTransferBalance(JSONObject data);
+
+    Result createTransfer(JSONObject data);
+
+    Result queryTransferDetail(String transferNo);
+}

+ 182 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceTransferBalanceServiceImpl.java

@@ -0,0 +1,182 @@
+package cn.com.ctop.toutiao.modules.material.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.toutiao.modules.material.mapper.ByteDanceTransferBalanceMapper;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceTransferBalanceService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+@Slf4j
+@Service
+public class ByteDanceTransferBalanceServiceImpl implements IByteDanceTransferBalanceService {
+
+    @Autowired
+    private ByteDanceTransferBalanceMapper balanceMapper;
+
+    @Autowired
+    IUserAllocationService userAllocationService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
+    @Override
+    public Result getTransferBalance(List<Long> accountIdList) {
+        String adid = PropertiesUtils.getValue("bytedance_config", "admin_account_id");
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(Long.valueOf(adid));
+        //转账-查询账户转账余额(代理)
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_rapi_url")
+                + PropertiesUtils.getValue("bytedance_config", "bytedance_v3_query_transfer_balance");
+        Map<String, Object> param = new HashMap<>();
+        param.put("biz_request_no", UUID.randomUUID().toString());
+        param.put("agent_id", 73970348172L);
+        param.put("account_id_list", accountIdList);
+        Map<String, String> header = new HashMap<>();
+        header.put("Access-Token", token.getAccessToken());
+        JSONObject result = JSONObject.parseObject(HttpUtils.httpGet(url, param, header));
+        System.out.println("结果result:" + result);
+        if (!Check.isNull(result)) {
+            String code = result.getString("code");
+            if ("0".equals(code)) {
+                //违规信息入库
+                JSONObject data = result.getJSONObject("data");
+                JSONArray accontAmountDetailList = data.getJSONArray("accont_amount_detail_list");
+                List<JSONObject> list = new ArrayList<>();
+                for (int i = 0; i < accontAmountDetailList.size(); i++) {
+                    JSONObject obj = accontAmountDetailList.getJSONObject(i);
+                    JSONArray capitalDetailList = obj.getJSONArray("capital_detail_list");
+                    JSONObject cdl = new JSONObject();
+                    capitalDetailList.stream().forEach(cap -> {
+                        JSONObject capObj = (JSONObject) cap;
+                        cdl.put(capObj.getString("capital_type"), capObj.getLong("transfer_balance"));
+                    });
+                    obj.put("capitalDetailList", cdl.toJSONString());
+                    JSONObject project = userAllocationService.getAccountInfoByAccountId(obj.getLong("account_id"));
+                    if (!Check.isNull(project)) {
+                        obj.put("projectId", project.getLong("projectId"));
+                        obj.put("projectName", project.getString("projectName"));
+                        obj.put("accountName", project.getString("accountName"));
+                    }
+                    list.add(obj);
+                }
+                if (!Check.isNull(list)) {
+                    balanceMapper.replaceBatch(list);
+                }
+                return Result.successMsg("success", null);
+            } else {
+                log.error("查询账户转账余额失败,原因:" + result.getString("message"));
+            }
+        }
+        return Result.error(result.getString("message"));
+
+    }
+
+    @Override
+    public Result getCanTransferBalance(JSONObject data) {
+        String adid = PropertiesUtils.getValue("bytedance_config", "admin_account_id");
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(Long.valueOf(adid));
+        //转账-获取最大可转余额(代理)
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_rapi_url")
+                + PropertiesUtils.getValue("bytedance_config", "bytedance_v3_query_can_transfer_balance");
+        Map<String, Object> param = new HashMap<>();
+        param.put("biz_request_no", UUID.randomUUID().toString());
+        param.put("agent_id", 73970348172L);
+        param.put("target_account_id_list", data.getJSONArray("target_account_id_list"));
+        param.put("account_id", data.getLong("account_id"));
+        param.put("transfer_direction", data.getString("transfer_direction"));
+        Map<String, String> header = new HashMap<>();
+        header.put("Access-Token", token.getAccessToken());
+        JSONObject result = JSONObject.parseObject(HttpUtils.httpGet(url, param, header));
+        System.out.println("结果result:" + result);
+        if (!Check.isNull(result)) {
+            String code = result.getString("code");
+            if ("0".equals(code)) {
+                //违规信息入库
+                JSONObject restdata = result.getJSONObject("data");
+                JSONArray accontAmountDetailList = restdata.getJSONArray("can_transfer_detail_list");
+                return Result.successMsg(result.getString("message"), accontAmountDetailList);
+
+            } else {
+                log.error("获取最大可转余额失败,原因:" + result.getString("message"));
+            }
+        }
+        return Result.error(result.getString("message"));
+    }
+
+    @Override
+    public Result createTransfer(JSONObject data) {
+        String adid = PropertiesUtils.getValue("bytedance_config", "admin_account_id");
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(Long.valueOf(adid));
+        //转账-发起转账(代理)
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_rapi_url")
+                + PropertiesUtils.getValue("bytedance_config", "bytedance_v3_create_transfer");
+        Map<String, Object> param = new HashMap<>();
+        String uuid = UUID.randomUUID().toString();
+        param.put("biz_request_no", uuid);
+        param.put("agent_id", 73970348172L);
+        param.put("target_account_id_list", data.getJSONArray("target_account_detail_list"));
+        param.put("account_id", data.getLong("account_id"));
+        param.put("transfer_direction", data.getString("transfer_direction"));
+        Map<String, String> header = new HashMap<>();
+        String accessToken = token.getAccessToken();
+        header.put("Access-Token", accessToken);
+        JSONObject result = JSONObject.parseObject(HttpUtils.httpPostRequest(url, param, header));
+        System.out.println("结果result:" + result);
+        if (!Check.isNull(result)) {
+            String code = result.getString("code");
+            if ("0".equals(code)) {
+                JSONObject restData = result.getJSONObject("data");
+                String transferSerial = restData.getString("transfer_serial");
+                System.out.println(transferSerial);
+                return Result.successMsg(result.getString("message"), transferSerial);
+            } else {
+                log.error("发起转账失败,原因:" + result.getString("message"));
+            }
+        }
+        return Result.error(result.getString("message"));
+    }
+
+    @Override
+    public Result queryTransferDetail(String transferNo) {
+        String adid = PropertiesUtils.getValue("bytedance_config", "admin_account_id");
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(Long.valueOf(adid));
+        //转账-查询转账单信息(代理)
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_rapi_url")
+                + PropertiesUtils.getValue("bytedance_config", "bytedance_v3_create_transfer");
+        Map<String, Object> param = new HashMap<>();
+        String uuid = UUID.randomUUID().toString();
+        param.put("biz_request_no", uuid);
+        param.put("agent_id", 73970348172L);
+        param.put("transfer_serial", transferNo);//转账单号,与transfer_biz_request_no两者传其一即可
+//      param.put("transfer_biz_request_no", "");//发起转账的幂等id
+        Map<String, String> header = new HashMap<>();
+        header.put("Access-Token", token.getAccessToken());
+        JSONObject result = JSONObject.parseObject(HttpUtils.httpGet(url, param, header));
+        System.out.println("结果result:" + result);
+        if (!Check.isNull(result)) {
+            String code = result.getString("code");
+            if ("0".equals(code)) {
+                JSONObject restData = result.getJSONObject("data");
+                System.out.println(restData);
+                return Result.successMsg(result.getString("message"), restData);
+            } else {
+                log.error("查询转账单信息失败,原因:" + result.getString("message"));
+            }
+        }
+        return Result.error(result.getString("message"));
+    }
+
+}

+ 6 - 0
jeecg-boot-module-system/src/main/resources/bytedance_config.properties

@@ -38,4 +38,10 @@ bytedance_v2_creative_word_select=/2/tools/creative_word/select/
 bytedance_v2_risk_promotion_list=/2/agent/query/risk_promotion_list/
 #转账-查询账户转账余额(代理)↓
 bytedance_v3_query_transfer_balance=/v3.0/cg_transfer/query_transfer_balance/
+#转账-获取最大可转余额(代理)↓
+bytedance_v3_query_can_transfer_balance=/v3.0/cg_transfer/query_can_transfer_balance/
+#转账-发起转账(代理)↓
+bytedance_v3_create_transfer=/v3.0/cg_transfer/create_transfer/
+#转账-查询转账单信息(代理)↓
+bytedance_v3_query_transfer_detail=/v3.0/cg_transfer/query_transfer_detail/
 admin_account_id=73970348172