动态详情新增礼物数量字段
This commit is contained in:
parent
129bbe17a4
commit
d6825afe1a
@ -13,6 +13,7 @@ import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicPicture;
|
||||
import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicTag;
|
||||
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicCommentService;
|
||||
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicContentService;
|
||||
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicGiftService;
|
||||
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicLikeService;
|
||||
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicPictureService;
|
||||
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicTagService;
|
||||
@ -48,6 +49,7 @@ public class DynamicDetailsQryExe {
|
||||
private final DynamicContentService dynamicContentService;
|
||||
private final DynamicPictureService dynamicPictureService;
|
||||
private final DynamicCommentService dynamicCommentService;
|
||||
private final DynamicGiftService dynamicGiftService;
|
||||
private final UserSubscriptionService userSubscriptionService;
|
||||
private final UserProfileAppConvertor userProfileAppConvertor;
|
||||
|
||||
@ -65,6 +67,7 @@ public class DynamicDetailsQryExe {
|
||||
//自己是否已点赞
|
||||
Map<Long, Boolean> likeMap = getLikeMap(cmd, contentIds);
|
||||
Map<Long, Long> likeQuantityMap = dynamicLikeService.mapLikeQuantity(contentIds);
|
||||
Map<Long, Long> giftQuantityMap = dynamicGiftService.mapGiftQuantity(contentIds);
|
||||
Map<Long, Integer> commentQuantityMap = dynamicCommentService.mapCommentQuantity(contentIds);
|
||||
Map<Long, List<DynamicPicture>> pictureMap = dynamicPictureService.mapPreviewGroup(contentIds);
|
||||
|
||||
@ -76,6 +79,7 @@ public class DynamicDetailsQryExe {
|
||||
result.setSubscription(checkSubscription(cmd.getReqUserId(), dynamic.getCreateUser()));
|
||||
result.setLikeStrQuantity(NumUtils.formatLong(likeQuantityMap.get(dynamic.getId())));
|
||||
result.setLike(Optional.ofNullable(likeMap.get(dynamic.getId())).orElse(Boolean.FALSE));
|
||||
result.setGiftStrQuantity(NumUtils.formatLong(giftQuantityMap.get(dynamic.getId())));
|
||||
result.setCommentStrQuantity(NumUtils.formatInt(commentQuantityMap.get(dynamic.getId())));
|
||||
return result;
|
||||
|
||||
|
||||
@ -95,6 +95,11 @@ public class DynamicListCO extends ClientObject {
|
||||
*/
|
||||
private String likeStrQuantity;
|
||||
|
||||
/**
|
||||
* 礼物数量.
|
||||
*/
|
||||
private String giftStrQuantity;
|
||||
|
||||
/**
|
||||
* 创建时间.
|
||||
*/
|
||||
|
||||
@ -5,6 +5,8 @@ import com.red.circle.framework.dto.PageResult;
|
||||
import com.red.circle.framework.mybatis.service.BaseService;
|
||||
import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicGift;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 动态-礼物 服务类.
|
||||
@ -35,4 +37,12 @@ public interface DynamicGiftService extends BaseService<DynamicGift> {
|
||||
*/
|
||||
PageResult<DynamicGift> pageByUpdateTimeDesc(PageQuery pageQuery, Long contentId);
|
||||
|
||||
/**
|
||||
* 统计动态礼物数量(所有用户送的总数).
|
||||
*
|
||||
* @param contentIds 动态内容ID集合
|
||||
* @return key: contentId, value: 礼物总数
|
||||
*/
|
||||
Map<Long, Long> mapGiftQuantity(Collection<Long> contentIds);
|
||||
|
||||
}
|
||||
|
||||
@ -8,9 +8,12 @@ import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicGift;
|
||||
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicGiftService;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* 动态-礼物 服务实现类.
|
||||
@ -67,4 +70,40 @@ public class DynamicGiftServiceImpl extends BaseServiceImpl<DynamicGiftDAO, Dyna
|
||||
.page(pageQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Long> mapGiftQuantity(java.util.Collection<Long> contentIds) {
|
||||
if (CollectionUtils.isEmpty(contentIds)) {
|
||||
return java.util.Collections.emptyMap();
|
||||
}
|
||||
|
||||
// 查询所有礼物记录
|
||||
List<DynamicGift> gifts = query()
|
||||
.select(DynamicGift::getDynamicContentId, DynamicGift::getGiftQuantity)
|
||||
.in(DynamicGift::getDynamicContentId, contentIds)
|
||||
.list();
|
||||
|
||||
if (CollectionUtils.isEmpty(gifts)) {
|
||||
return contentIds.stream()
|
||||
.collect(java.util.stream.Collectors.toMap(
|
||||
java.util.function.Function.identity(),
|
||||
id -> 0L
|
||||
));
|
||||
}
|
||||
|
||||
// 按 contentId 分组统计总数
|
||||
Map<Long, Long> result = new java.util.HashMap<>();
|
||||
for (DynamicGift gift : gifts) {
|
||||
Long contentId = gift.getDynamicContentId();
|
||||
Long quantity = gift.getGiftQuantity().longValue();
|
||||
result.put(contentId, result.getOrDefault(contentId, 0L) + quantity);
|
||||
}
|
||||
|
||||
// 为所有 contentId 设置默认值
|
||||
for (Long contentId : contentIds) {
|
||||
result.putIfAbsent(contentId, 0L);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user