diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/ResiGroupMemberDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/ResiGroupMemberDTO.java index e50dc83a5f..49de542902 100644 --- a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/ResiGroupMemberDTO.java +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/ResiGroupMemberDTO.java @@ -98,4 +98,8 @@ public class ResiGroupMemberDTO implements Serializable { */ private String updatedBy; + /** + * 客户Id + * */ + private String customerId; } diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/result/ResiGroupMemberInfoRedisResultDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/result/ResiGroupMemberInfoRedisResultDTO.java new file mode 100644 index 0000000000..83d9709518 --- /dev/null +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/result/ResiGroupMemberInfoRedisResultDTO.java @@ -0,0 +1,30 @@ +package com.epmet.resi.group.dto.member.result; + +import com.epmet.resi.group.dto.member.ResiGroupMemberInfoRedisDTO; +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; +import java.util.Set; + +/** + * @Description + * @ClassName ResiGroupMemberInfoRedisResultDTO + * @Author wangc + * @date 2020.04.14 00:21 + */ +@Data +public class ResiGroupMemberInfoRedisResultDTO implements Serializable { + private static final long serialVersionUID = -1L; + + /** + * 该组内所有成员的key + * + * */ + private Set memberKeys; + + /** + * 该组内所有成员的信息 + * */ + private Map memberMap; +} diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/feign/EpmetUserFeignClient.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/feign/EpmetUserFeignClient.java index 72c34fedcb..575d610516 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/feign/EpmetUserFeignClient.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/feign/EpmetUserFeignClient.java @@ -21,7 +21,7 @@ import java.util.List; * @Author yinzuomei * @Date 2020/3/16 14:48 */ -@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallback = EpmetUserFeignClientFallback.class,url="http://localhost:8087") +@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallback = EpmetUserFeignClientFallback.class) public interface EpmetUserFeignClient { /** diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/redis/ResiGroupRedis.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/redis/ResiGroupRedis.java index a04d51a70d..12d4ab4d7a 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/redis/ResiGroupRedis.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/redis/ResiGroupRedis.java @@ -51,7 +51,12 @@ public class ResiGroupRedis { } } - public String get(String id){ + public ResiGroupInfoRedisDTO get(String groupId){ + if(StringUtils.isNotBlank(groupId)){ + ResiGroupInfoRedisDTO groupCache = (ResiGroupInfoRedisDTO) + redisUtils.get(RedisKeys.getResiGroupInfoKey(groupId)); + return groupCache; + } return null; } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java index bbd1376a9c..4998d0fedd 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ResiGroupServiceImpl.java @@ -474,7 +474,7 @@ public class ResiGroupServiceImpl extends BaseServiceImpl map = redisUtils.hGetAll(RedisKeys.getResiGroupMemberInfoKey(groupId,userId)); + if (MapUtil.isEmpty(map)) { + return null; + } + //map to bean + ResiGroupMemberInfoRedisDTO member = BeanUtil.mapToBean(map, ResiGroupMemberInfoRedisDTO.class, true); + return member; } + /** + * @Description 得到一个组中所有成员的信息 + * @Param groupId + * @return + * @Author wangc + * @Date 2020.04.14 00:13 + **/ + public ResiGroupMemberInfoRedisResultDTO getKeys(String groupId){ + Set groupMemberKeys = + redisUtils.keys(RedisKeys.getResiGroupMemberInfoKey(groupId,"*")); + Map memberMap = new HashMap<>(NumConstant.ONE_HUNDRED); + for(String key : groupMemberKeys){ + ResiGroupMemberInfoRedisDTO member = (ResiGroupMemberInfoRedisDTO)redisUtils.get(key); + if(null != member){ + memberMap.put(member.getUserId(),member); + } + } + ResiGroupMemberInfoRedisResultDTO result = new ResiGroupMemberInfoRedisResultDTO(); + result.setMemberKeys(groupMemberKeys); + result.setMemberMap(memberMap); + return result; + } } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/service/impl/ResiGroupMemberServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/service/impl/ResiGroupMemberServiceImpl.java index c262320f1e..368a02d517 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/service/impl/ResiGroupMemberServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/service/impl/ResiGroupMemberServiceImpl.java @@ -29,8 +29,8 @@ import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.ReadFlagConstant; -import com.epmet.dto.UserMessageDTO; import com.epmet.dto.form.UserMessageFormDTO; +import com.epmet.dto.form.UserResiInfoFormDTO; import com.epmet.dto.form.UserResiInfoListFormDTO; import com.epmet.dto.result.UserResiInfoResultDTO; import com.epmet.feign.MessageFeignClient; @@ -39,10 +39,12 @@ import com.epmet.modules.constant.UserMessageConstant; import com.epmet.modules.exception.ModuleErrorCode; import com.epmet.modules.feign.EpmetUserFeignClient; import com.epmet.modules.group.entity.ResiGroupEntity; +import com.epmet.modules.group.redis.ResiGroupRedis; import com.epmet.modules.group.service.ResiGroupService; import com.epmet.modules.group.service.ResiGroupStatisticalService; import com.epmet.modules.member.dao.ResiGroupMemberDao; import com.epmet.modules.member.entity.ResiGroupMemberEntity; +import com.epmet.modules.member.redis.ResiGroupMemberRedis; import com.epmet.modules.member.service.GroupMemeberOperationService; import com.epmet.modules.member.service.ResiGroupMemberService; import com.epmet.modules.topic.service.ResiTopicService; @@ -54,6 +56,7 @@ import com.epmet.resi.group.dto.UserRoleDTO; import com.epmet.resi.group.dto.group.ResiGroupDTO; import com.epmet.resi.group.dto.member.GroupMemeberOperationDTO; import com.epmet.resi.group.dto.member.ResiGroupMemberDTO; +import com.epmet.resi.group.dto.member.ResiGroupMemberInfoRedisDTO; import com.epmet.resi.group.dto.member.form.*; import com.epmet.resi.group.dto.member.result.ApplyingMemberResultDTO; import com.epmet.resi.group.dto.member.result.GroupMemberListResultDTO; @@ -99,6 +102,12 @@ public class ResiGroupMemberServiceImpl extends BaseServiceImpl page(Map params) { IPage page = baseDao.selectPage( @@ -334,6 +343,12 @@ public class ResiGroupMemberServiceImpl extends BaseServiceImpl result = epmetUserFeignClient.getUserResiInfoDTO(resiInfoParam); + if(result.success() && null != result.getData()){ + targetObject.setUserHeadPhoto(result.getData().getHeadPhoto()); + targetObject.setUserShowName(result.getData().getShowName()); + } + return targetObject; + } + } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java index 2b7898551b..1c43e81890 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/topic/service/impl/ResiTopicServiceImpl.java @@ -25,7 +25,7 @@ import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; -import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; @@ -40,9 +40,9 @@ import com.epmet.modules.group.entity.ResiGroupEntity; import com.epmet.modules.group.entity.ResiGroupStatisticalEntity; import com.epmet.modules.member.dao.ResiGroupMemberDao; import com.epmet.modules.member.entity.ResiGroupMemberEntity; +import com.epmet.modules.member.redis.ResiGroupMemberRedis; import com.epmet.modules.member.service.ResiGroupMemberService; import com.epmet.modules.topic.dao.ResiTopicAttachmentDao; -import com.epmet.modules.topic.dao.ResiTopicCommentDao; import com.epmet.modules.topic.dao.ResiTopicDao; import com.epmet.modules.topic.dao.ResiTopicOperationDao; import com.epmet.modules.topic.entity.ResiTopicAttachmentEntity; @@ -54,7 +54,9 @@ import com.epmet.modules.utils.ModuleConstant; import com.epmet.resi.group.constant.MemberStateConstant; import com.epmet.resi.group.constant.TopicConstant; import com.epmet.resi.group.dto.member.ResiGroupMemberDTO; +import com.epmet.resi.group.dto.member.ResiGroupMemberInfoRedisDTO; import com.epmet.resi.group.dto.member.form.RemoveMemberFormDTO; +import com.epmet.resi.group.dto.member.result.ResiGroupMemberInfoRedisResultDTO; import com.epmet.resi.group.dto.topic.ResiTopicDTO; import com.epmet.resi.group.dto.topic.form.ResiTopicOperationFormDTO; import com.epmet.resi.group.dto.topic.form.ResiTopicPageFormDTO; @@ -70,6 +72,7 @@ import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; /** * 话题信息表 @@ -89,9 +92,6 @@ public class ResiTopicServiceImpl extends BaseServiceImpl 0) { - //2.遍历存储用户信息 - List userIdList = new ArrayList<>(); + //2.遍历存储用户信息 从数据库中查找 + /*List userIdList = new ArrayList<>(); for (ResiTopicInfoResultDTO topic : lastestTenTopics) { userIdList.add(topic.getUserId()); } @@ -290,6 +290,10 @@ public class ResiTopicServiceImpl extends BaseServiceImpl> userResiInfoDTOListResult = epmetUserFeignClient.getUserResiInfoList(formDTO); setUserInfo(userResiInfoDTOListResult, lastestTenTopics); + */ + + //2.2从缓存中查找用户信息 + setCacheUserInfo(groupId,lastestTenTopics); } return new Result>().ok(lastestTenTopics); } @@ -321,7 +325,8 @@ public class ResiTopicServiceImpl extends BaseServiceImpl 0) { - //2.遍历用户信息 + /* + //2.遍历用户信息 List userIdList = new ArrayList<>(); for (ResiTopicInfoResultDTO topic : pastTopics) { userIdList.add(topic.getUserId()); @@ -330,7 +335,12 @@ public class ResiTopicServiceImpl extends BaseServiceImpl> userResiInfoDTOListResult = epmetUserFeignClient.getUserResiInfoList(formDTO); setUserInfo(userResiInfoDTOListResult, pastTopics); - } + + */ + + //2.2 在缓存中拉取用户信息 + setCacheUserInfo(topicPageFormDTO.getGroupId(), pastTopics); + } return new Result>().ok(pastTopics); } @@ -513,24 +523,53 @@ public class ResiTopicServiceImpl extends BaseServiceImpl userInfo = epmetUserFeignClient.getUserResiInfoDTO(userParam); - if(userInfo.success()){ - if(null != userInfo.getData()){ - resultDTO.setReleaseUserName(userInfo.getData().getShowName()); - resultDTO.setReleaseUserHeadPhoto(userInfo.getData().getHeadPhoto()); - } - + ResiGroupMemberInfoRedisDTO memberRedis = + resiGroupMemberRedis.get(group.getId(),topic.getCreatedBy()); + if(null != memberRedis && StringUtils.isNotBlank(memberRedis.getUserId())){ + resultDTO.setReleaseUserName(memberRedis.getUserShowName()); + resultDTO.setReleaseUserHeadPhoto(memberRedis.getUserHeadPhoto()); }else{ - logger.warn(ModuleConstant.USER_INFO_LIST_NOT_FOUND); + logger.warn(ModuleConstant.GROUP_MEMBER_NOT_EXISTS_IN_CACHE); + + UserResiInfoFormDTO userParam = new UserResiInfoFormDTO(); + userParam.setUserId(topic.getCreatedBy()); + userParam.setCustomerId(group.getCustomerId()); + Result userInfo = epmetUserFeignClient.getUserResiInfoDTO(userParam); + if(userInfo.success()){ + if(null != userInfo.getData()){ + resultDTO.setReleaseUserName(userInfo.getData().getShowName()); + resultDTO.setReleaseUserHeadPhoto(userInfo.getData().getHeadPhoto()); + + ResiGroupMemberInfoRedisDTO memberRedisDTO = new ResiGroupMemberInfoRedisDTO(); + ResiGroupMemberDTO memberMySql = resiGroupMemberDao.selectGroupMemberInfo(group.getId(), userInfo.getData().getUserId()); + + memberRedisDTO.setUserId(userInfo.getData().getUserId()); + memberRedisDTO.setUserHeadPhoto(userInfo.getData().getHeadPhoto()); + memberRedisDTO.setUserShowName(userInfo.getData().getShowName()); + + memberRedisDTO.setEnterGroupType(memberMySql.getEnterGroupType()); + memberRedisDTO.setGroupLeaderFlag(memberMySql.getGroupLeaderFlag()); + memberRedisDTO.setMemberStatus(memberMySql.getStatus()); + + memberRedisDTO.setGroupId(group.getId()); + resiGroupMemberRedis.set(memberRedisDTO); + } + + }else{ + logger.warn(ModuleConstant.USER_INFO_LIST_NOT_FOUND); + } } + + + + return new Result().ok(resultDTO); } @@ -556,14 +595,16 @@ public class ResiTopicServiceImpl extends BaseServiceImpl 0) { - List userIdList = new ArrayList<>(); + /*List userIdList = new ArrayList<>(); for (ResiTopicInfoResultDTO topic : hiddenTopics) { userIdList.add(topic.getUserId()); } UserResiInfoListFormDTO formDTO = new UserResiInfoListFormDTO(); formDTO.setUserIdList(userIdList); Result> userResiInfoDTOListResult = epmetUserFeignClient.getUserResiInfoList(formDTO); - setUserInfo(userResiInfoDTOListResult, hiddenTopics); + setUserInfo(userResiInfoDTOListResult, hiddenTopics);*/ + + setCacheUserInfo(topicPageFormDTO.getGroupId(), hiddenTopics); } return new Result>().ok(hiddenTopics); @@ -636,7 +677,7 @@ public class ResiTopicServiceImpl extends BaseServiceImpl> userResiInfoDTOListResult,List topics){ + private void setUserInfo(Result> userResiInfoDTOListResult,List topics){ if(userResiInfoDTOListResult.success() && null != userResiInfoDTOListResult.getData()){ if(userResiInfoDTOListResult.getData().size() > 0){ for(UserResiInfoResultDTO resiUser : userResiInfoDTOListResult.getData()){ @@ -691,4 +732,75 @@ public class ResiTopicServiceImpl extends BaseServiceImpl + * @return void + * @Author wangc + * @Date 2020.04.14 10:32 + **/ + private void setCacheUserInfo(String groupId ,List topics) { + + //1.初始化存储缺失缓存信息的组员Id的容器,默认去重 + Set usersNotInCache = new HashSet<>(); + + //2.读取用户缓存信息 + ResiGroupMemberInfoRedisResultDTO memberRedis = resiGroupMemberRedis.getKeys(groupId); + if (null != memberRedis && null != memberRedis.getMemberKeys() && null != memberRedis.getMemberMap()) { + String keyPrefix = RedisKeys.getResiGroupMemberInfoKey(groupId, ""); + for (ResiTopicInfoResultDTO topic : topics) { + //缓存中有该用户的key + if (memberRedis.getMemberKeys().contains(keyPrefix.concat(topic.getUserId()))) { + ResiGroupMemberInfoRedisDTO memberInfoCache = memberRedis.getMemberMap().get(topic.getUserId()); + if (null != memberInfoCache) { + //缓存中有该用户信息 + topic.setReleaseUserName(memberInfoCache.getUserShowName()); + topic.setReleaseUserHeadPhoto(memberInfoCache.getUserHeadPhoto()); + } else { + //缓存中没有该用户信息 + usersNotInCache.add(topic.getUserId()); + } + } else { + //缓存中没有该用户的key + usersNotInCache.add(topic.getUserId()); + } + } + } + + //3.如果存在缺失缓存的组员,去数据库中查找,并存入缓存 + if (usersNotInCache.size() > 0) { + Map> topicMap + = topics.stream().collect(Collectors.groupingBy(ResiTopicInfoResultDTO::getUserId)); + List userIds = new ArrayList<>(usersNotInCache); + Result> result = + epmetUserFeignClient.getUserResiInfoList(new UserResiInfoListFormDTO(userIds)); + + if (result.success() && null != result.getData() && result.getData().size() > 0) { + for (UserResiInfoResultDTO user : result.getData()) { + ResiTopicInfoResultDTO topic = + topicMap.get(user.getUserId()).get(0); + topic.setReleaseUserHeadPhoto(user.getHeadPhoto()); + topic.setReleaseUserName(user.getShowName()); + + //存入缓存 + ResiGroupMemberInfoRedisDTO memberRedisDTO = new ResiGroupMemberInfoRedisDTO(); + ResiGroupMemberDTO memberMySql = resiGroupMemberDao.selectGroupMemberInfo(groupId, user.getUserId()); + memberRedisDTO.setMemberStatus(memberMySql.getStatus()); + memberRedisDTO.setUserId(user.getUserId()); + memberRedisDTO.setUserShowName(user.getShowName()); + memberRedisDTO.setEnterGroupType(memberMySql.getEnterGroupType()); + memberRedisDTO.setGroupLeaderFlag(memberMySql.getGroupLeaderFlag()); + memberRedisDTO.setUserHeadPhoto(user.getHeadPhoto()); + memberRedisDTO.setGroupId(groupId); + resiGroupMemberRedis.set(memberRedisDTO); + } + } else { + + logger.warn(ModuleConstant.USER_INFO_LIST_NOT_FOUND); + } + } + + } } diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/utils/ModuleConstant.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/utils/ModuleConstant.java index 624b5cba9d..957c9857bc 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/utils/ModuleConstant.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/utils/ModuleConstant.java @@ -158,4 +158,9 @@ public interface ModuleConstant extends Constant { String DELETE_FAILED = "组成员删除失败"; String SLIENT_FAILED = "组成员禁言失败"; + + /** + * 缺失组成员缓存信息 + * */ + String GROUP_MEMBER_NOT_EXISTS_IN_CACHE = "缺失组成员缓存信息"; } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/UserResiInfoListFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/UserResiInfoListFormDTO.java index b5a34ed278..1a5fe5274c 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/UserResiInfoListFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/UserResiInfoListFormDTO.java @@ -1,6 +1,8 @@ package com.epmet.dto.form; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; import java.util.List; @@ -11,6 +13,8 @@ import java.util.List; * @Date 2020/4/7 18:20 */ @Data +@AllArgsConstructor +@NoArgsConstructor public class UserResiInfoListFormDTO implements Serializable { private static final long serialVersionUID = -4454561042197166135L; diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java index 3bf4faf749..a3e14d4e01 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserResiInfoServiceImpl.java @@ -19,17 +19,14 @@ package com.epmet.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.EpmetRoleKeyConstant; import com.epmet.commons.tools.constant.FieldConstant; -import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.UserConstant; -import com.epmet.constant.UserResiRegisterConstant; import com.epmet.constant.UserRoleConstant; import com.epmet.dao.UserResiInfoDao; import com.epmet.dto.UserResiInfoDTO; @@ -39,7 +36,6 @@ import com.epmet.dto.form.UserResiInfoListFormDTO; import com.epmet.dto.form.VerificationCodeFormDTO; import com.epmet.dto.result.UserResiInfoResultDTO; import com.epmet.entity.UserResiInfoEntity; -import com.epmet.entity.UserRoleEntity; import com.epmet.feign.MessageFeignClient; import com.epmet.redis.UserResiInfoRedis; import com.epmet.service.RegisterRelationService;