Merge branch 'refs/heads/release/3.0' into dev/dev_xp

# Conflicts:
#	src/main/java/com/ai/da/common/utils/RedisUtil.java
#	src/main/java/com/ai/da/service/impl/AccountServiceImpl.java
#	src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java
This commit is contained in:
2024-09-24 10:27:18 +08:00
12 changed files with 190 additions and 61 deletions

View File

@@ -322,19 +322,16 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("BINARY user_email", email);
List<Account> accountList = accountMapper.selectList(queryWrapper);
log.info(accountList.toString());
if (CollectionUtil.isEmpty(accountList)) {
throw new BusinessException("email.does.not.exist", ResultEnum.PROMPT.getCode());
}
return accountList.get(0);
}
// 忽略大小写
private Account getAccountByEmail(String email) {
private Account getByEmailIgnoreCase(String email) {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_email", email);
List<Account> accountList = accountMapper.selectList(queryWrapper);
log.info(accountList.toString());
if (CollectionUtil.isEmpty(accountList)) {
throw new BusinessException("email.does.not.exist", ResultEnum.PROMPT.getCode());
}
@@ -1134,7 +1131,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
Boolean flag = Boolean.FALSE;
try {
// 不是新用户 直接延长使用期限
userInfo = getAccountByEmail(email);
userInfo = getByEmailIgnoreCase(email);
} catch (BusinessException e) {
// 通过邮箱找不到用户 说明是新用户 => 创建用户
flag = Boolean.TRUE;

View File

@@ -813,9 +813,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
// return new DesignLikeVO();
// }
List<CollectionElement> oldElements = collectionElementService.getByCollectionId(userLikeGroup.getCollectionId());
if (CollectionUtil.isEmpty(oldElements)) {
throw new BusinessException("old.elements.not.found");
}
// if (CollectionUtil.isEmpty(oldElements)) {
// throw new BusinessException("old.elements.not.found");
// }
List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designLikeDTO.getDesignItemId());
if (CollectionUtil.isEmpty(designItemDetails)) {
throw new BusinessException("new.designItemDetails.not.found");
@@ -867,8 +867,11 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
if (CollectionUtils.isEmpty(hasCollections)) {
return null;
}
List<Long> oldIds = oldElements.stream().map(CollectionElement::getId).collect(Collectors.toList());
List<Long> elementIds = hasCollections.stream().map(DesignItemDetail::getCollectionElementId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(oldElements)) {
return elementIds;
}
List<Long> oldIds = oldElements.stream().map(CollectionElement::getId).collect(Collectors.toList());
//本次新增collection个数
List<Long> adds = elementIds.stream().filter(id -> !oldIds.contains(id)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(adds)) {
@@ -934,7 +937,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(userLike.getUserLikeGroupId());
if (CollectionUtils.isEmpty(userLikeVOS)) {
//group 下面没有元素时候 直接删除
userLikeGroupService.removeById(userLike.getUserLikeGroupId());
// userLikeGroupService.removeById(userLike.getUserLikeGroupId());
}
return Boolean.TRUE;
}

View File

@@ -23,6 +23,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Function;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -35,6 +36,7 @@ import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio> implements PortfolioService {
@@ -76,6 +78,7 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
@Resource
private DesignItemDetailPrintMapper designItemDetailPrintMapper;
@Resource
private MinioUtil minioUtil;
@@ -436,8 +439,31 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
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);
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 -> {
if (portfolio != null) {
PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class);
@@ -670,8 +696,8 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
Long designItemDetailIdNew = designItemDetailOld.getId();
QueryWrapper<DesignItemDetailPrint> designItemDetailPrintQueryWrapper = new QueryWrapper<>();
designItemDetailPrintQueryWrapper.lambda().eq(DesignItemDetailPrint::getDesignItemDetailId, designItemDetailIdOld);
DesignItemDetailPrint designItemDetailPrint = designItemDetailPrintMapper.selectOne(designItemDetailPrintQueryWrapper);
if (Objects.nonNull(designItemDetailPrint)) {
List<DesignItemDetailPrint> designItemDetailPrintList = designItemDetailPrintMapper.selectList(designItemDetailPrintQueryWrapper);
for (DesignItemDetailPrint designItemDetailPrint : designItemDetailPrintList) {
designItemDetailPrint.setId(null);
designItemDetailPrint.setDesignItemDetailId(designItemDetailIdNew);
designItemDetailPrintMapper.insert(designItemDetailPrint);
@@ -960,6 +986,65 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
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;
}
public void follow(Long followeeId) {
Long accountId = UserContext.getUserHolder().getId();
// 1、不能关注自己