代码调整

This commit is contained in:
2025-01-21 16:48:41 +08:00
parent 7da5d7c1f8
commit 8a2ef975ea
3 changed files with 4 additions and 4 deletions

View File

@@ -459,7 +459,7 @@ public class SocketDevResponseService {
double diff = Math.abs(num1 - num2); double diff = Math.abs(num1 - num2);
double larger = Math.max(num1, num2); double larger = Math.max(num1, num2);
if(DicDataEnum.V.getCode().equals(type)){ if(DicDataEnum.V.getCode().equals(type)){
return BigDecimal.valueOf(diff / larger).setScale(4, RoundingMode.HALF_UP); return BigDecimal.valueOf(num1 - num2).setScale(4, RoundingMode.HALF_UP);
}else { }else {
return BigDecimal.valueOf(diff / larger).multiply(BigDecimal.valueOf(100)).setScale(4, RoundingMode.HALF_UP); return BigDecimal.valueOf(diff / larger).multiply(BigDecimal.valueOf(100)).setScale(4, RoundingMode.HALF_UP);
} }

View File

@@ -108,7 +108,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
} }
@Override @Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { public void handlerRemoved(ChannelHandlerContext ctx){
// 假设用户 ID 是从某个地方获取的,这里简单示例为 "userId" // 假设用户 ID 是从某个地方获取的,这里简单示例为 "userId"
System.out.println("weoSocket客户端退出: " + ctx.channel().id()); System.out.println("weoSocket客户端退出: " + ctx.channel().id());
WebServiceManager.removeChannel(ctx.channel().id().toString()); WebServiceManager.removeChannel(ctx.channel().id().toString());
@@ -116,7 +116,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
} }
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) {
System.out.println("weoSocket断线" + ctx.channel().id()); System.out.println("weoSocket断线" + ctx.channel().id());
ctx.close(); ctx.close();

View File

@@ -43,7 +43,7 @@ public class WebSocketInitializer extends ChannelInitializer<SocketChannel> {
* 这个时候我们只需要访问 ws://127.0.0.1:7777/hello 就可以了 * 这个时候我们只需要访问 ws://127.0.0.1:7777/hello 就可以了
* 这个handler是将http协议升级为websocket 并且使用 101 作为响应码 * 这个handler是将http协议升级为websocket 并且使用 101 作为响应码
* */ * */
pipeline.addLast(new IdleStateHandler(10, -1, -1, TimeUnit.SECONDS)); pipeline.addLast(new IdleStateHandler(13, 0, 0, TimeUnit.SECONDS));
pipeline.addLast(new WebSocketHandler()); pipeline.addLast(new WebSocketHandler());
pipeline.addLast(new WebSocketServerProtocolHandler("/hello")); pipeline.addLast(new WebSocketServerProtocolHandler("/hello"));