|
@@ -1,14 +1,19 @@
|
|
|
package com.lutao.tcp.server.tcptest;
|
|
|
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.lutao.tcp.server.domain.entity.RecSendLog;
|
|
|
+import com.lutao.tcp.server.service.RecSendLogService;
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.time.Instant;
|
|
@@ -21,6 +26,10 @@ import java.time.format.DateTimeFormatter;
|
|
|
public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
private static BootNettyChannelInboundHandlerAdapter nettyServerHandler;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RecSendLogService recSendLogService;
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
nettyServerHandler = this;
|
|
@@ -44,6 +53,30 @@ public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandler
|
|
|
if (JSONUtil.isJson(json)){
|
|
|
JSONObject jsonObject = JSON.parseObject(json);
|
|
|
log.info("======加载客户端报文======【" + ctx.channel().id() + "】" + " :" + jsonObject.toJSONString());
|
|
|
+ RecSendLog recSendLog = new RecSendLog();
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+ recSendLog.setRec(jsonObject.toJSONString());
|
|
|
+ recSendLog.setLogType("大范围速报报警");
|
|
|
+ recSendLog.setCreateTime(LocalDateTime.now());
|
|
|
+ recSendLog.setUpdateTime(LocalDateTime.now());
|
|
|
+ recSendLog.setId(uuid);
|
|
|
+ recSendLogService.save(recSendLog);
|
|
|
+ //http://115.85.203.230:45002/utility/scopeScan/warnData/submit 转发
|
|
|
+
|
|
|
+ String body = HttpUtil.createPost("http://115.85.203.230:45002/utility/scopeScan/warnData/submit")
|
|
|
+ .body(jsonObject.toJSONString())
|
|
|
+ .execute().body();
|
|
|
+ Integer code = JSONUtil.parseObj(body).getInt("code");
|
|
|
+ log.info("======转发状态码======【" + ctx.channel().id() + "】" + " :" + code);
|
|
|
+ if (code == 200){
|
|
|
+ log.info("======转发成功======【" + ctx.channel().id() + "】" + " :" + jsonObject.toJSONString());
|
|
|
+ recSendLog.setSend(jsonObject.toJSONString());
|
|
|
+ recSendLogService.updateById(recSendLog);
|
|
|
+ }else{
|
|
|
+ log.info("======转发失败======【" + ctx.channel().id() + "】" + " :" + jsonObject.toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}else{
|
|
|
log.info("======无法转换为json======【" + ctx.channel().id() + "】" + " :" + json);
|
|
|
}
|
|
@@ -53,7 +86,6 @@ public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandler
|
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
|
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|