|
@@ -2,11 +2,13 @@ package com.leromro.core.facade;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONConfig;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.leromro.common.core.domain.R;
|
|
|
+import com.leromro.common.core.domain.entity.SysDept;
|
|
|
import com.leromro.common.core.domain.entity.SysUser;
|
|
|
import com.leromro.common.utils.SecurityUtils;
|
|
|
import com.leromro.core.domain.ConversationMsgRecord;
|
|
@@ -22,6 +24,7 @@ import com.leromro.core.service.IConversationRecordService;
|
|
|
import com.leromro.core.service.IMainOrderService;
|
|
|
import com.leromro.core.service.IVolunteerInfoService;
|
|
|
import com.leromro.core.socket.WebSocketService;
|
|
|
+import com.leromro.system.service.ISysDeptService;
|
|
|
import com.leromro.system.service.ISysUserService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -49,6 +52,8 @@ public class ConversationRecordFacade {
|
|
|
|
|
|
private final WebSocketService webSocketService;
|
|
|
|
|
|
+ private final ISysDeptService sysDeptService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取会话记录详细信息
|
|
@@ -90,6 +95,9 @@ public class ConversationRecordFacade {
|
|
|
return R.ok(vo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 消息列表页面 点击会话 获取会话记录详细信息
|
|
|
+ */
|
|
|
public R<ConversationRecordVO> getListConversationInfo(Long conversationRecordId) {
|
|
|
ConversationRecordVO vo = new ConversationRecordVO();
|
|
|
ConversationRecord conversationRecord = conversationRecordService.getOne(new LambdaQueryWrapper<ConversationRecord>()
|
|
@@ -105,11 +113,11 @@ public class ConversationRecordFacade {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void sendMsg(ConversationMsgDTO dto) {
|
|
|
- Long userId = SecurityUtils.getUserId();
|
|
|
+ SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
//保存消息
|
|
|
ConversationMsgRecord conversationMsgRecord = ConversationMsgRecord.builder()
|
|
|
.conversationRecordId(dto.getConversationRecordId())
|
|
|
- .senderId(userId)
|
|
|
+ .senderId(user.getUserId())
|
|
|
.userId(dto.getUserId())
|
|
|
.volunteerId(dto.getVolunteerId())
|
|
|
.msgType(dto.getMsgType())
|
|
@@ -126,13 +134,37 @@ public class ConversationRecordFacade {
|
|
|
if (dto.getSystem() == 1){
|
|
|
//用户发送,设置用户已读
|
|
|
conversationMsgRecord.setUserReadFlag("2");
|
|
|
- receiver = dto.getVolunteerId();
|
|
|
+ // 目前系统消息不允许发送,如果为订单消息则设置接收人为志愿者,如果是客服消息则设置区域编号和名称
|
|
|
+ if ("2".equals(dto.getConversationType())){
|
|
|
+ receiver = dto.getVolunteerId();
|
|
|
+ }else {
|
|
|
+ conversationMsgRecord.setDistrictCode(user.getDistrictCode());
|
|
|
+ conversationMsgRecord.setDistrictName(user.getDistrictName());
|
|
|
+ }
|
|
|
+ //设置会话
|
|
|
wrapper.set(ConversationRecord::getVolunteerDelFlag, "0");
|
|
|
} else if (dto.getSystem() == 2) {
|
|
|
//志愿者发送,设置志愿者已读
|
|
|
conversationMsgRecord.setVolunteerReadFlag("2");
|
|
|
- receiver = dto.getUserId();
|
|
|
+ // 目前系统消息不允许发送,如果为订单消息则设置接收人为志愿者,如果是客服消息则设置区域编号和名称
|
|
|
+ if ("2".equals(dto.getConversationType())){
|
|
|
+ receiver = dto.getUserId();
|
|
|
+ }else {
|
|
|
+ conversationMsgRecord.setDistrictCode(user.getDistrictCode());
|
|
|
+ conversationMsgRecord.setDistrictName(user.getDistrictName());
|
|
|
+ }
|
|
|
+ //设置会话
|
|
|
wrapper.set(ConversationRecord::getUserDelFlag, "0");
|
|
|
+ }else if (dto.getSystem() == 3){
|
|
|
+ //系统发送,设置系统已读
|
|
|
+ conversationMsgRecord.setCustomerServiceReadFlag("2");
|
|
|
+ conversationMsgRecord.setUserId(dto.getUserId());
|
|
|
+ conversationMsgRecord.setVolunteerId(dto.getVolunteerId());
|
|
|
+ //设置接收人
|
|
|
+ receiver = ObjectUtil.isNull(dto.getUserId())?dto.getVolunteerId():dto.getUserId();
|
|
|
+ //设置会话
|
|
|
+ wrapper.set(ConversationRecord::getUserDelFlag, "0")
|
|
|
+ .set(ConversationRecord::getVolunteerDelFlag, "0");
|
|
|
}
|
|
|
//保存消息
|
|
|
conversationMsgRecordService.save(conversationMsgRecord);
|
|
@@ -143,7 +175,7 @@ public class ConversationRecordFacade {
|
|
|
SocketMsgVO<ConversationMsgRecordVO> msgVO = SocketMsgVO.<ConversationMsgRecordVO>builder().type("msgNew").data(BeanUtil.copyProperties(conversationMsgRecord, ConversationMsgRecordVO.class)).build();
|
|
|
webSocketService.sendMessage(receiver,JSONUtil.toJsonStr(msgVO,new JSONConfig().setDateFormat("yyyy-MM-dd HH:mm:ss")));
|
|
|
//推送总数
|
|
|
- conversationMsgRecordService.getUnreadMsgCountByUserId(dto.getSystem(), userId);
|
|
|
+ conversationMsgRecordService.getUnreadMsgCountByUserId(dto.getSystem(), user.getUserId());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -153,13 +185,21 @@ public class ConversationRecordFacade {
|
|
|
LambdaUpdateWrapper<ConversationMsgRecord> wrapper = new LambdaUpdateWrapper<ConversationMsgRecord>()
|
|
|
.eq(ConversationMsgRecord::getConversationRecordId, dto.getConversationRecordId());
|
|
|
if (dto.getSystem() == 1){
|
|
|
- //用户发送,设置用户已读
|
|
|
+ //用户,设置用户已读
|
|
|
wrapper.eq(ConversationMsgRecord::getUserId, SecurityUtils.getUserId());
|
|
|
+ wrapper.eq(ConversationMsgRecord::getUserReadFlag, "0");
|
|
|
wrapper.set(ConversationMsgRecord::getUserReadFlag, "2");
|
|
|
} else if (dto.getSystem() == 2) {
|
|
|
- //志愿者发送,设置志愿者已读
|
|
|
+ //志愿者,设置志愿者已读
|
|
|
wrapper.eq(ConversationMsgRecord::getVolunteerId, SecurityUtils.getUserId());
|
|
|
+ wrapper.eq(ConversationMsgRecord::getVolunteerReadFlag, "0");
|
|
|
wrapper.set(ConversationMsgRecord::getVolunteerReadFlag, "2");
|
|
|
+ } else if (dto.getSystem() == 3) {
|
|
|
+ //后台,设置客服已读
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getUserId()),ConversationMsgRecord::getUserId, dto.getUserId());
|
|
|
+ wrapper.set(ObjectUtil.isNotNull(dto.getUserId()),ConversationMsgRecord::getUserReadFlag, "2");
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getVolunteerId()),ConversationMsgRecord::getVolunteerId, dto.getVolunteerId());
|
|
|
+ wrapper.set(ObjectUtil.isNotNull(dto.getVolunteerId()),ConversationMsgRecord::getVolunteerReadFlag, "2");
|
|
|
}
|
|
|
conversationMsgRecordService.update(wrapper);
|
|
|
//推送总数
|
|
@@ -167,7 +207,81 @@ public class ConversationRecordFacade {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取历史聊天记录,目前设置为获取10条
|
|
|
+ */
|
|
|
public List<ConversationMsgRecordVO> getHistoryMsg(ConversationMsgDTO dto) {
|
|
|
return conversationMsgRecordService.getNewestMsg(dto.getConversationRecordId(),dto.getConversationMsgRecordId());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 帮助与客服,获取与客服会话记录和详细信息
|
|
|
+ * 如果没有会话,会自动创建会话
|
|
|
+ * 返回值为会话信息和最新的10条聊天记录
|
|
|
+ */
|
|
|
+ public R<ConversationRecordVO> getHelpConversation(ConversationMsgDTO dto) {
|
|
|
+ Integer system = dto.getSystem();
|
|
|
+ //获取当前用户所在地区
|
|
|
+ String districtCode = SecurityUtils.getLoginUser().getUser().getDistrictCode();
|
|
|
+ if (StrUtil.isEmpty(districtCode)){
|
|
|
+ return R.fail("当前用户还未选择地区,无法获取当前地区客服");
|
|
|
+ }
|
|
|
+ //获取当前用户所在地区的区域中心
|
|
|
+ SysDept dept = sysDeptService.getOne(new LambdaQueryWrapper<SysDept>()
|
|
|
+ .eq(SysDept::getDistrictCode, districtCode)
|
|
|
+ .eq(SysDept::getAreaType, "3"));
|
|
|
+ //如果不存在区域中心,则提示
|
|
|
+ if (ObjectUtil.isNull(dept)){
|
|
|
+ return R.fail("当前所在地区还未开展服务,如需加盟请联系XXXX");
|
|
|
+ }
|
|
|
+ ConversationRecordVO vo = new ConversationRecordVO();
|
|
|
+ LambdaQueryWrapper<ConversationRecord> wrapper = new LambdaQueryWrapper<ConversationRecord>().eq(ConversationRecord::getConversationType, "3");
|
|
|
+ if (system == 1){
|
|
|
+ wrapper.eq(ConversationRecord::getUserId, SecurityUtils.getUserId());
|
|
|
+ } else if (system == 2) {
|
|
|
+ wrapper.eq(ConversationRecord::getVolunteerId, SecurityUtils.getUserId());
|
|
|
+ }else {
|
|
|
+ return R.fail("系统类型错误");
|
|
|
+ }
|
|
|
+ ConversationRecord conversationRecord = conversationRecordService.getOne(wrapper);
|
|
|
+ if (ObjectUtil.isNull(conversationRecord)){
|
|
|
+ //插入一条客服提示语
|
|
|
+ ConversationMsgRecord conversationMsgRecord = ConversationMsgRecord.builder()
|
|
|
+ .msgType("1")
|
|
|
+ .msgContent("您好,请问需要什么帮助")
|
|
|
+ .msgSendTime(LocalDateTime.now())
|
|
|
+ .userReadFlag("2")
|
|
|
+ .districtName(dept.getDistrictName())
|
|
|
+ .districtCode(dept.getDistrictCode())
|
|
|
+ .build();
|
|
|
+ //不存在则创建会话,并保存
|
|
|
+ conversationRecord = ConversationRecord.builder()
|
|
|
+ .districtCode(dept.getDistrictCode())
|
|
|
+ .districtName(dept.getDistrictName())
|
|
|
+ .newestMsgContent(conversationMsgRecord.getMsgContent())
|
|
|
+ .newestMsgTime(conversationMsgRecord.getMsgSendTime())
|
|
|
+ .msgType(conversationMsgRecord.getMsgType())
|
|
|
+ .conversationType("3")
|
|
|
+ .build();
|
|
|
+ if (system == 1){
|
|
|
+ //设置会话信息
|
|
|
+ conversationRecord.setUserId(SecurityUtils.getUserId());
|
|
|
+ conversationRecord.setUserName(SecurityUtils.getUsername());
|
|
|
+ conversationRecord.setUserOrVolunteer("1");
|
|
|
+ conversationMsgRecord.setUserId(SecurityUtils.getUserId());
|
|
|
+ } else {
|
|
|
+ //设置会话信息
|
|
|
+ conversationRecord.setVolunteerId(SecurityUtils.getUserId());
|
|
|
+ conversationRecord.setVolunteerName(SecurityUtils.getUsername());
|
|
|
+ conversationRecord.setUserOrVolunteer("2");
|
|
|
+ conversationMsgRecord.setVolunteerId(SecurityUtils.getUserId());
|
|
|
+ }
|
|
|
+ conversationRecordService.save(conversationRecord);
|
|
|
+ conversationMsgRecord.setConversationRecordId(conversationRecord.getConversationRecordId());
|
|
|
+ conversationMsgRecordService.save(conversationMsgRecord);
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(conversationRecord,vo);
|
|
|
+ vo.setVos(conversationMsgRecordService.getNewestMsg(vo.getConversationRecordId(),null));
|
|
|
+ return R.ok(vo);
|
|
|
+ }
|
|
|
}
|