|
@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.pagehelper.util.StringUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.vo.LifeFansVo;
|
|
|
import shop.alien.entity.store.vo.LifeMessageVo;
|
|
@@ -17,9 +19,11 @@ import shop.alien.mapper.LifeMessageMapper;
|
|
|
import shop.alien.mapper.LifeUserMapper;
|
|
|
import shop.alien.store.service.LifeMessageService;
|
|
|
import shop.alien.store.service.LifeUserService;
|
|
|
+import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -37,43 +41,77 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public IPage<LifeMessageVo> getMessageList(String receiverId, int page, int size, int friendType) {
|
|
|
+ public List<LifeMessageVo> getMessageList(String receiverId, int friendType, String search) {
|
|
|
// 查询所有好友
|
|
|
+// QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
|
|
|
+// wrapper.groupBy("foll.phoneId");
|
|
|
+
|
|
|
+// if ("user".equals(receiverId.split("_")[0])) {
|
|
|
+// String myselfUserPhone = receiverId.split("_")[1];
|
|
|
+// blockerType = "2";
|
|
|
+// LifeUser myLifeUser = lifeUserService.getUserByPhone(myselfUserPhone);
|
|
|
+// blockerId = String.valueOf(myLifeUser.getId());
|
|
|
+// } else {
|
|
|
+// String myselfStorePhone = receiverId.split("_")[1];
|
|
|
+// blockerType = "1";
|
|
|
+// StoreUser myStoreUser = storeUserService.getUserByPhone(myselfStorePhone);
|
|
|
+// blockerId = String.valueOf(myStoreUser.getId());
|
|
|
+// }
|
|
|
+
|
|
|
+// List<LifeFansVo> lifeFansList = lifeFansMapper.getMutualAttention(new Page<>(1, Integer.MAX_VALUE), receiverId, blockerType, blockerId, wrapper).getRecords();
|
|
|
+// List<String> friendsIds = lifeFansList.stream().map(LifeFansVo::getPhoneId).filter(item -> !item.equals(receiverId)).collect(Collectors.toList());
|
|
|
+// String friendsIdsStr = "'" + String.join("','", friendsIds) + "'";
|
|
|
+
|
|
|
+// wrapper = new QueryWrapper<>();
|
|
|
+// wrapper.eq("num", 1);
|
|
|
+// if (1 == friendType) {
|
|
|
+// // 当前用户的所有好友消息
|
|
|
+// wrapper.apply("(sender_id in (" + friendsIdsStr + ") or receiver_id in (" + friendsIdsStr + "))");
|
|
|
+// } else {
|
|
|
+// // 当前用户的所有未关注人消息
|
|
|
+// wrapper.apply("(sender_id not in (" + friendsIdsStr + ") and receiver_id not in (" + friendsIdsStr + "))");
|
|
|
+// }
|
|
|
+
|
|
|
+ String blockerType = "user".equals(Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getString("userType")) ? "2" : "1";
|
|
|
+ String blockerId = JwtUtil.getCurrentUserInfo().getString("userId");
|
|
|
QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.groupBy("foll.phoneId");
|
|
|
- String blockerType = "";
|
|
|
- String blockerId = "";
|
|
|
- if ("user".equals(receiverId.split("_")[0])) {
|
|
|
- String myselfUserPhone = receiverId.split("_")[1];
|
|
|
- blockerType = "2";
|
|
|
- LifeUser myLifeUser = lifeUserService.getUserByPhone(myselfUserPhone);
|
|
|
- blockerId = String.valueOf(myLifeUser.getId());
|
|
|
- } else {
|
|
|
- String myselfStorePhone = receiverId.split("_")[1];
|
|
|
- blockerType = "1";
|
|
|
- StoreUser myStoreUser = storeUserService.getUserByPhone(myselfStorePhone);
|
|
|
- blockerId = String.valueOf(myStoreUser.getId());
|
|
|
+ wrapper.eq("message.num", 1);
|
|
|
+ // 过滤拉黑
|
|
|
+ wrapper.apply("(user.id not in ( " +
|
|
|
+ " select blocked_id from life_blacklist " +
|
|
|
+ " where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '2' and delete_flag = 0 " +
|
|
|
+ ") or user.id is null)");
|
|
|
+ wrapper.apply("(suser.id not in ( " +
|
|
|
+ " select blocked_id from life_blacklist " +
|
|
|
+ " where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '1' and delete_flag = 0 " +
|
|
|
+ ") or suser.id is null)");
|
|
|
+
|
|
|
+ // 通过搜索查询的情况下 不区分是否聊过 搜索所有消息
|
|
|
+ if (0 == friendType && StringUtil.isNotEmpty(search)) {
|
|
|
+ wrapper.apply("(user.user_name like '%" + search + "%' or suser.name like '%" + search + "%')");
|
|
|
+ // 聊过
|
|
|
+ } else if (1 == friendType) {
|
|
|
+ wrapper.apply("message.phoneId in ( " +
|
|
|
+ " select receiver_id " +
|
|
|
+ " from life_message " +
|
|
|
+ " where sender_id = '" + receiverId + "'" +
|
|
|
+ " group by receiver_id " +
|
|
|
+ ")");
|
|
|
+ // 没聊过
|
|
|
+ } else if (2 == friendType) {
|
|
|
+ wrapper.apply("message.phoneId not in ( " +
|
|
|
+ " select receiver_id " +
|
|
|
+ " from life_message " +
|
|
|
+ " where sender_id = '" + receiverId + "'" +
|
|
|
+ " group by receiver_id " +
|
|
|
+ ")");
|
|
|
}
|
|
|
-
|
|
|
- List<LifeFansVo> lifeFansList = lifeFansMapper.getMutualAttention(new Page<>(1, Integer.MAX_VALUE), receiverId, blockerType, blockerId, wrapper).getRecords();
|
|
|
- List<String> friendsIds = lifeFansList.stream().map(LifeFansVo::getPhoneId).filter(item -> !item.equals(receiverId)).collect(Collectors.toList());
|
|
|
- String friendsIdsStr = "'" + String.join("','", friendsIds) + "'";
|
|
|
-
|
|
|
- wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("num", 1);
|
|
|
- if (1 == friendType) {
|
|
|
- // 当前用户的所有好友消息
|
|
|
- wrapper.apply("(sender_id in (" + friendsIdsStr + ") or receiver_id in (" + friendsIdsStr + "))");
|
|
|
- } else {
|
|
|
- // 当前用户的所有未关注人消息
|
|
|
- wrapper.apply("(sender_id not in (" + friendsIdsStr + ") and receiver_id not in (" + friendsIdsStr + "))");
|
|
|
- }
|
|
|
- wrapper.orderByDesc("created_time");
|
|
|
- IPage<LifeMessageVo> ipage = new Page<>(page, size);
|
|
|
- IPage<LifeMessageVo> lifeMessagePageList = messageMapper.getLifeMessagePageByPhoneId(ipage, receiverId, wrapper);
|
|
|
- if (!CollectionUtils.isEmpty(lifeMessagePageList.getRecords())) {
|
|
|
+ wrapper.orderByDesc("message.created_time");
|
|
|
+// IPage<LifeMessageVo> ipage = new Page<>(page, size);
|
|
|
+ List<LifeMessageVo> lifeMessagePageList = messageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(lifeMessagePageList)) {
|
|
|
// 取出所有发送消息的用户
|
|
|
- List<String> phoneIdList = lifeMessagePageList.getRecords().stream().map(LifeMessageVo::getPhoneId).filter(item -> item.contains("_")).collect(Collectors.toList());
|
|
|
+// List<String> phoneIdList = lifeMessagePageList.stream().map(LifeMessageVo::getPhoneId).filter(item -> item.contains("_")).collect(Collectors.toList());
|
|
|
|
|
|
// 当前用户的所有关注
|
|
|
LambdaQueryWrapper<LifeFans> followWrapper = new LambdaQueryWrapper<>();
|
|
@@ -97,18 +135,18 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
messageWrapper.eq(LifeMessage::getDeleteFlag, 0);
|
|
|
List<LifeMessage> noReadList = messageMapper.selectList(messageWrapper);
|
|
|
|
|
|
- // 根据手机号查询发送人信息
|
|
|
- List<String> storePhoneList = phoneIdList.stream().filter(item -> "store".equals(item.split("_")[0])).map(item -> item.split("_")[1]).collect(Collectors.toList());
|
|
|
- List<String> userPhoneList = phoneIdList.stream().filter(item -> "user".equals(item.split("_")[0])).map(item -> item.split("_")[1]).collect(Collectors.toList());
|
|
|
- String storePhones = "'" + String.join("','", storePhoneList) + "'";
|
|
|
- String userPhones = "'" + String.join("','", userPhoneList) + "'";
|
|
|
- List<LifeMessageVo> userList = messageMapper.getLifeUserAndStoreUserByPhone(storePhones, userPhones);
|
|
|
+// // 根据手机号查询发送人信息
|
|
|
+// List<String> storePhoneList = phoneIdList.stream().filter(item -> "store".equals(item.split("_")[0])).map(item -> item.split("_")[1]).collect(Collectors.toList());
|
|
|
+// List<String> userPhoneList = phoneIdList.stream().filter(item -> "user".equals(item.split("_")[0])).map(item -> item.split("_")[1]).collect(Collectors.toList());
|
|
|
+// String storePhones = "'" + String.join("','", storePhoneList) + "'";
|
|
|
+// String userPhones = "'" + String.join("','", userPhoneList) + "'";
|
|
|
+// List<LifeMessageVo> userList = messageMapper.getLifeUserAndStoreUserByPhone(storePhones, userPhones);
|
|
|
|
|
|
- for (LifeMessageVo messageVo : lifeMessagePageList.getRecords()) {
|
|
|
- // 发送人信息
|
|
|
- LifeMessageVo user = userList.stream().filter(item -> item.getPhoneId().equals(messageVo.getPhoneId())).findFirst().orElse(null);
|
|
|
- messageVo.setUserName(null == user ? "" : user.getUserName());
|
|
|
- messageVo.setUserImage(null == user ? "" : user.getUserImage());
|
|
|
+ for (LifeMessageVo messageVo : lifeMessagePageList) {
|
|
|
+// // 发送人信息
|
|
|
+// LifeMessageVo user = userList.stream().filter(item -> item.getPhoneId().equals(messageVo.getPhoneId())).findFirst().orElse(null);
|
|
|
+// messageVo.setUserName(null == user ? "" : user.getUserName());
|
|
|
+// messageVo.setUserImage(null == user ? "" : user.getUserImage());
|
|
|
|
|
|
// 未读消息数量
|
|
|
messageVo.setNotReadCount(noReadList.stream().filter(item -> item.getSenderId().equals(messageVo.getPhoneId())).count());
|
|
@@ -137,11 +175,43 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
return lifeMessagePageList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public LifeMessageVo getStrangerMessageNum(String receiverId) {
|
|
|
+ String blockerType = "user".equals(Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getString("userType")) ? "2" : "1";
|
|
|
+ String blockerId = JwtUtil.getCurrentUserInfo().getString("userId");
|
|
|
+ QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
|
|
|
+ // 过滤拉黑
|
|
|
+ wrapper.apply("(user.id not in ( " +
|
|
|
+ " select blocked_id from life_blacklist " +
|
|
|
+ " where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '2' and delete_flag = 0 " +
|
|
|
+ ") or user.id is null)");
|
|
|
+ wrapper.apply("(suser.id not in ( " +
|
|
|
+ " select blocked_id from life_blacklist " +
|
|
|
+ " where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '1' and delete_flag = 0 " +
|
|
|
+ ") or suser.id is null)");
|
|
|
+ // 没聊过
|
|
|
+ wrapper.apply("message.phoneId not in ( " +
|
|
|
+ " select receiver_id " +
|
|
|
+ " from life_message " +
|
|
|
+ " where sender_id = '" + receiverId + "'" +
|
|
|
+ " group by receiver_id " +
|
|
|
+ ")");
|
|
|
+ wrapper.orderByDesc("message.created_time");
|
|
|
+// IPage<LifeMessageVo> ipage = new Page<>(1, Integer.MAX_VALUE);
|
|
|
+ List<LifeMessageVo> lifeMessagePageList = messageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
|
|
|
+ LifeMessageVo vo = new LifeMessageVo();
|
|
|
+ if (!CollectionUtils.isEmpty(lifeMessagePageList)) {
|
|
|
+ vo.setUserName(lifeMessagePageList.get(0).getUserName());
|
|
|
+ vo.setNotReadCount(lifeMessagePageList.stream().filter(item -> 0 == item.getIsRead()).count());
|
|
|
+ }
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public LifeMessageVo getNoFriendMessageNum(String receiverId) {
|
|
|
// 查询所有好友
|
|
|
QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
|
|
@@ -169,8 +239,8 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
wrapper.eq("num", 1);
|
|
|
wrapper.apply("(sender_id not in (" + friendsIdsStr + ") and receiver_id not in (" + friendsIdsStr + "))");
|
|
|
wrapper.orderByDesc("created_time");
|
|
|
- IPage<LifeMessageVo> ipage = new Page<>(1, Integer.MAX_VALUE);
|
|
|
- List<LifeMessageVo> lifeMessageVoList = messageMapper.getLifeMessagePageByPhoneId(ipage, receiverId, wrapper).getRecords();
|
|
|
+// IPage<LifeMessageVo> ipage = new Page<>(1, Integer.MAX_VALUE);
|
|
|
+ List<LifeMessageVo> lifeMessageVoList = messageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
|
|
|
|
|
|
LifeMessageVo messageVo = lifeMessageVoList.stream().max(Comparator.comparing(LifeMessageVo::getCreatedTime)).orElse(null);
|
|
|
if (messageVo != null) {
|
|
@@ -276,4 +346,9 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
public int deleteMessageByPhoneId(String senderId, String receiverId) {
|
|
|
return messageMapper.deleteMessageByPhoneId(senderId, receiverId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean notDisturb(String receiverId, int disturbId, int type) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|