|
@@ -6,7 +6,9 @@ import cn.com.ty.lift.ud.chat.controller.model.ChatSessionReq;
|
|
|
import cn.com.ty.lift.ud.chat.controller.model.ChatSessionVo;
|
|
|
import cn.com.ty.lift.ud.chat.controller.query.ChatSessionQuery;
|
|
|
import cn.com.ty.lift.ud.chat.mapper.ChatSessionMapper;
|
|
|
+import cn.com.ty.lift.ud.chat.mapper.entity.ChatMsgEntity;
|
|
|
import cn.com.ty.lift.ud.chat.mapper.entity.ChatSessionEntity;
|
|
|
+import cn.com.ty.lift.ud.chat.service.IChatMsgService;
|
|
|
import cn.com.ty.lift.ud.chat.service.IChatSessionService;
|
|
|
import cn.com.ty.lift.ud.neety.task.RoomInfo;
|
|
|
import cn.com.ty.lift.ud.neety.task.UserInfo;
|
|
@@ -26,13 +28,12 @@ import org.springframework.jms.core.JmsMessagingTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.lang.reflect.Array;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* 会话 -ServiceImpl
|
|
@@ -42,8 +43,7 @@ import java.util.Set;
|
|
|
*/
|
|
|
@Service
|
|
|
@Transactional
|
|
|
-public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatSessionEntity>
|
|
|
- implements IChatSessionService {
|
|
|
+public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatSessionEntity> implements IChatSessionService {
|
|
|
@Autowired
|
|
|
private ChatSessionMapper sessionMapper;
|
|
|
@Autowired
|
|
@@ -52,6 +52,8 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
private UserInfoMapper userInfoMapper;
|
|
|
@Autowired
|
|
|
private RedisUtils redis;
|
|
|
+ @Autowired
|
|
|
+ private IChatMsgService msgService;
|
|
|
|
|
|
@Autowired
|
|
|
private JmsMessagingTemplate jmsMessagingTemplate;
|
|
@@ -117,9 +119,12 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
|
|
|
@Override
|
|
|
public RestResponse findOneByLiftCase(ChatSessionQuery req) {
|
|
|
- QueryWrapper<ChatSessionEntity> queryWrapper = new QueryWrapper<ChatSessionEntity>();
|
|
|
+ /*QueryWrapper<ChatSessionEntity> queryWrapper = new QueryWrapper<ChatSessionEntity>();
|
|
|
queryWrapper.eq("data_id", req.getDataId());
|
|
|
- queryWrapper.eq("user_id", req.getUserId());
|
|
|
+ queryWrapper.eq("user_id", req.getUserId());*/
|
|
|
+ QueryWrapper<ChatSessionEntity> queryWrapper = new QueryWrapper<ChatSessionEntity>()
|
|
|
+ .eq("data_id", req.getDataId())
|
|
|
+ .last("find_in_set(" + req.getUserId() + ",user_id)");
|
|
|
ChatSessionEntity data = sessionMapper.selectOne(queryWrapper);
|
|
|
|
|
|
return RestResponse.success(data, "success");
|
|
@@ -149,20 +154,20 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
});*/
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
ChatSessionEntity entity = list.get(i);
|
|
|
- RoomInfo roomInfo = JSONObject.parseObject(redis.get("ROOM:" + entity.getSessionid()),RoomInfo.class);
|
|
|
+ RoomInfo roomInfo = JSONObject.parseObject(redis.get("ROOM:" + entity.getSessionid()), RoomInfo.class);
|
|
|
if (null != roomInfo) {
|
|
|
entity.setLastMsg(roomInfo.getLastChat());
|
|
|
entity.setLastTime(roomInfo.getLastTime());
|
|
|
|
|
|
roomInfo.getUserLIst().forEach(userInfo -> {
|
|
|
- if (userInfo.getUserId().equals(query.getUserId())){
|
|
|
+ if (userInfo.getUserId().equals(query.getUserId())) {
|
|
|
roomInfo.setIsRed(userInfo.getIsRed());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
Collections.sort(list, (ent1, ent2) -> {
|
|
|
- if (ent1.getLastTime() == null || ent2.getLastTime() == null){
|
|
|
+ if (ent1.getLastTime() == null || ent2.getLastTime() == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -186,13 +191,13 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
ChatSessionVo vo = new ChatSessionVo();
|
|
|
// 使用我的用户id和将要聊天的用户id正反去数据库查询房间号是否存在
|
|
|
String sessionId =
|
|
|
- sessionMapper.findOneByUserIdAndCreateUserIdAndDateTable(request.getUserId(), request.getCreateUserId(), 3);
|
|
|
+ sessionMapper.findOneByUserIdAndCreateUserIdAndDateTable(request.getUserId(), request.getCreateUserId(), 3);
|
|
|
|
|
|
if (StringUtils.isBlank(sessionId)) {
|
|
|
ChatSessionEntity record = new ChatSessionEntity();
|
|
|
// 添加自己到房间
|
|
|
sessionId = UUIDUtil.getUuidByTime9();
|
|
|
- record.setUserId(request.getUserId()+","+request.getCreateUserId());
|
|
|
+ record.setUserId(request.getUserId() + "," + request.getCreateUserId());
|
|
|
record.setCreateUserId(request.getCreateUserId());
|
|
|
record.setSessionid(sessionId);
|
|
|
record.setDataTable(3);
|
|
@@ -251,4 +256,17 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResponse batchDelete(Collection ids) {
|
|
|
+ boolean deleteFlag = removeByIds(ids);
|
|
|
+
|
|
|
+ if (deleteFlag){
|
|
|
+ msgService.remove(new QueryWrapper<ChatMsgEntity>().in("session_id",ids));
|
|
|
+ return RestResponse.success(null, "Deleted successfully");
|
|
|
+ } else {
|
|
|
+ return RestResponse.fail("Deleted unsuccessfully");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|