|
@@ -1,38 +1,37 @@
|
|
|
package cn.com.ty.lift.ud.chat.service.impl;
|
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneOffset;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
import cn.com.ty.lift.common.model.PushMessage;
|
|
|
import cn.com.ty.lift.common.model.PushUserInfo;
|
|
|
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.ChatSessionEntity;
|
|
|
+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;
|
|
|
import cn.com.ty.lift.ud.redis.RedisUtil;
|
|
|
+import cn.com.ty.lift.ud.userAccount.service.IUserAccountService;
|
|
|
+import cn.com.ty.lift.ud.userInfo.mapper.UserInfoMapper;
|
|
|
+import cn.com.ty.lift.ud.userInfo.mapper.entity.UserInfoEntity;
|
|
|
+import cn.com.ty.lift.ud.utils.UUIDUtil;
|
|
|
+import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jms.core.JmsMessagingTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-
|
|
|
-import cn.com.ty.lift.ud.chat.mapper.ChatSessionMapper;
|
|
|
-import cn.com.ty.lift.ud.chat.mapper.entity.ChatSessionEntity;
|
|
|
-import cn.com.ty.lift.ud.chat.service.IChatSessionService;
|
|
|
-import cn.com.ty.lift.ud.userAccount.service.IUserAccountService;
|
|
|
-import cn.com.ty.lift.ud.userInfo.mapper.UserInfoMapper;
|
|
|
-import cn.com.ty.lift.ud.userInfo.mapper.entity.UserInfoEntity;
|
|
|
-import cn.com.ty.lift.ud.utils.UUIDUtil;
|
|
|
-import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import java.lang.reflect.Array;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* 会话 -ServiceImpl
|
|
@@ -43,15 +42,19 @@ import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatSessionEntity>
|
|
|
- implements IChatSessionService {
|
|
|
+ implements IChatSessionService {
|
|
|
|
|
|
- private @Autowired ChatSessionMapper sessionMapper;
|
|
|
-
|
|
|
- private @Autowired IUserAccountService iUserAccountService;
|
|
|
-
|
|
|
- private @Autowired UserInfoMapper userInfoMapper;
|
|
|
+ private @Autowired
|
|
|
+ ChatSessionMapper sessionMapper;
|
|
|
|
|
|
- private @Autowired RedisUtil redis;
|
|
|
+ private @Autowired
|
|
|
+ IUserAccountService iUserAccountService;
|
|
|
+
|
|
|
+ private @Autowired
|
|
|
+ UserInfoMapper userInfoMapper;
|
|
|
+
|
|
|
+ private @Autowired
|
|
|
+ RedisUtil redis;
|
|
|
|
|
|
@Autowired
|
|
|
private JmsMessagingTemplate jmsMessagingTemplate;
|
|
@@ -78,7 +81,7 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
@Override
|
|
|
public RestResponse batchUpdate(ChatSessionReq req) {
|
|
|
List<String> sessionList = new ArrayList<>();
|
|
|
- for(Long id :req.getIds()) {
|
|
|
+ for (Long id : req.getIds()) {
|
|
|
ChatSessionEntity selectById = sessionMapper.selectById(id);
|
|
|
sessionList.add(selectById.getSessionid());
|
|
|
}
|
|
@@ -130,12 +133,16 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
public RestResponse findDBListByUserId(ChatSessionQuery query) {
|
|
|
IPage page = query.page();
|
|
|
List<ChatSessionEntity> list = sessionMapper.findDBListByUserId(query.getUserId());
|
|
|
- Set<String> keys = redis.keys("ROOM:");
|
|
|
+ list.forEach(entity -> {
|
|
|
+ RoomInfo roomInfo = redis.get("ROOM:" + entity.getSessionid(), RoomInfo.class);
|
|
|
+ entity.setLastMsg(roomInfo.getLastChat());
|
|
|
+ entity.setLastTime(roomInfo.getLastTime());
|
|
|
+ });
|
|
|
+ Collections.sort(list, (ent1, ent2) -> ent2.getLastTime().compareTo(ent1.getLastTime()));
|
|
|
|
|
|
page.setRecords(list);
|
|
|
return RestResponse.success(page);
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
/**
|
|
|
* 系统启动的时候加载放假及用户信息
|
|
@@ -171,7 +178,7 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
record.setStatuz(1);
|
|
|
record.setCreateTime(LocalDateTime.now());
|
|
|
sessionMapper.insertSelective(record);
|
|
|
-
|
|
|
+
|
|
|
vo.setType(1);
|
|
|
vo.setRoom(sessionId);
|
|
|
//在redis中创建房间
|
|
@@ -189,26 +196,26 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
|
|
|
userList.add(userInfo2);
|
|
|
|
|
|
roomInfo.setUserLIst(userList);
|
|
|
- redis.setValue("ROOM:"+vo.getRoom(),roomInfo);
|
|
|
+ redis.setValue("ROOM:" + vo.getRoom(), roomInfo);
|
|
|
} else {
|
|
|
vo.setType(2);
|
|
|
vo.setRoom(sessionId);
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 推送消息
|
|
|
+ // 推送消息
|
|
|
UserInfoEntity byUserId = userInfoMapper.getByUserId(Long.parseLong(request.getUserId()));
|
|
|
PushUserInfo pushUserInfo = iUserAccountService.getPushUserInfoByUserId(request.getCreateUserId().toString());
|
|
|
PushMessage pushMessage = PushMessage.sayHelloToFriend(byUserId.getName());
|
|
|
pushMessage.sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfo);
|
|
|
-
|
|
|
+
|
|
|
return RestResponse.success(vo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<ChatSessionEntity> findListBySessionId(String sessionid) {
|
|
|
QueryWrapper query = new QueryWrapper();
|
|
|
- query.eq("sessionid",sessionid);
|
|
|
+ query.eq("sessionid", sessionid);
|
|
|
List list = list(query);
|
|
|
|
|
|
return list;
|