diff --git a/mall-sns/src/main/java/com/suisung/mall/sns/service/impl/SnsUserMessageServiceImpl.java b/mall-sns/src/main/java/com/suisung/mall/sns/service/impl/SnsUserMessageServiceImpl.java index 370e24f4..01c0d622 100644 --- a/mall-sns/src/main/java/com/suisung/mall/sns/service/impl/SnsUserMessageServiceImpl.java +++ b/mall-sns/src/main/java/com/suisung/mall/sns/service/impl/SnsUserMessageServiceImpl.java @@ -37,12 +37,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -57,28 +59,23 @@ import java.util.stream.Collectors; @Service public class SnsUserMessageServiceImpl extends BaseServiceImpl implements SnsUserMessageService { + private static final Logger logger = LoggerFactory.getLogger(SnsUserMessageServiceImpl.class); @Value("${mall.socket.url}") private String MALLSUITE_IM_SOCKETURL; - @Autowired private AccountService accountService; - @Autowired private SnsUserMessageMapper snsUserMessageMapper; - @Autowired private ShopService shopService; - @Autowired private AccountBaseConfigService accountBaseConfigService; - @Autowired private SnsUserFriendService snsUserFriendService; - @Autowired private ImService imService; - - private static Logger logger = LoggerFactory.getLogger(SnsUserMessageServiceImpl.class); + @Autowired + private RedisTemplate redisTemplate; @Override public Map getMsgCount() { @@ -89,26 +86,35 @@ public class SnsUserMessageServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("user_id", user_id).eq("message_kind", 2).eq("message_is_read", 0); + queryWrapper.eq("user_id", userId).eq("message_kind", 2).eq("message_is_read", 0); long num = count(queryWrapper); rs.put("num", num); // 构造最后一个用户聊天网址 if (num > 0) { - QueryWrapper query = new QueryWrapper<>(); - query.orderByAsc("message_is_read").orderByDesc("message_time").eq("user_id", user_id).eq("message_is_read", 0).eq("message_kind", 2); + QueryWrapper messageQuery = new QueryWrapper<>(); + messageQuery.orderByAsc("message_is_read").orderByDesc("message_time") + .eq("user_id", userId).eq("message_is_read", 0).eq("message_kind", 2); Integer recently_flag = getParameter("recently_flag", Integer.class); if (CheckUtil.isNotEmpty(recently_flag)) { long time = new Date().getTime(); - query.gt("message_time", (time - 60 * 5)); + messageQuery.gt("message_time", (time - 60 * 5)); } - SnsUserMessage userMessage = findOne(queryWrapper); + // 修复bug:使用正确的查询条件messageQuery而不是queryWrapper + SnsUserMessage userMessage = findOne(messageQuery); Map msg_row = Convert.toMap(String.class, Object.class, userMessage); if (ObjectUtil.isNotNull(msg_row)) { @@ -116,6 +122,10 @@ public class SnsUserMessageServiceImpl extends BaseServiceImpl user_rows = accountService.getUser(Arrays.asList(user_other_id)); + List user_rows = accountService.getUser(Collections.singletonList(user_other_id)); if (CollUtil.isNotEmpty(user_rows)) { Map user_other_info = user_rows.get(0); @@ -802,10 +812,10 @@ public class SnsUserMessageServiceImpl extends BaseServiceImpl