|
|
@@ -9,8 +9,10 @@ import com.xueyi.common.core.web.result.R; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; |
|
|
|
import com.xueyi.nlt.netty.server.config.ServerConfig; |
|
|
|
import com.xueyi.nlt.nlt.domain.vo.WordProcessVo; |
|
|
|
import com.xueyi.nlt.nlt.service.IDmIntentService; |
|
|
|
import com.xueyi.nlt.nlt.service.IDmRegularService; |
|
|
|
import com.xueyi.nlt.nlt.service.IDmWordProcessService; |
|
|
|
import com.xueyi.nlt.nlt.service.impl.LogServiceImpl; |
|
|
|
import com.xueyi.nlt.nlt.template.FreeChatTemplate; |
|
|
|
import com.xueyi.nlt.nlt.template.MovieChatTemplate; |
|
|
@@ -57,6 +59,8 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket |
|
|
|
@Autowired |
|
|
|
private IDmIntentService intentService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IDmWordProcessService wordProcessService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MovieChatTemplate movieChatTemplate; |
|
|
@@ -75,6 +79,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket |
|
|
|
INSTANCE.manDeviceService = this.manDeviceService; |
|
|
|
INSTANCE.remoteEnterpriseService = this.remoteEnterpriseService; |
|
|
|
INSTANCE.logService = this.logService; |
|
|
|
INSTANCE.wordProcessService = this.wordProcessService; |
|
|
|
} |
|
|
|
@Override |
|
|
|
protected void channelRead0(ChannelHandlerContext channelHandlerContext, TextWebSocketFrame textWebSocketFrame) throws Exception { |
|
|
@@ -146,6 +151,32 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket |
|
|
|
return; |
|
|
|
} |
|
|
|
else { |
|
|
|
// 语意判断 |
|
|
|
WordProcessVo wordProcessVo = new WordProcessVo(); |
|
|
|
wordProcessVo.setMetadata(msg); |
|
|
|
WordProcessVo result = INSTANCE.wordProcessService.semanticIntegrityDetection(wordProcessVo); |
|
|
|
if (result != null) { |
|
|
|
System.out.println(result.getProcessedResult()); |
|
|
|
// 判断结果 |
|
|
|
switch (result.getProcessedResult()){ |
|
|
|
|
|
|
|
case "0": |
|
|
|
// 返回前端,抛弃 |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("action","chat"); |
|
|
|
jo.put("motion","idle"); |
|
|
|
jo.put("traceId",""); |
|
|
|
jo.put("status",2); |
|
|
|
jo.put("code", -1); |
|
|
|
jo.put("tts",""); |
|
|
|
reply(channel, msg,jo, enterpriseName,"大模型"); |
|
|
|
return; |
|
|
|
case "1": |
|
|
|
case "2": |
|
|
|
break; |
|
|
|
default: |
|
|
|
} |
|
|
|
} |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("action","chat"); |
|
|
|
jo.put("motion","idle"); |
|
|
@@ -163,6 +194,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket |
|
|
|
jo.put("traceId",""); |
|
|
|
jo.put("status",2); |
|
|
|
jo.put("tts","大模型出现异常,请稍后重试。"); |
|
|
|
jo.put("code",500); |
|
|
|
String str = jo.toJSONString(); |
|
|
|
log.info("发生异常client:{},内容:{}",devId,jo.toJSONString()); |
|
|
|
channel.writeAndFlush(new TextWebSocketFrame(str)); |
|
|
@@ -236,7 +268,9 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket |
|
|
|
@TLogAspect(str = "testtest") |
|
|
|
// @TLogAspect({"enterpriseName","type"}) |
|
|
|
private void reply(Channel channel, String msg, JSONObject jo,String enterpriseName,String type ) { |
|
|
|
|
|
|
|
if (!jo.containsKey("code")) { |
|
|
|
jo.put("code",0); |
|
|
|
} |
|
|
|
INSTANCE.logService.record(jo,msg,enterpriseName,type); |
|
|
|
channel.writeAndFlush(new TextWebSocketFrame(jo.toJSONString())); |
|
|
|
} |
|
|
@@ -285,6 +319,10 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket |
|
|
|
log.info("断开废弃连接,userId:{},channel:{}:", userId, channel.id().asLongText()); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 清楚traceId信息 |
|
|
|
if (ServerConfig.currentTraceMap.containsKey(userId)) { |
|
|
|
ServerConfig.currentTraceMap.remove(userId); |
|
|
|
} |
|
|
|
if (ServerConfig.sessionMap.containsKey(userId)) { |
|
|
|
ServerConfig.sessionMap.remove(userId); |
|
|
|
log.info("用户下线,userId:{},channel:{}:", userId, channel.id().asLongText()); |
|
|
|