# ReviewServiceImpl.java

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

    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.rateshop.entity.reviewanalysis.Review;
    import cloud.wconnect.rateshop.mapper.reviewanalysis.ReviewMapper;
    import cloud.wconnect.rateshop.service.reviewanalysis.IReviewService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.List;
    import java.util.Objects;

    /**
     * <p>
     * 评论表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2024-12-27
     */
    @Service
    @DS("rate_shop")
    public class ReviewServiceImpl extends ServiceImpl<ReviewMapper, Review> implements IReviewService {

        /**
         * 查询评论数据
         *
         * @param propertyId 资产ID
         * @param startDate  开始日期（yyyyMMdd）
         * @param endDate    结束日期（yyyyMMdd）
         * @return java.util.List<cloud.wconnect.rateshop.entity.reviewanalysis.Review>
         * @author lichen
         * @date 2024/12/27
         */
        @Override
        public List<Review> listByDateRange(Integer propertyId, String startDate, String endDate) {
            return list(new LambdaQueryWrapper<Review>().eq(Review::getPropertyId, propertyId)
                    .between(Review::getReviewDate, startDate, endDate));
        }

        /**
         * 批量保存抓取的评论数据
         *
         * @param propertyDTO 资产DTO
         * @param reviewDate  评论时间（yyyyMMdd）
         * @param reviews     评论数据
         * @return void
         * @author lichen
         * @date 2024/12/30
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void saveBatch(PropertyDTO propertyDTO, String reviewDate, List<Review> reviews) {
            //删除资产指定日期的所有评论数据
            remove(new LambdaQueryWrapper<Review>().eq(Review::getPropertyId, propertyDTO.getId())
                    .eq(Review::getReviewDate, reviewDate));
            //批量新增
            saveBatch(reviews);
        }

        /**
         * 获取指定资产最后一次的抓取数据时间
         *
         * @param propertyId 资产id
         * @return java.lang.Long
         * @author lichen
         * @date 2025/1/18
         */
        @Override
        public Long getLastTime(Integer propertyId) {
            Review review = getOne(new LambdaQueryWrapper<Review>()
                    .eq(Review::getPropertyId, propertyId)
                    .orderByDesc(Review::getCreateTime)
                    .last("limit 1"));
            if (Objects.isNull(review)) return null;
            return review.getCreateTime();
        }
    }