Parcourir la source

yinruoxi

feature:
    1.修改:整合工作模式和闲聊模式。
undefined
kira il y a 1 an
Parent
révision
79ba2ffb9c
1 fichiers modifiés avec 51 ajouts et 1 suppressions
  1. +51
    -1
      xueyi-modules/xueyi-nlt/src/main/java/com/xueyi/nlt/netty/server/handler/ChatServerHandler.java

+ 51
- 1
xueyi-modules/xueyi-nlt/src/main/java/com/xueyi/nlt/netty/server/handler/ChatServerHandler.java Voir le fichier

@@ -2,7 +2,12 @@ package com.xueyi.nlt.netty.server.handler;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xueyi.common.core.utils.core.ObjectUtil;
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.service.IDmIntentService;
import com.xueyi.nlt.nlt.service.IDmRegularService;
import com.xueyi.nlt.nlt.template.FreeChatTemplate;
import com.xueyi.nlt.nlt.template.MovieChatTemplate;
import com.yomahub.tlog.core.annotation.TLogAspect;
@@ -32,6 +37,10 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
@Autowired
private FreeChatTemplate freeChatTemplate;

@Autowired
private IDmIntentService intentService;


@Autowired
private MovieChatTemplate movieChatTemplate;

@@ -42,6 +51,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
INSTANCE = this;
INSTANCE.freeChatTemplate = this.freeChatTemplate;
INSTANCE.movieChatTemplate = this.movieChatTemplate;
INSTANCE.intentService = this.intentService;
}
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, TextWebSocketFrame textWebSocketFrame) throws Exception {
@@ -65,6 +75,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
}
// 获取到发送人的设备号
String devId = jsonObject.getString("devId");
Long operatorId = jsonObject.getLong("operatorId");
// 获取到发送人的用户id
String msg = jsonObject.getString("msg");
synchronized (ServerConfig.class) {
@@ -78,7 +89,34 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
update(devId, channel);
}
try {
sendMsg(devId, msg);
DmIntentVo dmIntentVo = new DmIntentVo();
dmIntentVo.setContent(msg);
dmIntentVo.setDevId(devId);
// 调用正则判断,如果正则匹配到了,则返回正则匹配到的结果
DmIntentResponse dmIntentResponse = INSTANCE.intentService.regularAnswer(dmIntentVo);

if (ObjectUtil.isNotNull(dmIntentResponse) && StringUtils.isNotEmpty(dmIntentResponse.getSkillCode())) {
JSONObject jo = formatResult(dmIntentResponse,2);
channel.writeAndFlush(new TextWebSocketFrame(jo.toJSONString()));
return;
}
// 调用知识库,如果知识库匹配到了,则返回知识库匹配到的结果
dmIntentResponse = INSTANCE.intentService.knowledgeAnswer(dmIntentVo);
if (ObjectUtil.isNotNull(dmIntentResponse) && StringUtils.isNotEmpty(dmIntentResponse.getSkillCode()) && dmIntentResponse.getH5().getInteger("accurate") == 1) {
JSONObject jo = formatResult(dmIntentResponse,2);
channel.writeAndFlush(new TextWebSocketFrame(jo.toJSONString()));
return;
}
else {
JSONObject jo = new JSONObject();
jo.put("action","chat");
jo.put("motion","idle");
jo.put("traceId","");
jo.put("status",1);
jo.put("tts","请稍等一下,我要查询一下功能。");
channel.writeAndFlush(new TextWebSocketFrame(jo.toJSONString()));
sendMsg(devId, msg);
}
} catch (Exception e) {
JSONObject jo = new JSONObject();
jo.put("action","chat");
@@ -211,4 +249,16 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
ctx.close();
}

private JSONObject formatResult(DmIntentResponse dmIntentResponse,Integer status) {
JSONObject resultJson = new JSONObject();
resultJson.put("action",dmIntentResponse.getAction());
resultJson.put("motion",dmIntentResponse.getMotion());
resultJson.put("traceId","");
resultJson.put("skillCode",dmIntentResponse.getSkillCode());
resultJson.put("status",status);
resultJson.put("tts","");
resultJson.put("h5",dmIntentResponse.getH5());
return resultJson;
}

}

Chargement…
Annuler
Enregistrer