shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.ishop.merchant.service;
 
import com.ishop.merchant.ProductConstants;
import com.ishop.model.vo.ProductDetailReplyVo;
import com.ishop.model.vo.ProductReplayCountVo;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.jdbc.service.BaseServiceImpl;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.Map;
 
@Service
public class ProductReplyServiceImpl extends BaseServiceImpl {
 
    /**
     * H5商品详情评论信息
     * @param productId 商品ID
     * @return
     * @date 2023-07-04
     */
    public ProductDetailReplyVo queryH5ProductReply(long productId){
        ProductDetailReplyVo vo = new ProductDetailReplyVo();
        // 评论总数
        int sumCount = getReplyCountByScope(ProductConstants.PRODUCT_REPLY_TYPE_ALL, productId);
        if (sumCount == 0) {
            vo.setSumCount(0);
            vo.setReplyChance("0");
            return vo;
        }
        System.out.println("还未实现代码(商品评价详情)!");
        return vo;
    }
 
    private int getReplyCountByScope(String type, long productId){
        StringBuilder sql = new StringBuilder("select count(*) from eb_product_reply where product_id=:productId and is_del=0");
        if(StringUtils.isNotEmpty(type)){
            if(type.equals(ProductConstants.PRODUCT_REPLY_TYPE_GOOD)){
                sql.append(" and star=5");
            } else if(type.equals(ProductConstants.PRODUCT_REPLY_TYPE_POOR)){
                sql.append(" and star=1");
            } else if (type.equals(ProductConstants.PRODUCT_REPLY_TYPE_MEDIUM)) {
                sql.append(" and (star>1 and star<5)");
            } else if (type.equals(ProductConstants.PRODUCT_REPLY_TYPE_ALL)) {
                // 查询所有星级
            }
        }
        Map<String, Object> parameter = new HashMap<>(2);
        parameter.put("productId", productId);
        return this.queryForInt(sql.toString(), parameter);
    }
 
    /**
     * 返回手机端商品评论统计
     * @return
     * @date 2023-07-04
     */
    public ProductReplayCountVo queryH5ReplyCount(long productId){
        // 评论总数
//        Integer sumCount = getCountByScore(productId, ProductConstants.PRODUCT_REPLY_TYPE_ALL);
        Integer sumCount = 0;
//        // 好评总数
//        Integer goodCount = getCountByScore(productId, ProductConstants.PRODUCT_REPLY_TYPE_GOOD);
        Integer goodCount = 0;
//        // 中评总数
//        Integer mediumCount = getCountByScore(productId, ProductConstants.PRODUCT_REPLY_TYPE_MEDIUM);
//        // 差评总数
//        Integer poorCount = getCountByScore(productId, ProductConstants.PRODUCT_REPLY_TYPE_POOR);
        // 好评率
        String replyChance = "0";
        if (sumCount > 0 && goodCount > 0) {
            replyChance = String.format("%.2f", ((goodCount.doubleValue() / sumCount.doubleValue())));
        }
        // 评分星数 = 总星数/评价数
        Integer replyStar = 0;
//        if (sumCount > 0) {
//            replyStar = getSumStar(productId);
//            BigDecimal divide = new BigDecimal(replyStar).divide(new BigDecimal(sumCount.toString()), 0, BigDecimal.ROUND_DOWN);
//            replyStar = divide.intValue();
//        }
        return new ProductReplayCountVo(sumCount, goodCount, 0, 0, replyChance, replyStar);
    }
}