作品广场优化,将点赞前三和浏览量前三的作品放在第一页的最前面
This commit is contained in:
@@ -7,10 +7,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -154,6 +151,8 @@ public class RedisUtil {
|
|||||||
return redisTemplate.keys(key);
|
return redisTemplate.keys(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getSize(String key){return redisTemplate.opsForSet().size(key);}
|
||||||
|
|
||||||
public List<String> getMultiValue(Set<String> keys){
|
public List<String> getMultiValue(Set<String> keys){
|
||||||
return redisTemplate.opsForValue().multiGet(keys);
|
return redisTemplate.opsForValue().multiGet(keys);
|
||||||
}
|
}
|
||||||
@@ -216,4 +215,17 @@ public class RedisUtil {
|
|||||||
return redisTemplate.opsForValue().increment(key, 0);
|
return redisTemplate.opsForValue().increment(key, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getViewCount(String key) {
|
||||||
|
Object value = redisTemplate.opsForValue().get(key);
|
||||||
|
if (value instanceof Integer) {
|
||||||
|
return Long.valueOf((Integer) value);
|
||||||
|
} else if (value instanceof Long) {
|
||||||
|
return (Long) value;
|
||||||
|
} else if (value instanceof String) {
|
||||||
|
return Long.valueOf((String) value);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unexpected value type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.ai.da.common.utils.MinioUtil;
|
|||||||
import com.ai.da.common.utils.RedisUtil;
|
import com.ai.da.common.utils.RedisUtil;
|
||||||
import com.ai.da.mapper.primary.*;
|
import com.ai.da.mapper.primary.*;
|
||||||
import com.ai.da.mapper.primary.entity.*;
|
import com.ai.da.mapper.primary.entity.*;
|
||||||
|
import com.ai.da.mapper.primary.entity.Collection;
|
||||||
import com.ai.da.model.dto.*;
|
import com.ai.da.model.dto.*;
|
||||||
import com.ai.da.model.enums.Position;
|
import com.ai.da.model.enums.Position;
|
||||||
import com.ai.da.model.enums.Sex;
|
import com.ai.da.model.enums.Sex;
|
||||||
@@ -20,21 +21,20 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import sun.security.krb5.internal.crypto.Des;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
import java.util.stream.Collectors;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio> implements PortfolioService {
|
public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio> implements PortfolioService {
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserLikeMapper userLikeMapper;
|
private UserLikeMapper userLikeMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TDesignPythonOutfitMapper designPythonOutfitMapper;
|
private TDesignPythonOutfitMapper designPythonOutfitMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@@ -76,7 +76,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
@Resource
|
@Resource
|
||||||
private DesignItemDetailPrintMapper designItemDetailPrintMapper;
|
private DesignItemDetailPrintMapper designItemDetailPrintMapper;
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MinioUtil minioUtil;
|
private MinioUtil minioUtil;
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
portfolio.setOriginal(0);
|
portfolio.setOriginal(0);
|
||||||
portfolio.setOriginalAccountId(userLikeGroup.getOriginalAccountId());
|
portfolio.setOriginalAccountId(userLikeGroup.getOriginalAccountId());
|
||||||
portfolio.setOriginalPortfolioId(userLikeGroup.getOriginalPortfolioId());
|
portfolio.setOriginalPortfolioId(userLikeGroup.getOriginalPortfolioId());
|
||||||
}else {
|
} else {
|
||||||
portfolio.setOriginal(1);
|
portfolio.setOriginal(1);
|
||||||
// portfolio.setOriginalAccountId(authPrincipalVo.getId());
|
// portfolio.setOriginalAccountId(authPrincipalVo.getId());
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
portfolio.setPortfolioDes(portfolioDTO.getPortfolioDes());
|
portfolio.setPortfolioDes(portfolioDTO.getPortfolioDes());
|
||||||
if (!CollectionUtils.isEmpty(portfolios)) {
|
if (!CollectionUtils.isEmpty(portfolios)) {
|
||||||
portfolioMapper.updateById(portfolio);
|
portfolioMapper.updateById(portfolio);
|
||||||
}else {
|
} else {
|
||||||
portfolioMapper.insert(portfolio);
|
portfolioMapper.insert(portfolio);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
portfolio.setOriginal(0);
|
portfolio.setOriginal(0);
|
||||||
portfolio.setOriginalAccountId(userLikeGroup.getOriginalAccountId());
|
portfolio.setOriginalAccountId(userLikeGroup.getOriginalAccountId());
|
||||||
portfolio.setOriginalPortfolioId(userLikeGroup.getOriginalPortfolioId());
|
portfolio.setOriginalPortfolioId(userLikeGroup.getOriginalPortfolioId());
|
||||||
}else {
|
} else {
|
||||||
portfolio.setOriginal(1);
|
portfolio.setOriginal(1);
|
||||||
// portfolio.setOriginalAccountId(authPrincipalVo.getId());
|
// portfolio.setOriginalAccountId(authPrincipalVo.getId());
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
portfolio.setPortfolioDes(portfolioDTO.getPortfolioDes());
|
portfolio.setPortfolioDes(portfolioDTO.getPortfolioDes());
|
||||||
if (!CollectionUtils.isEmpty(portfolios)) {
|
if (!CollectionUtils.isEmpty(portfolios)) {
|
||||||
portfolioMapper.updateById(portfolio);
|
portfolioMapper.updateById(portfolio);
|
||||||
}else {
|
} else {
|
||||||
portfolioMapper.insert(portfolio);
|
portfolioMapper.insert(portfolio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,12 +428,35 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
List<Long> likedPortfolioIdList = redisUtil.getLikedPortfolios(userHolder.getId());
|
List<Long> likedPortfolioIdList = redisUtil.getLikedPortfolios(userHolder.getId());
|
||||||
if (!CollectionUtils.isEmpty(likedPortfolioIdList)) {
|
if (!CollectionUtils.isEmpty(likedPortfolioIdList)) {
|
||||||
qw.lambda().in(Portfolio::getId, likedPortfolioIdList);
|
qw.lambda().in(Portfolio::getId, likedPortfolioIdList);
|
||||||
}else {
|
} else {
|
||||||
return PageBaseResponse.success(new Page<>());
|
return PageBaseResponse.success(new Page<>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<Portfolio> topThree = new ArrayList<>();
|
||||||
|
|
||||||
|
if (query.getPage() == 1 &&
|
||||||
|
(query.getGetMyPortfolio() != 1 || query.getGetLikePortfolio() != 1)) {
|
||||||
|
List<Long> topThreeLike = getTopThreeLikeFromRedis(RedisUtil.PORTFOLIO_LIKE_KEY);
|
||||||
|
log.info("top three like 的作品集的id : {}", topThreeLike);
|
||||||
|
List<Long> topThreeView = getTopThreeViewFromRedis(RedisUtil.PORTFOLIO_VIEW_KEY);
|
||||||
|
log.info("top three view 的作品集的id : {}", topThreeView);
|
||||||
|
QueryWrapper<Portfolio> queryLike = new QueryWrapper<>();
|
||||||
|
queryLike.in("id", topThreeLike);
|
||||||
|
QueryWrapper<Portfolio> queryView = new QueryWrapper<>();
|
||||||
|
queryView.in("id", topThreeView);
|
||||||
|
List<Portfolio> topThreeLikePortfolio = baseMapper.selectList(queryLike);
|
||||||
|
List<Portfolio> topThreeViewPortfolio = baseMapper.selectList(queryView);
|
||||||
|
topThree.addAll(topThreeLikePortfolio);
|
||||||
|
topThree.addAll(topThreeViewPortfolio);
|
||||||
|
}
|
||||||
|
|
||||||
qw.lambda().orderByDesc(Portfolio::getUpdateDate);
|
qw.lambda().orderByDesc(Portfolio::getUpdateDate);
|
||||||
IPage<Portfolio> page = portfolioMapper.selectPage(new Page<>(query.getPage(), query.getSize()),qw);
|
IPage<Portfolio> page = portfolioMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
|
||||||
|
if (!topThree.isEmpty()) {
|
||||||
|
List<Portfolio> records = page.getRecords();
|
||||||
|
records.addAll(0, topThree);
|
||||||
|
page.setRecords(records);
|
||||||
|
}
|
||||||
IPage<PortfolioVO> convert = page.convert((Function<Portfolio, PortfolioVO>) portfolio -> {
|
IPage<PortfolioVO> convert = page.convert((Function<Portfolio, PortfolioVO>) portfolio -> {
|
||||||
if (portfolio != null) {
|
if (portfolio != null) {
|
||||||
PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class);
|
PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class);
|
||||||
@@ -481,11 +504,11 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
vo.setLikeNum(redisUtil.getLikeCount(vo.getId()));
|
vo.setLikeNum(redisUtil.getLikeCount(vo.getId()));
|
||||||
if (userHolder == null) {
|
if (userHolder == null) {
|
||||||
vo.setIsLike(0);
|
vo.setIsLike(0);
|
||||||
}else {
|
} else {
|
||||||
boolean postLikedByUser = redisUtil.isPostLikedByUser(portfolioDTO.getId(), userHolder.getId());
|
boolean postLikedByUser = redisUtil.isPostLikedByUser(portfolioDTO.getId(), userHolder.getId());
|
||||||
if (postLikedByUser) {
|
if (postLikedByUser) {
|
||||||
vo.setIsLike(1);
|
vo.setIsLike(1);
|
||||||
}else {
|
} else {
|
||||||
vo.setIsLike(0);
|
vo.setIsLike(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -500,7 +523,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
vo.setOriginalPortfolioName(portfolioName);
|
vo.setOriginalPortfolioName(portfolioName);
|
||||||
if (byId.getIsDeleted() == 0) {
|
if (byId.getIsDeleted() == 0) {
|
||||||
vo.setJumpable(1);
|
vo.setJumpable(1);
|
||||||
}else {
|
} else {
|
||||||
vo.setJumpable(0);
|
vo.setJumpable(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -508,11 +531,11 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
if (userHolder == null) {
|
if (userHolder == null) {
|
||||||
vo.setIsMine(0);
|
vo.setIsMine(0);
|
||||||
vo.setSelected(0);
|
vo.setSelected(0);
|
||||||
}else {
|
} else {
|
||||||
if (Objects.equals(vo.getAccountId(), userHolder.getId()) || Objects.equals(vo.getOriginalAccountId(), userHolder.getId())) {
|
if (Objects.equals(vo.getAccountId(), userHolder.getId()) || Objects.equals(vo.getOriginalAccountId(), userHolder.getId())) {
|
||||||
vo.setIsMine(1);
|
vo.setIsMine(1);
|
||||||
vo.setSelected(1);
|
vo.setSelected(1);
|
||||||
}else {
|
} else {
|
||||||
vo.setIsMine(0);
|
vo.setIsMine(0);
|
||||||
QueryWrapper<UserLikeGroup> getSelectedQw = new QueryWrapper<>();
|
QueryWrapper<UserLikeGroup> getSelectedQw = new QueryWrapper<>();
|
||||||
getSelectedQw.lambda().eq(UserLikeGroup::getAccountId, userHolder.getId());
|
getSelectedQw.lambda().eq(UserLikeGroup::getAccountId, userHolder.getId());
|
||||||
@@ -520,7 +543,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
List<UserLikeGroup> userLikeGroups = userLikeGroupMapper.selectList(getSelectedQw);
|
List<UserLikeGroup> userLikeGroups = userLikeGroupMapper.selectList(getSelectedQw);
|
||||||
if (CollectionUtils.isEmpty(userLikeGroups)) {
|
if (CollectionUtils.isEmpty(userLikeGroups)) {
|
||||||
vo.setSelected(0);
|
vo.setSelected(0);
|
||||||
}else {
|
} else {
|
||||||
vo.setSelected(1);
|
vo.setSelected(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,12 +570,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
if (portfolio.getOriginal() == 1) {
|
if (portfolio.getOriginal() == 1) {
|
||||||
if (Objects.equals(portfolio.getAccountId(), authPrincipalVo.getId())) {
|
if (Objects.equals(portfolio.getAccountId(), authPrincipalVo.getId())) {
|
||||||
userLikeGroupNew.setOriginal(1);
|
userLikeGroupNew.setOriginal(1);
|
||||||
}else {
|
} else {
|
||||||
userLikeGroupNew.setOriginal(0);
|
userLikeGroupNew.setOriginal(0);
|
||||||
userLikeGroupNew.setOriginalAccountId(portfolio.getAccountId());
|
userLikeGroupNew.setOriginalAccountId(portfolio.getAccountId());
|
||||||
userLikeGroupNew.setOriginalPortfolioId(portfolio.getId());
|
userLikeGroupNew.setOriginalPortfolioId(portfolio.getId());
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
userLikeGroupNew.setOriginal(0);
|
userLikeGroupNew.setOriginal(0);
|
||||||
userLikeGroupNew.setOriginalAccountId(portfolio.getOriginalAccountId());
|
userLikeGroupNew.setOriginalAccountId(portfolio.getOriginalAccountId());
|
||||||
userLikeGroupNew.setOriginalPortfolioId(portfolio.getId());
|
userLikeGroupNew.setOriginalPortfolioId(portfolio.getId());
|
||||||
@@ -572,7 +595,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
if (workspace.getSex().equals(Sex.FEMALE.getValue())) {
|
if (workspace.getSex().equals(Sex.FEMALE.getValue())) {
|
||||||
design.setTemplateId(workspace.getMannequinFemaleId());
|
design.setTemplateId(workspace.getMannequinFemaleId());
|
||||||
design.setModelType(workspace.getMannequinFemaleType());
|
design.setModelType(workspace.getMannequinFemaleType());
|
||||||
}else {
|
} else {
|
||||||
design.setTemplateId(workspace.getMannequinMaleId());
|
design.setTemplateId(workspace.getMannequinMaleId());
|
||||||
design.setModelType(workspace.getMannequinMaleType());
|
design.setModelType(workspace.getMannequinMaleType());
|
||||||
}
|
}
|
||||||
@@ -580,7 +603,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
if (workspace.getPosition().equals(Position.OVERALL.getValue())) {
|
if (workspace.getPosition().equals(Position.OVERALL.getValue())) {
|
||||||
design.setSingleOverall("overall");
|
design.setSingleOverall("overall");
|
||||||
design.setSwitchCategory("");
|
design.setSwitchCategory("");
|
||||||
}else {
|
} else {
|
||||||
design.setSingleOverall("single");
|
design.setSingleOverall("single");
|
||||||
design.setSwitchCategory(workspace.getPosition());
|
design.setSwitchCategory(workspace.getPosition());
|
||||||
}
|
}
|
||||||
@@ -698,7 +721,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
workspaceNew.setSystemDesignerPercentage((design1.getSystemScale().multiply(BigDecimal.valueOf(100)).intValue()));
|
workspaceNew.setSystemDesignerPercentage((design1.getSystemScale().multiply(BigDecimal.valueOf(100)).intValue()));
|
||||||
if (design1.getSingleOverall().equals("overall")) {
|
if (design1.getSingleOverall().equals("overall")) {
|
||||||
workspaceNew.setPosition("Overall");
|
workspaceNew.setPosition("Overall");
|
||||||
}else {
|
} else {
|
||||||
workspaceNew.setPosition(design1.getSwitchCategory());
|
workspaceNew.setPosition(design1.getSwitchCategory());
|
||||||
}
|
}
|
||||||
workspaceMapper.insert(workspaceNew);
|
workspaceMapper.insert(workspaceNew);
|
||||||
@@ -727,7 +750,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
workspaceNew.setMannequinMaleId(anotherOne.getId());
|
workspaceNew.setMannequinMaleId(anotherOne.getId());
|
||||||
workspaceNew.setMannequinMaleType("System");
|
workspaceNew.setMannequinMaleType("System");
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
workspaceNew.setSex("Male");
|
workspaceNew.setSex("Male");
|
||||||
workspaceNew.setMannequinMaleId(design1.getTemplateId());
|
workspaceNew.setMannequinMaleId(design1.getTemplateId());
|
||||||
workspaceNew.setMannequinMaleType("System");
|
workspaceNew.setMannequinMaleType("System");
|
||||||
@@ -751,7 +774,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
workspaceNew.setMannequinFemaleType("System");
|
workspaceNew.setMannequinFemaleType("System");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
Library library = libraryMapper.selectById(design1.getTemplateId());
|
Library library = libraryMapper.selectById(design1.getTemplateId());
|
||||||
if (library.getLevel2Type().equals("Female")) {
|
if (library.getLevel2Type().equals("Female")) {
|
||||||
workspaceNew.setSex("Female");
|
workspaceNew.setSex("Female");
|
||||||
@@ -766,7 +789,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
workspaceNew.setMannequinMaleId(anotherOne.getId());
|
workspaceNew.setMannequinMaleId(anotherOne.getId());
|
||||||
workspaceNew.setMannequinMaleType("System");
|
workspaceNew.setMannequinMaleType("System");
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
workspaceNew.setSex("Male");
|
workspaceNew.setSex("Male");
|
||||||
workspaceNew.setMannequinMaleId(design1.getTemplateId());
|
workspaceNew.setMannequinMaleId(design1.getTemplateId());
|
||||||
workspaceNew.setMannequinMaleType("Library");
|
workspaceNew.setMannequinMaleType("Library");
|
||||||
@@ -795,6 +818,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean like(Long id) {
|
public Boolean like(Long id) {
|
||||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||||
@@ -804,6 +828,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CommentMapper commentMapper;
|
private CommentMapper commentMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean comment(CommentDTO commentDTO) {
|
public Boolean comment(CommentDTO commentDTO) {
|
||||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||||
@@ -925,4 +950,63 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
|
|||||||
// }
|
// }
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Long> getTopThreeLikeFromRedis(String prefix) {
|
||||||
|
// 获取所有与 PORTFOLIO_LIKE_KEY 相关的 keys
|
||||||
|
Set<String> keys = redisUtil.getKeysFromString(prefix + "*");
|
||||||
|
|
||||||
|
List<Map.Entry<String, Long>> portfolioSizes = new ArrayList<>();
|
||||||
|
|
||||||
|
if (keys != null) {
|
||||||
|
for (String key : keys) {
|
||||||
|
// 获取 Set 的 size
|
||||||
|
Long size = redisUtil.getSize(key);
|
||||||
|
// 保存 key 和 size
|
||||||
|
portfolioSizes.add(new AbstractMap.SimpleEntry<>(key, size));
|
||||||
|
}
|
||||||
|
// 按 size 倒序排序
|
||||||
|
portfolioSizes.sort((e1, e2) -> e2.getValue().compareTo(e1.getValue()));
|
||||||
|
// 获取 size 最大的前三个
|
||||||
|
List<Long> top3PortfolioIds = portfolioSizes.stream()
|
||||||
|
.limit(3)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.map(key -> key.replace(prefix, "")) // 去掉前缀,获取 portfolioId
|
||||||
|
.map(Long::valueOf)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
// 输出 top3PortfolioIds
|
||||||
|
top3PortfolioIds.forEach(System.out::println);
|
||||||
|
return top3PortfolioIds;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Long> getTopThreeViewFromRedis(String prefix) {
|
||||||
|
// Step 1: Get all keys with the specific prefix
|
||||||
|
Set<String> keys = redisUtil.getKeysFromString(prefix + "*");
|
||||||
|
// Step 2: Create a map to store portfolioId and its corresponding value
|
||||||
|
Map<Long, Long> portfolioViews = new HashMap<>();
|
||||||
|
if (keys != null) {
|
||||||
|
for (String key : keys) {
|
||||||
|
// Get the value associated with the key
|
||||||
|
Long value = redisUtil.getViewCount(key);
|
||||||
|
if (!Objects.isNull(value)) {
|
||||||
|
// Extract the portfolioId from the key (assuming the key structure is consistent)
|
||||||
|
Long portfolioId = Long.valueOf(key.replace(prefix, ""));
|
||||||
|
portfolioViews.put(portfolioId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Step 3: Find the top 3 portfolio IDs with the largest values
|
||||||
|
if (!portfolioViews.isEmpty()){
|
||||||
|
List<Long> top3PortfolioIds = portfolioViews.entrySet().stream()
|
||||||
|
.sorted(Map.Entry.<Long, Long>comparingByValue().reversed())
|
||||||
|
.limit(3)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
System.out.println("Top 3 Portfolio IDs: " + top3PortfolioIds);
|
||||||
|
return top3PortfolioIds;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user