Commit 68c6e9f4 authored by shiyu's avatar shiyu

人工介入接口

parent ab6d0528
...@@ -73,4 +73,25 @@ public class SysIMController { ...@@ -73,4 +73,25 @@ public class SysIMController {
return sysIMService.setChatUserRemark(dto); return sysIMService.setChatUserRemark(dto);
} }
@ApiOperation(value = "人工介入")
@PostMapping("/humanIntervene")
public Result humanIntervene(@RequestBody ConversationRequestDto dto) {
logger.info("【请求开始】人工介入,请求参数:{}", JSON.toJSONString(dto));
if (StringUtils.isEmpty(dto.getFromAccount()) || StringUtils.isEmpty(dto.getToAccount())) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return sysIMService.humanIntervene(dto);
}
@ApiOperation(value = "结束人工介入")
@PostMapping("/stopHumanIntervene")
public Result stopHumanIntervene(@RequestBody ConversationRequestDto dto) {
logger.info("【请求开始】结束人工介入,请求参数:{}", JSON.toJSONString(dto));
if (StringUtils.isEmpty(dto.getFromAccount()) || StringUtils.isEmpty(dto.getToAccount())) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return sysIMService.stopHumanIntervene(dto);
}
} }
...@@ -7,12 +7,12 @@ import com.wwdz.ch.core.im.api.ConversationApi; ...@@ -7,12 +7,12 @@ import com.wwdz.ch.core.im.api.ConversationApi;
import com.wwdz.ch.core.im.api.TLSSigApi; import com.wwdz.ch.core.im.api.TLSSigApi;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.IMUtil; import com.wwdz.ch.core.util.IMUtil;
import com.wwdz.ch.core.util.RedisUtils;
import com.wwdz.ch.db.dao.AiAssistantDao; import com.wwdz.ch.db.dao.AiAssistantDao;
import com.wwdz.ch.db.dao.UserDao; import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.domain.AiAssistant; import com.wwdz.ch.db.domain.AiAssistant;
import com.wwdz.ch.db.domain.User; import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.dto.request.ConversationRequestDto; import com.wwdz.ch.db.dto.request.ConversationRequestDto;
import com.wwdz.ch.db.dto.request.ImRecordRequestDto;
import com.wwdz.ch.db.dto.request.UserRequestDto; import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.xxdxxs.utils.JsonUtils; import com.xxdxxs.utils.JsonUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -43,6 +43,9 @@ public class SysIMServiceImpl implements SysIMService { ...@@ -43,6 +43,9 @@ public class SysIMServiceImpl implements SysIMService {
@Autowired @Autowired
AiAssistantDao aiAssistantDao; AiAssistantDao aiAssistantDao;
@Autowired
RedisUtils redisUtils;
@Override @Override
public Result sendChatMsg(SendChatMsgRequestDto dto) { public Result sendChatMsg(SendChatMsgRequestDto dto) {
try { try {
...@@ -50,6 +53,8 @@ public class SysIMServiceImpl implements SysIMService { ...@@ -50,6 +53,8 @@ public class SysIMServiceImpl implements SysIMService {
if (dto.getIsRealPersonAnswer() != null && dto.getIsRealPersonAnswer() == 1) { if (dto.getIsRealPersonAnswer() != null && dto.getIsRealPersonAnswer() == 1) {
dto.setCloudCustomData(JsonUtils.fromMap(new HashMap<String, Object>(){{put("realPersonId", dto.getRealPersonId());}})); dto.setCloudCustomData(JsonUtils.fromMap(new HashMap<String, Object>(){{put("realPersonId", dto.getRealPersonId());}}));
} }
String key = imUtil.getHumanInterveneKey(dto.getToAccount(), dto.getFromAccount());
redisUtils.set(key, System.currentTimeMillis(), 60 * 3);
Result result = conversationApi.sendChatMsg(dto); Result result = conversationApi.sendChatMsg(dto);
return result; return result;
} catch (Exception e) { } catch (Exception e) {
...@@ -80,6 +85,12 @@ public class SysIMServiceImpl implements SysIMService { ...@@ -80,6 +85,12 @@ public class SysIMServiceImpl implements SysIMService {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("user", user); map.put("user", user);
map.put("aiAssistant", aiAssistant); map.put("aiAssistant", aiAssistant);
//判断该会话是否有人工介入
if (redisUtils.hasKey(imUtil.getHumanInterveneKey(dto.getFromAccount(), dto.getToAccount()))) {
map.put("intervened", true);
} else {
map.put("intervened", false);
}
return Result.success(map); return Result.success(map);
} catch (Exception e) { } catch (Exception e) {
logger.error("获取用户信息失败:{}", e); logger.error("获取用户信息失败:{}", e);
...@@ -100,4 +111,28 @@ public class SysIMServiceImpl implements SysIMService { ...@@ -100,4 +111,28 @@ public class SysIMServiceImpl implements SysIMService {
} }
return Result.failed(); return Result.failed();
} }
/**
* fromAccount为用户账号
* toAccount为机器人账号
* @param dto
* @return
*/
@Override
public Result humanIntervene(ConversationRequestDto dto) {
String key = imUtil.getHumanInterveneKey(dto.getFromAccount(), dto.getToAccount());
redisUtils.set(key, System.currentTimeMillis(), 60 * 3);
return Result.success();
}
@Override
public Result stopHumanIntervene(ConversationRequestDto dto) {
String key = imUtil.getHumanInterveneKey(dto.getFromAccount(), dto.getToAccount());
boolean flag = redisUtils.delete(key);
if (flag) {
return Result.success();
}
return Result.failed();
}
} }
...@@ -38,4 +38,18 @@ public interface SysIMService { ...@@ -38,4 +38,18 @@ public interface SysIMService {
* @return * @return
*/ */
Result setChatUserRemark(UserRequestDto dto); Result setChatUserRemark(UserRequestDto dto);
/**
* 人工介入
* @param dto
* @return
*/
Result humanIntervene(ConversationRequestDto dto);
/**
* 结束人工介入
* @param dto
* @return
*/
Result stopHumanIntervene(ConversationRequestDto dto);
} }
...@@ -90,4 +90,15 @@ public class IMUtil { ...@@ -90,4 +90,15 @@ public class IMUtil {
return url + stringBuffer.toString(); return url + stringBuffer.toString();
} }
/**
* 人工介入在redis中的标识
* @param fromAccount
* @param toAccount
* @return
*/
public String getHumanInterveneKey(String fromAccount, String toAccount) {
String key = "C2C:INTERVENE:" + formatUserId(fromAccount) + "_to_" + formatUserId(toAccount);
return key;
}
} }
...@@ -140,6 +140,11 @@ public class ImServiceImpl implements IMService { ...@@ -140,6 +140,11 @@ public class ImServiceImpl implements IMService {
} }
logger.info("=========== userid:{}, 提问ai的消息发送成功 ==========", dto.getFromAccount()); logger.info("=========== userid:{}, 提问ai的消息发送成功 ==========", dto.getFromAccount());
if (redisUtils.hasKey(imUtil.getHumanInterveneKey(dto.getFromAccount(), dto.getToAccount()))) {
logger.info(">>>> 会话: {} to {}, 已有人工介入, 无需机器人回答 <<<<", dto.getFromAccount(), dto.getToAccount());
return Result.success();
}
if (dto.getMsgType() == IMEnum.MsgTypeEnum.TIMTextElem.getCode()) { if (dto.getMsgType() == IMEnum.MsgTypeEnum.TIMTextElem.getCode()) {
String question = (String) dto.getMsgContent(); String question = (String) dto.getMsgContent();
question = question + ",请回答钱币相关的内容"; question = question + ",请回答钱币相关的内容";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment