xuhy
2024-08-10 d378b55981bca01371325eeb4e9e60483ff7d609
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
package com.ruoyi.order.service.impl;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.order.api.model.TOrderEvaluate;
import com.ruoyi.order.mapper.TOrderEvaluateMapper;
import com.ruoyi.order.mapper.TOrderEvaluateTagMapper;
import com.ruoyi.order.service.TOrderEvaluateService;
import com.ruoyi.other.api.feignClient.TEvaluationTagClient;
import com.ruoyi.other.api.vo.TEvaluationTagVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-07
 */
@Service
public class TOrderEvaluateServiceImpl extends ServiceImpl<TOrderEvaluateMapper, TOrderEvaluate> implements TOrderEvaluateService {
 
    @Autowired
    private TEvaluationTagClient evaluationTagClient;
    @Autowired
    private TOrderEvaluateTagMapper orderEvaluateTagMapper;
    @Override
    public List<TEvaluationTagVO> getTagList() {
        // 查询标签列表
        R<List<TEvaluationTagVO>> r = evaluationTagClient.getTagList();
        List<TEvaluationTagVO> tagList = r.getData();
        List<Integer> tagIds = tagList.stream().map(TEvaluationTagVO::getId).collect(Collectors.toList());
        // 统计标签使用数量
        List<TEvaluationTagVO> counts = orderEvaluateTagMapper.getCountByTagIds(tagIds);
        tagList.forEach(tag -> {
            counts.forEach(count -> {
                if (tag.getId().equals(count.getId())) {
                    tag.setTagCount(count.getTagCount());
                }
            });
        });
        tagList = tagList.stream().sorted(Comparator.comparing(TEvaluationTagVO::getTagCount).reversed()).collect(Collectors.toList());
        // 统计有图,好评,中差评数量
        long imgUrlCount = this.count(Wrappers.lambdaQuery(TOrderEvaluate.class)
                .isNotNull(TOrderEvaluate::getImgUrl));
        packageTagCount(imgUrlCount,"有图",tagList);
        long goodCount = this.count(Wrappers.lambdaQuery(TOrderEvaluate.class)
                .ge(TOrderEvaluate::getMark,4));
        packageTagCount(goodCount,"好评",tagList);
        long badCount = this.count(Wrappers.lambdaQuery(TOrderEvaluate.class)
                .le(TOrderEvaluate::getMark,3));
        packageTagCount(badCount,"中差评",tagList);
        return tagList;
    }
 
    private void packageTagCount(Long count,String name,List<TEvaluationTagVO> tagList){
        if(count>0){
            TEvaluationTagVO evaluationTagVO = new TEvaluationTagVO();
            evaluationTagVO.setName(name);
            evaluationTagVO.setTagCount(Integer.parseInt(String.valueOf(count)));
            tagList.add(evaluationTagVO);
        }
    }
 
}