From c57db9216713b3cbba30c43734cca86b5c63a58b Mon Sep 17 00:00:00 2001 From: dorion <872354125@qq.com> Date: Mon, 22 Apr 2024 01:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0usdt=E5=85=91=E6=8D=A2trx?= =?UTF-8?q?=E6=9C=AA=E6=8E=A5=E5=85=A5=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/TenantInfoController.java | 9 +- .../exchange/UsdtExchangeInfoController.java | 123 +++++++++++ .../templates/exchange/usdt/add.html | 44 ++++ .../templates/exchange/usdt/edit.html | 118 +++++++++++ .../templates/exchange/usdt/usdt.html | 144 +++++++++++++ .../core/domain/entity/UsdtExchangeInfo.java | 83 ++++++++ .../quartz/task/MonitorTrxTransferTask.java | 4 +- .../quartz/task/MonitorUsdtTransferTask.java | 31 +++ .../quartz/task/UndelegateEnergyTask.java | 7 +- .../java/com/ruoyi/system/api/IOkxApi.java | 10 + .../java/com/ruoyi/system/api/ITronApi.java | 8 + .../com/ruoyi/system/api/entity/okx/Data.java | 144 +++++++++++++ .../system/api/entity/okx/OkxResponse.java | 34 ++++ .../ruoyi/system/api/enums/ContractType.java | 10 + .../com/ruoyi/system/api/enums/Symbol.java | 10 + .../com/ruoyi/system/api/impl/OkxApiImpl.java | 79 +++++++ .../ruoyi/system/api/impl/TronApiImpl.java | 74 +++++++ .../system/handler/UsdtTransferHandler.java | 192 ++++++++++++++++++ .../system/mapper/UsdtExchangeInfoMapper.java | 63 ++++++ .../service/IMonitorAddressInfoService.java | 8 +- .../service/IUsdtExchangeInfoService.java | 65 ++++++ .../impl/MonitorAddressInfoServiceImpl.java | 3 +- .../impl/UsdtExchangeInfoServiceImpl.java | 136 +++++++++++++ .../exchange/UsdtExchangeInfoMapper.xml | 117 +++++++++++ 24 files changed, 1502 insertions(+), 14 deletions(-) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/exchange/UsdtExchangeInfoController.java create mode 100644 ruoyi-admin/src/main/resources/templates/exchange/usdt/add.html create mode 100644 ruoyi-admin/src/main/resources/templates/exchange/usdt/edit.html create mode 100644 ruoyi-admin/src/main/resources/templates/exchange/usdt/usdt.html create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/UsdtExchangeInfo.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/api/IOkxApi.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/api/ITronApi.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/api/entity/okx/Data.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/api/entity/okx/OkxResponse.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/api/enums/ContractType.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/api/enums/Symbol.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/api/impl/OkxApiImpl.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/handler/UsdtTransferHandler.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsdtExchangeInfoMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/IUsdtExchangeInfoService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsdtExchangeInfoServiceImpl.java create mode 100644 ruoyi-system/src/main/resources/mapper/exchange/UsdtExchangeInfoMapper.xml diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/account/TenantInfoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/account/TenantInfoController.java index 66c9a9dd7..594c7ff0e 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/account/TenantInfoController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/account/TenantInfoController.java @@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.entity.MonitorAddressInfo; import com.ruoyi.common.core.domain.entity.TenantInfo; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.DictUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.system.service.IMonitorAddressInfoService; import com.ruoyi.system.service.ITenantInfoService; @@ -75,8 +76,8 @@ public class TenantInfoController extends BaseController @GetMapping("/add") public String add(ModelMap mmap) { - - List monitorAddressAccountList = monitorAddressInfoService.selectAllValidMonitorAddressAccount(); + String trx2Energy = DictUtils.getDictValue("sys_busi_type", "TRX兑能量"); + List monitorAddressAccountList = monitorAddressInfoService.selectAllValidMonitorAddressAccount(trx2Energy); mmap.put("monitorAddressInfoList", monitorAddressAccountList); return prefix + "/add"; } @@ -102,8 +103,8 @@ public class TenantInfoController extends BaseController { TenantInfo tenantInfo = tenantInfoService.selectTenantInfoByIdTenantInfo(idTenantInfo); mmap.put("tenantInfo", tenantInfo); - - List monitorAddressInfoList = monitorAddressInfoService.selectAllValidMonitorAddressAccount(); + String trx2Energy = DictUtils.getDictValue("sys_busi_type", "TRX兑能量"); + List monitorAddressInfoList = monitorAddressInfoService.selectAllValidMonitorAddressAccount(trx2Energy); mmap.put("monitorAddressInfoList", monitorAddressInfoList); return prefix + "/edit"; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/exchange/UsdtExchangeInfoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/exchange/UsdtExchangeInfoController.java new file mode 100644 index 000000000..d59f125a6 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/exchange/UsdtExchangeInfoController.java @@ -0,0 +1,123 @@ +package com.ruoyi.web.controller.exchange; + +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.UsdtExchangeInfo; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.service.IUsdtExchangeInfoService; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * USDT交易明细Controller + * + * @author dorion + * @date 2024-04-19 + */ +@Controller +@RequestMapping("/exchange/usdt") +public class UsdtExchangeInfoController extends BaseController +{ + private String prefix = "exchange/usdt"; + + @Autowired + private IUsdtExchangeInfoService usdtExchangeInfoService; + + @RequiresPermissions("exchange:usdt:view") + @GetMapping() + public String usdt() + { + return prefix + "/usdt"; + } + + /** + * 查询USDT交易明细列表 + */ + @RequiresPermissions("exchange:usdt:list") + @PostMapping("/list") + @ResponseBody + public TableDataInfo list(UsdtExchangeInfo usdtExchangeInfo) + { + startPage(); + List list = usdtExchangeInfoService.selectUsdtExchangeInfoList(usdtExchangeInfo); + return getDataTable(list); + } + + /** + * 导出USDT交易明细列表 + */ + @RequiresPermissions("exchange:usdt:export") + @Log(title = "USDT交易明细", businessType = BusinessType.EXPORT) + @PostMapping("/export") + @ResponseBody + public AjaxResult export(UsdtExchangeInfo usdtExchangeInfo) + { + List list = usdtExchangeInfoService.selectUsdtExchangeInfoList(usdtExchangeInfo); + ExcelUtil util = new ExcelUtil(UsdtExchangeInfo.class); + return util.exportExcel(list, "USDT交易明细数据"); + } + + /** + * 新增USDT交易明细 + */ + @GetMapping("/add") + public String add() + { + return prefix + "/add"; + } + + /** + * 新增保存USDT交易明细 + */ + @RequiresPermissions("exchange:usdt:add") + @Log(title = "USDT交易明细", businessType = BusinessType.INSERT) + @PostMapping("/add") + @ResponseBody + public AjaxResult addSave(UsdtExchangeInfo usdtExchangeInfo) throws Exception { + return toAjax(usdtExchangeInfoService.insertUsdtExchangeInfo(usdtExchangeInfo)); + } + + /** + * 修改USDT交易明细 + */ + @RequiresPermissions("exchange:usdt:edit") + @GetMapping("/edit/{idUsdtExchangeInfo}") + public String edit(@PathVariable("idUsdtExchangeInfo") Long idUsdtExchangeInfo, ModelMap mmap) + { + UsdtExchangeInfo usdtExchangeInfo = usdtExchangeInfoService.selectUsdtExchangeInfoByIdUsdtExchangeInfo(idUsdtExchangeInfo); + mmap.put("usdtExchangeInfo", usdtExchangeInfo); + return prefix + "/edit"; + } + + /** + * 修改保存USDT交易明细 + */ + @RequiresPermissions("exchange:usdt:edit") + @Log(title = "USDT交易明细", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + @ResponseBody + public AjaxResult editSave(UsdtExchangeInfo usdtExchangeInfo) + { + return toAjax(usdtExchangeInfoService.updateUsdtExchangeInfo(usdtExchangeInfo)); + } + + /** + * 删除USDT交易明细 + */ + @RequiresPermissions("exchange:usdt:remove") + @Log(title = "USDT交易明细", businessType = BusinessType.DELETE) + @PostMapping( "/remove") + @ResponseBody + public AjaxResult remove(String ids) + { + return toAjax(usdtExchangeInfoService.deleteUsdtExchangeInfoByIdUsdtExchangeInfos(ids)); + } +} diff --git a/ruoyi-admin/src/main/resources/templates/exchange/usdt/add.html b/ruoyi-admin/src/main/resources/templates/exchange/usdt/add.html new file mode 100644 index 000000000..e225c94a4 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/exchange/usdt/add.html @@ -0,0 +1,44 @@ + + + + + + + +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/exchange/usdt/edit.html b/ruoyi-admin/src/main/resources/templates/exchange/usdt/edit.html new file mode 100644 index 000000000..e3d6fabf3 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/exchange/usdt/edit.html @@ -0,0 +1,118 @@ + + + + + + + +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+ +
+ +
+
+
+
+ + + + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/exchange/usdt/usdt.html b/ruoyi-admin/src/main/resources/templates/exchange/usdt/usdt.html new file mode 100644 index 000000000..7fbb214c4 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/exchange/usdt/usdt.html @@ -0,0 +1,144 @@ + + + + + + +
+
+
+
+
+
    +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • + +
  • + + +
  • + +
  • +  搜索 +  重置 +
  • +
+
+
+
+ + +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/UsdtExchangeInfo.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/UsdtExchangeInfo.java new file mode 100644 index 000000000..5d89a8dd6 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/UsdtExchangeInfo.java @@ -0,0 +1,83 @@ +package com.ruoyi.common.core.domain.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * USDT交易明细对象 usdt_exchange_info + * + * @author dorion + * @date 2024-04-19 + */ +@Accessors(chain = true) +@Data +public class UsdtExchangeInfo extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键 */ + private Long idUsdtExchangeInfo; + + /** 转入地址 */ + @Excel(name = "交易地址") + private String fromAddress; + + /** 转出地址 */ + @Excel(name = "转入地址") + private String toAddress; + + + /** 出账地址 */ + @Excel(name = "出账地址") + private String accountAddress; + + /** 交易订单 */ + @Excel(name = "交易订单") + private String usdtTxId; + + /** 转入金额 */ + @Excel(name = "转入金额") + private BigDecimal usdtAmount; + + /** 转出金额 */ + @Excel(name = "转出金额") + private BigDecimal trxAmount; + + /** 兑换费率 */ + @Excel(name = "兑换费率") + private BigDecimal exchangeRate; + + /** TRX订单 */ + @Excel(name = "TRX订单") + private String trxTxId; + + /** 原始费率 */ + @Excel(name = "原始费率") + private BigDecimal orginalExchangeRate; + + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date fcd; + + /** 创建用户 */ + @Excel(name = "创建用户") + private String fcu; + + /** 更新时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date lcd; + + /** 更新用户 */ + @Excel(name = "更新用户") + private String lcu; + + +} diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/MonitorTrxTransferTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/MonitorTrxTransferTask.java index a733f154b..d409b4920 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/MonitorTrxTransferTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/MonitorTrxTransferTask.java @@ -3,6 +3,7 @@ package com.ruoyi.quartz.task; import com.ruoyi.common.core.domain.entity.AccountAddressInfo; import com.ruoyi.common.core.domain.entity.MonitorAddressInfo; +import com.ruoyi.common.utils.DictUtils; import com.ruoyi.system.domain.MonitorAddressAccount; import com.ruoyi.system.service.IAccountAddressInfoService; import com.ruoyi.system.service.IMonitorAddressInfoService; @@ -32,7 +33,8 @@ public class MonitorTrxTransferTask { .monitorType("TRX") .build(); List monitorAddressAccountList = iMonitorAddressInfoService.selectAllMonitorAddressAccount(monitorAddressAccountExample);*/ - List monitorAddressInfoList = iMonitorAddressInfoService.selectAllValidMonitorAddressAccount(); + String trx2Energy = DictUtils.getDictValue("sys_busi_type", "TRX兑能量"); + List monitorAddressInfoList = iMonitorAddressInfoService.selectAllValidMonitorAddressAccount(trx2Energy); List monitorAddressAccountList = new ArrayList<>(); for (MonitorAddressInfo monitorAddressInfo : monitorAddressInfoList) { diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/MonitorUsdtTransferTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/MonitorUsdtTransferTask.java index 8d989ab3e..8d6a76e65 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/MonitorUsdtTransferTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/MonitorUsdtTransferTask.java @@ -1,4 +1,35 @@ package com.ruoyi.quartz.task; +import com.ruoyi.common.core.domain.entity.MonitorAddressInfo; +import com.ruoyi.common.utils.DictUtils; +import com.ruoyi.system.handler.UsdtTransferHandler; +import com.ruoyi.system.service.IMonitorAddressInfoService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component("monitorUsdtTransferTask") +@Slf4j public class MonitorUsdtTransferTask { + + @Autowired + private IMonitorAddressInfoService iMonitorAddressInfoService; + + @Autowired + private UsdtTransferHandler usdtTransferHandler; + + public void doMonitorUsdtTransferTask() throws Exception { + String usdt2Trx = DictUtils.getDictValue("sys_busi_type", "USDT兑TRX"); + List monitorAddressInfoList = + iMonitorAddressInfoService.selectAllValidMonitorAddressAccount(usdt2Trx); + + for (MonitorAddressInfo monitorAddressInfo : monitorAddressInfoList) { + + usdtTransferHandler.doMonitorUsdtTransfer(monitorAddressInfo); + } + + + } } diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/UndelegateEnergyTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/UndelegateEnergyTask.java index 31eed5d27..95e3419ad 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/UndelegateEnergyTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/UndelegateEnergyTask.java @@ -1,6 +1,7 @@ package com.ruoyi.quartz.task; +import cn.hutool.core.date.DateUtil; import com.ruoyi.common.core.domain.entity.TrxExchangeInfo; import com.ruoyi.common.utils.DictUtils; import com.ruoyi.system.service.ITrxExchangeInfoService; @@ -8,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.Date; import java.util.List; @Component("undelegateEnergyTask") @@ -23,7 +25,10 @@ public class UndelegateEnergyTask { String dictValue = DictUtils.getDictValue("sys_delegate_status", "已委托"); - TrxExchangeInfo trxExchangeInfoExample = TrxExchangeInfo.builder().delegateStatus(dictValue).build(); + TrxExchangeInfo trxExchangeInfoExample = TrxExchangeInfo.builder() + .delegateStatus(dictValue) + .fcd(DateUtil.offsetDay(new Date(),-1)) + .build(); List trxExchangeInfoList = trxExchangeInfoService.selectTrxExchangeInfoList(trxExchangeInfoExample); for (TrxExchangeInfo trxExchangeInfo : trxExchangeInfoList) { diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/IOkxApi.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/IOkxApi.java new file mode 100644 index 000000000..da358aa20 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/IOkxApi.java @@ -0,0 +1,10 @@ +package com.ruoyi.system.api; + +import com.ruoyi.system.api.entity.okx.OkxResponse; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +public interface IOkxApi { + OkxResponse getSingleTickerOkxResponse() throws NoSuchAlgorithmException, InvalidKeyException; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/ITronApi.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/ITronApi.java new file mode 100644 index 000000000..d54f7bde7 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/ITronApi.java @@ -0,0 +1,8 @@ +package com.ruoyi.system.api; + +import com.ruoyi.system.dto.TronGridResponse; + +public interface ITronApi { + + TronGridResponse getTronGridResponse(String monitorAddress, String apiKey); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/okx/Data.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/okx/Data.java new file mode 100644 index 000000000..384d02615 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/okx/Data.java @@ -0,0 +1,144 @@ +package com.ruoyi.system.api.entity.okx; + + +import java.io.Serializable; + +/** + * Auto-generated: 2024-04-20 16:33:40 + * + * @author bejson.com (i@bejson.com) + * @website http://www.bejson.com/java2pojo/ + */ +public class Data implements Serializable { + + private static final long serialVersionUID = 1L; + + private String instType; + private String instId; + private String last; + private String lastSz; + private String askPx; + private String askSz; + private String bidPx; + private String bidSz; + private String open24h; + private String high24h; + private String low24h; + private String volCcy24h; + private String vol24h; + private String ts; + private String sodUtc0; + private String sodUtc8; + public void setInstType(String instType) { + this.instType = instType; + } + public String getInstType() { + return instType; + } + + public void setInstId(String instId) { + this.instId = instId; + } + public String getInstId() { + return instId; + } + + public void setLast(String last) { + this.last = last; + } + public String getLast() { + return last; + } + + public void setLastSz(String lastSz) { + this.lastSz = lastSz; + } + public String getLastSz() { + return lastSz; + } + + public void setAskPx(String askPx) { + this.askPx = askPx; + } + public String getAskPx() { + return askPx; + } + + public void setAskSz(String askSz) { + this.askSz = askSz; + } + public String getAskSz() { + return askSz; + } + + public void setBidPx(String bidPx) { + this.bidPx = bidPx; + } + public String getBidPx() { + return bidPx; + } + + public void setBidSz(String bidSz) { + this.bidSz = bidSz; + } + public String getBidSz() { + return bidSz; + } + + public void setOpen24h(String open24h) { + this.open24h = open24h; + } + public String getOpen24h() { + return open24h; + } + + public void setHigh24h(String high24h) { + this.high24h = high24h; + } + public String getHigh24h() { + return high24h; + } + + public void setLow24h(String low24h) { + this.low24h = low24h; + } + public String getLow24h() { + return low24h; + } + + public void setVolCcy24h(String volCcy24h) { + this.volCcy24h = volCcy24h; + } + public String getVolCcy24h() { + return volCcy24h; + } + + public void setVol24h(String vol24h) { + this.vol24h = vol24h; + } + public String getVol24h() { + return vol24h; + } + + public void setTs(String ts) { + this.ts = ts; + } + public String getTs() { + return ts; + } + + public void setSodUtc0(String sodUtc0) { + this.sodUtc0 = sodUtc0; + } + public String getSodUtc0() { + return sodUtc0; + } + + public void setSodUtc8(String sodUtc8) { + this.sodUtc8 = sodUtc8; + } + public String getSodUtc8() { + return sodUtc8; + } + +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/okx/OkxResponse.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/okx/OkxResponse.java new file mode 100644 index 000000000..6b216b605 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/okx/OkxResponse.java @@ -0,0 +1,34 @@ +package com.ruoyi.system.api.entity.okx; + +import java.io.Serializable; +import java.util.List; + +public class OkxResponse implements Serializable { + + private static final long serialVersionUID = 1L; + + + private String code; + private String msg; + private List data; + public void setCode(String code) { + this.code = code; + } + public String getCode() { + return code; + } + + public void setMsg(String msg) { + this.msg = msg; + } + public String getMsg() { + return msg; + } + + public void setData(List data) { + this.data = data; + } + public List getData() { + return data; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/enums/ContractType.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/enums/ContractType.java new file mode 100644 index 000000000..a5a79b31f --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/enums/ContractType.java @@ -0,0 +1,10 @@ +package com.ruoyi.system.api.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum ContractType { + Approval, Transfer; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/enums/Symbol.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/enums/Symbol.java new file mode 100644 index 000000000..0a0368f05 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/enums/Symbol.java @@ -0,0 +1,10 @@ +package com.ruoyi.system.api.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum Symbol { + USDT; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/OkxApiImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/OkxApiImpl.java new file mode 100644 index 000000000..3ebaac7ed --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/OkxApiImpl.java @@ -0,0 +1,79 @@ +package com.ruoyi.system.api.impl; + +import cn.hutool.json.JSONUtil; +import com.ruoyi.common.utils.http.RestTemplateUtils; +import com.ruoyi.system.api.IOkxApi; +import com.ruoyi.system.api.entity.okx.OkxResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.util.UriComponentsBuilder; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.text.SimpleDateFormat; +import java.util.Base64; +import java.util.Date; +import java.util.TimeZone; + +@Component +@Slf4j +public class OkxApiImpl implements IOkxApi { + @Override + public OkxResponse getSingleTickerOkxResponse() throws NoSuchAlgorithmException, InvalidKeyException { + + //apikey = "b5937540-0817-41f8-bff3-3fda1262c744" + //secretkey = "4CAAAA212D525D14AA1012E24B5FABDD" + //IP = "" + //备注名 = "实时查询费率" + //权限 = "读取" + HttpHeaders headers = new HttpHeaders(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + String timestamp = dateFormat.format(new Date()); + headers.add("OK-ACCESS-TIMESTAMP", timestamp); + String apiKey = "eb3163ad-5221-491a-9ae9-e74e9637574c"; + headers.add("OK-ACCESS-KEY", apiKey); + String passphrase = "CHenduoqi0101!"; + headers.add("OK-ACCESS-PASSPHRASE", passphrase); + String method = "GET"; + String sign = generateSignature(timestamp, "get", "/api/v5/market/ticker?instId=TRX-USDT", "", "4CAAAA212D525D14AA1012E24B5FABDD"); + headers.add("OK-ACCESS-SIGN", sign); + //监听 + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://www.okx.com/api/v5/market/ticker?instId=TRX-USDT"); + String uriString = builder.toUriString(); + ResponseEntity responseEntity = RestTemplateUtils.get(uriString, headers, String.class); + if (responseEntity == null) { + log.error("getSingleTickerOkxResponse:responseEntity is null"); + return null; + } + HttpStatus statusCode = responseEntity.getStatusCode(); + if (statusCode != HttpStatus.OK) { + log.error("getSingleTickerOkxResponse响应失败:{}", JSONUtil.toJsonStr(responseEntity)); + return null; + } + Object responseEntityBody = responseEntity.getBody(); + if (responseEntityBody == null) { + log.warn("getSingleTickerOkxResponse:responseEntityBody is null"); + return null; + } + + OkxResponse okxResponse = JSONUtil.toBean((String) responseEntityBody, OkxResponse.class); + return okxResponse; + } + + private static String generateSignature(String timestamp, String method, String requestPath, String body, String secretKey) + throws NoSuchAlgorithmException, InvalidKeyException { + String preHash = timestamp + method + requestPath + body; + SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256"); + Mac mac = Mac.getInstance("HmacSHA256"); + mac.init(secretKeySpec); + byte[] hmacSha256 = mac.doFinal(preHash.getBytes(StandardCharsets.UTF_8)); + return Base64.getEncoder().encodeToString(hmacSha256); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java new file mode 100644 index 000000000..ac2cad5c6 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java @@ -0,0 +1,74 @@ +package com.ruoyi.system.api.impl; + +import cn.hutool.json.JSONUtil; +import com.ruoyi.common.utils.http.RestTemplateUtils; +import com.ruoyi.system.api.ITronApi; +import com.ruoyi.system.dto.TronGridResponse; +import com.ruoyi.system.service.ISysConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.util.UriComponentsBuilder; + +@Component +@Slf4j +public class TronApiImpl implements ITronApi { + + @Autowired + private ISysConfigService configService; + + @Override + public TronGridResponse getTronGridResponse(String monitorAddress, String apiKey) { + HttpHeaders headers = new HttpHeaders(); + headers.add("TRON-PRO-API-KEY", apiKey); + //监听 + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://api.trongrid.io/v1/accounts/" + monitorAddress + "/transactions/trc20"); +// builder.queryParam("only_confirmed", true); + builder.queryParam("only_to", true); + builder.queryParam("limit", 200); +// String sysTransferBetween = configService.selectConfigByKey("sys.transfer.between"); +// +// DateTime min_timestamp = DateUtil.offset(new Date(), DateField.MINUTE, Integer.valueOf(sysTransferBetween)); +// builder.queryParam("min_timestamp", min_timestamp.getTime()); + + String uriString = builder.toUriString(); + ResponseEntity responseEntity = RestTemplateUtils.get(uriString, headers, String.class); + + Object responseEntityBody = getResponseEntityBody(responseEntity, monitorAddress); + if (responseEntityBody == null) return null; + TronGridResponse tronGridResponse = JSONUtil.toBean((String) responseEntityBody, TronGridResponse.class); + if (log.isInfoEnabled()) { + log.info("{}responseEntityBody:{}", monitorAddress, JSONUtil.toJsonStr(tronGridResponse)); + } + return tronGridResponse; + } + + + /** + * 获取响应体 + * + * @param responseEntity + * @param address + * @return + */ + private static Object getResponseEntityBody(ResponseEntity responseEntity, String address) { + if (responseEntity == null) { + log.warn("{}:responseEntity is null", address); + return null; + } + HttpStatus statusCode = responseEntity.getStatusCode(); + if (statusCode != HttpStatus.OK) { + log.error("获取trx交易信息失败:{}", address); + return null; + } + Object responseEntityBody = responseEntity.getBody(); + if (responseEntityBody == null) { + log.warn("{}:responseEntityBody is null", address); + return null; + } + return responseEntityBody; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/UsdtTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/UsdtTransferHandler.java new file mode 100644 index 000000000..ca5cafc4e --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/UsdtTransferHandler.java @@ -0,0 +1,192 @@ +package com.ruoyi.system.handler; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.json.JSONUtil; +import com.google.common.base.Preconditions; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.core.domain.entity.MonitorAddressInfo; +import com.ruoyi.common.core.domain.entity.UsdtExchangeInfo; +import com.ruoyi.system.api.IOkxApi; +import com.ruoyi.system.api.ITronApi; +import com.ruoyi.system.api.entity.okx.OkxResponse; +import com.ruoyi.system.api.enums.ContractType; +import com.ruoyi.system.api.enums.Symbol; +import com.ruoyi.system.dto.Data; +import com.ruoyi.system.dto.Token_info; +import com.ruoyi.system.dto.TronGridResponse; +import com.ruoyi.system.mapper.UsdtExchangeInfoMapper; +import com.ruoyi.system.service.IAccountAddressInfoService; +import com.ruoyi.system.service.ISysConfigService; +import com.ruoyi.system.util.AddressUtil; +import lombok.extern.slf4j.Slf4j; +import org.redisson.api.RedissonClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +import org.tron.trident.core.ApiWrapper; +import org.tron.trident.core.exceptions.IllegalException; +import org.tron.trident.proto.Chain; +import org.tron.trident.proto.Response; + +import java.math.BigDecimal; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.concurrent.TimeUnit; + +@Component +@Slf4j +public class UsdtTransferHandler { + + @Autowired + private ITronApi tronApi; + @Autowired + private IOkxApi okxApi; + + @Autowired + private IAccountAddressInfoService accountAddressInfoService; + + @Autowired + private UsdtExchangeInfoMapper usdtExchangeInfoMapper; + @Autowired + private ISysConfigService configService; + + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private RedissonClient redissonClient; + + public void doMonitorUsdtTransfer(MonitorAddressInfo monitorAddressInfo) throws Exception { + + String monitorAddress = monitorAddressInfo.getMonitorAddress(); + String apiKey = monitorAddressInfo.getApiKey(); + TronGridResponse tronGridResponse = tronApi.getTronGridResponse(monitorAddress, apiKey); + + List dataList = tronGridResponse.getData(); + if (CollectionUtil.isEmpty(dataList)) { + return; + } + + + //获取欧易费率 + BigDecimal oneUsdtToTrx = getOneUsdtToTrx(); + + + for (Data data : dataList) { + doMonitorUsdtTransferByData(monitorAddressInfo, data, oneUsdtToTrx, apiKey); + } + + } + + private void doMonitorUsdtTransferByData(MonitorAddressInfo monitorAddressInfo, Data data, BigDecimal oneUsdtToTrx, String apiKey) throws Exception { + BigDecimal transferValue = getTransferValue(data); + if (transferValue == null) return; + + BigDecimal trxValue = transferValue.multiply(oneUsdtToTrx); + + String accountAddress = monitorAddressInfo.getAccountAddress(); + String decryptPrivateKey = accountAddressInfoService.getDecryptPrivateKey(accountAddress); + + //转账地址 + String from = data.getFrom(); + //接收地址 + String dataTo = data.getTo(); + String transactionId = data.getTransaction_id(); + + doTransferUsdtAndStore(oneUsdtToTrx, apiKey, decryptPrivateKey, accountAddress, from, trxValue, dataTo, transactionId, transferValue); + + redisTemplate.opsForValue().set("transfer_USDT_" + transactionId, transactionId, 1, TimeUnit.DAYS); + + } + + public void doTransferUsdtAndStore(BigDecimal oneUsdtToTrx, String apiKey, String decryptPrivateKey, String accountAddress, String from, BigDecimal trxValue, String dataTo, String transactionId, BigDecimal transferValue) throws IllegalException { + + String systronApiSwitch = configService.selectConfigByKey("sys.tron.api"); + + String txId = null; + if (UserConstants.YES.equals(systronApiSwitch)) { + + ApiWrapper apiWrapper = ApiWrapper.ofMainnet(decryptPrivateKey, apiKey); + + //转账 + Response.TransactionExtention transfer = apiWrapper.transfer(accountAddress, from, trxValue.movePointRight(6).longValue()); + //签名 + Chain.Transaction transaction = apiWrapper.signTransaction(transfer); + //广播 + txId = apiWrapper.broadcastTransaction(transaction); + } + + + UsdtExchangeInfo usdtExchangeInfo = new UsdtExchangeInfo(); + usdtExchangeInfo.setFromAddress(AddressUtil.hexToBase58(from)) + .setToAddress(AddressUtil.hexToBase58(dataTo)) + .setAccountAddress(accountAddress) + .setUsdtTxId(transactionId) + .setUsdtAmount(transferValue) + .setTrxAmount(trxValue) + .setExchangeRate(oneUsdtToTrx) + .setOrginalExchangeRate(oneUsdtToTrx) + .setTrxTxId(txId); + + usdtExchangeInfoMapper.insertUsdtExchangeInfo(usdtExchangeInfo); + } + + /** + * 获取对方转账的U数量 + * + * @param data + * @return + */ + private BigDecimal getTransferValue(Data data) { + String transFerName = ContractType.Transfer.name(); + if (!transFerName.equals(data.getType())) { + log.warn("未知交易类型:{},交易数据:{}", data.getType(), JSONUtil.toJsonStr(data)); + return null; + } + + + Token_info tokenInfo = data.getToken_info(); + + if (!Symbol.USDT.name().equals(tokenInfo.getSymbol())) { + log.warn("未知交易币种:{},交易数据:{}", tokenInfo.getSymbol(), JSONUtil.toJsonStr(data)); + return null; + } + int decimals = tokenInfo.getDecimals(); + + + //转账金额 + BigDecimal transferValue = new BigDecimal(data.getValue()).movePointLeft(decimals); + + if (transferValue.compareTo(BigDecimal.ONE) == -1) { + log.warn("交易金额小于1,交易数据:{}", JSONUtil.toJsonStr(data)); + return null; + } + return transferValue; + } + + /** + * 获取欧易费率 1U + * + * @return + * @throws NoSuchAlgorithmException + * @throws InvalidKeyException + */ + public BigDecimal getOneUsdtToTrx() throws NoSuchAlgorithmException, InvalidKeyException { + OkxResponse oksResponse = okxApi.getSingleTickerOkxResponse(); + Preconditions.checkNotNull(oksResponse, "查询费率失败无法兑换"); + String code = oksResponse.getCode(); + + Preconditions.checkState("0".equals(code), "okx响应码异常:" + JSONUtil.toJsonStr(oksResponse)); + + List oksResponseDataList = oksResponse.getData(); + Preconditions.checkState(CollectionUtil.isNotEmpty(oksResponseDataList), "okx费率响应为空:" + JSONUtil.toJsonStr(oksResponse)); + + log.info("oksResponse:{}",oksResponse); + String last = oksResponseDataList.get(0).getLast(); + + BigDecimal oneUsdtToTrx = BigDecimal.ONE.divide(new BigDecimal(last)).setScale(6, BigDecimal.ROUND_HALF_DOWN); + return oneUsdtToTrx; + } + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsdtExchangeInfoMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsdtExchangeInfoMapper.java new file mode 100644 index 000000000..383178abf --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsdtExchangeInfoMapper.java @@ -0,0 +1,63 @@ +package com.ruoyi.system.mapper; + +import com.ruoyi.common.core.domain.entity.UsdtExchangeInfo; + +import java.util.List; + + +/** + * USDT交易明细Mapper接口 + * + * @author dorion + * @date 2024-04-19 + */ +public interface UsdtExchangeInfoMapper +{ + /** + * 查询USDT交易明细 + * + * @param idUsdtExchangeInfo USDT交易明细主键 + * @return USDT交易明细 + */ + public UsdtExchangeInfo selectUsdtExchangeInfoByIdUsdtExchangeInfo(Long idUsdtExchangeInfo); + + /** + * 查询USDT交易明细列表 + * + * @param usdtExchangeInfo USDT交易明细 + * @return USDT交易明细集合 + */ + public List selectUsdtExchangeInfoList(UsdtExchangeInfo usdtExchangeInfo); + + /** + * 新增USDT交易明细 + * + * @param usdtExchangeInfo USDT交易明细 + * @return 结果 + */ + public int insertUsdtExchangeInfo(UsdtExchangeInfo usdtExchangeInfo); + + /** + * 修改USDT交易明细 + * + * @param usdtExchangeInfo USDT交易明细 + * @return 结果 + */ + public int updateUsdtExchangeInfo(UsdtExchangeInfo usdtExchangeInfo); + + /** + * 删除USDT交易明细 + * + * @param idUsdtExchangeInfo USDT交易明细主键 + * @return 结果 + */ + public int deleteUsdtExchangeInfoByIdUsdtExchangeInfo(Long idUsdtExchangeInfo); + + /** + * 批量删除USDT交易明细 + * + * @param idUsdtExchangeInfos 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteUsdtExchangeInfoByIdUsdtExchangeInfos(String[] idUsdtExchangeInfos); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IMonitorAddressInfoService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IMonitorAddressInfoService.java index c2895303f..7ddf4abe0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IMonitorAddressInfoService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IMonitorAddressInfoService.java @@ -60,12 +60,6 @@ public interface IMonitorAddressInfoService * @return 结果 */ public int deleteMonitorAddressInfoByIdMonitorAddress(Long idMonitorAddress); -/* - - List selectAllMonitorAddressAccount(MonitorAddressAccount monitorAddressAccountExample); -*/ - - List selectAllValidMonitorAddressAccount(); - + List selectAllValidMonitorAddressAccount(String busiType); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsdtExchangeInfoService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsdtExchangeInfoService.java new file mode 100644 index 000000000..3ad1bc8e3 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsdtExchangeInfoService.java @@ -0,0 +1,65 @@ +package com.ruoyi.system.service; + +import com.ruoyi.common.core.domain.entity.UsdtExchangeInfo; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.List; + + +/** + * USDT交易明细Service接口 + * + * @author dorion + * @date 2024-04-19 + */ +public interface IUsdtExchangeInfoService +{ + /** + * 查询USDT交易明细 + * + * @param idUsdtExchangeInfo USDT交易明细主键 + * @return USDT交易明细 + */ + public UsdtExchangeInfo selectUsdtExchangeInfoByIdUsdtExchangeInfo(Long idUsdtExchangeInfo); + + /** + * 查询USDT交易明细列表 + * + * @param usdtExchangeInfo USDT交易明细 + * @return USDT交易明细集合 + */ + public List selectUsdtExchangeInfoList(UsdtExchangeInfo usdtExchangeInfo); + + /** + * 新增USDT交易明细 + * + * @param usdtExchangeInfo USDT交易明细 + * @return 结果 + */ + public int insertUsdtExchangeInfo(UsdtExchangeInfo usdtExchangeInfo) throws Exception; + + /** + * 修改USDT交易明细 + * + * @param usdtExchangeInfo USDT交易明细 + * @return 结果 + */ + public int updateUsdtExchangeInfo(UsdtExchangeInfo usdtExchangeInfo); + + /** + * 批量删除USDT交易明细 + * + * @param idUsdtExchangeInfos 需要删除的USDT交易明细主键集合 + * @return 结果 + */ + public int deleteUsdtExchangeInfoByIdUsdtExchangeInfos(String idUsdtExchangeInfos); + + /** + * 删除USDT交易明细信息 + * + * @param idUsdtExchangeInfo USDT交易明细主键 + * @return 结果 + */ + public int deleteUsdtExchangeInfoByIdUsdtExchangeInfo(Long idUsdtExchangeInfo); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MonitorAddressInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MonitorAddressInfoServiceImpl.java index 29717c51e..40d28355a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MonitorAddressInfoServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MonitorAddressInfoServiceImpl.java @@ -102,9 +102,10 @@ public class MonitorAddressInfoServiceImpl implements IMonitorAddressInfoService }*/ @Override - public List selectAllValidMonitorAddressAccount() { + public List selectAllValidMonitorAddressAccount(String busiType) { MonitorAddressInfo monitorAddressInfo = new MonitorAddressInfo(); monitorAddressInfo.setIsValid("Y"); + monitorAddressInfo.setBusiType(busiType); return monitorAddressInfoMapper.selectMonitorAddressInfoList(monitorAddressInfo); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsdtExchangeInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsdtExchangeInfoServiceImpl.java new file mode 100644 index 000000000..838f4d50a --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsdtExchangeInfoServiceImpl.java @@ -0,0 +1,136 @@ +package com.ruoyi.system.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.google.common.base.Preconditions; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.core.domain.entity.AccountAddressInfo; +import com.ruoyi.common.core.domain.entity.UsdtExchangeInfo; +import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.utils.DictUtils; +import com.ruoyi.system.handler.UsdtTransferHandler; +import com.ruoyi.system.mapper.AccountAddressInfoMapper; +import com.ruoyi.system.mapper.UsdtExchangeInfoMapper; +import com.ruoyi.system.service.IUsdtExchangeInfoService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; + +/** + * USDT交易明细Service业务层处理 + * + * @author dorion + * @date 2024-04-19 + */ +@Service +public class UsdtExchangeInfoServiceImpl implements IUsdtExchangeInfoService { + @Autowired + private UsdtExchangeInfoMapper usdtExchangeInfoMapper; + + @Autowired + private UsdtTransferHandler usdtTransferHandler; + @Autowired + private AccountAddressInfoMapper accountAddressInfoMapper; + @Autowired + private AccountAddressInfoServiceImpl accountAddressInfoService; + @Autowired + private SysConfigServiceImpl configService; + + /** + * 查询USDT交易明细 + * + * @param idUsdtExchangeInfo USDT交易明细主键 + * @return USDT交易明细 + */ + @Override + public UsdtExchangeInfo selectUsdtExchangeInfoByIdUsdtExchangeInfo(Long idUsdtExchangeInfo) { + return usdtExchangeInfoMapper.selectUsdtExchangeInfoByIdUsdtExchangeInfo(idUsdtExchangeInfo); + } + + /** + * 查询USDT交易明细列表 + * + * @param usdtExchangeInfo USDT交易明细 + * @return USDT交易明细 + */ + @Override + public List selectUsdtExchangeInfoList(UsdtExchangeInfo usdtExchangeInfo) { + return usdtExchangeInfoMapper.selectUsdtExchangeInfoList(usdtExchangeInfo); + } + + /** + * 新增USDT交易明细 + * + * @param usdtExchangeInfo USDT交易明细 + * @return 结果 + */ + @Override + public int insertUsdtExchangeInfo(UsdtExchangeInfo usdtExchangeInfo) throws Exception { + BigDecimal oneUsdtToTrx; + String systronApiSwitch = configService.selectConfigByKey("sys.tron.api"); + + if (UserConstants.YES.equals(systronApiSwitch)) { + oneUsdtToTrx = usdtTransferHandler.getOneUsdtToTrx(); + } else { + oneUsdtToTrx = new BigDecimal("7.565113"); + } + + + BigDecimal usdtAmount = usdtExchangeInfo.getUsdtAmount(); + + BigDecimal trxValue = usdtAmount.multiply(oneUsdtToTrx); + String accountAddress = usdtExchangeInfo.getAccountAddress(); + if (StringUtils.isEmpty(accountAddress)) { + AccountAddressInfo accountAddressInfoExample = new AccountAddressInfo(); + accountAddressInfoExample.setIsValid("Y"); + accountAddressInfoExample.setBusiType(DictUtils.getDictValue("sys_busi_type", "USDT兑TRX")); + List accountAddressInfoList = accountAddressInfoMapper.selectAccountAddressInfoList(accountAddressInfoExample); + Preconditions.checkState(CollectionUtil.isNotEmpty(accountAddressInfoList), "无合适的转trx账户,请先设置"); + accountAddress = accountAddressInfoList.get(0).getAddress(); + } + + String decryptPrivateKey = accountAddressInfoService.getDecryptPrivateKey(accountAddress); + String tronApiKey = DictUtils.getDictValue("sys_tron_api_key", "synp@outlook"); + + String fromAddress = usdtExchangeInfo.getFromAddress(); + usdtTransferHandler. + doTransferUsdtAndStore(oneUsdtToTrx, tronApiKey, decryptPrivateKey, accountAddress, fromAddress, trxValue, null, null, usdtAmount); + + return 1; + } + + /** + * 修改USDT交易明细 + * + * @param usdtExchangeInfo USDT交易明细 + * @return 结果 + */ + @Override + public int updateUsdtExchangeInfo(UsdtExchangeInfo usdtExchangeInfo) { + return usdtExchangeInfoMapper.updateUsdtExchangeInfo(usdtExchangeInfo); + } + + /** + * 批量删除USDT交易明细 + * + * @param idUsdtExchangeInfos 需要删除的USDT交易明细主键 + * @return 结果 + */ + @Override + public int deleteUsdtExchangeInfoByIdUsdtExchangeInfos(String idUsdtExchangeInfos) { + return usdtExchangeInfoMapper.deleteUsdtExchangeInfoByIdUsdtExchangeInfos(Convert.toStrArray(idUsdtExchangeInfos)); + } + + /** + * 删除USDT交易明细信息 + * + * @param idUsdtExchangeInfo USDT交易明细主键 + * @return 结果 + */ + @Override + public int deleteUsdtExchangeInfoByIdUsdtExchangeInfo(Long idUsdtExchangeInfo) { + return usdtExchangeInfoMapper.deleteUsdtExchangeInfoByIdUsdtExchangeInfo(idUsdtExchangeInfo); + } +} diff --git a/ruoyi-system/src/main/resources/mapper/exchange/UsdtExchangeInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/exchange/UsdtExchangeInfoMapper.xml new file mode 100644 index 000000000..40c69beab --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/exchange/UsdtExchangeInfoMapper.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + select id_usdt_exchange_info, from_address, to_address, account_address, usdt_tx_id, usdt_amount, trx_amount, exchange_rate, trx_tx_id, orginal_exchange_rate, fcd, fcu, lcd, lcu from usdt_exchange_info + + + + + + + + insert into usdt_exchange_info + + from_address, + to_address, + account_address, + usdt_tx_id, + usdt_amount, + trx_amount, + exchange_rate, + trx_tx_id, + orginal_exchange_rate, + fcd, + fcu, + lcd, + lcu, + + + #{fromAddress}, + #{toAddress}, + #{accountAddress}, + #{usdtTxId}, + #{usdtAmount}, + #{trxAmount}, + #{exchangeRate}, + #{trxTxId}, + #{orginalExchangeRate}, + #{fcd}, + #{fcu}, + #{lcd}, + #{lcu}, + + + + + update usdt_exchange_info + + from_address = #{fromAddress}, + to_address = #{toAddress}, + account_address = #{accountAddress}, + usdt_tx_id = #{usdtTxId}, + usdt_amount = #{usdtAmount}, + trx_amount = #{trxAmount}, + exchange_rate = #{exchangeRate}, + trx_tx_id = #{trxTxId}, + orginal_exchange_rate = #{orginalExchangeRate}, + fcd = #{fcd}, + fcu = #{fcu}, + lcd = #{lcd}, + lcu = #{lcu}, + + where id_usdt_exchange_info = #{idUsdtExchangeInfo} + + + + delete from usdt_exchange_info where id_usdt_exchange_info = #{idUsdtExchangeInfo} + + + + delete from usdt_exchange_info where id_usdt_exchange_info in + + #{idUsdtExchangeInfo} + + + + \ No newline at end of file