客服自动回复-删除

This commit is contained in:
2025-09-07 10:33:08 +08:00
parent 392c25119b
commit b74b467cf7
4 changed files with 0 additions and 203 deletions

View File

@@ -1,17 +0,0 @@
package com.accompany.business.event;
import org.springframework.context.ApplicationEvent;
/**
* Created by chenli on 2021/09/08
* 客服会话事件
*/
public class CustomerConversationEvent extends ApplicationEvent {
/**
*
* @param source
*/
public CustomerConversationEvent(Object source) {
super(source);
}
}

View File

@@ -1,110 +0,0 @@
package com.accompany.business.event.listener;
import cn.hutool.core.util.ObjectUtil;
import com.accompany.business.dto.netease.IMChatMsgDTO;
import com.accompany.business.event.CustomerConversationEvent;
import com.accompany.business.param.neteasepush.NeteaseSendMsgParam;
import com.accompany.business.service.SendSysMsgService;
import com.accompany.common.config.SystemConfig;
import com.accompany.common.constant.Constant;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.utils.StringUtils;
import com.accompany.core.model.Users;
import com.accompany.core.service.SysConfService;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.service.user.UsersBaseService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
/**
* Created By chenli on 2021/09/08
* 私聊次数统计监听:目前周期只支持周
*/
@Component
public class CustomerConversationListener implements ApplicationListener<CustomerConversationEvent> {
private static final Logger logger = LoggerFactory.getLogger(CustomerConversationListener.class);
@Autowired
private SysConfService sysConfService;
@Autowired
private JedisService jedisService;
@Autowired
private UsersBaseService usersBaseService;
@Autowired
private SendSysMsgService sendSysMsgService;
private Gson gson = new Gson();
@Override
@Async
public void onApplicationEvent(CustomerConversationEvent customerConversationEvent) {
IMChatMsgDTO chatMsg = (IMChatMsgDTO) customerConversationEvent.getSource();
final List<String> offical_account = Arrays.asList(SystemConfig.secretaryUid, SystemConfig.systemMessageUid, SystemConfig.hallMessageUid);
try {
String fromUidStr = chatMsg.getFromAccount();
if (StringUtils.isEmpty(fromUidStr)) return;
if (offical_account.contains(fromUidStr)) return;
Users users = usersBaseService.getUsersByUid(Long.parseLong(fromUidStr));
if (ObjectUtil.isEmpty(users)) return;
//接收人为空,直接返回
if (StringUtils.isEmpty(chatMsg.getTo())) return;
logger.info("客服消息处理,消息接受者to:{}", chatMsg.getTo());
Users customerUser = usersBaseService.getUsersByUid(Long.parseLong(chatMsg.getTo()));
String erbanNos = sysConfService.getSysConfValueById(Constant.SysConfId.CUSTOMER_USER_ERBAN_NO);
if (StringUtils.isBlank(erbanNos)) return;
List<Long> erbanNoList = gson.fromJson(erbanNos, new TypeToken<List<Long>>() {}.getType());
if (CollectionUtils.isEmpty(erbanNoList)) return;
//不是发给客服
if (!erbanNoList.contains(customerUser.getErbanNo())) return;
//发送人是客服自己
if (erbanNoList.contains(users.getErbanNo())) return;
//检查缓存是否20分钟以内
if (jedisService.exits(RedisKey.reply_customer_msg_flag.getKey(String.valueOf(users.getUid())))) return;
//回复消息
sendActivityFortuneMsg(customerUser.getUid(), users.getUid());
//将消息推送到企业微信
/*sendEnterpriseWechatMsg(users, chatMsg);*/
String defaultmin = sysConfService.getDefaultSysConfValueById(Constant.SysConfId.REPLY_CUSTOMER_MSG_MIN_DURATION, String.valueOf(Constant.ConfigDefaultVal.reply_customer_msg_duration_default_val));
Integer second = Integer.valueOf(defaultmin) * 60;
jedisService.setex(RedisKey.reply_customer_msg_flag.getKey(String.valueOf(users.getUid())), second, String.valueOf(1));
}catch (Exception e) {
e.printStackTrace();
}
}
@Async
public void sendActivityFortuneMsg(Long customerUid, Long uid) {
NeteaseSendMsgParam msg = new NeteaseSendMsgParam();
msg.setOpe(0);
msg.setType(0);
msg.setFrom(String.valueOf(customerUid));
msg.setTo(String.valueOf(uid));
msg.setBody("您好,為了快速解決問題,請您先告訴我遇到的問題,由於諮詢人數較多,客服小哥哥和小姐姐正在飛速趕來,我們會儘快回復您。");
sendSysMsgService.sendMsg(msg);
}
}

View File

@@ -1,75 +0,0 @@
package com.accompany.business.event.listener;
import com.accompany.business.dto.netease.IMChatMsgDTO;
import com.accompany.business.event.CustomerConversationEvent;
import com.accompany.business.model.HallMember;
import com.accompany.business.model.HallRoomChatRecord;
import com.accompany.business.service.hall.HallRoomChatService;
import com.accompany.business.service.hall.HallService;
import com.accompany.business.service.room.UserInOutRoomRecordService;
import com.accompany.common.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
@Slf4j
public class RoomPersonChatListener implements ApplicationListener<CustomerConversationEvent> {
@Autowired
private HallService hallService;
@Autowired
private HallRoomChatService hallRoomChatService;
@Autowired
private UserInOutRoomRecordService userInOutRoomRecordService;
@Override
@Async
public void onApplicationEvent(CustomerConversationEvent customerConversationEvent) {
IMChatMsgDTO chatMsg = (IMChatMsgDTO) customerConversationEvent.getSource();
if (StringUtils.isEmpty(chatMsg.getFromAccount()) || StringUtils.isEmpty(chatMsg.getTo())){
return;
}
Long fromUid = Long.parseLong(chatMsg.getFromAccount());
Long toUid = Long.parseLong(chatMsg.getTo());
Long fromRoomUid = userInOutRoomRecordService.getUserCurrentRoomUid(fromUid);
Long toRoomUid = userInOutRoomRecordService.getUserCurrentRoomUid(toUid);
if (null == fromRoomUid || !fromRoomUid.equals(toRoomUid)){
return;
}
HallMember hallMember = hallService.getHallMember(fromUid);
if (null == hallMember){
return;
}
HallMember roomHallMember = hallService.getHallMember(fromRoomUid);
if (null == roomHallMember || !hallMember.getHallId().equals(roomHallMember.getHallId())){
return;
}
HallRoomChatRecord record = new HallRoomChatRecord();
record.setFromUid(fromUid);
record.setToUid(toUid);
record.setRoomUid(fromRoomUid);
record.setHallId(hallMember.getHallId());
record.setMsgId(chatMsg.getMsgidClient());
record.setConvType(chatMsg.getConvType());
record.setMsgType(chatMsg.getMsgType());
record.setBody(chatMsg.getBody());
record.setAttach(chatMsg.getAttach());
record.setCreateTime(new Date(chatMsg.getMsgTimestamp()));
hallRoomChatService.save(record);
log.info("[私聊消息记录] {} {} {} {} {}", fromUid, fromRoomUid, toUid, toRoomUid, JSON.toJSONString(chatMsg));
}
}

View File

@@ -262,7 +262,6 @@ public class ReceiveNeteaseService extends BaseService {
//私聊信息
chatMsg.setStatus(msgStatus);
applicationContext.publishEvent(new UserChatMsgEvent(chatMsg));
applicationContext.publishEvent(new CustomerConversationEvent(chatMsg));
}
@NotNull