Commit 3636b0f5 authored by shiyu's avatar shiyu

新增粉丝头像

parent 473ce221
...@@ -3,6 +3,7 @@ package com.wwdz.ch.core.util; ...@@ -3,6 +3,7 @@ package com.wwdz.ch.core.util;
import com.github.benmanes.caffeine.cache.AsyncLoadingCache; import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import com.wwdz.ch.db.dao.CategoryDao; import com.wwdz.ch.db.dao.CategoryDao;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.dao.dts.DtsAdminDao; import com.wwdz.ch.db.dao.dts.DtsAdminDao;
import com.wwdz.ch.db.dao.dts.DtsUserDao; import com.wwdz.ch.db.dao.dts.DtsUserDao;
import com.wwdz.ch.db.domain.Admin; import com.wwdz.ch.db.domain.Admin;
...@@ -12,10 +13,12 @@ import com.wwdz.ch.db.dto.request.CategorySearchRequestDto; ...@@ -12,10 +13,12 @@ import com.wwdz.ch.db.dto.request.CategorySearchRequestDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
...@@ -30,6 +33,9 @@ public class CacheUtil { ...@@ -30,6 +33,9 @@ public class CacheUtil {
@Autowired @Autowired
CategoryDao categoryDao; CategoryDao categoryDao;
@Autowired
UserDao userDao;
public String getAppletUserNameById(long key) { public String getAppletUserNameById(long key) {
try { try {
...@@ -40,6 +46,17 @@ public class CacheUtil { ...@@ -40,6 +46,17 @@ public class CacheUtil {
return null; return null;
} }
public User getAppletUserById(long key) {
try {
return appletUserInfoCache.get(key).get(3, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
return new User();
}
public String getSystemUserNameById(int key) { public String getSystemUserNameById(int key) {
try { try {
return systemUserCache.get(key).get(5, TimeUnit.SECONDS); return systemUserCache.get(key).get(5, TimeUnit.SECONDS);
...@@ -59,6 +76,15 @@ public class CacheUtil { ...@@ -59,6 +76,15 @@ public class CacheUtil {
.buildAsync(k -> getAppletUserList(k)); .buildAsync(k -> getAppletUserList(k));
/**
* 小程序会员缓存
*/
public AsyncLoadingCache<Long, User> appletUserInfoCache = Caffeine.newBuilder()
.maximumSize(5000)
.expireAfterWrite(30, TimeUnit.MINUTES)
.buildAsync(k -> getAppletUsers(k));
/** /**
* 后台用户缓存 * 后台用户缓存
*/ */
...@@ -80,6 +106,17 @@ public class CacheUtil { ...@@ -80,6 +106,17 @@ public class CacheUtil {
} }
/**
* 查询小程序会员
* @return
*/
public User getAppletUsers(long key) {
List<User> userList = dtsUserDao.findAll();
Map<Long, User> map = userList.stream().collect(Collectors.toMap(User::getId, Function.identity(), (k1, k2) -> k2));
return map.get(key);
}
/** /**
* 查询后台用户 * 查询后台用户
* *
......
...@@ -17,6 +17,11 @@ public class FollowFansRecordVo implements Entity { ...@@ -17,6 +17,11 @@ public class FollowFansRecordVo implements Entity {
private String fansName; private String fansName;
/**
* 粉丝头像
*/
private String fansIcon;
/** /**
* 被关注者id * 被关注者id
*/ */
...@@ -24,6 +29,11 @@ public class FollowFansRecordVo implements Entity { ...@@ -24,6 +29,11 @@ public class FollowFansRecordVo implements Entity {
private String followerName; private String followerName;
/**
* 关注人头像
*/
private String followerIcon;
/** /**
* 关系(已关注,互相关注, 回关) * 关系(已关注,互相关注, 回关)
*/ */
......
...@@ -18,6 +18,11 @@ public class MessageVo implements Entity { ...@@ -18,6 +18,11 @@ public class MessageVo implements Entity {
private String senderName; private String senderName;
/**
* 发送者头像
*/
private String senderIcon;
/** /**
* 消息类型 * 消息类型
*/ */
......
...@@ -126,7 +126,8 @@ public class FollowFansRecordServiceImpl implements FollowFansRecordService { ...@@ -126,7 +126,8 @@ public class FollowFansRecordServiceImpl implements FollowFansRecordService {
followFansRecordList.forEach(f -> { followFansRecordList.forEach(f -> {
FollowFansRecordVo followFansRecordVo = new FollowFansRecordVo(); FollowFansRecordVo followFansRecordVo = new FollowFansRecordVo();
EntityMapper.copyAttribute(f, followFansRecordVo); EntityMapper.copyAttribute(f, followFansRecordVo);
followFansRecordVo.setFollowerName(cacheUtil.getAppletUserNameById(f.getFansId())); followFansRecordVo.setFollowerName(cacheUtil.getAppletUserNameById(f.getFollowerId()));
followFansRecordVo.setFollowerIcon(cacheUtil.getAppletUsers(f.getFollowerId()).getAvatar());
if (fansIdList.contains(f.getFollowerId().longValue())) { if (fansIdList.contains(f.getFollowerId().longValue())) {
followFansRecordVo.setRelation("互相关注"); followFansRecordVo.setRelation("互相关注");
} else { } else {
...@@ -161,6 +162,7 @@ public class FollowFansRecordServiceImpl implements FollowFansRecordService { ...@@ -161,6 +162,7 @@ public class FollowFansRecordServiceImpl implements FollowFansRecordService {
FollowFansRecordVo followFansRecordVo = new FollowFansRecordVo(); FollowFansRecordVo followFansRecordVo = new FollowFansRecordVo();
EntityMapper.copyAttribute(f, followFansRecordVo); EntityMapper.copyAttribute(f, followFansRecordVo);
followFansRecordVo.setFansName(cacheUtil.getAppletUserNameById(f.getFansId())); followFansRecordVo.setFansName(cacheUtil.getAppletUserNameById(f.getFansId()));
followFansRecordVo.setFansIcon(cacheUtil.getAppletUsers(f.getFansId()).getAvatar());
if (followerIdList.contains(f.getFansId().longValue())) { if (followerIdList.contains(f.getFansId().longValue())) {
followFansRecordVo.setRelation("互相关注"); followFansRecordVo.setRelation("互相关注");
} else { } else {
......
...@@ -111,8 +111,10 @@ public class MessageServiceImpl implements MessageService { ...@@ -111,8 +111,10 @@ public class MessageServiceImpl implements MessageService {
MessageVo messageVo = new MessageVo(); MessageVo messageVo = new MessageVo();
messageVo.setMessageRecordId(m.getId()); messageVo.setMessageRecordId(m.getId());
messageVo.setMessageId(m.getMessageId()); messageVo.setMessageId(m.getMessageId());
messageVo.setSenderId(messageContentMap.get(m.getMessageId()).getSenderId()); messageVo.setSenderId(messageContentMap.get(m.getMessageId()).getSenderId());
messageVo.setSenderName(cacheUtil.getAppletUserNameById(messageContentMap.get(m.getMessageId()).getSenderId())); messageVo.setSenderName(cacheUtil.getAppletUserNameById(messageContentMap.get(m.getMessageId()).getSenderId()));
messageVo.setSenderIcon(cacheUtil.getAppletUsers(messageContentMap.get(m.getMessageId()).getSenderId()).getAvatar());
messageVo.setReceiverId(m.getReceiverId()); messageVo.setReceiverId(m.getReceiverId());
messageVo.setReceiverName(cacheUtil.getAppletUserNameById(m.getReceiverId())); messageVo.setReceiverName(cacheUtil.getAppletUserNameById(m.getReceiverId()));
messageVo.setType(m.getType()); messageVo.setType(m.getType());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment