Commit 7faffb68 authored by shiyu's avatar shiyu

用户停止回答,人工回复不被发送

parent eaab10f6
......@@ -37,7 +37,7 @@ public class SysIMController {
@PostMapping("/sendChatMsg")
public Result sendChatMsg(@RequestBody SendChatMsgRequestDto dto) {
logger.info("【请求开始】人工介入ai发送聊天消息,请求参数:{}", JSON.toJSONString(dto));
if (!StringUtils.isAllNotEmpty(dto.getFromAccount(), dto.getToAccount(), dto.getMsgType())) {
if (!StringUtils.isAllNotEmpty(dto.getFromAccount(), dto.getToAccount(), dto.getMsgType(), dto.getReqId())) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return sysIMService.sendChatMsg(dto);
......
......@@ -92,7 +92,8 @@ public class SysIMRecordServiceImpl implements SysIMRecordService {
imRecordVo.setFromAccountIcon(cacheUtil.getAppletUserById(Long.valueOf(imRecord.getFromAccount())).getAvatar());
imRecordVo.setToAccountIcon(cacheUtil.getAiAssistantByCode(imRecord.getToAccount()).getAvatar());
}
if (StringUtils.hasLength(imRecord.getCloudCustomData())){
String cloudCustomData = imRecord.getCloudCustomData();
if (cloudCustomData.contains("realPersonId")){
imRecordVo.setIsRealPerson(true);
}
imRecordVos.add(imRecordVo);
......
package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.service.SysIMService;
import com.wwdz.ch.core.consts.ResultCode;
import com.wwdz.ch.core.entity.im.IMChatRequestDto;
import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto;
import com.wwdz.ch.core.im.api.ConversationApi;
......@@ -51,10 +52,14 @@ public class SysIMServiceImpl implements SysIMService {
try {
//转人工需要设置人工的id,放入自定义数据字段中
if (dto.getIsRealPersonAnswer() != null && dto.getIsRealPersonAnswer() == 1) {
dto.setCloudCustomData(JsonUtils.fromMap(new HashMap<String, Object>(){{put("realPersonId", dto.getRealPersonId());}}));
dto.setCloudCustomData(new HashMap<String, Object>(){{put("realPersonId", dto.getRealPersonId());}});
}
String key = imUtil.getHumanInterveneKey(dto.getToAccount(), dto.getFromAccount());
redisUtils.set(key, System.currentTimeMillis(), 60 * 3);
if (redisUtils.hasKey(dto.getReqId())){
logger.info("============= 用户要求停止回答了,人工回复不会被发送 ============= ");
return Result.failed(ResultCode.USER_STOP_AI_ANSWER.getCode(), ResultCode.USER_STOP_AI_ANSWER.getMessage());
}
Result result = conversationApi.sendChatMsg(dto);
return result;
} catch (Exception e) {
......
......@@ -56,6 +56,8 @@ public enum ResultCode {
*/
LOGIN_ACCOUNT_UNENABLED(21012, "用户已被禁用"),
USER_STOP_AI_ANSWER(30000, "该问题被用户要求停止回答,回复不会被发送")
;
int code;
......
......@@ -3,6 +3,8 @@ package com.wwdz.ch.core.entity.im;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.HashMap;
@Data
public class SendChatMsgRequestDto implements Entity {
......@@ -75,6 +77,6 @@ public class SendChatMsgRequestDto implements Entity {
* 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
* 格式 {realPersonId:xxxx}
*/
private String CloudCustomData;
private HashMap<String, Object> CloudCustomData;
}
......@@ -72,8 +72,14 @@ public class IMUtil {
msgContentMap.put("MsgType", IMEnum.MsgTypeEnum.getValueByCode(dto.getMsgType()));
msgContentMap.put("MsgContent", new HashMap(){{put("Text", dto.getMsgContent());}});
imChatMsg.setMsgBody(Arrays.asList(msgContentMap));
imChatMsg.setCloudCustomData(dto.getCloudCustomData());
if (dto.getCloudCustomData() == null) {
HashMap<String, Object> map = new HashMap<>();
map.put("reqId", dto.getReqId());
imChatMsg.setCloudCustomData(JsonUtils.fromMap(map));
} else {
dto.getCloudCustomData().put("reqId", dto.getReqId());
imChatMsg.setCloudCustomData(JsonUtils.fromMap(dto.getCloudCustomData()));
}
return imChatMsg;
}
......
......@@ -24,6 +24,7 @@ public class ConversationDaoImpl implements ConversationDao {
ConversationExample.Criteria criteria = conversationExample.createCriteria();
JdbcHelper.ifPresent(dto.getFromAccount(), criteria::andFromAccountEqualTo);
JdbcHelper.ifPresent(dto.getToAccount(), criteria::andToAccountEqualTo);
conversationExample.setOrderByClause("id asc");
PageHelper.startPage(dto.getPage(), dto.getLimit());
return conversationMapper.selectByExample(conversationExample);
}
......
......@@ -179,7 +179,7 @@ public class ImServiceImpl implements IMService {
@Override
public Result stopAiAnswer(SendChatMsgRequestDto dto) {
redisUtils.set(dto.getReqId(), false, 10, TimeUnit.SECONDS);
redisUtils.set(dto.getReqId(), false, 3, TimeUnit.MINUTES);
return Result.success();
}
}
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