From 8bf923b44bbe9b45b73ddcc25df75c9c59f54e07 Mon Sep 17 00:00:00 2001
From: Hentua <wangdoubleone@gmail.com>
Date: Thu, 15 Jun 2023 11:19:44 +0800
Subject: [PATCH] fix

---
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsServiceImpl.java |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsServiceImpl.java
index 6a9f5a0..875ed7c 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsServiceImpl.java
@@ -1,10 +1,21 @@
 package cc.mrbird.febs.mall.service.impl;
 
+import cc.mrbird.febs.common.exception.FebsException;
+import cc.mrbird.febs.mall.conversion.MallGoodsConversion;
+import cc.mrbird.febs.mall.conversion.MallMemberConversion;
+import cc.mrbird.febs.mall.dto.ApiMallGoodsCommentDto;
 import cc.mrbird.febs.mall.dto.MallGoodsQueryDto;
 import cc.mrbird.febs.mall.entity.MallGoods;
+import cc.mrbird.febs.mall.entity.MallGoodsComment;
+import cc.mrbird.febs.mall.mapper.MallGoodsCommentMapper;
+import cc.mrbird.febs.mall.mapper.MallGoodsImagesMapper;
 import cc.mrbird.febs.mall.mapper.MallGoodsMapper;
 import cc.mrbird.febs.mall.service.IApiMallGoodsService;
+import cc.mrbird.febs.mall.vo.MallGoodsCommentVo;
+import cc.mrbird.febs.mall.vo.MallGoodsDetailsVo;
 import cc.mrbird.febs.mall.vo.MallGoodsListVo;
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -12,7 +23,9 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author wzy
@@ -23,9 +36,47 @@
 @RequiredArgsConstructor
 public class ApiMallGoodsServiceImpl extends ServiceImpl<MallGoodsMapper, MallGoods> implements IApiMallGoodsService {
 
+    private final MallGoodsImagesMapper goodsImagesMapper;
+    private final MallGoodsCommentMapper mallGoodsCommentMapper;
+
+
     @Override
     public IPage<MallGoodsListVo> findMallGoodsListInPage(MallGoodsQueryDto queryDto) {
         Page<MallGoodsListVo> page = new Page<>(queryDto.getPageNow(), queryDto.getPageSize());
         return this.baseMapper.selectMallGoodsListQueryInPage(queryDto, page);
     }
+
+    @Override
+    public MallGoodsDetailsVo findMallGoodsDetailsById(Long id) {
+        MallGoods mallGoods = this.baseMapper.selectGoodsDetailById(id);
+        if (mallGoods == null) {
+            throw new FebsException("商品不存在");
+        }
+        List<String> images = goodsImagesMapper.selectGoodsImagesByGoodsId(mallGoods.getId());
+        MallGoodsDetailsVo mallGoodsDetailsVo = MallGoodsConversion.INSTANCE.entityToDetailsVo(mallGoods);
+
+        if (CollUtil.isNotEmpty(mallGoods.getStyles())) {
+            Map<String, BigDecimal> stockAndVolume = this.baseMapper.selectGoodsStockAndVolume(id);
+            mallGoodsDetailsVo.setStock(stockAndVolume.get("stock").intValue());
+            mallGoodsDetailsVo.setVolume(stockAndVolume.get("volume").intValue());
+        }
+        mallGoodsDetailsVo.setImages(images);
+
+        QueryWrapper<MallGoodsComment> objectQueryWrapper = new QueryWrapper<>();
+        objectQueryWrapper.eq("goods_id",id);
+        Integer commentCount = mallGoodsCommentMapper.selectCount(objectQueryWrapper);
+        mallGoodsDetailsVo.setCommentCount(commentCount);
+        int scorePercent = mallGoodsDetailsVo.getScorePercent() == null ? 0 : mallGoodsDetailsVo.getScorePercent();
+        mallGoodsDetailsVo.setScorePercentNum(new BigDecimal(scorePercent).multiply(new BigDecimal("0.01")));
+
+        return mallGoodsDetailsVo;
+    }
+
+    @Override
+    public IPage<MallGoodsCommentVo> findMallGoodsCommentByGoodsId(ApiMallGoodsCommentDto queryDto) {
+        Page<MallGoodsCommentVo> page = new Page<>(queryDto.getPageNow(), queryDto.getPageSize());
+        MallGoodsComment mallGoodsComment = new MallGoodsComment();
+        mallGoodsComment.setGoodsId(queryDto.getGoodsId());
+        return this.baseMapper.selectMallGoodsCommentListQueryInPage(page,mallGoodsComment);
+    }
 }

--
Gitblit v1.9.1