Browse Source

上报上级系统优化

master
lijiuwei 4 months ago
parent
commit
9c96acb246
3 changed files with 14 additions and 5 deletions
  1. +2
    -2
      src/main/java/com/inspect/tcpserver/minio/service/MinioService.java
  2. +0
    -1
      src/main/java/com/inspect/tcpserver/tcp/NettyClient.java
  3. +12
    -2
      src/main/java/com/inspect/tcpserver/tcp/NettyClientHandler.java

+ 2
- 2
src/main/java/com/inspect/tcpserver/minio/service/MinioService.java View File

@ -26,7 +26,7 @@ public class MinioService {
public UploadResponse upload(MultipartFile file) throws Exception {
String fileName = file.getOriginalFilename();
String objectName = "lingzhouzhiliu/Model/" + fileName;
String objectName = "/lingzhouzhiliu/Model/" + fileName;
log.info("fileName: {}, objectName: {}", fileName, objectName);
try (InputStream in = file.getInputStream()) {
@ -43,7 +43,7 @@ public class MinioService {
String url = getObjectUrl(fileName);
log.info("url: {}", url);
return new UploadResponse(fileName, url);
return new UploadResponse(fileName, objectName);
}
public String getObjectUrl(String objectName) throws Exception {


+ 0
- 1
src/main/java/com/inspect/tcpserver/tcp/NettyClient.java View File

@ -157,7 +157,6 @@ public class NettyClient {
client.sendProtoBuffer(allBuf);
this.sendIndex++;
log.info("sent data to upperServer successfully");
} else {
log.info("###### 会话:{}, 与上级系统连接失败 ######", uuid);
}


+ 12
- 2
src/main/java/com/inspect/tcpserver/tcp/NettyClientHandler.java View File

@ -1,6 +1,9 @@
package com.inspect.tcpserver.tcp;
import com.inspect.tcpserver.util.Color;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.EventLoop;
@ -30,9 +33,16 @@ public class NettyClientHandler extends ChannelInboundHandlerAdapter {
public void sendProtoBuffer(ByteBuf byteBuf) {
if (clientChannelHandlerContext != null) {
clientChannelHandlerContext.writeAndFlush(byteBuf);
clientChannelHandlerContext.writeAndFlush(Unpooled.wrappedBuffer(byteBuf)).addListener(
(ChannelFuture future) -> {
if (future.isSuccess()) {
log.info(Color.CYAN + "###### 向上级系统发送消息成功 ######" + Color.END);
} else {
log.info(Color.RED + "###### 向上级系发送消息失败 ######" + Color.END);
}
});
} else {
log.info("client发送消息时,content为空,未连接服务端,取消发送");
log.info(Color.RED + "###### 无法向上级系发送消息,ctx==null ######" + Color.END);
}
}


Loading…
Cancel
Save