From 29a6c0f389961cf96a77eb0dbde72fc35faf26ed Mon Sep 17 00:00:00 2001 From: dorion <872354125@qq.com> Date: Thu, 25 Apr 2024 22:03:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E8=B4=A6=E5=88=86=E5=B8=83=E5=BC=8F?= =?UTF-8?q?=E9=94=81bug=E8=A7=A3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/pom.xml | 4 +- .../templates/account/freeze/freeze.html | 9 ++- .../templates/account/monitor/monitor.html | 12 ++-- .../resources/templates/exchange/trx/trx.html | 15 +++-- .../templates/exchange/usdt/usdt.html | 12 ++-- .../ruoyi/system/api/impl/TronApiImpl.java | 11 ++- .../ruoyi/system/bot/CustomBotFunction.java | 21 +++++- .../ruoyi/system/bot/TgLongPollingBot.java | 5 +- .../bot/handleService/NewMemberIntoGroup.java | 67 +++++++++++++++++++ .../system/handler/UsdtTransferHandler.java | 18 ++--- 10 files changed, 137 insertions(+), 37 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/bot/handleService/NewMemberIntoGroup.java diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index d8be3d724..5de38d30d 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -147,7 +147,7 @@ --> ${project.artifactId} - + diff --git a/ruoyi-admin/src/main/resources/templates/account/freeze/freeze.html b/ruoyi-admin/src/main/resources/templates/account/freeze/freeze.html index 4e31262e7..0b2c11cfd 100644 --- a/ruoyi-admin/src/main/resources/templates/account/freeze/freeze.html +++ b/ruoyi-admin/src/main/resources/templates/account/freeze/freeze.html @@ -106,15 +106,18 @@ }, { field: 'fcu', - title: '创建用户' + title: '创建用户', + visible: false }, { field: 'lcd', - title: '更新时间' + title: '更新时间', + visible: false }, { field: 'lcu', - title: '更新用户' + title: '更新用户', + visible: false }, { diff --git a/ruoyi-admin/src/main/resources/templates/account/monitor/monitor.html b/ruoyi-admin/src/main/resources/templates/account/monitor/monitor.html index be9d0f708..e0c20a308 100644 --- a/ruoyi-admin/src/main/resources/templates/account/monitor/monitor.html +++ b/ruoyi-admin/src/main/resources/templates/account/monitor/monitor.html @@ -134,19 +134,23 @@ }, { field: 'fcd', - title: '创建时间' + title: '创建时间', + visible: false }, { field: 'fcu', - title: '创建用户' + title: '创建用户', + visible: false }, { field: 'lcd', - title: '更新时间' + title: '更新时间', + visible: false }, { field: 'lcu', - title: '更新用户' + title: '更新用户', + visible: false }, { diff --git a/ruoyi-admin/src/main/resources/templates/exchange/trx/trx.html b/ruoyi-admin/src/main/resources/templates/exchange/trx/trx.html index ce3e4f77c..2ab1b26f8 100644 --- a/ruoyi-admin/src/main/resources/templates/exchange/trx/trx.html +++ b/ruoyi-admin/src/main/resources/templates/exchange/trx/trx.html @@ -121,7 +121,8 @@ }, { field: 'trxTxId', - title: 'TRX订单' + title: 'TRX订单', + visible: false }, { field: 'tranferCount', @@ -147,7 +148,8 @@ }, { field: 'delegateTxId', - title: '能量交易订单' + title: '能量交易订单', + visible: false }, { field: 'lockPeriod', @@ -165,11 +167,13 @@ }, { field: 'unDelegateTxId', - title: '回收资源交易' + title: '回收资源交易', + visible: false }, { field: 'fcd', - title: '创建时间' + title: '创建时间', + visible: false }, /* { field: 'fcu', @@ -177,7 +181,8 @@ },*/ { field: 'lcd', - title: '更新时间' + title: '更新时间', + visible: false }, /*{ field: 'lcu', diff --git a/ruoyi-admin/src/main/resources/templates/exchange/usdt/usdt.html b/ruoyi-admin/src/main/resources/templates/exchange/usdt/usdt.html index 7fbb214c4..b2e602420 100644 --- a/ruoyi-admin/src/main/resources/templates/exchange/usdt/usdt.html +++ b/ruoyi-admin/src/main/resources/templates/exchange/usdt/usdt.html @@ -112,19 +112,23 @@ }, { field: 'fcd', - title: '创建时间' + title: '创建时间', + visible: false }, { field: 'fcu', - title: '创建用户' + title: '创建用户', + visible: false }, { field: 'lcd', - title: '更新时间' + title: '更新时间', + visible: false }, { field: 'lcu', - title: '更新用户' + title: '更新用户', + visible: false }, { title: '操作', diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java index ac2cad5c6..00bdc69d2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java @@ -1,5 +1,8 @@ package com.ruoyi.system.api.impl; +import cn.hutool.core.date.DateField; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONUtil; import com.ruoyi.common.utils.http.RestTemplateUtils; import com.ruoyi.system.api.ITronApi; @@ -13,6 +16,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.util.UriComponentsBuilder; +import java.util.Date; + @Component @Slf4j public class TronApiImpl implements ITronApi { @@ -29,10 +34,10 @@ public class TronApiImpl implements ITronApi { // builder.queryParam("only_confirmed", true); builder.queryParam("only_to", true); builder.queryParam("limit", 200); -// String sysTransferBetween = configService.selectConfigByKey("sys.transfer.between"); + String sysTransferBetween = configService.selectConfigByKey("sys.transfer.between"); // -// DateTime min_timestamp = DateUtil.offset(new Date(), DateField.MINUTE, Integer.valueOf(sysTransferBetween)); -// builder.queryParam("min_timestamp", min_timestamp.getTime()); + DateTime min_timestamp = DateUtil.offset(new Date(), DateField.MINUTE, Integer.valueOf(sysTransferBetween)); + builder.queryParam("min_timestamp", min_timestamp.getTime()); String uriString = builder.toUriString(); ResponseEntity responseEntity = RestTemplateUtils.get(uriString, headers, String.class); 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 6f39788b6..fb976bae7 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,5 +1,7 @@ package com.ruoyi.system.bot; +import com.ruoyi.system.bot.handleService.NewMemberIntoGroup; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.objects.Update; @@ -8,20 +10,37 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.Keyboard import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; @Component public class CustomBotFunction { + @Autowired + private NewMemberIntoGroup newMemberIntoGroup; /** * 对消息进行处理 + * * @param sender * @param update */ - public void mainFunc(AbsSender sender, Update update) throws TelegramApiException { + public void mainFunc(AbsSender sender, Update update) throws TelegramApiException, IOException, NoSuchAlgorithmException, InvalidKeyException { + + + if (update.getChatMember() != null && "left".equals(update.getChatMember().getOldChatMember().getStatus()) + && "member".equals(update.getChatMember().getNewChatMember().getStatus()) && + (update.getChatMember().getChat().isGroupChat() || update.getChatMember().getChat().isSuperGroupChat())) { + + newMemberIntoGroup.handleMessage(sender, update); + + return; + } + if ("/start".equals(update.getMessage().getText())) { SendMessage message = new SendMessage(); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java index 22ce40639..45f70b464 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java @@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.telegram.telegrambots.bots.TelegramLongPollingBot; -import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; @@ -57,10 +56,10 @@ public class TgLongPollingBot extends TelegramLongPollingBot { @SneakyThrows public void onUpdateReceived(Update update) { // log.info("消息:{}",update.getMessage().getText()); - SendMessage sendMessage = SendMessage.builder().chatId(update.getMessage().getChatId().toString()).text("收到消息:"+update.getMessage().getChatId().toString()).build(); +// SendMessage sendMessage = SendMessage.builder().chatId(update.getMessage().getChatId().toString()).text("收到消息:"+update.getMessage().getChatId().toString()).build(); try { customBotFunction.mainFunc(this,update); - execute(sendMessage); +// execute(sendMessage); } catch (TelegramApiException e) { log.error("ex:{}",e); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/handleService/NewMemberIntoGroup.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handleService/NewMemberIntoGroup.java new file mode 100644 index 000000000..8af66eaee --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handleService/NewMemberIntoGroup.java @@ -0,0 +1,67 @@ +package com.ruoyi.system.bot.handleService; + +import com.ruoyi.system.bot.utils.SendContent; +import com.ruoyi.system.handler.UsdtTransferHandler; +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 UsdtTransferHandler usdtTransferHandlerl; + + + 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 = usdtTransferHandlerl.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/handler/UsdtTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/UsdtTransferHandler.java index 1c138d0be..3dd8ef38f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/UsdtTransferHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/UsdtTransferHandler.java @@ -110,6 +110,11 @@ public class UsdtTransferHandler { String dataTo = data.getTo(); String transactionId = data.getTransaction_id(); + Boolean hasKey = redisTemplate.hasKey("transfer_USDT_" + transactionId); + if (hasKey) { + return; + } + RLock lock = redissonClient.getLock("lock_" + transactionId); try { boolean res = lock.tryLock(3, 50, TimeUnit.SECONDS); @@ -139,7 +144,7 @@ public class UsdtTransferHandler { ApiWrapper apiWrapper = ApiWrapper.ofMainnet(decryptPrivateKey, apiKey); - //转账 + //转账 Response.TransactionExtention transfer = apiWrapper.transfer(accountAddress, from, trxValue.movePointRight(6).longValue()); //签名 Chain.Transaction transaction = apiWrapper.signTransaction(transfer); @@ -283,16 +288,5 @@ public class UsdtTransferHandler { } } -/* public static void main(String[] args) { - String res ="{\"code\":\"0\",\"msg\":\"\",\"data\":[{\"instType\":\"SPOT\",\"instId\":\"TRX-USDT\",\"last\":\"0.11108\",\"lastSz\":\"534.839755\",\"askPx\":\"0.11108\",\"askSz\":\"12244.867483\",\"bidPx\":\"0.11107\",\"bidSz\":\"2776.220524\",\"open24h\":\"0.11093\",\"high24h\":\"0.11199\",\"low24h\":\"0.11018\",\"volCcy24h\":\"3721341.18131714737\",\"vol24h\":\"33527411.881202\",\"ts\":\"1713782792103\",\"sodUtc0\":\"0.11134\",\"sodUtc8\":\"0.11081\"}]}"; - OkxResponse okxResponse = JSONUtil.toBean(res, OkxResponse.class); - List oksResponseDataList = okxResponse.getData(); - String last = oksResponseDataList.get(0).getLast(); - - double v = 1 / new Double(last); - BigDecimal bigDecimal = BigDecimal.valueOf(v).setScale(6, BigDecimal.ROUND_HALF_DOWN); - System.out.println(bigDecimal); - }*/ - }