zhibing.pu
2024-08-10 c3363d35b8dd42a862681d505360cd2c72d070a1
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.ruoyi.order.service.impl;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.chargingPile.api.vo.TAccountingStrategyVO;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.order.api.model.TChargingOrder;
import com.ruoyi.order.api.model.TOrderEvaluate;
import com.ruoyi.order.api.query.TOrderEvaluateQuery;
import com.ruoyi.order.api.vo.TOrderEvaluateVO;
import com.ruoyi.order.mapper.TChargingOrderMapper;
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 org.springframework.util.CollectionUtils;
 
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;
    @Autowired
    private TChargingOrderMapper chargingOrderMapper;
    @Override
    public List<TEvaluationTagVO> getTagCount() {
        // 查询标签列表
        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;
    }
 
    @Override
    public PageInfo<TOrderEvaluateVO> getTagList(TOrderEvaluateQuery query) {
        PageInfo<TOrderEvaluateVO> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize());
        // 查询站点下的所有订单
        List<TChargingOrder> tChargingOrders = chargingOrderMapper.selectList(Wrappers.lambdaQuery(TChargingOrder.class)
                .eq(TChargingOrder::getSiteId, query.getSiteId()));
        if(CollectionUtils.isEmpty(tChargingOrders)){
            return new PageInfo<>();
        }
        List<Long> orderIds = tChargingOrders.stream().map(TChargingOrder::getId).collect(Collectors.toList());
        query.setOrderIds(orderIds);
        List<TOrderEvaluateVO> list = this.baseMapper.pageList(query,pageInfo);
        pageInfo.setRecords(list);
        return pageInfo;
    }
 
    /**
     * 统计有图,好评,中差评数量
     * @param count
     * @param name
     * @param 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);
        }
    }
 
}