# StatisticsReviewsByNightsImpl.java

    package cloud.wconnect.rateshop.service.reviewanalysis.impl;

    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.rateshop.cons.reviewanalysis.ReviewAnalysisCons;
    import cloud.wconnect.rateshop.entity.reviewanalysis.Review;
    import cloud.wconnect.rateshop.pojo.dto.reviewanalysis.GroupStatisticsReviewDTO;
    import cloud.wconnect.rateshop.service.reviewanalysis.IStatisticsReview;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.stereotype.Service;

    import java.util.Collections;
    import java.util.List;

    /**
     * 不同时间单位下，不同入住时长的评论数占比与总数对比（统计字段为date、nights）
     *
     * @author lichen
     * @date 2024/12/28
     */
    @Service
    @DS("rate_shop")
    public class StatisticsReviewsByNightsImpl implements IStatisticsReview {

        /**
         * 判断是否支持此统计类型
         *
         * @param type 统计类型
         * @return boolean
         * @author lichen
         * @date 2024/12/27
         */
        @Override
        public boolean supports(int type) {
            return ReviewAnalysisCons.REVIEWS_BY_NIGHTS == type;
        }

        /**
         * 统计数据
         *
         * @param propertyDTO         资产DTO
         * @param reviews             评论数据集合
         * @param statisticsDimension 统计维度 1-月 2-周 3-日
         * @return java.util.List<cloud.wconnect.rateshop.pojo.dto.reviewanalysis.StatisticsReviewDTO>
         * @author lichen
         * @date 2024/12/27
         */
        @Override
        public List<GroupStatisticsReviewDTO> statistics(PropertyDTO propertyDTO, List<Review> reviews, Integer statisticsDimension) {
            if (CollectionUtils.isEmpty(reviews)) return Collections.emptyList();
            //根据date、room进行统计
            return IStatisticsReview.statisticsByDateAndGroupField(propertyDTO, reviews, "nights", statisticsDimension);
        }
    }