代付订单
This commit is contained in:
1 parent
d81820c74f
commit
1eca7a77bc
15 files changed
+2200
-130
No files matched your search
+51
-9
@@ -2,20 +2,62 @@ package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrder;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrderPlus;
|
||||
import com.ruoyi.system.domain.dto.EncryptedRequest;
|
||||
import com.ruoyi.system.domain.vo.DecryptResult;
|
||||
import com.ruoyi.system.service.ApiSecurityService;
|
||||
import com.ruoyi.system.service.PayoutOrderService;
|
||||
import com.ruoyi.system.service.PayoutCallbackService;
|
||||
import com.ruoyi.system.service.PayoutOrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** 代付开放接口,不依赖浏览器会话或请求上下文。 */
|
||||
@RestController @RequestMapping("/api/v1/payout")
|
||||
/**
|
||||
* 代付开放接口,不依赖浏览器会话或请求上下文。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/payout")
|
||||
public class PayoutOpenApiController {
|
||||
@Autowired private ApiSecurityService security; @Autowired private PayoutOrderService service; @Autowired private PayoutCallbackService callbacks;
|
||||
@PostMapping("/create") public AjaxResult create(@RequestBody EncryptedRequest request){return AjaxResult.success(view(service.create(security.decryptAndVerify(request)),null));}
|
||||
@PostMapping("/query") public AjaxResult query(@RequestBody EncryptedRequest request){DecryptResult d=security.decryptAndVerify(request);String orderId=parseOrderId(d.getPlainData());UsdtPayoutOrder o=service.find(d.getAppId(),orderId);return o==null?AjaxResult.error("代付订单不存在"):AjaxResult.success(view(o,callbacks.signedRedirect(o,request.getApiKey())));}
|
||||
private java.util.Map<String,Object> view(UsdtPayoutOrder o,String redirect){java.util.Map<String,Object> m=new java.util.LinkedHashMap<>();m.put("order_id",o.getOrderId());m.put("trade_id",o.getTradeId());m.put("currency",o.getCurrency());m.put("amount",o.getAmount());m.put("fee_currency",o.getFeeCurrency());m.put("fee_amount",o.getFeeAmount());m.put("to_address",o.getToAddress());m.put("status",o.getStatus());m.put("transaction_id",o.getBlockTransactionId());if(redirect!=null)m.put("redirect_url",redirect);return m;}
|
||||
private String parseOrderId(String s){if(s==null||!s.startsWith("order_id=")||!s.endsWith("&"))throw new com.ruoyi.common.exception.CustomException("业务参数格式错误");return s.substring(9,s.length()-1);}
|
||||
@Autowired
|
||||
private ApiSecurityService security;
|
||||
@Autowired
|
||||
private PayoutOrderService service;
|
||||
@Autowired
|
||||
private PayoutCallbackService callbacks;
|
||||
|
||||
@PostMapping("/create")
|
||||
public AjaxResult create(@RequestBody EncryptedRequest request) {
|
||||
return AjaxResult.success(view(service.create(security.decryptAndVerify(request)), null));
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
public AjaxResult query(@RequestBody EncryptedRequest request) {
|
||||
DecryptResult d = security.decryptAndVerify(request);
|
||||
String orderId = parseOrderId(d.getPlainData());
|
||||
UsdtPayoutOrderPlus o = service.find(d.getAppId(), orderId);
|
||||
return o == null ? AjaxResult.error("代付订单不存在") : AjaxResult.success(view(o, callbacks.signedRedirect(o, request.getApiKey())));
|
||||
}
|
||||
|
||||
private java.util.Map<String, Object> view(UsdtPayoutOrderPlus o, String redirect) {
|
||||
java.util.Map<String, Object> m = new java.util.LinkedHashMap<>();
|
||||
m.put("order_id", o.getOrderId());
|
||||
m.put("trade_id", o.getTradeId());
|
||||
m.put("currency", o.getCurrency());
|
||||
m.put("amount", o.getAmount());
|
||||
m.put("fee_currency", o.getFeeCurrency());
|
||||
m.put("fee_amount", o.getFeeAmount());
|
||||
m.put("to_address", o.getToAddress());
|
||||
m.put("status", o.getStatus());
|
||||
m.put("transaction_id", o.getBlockTransactionId());
|
||||
if (redirect != null) m.put("redirect_url", redirect);
|
||||
return m;
|
||||
}
|
||||
|
||||
private String parseOrderId(String s) {
|
||||
if (s == null || !s.startsWith("order_id=") || !s.endsWith("&"))
|
||||
throw new com.ruoyi.common.exception.CustomException("业务参数格式错误");
|
||||
return s.substring(9, s.length() - 1);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrder;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrderPlus;
|
||||
import com.ruoyi.system.domain.dto.PayoutExecuteRequest;
|
||||
import com.ruoyi.system.mapper.UsdtPayoutOrderMapper;
|
||||
import com.ruoyi.system.service.PayoutProcessingService;
|
||||
@@ -29,17 +30,17 @@ public class PayoutOrderController extends BaseController {
|
||||
@PreAuthorize("@ss.hasPermi('system:payout:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(UsdtPayoutOrder query) {
|
||||
LambdaQueryWrapper<UsdtPayoutOrder> wrapper = new LambdaQueryWrapper<UsdtPayoutOrder>()
|
||||
.isNull(UsdtPayoutOrder::getDeletedAt)
|
||||
.orderByDesc(UsdtPayoutOrder::getId);
|
||||
LambdaQueryWrapper<UsdtPayoutOrderPlus> wrapper = new LambdaQueryWrapper<UsdtPayoutOrderPlus>()
|
||||
.isNull(UsdtPayoutOrderPlus::getDeletedAt)
|
||||
.orderByDesc(UsdtPayoutOrderPlus::getId);
|
||||
if (query.getAppId() != null) {
|
||||
wrapper.eq(UsdtPayoutOrder::getAppId, query.getAppId());
|
||||
wrapper.eq(UsdtPayoutOrderPlus::getAppId, query.getAppId());
|
||||
}
|
||||
if (query.getStatus() != null) {
|
||||
wrapper.eq(UsdtPayoutOrder::getStatus, query.getStatus());
|
||||
wrapper.eq(UsdtPayoutOrderPlus::getStatus, query.getStatus());
|
||||
}
|
||||
startPage();
|
||||
List<UsdtPayoutOrder> rows = mapper.selectList(wrapper);
|
||||
List<UsdtPayoutOrderPlus> rows = mapper.selectList(wrapper);
|
||||
return getDataTable(rows);
|
||||
}
|
||||
|
||||
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
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.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.select.Ids;
|
||||
import com.ruoyi.common.select.SelectItem;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrder;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrderPlus;
|
||||
import com.ruoyi.system.service.IUsdtPayoutOrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用代付订单Controller
|
||||
*
|
||||
* @author luqj
|
||||
* @date 2026-10-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/usdtPayoutOrder")
|
||||
public class UsdtPayoutOrderController extends BaseController {
|
||||
@Autowired
|
||||
private IUsdtPayoutOrderService usdtPayoutOrderService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:getByIds')")
|
||||
@PostMapping("/getByIds")
|
||||
public AjaxResult getByIds(@RequestBody Ids ids) {
|
||||
List<UsdtPayoutOrderPlus> list = usdtPayoutOrderService.getByIds(ids.getLongIds(), false, UsdtPayoutOrderPlus::getTradeId, UsdtPayoutOrderPlus::getId);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:user-getByIds')")
|
||||
@PostMapping("/user/getByIds")
|
||||
public AjaxResult userGetByIds(@RequestBody Ids ids) {
|
||||
List<UsdtPayoutOrderPlus> list = usdtPayoutOrderService.getByIds(ids.getLongIds(), true, UsdtPayoutOrderPlus::getUserId, UsdtPayoutOrderPlus::getTradeId, UsdtPayoutOrderPlus::getId);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:select')")
|
||||
@GetMapping("/select")
|
||||
public AjaxResult select(String keyword) {
|
||||
List<SelectItem> list = usdtPayoutOrderService.select(keyword, false);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:user-select')")
|
||||
@GetMapping("/user/select")
|
||||
public AjaxResult userSelect(String keyword) {
|
||||
List<SelectItem> list = usdtPayoutOrderService.select(keyword, true);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询应用代付订单列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(UsdtPayoutOrder usdtPayoutOrder) {
|
||||
startPage();
|
||||
List<UsdtPayoutOrder> list = usdtPayoutOrderService.selectUsdtPayoutOrderList(usdtPayoutOrder, false);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询应用代付订单列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:user-list')")
|
||||
@GetMapping("/user/list")
|
||||
public TableDataInfo userList(UsdtPayoutOrder usdtPayoutOrder) {
|
||||
startPage();
|
||||
List<UsdtPayoutOrder> list = usdtPayoutOrderService.selectUsdtPayoutOrderList(usdtPayoutOrder, true);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出应用代付订单列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:export')")
|
||||
@Log(title = "应用代付订单", businessType = BusinessType.EXPORT)
|
||||
@GetMapping("/export")
|
||||
public AjaxResult export(UsdtPayoutOrder usdtPayoutOrder) {
|
||||
List<UsdtPayoutOrder> list = usdtPayoutOrderService.selectUsdtPayoutOrderList(usdtPayoutOrder, false);
|
||||
ExcelUtil<UsdtPayoutOrder> util = new ExcelUtil<UsdtPayoutOrder>(UsdtPayoutOrder.class);
|
||||
return util.exportExcel(list, "usdtPayoutOrder");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用代付订单详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(usdtPayoutOrderService.selectUsdtPayoutOrderById(id, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用代付订单详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:user-query')")
|
||||
@GetMapping(value = "/user/{id}")
|
||||
public AjaxResult userGetInfo(@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(usdtPayoutOrderService.selectUsdtPayoutOrderById(id, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增应用代付订单
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:add')")
|
||||
@Log(title = "应用代付订单", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody UsdtPayoutOrder usdtPayoutOrder) {
|
||||
return toAjax(usdtPayoutOrderService.insertUsdtPayoutOrder(usdtPayoutOrder, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增应用代付订单
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:user-add')")
|
||||
@Log(title = "应用代付订单", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/user")
|
||||
public AjaxResult userAdd(@RequestBody UsdtPayoutOrder usdtPayoutOrder) {
|
||||
return toAjax(usdtPayoutOrderService.insertUsdtPayoutOrder(usdtPayoutOrder, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改应用代付订单
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:edit')")
|
||||
@Log(title = "应用代付订单", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody UsdtPayoutOrder usdtPayoutOrder) {
|
||||
return toAjax(usdtPayoutOrderService.updateUsdtPayoutOrder(usdtPayoutOrder, false));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:user-edit')")
|
||||
@Log(title = "应用代付订单", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/user")
|
||||
public AjaxResult userEdit(@RequestBody UsdtPayoutOrder usdtPayoutOrder) {
|
||||
return toAjax(usdtPayoutOrderService.updateUsdtPayoutOrder(usdtPayoutOrder, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除应用代付订单
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:remove')")
|
||||
@Log(title = "应用代付订单", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(usdtPayoutOrderService.deleteUsdtPayoutOrderByIds(ids, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除应用代付订单
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtPayoutOrder:user-remove')")
|
||||
@Log(title = "应用代付订单", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/user/{ids}")
|
||||
public AjaxResult userRemove(@PathVariable Long[] ids) {
|
||||
return toAjax(usdtPayoutOrderService.deleteUsdtPayoutOrderByIds(ids, true));
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,410 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/** 应用代付订单。 */
|
||||
@TableName("usdt_payout_order")
|
||||
public class UsdtPayoutOrder implements Serializable {
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import java.io.Serializable;
|
||||
/**
|
||||
* 应用代付订单对象 usdt_payout_order
|
||||
*
|
||||
* @author luqj
|
||||
* @date 2026-10-17
|
||||
*/
|
||||
public class UsdtPayoutOrder extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Long id; private String tradeId; private String orderId; private Long appId; private Long userId;
|
||||
private String currency; private BigDecimal amount; private String feeCurrency; private BigDecimal feeAmount;
|
||||
private String toAddress; private Integer status; private String auditType; private String auditorId;
|
||||
private String auditRemark; private Date auditedAt; private String blockTransactionId; private String executeError;
|
||||
private Integer executeCount; private Date executedAt; private Date confirmedAt; private String notifyUrl;
|
||||
private String redirectUrl; private Integer callbackNum; private Integer callbackConfirm;
|
||||
private Date createdAt; private Date updatedAt; private Date deletedAt;
|
||||
public Long getId(){return id;} public void setId(Long v){id=v;} public String getTradeId(){return tradeId;} public void setTradeId(String v){tradeId=v;}
|
||||
public String getOrderId(){return orderId;} public void setOrderId(String v){orderId=v;} public Long getAppId(){return appId;} public void setAppId(Long v){appId=v;}
|
||||
public Long getUserId(){return userId;} public void setUserId(Long v){userId=v;} public String getCurrency(){return currency;} public void setCurrency(String v){currency=v;}
|
||||
public BigDecimal getAmount(){return amount;} public void setAmount(BigDecimal v){amount=v;} public String getFeeCurrency(){return feeCurrency;} public void setFeeCurrency(String v){feeCurrency=v;}
|
||||
public BigDecimal getFeeAmount(){return feeAmount;} public void setFeeAmount(BigDecimal v){feeAmount=v;} public String getToAddress(){return toAddress;} public void setToAddress(String v){toAddress=v;}
|
||||
public Integer getStatus(){return status;} public void setStatus(Integer v){status=v;} public String getAuditType(){return auditType;} public void setAuditType(String v){auditType=v;}
|
||||
public String getAuditorId(){return auditorId;} public void setAuditorId(String v){auditorId=v;} public String getAuditRemark(){return auditRemark;} public void setAuditRemark(String v){auditRemark=v;}
|
||||
public Date getAuditedAt(){return auditedAt;} public void setAuditedAt(Date v){auditedAt=v;} public String getBlockTransactionId(){return blockTransactionId;} public void setBlockTransactionId(String v){blockTransactionId=v;}
|
||||
public String getExecuteError(){return executeError;} public void setExecuteError(String v){executeError=v;} public Integer getExecuteCount(){return executeCount;} public void setExecuteCount(Integer v){executeCount=v;}
|
||||
public Date getExecutedAt(){return executedAt;} public void setExecutedAt(Date v){executedAt=v;} public Date getConfirmedAt(){return confirmedAt;} public void setConfirmedAt(Date v){confirmedAt=v;}
|
||||
public String getNotifyUrl(){return notifyUrl;} public void setNotifyUrl(String v){notifyUrl=v;} public String getRedirectUrl(){return redirectUrl;} public void setRedirectUrl(String v){redirectUrl=v;}
|
||||
public Integer getCallbackNum(){return callbackNum;} public void setCallbackNum(Integer v){callbackNum=v;} public Integer getCallbackConfirm(){return callbackConfirm;} public void setCallbackConfirm(Integer v){callbackConfirm=v;}
|
||||
public Date getCreatedAt(){return createdAt;} public void setCreatedAt(Date v){createdAt=v;} public Date getUpdatedAt(){return updatedAt;} public void setUpdatedAt(Date v){updatedAt=v;} public Date getDeletedAt(){return deletedAt;} public void setDeletedAt(Date v){deletedAt=v;}
|
||||
|
||||
/** 代付订单ID */
|
||||
private Long id;
|
||||
|
||||
/** 平台代付交易号 */
|
||||
@Excel(name = "平台代付交易号")
|
||||
private String tradeId;
|
||||
|
||||
/** 商户代付订单号 */
|
||||
@Excel(name = "商户代付订单号")
|
||||
private String orderId;
|
||||
|
||||
/** 应用ID */
|
||||
@Excel(name = "应用ID")
|
||||
private Long appId;
|
||||
|
||||
/** 应用所属用户ID */
|
||||
@Excel(name = "应用所属用户ID")
|
||||
private Long userId;
|
||||
|
||||
/** 代付币种:USDT、TRX */
|
||||
@Excel(name = "代付币种:USDT、TRX")
|
||||
private String currency;
|
||||
|
||||
/** 代付本金 */
|
||||
@Excel(name = "代付本金")
|
||||
private BigDecimal amount;
|
||||
|
||||
/** 手续费币种,固定TRX */
|
||||
@Excel(name = "手续费币种,固定TRX")
|
||||
private String feeCurrency;
|
||||
|
||||
/** 代付手续费 */
|
||||
@Excel(name = "代付手续费")
|
||||
private BigDecimal feeAmount;
|
||||
|
||||
/** 收款TRON地址 */
|
||||
@Excel(name = "收款TRON地址")
|
||||
private String toAddress;
|
||||
|
||||
/** 0待审核 1待执行 2广播中 3已完成 4已拒绝 5执行失败 */
|
||||
@Excel(name = "0待审核 1待执行 2广播中 3已完成 4已拒绝 5执行失败")
|
||||
private Integer status;
|
||||
|
||||
/** 审核渠道:BACKOFFICE、TELEGRAM */
|
||||
@Excel(name = "审核渠道:BACKOFFICE、TELEGRAM")
|
||||
private String auditType;
|
||||
|
||||
/** 审核人标识 */
|
||||
@Excel(name = "审核人标识")
|
||||
private String auditorId;
|
||||
|
||||
/** 审核备注 */
|
||||
@Excel(name = "审核备注")
|
||||
private String auditRemark;
|
||||
|
||||
/** 审核时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "审核时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date auditedAt;
|
||||
|
||||
/** 链上交易哈希 */
|
||||
@Excel(name = "链上交易哈希")
|
||||
private String blockTransactionId;
|
||||
|
||||
/** 最近执行错误 */
|
||||
@Excel(name = "最近执行错误")
|
||||
private String executeError;
|
||||
|
||||
/** 执行次数 */
|
||||
@Excel(name = "执行次数")
|
||||
private Integer executeCount;
|
||||
|
||||
/** 广播时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "广播时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date executedAt;
|
||||
|
||||
/** 链上确认时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "链上确认时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date confirmedAt;
|
||||
|
||||
/** 异步通知地址 */
|
||||
@Excel(name = "异步通知地址")
|
||||
private String notifyUrl;
|
||||
|
||||
/** 同步跳转地址 */
|
||||
@Excel(name = "同步跳转地址")
|
||||
private String redirectUrl;
|
||||
|
||||
/** 通知尝试次数 */
|
||||
@Excel(name = "通知尝试次数")
|
||||
private Integer callbackNum;
|
||||
|
||||
/** 0未确认 1已确认 */
|
||||
@Excel(name = "0未确认 1已确认")
|
||||
private Integer callbackConfirm;
|
||||
|
||||
/** $column.columnComment */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "0未确认 1已确认", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date createdAt;
|
||||
|
||||
/** $column.columnComment */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "0未确认 1已确认", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date updatedAt;
|
||||
|
||||
/** $column.columnComment */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "0未确认 1已确认", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date deletedAt;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public void setTradeId(String tradeId)
|
||||
{
|
||||
this.tradeId = tradeId;
|
||||
}
|
||||
|
||||
public String getTradeId()
|
||||
{
|
||||
return tradeId;
|
||||
}
|
||||
public void setOrderId(String orderId)
|
||||
{
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getOrderId()
|
||||
{
|
||||
return orderId;
|
||||
}
|
||||
public void setAppId(Long appId)
|
||||
{
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public Long getAppId()
|
||||
{
|
||||
return appId;
|
||||
}
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
public void setCurrency(String currency)
|
||||
{
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
public String getCurrency()
|
||||
{
|
||||
return currency;
|
||||
}
|
||||
public void setAmount(BigDecimal amount)
|
||||
{
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount()
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
public void setFeeCurrency(String feeCurrency)
|
||||
{
|
||||
this.feeCurrency = feeCurrency;
|
||||
}
|
||||
|
||||
public String getFeeCurrency()
|
||||
{
|
||||
return feeCurrency;
|
||||
}
|
||||
public void setFeeAmount(BigDecimal feeAmount)
|
||||
{
|
||||
this.feeAmount = feeAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getFeeAmount()
|
||||
{
|
||||
return feeAmount;
|
||||
}
|
||||
public void setToAddress(String toAddress)
|
||||
{
|
||||
this.toAddress = toAddress;
|
||||
}
|
||||
|
||||
public String getToAddress()
|
||||
{
|
||||
return toAddress;
|
||||
}
|
||||
public void setStatus(Integer status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
public void setAuditType(String auditType)
|
||||
{
|
||||
this.auditType = auditType;
|
||||
}
|
||||
|
||||
public String getAuditType()
|
||||
{
|
||||
return auditType;
|
||||
}
|
||||
public void setAuditorId(String auditorId)
|
||||
{
|
||||
this.auditorId = auditorId;
|
||||
}
|
||||
|
||||
public String getAuditorId()
|
||||
{
|
||||
return auditorId;
|
||||
}
|
||||
public void setAuditRemark(String auditRemark)
|
||||
{
|
||||
this.auditRemark = auditRemark;
|
||||
}
|
||||
|
||||
public String getAuditRemark()
|
||||
{
|
||||
return auditRemark;
|
||||
}
|
||||
public void setAuditedAt(Date auditedAt)
|
||||
{
|
||||
this.auditedAt = auditedAt;
|
||||
}
|
||||
|
||||
public Date getAuditedAt()
|
||||
{
|
||||
return auditedAt;
|
||||
}
|
||||
public void setBlockTransactionId(String blockTransactionId)
|
||||
{
|
||||
this.blockTransactionId = blockTransactionId;
|
||||
}
|
||||
|
||||
public String getBlockTransactionId()
|
||||
{
|
||||
return blockTransactionId;
|
||||
}
|
||||
public void setExecuteError(String executeError)
|
||||
{
|
||||
this.executeError = executeError;
|
||||
}
|
||||
|
||||
public String getExecuteError()
|
||||
{
|
||||
return executeError;
|
||||
}
|
||||
public void setExecuteCount(Integer executeCount)
|
||||
{
|
||||
this.executeCount = executeCount;
|
||||
}
|
||||
|
||||
public Integer getExecuteCount()
|
||||
{
|
||||
return executeCount;
|
||||
}
|
||||
public void setExecutedAt(Date executedAt)
|
||||
{
|
||||
this.executedAt = executedAt;
|
||||
}
|
||||
|
||||
public Date getExecutedAt()
|
||||
{
|
||||
return executedAt;
|
||||
}
|
||||
public void setConfirmedAt(Date confirmedAt)
|
||||
{
|
||||
this.confirmedAt = confirmedAt;
|
||||
}
|
||||
|
||||
public Date getConfirmedAt()
|
||||
{
|
||||
return confirmedAt;
|
||||
}
|
||||
public void setNotifyUrl(String notifyUrl)
|
||||
{
|
||||
this.notifyUrl = notifyUrl;
|
||||
}
|
||||
|
||||
public String getNotifyUrl()
|
||||
{
|
||||
return notifyUrl;
|
||||
}
|
||||
public void setRedirectUrl(String redirectUrl)
|
||||
{
|
||||
this.redirectUrl = redirectUrl;
|
||||
}
|
||||
|
||||
public String getRedirectUrl()
|
||||
{
|
||||
return redirectUrl;
|
||||
}
|
||||
public void setCallbackNum(Integer callbackNum)
|
||||
{
|
||||
this.callbackNum = callbackNum;
|
||||
}
|
||||
|
||||
public Integer getCallbackNum()
|
||||
{
|
||||
return callbackNum;
|
||||
}
|
||||
public void setCallbackConfirm(Integer callbackConfirm)
|
||||
{
|
||||
this.callbackConfirm = callbackConfirm;
|
||||
}
|
||||
|
||||
public Integer getCallbackConfirm()
|
||||
{
|
||||
return callbackConfirm;
|
||||
}
|
||||
public void setCreatedAt(Date createdAt)
|
||||
{
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getCreatedAt()
|
||||
{
|
||||
return createdAt;
|
||||
}
|
||||
public void setUpdatedAt(Date updatedAt)
|
||||
{
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt()
|
||||
{
|
||||
return updatedAt;
|
||||
}
|
||||
public void setDeletedAt(Date deletedAt)
|
||||
{
|
||||
this.deletedAt = deletedAt;
|
||||
}
|
||||
|
||||
public Date getDeletedAt()
|
||||
{
|
||||
return deletedAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("tradeId", getTradeId())
|
||||
.append("orderId", getOrderId())
|
||||
.append("appId", getAppId())
|
||||
.append("userId", getUserId())
|
||||
.append("currency", getCurrency())
|
||||
.append("amount", getAmount())
|
||||
.append("feeCurrency", getFeeCurrency())
|
||||
.append("feeAmount", getFeeAmount())
|
||||
.append("toAddress", getToAddress())
|
||||
.append("status", getStatus())
|
||||
.append("auditType", getAuditType())
|
||||
.append("auditorId", getAuditorId())
|
||||
.append("auditRemark", getAuditRemark())
|
||||
.append("auditedAt", getAuditedAt())
|
||||
.append("blockTransactionId", getBlockTransactionId())
|
||||
.append("executeError", getExecuteError())
|
||||
.append("executeCount", getExecuteCount())
|
||||
.append("executedAt", getExecutedAt())
|
||||
.append("confirmedAt", getConfirmedAt())
|
||||
.append("notifyUrl", getNotifyUrl())
|
||||
.append("redirectUrl", getRedirectUrl())
|
||||
.append("callbackNum", getCallbackNum())
|
||||
.append("callbackConfirm", getCallbackConfirm())
|
||||
.append("createdAt", getCreatedAt())
|
||||
.append("updatedAt", getUpdatedAt())
|
||||
.append("deletedAt", getDeletedAt())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
/**
|
||||
* 应用代付订单对象 usdt_payout_order
|
||||
*
|
||||
* @author luqj
|
||||
* @date 2026-10-17
|
||||
*/
|
||||
@TableName(value = "usdt_payout_order")
|
||||
public class UsdtPayoutOrderPlus implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 代付订单ID */
|
||||
private Long id;
|
||||
/** 平台代付交易号 */
|
||||
@Excel(name = "平台代付交易号")
|
||||
private String tradeId;
|
||||
/** 商户代付订单号 */
|
||||
@Excel(name = "商户代付订单号")
|
||||
private String orderId;
|
||||
/** 应用ID */
|
||||
@Excel(name = "应用ID")
|
||||
private Long appId;
|
||||
/** 应用所属用户ID */
|
||||
@Excel(name = "应用所属用户ID")
|
||||
private Long userId;
|
||||
/** 代付币种:USDT、TRX */
|
||||
@Excel(name = "代付币种:USDT、TRX")
|
||||
private String currency;
|
||||
/** 代付本金 */
|
||||
@Excel(name = "代付本金")
|
||||
private BigDecimal amount;
|
||||
/** 手续费币种,固定TRX */
|
||||
@Excel(name = "手续费币种,固定TRX")
|
||||
private String feeCurrency;
|
||||
/** 代付手续费 */
|
||||
@Excel(name = "代付手续费")
|
||||
private BigDecimal feeAmount;
|
||||
/** 收款TRON地址 */
|
||||
@Excel(name = "收款TRON地址")
|
||||
private String toAddress;
|
||||
/** 0待审核 1待执行 2广播中 3已完成 4已拒绝 5执行失败 */
|
||||
@Excel(name = "0待审核 1待执行 2广播中 3已完成 4已拒绝 5执行失败")
|
||||
private Integer status;
|
||||
/** 审核渠道:BACKOFFICE、TELEGRAM */
|
||||
@Excel(name = "审核渠道:BACKOFFICE、TELEGRAM")
|
||||
private String auditType;
|
||||
/** 审核人标识 */
|
||||
@Excel(name = "审核人标识")
|
||||
private String auditorId;
|
||||
/** 审核备注 */
|
||||
@Excel(name = "审核备注")
|
||||
private String auditRemark;
|
||||
/** 审核时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "审核时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date auditedAt;
|
||||
/** 链上交易哈希 */
|
||||
@Excel(name = "链上交易哈希")
|
||||
private String blockTransactionId;
|
||||
/** 最近执行错误 */
|
||||
@Excel(name = "最近执行错误")
|
||||
private String executeError;
|
||||
/** 执行次数 */
|
||||
@Excel(name = "执行次数")
|
||||
private Integer executeCount;
|
||||
/** 广播时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "广播时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date executedAt;
|
||||
/** 链上确认时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "链上确认时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date confirmedAt;
|
||||
/** 异步通知地址 */
|
||||
@Excel(name = "异步通知地址")
|
||||
private String notifyUrl;
|
||||
/** 同步跳转地址 */
|
||||
@Excel(name = "同步跳转地址")
|
||||
private String redirectUrl;
|
||||
/** 通知尝试次数 */
|
||||
@Excel(name = "通知尝试次数")
|
||||
private Integer callbackNum;
|
||||
/** 0未确认 1已确认 */
|
||||
@Excel(name = "0未确认 1已确认")
|
||||
private Integer callbackConfirm;
|
||||
/** $column.columnComment */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "0未确认 1已确认", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date createdAt;
|
||||
/** $column.columnComment */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "0未确认 1已确认", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date updatedAt;
|
||||
/** $column.columnComment */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "0未确认 1已确认", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date deletedAt;
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public void setTradeId(String tradeId)
|
||||
{
|
||||
this.tradeId = tradeId;
|
||||
}
|
||||
|
||||
public String getTradeId()
|
||||
{
|
||||
return tradeId;
|
||||
}
|
||||
public void setOrderId(String orderId)
|
||||
{
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getOrderId()
|
||||
{
|
||||
return orderId;
|
||||
}
|
||||
public void setAppId(Long appId)
|
||||
{
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public Long getAppId()
|
||||
{
|
||||
return appId;
|
||||
}
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
public void setCurrency(String currency)
|
||||
{
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
public String getCurrency()
|
||||
{
|
||||
return currency;
|
||||
}
|
||||
public void setAmount(BigDecimal amount)
|
||||
{
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount()
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
public void setFeeCurrency(String feeCurrency)
|
||||
{
|
||||
this.feeCurrency = feeCurrency;
|
||||
}
|
||||
|
||||
public String getFeeCurrency()
|
||||
{
|
||||
return feeCurrency;
|
||||
}
|
||||
public void setFeeAmount(BigDecimal feeAmount)
|
||||
{
|
||||
this.feeAmount = feeAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getFeeAmount()
|
||||
{
|
||||
return feeAmount;
|
||||
}
|
||||
public void setToAddress(String toAddress)
|
||||
{
|
||||
this.toAddress = toAddress;
|
||||
}
|
||||
|
||||
public String getToAddress()
|
||||
{
|
||||
return toAddress;
|
||||
}
|
||||
public void setStatus(Integer status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
public void setAuditType(String auditType)
|
||||
{
|
||||
this.auditType = auditType;
|
||||
}
|
||||
|
||||
public String getAuditType()
|
||||
{
|
||||
return auditType;
|
||||
}
|
||||
public void setAuditorId(String auditorId)
|
||||
{
|
||||
this.auditorId = auditorId;
|
||||
}
|
||||
|
||||
public String getAuditorId()
|
||||
{
|
||||
return auditorId;
|
||||
}
|
||||
public void setAuditRemark(String auditRemark)
|
||||
{
|
||||
this.auditRemark = auditRemark;
|
||||
}
|
||||
|
||||
public String getAuditRemark()
|
||||
{
|
||||
return auditRemark;
|
||||
}
|
||||
public void setAuditedAt(Date auditedAt)
|
||||
{
|
||||
this.auditedAt = auditedAt;
|
||||
}
|
||||
|
||||
public Date getAuditedAt()
|
||||
{
|
||||
return auditedAt;
|
||||
}
|
||||
public void setBlockTransactionId(String blockTransactionId)
|
||||
{
|
||||
this.blockTransactionId = blockTransactionId;
|
||||
}
|
||||
|
||||
public String getBlockTransactionId()
|
||||
{
|
||||
return blockTransactionId;
|
||||
}
|
||||
public void setExecuteError(String executeError)
|
||||
{
|
||||
this.executeError = executeError;
|
||||
}
|
||||
|
||||
public String getExecuteError()
|
||||
{
|
||||
return executeError;
|
||||
}
|
||||
public void setExecuteCount(Integer executeCount)
|
||||
{
|
||||
this.executeCount = executeCount;
|
||||
}
|
||||
|
||||
public Integer getExecuteCount()
|
||||
{
|
||||
return executeCount;
|
||||
}
|
||||
public void setExecutedAt(Date executedAt)
|
||||
{
|
||||
this.executedAt = executedAt;
|
||||
}
|
||||
|
||||
public Date getExecutedAt()
|
||||
{
|
||||
return executedAt;
|
||||
}
|
||||
public void setConfirmedAt(Date confirmedAt)
|
||||
{
|
||||
this.confirmedAt = confirmedAt;
|
||||
}
|
||||
|
||||
public Date getConfirmedAt()
|
||||
{
|
||||
return confirmedAt;
|
||||
}
|
||||
public void setNotifyUrl(String notifyUrl)
|
||||
{
|
||||
this.notifyUrl = notifyUrl;
|
||||
}
|
||||
|
||||
public String getNotifyUrl()
|
||||
{
|
||||
return notifyUrl;
|
||||
}
|
||||
public void setRedirectUrl(String redirectUrl)
|
||||
{
|
||||
this.redirectUrl = redirectUrl;
|
||||
}
|
||||
|
||||
public String getRedirectUrl()
|
||||
{
|
||||
return redirectUrl;
|
||||
}
|
||||
public void setCallbackNum(Integer callbackNum)
|
||||
{
|
||||
this.callbackNum = callbackNum;
|
||||
}
|
||||
|
||||
public Integer getCallbackNum()
|
||||
{
|
||||
return callbackNum;
|
||||
}
|
||||
public void setCallbackConfirm(Integer callbackConfirm)
|
||||
{
|
||||
this.callbackConfirm = callbackConfirm;
|
||||
}
|
||||
|
||||
public Integer getCallbackConfirm()
|
||||
{
|
||||
return callbackConfirm;
|
||||
}
|
||||
public void setCreatedAt(Date createdAt)
|
||||
{
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getCreatedAt()
|
||||
{
|
||||
return createdAt;
|
||||
}
|
||||
public void setUpdatedAt(Date updatedAt)
|
||||
{
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt()
|
||||
{
|
||||
return updatedAt;
|
||||
}
|
||||
public void setDeletedAt(Date deletedAt)
|
||||
{
|
||||
this.deletedAt = deletedAt;
|
||||
}
|
||||
|
||||
public Date getDeletedAt()
|
||||
{
|
||||
return deletedAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("tradeId", getTradeId())
|
||||
.append("orderId", getOrderId())
|
||||
.append("appId", getAppId())
|
||||
.append("userId", getUserId())
|
||||
.append("currency", getCurrency())
|
||||
.append("amount", getAmount())
|
||||
.append("feeCurrency", getFeeCurrency())
|
||||
.append("feeAmount", getFeeAmount())
|
||||
.append("toAddress", getToAddress())
|
||||
.append("status", getStatus())
|
||||
.append("auditType", getAuditType())
|
||||
.append("auditorId", getAuditorId())
|
||||
.append("auditRemark", getAuditRemark())
|
||||
.append("auditedAt", getAuditedAt())
|
||||
.append("blockTransactionId", getBlockTransactionId())
|
||||
.append("executeError", getExecuteError())
|
||||
.append("executeCount", getExecuteCount())
|
||||
.append("executedAt", getExecutedAt())
|
||||
.append("confirmedAt", getConfirmedAt())
|
||||
.append("notifyUrl", getNotifyUrl())
|
||||
.append("redirectUrl", getRedirectUrl())
|
||||
.append("callbackNum", getCallbackNum())
|
||||
.append("callbackConfirm", getCallbackConfirm())
|
||||
.append("createdAt", getCreatedAt())
|
||||
.append("updatedAt", getUpdatedAt())
|
||||
.append("deletedAt", getDeletedAt())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,46 @@ package com.ruoyi.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrder;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrderPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
public interface UsdtPayoutOrderMapper extends BaseMapper<UsdtPayoutOrder> {
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public interface UsdtPayoutOrderMapper extends BaseMapper<UsdtPayoutOrderPlus> {
|
||||
@Select("select * from usdt_payout_order where id=#{id} and deleted_at is null for update")
|
||||
UsdtPayoutOrder selectByIdForUpdate(@Param("id") Long id);
|
||||
UsdtPayoutOrderPlus selectByIdForUpdate(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 查询应用当前未终结订单;调用方已持有应用行锁,保证创建串行化。
|
||||
*/
|
||||
@Select("select * from usdt_payout_order where app_id=#{appId} "
|
||||
+ "and status in (0,1,2,5,6) and deleted_at is null order by id asc limit 1")
|
||||
UsdtPayoutOrderPlus selectActiveByAppId(@Param("appId") Long appId);
|
||||
|
||||
/**
|
||||
* 审核通过前检查该应用是否已有进入执行流程的其他订单。
|
||||
*/
|
||||
@Select("select * from usdt_payout_order where app_id=#{appId} and id<>#{excludeId} "
|
||||
+ "and status in (1,2,5,6) and deleted_at is null order by id asc limit 1")
|
||||
UsdtPayoutOrderPlus selectExecutingByAppId(@Param("appId") Long appId,
|
||||
@Param("excludeId") Long excludeId);
|
||||
|
||||
/**
|
||||
* 未终结订单对主钱包指定币种本金的占用。
|
||||
*/
|
||||
@Select("select coalesce(sum(amount),0) from usdt_payout_order "
|
||||
+ "where currency=#{currency} and status in (0,1,2,5,6) and deleted_at is null")
|
||||
BigDecimal sumActivePrincipal(@Param("currency") String currency);
|
||||
|
||||
/**
|
||||
* 未终结订单对主钱包 TRX 手续费预算的占用。
|
||||
*/
|
||||
@Select("select coalesce(sum(fee_amount),0) from usdt_payout_order "
|
||||
+ "where status in (0,1,2,5,6) and deleted_at is null")
|
||||
BigDecimal sumActiveTrxFee();
|
||||
|
||||
/**
|
||||
* 原子领取待广播订单。允许失败订单在重新输入配置密码后重试,防止并发请求重复广播。
|
||||
@@ -20,7 +53,9 @@ public interface UsdtPayoutOrderMapper extends BaseMapper<UsdtPayoutOrder> {
|
||||
@Param("failedStatus") Integer failedStatus,
|
||||
@Param("processingStatus") Integer processingStatus);
|
||||
|
||||
/** 多实例定时任务通过当前重试次数领取一次通知机会。 */
|
||||
/**
|
||||
* 多实例定时任务通过当前重试次数领取一次通知机会。
|
||||
*/
|
||||
@Update("update usdt_payout_order set callback_num=callback_num+1, updated_at=now() "
|
||||
+ "where id=#{id} and status=#{completedStatus} and callback_confirm=0 "
|
||||
+ "and callback_num=#{callbackNum} and deleted_at is null")
|
||||
@@ -31,4 +66,54 @@ public interface UsdtPayoutOrderMapper extends BaseMapper<UsdtPayoutOrder> {
|
||||
@Update("update usdt_payout_order set callback_confirm=1, updated_at=now() "
|
||||
+ "where id=#{id} and callback_confirm=0 and deleted_at is null")
|
||||
int confirmCallback(@Param("id") Long id);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询应用代付订单
|
||||
*
|
||||
* @param id 应用代付订单ID
|
||||
* @return 应用代付订单
|
||||
*/
|
||||
public UsdtPayoutOrder selectUsdtPayoutOrderById(Long id);
|
||||
|
||||
/**
|
||||
* 查询应用代付订单列表
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 应用代付订单集合
|
||||
*/
|
||||
public List<UsdtPayoutOrder> selectUsdtPayoutOrderList(UsdtPayoutOrder usdtPayoutOrder);
|
||||
|
||||
/**
|
||||
* 新增应用代付订单
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertUsdtPayoutOrder(UsdtPayoutOrder usdtPayoutOrder);
|
||||
|
||||
/**
|
||||
* 修改应用代付订单
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateUsdtPayoutOrder(UsdtPayoutOrder usdtPayoutOrder);
|
||||
|
||||
/**
|
||||
* 删除应用代付订单
|
||||
*
|
||||
* @param id 应用代付订单ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUsdtPayoutOrderById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除应用代付订单
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUsdtPayoutOrderByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.ruoyi.system.service;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrder;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrderPlus;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.ruoyi.common.select.SelectItem;
|
||||
/**
|
||||
* 应用代付订单Service接口
|
||||
*
|
||||
* @author luqj
|
||||
* @date 2026-10-17
|
||||
*/
|
||||
public interface IUsdtPayoutOrderService extends IService<UsdtPayoutOrderPlus>
|
||||
{
|
||||
|
||||
List<SelectItem> select(String keyword,boolean isUser);
|
||||
/**
|
||||
* 查询应用代付订单
|
||||
*
|
||||
* @param id 应用代付订单ID
|
||||
* @return 应用代付订单
|
||||
*/
|
||||
public UsdtPayoutOrder selectUsdtPayoutOrderById(Long id,boolean isUser);
|
||||
|
||||
/**
|
||||
* 查询应用代付订单列表
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 应用代付订单集合
|
||||
*/
|
||||
public List<UsdtPayoutOrder> selectUsdtPayoutOrderList(UsdtPayoutOrder usdtPayoutOrder,boolean isUser);
|
||||
|
||||
/**
|
||||
* 新增应用代付订单
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertUsdtPayoutOrder(UsdtPayoutOrder usdtPayoutOrder,boolean isUser);
|
||||
|
||||
/**
|
||||
* 修改应用代付订单
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateUsdtPayoutOrder(UsdtPayoutOrder usdtPayoutOrder,boolean isUser);
|
||||
|
||||
/**
|
||||
* 批量删除应用代付订单
|
||||
*
|
||||
* @param ids 需要删除的应用代付订单ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUsdtPayoutOrderByIds(Long[] ids,boolean isUser);
|
||||
|
||||
/**
|
||||
* 删除应用代付订单信息
|
||||
*
|
||||
* @param id 应用代付订单ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUsdtPayoutOrderById(Long id,boolean isUser);
|
||||
|
||||
List<UsdtPayoutOrderPlus> getByIds(List<Long> ids,boolean isUser, SFunction<UsdtPayoutOrderPlus, ?>... columns);
|
||||
|
||||
UsdtPayoutOrderPlus getById(Long id, SFunction<UsdtPayoutOrderPlus, ?>... columns);
|
||||
|
||||
Map<Long, UsdtPayoutOrderPlus> getMapByIds(List<Long> ids, SFunction<UsdtPayoutOrderPlus, ?>... columns);
|
||||
|
||||
List<UsdtPayoutOrderPlus> getByIds(List<Long> ids);
|
||||
|
||||
Map<Long, UsdtPayoutOrderPlus> getMapByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* @param field sum 字段
|
||||
* @param where 条件
|
||||
* @param tClass 返回类型
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
<T> T sum(String field, String where, Class<T> tClass);
|
||||
|
||||
Long count(String where);
|
||||
|
||||
<T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass);
|
||||
}
|
||||
@@ -2,31 +2,126 @@ package com.ruoyi.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.AppApiKeysPlus;
|
||||
import com.ruoyi.system.domain.AppsPlus;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrder;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrderPlus;
|
||||
import com.ruoyi.system.mapper.UsdtPayoutOrderMapper;
|
||||
import com.ruoyi.system.security.RsaKeyUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.security.PrivateKey;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/** 代付完成后的RSA签名同步地址和平台主动异步通知。 */
|
||||
/**
|
||||
* 代付完成后的RSA签名同步地址和平台主动异步通知。
|
||||
*/
|
||||
@Service
|
||||
public class PayoutCallbackService {
|
||||
@Autowired private IAppsService apps; @Autowired private IAppApiKeysService keys;
|
||||
@Autowired private AppPrivateKeyCipher cipher; @Autowired private UsdtPayoutOrderMapper mapper;
|
||||
@Autowired
|
||||
private IAppsService apps;
|
||||
@Autowired
|
||||
private IAppApiKeysService keys;
|
||||
@Autowired
|
||||
private AppPrivateKeyCipher cipher;
|
||||
@Autowired
|
||||
private UsdtPayoutOrderMapper mapper;
|
||||
private final RestTemplate http;
|
||||
public PayoutCallbackService(){SimpleClientHttpRequestFactory f=new SimpleClientHttpRequestFactory();f.setConnectTimeout(60000);f.setReadTimeout(60000);http=new RestTemplate(f);}
|
||||
public String signedRedirect(UsdtPayoutOrder o,String apiKey){if(o==null||!Integer.valueOf(PayoutOrderService.COMPLETED).equals(o.getStatus())||blank(o.getRedirectUrl()))return null;return append(o.getRedirectUrl(),values(o),apiKey,sign(o));}
|
||||
@Scheduled(fixedDelay=10000L) public void notifyCompleted(){List<UsdtPayoutOrder> list=mapper.selectList(new LambdaQueryWrapper<UsdtPayoutOrder>().eq(UsdtPayoutOrder::getStatus,PayoutOrderService.COMPLETED).eq(UsdtPayoutOrder::getCallbackConfirm,0).lt(UsdtPayoutOrder::getCallbackNum,10).isNull(UsdtPayoutOrder::getDeletedAt).last("limit 50"));for(UsdtPayoutOrder o:list){int callbackNum=o.getCallbackNum()==null?0:o.getCallbackNum();if(mapper.claimCallback(o.getId(),PayoutOrderService.COMPLETED,callbackNum)!=1)continue;try{AppApiKeysPlus k=activeKey(o.getAppId());Map<String,Object> body=values(o);HttpHeaders h=new HttpHeaders();h.setContentType(MediaType.APPLICATION_JSON);h.set("X-Payment-Api-Key",k.getApiKey());h.set("X-Payment-Rsa-Signature",sign(o));ResponseEntity<String> r=http.postForEntity(o.getNotifyUrl(),new HttpEntity<Map<String,Object>>(body,h),String.class);if(r.getStatusCode().is2xxSuccessful()&&"ok".equalsIgnoreCase(r.getBody()==null?"":r.getBody().trim()))mapper.confirmCallback(o.getId());}catch(Exception ignored){}}}
|
||||
private Map<String,Object> values(UsdtPayoutOrder o){Map<String,Object> m=new TreeMap<>();m.put("order_id",o.getOrderId());m.put("trade_id",o.getTradeId());m.put("status",o.getStatus());m.put("transaction_id",o.getBlockTransactionId());m.put("currency",o.getCurrency());m.put("amount",o.getAmount());m.put("fee_currency",o.getFeeCurrency());m.put("fee_amount",o.getFeeAmount());m.put("to_address",o.getToAddress());return m;}
|
||||
private String sign(UsdtPayoutOrder o){try{AppsPlus a=apps.getById(o.getAppId());if(a==null||blank(a.getPrivateKey()))throw new CustomException("应用RSA私钥不存在");PrivateKey p=RsaKeyUtil.loadPrivateKey(cipher.decrypt(a.getPrivateKey()));return PaymentSignatureService.signRsa(values(o),p);}catch(Exception e){throw new CustomException("代付回调签名失败");}}
|
||||
private AppApiKeysPlus activeKey(Long appId){AppApiKeysPlus k=keys.getOne(new LambdaQueryWrapper<AppApiKeysPlus>().eq(AppApiKeysPlus::getAppId,appId).eq(AppApiKeysPlus::getStatus,1).isNull(AppApiKeysPlus::getDeletedAt).and(w->w.isNull(AppApiKeysPlus::getExpiredAt).or().gt(AppApiKeysPlus::getExpiredAt,new Date())).last("limit 1"));if(k==null)throw new CustomException("应用API Key不存在");return k;}
|
||||
private String append(String base,Map<String,Object> values,String apiKey,String signature){try{int fragmentIndex=base.indexOf('#');String fragment=fragmentIndex>=0?base.substring(fragmentIndex):"";String target=fragmentIndex>=0?base.substring(0,fragmentIndex):base;StringBuilder b=new StringBuilder(target);b.append(target.contains("?")?'&':'?');for(Map.Entry<String,Object> e:values.entrySet())b.append(URLEncoder.encode(e.getKey(),"UTF-8")).append('=').append(URLEncoder.encode(String.valueOf(e.getValue()),"UTF-8")).append('&');b.append("api_key=").append(URLEncoder.encode(apiKey,"UTF-8")).append("&signature=").append(URLEncoder.encode(signature,"UTF-8"));return b.append(fragment).toString();}catch(Exception e){throw new CustomException("代付跳转地址生成失败");}}
|
||||
private boolean blank(String s){return s==null||s.trim().isEmpty();}
|
||||
|
||||
public PayoutCallbackService() {
|
||||
SimpleClientHttpRequestFactory f = new SimpleClientHttpRequestFactory();
|
||||
f.setConnectTimeout(60000);
|
||||
f.setReadTimeout(60000);
|
||||
http = new RestTemplate(f);
|
||||
}
|
||||
|
||||
public String signedRedirect(UsdtPayoutOrderPlus o, String apiKey) {
|
||||
if (o == null || !Integer.valueOf(PayoutOrderService.COMPLETED).equals(o.getStatus()) || blank(o.getRedirectUrl()))
|
||||
return null;
|
||||
return append(o.getRedirectUrl(), values(o), apiKey, sign(o));
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 10000L)
|
||||
public void notifyCompleted() {
|
||||
List<UsdtPayoutOrderPlus> list = mapper.selectList(new LambdaQueryWrapper<UsdtPayoutOrderPlus>().eq(UsdtPayoutOrderPlus::getStatus, PayoutOrderService.COMPLETED).eq(UsdtPayoutOrderPlus::getCallbackConfirm, 0).lt(UsdtPayoutOrderPlus::getCallbackNum, 10).isNull(UsdtPayoutOrderPlus::getDeletedAt).last("limit 50"));
|
||||
for (UsdtPayoutOrderPlus o : list) {
|
||||
int callbackNum = o.getCallbackNum() == null ? 0 : o.getCallbackNum();
|
||||
if (mapper.claimCallback(o.getId(), PayoutOrderService.COMPLETED, callbackNum) != 1) continue;
|
||||
try {
|
||||
AppApiKeysPlus k = activeKey(o.getAppId());
|
||||
Map<String, Object> body = values(o);
|
||||
HttpHeaders h = new HttpHeaders();
|
||||
h.setContentType(MediaType.APPLICATION_JSON);
|
||||
h.set("X-Payment-Api-Key", k.getApiKey());
|
||||
h.set("X-Payment-Rsa-Signature", sign(o));
|
||||
ResponseEntity<String> r = http.postForEntity(o.getNotifyUrl(), new HttpEntity<Map<String, Object>>(body, h), String.class);
|
||||
if (r.getStatusCode().is2xxSuccessful() && "ok".equalsIgnoreCase(r.getBody() == null ? "" : r.getBody().trim()))
|
||||
mapper.confirmCallback(o.getId());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> values(UsdtPayoutOrderPlus o) {
|
||||
Map<String, Object> m = new TreeMap<>();
|
||||
m.put("order_id", o.getOrderId());
|
||||
m.put("trade_id", o.getTradeId());
|
||||
m.put("status", o.getStatus());
|
||||
m.put("transaction_id", o.getBlockTransactionId());
|
||||
m.put("currency", o.getCurrency());
|
||||
m.put("amount", o.getAmount());
|
||||
m.put("fee_currency", o.getFeeCurrency());
|
||||
m.put("fee_amount", o.getFeeAmount());
|
||||
m.put("to_address", o.getToAddress());
|
||||
return m;
|
||||
}
|
||||
|
||||
private String sign(UsdtPayoutOrderPlus o) {
|
||||
try {
|
||||
AppsPlus a = apps.getById(o.getAppId());
|
||||
if (a == null || blank(a.getPrivateKey())) throw new CustomException("应用RSA私钥不存在");
|
||||
PrivateKey p = RsaKeyUtil.loadPrivateKey(cipher.decrypt(a.getPrivateKey()));
|
||||
return PaymentSignatureService.signRsa(values(o), p);
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("代付回调签名失败");
|
||||
}
|
||||
}
|
||||
|
||||
private AppApiKeysPlus activeKey(Long appId) {
|
||||
AppApiKeysPlus k = keys.getOne(new LambdaQueryWrapper<AppApiKeysPlus>().eq(AppApiKeysPlus::getAppId, appId).eq(AppApiKeysPlus::getStatus, 1).isNull(AppApiKeysPlus::getDeletedAt).and(w -> w.isNull(AppApiKeysPlus::getExpiredAt).or().gt(AppApiKeysPlus::getExpiredAt, new Date())).last("limit 1"));
|
||||
if (k == null) throw new CustomException("应用API Key不存在");
|
||||
return k;
|
||||
}
|
||||
|
||||
private String append(String base, Map<String, Object> values, String apiKey, String signature) {
|
||||
try {
|
||||
int fragmentIndex = base.indexOf('#');
|
||||
String fragment = fragmentIndex >= 0 ? base.substring(fragmentIndex) : "";
|
||||
String target = fragmentIndex >= 0 ? base.substring(0, fragmentIndex) : base;
|
||||
StringBuilder b = new StringBuilder(target);
|
||||
b.append(target.contains("?") ? '&' : '?');
|
||||
for (Map.Entry<String, Object> e : values.entrySet())
|
||||
b.append(URLEncoder.encode(e.getKey(), "UTF-8")).append('=').append(URLEncoder.encode(String.valueOf(e.getValue()), "UTF-8")).append('&');
|
||||
b.append("api_key=").append(URLEncoder.encode(apiKey, "UTF-8")).append("&signature=").append(URLEncoder.encode(signature, "UTF-8"));
|
||||
return b.append(fragment).toString();
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("代付跳转地址生成失败");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean blank(String s) {
|
||||
return s == null || s.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -3,62 +3,220 @@ package com.ruoyi.system.service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.system.domain.Apps;
|
||||
import com.ruoyi.system.domain.UsdtConfigPlus;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrder;
|
||||
import com.ruoyi.system.domain.UsdtConfig;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrderPlus;
|
||||
import com.ruoyi.system.domain.vo.DecryptResult;
|
||||
import com.ruoyi.system.mapper.AppsMapper;
|
||||
import com.ruoyi.system.mapper.UsdtConfigMapper;
|
||||
import com.ruoyi.system.mapper.UsdtPayoutOrderMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/** 代付创建、审核及余额冻结状态机;所有余额修改均先锁定应用行。 */
|
||||
/**
|
||||
* 代付创建、审核及余额冻结状态机;所有余额修改均先锁定应用行。
|
||||
*/
|
||||
@Service
|
||||
public class PayoutOrderService {
|
||||
public static final int PENDING_AUDIT=0, PENDING_EXECUTE=1, BROADCASTED=2,
|
||||
COMPLETED=3, REJECTED=4, EXECUTE_FAILED=5;
|
||||
@Autowired private AppsMapper appsMapper;
|
||||
@Autowired private UsdtConfigMapper configMapper;
|
||||
@Autowired private UsdtPayoutOrderMapper payoutMapper;
|
||||
@Autowired private ApplicationEventPublisher eventPublisher;
|
||||
public static final int PENDING_AUDIT = 0, PENDING_EXECUTE = 1, BROADCASTED = 2,
|
||||
COMPLETED = 3, REJECTED = 4, EXECUTE_FAILED = 5;
|
||||
@Autowired
|
||||
private AppsMapper appsMapper;
|
||||
@Autowired
|
||||
private UsdtConfigMapper configMapper;
|
||||
@Autowired
|
||||
private UsdtPayoutOrderMapper payoutMapper;
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public UsdtPayoutOrder create(DecryptResult request) {
|
||||
Map<String,String> p=parse(request.getPlainData());
|
||||
String orderId=required(p,"order_id"), currency=required(p,"currency").toUpperCase();
|
||||
String address=required(p,"to_address"), notifyUrl=required(p,"notify_url"), redirectUrl=trim(p.get("redirect_url"));
|
||||
if(!"USDT".equals(currency)&&!"TRX".equals(currency))throw new CustomException("currency仅支持USDT或TRX");
|
||||
if(!address.matches("T[1-9A-HJ-NP-Za-km-z]{33}"))throw new CustomException("收款地址格式错误");
|
||||
if(orderId.length()>64)throw new CustomException("order_id长度不能超过64");
|
||||
validateUrl(notifyUrl,true);validateUrl(redirectUrl,false);BigDecimal amount=amount(required(p,"amount"));
|
||||
Apps app=appsMapper.selectAppsByIdForUpdate(request.getAppId());
|
||||
if(app==null||!Integer.valueOf(1).equals(app.getStatus())||!Objects.equals(app.getUserId(),request.getUserId()))throw new CustomException("商户应用不可用");
|
||||
UsdtPayoutOrder old=find(app.getId(),orderId);if(old!=null)return old;
|
||||
UsdtConfigPlus cfg=configMapper.selectOne(new LambdaQueryWrapper<UsdtConfigPlus>().orderByAsc(UsdtConfigPlus::getId).last("limit 1"));
|
||||
BigDecimal fee=cfg==null||cfg.getPayUsdtNum()==null?BigDecimal.ZERO:cfg.getPayUsdtNum().setScale(6,RoundingMode.UNNECESSARY);
|
||||
if(fee.signum()<0)throw new CustomException("代付手续费配置不能小于0");
|
||||
BigDecimal ub=z(app.getUsdtBalance()),tb=z(app.getTrxBalance()),uf=z(app.getUsdtFrozenBalance()),tf=z(app.getTrxFrozenBalance());
|
||||
if("USDT".equals(currency)){if(ub.compareTo(amount)<0)throw new CustomException("USDT可用余额不足");if(tb.compareTo(fee)<0)throw new CustomException("TRX手续费余额不足");ub=ub.subtract(amount);uf=uf.add(amount);tb=tb.subtract(fee);tf=tf.add(fee);}
|
||||
else {BigDecimal total=amount.add(fee);if(tb.compareTo(total)<0)throw new CustomException("TRX可用余额不足");tb=tb.subtract(total);tf=tf.add(total);}
|
||||
Date now=new Date();if(appsMapper.updatePayoutBalances(app.getId(),ub,tb,uf,tf,now)!=1)throw new CustomException("冻结余额失败");
|
||||
UsdtPayoutOrder o=new UsdtPayoutOrder();o.setTradeId(UUID.randomUUID().toString().replace("-",""));o.setOrderId(orderId);o.setAppId(app.getId());o.setUserId(app.getUserId());o.setCurrency(currency);o.setAmount(amount);o.setFeeCurrency("TRX");o.setFeeAmount(fee);o.setToAddress(address);o.setStatus(PENDING_AUDIT);o.setNotifyUrl(notifyUrl);o.setRedirectUrl(redirectUrl);o.setCallbackNum(0);o.setCallbackConfirm(0);o.setExecuteCount(0);o.setCreatedAt(now);o.setUpdatedAt(now);payoutMapper.insert(o);eventPublisher.publishEvent(new TelegramPayoutAuditEvent(o.getId(),o.getOrderId(),o.getCurrency(),o.getAmount().toPlainString(),o.getToAddress(),o.getFeeAmount().toPlainString()));return o;
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UsdtPayoutOrderPlus create(DecryptResult request) {
|
||||
Map<String, String> p = parse(request.getPlainData());
|
||||
String orderId = required(p, "order_id"), currency = required(p, "currency").toUpperCase();
|
||||
String address = required(p, "to_address"), notifyUrl = required(p, "notify_url"), redirectUrl = trim(p.get("redirect_url"));
|
||||
if (!"USDT".equals(currency) && !"TRX".equals(currency)) throw new CustomException("currency仅支持USDT或TRX");
|
||||
if (!address.matches("T[1-9A-HJ-NP-Za-km-z]{33}")) throw new CustomException("收款地址格式错误");
|
||||
if (orderId.length() > 64) throw new CustomException("order_id长度不能超过64");
|
||||
validateUrl(notifyUrl, true);
|
||||
validateUrl(redirectUrl, false);
|
||||
BigDecimal amount = amount(required(p, "amount"));
|
||||
Apps app = appsMapper.selectAppsByIdForUpdate(request.getAppId());
|
||||
if (app == null || !Integer.valueOf(1).equals(app.getStatus()) || !Objects.equals(app.getUserId(), request.getUserId()))
|
||||
throw new CustomException("商户应用不可用");
|
||||
UsdtPayoutOrderPlus old = find(app.getId(), orderId);
|
||||
if (old != null) return old;
|
||||
UsdtPayoutOrderPlus active = payoutMapper.selectActiveByAppId(app.getId());
|
||||
if (active != null) throw new CustomException("该应用已有未完成的代付订单,订单号:" + active.getOrderId());
|
||||
UsdtConfig cfg = configMapper.selectFirstForUpdate();
|
||||
if (cfg == null) throw new CustomException("全局配置不存在");
|
||||
BigDecimal fee = cfg.getPayUsdtNum() == null ? BigDecimal.ZERO : cfg.getPayUsdtNum().setScale(6, RoundingMode.UNNECESSARY);
|
||||
if (fee.signum() < 0) throw new CustomException("代付手续费配置不能小于0");
|
||||
BigDecimal ub = z(app.getUsdtBalance()), tb = z(app.getTrxBalance()), uf = z(app.getUsdtFrozenBalance()), tf = z(app.getTrxFrozenBalance());
|
||||
BigDecimal reservedUsdt = z(payoutMapper.sumActivePrincipal("USDT"));
|
||||
BigDecimal reservedTrx = z(payoutMapper.sumActivePrincipal("TRX")).add(z(payoutMapper.sumActiveTrxFee()));
|
||||
validateMainWalletBalance(cfg, currency, amount, fee, reservedUsdt, reservedTrx);
|
||||
if ("USDT".equals(currency)) {
|
||||
BigDecimal credit = z(app.getCreditLimit());
|
||||
if (credit.signum() < 0) throw new CustomException("应用信用额度配置不能小于0");
|
||||
if (!canUseUsdtCredit(ub, credit, amount)) throw new CustomException("USDT可用余额及信用额度不足");
|
||||
if (tb.compareTo(fee) < 0) throw new CustomException("TRX手续费余额不足");
|
||||
ub = ub.subtract(amount);
|
||||
uf = uf.add(amount);
|
||||
tb = tb.subtract(fee);
|
||||
tf = tf.add(fee);
|
||||
} else {
|
||||
BigDecimal total = amount.add(fee);
|
||||
if (tb.compareTo(total) < 0) throw new CustomException("TRX可用余额不足");
|
||||
tb = tb.subtract(total);
|
||||
tf = tf.add(total);
|
||||
}
|
||||
Date now = new Date();
|
||||
if (appsMapper.updatePayoutBalances(app.getId(), ub, tb, uf, tf, now) != 1)
|
||||
throw new CustomException("冻结余额失败");
|
||||
UsdtPayoutOrderPlus o = new UsdtPayoutOrderPlus();
|
||||
o.setTradeId(UUID.randomUUID().toString().replace("-", ""));
|
||||
o.setOrderId(orderId);
|
||||
o.setAppId(app.getId());
|
||||
o.setUserId(app.getUserId());
|
||||
o.setCurrency(currency);
|
||||
o.setAmount(amount);
|
||||
o.setFeeCurrency("TRX");
|
||||
o.setFeeAmount(fee);
|
||||
o.setToAddress(address);
|
||||
o.setStatus(PENDING_AUDIT);
|
||||
o.setNotifyUrl(notifyUrl);
|
||||
o.setRedirectUrl(redirectUrl);
|
||||
o.setCallbackNum(0);
|
||||
o.setCallbackConfirm(0);
|
||||
o.setExecuteCount(0);
|
||||
o.setCreatedAt(now);
|
||||
o.setUpdatedAt(now);
|
||||
payoutMapper.insert(o);
|
||||
eventPublisher.publishEvent(new TelegramPayoutAuditEvent(o.getId(), o.getOrderId(), o.getCurrency(), o.getAmount().toPlainString(), o.getToAddress(), o.getFeeAmount().toPlainString()));
|
||||
return o;
|
||||
}
|
||||
|
||||
public UsdtPayoutOrderPlus find(Long appId, String orderId) {
|
||||
return payoutMapper.selectOne(new LambdaQueryWrapper<UsdtPayoutOrderPlus>().eq(UsdtPayoutOrderPlus::getAppId, appId).eq(UsdtPayoutOrderPlus::getOrderId, orderId).isNull(UsdtPayoutOrderPlus::getDeletedAt).last("limit 1"));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void review(Long id, boolean approved, String channel, String reviewer, String remark) {
|
||||
UsdtPayoutOrderPlus probe = payoutMapper.selectById(id);
|
||||
if (probe == null) throw new CustomException("代付订单不存在");
|
||||
Apps app = appsMapper.selectAppsByIdForUpdate(probe.getAppId());
|
||||
UsdtPayoutOrderPlus o = payoutMapper.selectByIdForUpdate(id);
|
||||
if (o == null || !Integer.valueOf(PENDING_AUDIT).equals(o.getStatus()))
|
||||
throw new CustomException("订单状态不允许审核");
|
||||
if (approved) {
|
||||
UsdtPayoutOrderPlus executing = payoutMapper.selectExecutingByAppId(o.getAppId(), o.getId());
|
||||
if (executing != null)
|
||||
throw new CustomException("该应用已有待执行代付订单,订单号:" + executing.getOrderId());
|
||||
}
|
||||
Date now = new Date();
|
||||
o.setAuditType(channel);
|
||||
o.setAuditorId(reviewer);
|
||||
o.setAuditRemark(remark);
|
||||
o.setAuditedAt(now);
|
||||
o.setUpdatedAt(now);
|
||||
if (approved) o.setStatus(PENDING_EXECUTE);
|
||||
else {
|
||||
unfreeze(app, o);
|
||||
o.setStatus(REJECTED);
|
||||
}
|
||||
payoutMapper.updateById(o);
|
||||
}
|
||||
|
||||
private void unfreeze(Apps a, UsdtPayoutOrderPlus o) {
|
||||
BigDecimal ub = z(a.getUsdtBalance()), tb = z(a.getTrxBalance()), uf = z(a.getUsdtFrozenBalance()), tf = z(a.getTrxFrozenBalance());
|
||||
if ("USDT".equals(o.getCurrency())) {
|
||||
ub = ub.add(o.getAmount());
|
||||
uf = uf.subtract(o.getAmount());
|
||||
} else {
|
||||
tb = tb.add(o.getAmount());
|
||||
tf = tf.subtract(o.getAmount());
|
||||
}
|
||||
tb = tb.add(o.getFeeAmount());
|
||||
tf = tf.subtract(o.getFeeAmount());
|
||||
if (uf.signum() < 0 || tf.signum() < 0) throw new CustomException("代付冻结余额异常");
|
||||
if (appsMapper.updatePayoutBalances(a.getId(), ub, tb, uf, tf, new Date()) != 1)
|
||||
throw new CustomException("代付解冻余额失败");
|
||||
}
|
||||
|
||||
private BigDecimal z(BigDecimal v) {
|
||||
return v == null ? BigDecimal.ZERO : v;
|
||||
}
|
||||
|
||||
private String trim(String v) {
|
||||
return v == null || v.trim().isEmpty() ? null : v.trim();
|
||||
}
|
||||
|
||||
static boolean canUseUsdtCredit(BigDecimal availableBalance, BigDecimal creditLimit, BigDecimal amount) {
|
||||
return availableBalance.add(creditLimit).compareTo(amount) >= 0;
|
||||
}
|
||||
|
||||
static boolean hasMainWalletCapacity(String currency, BigDecimal mainUsdt, BigDecimal mainTrx,
|
||||
BigDecimal reservedUsdt, BigDecimal reservedTrx, BigDecimal amount, BigDecimal fee) {
|
||||
if ("USDT".equals(currency)) {
|
||||
return mainUsdt.subtract(reservedUsdt).compareTo(amount) >= 0
|
||||
&& mainTrx.subtract(reservedTrx).compareTo(fee) >= 0;
|
||||
}
|
||||
return mainTrx.subtract(reservedTrx).compareTo(amount.add(fee)) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主钱包余额来自定时链上快照。快照为空时失败关闭,避免在无法确认资金时接受代付。
|
||||
* USDT 代付还要求主钱包保留配置的 TRX 手续费;TRX 代付校验本金与手续费总额。
|
||||
*/
|
||||
private void validateMainWalletBalance(UsdtConfig config, String currency, BigDecimal amount, BigDecimal fee,
|
||||
BigDecimal reservedUsdt, BigDecimal reservedTrx) {
|
||||
if (config.getUsdtBalance() == null || config.getTrxBalance() == null)
|
||||
throw new CustomException("主钱包余额尚未同步,请稍后重试");
|
||||
if (!hasMainWalletCapacity(currency, config.getUsdtBalance(), config.getTrxBalance(),
|
||||
reservedUsdt, reservedTrx, amount, fee)) {
|
||||
throw new CustomException("USDT".equals(currency) ? "主钱包可用USDT或TRX余额不足" : "主钱包可用TRX余额不足");
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal amount(String v) {
|
||||
try {
|
||||
BigDecimal n = new BigDecimal(v).setScale(6, RoundingMode.UNNECESSARY);
|
||||
if (n.signum() <= 0) throw new Exception();
|
||||
return n;
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("amount必须大于0且最多6位小数");
|
||||
}
|
||||
}
|
||||
|
||||
private String required(Map<String, String> p, String n) {
|
||||
String v = trim(p.get(n));
|
||||
if (v == null) throw new CustomException(n + "不能为空");
|
||||
return v;
|
||||
}
|
||||
|
||||
private void validateUrl(String v, boolean required) {
|
||||
if (v == null) {
|
||||
if (required) throw new CustomException("notify_url不能为空");
|
||||
return;
|
||||
}
|
||||
if (v.length() > 512 || !(v.startsWith("http://") || v.startsWith("https://")))
|
||||
throw new CustomException("回调地址格式错误");
|
||||
}
|
||||
|
||||
private Map<String, String> parse(String plain) {
|
||||
Map<String, String> m = new LinkedHashMap<>();
|
||||
if (plain == null) throw new CustomException("业务参数格式错误");
|
||||
for (String s : plain.split("&")) {
|
||||
if (s.isEmpty()) continue;
|
||||
int i = s.indexOf('=');
|
||||
if (i <= 0) throw new CustomException("业务参数格式错误");
|
||||
if (m.put(s.substring(0, i), s.substring(i + 1)) != null) throw new CustomException("业务参数不能重复");
|
||||
}
|
||||
return m;
|
||||
}
|
||||
public UsdtPayoutOrder find(Long appId,String orderId){return payoutMapper.selectOne(new LambdaQueryWrapper<UsdtPayoutOrder>().eq(UsdtPayoutOrder::getAppId,appId).eq(UsdtPayoutOrder::getOrderId,orderId).isNull(UsdtPayoutOrder::getDeletedAt).last("limit 1"));}
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public void review(Long id,boolean approved,String channel,String reviewer,String remark){UsdtPayoutOrder probe=payoutMapper.selectById(id);if(probe==null)throw new CustomException("代付订单不存在");Apps app=appsMapper.selectAppsByIdForUpdate(probe.getAppId());UsdtPayoutOrder o=payoutMapper.selectByIdForUpdate(id);if(o==null||!Integer.valueOf(PENDING_AUDIT).equals(o.getStatus()))throw new CustomException("订单状态不允许审核");Date now=new Date();o.setAuditType(channel);o.setAuditorId(reviewer);o.setAuditRemark(remark);o.setAuditedAt(now);o.setUpdatedAt(now);if(approved)o.setStatus(PENDING_EXECUTE);else{unfreeze(app,o);o.setStatus(REJECTED);}payoutMapper.updateById(o);}
|
||||
private void unfreeze(Apps a,UsdtPayoutOrder o){BigDecimal ub=z(a.getUsdtBalance()),tb=z(a.getTrxBalance()),uf=z(a.getUsdtFrozenBalance()),tf=z(a.getTrxFrozenBalance());if("USDT".equals(o.getCurrency())){ub=ub.add(o.getAmount());uf=uf.subtract(o.getAmount());}else{tb=tb.add(o.getAmount());tf=tf.subtract(o.getAmount());}tb=tb.add(o.getFeeAmount());tf=tf.subtract(o.getFeeAmount());if(uf.signum()<0||tf.signum()<0)throw new CustomException("代付冻结余额异常");if(appsMapper.updatePayoutBalances(a.getId(),ub,tb,uf,tf,new Date())!=1)throw new CustomException("代付解冻余额失败");}
|
||||
private BigDecimal z(BigDecimal v){return v==null?BigDecimal.ZERO:v;} private String trim(String v){return v==null||v.trim().isEmpty()?null:v.trim();}
|
||||
private BigDecimal amount(String v){try{BigDecimal n=new BigDecimal(v).setScale(6,RoundingMode.UNNECESSARY);if(n.signum()<=0)throw new Exception();return n;}catch(Exception e){throw new CustomException("amount必须大于0且最多6位小数");}}
|
||||
private String required(Map<String,String> p,String n){String v=trim(p.get(n));if(v==null)throw new CustomException(n+"不能为空");return v;}
|
||||
private void validateUrl(String v,boolean required){if(v==null){if(required)throw new CustomException("notify_url不能为空");return;}if(v.length()>512||!(v.startsWith("http://")||v.startsWith("https://")))throw new CustomException("回调地址格式错误");}
|
||||
private Map<String,String> parse(String plain){Map<String,String> m=new LinkedHashMap<>();if(plain==null)throw new CustomException("业务参数格式错误");for(String s:plain.split("&")){if(s.isEmpty())continue;int i=s.indexOf('=');if(i<=0)throw new CustomException("业务参数格式错误");if(m.put(s.substring(0,i),s.substring(i+1))!=null)throw new CustomException("业务参数不能重复");}return m;}
|
||||
}
|
||||
@@ -3,36 +3,56 @@ package com.ruoyi.system.service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.mapper.AppsBalanceLedgerMapper;
|
||||
import com.ruoyi.system.mapper.AppsMapper;
|
||||
import com.ruoyi.system.mapper.UsdtConfigMapper;
|
||||
import com.ruoyi.system.mapper.UsdtPayoutOrderMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.tron.trident.core.ApiWrapper;
|
||||
import org.tron.trident.proto.Response;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/** 代付广播、链上确认和最终账务结算。 */
|
||||
/**
|
||||
* 代付广播、链上确认和最终账务结算。
|
||||
*/
|
||||
@Service
|
||||
public class PayoutProcessingService {
|
||||
/** 仅用于广播期间的并发占位,避免同一订单重复提交链上交易。 */
|
||||
/**
|
||||
* 仅用于广播期间的并发占位,避免同一订单重复提交链上交易。
|
||||
*/
|
||||
public static final int EXECUTING = 6;
|
||||
@Autowired private UsdtPayoutOrderMapper payoutMapper; @Autowired private UsdtConfigMapper configMapper;
|
||||
@Autowired private AppsMapper appsMapper; @Autowired private AppsBalanceLedgerMapper ledgerMapper;
|
||||
@Autowired private WalletSigningService signingService; @Autowired private TronServiceProvider tronProvider;
|
||||
@Autowired private TransactionTemplate transactionTemplate;
|
||||
@Autowired
|
||||
private UsdtPayoutOrderMapper payoutMapper;
|
||||
@Autowired
|
||||
private UsdtConfigMapper configMapper;
|
||||
@Autowired
|
||||
private AppsMapper appsMapper;
|
||||
@Autowired
|
||||
private AppsBalanceLedgerMapper ledgerMapper;
|
||||
@Autowired
|
||||
private WalletSigningService signingService;
|
||||
@Autowired
|
||||
private TronServiceProvider tronProvider;
|
||||
@Autowired
|
||||
private TransactionTemplate transactionTemplate;
|
||||
|
||||
/** 配置密码仅用于本次内存解锁,广播成功后订单进入待链上确认状态。 */
|
||||
/**
|
||||
* 配置密码仅用于本次内存解锁,广播成功后订单进入待链上确认状态。
|
||||
*/
|
||||
public String execute(Long id, String password) {
|
||||
if (payoutMapper.claimForExecution(id, PayoutOrderService.PENDING_EXECUTE,
|
||||
PayoutOrderService.EXECUTE_FAILED, EXECUTING) != 1) {
|
||||
throw new CustomException("仅待执行或执行失败的订单可以广播,请勿重复操作");
|
||||
}
|
||||
try {
|
||||
UsdtPayoutOrder order = payoutMapper.selectById(id);
|
||||
UsdtPayoutOrderPlus order = payoutMapper.selectById(id);
|
||||
UsdtConfigPlus config = config();
|
||||
WalletAddressPlus mainWallet = new WalletAddressPlus();
|
||||
mainWallet.setToken(config.getTokenAddress());
|
||||
@@ -40,31 +60,167 @@ public class PayoutProcessingService {
|
||||
String hash = signingService.execute(mainWallet, password, (tron, api, wallet) ->
|
||||
"USDT".equals(order.getCurrency())
|
||||
? tron.usdtTransWithBroadcastRetry(api, wallet.getToken(),
|
||||
order.getToAddress(), order.getAmount(), 3)
|
||||
order.getToAddress(), order.getAmount(), 3)
|
||||
: tron.trxTrans(api, wallet.getToken(), order.getToAddress(), order.getAmount()));
|
||||
transactionTemplate.execute(status -> { markBroadcasted(id, hash); return null; });
|
||||
transactionTemplate.execute(status -> {
|
||||
markBroadcasted(id, hash);
|
||||
return null;
|
||||
});
|
||||
return hash;
|
||||
} catch (Exception exception) {
|
||||
transactionTemplate.execute(status -> { markFailed(id, safe(exception)); return null; });
|
||||
transactionTemplate.execute(status -> {
|
||||
markFailed(id, safe(exception));
|
||||
return null;
|
||||
});
|
||||
throw exception instanceof CustomException
|
||||
? (CustomException) exception : new CustomException("代付广播失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public void markBroadcasted(Long id,String hash){UsdtPayoutOrder o=payoutMapper.selectByIdForUpdate(id);if(o==null||!Integer.valueOf(EXECUTING).equals(o.getStatus()))throw new CustomException("代付订单状态已变化");o.setStatus(PayoutOrderService.BROADCASTED);o.setBlockTransactionId(hash);o.setExecuteCount(n(o.getExecuteCount())+1);o.setExecutedAt(new Date());o.setExecuteError(null);o.setUpdatedAt(new Date());payoutMapper.updateById(o);}
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public void markFailed(Long id,String error){UsdtPayoutOrder o=payoutMapper.selectByIdForUpdate(id);if(o==null||!Integer.valueOf(EXECUTING).equals(o.getStatus()))return;o.setStatus(PayoutOrderService.EXECUTE_FAILED);o.setExecuteCount(n(o.getExecuteCount())+1);o.setExecuteError(error);o.setUpdatedAt(new Date());payoutMapper.updateById(o);}
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markBroadcasted(Long id, String hash) {
|
||||
UsdtPayoutOrderPlus o = payoutMapper.selectByIdForUpdate(id);
|
||||
if (o == null || !Integer.valueOf(EXECUTING).equals(o.getStatus()))
|
||||
throw new CustomException("代付订单状态已变化");
|
||||
o.setStatus(PayoutOrderService.BROADCASTED);
|
||||
o.setBlockTransactionId(hash);
|
||||
o.setExecuteCount(n(o.getExecuteCount()) + 1);
|
||||
o.setExecutedAt(new Date());
|
||||
o.setExecuteError(null);
|
||||
o.setUpdatedAt(new Date());
|
||||
payoutMapper.updateById(o);
|
||||
}
|
||||
|
||||
/** 查询已广播交易,只有链上SUCCESS后才完成账务结算。 */
|
||||
public void confirmPending(){List<UsdtPayoutOrder> list=payoutMapper.selectList(new LambdaQueryWrapper<UsdtPayoutOrder>().eq(UsdtPayoutOrder::getStatus,PayoutOrderService.BROADCASTED).isNotNull(UsdtPayoutOrder::getBlockTransactionId).isNull(UsdtPayoutOrder::getDeletedAt).last("limit 50"));if(list.isEmpty())return;ITronService tron=tronProvider.getCurrentService();ApiWrapper api=tron.buildApiWrapper();for(UsdtPayoutOrder o:list){try{Response.TransactionInfo info=api.getTransactionInfoById(o.getBlockTransactionId());if(info!=null&&!info.getId().isEmpty()){if(info.getResultValue()==0)settle(o.getId());else markChainFailed(o.getId(),"链上交易执行失败,resultValue="+info.getResultValue());}}catch(Exception ignored){}}}
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markFailed(Long id, String error) {
|
||||
UsdtPayoutOrderPlus o = payoutMapper.selectByIdForUpdate(id);
|
||||
if (o == null || !Integer.valueOf(EXECUTING).equals(o.getStatus())) return;
|
||||
o.setStatus(PayoutOrderService.EXECUTE_FAILED);
|
||||
o.setExecuteCount(n(o.getExecuteCount()) + 1);
|
||||
o.setExecuteError(error);
|
||||
o.setUpdatedAt(new Date());
|
||||
payoutMapper.updateById(o);
|
||||
}
|
||||
|
||||
public void markChainFailed(Long id,String error){transactionTemplate.execute(status->{UsdtPayoutOrder o=payoutMapper.selectByIdForUpdate(id);if(o!=null&&Integer.valueOf(PayoutOrderService.BROADCASTED).equals(o.getStatus())){o.setStatus(PayoutOrderService.EXECUTE_FAILED);o.setExecuteError(error);o.setUpdatedAt(new Date());payoutMapper.updateById(o);}return null;});}
|
||||
/**
|
||||
* 查询已广播交易,只有链上SUCCESS后才完成账务结算。
|
||||
*/
|
||||
public void confirmPending() {
|
||||
List<UsdtPayoutOrderPlus> list = payoutMapper.selectList(new LambdaQueryWrapper<UsdtPayoutOrderPlus>().eq(UsdtPayoutOrderPlus::getStatus, PayoutOrderService.BROADCASTED).isNotNull(UsdtPayoutOrderPlus::getBlockTransactionId).isNull(UsdtPayoutOrderPlus::getDeletedAt).last("limit 50"));
|
||||
if (list.isEmpty()) return;
|
||||
ITronService tron = tronProvider.getCurrentService();
|
||||
ApiWrapper api = tron.buildApiWrapper();
|
||||
for (UsdtPayoutOrderPlus o : list) {
|
||||
try {
|
||||
Response.TransactionInfo info = api.getTransactionInfoById(o.getBlockTransactionId());
|
||||
if (info != null && !info.getId().isEmpty()) {
|
||||
if (info.getResultValue() == 0) settle(o.getId());
|
||||
else markChainFailed(o.getId(), "链上交易执行失败,resultValue=" + info.getResultValue());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public void settle(Long id){transactionTemplate.execute(status->{settleInternal(id);return null;});}
|
||||
private void settleInternal(Long id){UsdtPayoutOrder probe=payoutMapper.selectById(id);if(probe==null)return;Apps app=appsMapper.selectAppsByIdForUpdate(probe.getAppId());UsdtPayoutOrder o=payoutMapper.selectByIdForUpdate(id);if(o==null||!Integer.valueOf(PayoutOrderService.BROADCASTED).equals(o.getStatus()))return;Date now=new Date();BigDecimal ub=z(app.getUsdtBalance()),tb=z(app.getTrxBalance()),uf=z(app.getUsdtFrozenBalance()),tf=z(app.getTrxFrozenBalance());BigDecimal principalFrozenBefore="USDT".equals(o.getCurrency())?uf:tf;BigDecimal principalFrozenAfter=principalFrozenBefore.subtract(o.getAmount());if("USDT".equals(o.getCurrency()))uf=principalFrozenAfter;else tf=principalFrozenAfter;BigDecimal feeFrozenBefore=tf;BigDecimal feeFrozenAfter=feeFrozenBefore.subtract(o.getFeeAmount());tf=feeFrozenAfter;if(uf.signum()<0||tf.signum()<0)throw new CustomException("代付冻结余额异常");if(appsMapper.updatePayoutBalances(app.getId(),ub,tb,uf,tf,now)!=1)throw new CustomException("代付结算余额更新失败");post(o,"PAYOUT_SUCCESS",o.getCurrency(),o.getAmount(),"PAYOUT_PRINCIPAL:"+o.getId(),"USDT".equals(o.getCurrency())?ub:tb,principalFrozenBefore,principalFrozenAfter,now);if(o.getFeeAmount().signum()>0)post(o,"PAYOUT_FEE","TRX",o.getFeeAmount(),"PAYOUT_FEE:"+o.getId(),tb,feeFrozenBefore,feeFrozenAfter,now);o.setStatus(PayoutOrderService.COMPLETED);o.setConfirmedAt(now);o.setUpdatedAt(now);payoutMapper.updateById(o);}
|
||||
private void post(UsdtPayoutOrder o,String type,String currency,BigDecimal amount,String key,BigDecimal available,BigDecimal frozenBefore,BigDecimal frozenAfter,Date now){AppsBalanceLedger l=new AppsBalanceLedger();l.setTradeNo("PL"+UUID.randomUUID().toString().replace("-","").substring(0,24));l.setIdempotencyKey(key);l.setAppId(o.getAppId());l.setUserId(o.getUserId());l.setCurrency(currency);l.setBalanceType(2);l.setBusinessType(type);l.setDirection(2);l.setAmount(amount);l.setBalanceBefore(frozenBefore);l.setBalanceAfter(frozenAfter);l.setAvailableBefore(available);l.setAvailableAfter(available);l.setFrozenBefore(frozenBefore);l.setFrozenAfter(frozenAfter);l.setPayoutOrderId(o.getId());l.setMerchantOrderId(o.getOrderId());l.setTransactionId(o.getBlockTransactionId());l.setRemark("应用代付链上确认");l.setCreatedAt(now);ledgerMapper.insertSystemLedgerIgnoreDuplicate(l);}
|
||||
private UsdtConfigPlus config(){UsdtConfigPlus c=configMapper.selectOne(new LambdaQueryWrapper<UsdtConfigPlus>().orderByAsc(UsdtConfigPlus::getId).last("limit 1"));if(c==null||c.getTokenAddress()==null)throw new CustomException("主钱包配置不存在");return c;}
|
||||
private int n(Integer v){return v==null?0:v;}private BigDecimal z(BigDecimal v){return v==null?BigDecimal.ZERO:v;}private String safe(Exception e){String s=e.getMessage();return s==null?e.getClass().getSimpleName():s.substring(0,Math.min(1000,s.length()));}
|
||||
public void markChainFailed(Long id, String error) {
|
||||
transactionTemplate.execute(status -> {
|
||||
UsdtPayoutOrderPlus o = payoutMapper.selectByIdForUpdate(id);
|
||||
if (o != null && Integer.valueOf(PayoutOrderService.BROADCASTED).equals(o.getStatus())) {
|
||||
o.setStatus(PayoutOrderService.EXECUTE_FAILED);
|
||||
o.setExecuteError(error);
|
||||
o.setUpdatedAt(new Date());
|
||||
payoutMapper.updateById(o);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void settle(Long id) {
|
||||
transactionTemplate.execute(status -> {
|
||||
settleInternal(id);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void settleInternal(Long id) {
|
||||
UsdtPayoutOrderPlus probe = payoutMapper.selectById(id);
|
||||
if (probe == null) return;
|
||||
Apps app = appsMapper.selectAppsByIdForUpdate(probe.getAppId());
|
||||
UsdtPayoutOrderPlus o = payoutMapper.selectByIdForUpdate(id);
|
||||
if (o == null || !Integer.valueOf(PayoutOrderService.BROADCASTED).equals(o.getStatus())) return;
|
||||
UsdtConfig config = configMapper.selectFirstForUpdate();
|
||||
if (config == null || config.getUsdtBalance() == null || config.getTrxBalance() == null)
|
||||
throw new CustomException("主钱包余额尚未同步");
|
||||
Date now = new Date();
|
||||
BigDecimal ub = z(app.getUsdtBalance()), tb = z(app.getTrxBalance()), uf = z(app.getUsdtFrozenBalance()), tf = z(app.getTrxFrozenBalance());
|
||||
BigDecimal principalFrozenBefore = "USDT".equals(o.getCurrency()) ? uf : tf;
|
||||
BigDecimal principalFrozenAfter = principalFrozenBefore.subtract(o.getAmount());
|
||||
if ("USDT".equals(o.getCurrency())) uf = principalFrozenAfter;
|
||||
else tf = principalFrozenAfter;
|
||||
BigDecimal feeFrozenBefore = tf;
|
||||
BigDecimal feeFrozenAfter = feeFrozenBefore.subtract(o.getFeeAmount());
|
||||
tf = feeFrozenAfter;
|
||||
if (uf.signum() < 0 || tf.signum() < 0) throw new CustomException("代付冻结余额异常");
|
||||
BigDecimal mainUsdt = config.getUsdtBalance();
|
||||
BigDecimal mainTrx = config.getTrxBalance().subtract(o.getFeeAmount());
|
||||
if ("USDT".equals(o.getCurrency())) mainUsdt = mainUsdt.subtract(o.getAmount());
|
||||
else mainTrx = mainTrx.subtract(o.getAmount());
|
||||
if (mainUsdt.signum() < 0 || mainTrx.signum() < 0) throw new CustomException("主钱包结算余额异常");
|
||||
if (configMapper.updateMainWalletBalances(config.getId(), mainUsdt, mainTrx) != 1)
|
||||
throw new CustomException("主钱包余额快照更新失败");
|
||||
if (appsMapper.updatePayoutBalances(app.getId(), ub, tb, uf, tf, now) != 1)
|
||||
throw new CustomException("代付结算余额更新失败");
|
||||
post(o, "PAYOUT_SUCCESS", o.getCurrency(), o.getAmount(), "PAYOUT_PRINCIPAL:" + o.getId(), "USDT".equals(o.getCurrency()) ? ub : tb, principalFrozenBefore, principalFrozenAfter, now);
|
||||
if (o.getFeeAmount().signum() > 0)
|
||||
post(o, "PAYOUT_FEE", "TRX", o.getFeeAmount(), "PAYOUT_FEE:" + o.getId(), tb, feeFrozenBefore, feeFrozenAfter, now);
|
||||
o.setStatus(PayoutOrderService.COMPLETED);
|
||||
o.setConfirmedAt(now);
|
||||
o.setUpdatedAt(now);
|
||||
payoutMapper.updateById(o);
|
||||
}
|
||||
|
||||
private void post(UsdtPayoutOrderPlus o, String type, String currency, BigDecimal amount, String key, BigDecimal available, BigDecimal frozenBefore, BigDecimal frozenAfter, Date now) {
|
||||
AppsBalanceLedger l = new AppsBalanceLedger();
|
||||
l.setTradeNo("PL" + UUID.randomUUID().toString().replace("-", "").substring(0, 24));
|
||||
l.setIdempotencyKey(key);
|
||||
l.setAppId(o.getAppId());
|
||||
l.setUserId(o.getUserId());
|
||||
l.setCurrency(currency);
|
||||
l.setBalanceType(2);
|
||||
l.setBusinessType(type);
|
||||
l.setDirection(2);
|
||||
l.setAmount(amount);
|
||||
l.setBalanceBefore(frozenBefore);
|
||||
l.setBalanceAfter(frozenAfter);
|
||||
l.setAvailableBefore(available);
|
||||
l.setAvailableAfter(available);
|
||||
l.setFrozenBefore(frozenBefore);
|
||||
l.setFrozenAfter(frozenAfter);
|
||||
l.setPayoutOrderId(o.getId());
|
||||
l.setMerchantOrderId(o.getOrderId());
|
||||
l.setTransactionId(o.getBlockTransactionId());
|
||||
l.setRemark("应用代付链上确认");
|
||||
l.setCreatedAt(now);
|
||||
ledgerMapper.insertSystemLedgerIgnoreDuplicate(l);
|
||||
}
|
||||
|
||||
private UsdtConfigPlus config() {
|
||||
UsdtConfigPlus c = configMapper.selectOne(new LambdaQueryWrapper<UsdtConfigPlus>().orderByAsc(UsdtConfigPlus::getId).last("limit 1"));
|
||||
if (c == null || c.getTokenAddress() == null) throw new CustomException("主钱包配置不存在");
|
||||
return c;
|
||||
}
|
||||
|
||||
private int n(Integer v) {
|
||||
return v == null ? 0 : v;
|
||||
}
|
||||
|
||||
private BigDecimal z(BigDecimal v) {
|
||||
return v == null ? BigDecimal.ZERO : v;
|
||||
}
|
||||
|
||||
private String safe(Exception e) {
|
||||
String s = e.getMessage();
|
||||
return s == null ? e.getClass().getSimpleName() : s.substring(0, Math.min(1000, s.length()));
|
||||
}
|
||||
}
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import java.util.HashMap;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import java.util.*;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import java.util.Map;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.system.mapper.UsdtPayoutOrderMapper;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrder;
|
||||
import com.ruoyi.system.domain.UsdtPayoutOrderPlus;
|
||||
import com.ruoyi.system.service.IUsdtPayoutOrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import com.ruoyi.common.select.SelectItem;
|
||||
/**
|
||||
* 应用代付订单Service业务层处理
|
||||
*
|
||||
* @author luqj
|
||||
* @date 2026-10-17
|
||||
*/
|
||||
@Service
|
||||
public class UsdtPayoutOrderServiceImpl extends ServiceImpl<UsdtPayoutOrderMapper, UsdtPayoutOrderPlus> implements IUsdtPayoutOrderService
|
||||
{
|
||||
@Autowired
|
||||
private UsdtPayoutOrderMapper usdtPayoutOrderMapper;
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Override
|
||||
public List<UsdtPayoutOrderPlus> getByIds(List<Long> ids ,boolean isUser, SFunction<UsdtPayoutOrderPlus, ?>... columns) {
|
||||
LambdaQueryWrapper<UsdtPayoutOrderPlus> lambdaQueryWrapper = new LambdaQueryWrapper<UsdtPayoutOrderPlus>()
|
||||
.select(columns).in(UsdtPayoutOrderPlus::getId, ids);
|
||||
if(isUser){
|
||||
lambdaQueryWrapper.eq(UsdtPayoutOrderPlus::getUserId, SecurityUtils.getUserId());
|
||||
}
|
||||
List<UsdtPayoutOrderPlus> list = this.list(lambdaQueryWrapper);
|
||||
if(isUser){
|
||||
checkUserPlus(list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
private void checkUserPlus(List<UsdtPayoutOrderPlus> list) {
|
||||
for (UsdtPayoutOrderPlus item : list){
|
||||
if(null != SecurityUtils.getUserId() && item.getUserId().longValue() != SecurityUtils.getUserId()){
|
||||
throw new RuntimeException("无权限");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void checkUser(List<UsdtPayoutOrder> list) {
|
||||
for (UsdtPayoutOrder item : list){
|
||||
if(null != SecurityUtils.getUserId() && item.getUserId().longValue() != SecurityUtils.getUserId()){
|
||||
throw new RuntimeException("无权限");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void checkUser(UsdtPayoutOrderPlus item) {
|
||||
if(null != SecurityUtils.getUserId() && item.getUserId().longValue() != SecurityUtils.getUserId()){
|
||||
throw new RuntimeException("无权限");
|
||||
}
|
||||
}
|
||||
private void checkUser(UsdtPayoutOrder item) {
|
||||
if(null != SecurityUtils.getUserId() && item.getUserId().longValue() != SecurityUtils.getUserId()){
|
||||
throw new RuntimeException("无权限");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<SelectItem> select(String keyword,boolean isUser) {
|
||||
LambdaQueryWrapper<UsdtPayoutOrderPlus> lambdaQueryWrapper = new LambdaQueryWrapper<UsdtPayoutOrderPlus>()
|
||||
.select(UsdtPayoutOrderPlus::getId,UsdtPayoutOrderPlus::getUserId, UsdtPayoutOrderPlus::getTradeId)
|
||||
.like(UsdtPayoutOrderPlus::getTradeId, keyword);
|
||||
if(isUser){
|
||||
lambdaQueryWrapper.eq(UsdtPayoutOrderPlus::getUserId, SecurityUtils.getUserId());
|
||||
}
|
||||
List<UsdtPayoutOrderPlus> list = this.list(lambdaQueryWrapper);
|
||||
if(isUser){
|
||||
checkUserPlus(list);
|
||||
}
|
||||
List<SelectItem> result =new ArrayList<>();
|
||||
for (UsdtPayoutOrderPlus item : list){
|
||||
SelectItem selectItem = new SelectItem();
|
||||
selectItem.setName(item.getTradeId());
|
||||
selectItem.setId(item.getId());
|
||||
result.add(selectItem);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public UsdtPayoutOrderPlus getById(Long id, SFunction<UsdtPayoutOrderPlus, ?>... columns) {
|
||||
LambdaQueryWrapper<UsdtPayoutOrderPlus> lambdaQueryWrapper = new LambdaQueryWrapper<UsdtPayoutOrderPlus>()
|
||||
.select(columns).eq(UsdtPayoutOrderPlus::getId, id);
|
||||
return baseMapper.selectOne(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, UsdtPayoutOrderPlus> getMapByIds(List<Long> ids, SFunction<UsdtPayoutOrderPlus, ?>... columns) {
|
||||
List<UsdtPayoutOrderPlus> list = this.getByIds(ids,false, columns);
|
||||
Map<Long, UsdtPayoutOrderPlus> map = new HashMap<>();
|
||||
for (UsdtPayoutOrderPlus item : list) {
|
||||
map.put(item.getId(), item);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, UsdtPayoutOrderPlus> getMapByIds(List<Long> ids) {
|
||||
List<UsdtPayoutOrderPlus> list = this.getByIds(ids);
|
||||
Map<Long, UsdtPayoutOrderPlus> map = new HashMap<>();
|
||||
for (UsdtPayoutOrderPlus item : list) {
|
||||
map.put(item.getId(), item);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UsdtPayoutOrderPlus> getByIds(List<Long> ids) {
|
||||
LambdaQueryWrapper<UsdtPayoutOrderPlus> lambdaQueryWrapper = new LambdaQueryWrapper<UsdtPayoutOrderPlus>().in(UsdtPayoutOrderPlus::getId, ids);
|
||||
return this.list(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
public <T> T sum(String field, String where, Class<T> tClass) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("select ");
|
||||
stringBuffer.append(" sum(" + field + ") as total ");
|
||||
stringBuffer.append(" from usdt_payout_order ");
|
||||
if (StringUtils.isNotBlank(where)) {
|
||||
stringBuffer.append(" where ");
|
||||
stringBuffer.append(where);
|
||||
}
|
||||
T result = jdbcTemplate.queryForObject(stringBuffer.toString(), tClass);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Long count(String where) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("select ");
|
||||
stringBuffer.append(" count(1)");
|
||||
stringBuffer.append(" from ");
|
||||
stringBuffer.append(" usdt_payout_order ");
|
||||
if (StringUtils.isNotBlank(where)) {
|
||||
stringBuffer.append(" where ");
|
||||
stringBuffer.append(where);
|
||||
}
|
||||
Long result = jdbcTemplate.queryForObject(stringBuffer.toString(), Long.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("select ");
|
||||
stringBuffer.append(select);
|
||||
stringBuffer.append(" from ");
|
||||
stringBuffer.append(" usdt_payout_order ");
|
||||
if (StringUtils.isNotBlank(where)) {
|
||||
stringBuffer.append(" where ");
|
||||
stringBuffer.append(where);
|
||||
}
|
||||
stringBuffer.append(" group by ");
|
||||
stringBuffer.append(groupby);
|
||||
List result = jdbcTemplate.queryForList(stringBuffer.toString());
|
||||
List<T> tList = JSONArray.parseArray(JSONArray.toJSONString(result), tClass);
|
||||
return tList;
|
||||
}
|
||||
/**
|
||||
* 查询应用代付订单
|
||||
*
|
||||
* @param id 应用代付订单ID
|
||||
* @return 应用代付订单
|
||||
*/
|
||||
@Override
|
||||
public UsdtPayoutOrder selectUsdtPayoutOrderById(Long id,boolean isUser)
|
||||
{
|
||||
UsdtPayoutOrder vo = usdtPayoutOrderMapper.selectUsdtPayoutOrderById(id);
|
||||
if(isUser){
|
||||
checkUser(vo);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询应用代付订单列表
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 应用代付订单
|
||||
*/
|
||||
@Override
|
||||
public List<UsdtPayoutOrder> selectUsdtPayoutOrderList(UsdtPayoutOrder usdtPayoutOrder,boolean isUser)
|
||||
{
|
||||
if(usdtPayoutOrder == null){
|
||||
usdtPayoutOrder = new UsdtPayoutOrder();
|
||||
}
|
||||
if(isUser){
|
||||
usdtPayoutOrder.setUserId(SecurityUtils.getUserId());
|
||||
}
|
||||
List<UsdtPayoutOrder> list = usdtPayoutOrderMapper.selectUsdtPayoutOrderList(usdtPayoutOrder);
|
||||
if(isUser){
|
||||
checkUser(list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增应用代付订单
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertUsdtPayoutOrder(UsdtPayoutOrder usdtPayoutOrder,boolean isUser)
|
||||
{
|
||||
usdtPayoutOrder.setCreatedAt(DateUtils.getNowDate());
|
||||
usdtPayoutOrder.setUpdatedAt(DateUtils.getNowDate());
|
||||
if(isUser){
|
||||
usdtPayoutOrder.setUserId(SecurityUtils.getUserId());
|
||||
}
|
||||
return usdtPayoutOrderMapper.insertUsdtPayoutOrder(usdtPayoutOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改应用代付订单
|
||||
*
|
||||
* @param usdtPayoutOrder 应用代付订单
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateUsdtPayoutOrder(UsdtPayoutOrder usdtPayoutOrder,boolean isUser)
|
||||
{
|
||||
usdtPayoutOrder.setUpdatedAt(DateUtils.getNowDate());
|
||||
if(isUser){
|
||||
checkUser(usdtPayoutOrder);
|
||||
}
|
||||
return usdtPayoutOrderMapper.updateUsdtPayoutOrder(usdtPayoutOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除应用代付订单
|
||||
*
|
||||
* @param ids 需要删除的应用代付订单ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteUsdtPayoutOrderByIds(Long[] ids,boolean isUser)
|
||||
{
|
||||
if(isUser){
|
||||
List<UsdtPayoutOrderPlus> list= getByIds(Arrays.asList(ids),false,UsdtPayoutOrderPlus::getUserId,UsdtPayoutOrderPlus::getId);
|
||||
checkUserPlus(list);
|
||||
}
|
||||
return usdtPayoutOrderMapper.deleteUsdtPayoutOrderByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除应用代付订单信息
|
||||
*
|
||||
* @param id 应用代付订单ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteUsdtPayoutOrderById(Long id,boolean isUser)
|
||||
{
|
||||
if(isUser){
|
||||
UsdtPayoutOrderPlus vo = getById(id,UsdtPayoutOrderPlus::getUserId,UsdtPayoutOrderPlus::getId);
|
||||
checkUser(vo);
|
||||
}
|
||||
return usdtPayoutOrderMapper.deleteUsdtPayoutOrderById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?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="com.ruoyi.system.mapper.UsdtPayoutOrderMapper">
|
||||
|
||||
<resultMap type="UsdtPayoutOrder" id="UsdtPayoutOrderResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="tradeId" column="trade_id" />
|
||||
<result property="orderId" column="order_id" />
|
||||
<result property="appId" column="app_id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="currency" column="currency" />
|
||||
<result property="amount" column="amount" />
|
||||
<result property="feeCurrency" column="fee_currency" />
|
||||
<result property="feeAmount" column="fee_amount" />
|
||||
<result property="toAddress" column="to_address" />
|
||||
<result property="status" column="status" />
|
||||
<result property="auditType" column="audit_type" />
|
||||
<result property="auditorId" column="auditor_id" />
|
||||
<result property="auditRemark" column="audit_remark" />
|
||||
<result property="auditedAt" column="audited_at" />
|
||||
<result property="blockTransactionId" column="block_transaction_id" />
|
||||
<result property="executeError" column="execute_error" />
|
||||
<result property="executeCount" column="execute_count" />
|
||||
<result property="executedAt" column="executed_at" />
|
||||
<result property="confirmedAt" column="confirmed_at" />
|
||||
<result property="notifyUrl" column="notify_url" />
|
||||
<result property="redirectUrl" column="redirect_url" />
|
||||
<result property="callbackNum" column="callback_num" />
|
||||
<result property="callbackConfirm" column="callback_confirm" />
|
||||
<result property="createdAt" column="created_at" />
|
||||
<result property="updatedAt" column="updated_at" />
|
||||
<result property="deletedAt" column="deleted_at" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectUsdtPayoutOrderVo">
|
||||
select id, trade_id, order_id, app_id, user_id, currency, amount, fee_currency, fee_amount, to_address, status, audit_type, auditor_id, audit_remark, audited_at, block_transaction_id, execute_error, execute_count, executed_at, confirmed_at, notify_url, redirect_url, callback_num, callback_confirm, created_at, updated_at, deleted_at from usdt_payout_order
|
||||
</sql>
|
||||
|
||||
<select id="selectUsdtPayoutOrderList" parameterType="UsdtPayoutOrder" resultMap="UsdtPayoutOrderResult">
|
||||
<include refid="selectUsdtPayoutOrderVo"/>
|
||||
<where>
|
||||
<if test="tradeId != null and tradeId != ''"> and trade_id = #{tradeId}</if>
|
||||
<if test="orderId != null and orderId != ''"> and order_id = #{orderId}</if>
|
||||
<if test="appId != null "> and app_id = #{appId}</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="currency != null and currency != ''"> and currency = #{currency}</if>
|
||||
<if test="amount != null "> and amount = #{amount}</if>
|
||||
<if test="feeCurrency != null and feeCurrency != ''"> and fee_currency = #{feeCurrency}</if>
|
||||
<if test="feeAmount != null "> and fee_amount = #{feeAmount}</if>
|
||||
<if test="toAddress != null and toAddress != ''"> and to_address = #{toAddress}</if>
|
||||
<if test="status != null "> and status = #{status}</if>
|
||||
<if test="auditType != null and auditType != ''"> and audit_type = #{auditType}</if>
|
||||
<if test="auditorId != null and auditorId != ''"> and auditor_id = #{auditorId}</if>
|
||||
<if test="auditRemark != null and auditRemark != ''"> and audit_remark = #{auditRemark}</if>
|
||||
<if test="auditedAt != null "> and audited_at = #{auditedAt}</if>
|
||||
<if test="blockTransactionId != null and blockTransactionId != ''"> and block_transaction_id = #{blockTransactionId}</if>
|
||||
<if test="executeError != null and executeError != ''"> and execute_error = #{executeError}</if>
|
||||
<if test="executeCount != null "> and execute_count = #{executeCount}</if>
|
||||
<if test="executedAt != null "> and executed_at = #{executedAt}</if>
|
||||
<if test="confirmedAt != null "> and confirmed_at = #{confirmedAt}</if>
|
||||
<if test="notifyUrl != null and notifyUrl != ''"> and notify_url = #{notifyUrl}</if>
|
||||
<if test="redirectUrl != null and redirectUrl != ''"> and redirect_url = #{redirectUrl}</if>
|
||||
<if test="callbackNum != null "> and callback_num = #{callbackNum}</if>
|
||||
<if test="callbackConfirm != null "> and callback_confirm = #{callbackConfirm}</if>
|
||||
<if test="createdAt != null "> and created_at = #{createdAt}</if>
|
||||
<if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
|
||||
<if test="deletedAt != null "> and deleted_at = #{deletedAt}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectUsdtPayoutOrderById" parameterType="Long" resultMap="UsdtPayoutOrderResult">
|
||||
<include refid="selectUsdtPayoutOrderVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertUsdtPayoutOrder" parameterType="UsdtPayoutOrder" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into usdt_payout_order
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="tradeId != null and tradeId != ''">trade_id,</if>
|
||||
<if test="orderId != null and orderId != ''">order_id,</if>
|
||||
<if test="appId != null">app_id,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="currency != null and currency != ''">currency,</if>
|
||||
<if test="amount != null">amount,</if>
|
||||
<if test="feeCurrency != null and feeCurrency != ''">fee_currency,</if>
|
||||
<if test="feeAmount != null">fee_amount,</if>
|
||||
<if test="toAddress != null and toAddress != ''">to_address,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="auditType != null">audit_type,</if>
|
||||
<if test="auditorId != null">auditor_id,</if>
|
||||
<if test="auditRemark != null">audit_remark,</if>
|
||||
<if test="auditedAt != null">audited_at,</if>
|
||||
<if test="blockTransactionId != null">block_transaction_id,</if>
|
||||
<if test="executeError != null">execute_error,</if>
|
||||
<if test="executeCount != null">execute_count,</if>
|
||||
<if test="executedAt != null">executed_at,</if>
|
||||
<if test="confirmedAt != null">confirmed_at,</if>
|
||||
<if test="notifyUrl != null and notifyUrl != ''">notify_url,</if>
|
||||
<if test="redirectUrl != null">redirect_url,</if>
|
||||
<if test="callbackNum != null">callback_num,</if>
|
||||
<if test="callbackConfirm != null">callback_confirm,</if>
|
||||
<if test="createdAt != null">created_at,</if>
|
||||
<if test="updatedAt != null">updated_at,</if>
|
||||
<if test="deletedAt != null">deleted_at,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="tradeId != null and tradeId != ''">#{tradeId},</if>
|
||||
<if test="orderId != null and orderId != ''">#{orderId},</if>
|
||||
<if test="appId != null">#{appId},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="currency != null and currency != ''">#{currency},</if>
|
||||
<if test="amount != null">#{amount},</if>
|
||||
<if test="feeCurrency != null and feeCurrency != ''">#{feeCurrency},</if>
|
||||
<if test="feeAmount != null">#{feeAmount},</if>
|
||||
<if test="toAddress != null and toAddress != ''">#{toAddress},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="auditType != null">#{auditType},</if>
|
||||
<if test="auditorId != null">#{auditorId},</if>
|
||||
<if test="auditRemark != null">#{auditRemark},</if>
|
||||
<if test="auditedAt != null">#{auditedAt},</if>
|
||||
<if test="blockTransactionId != null">#{blockTransactionId},</if>
|
||||
<if test="executeError != null">#{executeError},</if>
|
||||
<if test="executeCount != null">#{executeCount},</if>
|
||||
<if test="executedAt != null">#{executedAt},</if>
|
||||
<if test="confirmedAt != null">#{confirmedAt},</if>
|
||||
<if test="notifyUrl != null and notifyUrl != ''">#{notifyUrl},</if>
|
||||
<if test="redirectUrl != null">#{redirectUrl},</if>
|
||||
<if test="callbackNum != null">#{callbackNum},</if>
|
||||
<if test="callbackConfirm != null">#{callbackConfirm},</if>
|
||||
<if test="createdAt != null">#{createdAt},</if>
|
||||
<if test="updatedAt != null">#{updatedAt},</if>
|
||||
<if test="deletedAt != null">#{deletedAt},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateUsdtPayoutOrder" parameterType="UsdtPayoutOrder">
|
||||
update usdt_payout_order
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="tradeId != null and tradeId != ''">trade_id = #{tradeId},</if>
|
||||
<if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
|
||||
<if test="appId != null">app_id = #{appId},</if>
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
<if test="currency != null and currency != ''">currency = #{currency},</if>
|
||||
<if test="amount != null">amount = #{amount},</if>
|
||||
<if test="feeCurrency != null and feeCurrency != ''">fee_currency = #{feeCurrency},</if>
|
||||
<if test="feeAmount != null">fee_amount = #{feeAmount},</if>
|
||||
<if test="toAddress != null and toAddress != ''">to_address = #{toAddress},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="auditType != null">audit_type = #{auditType},</if>
|
||||
<if test="auditorId != null">auditor_id = #{auditorId},</if>
|
||||
<if test="auditRemark != null">audit_remark = #{auditRemark},</if>
|
||||
<if test="auditedAt != null">audited_at = #{auditedAt},</if>
|
||||
<if test="blockTransactionId != null">block_transaction_id = #{blockTransactionId},</if>
|
||||
<if test="executeError != null">execute_error = #{executeError},</if>
|
||||
<if test="executeCount != null">execute_count = #{executeCount},</if>
|
||||
<if test="executedAt != null">executed_at = #{executedAt},</if>
|
||||
<if test="confirmedAt != null">confirmed_at = #{confirmedAt},</if>
|
||||
<if test="notifyUrl != null and notifyUrl != ''">notify_url = #{notifyUrl},</if>
|
||||
<if test="redirectUrl != null">redirect_url = #{redirectUrl},</if>
|
||||
<if test="callbackNum != null">callback_num = #{callbackNum},</if>
|
||||
<if test="callbackConfirm != null">callback_confirm = #{callbackConfirm},</if>
|
||||
<if test="createdAt != null">created_at = #{createdAt},</if>
|
||||
<if test="updatedAt != null">updated_at = #{updatedAt},</if>
|
||||
<if test="deletedAt != null">deleted_at = #{deletedAt},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteUsdtPayoutOrderById" parameterType="Long">
|
||||
delete from usdt_payout_order where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteUsdtPayoutOrderByIds" parameterType="String">
|
||||
delete from usdt_payout_order where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/** 代付信用额度和主钱包预占资金计算测试。 */
|
||||
public class PayoutOrderServiceTest {
|
||||
@Test
|
||||
public void shouldAllowUsdtPayoutWithinCreditLimit() {
|
||||
Assert.assertTrue(PayoutOrderService.canUseUsdtCredit(
|
||||
new BigDecimal("10"), new BigDecimal("100"), new BigDecimal("110")));
|
||||
Assert.assertFalse(PayoutOrderService.canUseUsdtCredit(
|
||||
new BigDecimal("-80"), new BigDecimal("100"), new BigDecimal("21")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSubtractActiveReservationsFromMainWallet() {
|
||||
Assert.assertTrue(PayoutOrderService.hasMainWalletCapacity(
|
||||
"USDT", new BigDecimal("1000"), new BigDecimal("50"),
|
||||
new BigDecimal("900"), new BigDecimal("40"),
|
||||
new BigDecimal("100"), new BigDecimal("10")));
|
||||
Assert.assertFalse(PayoutOrderService.hasMainWalletCapacity(
|
||||
"USDT", new BigDecimal("1000"), new BigDecimal("49"),
|
||||
new BigDecimal("900"), new BigDecimal("40"),
|
||||
new BigDecimal("100"), new BigDecimal("10")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRequireTrxPrincipalAndFee() {
|
||||
Assert.assertTrue(PayoutOrderService.hasMainWalletCapacity(
|
||||
"TRX", BigDecimal.ZERO, new BigDecimal("120"),
|
||||
BigDecimal.ZERO, new BigDecimal("10"),
|
||||
new BigDecimal("100"), new BigDecimal("10")));
|
||||
Assert.assertFalse(PayoutOrderService.hasMainWalletCapacity(
|
||||
"TRX", BigDecimal.ZERO, new BigDecimal("119.999999"),
|
||||
BigDecimal.ZERO, new BigDecimal("10"),
|
||||
new BigDecimal("100"), new BigDecimal("10")));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user