|
|
|
@ -1,29 +1,17 @@
|
|
|
|
package cn.iocoder.yudao.module.product.convert.comment;
|
|
|
|
package cn.iocoder.yudao.module.product.convert.comment;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
|
|
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
|
|
|
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
|
|
|
|
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
|
|
import org.mapstruct.Mapper;
|
|
|
|
import org.mapstruct.Mapper;
|
|
|
|
import org.mapstruct.Mapping;
|
|
|
|
|
|
|
|
import org.mapstruct.Named;
|
|
|
|
|
|
|
|
import org.mapstruct.factory.Mappers;
|
|
|
|
import org.mapstruct.factory.Mappers;
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 商品评价 Convert
|
|
|
|
* 商品评价 Convert
|
|
|
|
@ -35,99 +23,40 @@ public interface ProductCommentConvert {
|
|
|
|
|
|
|
|
|
|
|
|
ProductCommentConvert INSTANCE = Mappers.getMapper(ProductCommentConvert.class);
|
|
|
|
ProductCommentConvert INSTANCE = Mappers.getMapper(ProductCommentConvert.class);
|
|
|
|
|
|
|
|
|
|
|
|
ProductCommentRespVO convert(ProductCommentDO bean);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mapping(target = "scores", expression = "java(calculateOverallScore(goodCount, mediocreCount, negativeCount))")
|
|
|
|
|
|
|
|
AppCommentStatisticsRespVO convert(Long goodCount, Long mediocreCount, Long negativeCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Named("calculateOverallScore")
|
|
|
|
|
|
|
|
default double calculateOverallScore(long goodCount, long mediocreCount, long negativeCount) {
|
|
|
|
|
|
|
|
return (goodCount * 5 + mediocreCount * 3 + negativeCount) / (double) (goodCount + mediocreCount + negativeCount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ProductCommentRespVO> convertList(List<ProductCommentDO> list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> page);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PageResult<AppProductCommentRespVO> convertPage01(PageResult<ProductCommentDO> pageResult);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult,
|
|
|
|
|
|
|
|
List<ProductSkuDO> skuList) {
|
|
|
|
|
|
|
|
Map<Long, ProductSkuDO> skuMap = CollectionUtils.convertMap(skuList, ProductSkuDO::getId);
|
|
|
|
|
|
|
|
PageResult<AppProductCommentRespVO> page = convertPage01(pageResult);
|
|
|
|
|
|
|
|
page.getList().forEach(item -> {
|
|
|
|
|
|
|
|
// 判断用户是否选择匿名
|
|
|
|
|
|
|
|
if (ObjectUtil.equal(item.getAnonymous(), true)) {
|
|
|
|
|
|
|
|
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置 SKU 规格值
|
|
|
|
|
|
|
|
findAndThen(skuMap, item.getSkuId(),
|
|
|
|
|
|
|
|
sku -> item.setSkuProperties(convertList01(sku.getProperties())));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return page;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<AppProductPropertyValueDetailRespVO> convertList01(List<ProductSkuDO.Property> properties);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 计算综合评分
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param descriptionScores 描述星级
|
|
|
|
|
|
|
|
* @param benefitScores 服务星级
|
|
|
|
|
|
|
|
* @return 综合评分
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Named("convertScores")
|
|
|
|
|
|
|
|
default Integer convertScores(Integer descriptionScores, Integer benefitScores) {
|
|
|
|
|
|
|
|
// 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
|
|
|
|
|
|
|
|
BigDecimal sumScore = new BigDecimal(descriptionScores + benefitScores);
|
|
|
|
|
|
|
|
BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN);
|
|
|
|
|
|
|
|
return divide.intValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mapping(target = "scores",
|
|
|
|
|
|
|
|
expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))")
|
|
|
|
|
|
|
|
ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO,
|
|
|
|
default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO,
|
|
|
|
ProductSpuDO spu, ProductSkuDO sku, MemberUserRespDTO user) {
|
|
|
|
ProductSpuDO spu, ProductSkuDO sku, MemberUserRespDTO user) {
|
|
|
|
ProductCommentDO comment = convert(createReqDTO).setReplyStatus(false);
|
|
|
|
ProductCommentDO comment = BeanUtils.toBean(createReqDTO, ProductCommentDO.class)
|
|
|
|
|
|
|
|
.setScores(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()));
|
|
|
|
if (user != null) {
|
|
|
|
if (user != null) {
|
|
|
|
comment.setUserId(user.getId());
|
|
|
|
comment.setUserId(user.getId()).setUserNickname(user.getNickname()).setUserAvatar(user.getAvatar());
|
|
|
|
comment.setUserNickname(user.getNickname());
|
|
|
|
|
|
|
|
comment.setUserAvatar(user.getAvatar());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (spu != null) {
|
|
|
|
if (spu != null) {
|
|
|
|
comment.setSpuId(spu.getId());
|
|
|
|
comment.setSpuId(spu.getId()).setSpuName(spu.getName());
|
|
|
|
comment.setSpuName(spu.getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sku != null) {
|
|
|
|
if (sku != null) {
|
|
|
|
comment.setSkuPicUrl(sku.getPicUrl());
|
|
|
|
comment.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
|
|
|
|
comment.setSkuProperties(sku.getProperties());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return comment;
|
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Mapping(target = "visible", constant = "true")
|
|
|
|
|
|
|
|
@Mapping(target = "replyStatus", constant = "false")
|
|
|
|
|
|
|
|
@Mapping(target = "userId", constant = "0L")
|
|
|
|
|
|
|
|
@Mapping(target = "orderId", constant = "0L")
|
|
|
|
|
|
|
|
@Mapping(target = "orderItemId", constant = "0L")
|
|
|
|
|
|
|
|
@Mapping(target = "anonymous", expression = "java(Boolean.FALSE)")
|
|
|
|
|
|
|
|
@Mapping(target = "scores",
|
|
|
|
|
|
|
|
expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))")
|
|
|
|
|
|
|
|
ProductCommentDO convert(ProductCommentCreateReqVO createReq);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) {
|
|
|
|
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) {
|
|
|
|
ProductCommentDO commentDO = convert(createReq);
|
|
|
|
ProductCommentDO comment = BeanUtils.toBean(createReq, ProductCommentDO.class)
|
|
|
|
|
|
|
|
.setVisible(true).setUserId(0L).setAnonymous(false)
|
|
|
|
|
|
|
|
.setScores(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()));
|
|
|
|
if (spu != null) {
|
|
|
|
if (spu != null) {
|
|
|
|
commentDO.setSpuId(spu.getId()).setSpuName(spu.getName());
|
|
|
|
comment.setSpuId(spu.getId()).setSpuName(spu.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sku != null) {
|
|
|
|
if (sku != null) {
|
|
|
|
commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
|
|
|
|
comment.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return commentDO;
|
|
|
|
return comment;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default Integer convertScores(Integer descriptionScores, Integer benefitScores) {
|
|
|
|
|
|
|
|
// 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
|
|
|
|
|
|
|
|
BigDecimal sumScore = new BigDecimal(descriptionScores + benefitScores);
|
|
|
|
|
|
|
|
BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN);
|
|
|
|
|
|
|
|
return divide.intValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|