update nexa 收益计算器问题

This commit is contained in:
yyb 2025-06-17 11:28:22 +08:00
parent 4fad507896
commit 315079e5d1
7 changed files with 56 additions and 14 deletions

View File

@ -62,4 +62,7 @@ public class ChatRoomDto {
*/ */
@ApiModelProperty(value = "聊天发起者id :一般为游客或登录用户", example = "1") @ApiModelProperty(value = "聊天发起者id :一般为游客或登录用户", example = "1")
private String selfEmail; private String selfEmail;
@ApiModelProperty(value = "客服是否在线", example = "true")
private boolean customerIsOnline;
} }

View File

@ -88,7 +88,6 @@ public class WebsocketChannelInterceptor implements ChannelInterceptor {
maxConnectionsLimit(); maxConnectionsLimit();
//根据客服端ip + 用户类型限制连接数 //根据客服端ip + 用户类型限制连接数
ipLimit(accessor,type,email); ipLimit(accessor,type,email);
//链接请求头中用户信息存入stomp中 //链接请求头中用户信息存入stomp中
mha.setUser(new StompPrincipal(email,type,true)); mha.setUser(new StompPrincipal(email,type,true));
} }

View File

@ -11,6 +11,7 @@ import com.m2pool.chat.service.ChatRoomService;
import com.m2pool.chat.vo.CharRoomVo; import com.m2pool.chat.vo.CharRoomVo;
import com.m2pool.chat.vo.RoomPageVo; import com.m2pool.chat.vo.RoomPageVo;
import com.m2pool.chat.vo.RoomVo; import com.m2pool.chat.vo.RoomVo;
import com.m2pool.chat.vo.UserMessageVo;
import com.m2pool.common.core.Result.R; import com.m2pool.common.core.Result.R;
import com.m2pool.common.core.constant.HttpStatus; import com.m2pool.common.core.constant.HttpStatus;
import com.m2pool.common.core.utils.PageUtils; import com.m2pool.common.core.utils.PageUtils;
@ -73,6 +74,7 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
return rspData; return rspData;
} }
private static final String EMAIL_REGEX = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$";
@Override @Override
@Transactional @Transactional
@ -81,6 +83,11 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
String userEmail = roomVo.getEmail(); String userEmail = roomVo.getEmail();
ChatRoomDto roomByUserEmail = chatRoomMapper.findRoomByUserEmail(userEmail); ChatRoomDto roomByUserEmail = chatRoomMapper.findRoomByUserEmail(userEmail);
if(roomByUserEmail != null){ if(roomByUserEmail != null){
if (checkOnline(roomByUserEmail.getUserEmail())) {
roomByUserEmail.setCustomerIsOnline(true);
} else{
roomByUserEmail.setCustomerIsOnline(false);
}
return R.success(roomByUserEmail); return R.success(roomByUserEmail);
} }
@ -91,14 +98,36 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
} }
Random random = new Random(); Random random = new Random();
SysUser sysUser = data.get(random.nextInt(data.size())); SysUser sysUser = data.get(random.nextInt(data.size()));
ChatRoom build = ChatRoom.builder().userOneEmail(userEmail).userTwoEmail(sysUser.getEmail()).build(); data.removeIf(datum -> !checkOnline(datum.getEmail()));
boolean customerIsOnline = false;
if (!data.isEmpty()){
sysUser = data.get(random.nextInt(data.size()));
customerIsOnline = true;
}
ChatRoom build = ChatRoom.builder()
.userOneEmail(userEmail)
.userTwoEmail(sysUser.getEmail())
.build();
int insert = chatRoomMapper.insert(build); int insert = chatRoomMapper.insert(build);
if (insert > 0){ if (insert > 0){
return R.success(ChatRoomDto.builder().id(build.getId()).selfEmail(userEmail).userEmail(build.getUserTwoEmail()).build()); return R.success(ChatRoomDto.builder()
.id(build.getId())
.selfEmail(userEmail)
.customerIsOnline(customerIsOnline)
.userEmail(build.getUserTwoEmail()).build());
} }
return R.fail("聊天室不存在,并且创建聊天室失败"); return R.fail("聊天室不存在,并且创建聊天室失败");
} }
/**
* 检查用户是否在线
* @return
*/
private boolean checkOnline(String email){
return userRegistry.getUsers().stream()
.anyMatch(user -> user.getName().equals(email));
}
@Override @Override
public R<String> updateRoom(CharRoomVo charRoomVo) { public R<String> updateRoom(CharRoomVo charRoomVo) {
int i = chatRoomMapper.updateById(ChatRoom.builder().id(charRoomVo.getId()).flag(charRoomVo.getFlag()).build()); int i = chatRoomMapper.updateById(ChatRoom.builder().id(charRoomVo.getId()).flag(charRoomVo.getFlag()).build());

View File

@ -64,7 +64,7 @@ public class StompServiceImpl implements StompService {
ChatRoom chatRoom = chatRoomMapper.selectOne(new LambdaQueryWrapper<ChatRoom>() ChatRoom chatRoom = chatRoomMapper.selectOne(new LambdaQueryWrapper<ChatRoom>()
.eq(ChatRoom::getUserOneEmail,userMessageVo.getEmail()) .eq(ChatRoom::getUserOneEmail,userMessageVo.getEmail())
.eq(ChatRoom::getUserTwoEmail,principal.getName())); .eq(ChatRoom::getUserTwoEmail,principal.getName()));
System.out.println("发送消息聊天室id"+userMessageVo.getRoomId()+"发送者邮箱"+principal.getName()+"接受者邮箱"+userMessageVo.getEmail());
build.setRoomId(userMessageVo.getRoomId()); build.setRoomId(userMessageVo.getRoomId());
int serviceReadNum = chatRoom != null ? chatRoom.getClientReadNum() : 0; int serviceReadNum = chatRoom != null ? chatRoom.getClientReadNum() : 0;
build.setClientReadNum( serviceReadNum+ 1); build.setClientReadNum( serviceReadNum+ 1);
@ -78,11 +78,12 @@ public class StompServiceImpl implements StompService {
//}else{ //}else{
// handleImage(userMessageVo.getEmail()+principal.getName(),userMessageVo.getContent()); // handleImage(userMessageVo.getEmail()+principal.getName(),userMessageVo.getContent());
//} //}
Long id = executeTran(principal, userMessageVo, chatRoom);
System.out.println("发送消息聊天室id"+userMessageVo.getRoomId()+"发送者邮箱"+principal.getName()+"接受者邮箱"+userMessageVo.getEmail()+"消息id"+id);
//多端情况下需要把消息发送给自己 //多端情况下需要把消息发送给自己
build.setId(id);
messagingTemplate.convertAndSendToUser(principal.getName(), Destination.QUEUE_CUSTOMER + "/" + principal.getName(),build); messagingTemplate.convertAndSendToUser(principal.getName(), Destination.QUEUE_CUSTOMER + "/" + principal.getName(),build);
messagingTemplate.convertAndSendToUser(userMessageVo.getEmail(), Destination.QUEUE_USER + "/" + userMessageVo.getEmail(),build); messagingTemplate.convertAndSendToUser(userMessageVo.getEmail(), Destination.QUEUE_USER + "/" + userMessageVo.getEmail(),build);
executeTran(principal, userMessageVo, chatRoom);
return AjaxResult.success("成功"); return AjaxResult.success("成功");
} }
@ -106,11 +107,13 @@ public class StompServiceImpl implements StompService {
//}else{ //}else{
// handleImage(userMessageVo.getEmail()+principal.getName(),userMessageVo.getContent()); // handleImage(userMessageVo.getEmail()+principal.getName(),userMessageVo.getContent());
//} //}
Long id = executeTran(principal, userMessageVo, chatRoom);
System.out.println("发送消息聊天室id"+userMessageVo.getRoomId()+"发送者邮箱"+principal.getName()+"接受者邮箱"+userMessageVo.getEmail()+"消息id"+id);
// 多端情况下需要把消息发送给 // 多端情况下需要把消息发送给
build.setId(id);
messagingTemplate.convertAndSendToUser(principal.getName(), Destination.QUEUE_USER + "/" + principal.getName(),build); messagingTemplate.convertAndSendToUser(principal.getName(), Destination.QUEUE_USER + "/" + principal.getName(),build);
messagingTemplate.convertAndSendToUser(userMessageVo.getEmail(), Destination.QUEUE_CUSTOMER + "/" + userMessageVo.getEmail(),build); messagingTemplate.convertAndSendToUser(userMessageVo.getEmail(), Destination.QUEUE_CUSTOMER + "/" + userMessageVo.getEmail(),build);
executeTran(principal, userMessageVo, chatRoom);
return AjaxResult.success("成功"); return AjaxResult.success("成功");
} }
/** /**
@ -150,14 +153,15 @@ public class StompServiceImpl implements StompService {
* @param userMessageVo * @param userMessageVo
* @param chatRoom * @param chatRoom
*/ */
private void executeTran(StompPrincipal principal, UserMessageVo userMessageVo, ChatRoom chatRoom){ private Long executeTran(StompPrincipal principal, UserMessageVo userMessageVo, ChatRoom chatRoom){
final Long[] id = {0L};
// 消息存储 // 消息存储
transactionTemplate.execute(new TransactionCallbackWithoutResult() { transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override @Override
protected void doInTransactionWithoutResult(TransactionStatus status) { protected void doInTransactionWithoutResult(TransactionStatus status) {
try { try {
// 插入消息并获取 ID // 插入消息并获取 ID
insertMessage(principal,userMessageVo); id[0] = insertMessage(principal, userMessageVo);
//聊天室已读未读数量更新 //聊天室已读未读数量更新
updateRoom(chatRoom,principal.getType()); updateRoom(chatRoom,principal.getType());
} catch (Exception e) { } catch (Exception e) {
@ -167,6 +171,7 @@ public class StompServiceImpl implements StompService {
} }
} }
}); });
return id[0];
} }
/** /**

View File

@ -434,7 +434,7 @@ public class PoolServiceImpl implements PoolService {
} }
else { else {
BlockInfo info = redisService.getCacheObject(pool.getCoin() + "_block"); BlockInfo info = redisService.getCacheObject(pool.getCoin() + "_block");
System.out.println("yyb-redis key"+ pool.getCoin() + "_block" +"查询结果"+ info);
if(StringUtils.isNull(info)){ if(StringUtils.isNull(info)){
if(!"enx".equals(pool.getCoin()) && !"alph".equals(pool.getCoin())){ if(!"enx".equals(pool.getCoin()) && !"alph".equals(pool.getCoin())){
// //

View File

@ -84,7 +84,6 @@ public class NodeTask {
@Scheduled(cron = "0 0/1 * * * ?") @Scheduled(cron = "0 0/1 * * * ?")
public void NEXABlockInfoToRedis(){ public void NEXABlockInfoToRedis(){
BlockInfo blockInfo = NodeRpc.getBlock("nexa"); BlockInfo blockInfo = NodeRpc.getBlock("nexa");
int count = 0; int count = 0;
while (StringUtils.isNull(blockInfo)){ while (StringUtils.isNull(blockInfo)){
if(count >= 3){ if(count >= 3){

View File

@ -239,7 +239,9 @@ public class NodeRpc{
} }
String[] params = {nowHeight,"2"}; String[] params = {nowHeight,"2"};
Object[] statsParams = {Convert.toLong(nowHeight)};
String result = getResult(coin, "getmininginfo", params); String result = getResult(coin, "getmininginfo", params);
String result2 = getResultTest(coin, "getblockstats", statsParams);
BlockInfo blockInfo = new BlockInfo(); BlockInfo blockInfo = new BlockInfo();
if(StringUtils.isBlank(result)){ if(StringUtils.isBlank(result)){
@ -253,11 +255,16 @@ public class NodeRpc{
} }
JSONObject jsonObject = JSON.parseObject(result); JSONObject jsonObject = JSON.parseObject(result);
JSONObject statsJs = JSON.parseObject(result2);
long height = jsonObject.getLongValue("blocks"); long height = jsonObject.getLongValue("blocks");
blockInfo.setHeight(height); blockInfo.setHeight(height);
BigDecimal difficulty = jsonObject.getBigDecimal("difficulty"); BigDecimal difficulty = jsonObject.getBigDecimal("difficulty");
BigDecimal subsidy = statsJs.getBigDecimal("subsidy");
if(StringUtils.isNull(subsidy)) {
System.out.println("subsidy获取结果为空");
return blockInfo;
}
if(StringUtils.isNotNull(difficulty)){ if(StringUtils.isNotNull(difficulty)){
blockInfo.setDifficulty(difficulty.setScale(2,BigDecimal.ROUND_HALF_UP)); blockInfo.setDifficulty(difficulty.setScale(2,BigDecimal.ROUND_HALF_UP));
//NodeConstant constant = (NodeConstant) EnumUtils.get(NodeConstant.class, coin); //NodeConstant constant = (NodeConstant) EnumUtils.get(NodeConstant.class, coin);
@ -294,7 +301,7 @@ public class NodeRpc{
// } // }
//}); //});
blockInfo.setReward(BigDecimal.valueOf(reward[0])); blockInfo.setReward(subsidy);
blockInfo.setFees(BigDecimal.valueOf(fees[0])); blockInfo.setFees(BigDecimal.valueOf(fees[0]));
blockInfo.setProfit(blockInfo.getReward().subtract(blockInfo.getFees())); blockInfo.setProfit(blockInfo.getReward().subtract(blockInfo.getFees()));
System.out.println("blockInfo信息rpc"+blockInfo); System.out.println("blockInfo信息rpc"+blockInfo);