xuhy
2024-08-10 d378b55981bca01371325eeb4e9e60483ff7d609
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
@@ -1,10 +1,21 @@
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>
@@ -17,4 +28,46 @@
@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);
        }
    }
}