diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tg/TgPremiumOrderInfoController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tg/TgPremiumOrderInfoController.java new file mode 100644 index 000000000..e6f440f3f --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tg/TgPremiumOrderInfoController.java @@ -0,0 +1,152 @@ +package com.ruoyi.web.controller.tg; + + +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.TgPremiumOrderInfo; +import com.ruoyi.common.core.domain.vo.TgPremiumOrderInfoMultiVO; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.service.ITgPremiumOrderInfoService; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * TG会员充值Controller + * + * @author dorion + * @date 2024-05-04 + */ +@Controller +@RequestMapping("/tg/recharge") +public class TgPremiumOrderInfoController extends BaseController +{ + private String prefix = "tg/recharge"; + + @Autowired + private ITgPremiumOrderInfoService tgPremiumOrderInfoService; + + @RequiresPermissions("tg:recharge:view") + @GetMapping() + public String recharge() + { + return prefix + "/recharge"; + } + + /** + * 查询TG会员充值列表 + */ + @RequiresPermissions("tg:recharge:list") + @PostMapping("/list") + @ResponseBody + public TableDataInfo list(TgPremiumOrderInfo tgPremiumOrderInfo) + { + startPage(); + List list = tgPremiumOrderInfoService.selectTgPremiumOrderInfoList(tgPremiumOrderInfo); + return getDataTable(list); + } + + /** + * 导出TG会员充值列表 + */ + @RequiresPermissions("tg:recharge:export") + @Log(title = "TG会员充值", businessType = BusinessType.EXPORT) + @PostMapping("/export") + @ResponseBody + public AjaxResult export(TgPremiumOrderInfo tgPremiumOrderInfo) + { + List list = tgPremiumOrderInfoService.selectTgPremiumOrderInfoList(tgPremiumOrderInfo); + ExcelUtil util = new ExcelUtil(TgPremiumOrderInfo.class); + return util.exportExcel(list, "TG会员充值数据"); + } + + /** + * 新增TG会员充值 + */ + @GetMapping("/add") + public String add() + { + return prefix + "/add"; + } + + /** + * 新增保存TG会员充值 + */ + @RequiresPermissions("tg:recharge:add") + @Log(title = "TG会员充值", businessType = BusinessType.INSERT) + @PostMapping("/add") + @ResponseBody + public AjaxResult addSave(TgPremiumOrderInfo tgPremiumOrderInfo) + { + return toAjax(tgPremiumOrderInfoService.insertTgPremiumOrderInfo(tgPremiumOrderInfo)); + } + + /** + * 新增保存TG会员充值 + */ + @RequiresPermissions("tg:recharge:add") + @Log(title = "TG会员批量充值", businessType = BusinessType.INSERT) + @PostMapping("/addMultiple") + @ResponseBody + public AjaxResult addSaveMultiple(TgPremiumOrderInfoMultiVO tgPremiumOrderInfoMultiVO) + { + return toAjax(tgPremiumOrderInfoService.insertTgPremiumOrderInfoMultiVO(tgPremiumOrderInfoMultiVO)); + } + + /** + * 修改TG会员充值 + */ + @RequiresPermissions("tg:recharge:edit") + @GetMapping("/edit/{idTgPremiumOrderInfo}") + public String edit(@PathVariable("idTgPremiumOrderInfo") Long idTgPremiumOrderInfo, ModelMap mmap) + { + TgPremiumOrderInfo tgPremiumOrderInfo = tgPremiumOrderInfoService.selectTgPremiumOrderInfoByIdTgPremiumOrderInfo(idTgPremiumOrderInfo); + mmap.put("tgPremiumOrderInfo", tgPremiumOrderInfo); + return prefix + "/edit"; + } + + /** + * 修改保存TG会员充值 + */ + @RequiresPermissions("tg:recharge:edit") + @Log(title = "TG会员充值", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + @ResponseBody + public AjaxResult editSave(TgPremiumOrderInfo tgPremiumOrderInfo) + { + return toAjax(tgPremiumOrderInfoService.updateTgPremiumOrderInfo(tgPremiumOrderInfo)); + } + + /** + * 删除TG会员充值 + */ + @RequiresPermissions("tg:recharge:remove") + @Log(title = "TG会员充值", businessType = BusinessType.DELETE) + @PostMapping( "/remove") + @ResponseBody + public AjaxResult remove(String ids) + { + return toAjax(tgPremiumOrderInfoService.deleteTgPremiumOrderInfoByIdTgPremiumOrderInfos(ids)); + } + + + /** + * 删除TG会员充值 + */ + @RequiresPermissions("tg:recharge:add") + @Log(title = "TG会员充值", businessType = BusinessType.ACTIVE_DATA) + @PostMapping( "/activeData") + @ResponseBody + public AjaxResult activeData(String ids) + { + return toAjax(tgPremiumOrderInfoService.activeDataByIdTgPremiumOrderInfos(ids)); + } + +} diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 3f7281aea..8389880a1 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -34,7 +34,7 @@ server: # 日志配置 logging: level: - com.ruoyi: debug + com.ruoyi: info org.springframework: warn # 用户配置 diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js index 44f47baa3..feb64aa8b 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js @@ -1115,6 +1115,18 @@ var table = { $.operate.submit(url, "post", "json", data); } }); + }, activeDataAll: function() { + table.set(); + var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); + if (rows.length == 0) { + $.modal.alertWarning("请至少选择一条记录"); + return; + } + $.modal.confirm("确认要开通/激活选中的" + rows.length + "条数据吗?", function() { + var url = table.options.activeDataUrl; + var data = { "ids": rows.join() }; + $.operate.submit(url, "post", "json", data); + }); }, // 删除信息 remove: function(id) { diff --git a/ruoyi-admin/src/main/resources/templates/tg/recharge/add.html b/ruoyi-admin/src/main/resources/templates/tg/recharge/add.html new file mode 100644 index 000000000..ec9c6eb38 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/tg/recharge/add.html @@ -0,0 +1,53 @@ + + + + + + + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + + +
+
+ + + + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/tg/recharge/edit.html b/ruoyi-admin/src/main/resources/templates/tg/recharge/edit.html new file mode 100644 index 000000000..c4e2b27b0 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/tg/recharge/edit.html @@ -0,0 +1,54 @@ + + + + + + + +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/tg/recharge/recharge.html b/ruoyi-admin/src/main/resources/templates/tg/recharge/recharge.html new file mode 100644 index 000000000..4fedd5f90 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/tg/recharge/recharge.html @@ -0,0 +1,188 @@ + + + + + + +
+
+
+
+
+
    +
  • + + +
  • + +
  • + + +
  • +
  • + + +
  • + +
  • + + +
  • + +
  • +  搜索 +  重置 +
  • +
+
+
+
+ + +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/trx2Energy/exchange/trx.html b/ruoyi-admin/src/main/resources/templates/trx2Energy/exchange/trx.html index 43b73cb3f..a9fe572f7 100644 --- a/ruoyi-admin/src/main/resources/templates/trx2Energy/exchange/trx.html +++ b/ruoyi-admin/src/main/resources/templates/trx2Energy/exchange/trx.html @@ -143,11 +143,11 @@ }, { field: 'trxAmount', - title: '转入金额TRX' + title: '转入TRX' }, { field: 'delegateAmountTrx', - title: '兑换支出TRX' + title: '支出TRX' }, { field: 'delegateTxId', @@ -163,7 +163,7 @@ }, { field: 'delegateStatus', - title: '资源委托状态', + title: '资源状态', formatter: function(value, item, index) { return $.table.selectDictLabel(datas, item.delegateStatus); } @@ -175,8 +175,7 @@ }, { field: 'fcd', - title: '创建时间', - visible: false + title: '创建时间' }, /* { field: 'fcu', diff --git a/ruoyi-admin/src/main/resources/templates/usdt2Trx/exchange/usdt.html b/ruoyi-admin/src/main/resources/templates/usdt2Trx/exchange/usdt.html index 778dffb0b..48e079aaf 100644 --- a/ruoyi-admin/src/main/resources/templates/usdt2Trx/exchange/usdt.html +++ b/ruoyi-admin/src/main/resources/templates/usdt2Trx/exchange/usdt.html @@ -115,8 +115,7 @@ }, { field: 'fcd', - title: '创建时间', - visible: false + title: '创建时间' }, { field: 'fcu', @@ -125,8 +124,7 @@ }, { field: 'lcd', - title: '更新时间', - visible: false + title: '更新时间' }, { field: 'lcu', diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index 9da01ab4f..4c89f49bd 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -1,5 +1,8 @@ package com.ruoyi.common.constant; + +import java.util.Arrays; +import java.util.List; import java.util.Locale; /** @@ -119,4 +122,7 @@ public class Constants */ public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", "org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config", "com.ruoyi.generator" }; + + + public static final List MONTHS = Arrays.asList("3", "6", "12"); } \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/TgPremiumOrderInfo.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/TgPremiumOrderInfo.java new file mode 100644 index 000000000..79a410d76 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/TgPremiumOrderInfo.java @@ -0,0 +1,87 @@ +package com.ruoyi.common.core.domain.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * TG会员充值对象 tg_premium_order_info + * + * @author dorion + * @date 2024-05-04 + */ +@Data +@Accessors(chain = true) +public class TgPremiumOrderInfo extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键 */ + private Long idTgPremiumOrderInfo; + + /** tg用户名 */ + @Excel(name = "tg用户名") + private String rechargeTgUserName; + + /** 开通时长 */ + @Excel(name = "开通时长") + private Long months; + + /** 支付金额(TON) */ + @Excel(name = "支付金额(TON)") + private BigDecimal actualAmount; + + /** tg订单id */ + @Excel(name = "tg订单id") + private String idTg; + + /** tg支付状态 */ + @Excel(name = "tg支付状态") + private String tgPaymentStatus; + + /** 售出金额(USDT) */ + @Excel(name = "售出金额(USDT)") + private String orderAmount; + + /** 是否到账 */ + @Excel(name = "是否到账") + private String isPaid; + + /** 交易账户 */ + @Excel(name = "交易账户") + private String fromAddress; + + /** 转入账户 */ + @Excel(name = "转入账户") + private String toAddress; + + /** 交易id */ + @Excel(name = "交易id") + private Long txId; + + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date fcd; + + /** 创建用户 */ + @Excel(name = "创建用户") + private String fcu; + + /** 更新时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date lcd; + + /** 更新用户 */ + @Excel(name = "更新用户") + private String lcu; + + +} + diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/UsdtExchangeInfo.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/UsdtExchangeInfo.java index 5d89a8dd6..8e2ce71f6 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/UsdtExchangeInfo.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/UsdtExchangeInfo.java @@ -62,8 +62,8 @@ public class UsdtExchangeInfo extends BaseEntity private BigDecimal orginalExchangeRate; /** 创建时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date fcd; /** 创建用户 */ @@ -71,8 +71,8 @@ public class UsdtExchangeInfo extends BaseEntity private String fcu; /** 更新时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date lcd; /** 更新用户 */ diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/TgPremiumOrderInfoMultiVO.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/TgPremiumOrderInfoMultiVO.java new file mode 100644 index 000000000..fc407c6ec --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/TgPremiumOrderInfoMultiVO.java @@ -0,0 +1,12 @@ +package com.ruoyi.common.core.domain.vo; + +import lombok.Data; + +@Data +public class TgPremiumOrderInfoMultiVO { + + private String tgPremiumOrderInfo; + + private String isJoindNow; + +} diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/CheckFragmentPaymentStatusTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/CheckFragmentPaymentStatusTask.java new file mode 100644 index 000000000..537f93fd4 --- /dev/null +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/CheckFragmentPaymentStatusTask.java @@ -0,0 +1,33 @@ +package com.ruoyi.quartz.task; + +import com.ruoyi.common.core.domain.entity.TgPremiumOrderInfo; +import com.ruoyi.system.handler.TgPremiumTransferHandler; +import com.ruoyi.system.mapper.TgPremiumOrderInfoMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component("checkFragmentPaymentStatusTask") +public class CheckFragmentPaymentStatusTask { + + @Autowired + private TgPremiumOrderInfoMapper tgPremiumOrderInfoMapper; + + @Autowired + private TgPremiumTransferHandler tgPremiumTransferHandler; + + public void doCheckFragmentPaymentStatus() { + + TgPremiumOrderInfo tgPremiumOrderInfoExample = new TgPremiumOrderInfo(); + tgPremiumOrderInfoExample.setTgPaymentStatus("P"); + List tgPremiumOrderInfos = tgPremiumOrderInfoMapper.selectTgPremiumOrderInfoList(tgPremiumOrderInfoExample); + + for (TgPremiumOrderInfo tgPremiumOrderInfo : tgPremiumOrderInfos) { + + tgPremiumTransferHandler.checkFragmentPaymentStatus(tgPremiumOrderInfo); + + } + } + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/IFragmentApi.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/IFragmentApi.java new file mode 100644 index 000000000..6bf0b295c --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/IFragmentApi.java @@ -0,0 +1,21 @@ +package com.ruoyi.system.api; + +import com.ruoyi.common.core.domain.entity.TgPremiumOrderInfo; +import com.ruoyi.system.api.entity.fragment.*; + +import java.io.IOException; +import java.math.BigDecimal; + +public interface IFragmentApi { + SearchPremiumGiftRecipientResponse searchPremiumGiftRecipient(TgPremiumOrderInfo tgPremiumOrderInfo) throws IOException; + + InitGiftPremiumResponse initGiftPremium(String recipient, Long months) throws IOException; + + GetGiftPremiumLinkResponse getGiftPremiumLink(String reqId) throws IOException; + + RawResponse rawRequest(String reqId) throws IOException; + + void sendTransactions(String address, BigDecimal amount, String comment) throws IOException; + + CheckReqRespose checkReq(String reqId) throws IOException; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/Params.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/Params.java new file mode 100644 index 000000000..decdc2915 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/Params.java @@ -0,0 +1,16 @@ +package com.ruoyi.system.api.entity; + +import com.ruoyi.system.api.entity.fragment.Messages; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +@Data +public class Params implements Serializable { + + private static final long serialVersionUID = 1L; + + private long valid_until; + private List messages; + private String source; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Body.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Body.java new file mode 100644 index 000000000..37d30f351 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Body.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.api.entity.fragment; + +import com.ruoyi.system.api.entity.Params; +import lombok.Data; + +import java.io.Serializable; +@Data +public class Body implements Serializable { + + private static final long serialVersionUID = 1L; + private String type; + private Params params; + private Response_options response_options; + private long expires_sec; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/CheckReqRespose.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/CheckReqRespose.java new file mode 100644 index 000000000..0bf41dfe0 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/CheckReqRespose.java @@ -0,0 +1,14 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; +@Data +public class CheckReqRespose implements Serializable { + + private static final long serialVersionUID = 1L; + + private Boolean confirmed; + + private String error; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Check_params.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Check_params.java new file mode 100644 index 000000000..e2177c242 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Check_params.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class Check_params implements Serializable { + + private static final long serialVersionUID = 1L; + private String id; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Confirm_params.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Confirm_params.java new file mode 100644 index 000000000..5336b22c2 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Confirm_params.java @@ -0,0 +1,11 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class Confirm_params implements Serializable { + private final static long serialVersionUID = 1L; + private String id; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Found.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Found.java new file mode 100644 index 000000000..07c1b961e --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Found.java @@ -0,0 +1,14 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class Found implements Serializable { + private static final long serialVersionUID = 1L; + private boolean myself; + private String recipient; + private String photo; + private String name; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/GetGiftPremiumLinkResponse.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/GetGiftPremiumLinkResponse.java new file mode 100644 index 000000000..839805d41 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/GetGiftPremiumLinkResponse.java @@ -0,0 +1,16 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; +@Data +public class GetGiftPremiumLinkResponse implements Serializable { + private final static long serialVersionUID = 1L; + + private boolean ok; + private String link; + private String qr_link; + private String check_method; + private Check_params check_params; + private int expire_after; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/InitGiftPremiumResponse.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/InitGiftPremiumResponse.java new file mode 100644 index 000000000..54bbba924 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/InitGiftPremiumResponse.java @@ -0,0 +1,17 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class InitGiftPremiumResponse implements Serializable { + + private static final long serialVersionUID = 1L; + private String req_id; + private boolean myself; + private String amount; + private String item_title; + private String content; + private String button; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Messages.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Messages.java new file mode 100644 index 000000000..b71d9152f --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Messages.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class Messages implements Serializable { + private final static long serialVersionUID = 1L; + private String address; + private long amount; + private String payload; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/RawResponse.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/RawResponse.java new file mode 100644 index 000000000..30e8a415d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/RawResponse.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; +@Data +public class RawResponse implements Serializable { + + private static final long serialVersionUID = 1L; + private String version; + private Body body; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Response_options.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Response_options.java new file mode 100644 index 000000000..718a29127 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Response_options.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; +@Data +public class Response_options implements Serializable { + + private static final long serialVersionUID = 1L; + private String callback_url; + private boolean broadcast; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/SearchPremiumGiftRecipientResponse.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/SearchPremiumGiftRecipientResponse.java new file mode 100644 index 000000000..2879e8dc0 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/SearchPremiumGiftRecipientResponse.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SearchPremiumGiftRecipientResponse implements Serializable { + + private static final long serialVersionUID = 1L; + private boolean ok; + private Found found; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Transaction.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Transaction.java new file mode 100644 index 000000000..2351239dd --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/entity/fragment/Transaction.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.api.entity.fragment; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +@Data +public class Transaction implements Serializable { + private final static long serialVersionUID = 1L; + private long validUntil; + private List messages; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/FragmentApiImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/FragmentApiImpl.java new file mode 100644 index 000000000..af7e26ad1 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/FragmentApiImpl.java @@ -0,0 +1,265 @@ +package com.ruoyi.system.api.impl; + + +import cn.hutool.json.JSONUtil; +import com.ruoyi.common.core.domain.entity.TgPremiumOrderInfo; +import com.ruoyi.system.api.IFragmentApi; +import com.ruoyi.system.api.entity.fragment.*; +import com.ruoyi.system.service.ISysConfigService; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.math.BigDecimal; +import java.net.URLEncoder; + +@Component +@Slf4j +public class FragmentApiImpl implements IFragmentApi { + + @Autowired + private ISysConfigService configService; + + @Override + public SearchPremiumGiftRecipientResponse searchPremiumGiftRecipient(TgPremiumOrderInfo tgPremiumOrderInfo) throws IOException { + + + String hash = configService.selectConfigByKey("sys.fragment.hash"); + String cookie = configService.selectConfigByKey("sys.fragment.cookie"); + // 设置请求URL + String url = "https://fragment.com/api?hash=" + hash; + + // 创建 HttpClient 实例 + HttpClient httpClient = HttpClients.createDefault(); + + // 创建 HttpPost 请求对象 + HttpPost httpPost = new HttpPost(url); + + // 设置请求头 + httpPost.setHeader("Cookie", cookie); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); + + // 构建请求体参数 + String formBody = "query=" + tgPremiumOrderInfo.getRechargeTgUserName() + "&months=" + tgPremiumOrderInfo.getMonths() + "&method=searchPremiumGiftRecipient"; + StringEntity requestEntity = new StringEntity(formBody, ContentType.APPLICATION_FORM_URLENCODED); + httpPost.setEntity(requestEntity); + + // 发送请求并获取响应 + HttpResponse response = httpClient.execute(httpPost); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("searchPremiumGiftRecipient 响应码错误:" + response.getStatusLine().getStatusCode()); + } + // 处理响应 + HttpEntity entity = response.getEntity(); + if (entity != null) { + // 将响应内容转换为字符串 + String responseString = EntityUtils.toString(entity); + SearchPremiumGiftRecipientResponse searchPremiumGiftRecipientResponse = JSONUtil.toBean(responseString, SearchPremiumGiftRecipientResponse.class); + return searchPremiumGiftRecipientResponse; + } + return null; + } + + @Override + public InitGiftPremiumResponse initGiftPremium(String recipient, Long months) throws IOException { + String hash = configService.selectConfigByKey("sys.fragment.hash"); + String cookie = configService.selectConfigByKey("sys.fragment.cookie"); + // 设置请求URL + String url = "https://fragment.com/api?hash=" + hash; + + // 创建 HttpClient 实例 + HttpClient httpClient = HttpClients.createDefault(); + + // 创建 HttpPost 请求对象 + HttpPost httpPost = new HttpPost(url); + + // 设置请求头 + httpPost.setHeader("Cookie", cookie); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); + + // 构建请求体参数 + String formBody = "recipient=" + recipient + "&months=" + months + "&method=initGiftPremiumRequest"; + StringEntity requestEntity = new StringEntity(formBody, ContentType.APPLICATION_FORM_URLENCODED); + httpPost.setEntity(requestEntity); + + // 发送请求并获取响应 + HttpResponse response = httpClient.execute(httpPost); + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("initGiftPremium 响应码错误:" + response.getStatusLine().getStatusCode()); + } + // 处理响应 + HttpEntity entity = response.getEntity(); + if (entity != null) { + // 将响应内容转换为字符串 + String responseString = EntityUtils.toString(entity); + InitGiftPremiumResponse initGiftPremiumResponse = JSONUtil.toBean(responseString, InitGiftPremiumResponse.class); + return initGiftPremiumResponse; + } + + + return null; + } + + @Override + public GetGiftPremiumLinkResponse getGiftPremiumLink(String reqId) throws IOException { + + String hash = configService.selectConfigByKey("sys.fragment.hash"); + String cookie = configService.selectConfigByKey("sys.fragment.cookie"); + // 设置请求URL + String url = "https://fragment.com/api?hash=" + hash; + + // 创建 HttpClient 实例 + HttpClient httpClient = HttpClients.createDefault(); + + // 创建 HttpPost 请求对象 + HttpPost httpPost = new HttpPost(url); + + // 设置请求头 + httpPost.setHeader("Cookie", cookie); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); + + // 构建请求体参数 + String formBody = "id=" + reqId + "&show_sender=0&method=getGiftPremiumLink"; + StringEntity requestEntity = new StringEntity(formBody, ContentType.APPLICATION_FORM_URLENCODED); + httpPost.setEntity(requestEntity); + + // 发送请求并获取响应 + HttpResponse response = httpClient.execute(httpPost); + + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("getGiftPremiumLink 响应码错误:" + response.getStatusLine().getStatusCode()); + } + // 处理响应 + HttpEntity entity = response.getEntity(); + if (entity != null) { + // 将响应内容转换为字符串 + String responseString = EntityUtils.toString(entity); + GetGiftPremiumLinkResponse getGiftPremiumLinkResponse = JSONUtil.toBean(responseString, GetGiftPremiumLinkResponse.class); + return getGiftPremiumLinkResponse; + } + + + return null; + } + + @Override + public RawResponse rawRequest(String reqId) throws IOException { + String cookie = configService.selectConfigByKey("sys.fragment.cookie"); + // 设置请求URL + String url = "https://fragment.com/tonkeeper/rawRequest?id=" + reqId + "&qr=1"; + + // 创建 HttpClient 实例 + HttpClient httpClient = HttpClients.createDefault(); + + // 创建 HttpPost 请求对象 + HttpPost httpPost = new HttpPost(url); + + // 设置请求头 + httpPost.setHeader("Cookie", cookie); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); + + // 构建请求体参数 + String formBody = "id=" + reqId + "&show_sender=1&method=getGiftPremiumLink"; + StringEntity requestEntity = new StringEntity(formBody, ContentType.APPLICATION_FORM_URLENCODED); + httpPost.setEntity(requestEntity); + + // 发送请求并获取响应 + HttpResponse response = httpClient.execute(httpPost); + + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("rawRequest 响应码错误:" + response.getStatusLine().getStatusCode()); + } + // 处理响应 + HttpEntity entity = response.getEntity(); + if (entity != null) { + // 将响应内容转换为字符串 + String responseString = EntityUtils.toString(entity); + RawResponse rawResponse = JSONUtil.toBean(responseString, RawResponse.class); + return rawResponse; + } + + return null; + } + + @Override + public void sendTransactions(String address, BigDecimal amount, String comment) throws IOException { + + // 设置请求URL + String url = "http://127.0.0.1:8888/sendTransactions?send_mode=3&comment=" + URLEncoder.encode(comment); + + // 创建 HttpClient 实例 + HttpClient httpClient = HttpClients.createDefault(); + + // 创建 HttpPost 请求对象 + HttpPost httpPost = new HttpPost(url); + + // 设置请求头 + httpPost.setHeader("Content-Type", "application/json"); + + // 构建请求体参数 + String formBody = "{\"" + address + "\":\"" + amount + "\"}"; + StringEntity requestEntity = new StringEntity(formBody, ContentType.APPLICATION_FORM_URLENCODED); + httpPost.setEntity(requestEntity); + + // 发送请求并获取响应 + HttpResponse response = httpClient.execute(httpPost); + if (response.getStatusLine().getStatusCode() != 200) { + HttpEntity entity = response.getEntity(); + String responseString = null; + if (entity != null) { + responseString = EntityUtils.toString(entity); + log.error("responseString:{}", responseString); + } + throw new RuntimeException("sendTransactions 响应码错误:" + response.getStatusLine().getStatusCode()+"responseString:"+responseString); + } + + } + + @Override + public CheckReqRespose checkReq(String reqId) throws IOException { + String hash = configService.selectConfigByKey("sys.fragment.hash"); + String cookie = configService.selectConfigByKey("sys.fragment.cookie"); + // 设置请求URL + String url = "https://fragment.com/api?hash=" + hash; + + // 创建 HttpClient 实例 + HttpClient httpClient = HttpClients.createDefault(); + + // 创建 HttpPost 请求对象 + HttpPost httpPost = new HttpPost(url); + + // 设置请求头 + httpPost.setHeader("Cookie", cookie); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); + + // 构建请求体参数 + String formBody = "id=" + reqId + "&method=checkReq"; + StringEntity requestEntity = new StringEntity(formBody, ContentType.APPLICATION_FORM_URLENCODED); + httpPost.setEntity(requestEntity); + + // 发送请求并获取响应 + HttpResponse response = httpClient.execute(httpPost); + + if (response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("checkReq 响应码错误:" + response.getStatusLine().getStatusCode()); + } + // 处理响应 + HttpEntity entity = response.getEntity(); + if (entity != null) { + // 将响应内容转换为字符串 + String responseString = EntityUtils.toString(entity); + CheckReqRespose checkReqRespose = JSONUtil.toBean(responseString, CheckReqRespose.class); + return checkReqRespose; + } + return null; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotFunction.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotFunction.java index a3da360f9..f5d482c48 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotFunction.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotFunction.java @@ -1,6 +1,5 @@ package com.ruoyi.system.bot; -import com.ruoyi.system.bot.handle.NewMemberIntoGroup; import com.ruoyi.system.bot.handle.UserChatHandle; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -18,8 +17,6 @@ import java.security.NoSuchAlgorithmException; @Slf4j public class CustomBotFunction { - @Autowired - private NewMemberIntoGroup newMemberIntoGroup; @Autowired private UserChatHandle userChatHandle; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/NewMemberIntoGroup.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/NewMemberIntoGroup.java index 68fd501d0..b59800c04 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/NewMemberIntoGroup.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/NewMemberIntoGroup.java @@ -1,67 +1,67 @@ -package com.ruoyi.system.bot.handle; - -import com.ruoyi.system.bot.utils.SendContent; -import com.ruoyi.system.handler.Usdt2TrxTransferHandler; -import com.ruoyi.system.service.ISysConfigService; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.text.StrSubstitutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.ClassPathResource; -import org.springframework.stereotype.Component; -import org.telegram.telegrambots.meta.api.methods.send.SendPhoto; -import org.telegram.telegrambots.meta.api.objects.InputFile; -import org.telegram.telegrambots.meta.api.objects.Update; -import org.telegram.telegrambots.meta.bots.AbsSender; -import org.telegram.telegrambots.meta.exceptions.TelegramApiException; - -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.util.HashMap; -import java.util.Map; - -@Component -@Slf4j -public class NewMemberIntoGroup { - - @Autowired - private SendContent sendContent; - @Autowired - private ISysConfigService configService; - @Autowired - private Usdt2TrxTransferHandler usdt2TrxTransferHandlerl; - - - public void handleMessage(AbsSender sender, Update update) throws TelegramApiException, IOException, NoSuchAlgorithmException, InvalidKeyException { - InputStream inputStream = - new ClassPathResource("pbottleRPA_1681804582722.png").getInputStream(); - - Long chatId = update.getChatMember().getChat().getId(); - String sysUsdtGroupWelcomTopic = configService.selectConfigByKey("sys.usdt.group.welcom.topic"); - String sysTgGroupChatId = configService.selectConfigByKey("sys.tg.group.chat.id"); - - - - if (StringUtils.isNotEmpty(sysUsdtGroupWelcomTopic) && StringUtils.isNotEmpty(sysTgGroupChatId)){ - BigDecimal oneUsdtToTrx = usdt2TrxTransferHandlerl.getOneUsdtToTrx(); - - BigDecimal tenUsdtToTrx = oneUsdtToTrx.multiply(BigDecimal.TEN); - Map arguments = new HashMap<>(); - arguments.put("tenUsdtToTrx", tenUsdtToTrx); - StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}"); - String message = substitutor.replace(sysUsdtGroupWelcomTopic); - SendPhoto sendPhoto = SendPhoto.builder() - .chatId(chatId.toString()) - .photo(new InputFile(inputStream, "aaa.png")) - .caption(message).build(); - - sender.execute(sendPhoto); - }else { - log.info("sysUsdtGroupWelcomTopic or sysTgGroupChatId is empty"); - } - - } -} +//package com.ruoyi.system.bot.handle; +// +//import com.ruoyi.system.bot.utils.SendContent; +//import com.ruoyi.system.handler.Usdt2TrxTransferHandler; +//import com.ruoyi.system.service.ISysConfigService; +//import lombok.extern.slf4j.Slf4j; +//import org.apache.commons.lang3.StringUtils; +//import org.apache.commons.lang3.text.StrSubstitutor; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.core.io.ClassPathResource; +//import org.springframework.stereotype.Component; +//import org.telegram.telegrambots.meta.api.methods.send.SendPhoto; +//import org.telegram.telegrambots.meta.api.objects.InputFile; +//import org.telegram.telegrambots.meta.api.objects.Update; +//import org.telegram.telegrambots.meta.bots.AbsSender; +//import org.telegram.telegrambots.meta.exceptions.TelegramApiException; +// +//import java.io.IOException; +//import java.io.InputStream; +//import java.math.BigDecimal; +//import java.security.InvalidKeyException; +//import java.security.NoSuchAlgorithmException; +//import java.util.HashMap; +//import java.util.Map; +// +//@Component +//@Slf4j +//public class NewMemberIntoGroup { +// +// @Autowired +// private SendContent sendContent; +// @Autowired +// private ISysConfigService configService; +// @Autowired +// private Usdt2TrxTransferHandler usdt2TrxTransferHandlerl; +// +// +// public void handleMessage(AbsSender sender, Update update) throws TelegramApiException, IOException, NoSuchAlgorithmException, InvalidKeyException { +// InputStream inputStream = +// new ClassPathResource("pbottleRPA_1681804582722.png").getInputStream(); +// +// Long chatId = update.getChatMember().getChat().getId(); +// String sysUsdtGroupWelcomTopic = configService.selectConfigByKey("sys.usdt.group.welcom.topic"); +// String sysTgGroupChatId = configService.selectConfigByKey("sys.tg.group.chat.id"); +// +// +// +// if (StringUtils.isNotEmpty(sysUsdtGroupWelcomTopic) && StringUtils.isNotEmpty(sysTgGroupChatId)){ +// BigDecimal oneUsdtToTrx = usdt2TrxTransferHandlerl.getOneUsdtToTrx(); +// +// BigDecimal tenUsdtToTrx = oneUsdtToTrx.multiply(BigDecimal.TEN); +// Map arguments = new HashMap<>(); +// arguments.put("tenUsdtToTrx", tenUsdtToTrx); +// StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}"); +// String message = substitutor.replace(sysUsdtGroupWelcomTopic); +// SendPhoto sendPhoto = SendPhoto.builder() +// .chatId(chatId.toString()) +// .photo(new InputFile(inputStream, "aaa.png")) +// .caption(message).build(); +// +// sender.execute(sendPhoto); +// }else { +// log.info("sysUsdtGroupWelcomTopic or sysTgGroupChatId is empty"); +// } +// +// } +//} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/UserChatHandle.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/UserChatHandle.java index ffa58ae3d..0f56a9fab 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/UserChatHandle.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/UserChatHandle.java @@ -48,7 +48,7 @@ public class UserChatHandle { configValue = StringUtils.isEmpty(configValue) ? "configKey is null" : configValue; String message = ""; if (StringUtils.isNotEmpty(configValue)){ - BigDecimal tenUsdtToTrx = usdt2TrxTransferHandler.getOneUsdtToTrx().multiply(BigDecimal.TEN); + BigDecimal tenUsdtToTrx = usdt2TrxTransferHandler.getOneUsdtToTrx().getFirst().multiply(BigDecimal.TEN); Map arguments = new HashMap<>(); arguments.put("tenUsdtToTrx", tenUsdtToTrx); StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}"); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/EnergyTenantTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/EnergyTenantTransferHandler.java index 9fac40017..7c9f4b950 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/EnergyTenantTransferHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/EnergyTenantTransferHandler.java @@ -8,8 +8,8 @@ import com.ruoyi.common.utils.DictUtils; import com.ruoyi.common.utils.ForwardCounter; import com.ruoyi.common.utils.LogUtils; import com.ruoyi.system.domain.TrxExchangeMonitorAccountInfo; -import com.ruoyi.system.mapper.ErrorLogMapper; import com.ruoyi.system.mapper.TrxExchangeInfoMapper; +import com.ruoyi.system.service.IErrorLogService; import com.ruoyi.system.service.ITenantInfoService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -29,8 +29,9 @@ public class EnergyTenantTransferHandler { private UndelegateEnergyHandler undelegateEnergyHandler; @Autowired private ITenantInfoService tenantInfoService; + @Autowired - private ErrorLogMapper errorLogMapper; + private IErrorLogService errorLogService; /** * 按照定制客户一个一个处理 @@ -65,7 +66,7 @@ public class EnergyTenantTransferHandler { .errorMsg(exceptionString.length() > 2000 ? exceptionString.substring(0, 2000) : exceptionString) .fcu("system") .lcu("system").build(); - errorLogMapper.insertErrorLog(errorLog); + errorLogService.insertErrorLog(errorLog); throw new RuntimeException(e); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/TRX2EneryTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/TRX2EneryTransferHandler.java index d33e2e5ff..a1cc9ce0d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/TRX2EneryTransferHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/TRX2EneryTransferHandler.java @@ -21,9 +21,9 @@ import com.ruoyi.system.dto.Contract; import com.ruoyi.system.dto.Data; import com.ruoyi.system.dto.TronGridResponse; import com.ruoyi.system.dto.Value; -import com.ruoyi.system.mapper.ErrorLogMapper; import com.ruoyi.system.mapper.TenantInfoMapper; import com.ruoyi.system.mapper.TrxExchangeInfoMapper; +import com.ruoyi.system.service.IErrorLogService; import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.util.AddressUtil; import lombok.extern.slf4j.Slf4j; @@ -65,14 +65,15 @@ public class TRX2EneryTransferHandler { private RedisTemplate redisTemplate; @Autowired private RedissonClient redissonClient; - @Autowired - private ErrorLogMapper errorLogMapper; + @Autowired private TenantInfoMapper tenantInfoMapper; @Autowired private TrxExchangeInfoMapper trxExchangeInfoMapper; @Autowired private SendContent sendContent; + @Autowired + private IErrorLogService errorLogService; public void doMonitorTrxTransferByMonitorAddressInfo(MonitorAddressAccount monitorAddressAccount) { @@ -94,8 +95,7 @@ public class TRX2EneryTransferHandler { .errorMsg(exceptionString.length() > 2000 ? exceptionString.substring(0, 2000) : exceptionString) .fcu("system") .lcu("system").build(); - errorLogMapper.insertErrorLog(errorLog); - + errorLogService.insertErrorLog(errorLog); } Object responseEntityBody = getResponseEntityBody(responseEntity, monitorAddress); @@ -147,7 +147,7 @@ public class TRX2EneryTransferHandler { .fcu("system") .lcu("system").build(); - errorLogMapper.insertErrorLog(errorLog); + errorLogService.insertErrorLog(errorLog); // throw new RuntimeException("doDelegateResource业务处理异常", e); } finally { if (lock.isLocked()) { @@ -262,7 +262,7 @@ public class TRX2EneryTransferHandler { .trxId(txID) .fcu("system") .lcu("system").build(); - errorLogMapper.insertErrorLog(errorLog); + errorLogService.insertErrorLog(errorLog); return; } tenantInfo.setIsPaid("Y"); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/TgPremiumTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/TgPremiumTransferHandler.java new file mode 100644 index 000000000..673dfb6c9 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/TgPremiumTransferHandler.java @@ -0,0 +1,323 @@ +package com.ruoyi.system.handler; + +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.ruoyi.common.core.domain.entity.ErrorLog; +import com.ruoyi.common.core.domain.entity.TgPremiumOrderInfo; +import com.ruoyi.common.utils.ForwardCounter; +import com.ruoyi.common.utils.LogUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.api.IFragmentApi; +import com.ruoyi.system.api.entity.Params; +import com.ruoyi.system.api.entity.fragment.*; +import com.ruoyi.system.mapper.TgPremiumOrderInfoMapper; +import com.ruoyi.system.service.IErrorLogService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Base64; +import java.util.Date; +import java.util.List; + +@Component +@Slf4j +public class TgPremiumTransferHandler { + + @Autowired + private IFragmentApi fragmentApi; + + @Autowired + private IErrorLogService errorLogService; + @Autowired + private TgPremiumOrderInfoMapper tgPremiumOrderInfoMapper; + + public void doRechargeAndUpdate(TgPremiumOrderInfo tgPremiumOrderInfo) { + + doRecharge(tgPremiumOrderInfo); + tgPremiumOrderInfo.setLcu("syste"); + tgPremiumOrderInfoMapper.updateTgPremiumOrderInfo(tgPremiumOrderInfo); + } + + private void doRecharge(TgPremiumOrderInfo tgPremiumOrderInfo) { + String comment = null; + String address = null; + Long amount = null; + + Integer count = 0; + do { + try { + SearchPremiumGiftRecipientResponse searchPremiumGiftRecipientResponse = fragmentApi.searchPremiumGiftRecipient(tgPremiumOrderInfo); + + String recipient = recipient(searchPremiumGiftRecipientResponse); + //创建订单 + InitGiftPremiumResponse initGiftPremiumResponse = fragmentApi.initGiftPremium(recipient, tgPremiumOrderInfo.getMonths()); + + String reqId = reqId(initGiftPremiumResponse); + //确认订单 + GetGiftPremiumLinkResponse getGiftPremiumLinkResponse = fragmentApi.getGiftPremiumLink(reqId); + + //获取收款地址和payload参数 + RawResponse response = fragmentApi.rawRequest(reqId); + + Messages message = messages(response); + + address = message.getAddress(); + String payload = message.getPayload(); + +// comment = extractRefFromPayload(payload, tgPremiumOrderInfo.getMonths()); +// + comment = constructComment(payload, tgPremiumOrderInfo.getMonths()); + + amount = message.getAmount(); + BigDecimal actualAmount = BigDecimal.valueOf(amount).movePointLeft(9); + tgPremiumOrderInfo.setActualAmount(actualAmount); + tgPremiumOrderInfo.setIdTg(reqId); + } catch (Exception e) { + String exceptionString = LogUtils.doRecursiveReversePrintStackCause(e, 5, ForwardCounter.builder().count(0).build(), 5); + log.error("fragment_error:{}", exceptionString); + ErrorLog errorLog = ErrorLog.builder() + .address(tgPremiumOrderInfo.getRechargeTgUserName()) + .otherId(String.valueOf(tgPremiumOrderInfo.getIdTgPremiumOrderInfo())) + .errorCode("fragment_error") + .errorMsg(exceptionString.length() > 2000 ? exceptionString.substring(0, 2000) : exceptionString) + .fcu("system") + .lcu("system").build(); + + errorLogService.insertErrorLog(errorLog); + + if (count >= 5) { + break; + } + count++; + } + + } while (comment == null); + + + + if (count < 5) { + count = 0; + do { + try { +// BigDecimal actualAmount = BigDecimal.valueOf(amount).movePointLeft(9); + fragmentApi.sendTransactions(address, tgPremiumOrderInfo.getActualAmount(), comment); + tgPremiumOrderInfo.setTgPaymentStatus("P"); +// tgPremiumOrderInfo.setActualAmount(actualAmount); + break; + } catch (Exception e) { + String exceptionString = LogUtils.doRecursiveReversePrintStackCause(e, 5, ForwardCounter.builder().count(0).build(), 5); + log.error("go_sendTransactions_error:{}", exceptionString); + ErrorLog errorLog = ErrorLog.builder() + .address(tgPremiumOrderInfo.getRechargeTgUserName()) + .otherId(String.valueOf(tgPremiumOrderInfo.getIdTgPremiumOrderInfo())) + .errorCode("go_sendTransactions_error") + .errorMsg(exceptionString.length() > 2000 ? exceptionString.substring(0, 2000) : exceptionString) + .fcu("system") + .lcu("system").build(); + + errorLogService.insertErrorLog(errorLog); + count++; + } + } while (count < 5); + } + + tgPremiumOrderInfo.setTgPaymentStatus("E"); + + } + + private static Messages messages(RawResponse response) { + if (response == null) { + throw new RuntimeException("response is null"); + } + + Body body = response.getBody(); + + if (body == null) { + throw new RuntimeException("body is null"); + } + Params params = body.getParams(); + + if (params == null) { + throw new RuntimeException("params is null"); + } + List messages = params.getMessages(); + if (messages == null || messages.size() == 0) { + throw new RuntimeException("params.getMessages() is null"); + } + Messages message = messages.get(0); + return message; + } + + private static String reqId(InitGiftPremiumResponse initGiftPremiumResponse) { + if (initGiftPremiumResponse == null) { + throw new RuntimeException("initGiftPremiumResponse is null"); + } + + String reqId = initGiftPremiumResponse.getReq_id(); + if (StringUtils.isBlank(reqId)) { + throw new RuntimeException("reqId is null"); + } + return reqId; + } + + private static String recipient(SearchPremiumGiftRecipientResponse searchPremiumGiftRecipientResponse) { + if (searchPremiumGiftRecipientResponse == null) { + throw new RuntimeException("searchPremiumGiftRecipientResponse is null"); + } + + if (!searchPremiumGiftRecipientResponse.isOk()) { + throw new RuntimeException("searchPremiumGiftRecipientResponse is not ok,请检查用户信息"); + } + + Found found = searchPremiumGiftRecipientResponse.getFound(); + + if (found == null) { + throw new RuntimeException("found is null"); + } + + //获取用户信息 + String recipient = found.getRecipient(); + return recipient; + } + + + public static String constructComment(String payload, Long premium_package_month) { + byte[] decodedBytes = Base64.getDecoder().decode(payload); + + String decodedString = new String(decodedBytes); + log.info("decodedString:{}", decodedString); + + // 使用 "#" 分割字符串 + String[] parts = decodedString.split("#"); + String base32_1 = parts.length > 1 ? parts[1] : ""; + + // 移除 base32_1 中的非字母数字字符 + base32_1 = base32_1.replaceAll("[^A-Za-z0-9]", ""); + + // 如果 base32_1 长度不是 8,则重试 + if (base32_1.length() != 9) { + // 在这里添加重试逻辑 + log.error("长度不是 9"); + return null; + } + + // 构造最终订单数据 +// Integer premium_package_month = 3; +// String orderData = "Telegram Premium for " + (premium_package_month == 12 ? "1 year" : premium_package_month + " months") + " Ref#" + base32_1; + String orderData = "Telegram Premium for " + (premium_package_month == 12 ? "1 year" : premium_package_month + " months") + " \n" + + "\n" + + "Ref#" + base32_1; + return orderData; + } + +/* public static void main(String[] args) { + String comment = constructComment("te6ccgEBAgEANgABTgAAAABUZWxlZ3JhbSBQcmVtaXVtIGZvciAzIG1vbnRocyAKClJlZgEAFCNMa2M1MWhvZkw"); + + + String s = extractRefFromPayload("te6ccgEBAgEANgABTgAAAABUZWxlZ3JhbSBQcmVtaXVtIGZvciAzIG1vbnRocyAKClJlZgEAFCNMa2M1MWhvZkw", tgPremiumOrderInfo.getMonths()); + System.out.println(s); + }*/ + + + public static String extractRefFromPayload(String payload, Long months) { + byte[] decodedBytes = Base64.getDecoder().decode(payload); + + String decodedPayloadStr = new String(decodedBytes); + + log.info("decodedPayloadStr:{}", decodedPayloadStr); +// String decodedPayloadStr = payload; + String refStr = null; + int index = decodedPayloadStr.indexOf("#"); + + if (index != -1) { + StringBuilder sb = new StringBuilder(); + // 开始从 "#" 之后的位置提取字符,最多提取8个字符 + for (int i = index + 1; i < decodedPayloadStr.length() && sb.length() < 9; i++) { + char c = decodedPayloadStr.charAt(i); + if (Character.isLetterOrDigit(c)) { + sb.append(c); + } + } + refStr = sb.toString(); +// String orderData = "Telegram Premium for " + (months == 12 ? "1 year" : months + " months") + " Ref#" + refStr; + String orderData = "Telegram Premium for " + (months == 12 ? "1 year" : months + " months") + " \n" + + "\n" + + "Ref#" + refStr; + return orderData; + } + + return refStr; + } + + public void checkFragmentPaymentStatus(TgPremiumOrderInfo tgPremiumOrderInfo) { + try { + CheckReqRespose checkReqRespose = fragmentApi.checkReq(tgPremiumOrderInfo.getIdTg()); + if (checkReqRespose == null){ + log.error("checkReqRespose is null"); + return; + } + Boolean confirmed = checkReqRespose.getConfirmed(); + if (confirmed != null && confirmed){ + log.error("confirmed is null"); + tgPremiumOrderInfo.setTgPaymentStatus("Y"); + tgPremiumOrderInfo.setLcu("system"); + tgPremiumOrderInfoMapper.updateTgPremiumOrderInfo(tgPremiumOrderInfo); + }else { + String error = checkReqRespose.getError(); + if (StringUtils.isNotBlank(error)){ + log.error("checkFragmentPaymentStatus_error_return:{}", error); + tgPremiumOrderInfo.setTgPaymentStatus("E"); + tgPremiumOrderInfoMapper.updateTgPremiumOrderInfo(tgPremiumOrderInfo); + ErrorLog errorLog = ErrorLog.builder() + .address(tgPremiumOrderInfo.getRechargeTgUserName()) + .otherId(String.valueOf(tgPremiumOrderInfo.getIdTgPremiumOrderInfo())) + .errorCode("checkFragmentPaymentStatus_error_return") + .errorMsg(error) + .fcu("system") + .lcu("system").build(); + + errorLogService.insertErrorLog(errorLog); + }else { + Date fcd = tgPremiumOrderInfo.getFcd(); + long betweenMinutes = DateUtil.between(fcd, new Date(), DateUnit.MINUTE); + if (betweenMinutes >= 10){ + log.error("checkFragmentPaymentStatus_error_timeout:"); + tgPremiumOrderInfo.setTgPaymentStatus("E"); + tgPremiumOrderInfoMapper.updateTgPremiumOrderInfo(tgPremiumOrderInfo); + ErrorLog errorLog = ErrorLog.builder() + .address(tgPremiumOrderInfo.getRechargeTgUserName()) + .otherId(String.valueOf(tgPremiumOrderInfo.getIdTgPremiumOrderInfo())) + .errorCode("checkFragmentPaymentStatus_error_timeout") + .errorMsg("systemScanTimeOut") + .fcu("system") + .lcu("system").build(); + + errorLogService.insertErrorLog(errorLog); + } + } + + + + + } + + } catch (IOException e) { + String exceptionString = LogUtils.doRecursiveReversePrintStackCause(e, 5, ForwardCounter.builder().count(0).build(), 5); + log.error("checkFragmentPaymentStatus_error:{}", exceptionString); + ErrorLog errorLog = ErrorLog.builder() + .address(tgPremiumOrderInfo.getRechargeTgUserName()) + .otherId(String.valueOf(tgPremiumOrderInfo.getIdTgPremiumOrderInfo())) + .errorCode("checkFragmentPaymentStatus_error") + .errorMsg(exceptionString.length() > 2000 ? exceptionString.substring(0, 2000) : exceptionString) + .fcu("system") + .lcu("system").build(); + + errorLogService.insertErrorLog(errorLog); + } + } +} + + diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/UndelegateEnergyHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/UndelegateEnergyHandler.java index ec804bf15..aa8d3168a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/UndelegateEnergyHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/UndelegateEnergyHandler.java @@ -12,9 +12,9 @@ import com.ruoyi.common.utils.encrpt.Dt; import com.ruoyi.system.api.ITronApi; import com.ruoyi.system.domain.TrxExchangeMonitorAccountInfo; import com.ruoyi.system.dto.AccountResourceResponse; -import com.ruoyi.system.mapper.ErrorLogMapper; import com.ruoyi.system.mapper.TenantInfoMapper; import com.ruoyi.system.mapper.TrxExchangeInfoMapper; +import com.ruoyi.system.service.IErrorLogService; import lombok.extern.slf4j.Slf4j; import org.redisson.Redisson; import org.redisson.api.RLock; @@ -41,14 +41,17 @@ public class UndelegateEnergyHandler { private TenantInfoMapper tenantInfoMapper; @Autowired private TRX2EneryTransferHandler trx2EneryTransferHandler; - @Autowired - private ErrorLogMapper errorLogMapper; + @Autowired private TrxExchangeInfoMapper trxExchangeInfoMapper; @Autowired private ITronApi tronApi; + @Autowired + private IErrorLogService errorLogService; + + public void doUndelegateEnergyByTrxExchangeInfo(TrxExchangeMonitorAccountInfo trxExchangeMonitorAccountInfo) { Long lockPeriod = trxExchangeMonitorAccountInfo.getLockPeriod(); Date fcd = trxExchangeMonitorAccountInfo.getFcd(); @@ -193,8 +196,8 @@ public class UndelegateEnergyHandler { .otherId(trxExchangeMonitorAccountInfo.getIdTrxExchangeInfo().toString()) .fcu("system") .lcu("system").build(); - errorLogMapper.insertErrorLog(errorLog); - throw new RuntimeException("回收能量业务处理异常", e); + errorLogService.insertErrorLog(errorLog); +// throw new RuntimeException("回收能量业务处理异常", e); } finally { if (lock.isLocked()) { if (lock.isHeldByCurrentThread()) { @@ -238,4 +241,6 @@ public class UndelegateEnergyHandler { .build(); trxExchangeInfoMapper.updateTrxExchangeInfo(trxExchangeInfo); } + + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java index e28fbf888..13af0e93a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java @@ -24,9 +24,9 @@ import com.ruoyi.system.domain.MonitorAddressAccount; import com.ruoyi.system.dto.Data; import com.ruoyi.system.dto.Token_info; import com.ruoyi.system.dto.TronGridResponse; -import com.ruoyi.system.mapper.ErrorLogMapper; import com.ruoyi.system.mapper.UsdtExchangeInfoMapper; import com.ruoyi.system.service.IAccountAddressInfoService; +import com.ruoyi.system.service.IErrorLogService; import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.util.AddressUtil; import lombok.extern.slf4j.Slf4j; @@ -35,6 +35,7 @@ import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.util.Pair; import org.springframework.stereotype.Component; import org.telegram.telegrambots.meta.api.methods.ParseMode; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -79,10 +80,11 @@ public class Usdt2TrxTransferHandler { private TgLongPollingBot longPollingBot; @Autowired private SendContent sendContent; - @Autowired - private ErrorLogMapper errorLogMapper; - public void doMonitorUsdtTransfer(MonitorAddressAccount monitorAddressAccount) { + @Autowired + private IErrorLogService errorLogService; + + public void doMonitorUsdtTransfer(MonitorAddressAccount monitorAddressAccount) { try { String monitorAddress = monitorAddressAccount.getMonitorAddress(); @@ -91,7 +93,7 @@ public class Usdt2TrxTransferHandler { // DateTime min_timestamp = DateUtil.offset(new Date(), DateField.MINUTE, Integer.valueOf(sysTransferBetween)); - TronGridResponse tronGridResponse = tronApi.getTronGridTrc20Response(monitorAddress,true,false, apiKey,min_timestamp.getTime()); + TronGridResponse tronGridResponse = tronApi.getTronGridTrc20Response(monitorAddress, true, false, apiKey, min_timestamp.getTime()); List dataList = tronGridResponse.getData(); if (CollectionUtil.isEmpty(dataList)) { @@ -100,11 +102,13 @@ public class Usdt2TrxTransferHandler { //获取欧易费率 - BigDecimal oneUsdtToTrx = getOneUsdtToTrx(); +// BigDecimal oneUsdtToTrx = getOneUsdtToTrx(); + + Pair oneUsdtToTrxPair = getOneUsdtToTrx(); for (Data data : dataList) { - doMonitorUsdtTransferByData(monitorAddressAccount, data, oneUsdtToTrx, apiKey); + doMonitorUsdtTransferByData(monitorAddressAccount, data, oneUsdtToTrxPair, apiKey); } } catch (Exception e) { String exceptionString = LogUtils.doRecursiveReversePrintStackCause(e, 5, ForwardCounter.builder().count(0).build(), 5); @@ -115,18 +119,18 @@ public class Usdt2TrxTransferHandler { .errorMsg(exceptionString.length() > 2000 ? exceptionString.substring(0, 2000) : exceptionString) .fcu("system") .lcu("system").build(); - errorLogMapper.insertErrorLog(errorLog); + errorLogService.insertErrorLog(errorLog); - throw new RuntimeException("获取trx20交易列表异常",e); + throw new RuntimeException("获取trx20交易列表异常", e); } } - private void doMonitorUsdtTransferByData(MonitorAddressAccount monitorAddressAccount, Data data, BigDecimal oneUsdtToTrx, String apiKey) throws Exception { + private void doMonitorUsdtTransferByData(MonitorAddressAccount monitorAddressAccount, Data data, Pair oneUsdtToTrxPair, String apiKey) throws Exception { BigDecimal transferValue = getTransferValue(data); if (transferValue == null) return; - BigDecimal trxValue = transferValue.multiply(oneUsdtToTrx).setScale(6, BigDecimal.ROUND_HALF_DOWN); + BigDecimal trxValue = transferValue.multiply(oneUsdtToTrxPair.getFirst()).setScale(6, BigDecimal.ROUND_HALF_DOWN); String accountAddress = monitorAddressAccount.getAccountAddress(); String encryptPrivateKey = monitorAddressAccount.getEncryptPrivateKey(); @@ -152,7 +156,7 @@ public class Usdt2TrxTransferHandler { return; } - doTransferUsdtAndStore(oneUsdtToTrx, apiKey, decryptPrivateKey, accountAddress, from, trxValue, dataTo, transactionId, transferValue); + doTransferUsdtAndStore(oneUsdtToTrxPair, apiKey, decryptPrivateKey, accountAddress, from, trxValue, dataTo, transactionId, transferValue); redisTemplate.opsForValue().set("transfer_USDT_" + transactionId, transactionId, 1, TimeUnit.DAYS); } finally { @@ -164,7 +168,7 @@ public class Usdt2TrxTransferHandler { } } - public void doTransferUsdtAndStore(BigDecimal oneUsdtToTrx, String apiKey, String decryptPrivateKey, String accountAddress, String from, BigDecimal trxValue, String dataTo, String transactionId, BigDecimal transferValue) throws IllegalException, TelegramApiException { + public void doTransferUsdtAndStore(Pair oneUsdtToTrxPair, String apiKey, String decryptPrivateKey, String accountAddress, String from, BigDecimal trxValue, String dataTo, String transactionId, BigDecimal transferValue) throws IllegalException, TelegramApiException { String systronApiSwitch = configService.selectConfigByKey("sys.tron.api"); @@ -173,7 +177,7 @@ public class Usdt2TrxTransferHandler { ApiWrapper apiWrapper = ApiWrapper.ofMainnet(decryptPrivateKey, apiKey); - //转账 + //转账 Response.TransactionExtention transfer = apiWrapper.transfer(accountAddress, from, trxValue.movePointRight(6).longValue()); //签名 Chain.Transaction transaction = apiWrapper.signTransaction(transfer); @@ -189,14 +193,16 @@ public class Usdt2TrxTransferHandler { .setUsdtTxId(transactionId) .setUsdtAmount(transferValue) .setTrxAmount(trxValue) - .setExchangeRate(oneUsdtToTrx) - .setOrginalExchangeRate(oneUsdtToTrx) - .setTrxTxId(txId); + .setExchangeRate(oneUsdtToTrxPair.getFirst()) + .setOrginalExchangeRate(oneUsdtToTrxPair.getSecond()) + .setTrxTxId(txId) + .setFcu("system") + .setLcu("system"); usdtExchangeInfoMapper.insertUsdtExchangeInfo(usdtExchangeInfo); - doSendTgNotice(oneUsdtToTrx, from, trxValue, transferValue, txId); + doSendTgNotice(oneUsdtToTrxPair.getFirst(), from, trxValue, transferValue, txId); } private void doSendTgNotice(BigDecimal oneUsdtToTrx, String from, BigDecimal trxValue, BigDecimal transferValue, String txId) throws TelegramApiException { @@ -209,7 +215,7 @@ public class Usdt2TrxTransferHandler { arguments.put("trxAmount", trxValue); arguments.put("FromAddress", from.replaceAll("(.{6})(.*)(.{8})", "$1********$3")); arguments.put("txId", txId.replaceAll("(.{6})(.*)(.{8})", "$1*******************$3")); - arguments.put("txTime", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss")); + arguments.put("txTime", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); // String message = MessageFormat.format(sysUsdtTranferNotice, arguments); StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}"); String message = substitutor.replace(sysUsdtTranferNotice); @@ -260,7 +266,7 @@ public class Usdt2TrxTransferHandler { * @throws NoSuchAlgorithmException * @throws InvalidKeyException */ - public BigDecimal getOneUsdtToTrx() throws NoSuchAlgorithmException, InvalidKeyException, IOException { + public Pair getOneUsdtToTrx() throws NoSuchAlgorithmException, InvalidKeyException, IOException { OkxResponse oksResponse = okxApi.getSingleTickerOkxResponse2(); Preconditions.checkNotNull(oksResponse, "查询费率失败无法兑换"); String code = oksResponse.getCode(); @@ -278,13 +284,13 @@ public class Usdt2TrxTransferHandler { double oneUsdtToTrxDouble = 1 / new Double(last); BigDecimal oneUsdtToTrx = BigDecimal.valueOf(oneUsdtToTrxDouble).setScale(6, BigDecimal.ROUND_HALF_DOWN); - log.info("实时汇率:{}",oneUsdtToTrx); + log.info("实时汇率:{}", oneUsdtToTrx); String sysUsdtProportionRate = configService.selectConfigByKey("sys.usdt.proportion.rate"); - + BigDecimal discountOneUsdtToTrx = oneUsdtToTrx; if (StringUtils.isNotEmpty(sysUsdtProportionRate)) { - oneUsdtToTrx = oneUsdtToTrx.multiply(BigDecimal.ONE.subtract(new BigDecimal(sysUsdtProportionRate))).setScale(6, BigDecimal.ROUND_HALF_DOWN); + discountOneUsdtToTrx = oneUsdtToTrx.multiply(BigDecimal.ONE.subtract(new BigDecimal(sysUsdtProportionRate))).setScale(6, BigDecimal.ROUND_HALF_DOWN); } - return oneUsdtToTrx; + return Pair.of(discountOneUsdtToTrx, oneUsdtToTrx); } @@ -299,7 +305,8 @@ public class Usdt2TrxTransferHandler { if (longPollingBot != null && StringUtils.isNotEmpty(sysUsdtGroupTopic) && StringUtils.isNotEmpty(sysTgGroupChatId)) { log.info("进入这里1"); try { - BigDecimal tenUsdtToTrx = getOneUsdtToTrx().multiply(BigDecimal.TEN); + BigDecimal oneUsdtToTrx = getOneUsdtToTrx().getFirst(); + BigDecimal tenUsdtToTrx = oneUsdtToTrx.multiply(BigDecimal.TEN); Map arguments = new HashMap<>(); arguments.put("tenUsdtToTrx", tenUsdtToTrx); StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}"); @@ -309,9 +316,9 @@ public class Usdt2TrxTransferHandler { longPollingBot.execute(sendMessage); } catch (Exception e) { - log.error("广播消息异常",e); + log.error("广播消息异常", e); } - }else { + } else { log.info("进入这里2"); log.warn("sysUsdtTranferNotice OR sysTgGroupChatId is null"); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/interceptor/MiddlegenSystemBean.java b/ruoyi-system/src/main/java/com/ruoyi/system/interceptor/MiddlegenSystemBean.java new file mode 100644 index 000000000..1c7ad8d73 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/interceptor/MiddlegenSystemBean.java @@ -0,0 +1,31 @@ +package com.ruoyi.system.interceptor; + + +import org.springframework.aop.aspectj.AspectJExpressionPointcut; +import org.springframework.aop.support.DefaultPointcutAdvisor; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +@Component +public class MiddlegenSystemBean { + + public static final String DIGEST_EXECUTION = "execution( * com.ruoyi.system.api.*.*(..))"; + + /** + * 切面摘要 + * @return + */ + @Bean(name = "systemPointcutAdvisor") + public DefaultPointcutAdvisor defaultPointcutAdvisor(){ + + AspectJExpressionPointcut aspectJExpressionPointcut = new AspectJExpressionPointcut(); + aspectJExpressionPointcut.setExpression(DIGEST_EXECUTION); + + SystemDigestInterceptor systemDigestInterceptor = new SystemDigestInterceptor(); + + DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor(); + defaultPointcutAdvisor.setAdvice(systemDigestInterceptor); + defaultPointcutAdvisor.setPointcut(aspectJExpressionPointcut); + return defaultPointcutAdvisor; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/interceptor/SystemDigestInterceptor.java b/ruoyi-system/src/main/java/com/ruoyi/system/interceptor/SystemDigestInterceptor.java new file mode 100644 index 000000000..5cbe07887 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/interceptor/SystemDigestInterceptor.java @@ -0,0 +1,77 @@ +package com.ruoyi.system.interceptor; + + +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.lang.reflect.Method; + +@Slf4j +public class SystemDigestInterceptor implements MethodInterceptor { + + + private static final String SEP = ","; + private static final String NULL_REPLACEMENT = "null"; + + @Nullable + @Override + public Object invoke(@Nonnull MethodInvocation invocation) throws Throwable { + + //被拦截的方法 + Method method = invocation.getMethod(); + //方法签名 + String invocationSignature = method.getDeclaringClass().getSimpleName() + SEP + method.getName(); + + boolean isSuccess = true; + + long start = System.currentTimeMillis(); + Object proceed = null; + try { + proceed = invocation.proceed(); + return proceed; + } catch (Exception e) { + isSuccess = false; + throw e; + } finally { + long elapseTime = System.currentTimeMillis() - start; + if (log.isInfoEnabled()) { + log.info(buildDigestLog(invocationSignature, isSuccess, elapseTime, invocation.getArguments(),proceed)); + } + } + } + + /** + * 构造摘要日志 + * + * @param invocationSignature 调用签名 + * @param isSuccess 是否成功 + * @param elapseTime 耗时 + * @param arguments 参数 + * @return 日志 + */ + private String buildDigestLog(String invocationSignature, boolean isSuccess, long elapseTime, Object[] arguments,Object proceed) { + + StringBuilder sb = new StringBuilder(); + sb.append("["); + + { + sb.append("("); + sb.append(invocationSignature).append(SEP); + sb.append(isSuccess ? "Y" : "N").append(SEP); + sb.append(arguments == null ? NULL_REPLACEMENT : JSONUtil.toJsonStr(arguments)).append(SEP); + sb.append(proceed == null ? NULL_REPLACEMENT : JSONUtil.toJsonStr(proceed)).append(SEP); + sb.append(elapseTime).append("ms"); + sb.append(")"); + + } + sb.append("]"); + + return sb.toString(); + } + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TgPremiumOrderInfoMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TgPremiumOrderInfoMapper.java new file mode 100644 index 000000000..5f1be35e5 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TgPremiumOrderInfoMapper.java @@ -0,0 +1,63 @@ +package com.ruoyi.system.mapper; + +import com.ruoyi.common.core.domain.entity.TgPremiumOrderInfo; + +import java.util.List; + + +/** + * TG会员充值Mapper接口 + * + * @author dorion + * @date 2024-05-04 + */ +public interface TgPremiumOrderInfoMapper +{ + /** + * 查询TG会员充值 + * + * @param idTgPremiumOrderInfo TG会员充值主键 + * @return TG会员充值 + */ + public TgPremiumOrderInfo selectTgPremiumOrderInfoByIdTgPremiumOrderInfo(Long idTgPremiumOrderInfo); + + /** + * 查询TG会员充值列表 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return TG会员充值集合 + */ + public List selectTgPremiumOrderInfoList(TgPremiumOrderInfo tgPremiumOrderInfo); + + /** + * 新增TG会员充值 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return 结果 + */ + public int insertTgPremiumOrderInfo(TgPremiumOrderInfo tgPremiumOrderInfo); + + /** + * 修改TG会员充值 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return 结果 + */ + public int updateTgPremiumOrderInfo(TgPremiumOrderInfo tgPremiumOrderInfo); + + /** + * 删除TG会员充值 + * + * @param idTgPremiumOrderInfo TG会员充值主键 + * @return 结果 + */ + public int deleteTgPremiumOrderInfoByIdTgPremiumOrderInfo(Long idTgPremiumOrderInfo); + + /** + * 批量删除TG会员充值 + * + * @param idTgPremiumOrderInfos 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteTgPremiumOrderInfoByIdTgPremiumOrderInfos(String[] idTgPremiumOrderInfos); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IErrorLogService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IErrorLogService.java index 323dd5fb8..3c1e92be4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IErrorLogService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IErrorLogService.java @@ -35,7 +35,7 @@ public interface IErrorLogService * @param errorLog 错误日志 * @return 结果 */ - public int insertErrorLog(ErrorLog errorLog); + public int insertErrorLog(ErrorLog errorLog) ; /** * 修改错误日志 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ITgPremiumOrderInfoService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITgPremiumOrderInfoService.java new file mode 100644 index 000000000..573a07f26 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ITgPremiumOrderInfoService.java @@ -0,0 +1,68 @@ +package com.ruoyi.system.service; + + +import com.ruoyi.common.core.domain.entity.TgPremiumOrderInfo; +import com.ruoyi.common.core.domain.vo.TgPremiumOrderInfoMultiVO; + +import java.util.List; + +/** + * TG会员充值Service接口 + * + * @author dorion + * @date 2024-05-04 + */ +public interface ITgPremiumOrderInfoService +{ + /** + * 查询TG会员充值 + * + * @param idTgPremiumOrderInfo TG会员充值主键 + * @return TG会员充值 + */ + public TgPremiumOrderInfo selectTgPremiumOrderInfoByIdTgPremiumOrderInfo(Long idTgPremiumOrderInfo); + + /** + * 查询TG会员充值列表 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return TG会员充值集合 + */ + public List selectTgPremiumOrderInfoList(TgPremiumOrderInfo tgPremiumOrderInfo); + + /** + * 新增TG会员充值 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return 结果 + */ + public int insertTgPremiumOrderInfo(TgPremiumOrderInfo tgPremiumOrderInfo); + + /** + * 修改TG会员充值 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return 结果 + */ + public int updateTgPremiumOrderInfo(TgPremiumOrderInfo tgPremiumOrderInfo); + + /** + * 批量删除TG会员充值 + * + * @param idTgPremiumOrderInfos 需要删除的TG会员充值主键集合 + * @return 结果 + */ + public int deleteTgPremiumOrderInfoByIdTgPremiumOrderInfos(String idTgPremiumOrderInfos); + + /** + * 删除TG会员充值信息 + * + * @param idTgPremiumOrderInfo TG会员充值主键 + * @return 结果 + */ + public int deleteTgPremiumOrderInfoByIdTgPremiumOrderInfo(Long idTgPremiumOrderInfo); + + int insertTgPremiumOrderInfoMultiVO(TgPremiumOrderInfoMultiVO tgPremiumOrderInfoMultiVO); + + int activeDataByIdTgPremiumOrderInfos(String ids); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ApiServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ApiServiceImpl.java index 2747faa2c..9a8e8f40c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ApiServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ApiServiceImpl.java @@ -54,7 +54,7 @@ public class ApiServiceImpl implements IApiService { CompletableFuture queryOkxFuture = CompletableFuture.runAsync(() -> { BigDecimal oneUsdtToTrx = null; try { - oneUsdtToTrx = usdt2TrxTransferHandler.getOneUsdtToTrx(); + oneUsdtToTrx = usdt2TrxTransferHandler.getOneUsdtToTrx().getFirst(); // oneUsdtToTrx = BigDecimal.valueOf(7.53); } catch (Exception e) { throw new RuntimeException(e); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ErrorLogServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ErrorLogServiceImpl.java index 4308058d2..c6265e5e7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ErrorLogServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ErrorLogServiceImpl.java @@ -1,101 +1,133 @@ package com.ruoyi.system.service.impl; +import cn.hutool.core.date.DateUtil; import com.ruoyi.common.core.domain.entity.ErrorLog; import com.ruoyi.common.core.text.Convert; -import com.ruoyi.common.utils.ShiroUtils; +import com.ruoyi.common.utils.ForwardCounter; +import com.ruoyi.common.utils.LogUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.bot.TgLongPollingBot; +import com.ruoyi.system.bot.utils.SendContent; import com.ruoyi.system.mapper.ErrorLogMapper; import com.ruoyi.system.service.IErrorLogService; +import com.ruoyi.system.service.ISysConfigService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.text.StrSubstitutor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.telegram.telegrambots.meta.api.methods.ParseMode; +import org.telegram.telegrambots.meta.api.methods.send.SendMessage; +import org.telegram.telegrambots.meta.exceptions.TelegramApiException; +import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 错误日志Service业务层处理 - * + * * @author dorion * @date 2024-04-13 */ @Service -public class ErrorLogServiceImpl implements IErrorLogService -{ +@Slf4j +public class ErrorLogServiceImpl implements IErrorLogService { + + @Autowired(required = false) + private TgLongPollingBot tgLongPollingBot; + @Autowired private ErrorLogMapper errorLogMapper; + @Autowired + private SendContent sendContent; + @Autowired + private ISysConfigService configService; + /** * 查询错误日志 - * + * * @param idErrorLog 错误日志主键 * @return 错误日志 */ @Override - public ErrorLog selectErrorLogByIdErrorLog(Long idErrorLog) - { + public ErrorLog selectErrorLogByIdErrorLog(Long idErrorLog) { return errorLogMapper.selectErrorLogByIdErrorLog(idErrorLog); } /** * 查询错误日志列表 - * + * * @param errorLog 错误日志 * @return 错误日志 */ @Override - public List selectErrorLogList(ErrorLog errorLog) - { + public List selectErrorLogList(ErrorLog errorLog) { return errorLogMapper.selectErrorLogList(errorLog); } /** * 新增错误日志 - * + * * @param errorLog 错误日志 * @return 结果 */ @Override - public int insertErrorLog(ErrorLog errorLog) - { - String userName = ShiroUtils.getLoginName(); - errorLog.setFcu(userName); - errorLog.setLcu(userName); + @Async + public int insertErrorLog(ErrorLog errorLog){ + String sysErrorLogTemplate = configService.selectConfigByKey("sys.error.log.template"); + String sysErrorLogChatId = configService.selectConfigByKey("sys.error.log.chatid"); + if (tgLongPollingBot != null && StringUtils.isNotEmpty(sysErrorLogChatId) && StringUtils.isNotEmpty(sysErrorLogTemplate)) { + Map arguments = new HashMap<>(); + arguments.put("errorCode", errorLog.getErrorCode()); + arguments.put("address", errorLog.getAddress()); + arguments.put("txTime", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); + StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}"); + String message = substitutor.replace(sysErrorLogTemplate); + SendMessage sendMessage = sendContent.messageText(sysErrorLogChatId, message, ParseMode.HTML); + try { + tgLongPollingBot.execute(sendMessage); + } catch (TelegramApiException e) { + String exceptionString = LogUtils.doRecursiveReversePrintStackCause(e, 5, ForwardCounter.builder().count(0).build(), 5); + log.error("TelegramApiException异常:{}", exceptionString); + } + } + return errorLogMapper.insertErrorLog(errorLog); } /** * 修改错误日志 - * + * * @param errorLog 错误日志 * @return 结果 */ @Override - public int updateErrorLog(ErrorLog errorLog) - { - String userName = ShiroUtils.getLoginName(); - errorLog.setLcu(userName); + public int updateErrorLog(ErrorLog errorLog) { return errorLogMapper.updateErrorLog(errorLog); } /** * 批量删除错误日志 - * + * * @param idErrorLogs 需要删除的错误日志主键 * @return 结果 */ @Override - public int deleteErrorLogByIdErrorLogs(String idErrorLogs) - { + public int deleteErrorLogByIdErrorLogs(String idErrorLogs) { return errorLogMapper.deleteErrorLogByIdErrorLogs(Convert.toStrArray(idErrorLogs)); } /** * 删除错误日志信息 - * + * * @param idErrorLog 错误日志主键 * @return 结果 */ @Override - public int deleteErrorLogByIdErrorLog(Long idErrorLog) - { + public int deleteErrorLogByIdErrorLog(Long idErrorLog) { return errorLogMapper.deleteErrorLogByIdErrorLog(idErrorLog); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TgPremiumOrderInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TgPremiumOrderInfoServiceImpl.java new file mode 100644 index 000000000..bd18b32e9 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TgPremiumOrderInfoServiceImpl.java @@ -0,0 +1,166 @@ +package com.ruoyi.system.service.impl; + + +import com.google.common.base.Preconditions; +import com.ruoyi.common.core.domain.entity.TgPremiumOrderInfo; +import com.ruoyi.common.core.domain.vo.TgPremiumOrderInfoMultiVO; +import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.utils.ShiroUtils; +import com.ruoyi.system.handler.TgPremiumTransferHandler; +import com.ruoyi.system.mapper.TgPremiumOrderInfoMapper; +import com.ruoyi.system.service.ITgPremiumOrderInfoService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static com.ruoyi.common.constant.Constants.MONTHS; + +/** + * TG会员充值Service业务层处理 + * + * @author dorion + * @date 2024-05-04 + */ +@Service +@Slf4j +public class TgPremiumOrderInfoServiceImpl implements ITgPremiumOrderInfoService { + @Autowired + private TgPremiumOrderInfoMapper tgPremiumOrderInfoMapper; + @Autowired + private TgPremiumTransferHandler tgPremiumTransferHandler; + + /** + * 查询TG会员充值 + * + * @param idTgPremiumOrderInfo TG会员充值主键 + * @return TG会员充值 + */ + @Override + public TgPremiumOrderInfo selectTgPremiumOrderInfoByIdTgPremiumOrderInfo(Long idTgPremiumOrderInfo) { + return tgPremiumOrderInfoMapper.selectTgPremiumOrderInfoByIdTgPremiumOrderInfo(idTgPremiumOrderInfo); + } + + /** + * 查询TG会员充值列表 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return TG会员充值 + */ + @Override + public List selectTgPremiumOrderInfoList(TgPremiumOrderInfo tgPremiumOrderInfo) { + return tgPremiumOrderInfoMapper.selectTgPremiumOrderInfoList(tgPremiumOrderInfo); + } + + /** + * 新增TG会员充值 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return 结果 + */ + @Override + public int insertTgPremiumOrderInfo(TgPremiumOrderInfo tgPremiumOrderInfo) { + return tgPremiumOrderInfoMapper.insertTgPremiumOrderInfo(tgPremiumOrderInfo); + } + + /** + * 修改TG会员充值 + * + * @param tgPremiumOrderInfo TG会员充值 + * @return 结果 + */ + @Override + public int updateTgPremiumOrderInfo(TgPremiumOrderInfo tgPremiumOrderInfo) { + Long userId = ShiroUtils.getUserId(); + tgPremiumOrderInfo.setLcu(userId.toString()); + return tgPremiumOrderInfoMapper.updateTgPremiumOrderInfo(tgPremiumOrderInfo); + } + + /** + * 批量删除TG会员充值 + * + * @param idTgPremiumOrderInfos 需要删除的TG会员充值主键 + * @return 结果 + */ + @Override + public int deleteTgPremiumOrderInfoByIdTgPremiumOrderInfos(String idTgPremiumOrderInfos) { + return tgPremiumOrderInfoMapper.deleteTgPremiumOrderInfoByIdTgPremiumOrderInfos(Convert.toStrArray(idTgPremiumOrderInfos)); + } + + /** + * 删除TG会员充值信息 + * + * @param idTgPremiumOrderInfo TG会员充值主键 + * @return 结果 + */ + @Override + public int deleteTgPremiumOrderInfoByIdTgPremiumOrderInfo(Long idTgPremiumOrderInfo) { + return tgPremiumOrderInfoMapper.deleteTgPremiumOrderInfoByIdTgPremiumOrderInfo(idTgPremiumOrderInfo); + } + + @Override + public int insertTgPremiumOrderInfoMultiVO(TgPremiumOrderInfoMultiVO tgPremiumOrderInfoMultiVO) { + + log.info("tgPremiumOrderInfoMultiVO:{}", tgPremiumOrderInfoMultiVO); + + String[] tgPremiumOrderInfoArray = tgPremiumOrderInfoMultiVO.getTgPremiumOrderInfo().split("\r\n"); + int count = 1; + String loginName = ShiroUtils.getLoginName(); + List tgPremiumOrderInfoList = new ArrayList<>(); + + + for (String tgPremiumOrderInfoString : tgPremiumOrderInfoArray) { + String[] split = tgPremiumOrderInfoString.split(","); + Preconditions.checkState(split.length == 2, "第" + count + "行,请输入正确的格式[tgUserName],[months]"); + TgPremiumOrderInfo tgPremiumOrderInfo = new TgPremiumOrderInfo(); + tgPremiumOrderInfo.setRechargeTgUserName(split[0]); + Preconditions.checkState(MONTHS.contains(split[1]), "第" + count + "行,请输入正确的月数[3,6,12]"); + tgPremiumOrderInfo.setMonths(Long.valueOf(split[1])); + tgPremiumOrderInfo.setFcd(new Date()); + tgPremiumOrderInfo.setLcd(new Date()); + tgPremiumOrderInfo.setFcu(loginName); + tgPremiumOrderInfo.setLcu(loginName); + tgPremiumOrderInfo.setTgPaymentStatus("N"); + + tgPremiumOrderInfoList.add(tgPremiumOrderInfo); + count++; + } + + if (tgPremiumOrderInfoList.size() > 0) { + for (TgPremiumOrderInfo tgPremiumOrderInfo : tgPremiumOrderInfoList) { + tgPremiumOrderInfoMapper.insertTgPremiumOrderInfo(tgPremiumOrderInfo); + } + + + if ("Y".equals(tgPremiumOrderInfoMultiVO.getIsJoindNow())) { + for (TgPremiumOrderInfo tgPremiumOrderInfo : tgPremiumOrderInfoList) { + tgPremiumTransferHandler.doRechargeAndUpdate(tgPremiumOrderInfo); + /* tgPremiumOrderInfo.setTgPaymentStatus("N"); + if (amount != null){ + tgPremiumOrderInfo.setTgPaymentStatus("Y"); + tgPremiumOrderInfo.setActualAmount(BigDecimal.valueOf(amount).movePointLeft(9)); + } + tgPremiumOrderInfoMapper.updateTgPremiumOrderInfo(tgPremiumOrderInfo);*/ + } + } + } + return 1; + } + + @Override + public int activeDataByIdTgPremiumOrderInfos(String ids) { + String[] idsArray = Convert.toStrArray(ids); + + for (String id : idsArray) { + TgPremiumOrderInfo tgPremiumOrderInfo = tgPremiumOrderInfoMapper.selectTgPremiumOrderInfoByIdTgPremiumOrderInfo(Long.valueOf(id)); + Preconditions.checkState(!"Y".equals(tgPremiumOrderInfo.getTgPaymentStatus()), tgPremiumOrderInfo.getRechargeTgUserName() + "该用户已经开通,请勿重复开通"); + tgPremiumTransferHandler.doRechargeAndUpdate(tgPremiumOrderInfo); + } + return 1; + } + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsdtExchangeInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsdtExchangeInfoServiceImpl.java index 0025932ac..0f157687e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsdtExchangeInfoServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsdtExchangeInfoServiceImpl.java @@ -13,6 +13,7 @@ import com.ruoyi.system.mapper.UsdtExchangeInfoMapper; import com.ruoyi.system.service.IUsdtExchangeInfoService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.util.Pair; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -70,17 +71,18 @@ public class UsdtExchangeInfoServiceImpl implements IUsdtExchangeInfoService { public int insertUsdtExchangeInfo(UsdtExchangeInfo usdtExchangeInfo) throws Exception { BigDecimal oneUsdtToTrx; String systronApiSwitch = configService.selectConfigByKey("sys.tron.api"); - + Pair oneUsdtToTrxPair = null; if (UserConstants.YES.equals(systronApiSwitch)) { - oneUsdtToTrx = usdt2TrxTransferHandler.getOneUsdtToTrx(); +// oneUsdtToTrx = usdt2TrxTransferHandler.getOneUsdtToTrx().getFirst(); + oneUsdtToTrxPair = usdt2TrxTransferHandler.getOneUsdtToTrx(); } else { - oneUsdtToTrx = new BigDecimal("7.565113"); + oneUsdtToTrxPair=Pair.of(BigDecimal.TEN,BigDecimal.TEN); } BigDecimal usdtAmount = usdtExchangeInfo.getUsdtAmount(); - BigDecimal trxValue = usdtAmount.multiply(oneUsdtToTrx); + BigDecimal trxValue = usdtAmount.multiply(oneUsdtToTrxPair.getFirst()); String accountAddress = usdtExchangeInfo.getAccountAddress(); if (StringUtils.isEmpty(accountAddress)) { AccountAddressInfo accountAddressInfoExample = new AccountAddressInfo(); @@ -96,7 +98,7 @@ public class UsdtExchangeInfoServiceImpl implements IUsdtExchangeInfoService { String fromAddress = usdtExchangeInfo.getFromAddress(); usdt2TrxTransferHandler. - doTransferUsdtAndStore(oneUsdtToTrx, tronApiKey, decryptPrivateKey, accountAddress, fromAddress, trxValue, null, null, usdtAmount); + doTransferUsdtAndStore(oneUsdtToTrxPair, tronApiKey, decryptPrivateKey, accountAddress, fromAddress, trxValue, null, null, usdtAmount); return 1; } diff --git a/ruoyi-system/src/main/resources/mapper/exchange/TgPremiumOrderInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/exchange/TgPremiumOrderInfoMapper.xml new file mode 100644 index 000000000..1a80786b6 --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/exchange/TgPremiumOrderInfoMapper.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + select id_tg_premium_order_info, recharge_tg_user_name, months, actual_amount, id_tg, tg_payment_status, order_amount, is_paid, from_address, to_address, tx_id, fcd, fcu, lcd, lcu from tg_premium_order_info + + + + + + + + insert into tg_premium_order_info + + recharge_tg_user_name, + months, + actual_amount, + id_tg, + tg_payment_status, + order_amount, + is_paid, + from_address, + to_address, + tx_id, + fcd, + fcu, + lcd, + lcu, + + + #{rechargeTgUserName}, + #{months}, + #{actualAmount}, + #{idTg}, + #{tgPaymentStatus}, + #{orderAmount}, + #{isPaid}, + #{fromAddress}, + #{toAddress}, + #{txId}, + #{fcd}, + #{fcu}, + #{lcd}, + #{lcu}, + + + + + update tg_premium_order_info + + recharge_tg_user_name = #{rechargeTgUserName}, + months = #{months}, + actual_amount = #{actualAmount}, + id_tg = #{idTg}, + tg_payment_status = #{tgPaymentStatus}, + order_amount = #{orderAmount}, + is_paid = #{isPaid}, + from_address = #{fromAddress}, + to_address = #{toAddress}, + tx_id = #{txId}, + fcd = #{fcd}, + fcu = #{fcu}, + lcd = #{lcd}, + lcu = #{lcu}, + + where id_tg_premium_order_info = #{idTgPremiumOrderInfo} + + + + delete from tg_premium_order_info where id_tg_premium_order_info = #{idTgPremiumOrderInfo} + + + + delete from tg_premium_order_info where id_tg_premium_order_info in + + #{idTgPremiumOrderInfo} + + + + \ No newline at end of file