|
@@ -54,6 +54,7 @@ import com.fs.qwHookApi.vo.QwHookMsgVO;
|
|
|
import com.fs.qwHookApi.vo.QwHookVO;
|
|
|
import com.fs.sop.domain.QwSopLogs;
|
|
|
import com.fs.sop.mapper.QwSopLogsMapper;
|
|
|
+import com.fs.utils.SensitiveDataUtils;
|
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
import com.fs.wxwork.dto.*;
|
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
@@ -61,6 +62,7 @@ import com.vdurmont.emoji.EmojiParser;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -156,6 +158,8 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
private IFsExpressService expressService;
|
|
|
@Autowired
|
|
|
private CompanyConfigMapper companyConfigMapper;
|
|
|
+ @Autowired
|
|
|
+ private IFastGptChatReplaceTextService fastGptChatReplaceTextService;
|
|
|
|
|
|
/** Ai半小时未回复提醒 **/
|
|
|
/**
|
|
@@ -363,38 +367,38 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
if (qwContent.contains("我已经添加了你")){
|
|
|
return R.ok();
|
|
|
}
|
|
|
- System.out.println(qwUserId);
|
|
|
+ log.info("数据:{}", qwUserId);
|
|
|
QwUser user = qwUserMapper.selectQwUserById(qwUserId);
|
|
|
//查询接收人
|
|
|
if(user==null){
|
|
|
- System.out.println("查询接收人为空");
|
|
|
+ log.error("查询接收人为空");
|
|
|
return R.ok();
|
|
|
}
|
|
|
if(user.getFastGptRoleId()==null){
|
|
|
- System.out.println("未绑定角色");
|
|
|
+ log.error("未绑定角色");
|
|
|
return R.ok();
|
|
|
}
|
|
|
Long serverId = user.getServerId();
|
|
|
- System.out.println("服务器id"+serverId);
|
|
|
+ log.info("服务器id"+serverId);
|
|
|
if (serverId == null) {
|
|
|
- System.out.println("服务id为空");
|
|
|
+ log.error("服务id为空");
|
|
|
return R.ok();
|
|
|
}
|
|
|
FastGptRole role=roleService.selectFastGptRoleTypeByRoleId(user.getFastGptRoleId());
|
|
|
//没用ai角色跳过
|
|
|
if(role==null){
|
|
|
- System.out.println("没用ai角色跳过");
|
|
|
+ log.error("没用ai角色跳过");
|
|
|
return R.ok();
|
|
|
}
|
|
|
String modeConfig=role.getModeConfigJson();
|
|
|
//key不为空
|
|
|
if(StringUtils.isEmpty(modeConfig)){
|
|
|
- System.out.println("没有aiKey");
|
|
|
+ log.error("没有aiKey");
|
|
|
return R.ok();
|
|
|
}
|
|
|
ModeConfig config=JSONUtil.toBean(modeConfig,ModeConfig.class);
|
|
|
if(StringUtils.isEmpty(config.getAPPKey())){
|
|
|
- System.out.println("没有aiKey");
|
|
|
+ log.error("没有aiKey");
|
|
|
return R.ok();
|
|
|
}
|
|
|
WxWorkVid2UserIdDTO wxWorkVid2UserIdDTO = new WxWorkVid2UserIdDTO();
|
|
@@ -404,14 +408,14 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
List<WxWorkVid2UserIdRespDTO> data = WxWorkVid2UserIdRespDTO.getData();
|
|
|
if (data==null|| data.isEmpty()){
|
|
|
|
|
|
- System.out.println("未获取到extId"+wxWorkVid2UserIdDTO);
|
|
|
+ log.error("未获取到extId"+wxWorkVid2UserIdDTO);
|
|
|
return R.ok();
|
|
|
}
|
|
|
com.fs.wxwork.dto.WxWorkVid2UserIdRespDTO dto = data.get(0);
|
|
|
|
|
|
QwExternalContact qwExternalContacts = qwExternalContactMapper.selectQwExternalContactByExternalUserIdAndQwUserId(dto.getOpenid(), user.getCorpId(),user.getQwUserId());
|
|
|
if (qwExternalContacts==null){
|
|
|
- System.out.println("没有外部联系人");
|
|
|
+ log.error("没有外部联系人" + "user:" + user);
|
|
|
return R.ok();
|
|
|
}
|
|
|
if(qwExternalContacts.getType()==2){
|
|
@@ -437,10 +441,12 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
- System.out.println("不是图片"+type);
|
|
|
+ log.info("不是图片"+type);
|
|
|
}
|
|
|
|
|
|
- String contentEmj = replaceWxEmo(qwContent);
|
|
|
+ //对用户处理的内容做处理
|
|
|
+ String maskedContent = processContent(qwContent);
|
|
|
+ String contentEmj = replaceWxEmo(maskedContent);
|
|
|
if(!contentEmj.contains("表情包")){
|
|
|
if(!contentEmj.isEmpty()){
|
|
|
addSaveAiMsg(1,1,contentEmj,user,fastGptChatSession.getSessionId(),role.getRoleId(),qwExternalContacts,fastGptChatSession.getUserId(),null,null,null);
|
|
@@ -455,7 +461,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
|
|
|
//判断是否转人工
|
|
|
if (fastGptChatSession.getIsArtificial()==1){
|
|
|
- System.out.println("转人工了");
|
|
|
+ log.error("转人工了,sessionId:" + fastGptChatSession.getSessionId());
|
|
|
return R.ok();
|
|
|
}
|
|
|
//获取是用户是否发送消息
|
|
@@ -472,22 +478,32 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
redisCache.setCacheObject("msg:" + fastGptChatSession.getSessionId(),msg+","+contentEmj,5,TimeUnit.MINUTES);
|
|
|
}
|
|
|
//本次跳过
|
|
|
- System.out.println("正在对话");
|
|
|
+ log.info("正在对话");
|
|
|
return R.ok();
|
|
|
}
|
|
|
//用户首次发送消息
|
|
|
redisCache.setCacheObject("reply:" + fastGptChatSession.getSessionId(),1,5,TimeUnit.MINUTES);
|
|
|
redisCache.setCacheObject("msg:" + fastGptChatSession.getSessionId(),contentEmj,5,TimeUnit.MINUTES);
|
|
|
- System.out.println("等待");
|
|
|
+ log.info("等待");
|
|
|
R r= sendAiMsg(replyI,fastGptChatSession,role,user,qwExternalContacts.getId(),config.getAPPKey(),qwExternalContacts,sender);
|
|
|
EventLogUtils.recordEventLog(sender,1L,1,user);
|
|
|
EventLogUtils.recordEventLog(sender,1L,2,user);
|
|
|
- System.out.println(r);
|
|
|
+ log.info("数据:{}", r);
|
|
|
//完成对话 删除消息记录
|
|
|
redisCache.deleteObject("reply:" + fastGptChatSession.getSessionId());
|
|
|
redisCache.deleteObject("msg:" + fastGptChatSession.getSessionId());
|
|
|
if(!r.get("code").equals(200)){
|
|
|
- log.info("ai报错转人工:"+role.getRoleId()+":"+qwExternalContacts.getName());
|
|
|
+ //判断消息是否需要重发的依据
|
|
|
+ /*redisCache.setCacheObject("retry:" + fastGptChatSession.getSessionId(),1,2,TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject("retryMsg:" + fastGptChatSession.getSessionId(),contentEmj,2,TimeUnit.MINUTES);
|
|
|
+ Integer retryCount = redisCache.getCacheObject("retry:" + fastGptChatSession.getSessionId());
|
|
|
+ if(retryCount < 3){
|
|
|
+ r= retrySendAiMsg(retryCount,fastGptChatSession,role,user,qwExternalContacts.getId(),config.getAPPKey(),qwExternalContacts,sender);
|
|
|
+ }
|
|
|
+ redisCache.deleteObject("retry:" + fastGptChatSession.getSessionId());
|
|
|
+ redisCache.deleteObject("retryMsg:" + fastGptChatSession.getSessionId());*/
|
|
|
+
|
|
|
+ log.error("ai报错转人工:"+role.getRoleId()+":"+qwExternalContacts.getName());
|
|
|
notifyArtificial(fastGptChatSession.getSessionId(),user,qwExternalContacts.getName()," ai报错转人工",qwExternalContacts.getId(),sender);
|
|
|
return R.ok();
|
|
|
}
|
|
@@ -507,13 +523,6 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
}
|
|
|
//存聊天记录
|
|
|
addSaveAiMsg(2,2,contentKh,user,fastGptChatSession.getSessionId(),role.getRoleId(),qwExternalContacts,fastGptChatSession.getUserId(),result.getUsage().prompt_tokens,result.getUsage().completion_tokens,token);
|
|
|
- Integer replyOne = redisCache.getCacheObject("reply:" + fastGptChatSession.getSessionId());
|
|
|
- if (replyOne!=null && replyOne == 1){
|
|
|
- QwUser qwUser = qwUserService.selectQwUserById(fastGptChatSession.getQwUserId());
|
|
|
- if (ObjectUtils.isNotEmpty(qwUser)&&ObjectUtils.isNotEmpty(qwUser.getIpadStatus())&&qwUser.getIpadStatus() == 1){
|
|
|
- addQwAutoTags(qwUser,qwExternalContacts.getUserId(),qwExternalContacts.getExternalUserId());
|
|
|
- }
|
|
|
- }
|
|
|
if (!content.isEmpty()){
|
|
|
addSaveAiMsg(1,2,content,user,fastGptChatSession.getSessionId(),role.getRoleId(),qwExternalContacts,fastGptChatSession.getUserId(),null,null,null);
|
|
|
//从fastgpt_chat_artificial_words表中查询所有转人工文本
|
|
@@ -524,6 +533,12 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
notifyArtificial(fastGptChatSession.getSessionId(),user,qwExternalContacts.getName()," 触发关键词",qwExternalContacts.getId(),sender);
|
|
|
return R.ok();
|
|
|
}
|
|
|
+ //ai回复文字长度大于500就转人工
|
|
|
+ if(content.length() > 500){
|
|
|
+ log.error("回复长度异常:"+role.getRoleId()+":"+qwExternalContacts.getName());
|
|
|
+ notifyArtificial(fastGptChatSession.getSessionId(),user,qwExternalContacts.getName()," 回复长度异常",qwExternalContacts.getId(),sender);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
if (result.isLongText()){
|
|
|
//新增用户信息
|
|
|
addUserInfo(contentKh, qwExternalContacts.getId(),fastGptChatSession);
|
|
@@ -569,7 +584,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
|
|
|
|
|
|
if (result.isArtificial()){
|
|
|
- log.info("ai请求人工:"+role.getRoleId()+":"+qwExternalContacts.getName());
|
|
|
+ log.error("ai请求人工:"+role.getRoleId()+":"+qwExternalContacts.getName());
|
|
|
notifyArtificial(fastGptChatSession.getSessionId(),user,qwExternalContacts.getName()," ai请求人工协助",qwExternalContacts.getId(),sender);
|
|
|
}
|
|
|
}
|
|
@@ -636,7 +651,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
Random random = new Random();
|
|
|
FastGptKeywordSend fastGptKeywordSend = keywordSendList.get(random.nextInt(keywordSendList.size()));
|
|
|
if (fastGptKeywordSend == null){
|
|
|
- System.out.println("输出为空格");
|
|
|
+ log.info("输出为空格");
|
|
|
return;
|
|
|
}
|
|
|
if(fastGptKeywordSend.getKeywordType() == 1L && "物流".equals(fastGptKeywordSend.getKeyword())){
|
|
@@ -662,11 +677,11 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
fastGptChatSessionMapper.updateFastGptChatSession(fastGptChatSession);
|
|
|
break;
|
|
|
case 2:
|
|
|
- sBuilder.append("您购买的 ").append(fsStoreOrder.getPackageName()).append(" 正在准备发货,请耐心等待;\n");
|
|
|
- break;
|
|
|
+ sBuilder.append("您好,您有一个包裹正在准备发货,请耐心等待;\n")
|
|
|
+ .append("\uD83C\uDF39\uD83C\uDF39\uD83C\uDF39");
|
|
|
case 3:
|
|
|
ExpressInfoDTO expressInfo = getExpress(fsStoreOrder.getOrderId());
|
|
|
- sBuilder.append("您购买的 ").append(fsStoreOrder.getPackageName());
|
|
|
+ sBuilder.append("您购买的有一个包裹 ");
|
|
|
sBuilder.append(" 已经查询到了,正在配送中了。\n");
|
|
|
if(expressInfo != null && expressInfo.getTraces() != null && !expressInfo.getTraces().isEmpty()){
|
|
|
List<TracesDTO> traces = expressInfo.getTraces();
|
|
@@ -679,7 +694,7 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
case 5:
|
|
|
ExpressInfoDTO express = getExpress(fsStoreOrder.getOrderId());
|
|
|
//你好,这边查询到您购买的XXX(购买套餐)在XXX(时间)已经送到了,送货员电话为XXX(送货员信息)
|
|
|
- sBuilder.append("这边查询到您购买的 ").append(fsStoreOrder.getPackageName());
|
|
|
+ sBuilder.append("这边查询到您有一个包裹");
|
|
|
if(express != null && express.getTraces() != null && !express.getTraces().isEmpty()){
|
|
|
List<TracesDTO> traces = express.getTraces();
|
|
|
TracesDTO tracesDTO = traces.get(traces.size() - 1);
|
|
@@ -813,6 +828,28 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理用户的输入问题
|
|
|
+ * @param qwContent
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private @Nullable String processContent(String qwContent) {
|
|
|
+ String maskedContent = SensitiveDataUtils.maskMobileNumbers(qwContent);
|
|
|
+ if(maskedContent != null && !maskedContent.isEmpty()){
|
|
|
+ FastGptChatReplaceText fastGptChatReplaceText = new FastGptChatReplaceText();
|
|
|
+ fastGptChatReplaceText.setStatus(1);
|
|
|
+ List<FastGptChatReplaceText> chatReplaceTextList = fastGptChatReplaceTextService.selectFastGptChatReplaceTextList(fastGptChatReplaceText);
|
|
|
+ if(chatReplaceTextList != null && !chatReplaceTextList.isEmpty()){
|
|
|
+ for (FastGptChatReplaceText replaceText : chatReplaceTextList) {
|
|
|
+ if(maskedContent.contains(replaceText.getContent())){
|
|
|
+ maskedContent = maskedContent.replace(replaceText.getContent(), replaceText.getChangeCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return maskedContent;
|
|
|
+ }
|
|
|
+
|
|
|
private void sendAiVoiceMsg(String content, Long sendId , String uuid,Long serverId,QwUser user) {
|
|
|
if (content == null || content.trim().isEmpty()){
|
|
|
System.out.println("输出为空格");
|