# TrendServiceImpl.java

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

    import cloud.wconnect.rateshop.entity.rateshop.Trend;
    import cloud.wconnect.rateshop.entity.rateshop.TrendSourceSetting;
    import cloud.wconnect.rateshop.mapper.rateshop.TrendMapper;
    import cloud.wconnect.rateshop.service.rateshop.ITrendService;
    import cloud.wconnect.rateshop.service.rateshop.ITrendSourceSettingService;
    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.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

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

    /**
     * <p>
     * Market Demand 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2023-06-08
     */
    @DS("rate_shop")
    @Service
    public class TrendServiceImpl extends ServiceImpl<TrendMapper, Trend> implements ITrendService {

        @Autowired
        private ITrendSourceSettingService trendSourceSettingService;

        /**
         * 查询指定日期内资产的需求趋势
         *
         * @param propertyId 资产Id
         * @param startDate  开始时间（yyyyMMdd）
         * @param endDate    结束时间（yyyyMMdd）
         * @return java.util.List<cloud.wconnect.rateshop.entity.rateshop.Trend>
         * @author lichen
         * @date 2024/11/25
         */
        @Override
        public List<Trend> listByDataRange(Integer propertyId, String startDate, String endDate) {
            //查询资产配置的市场趋势（目前资产只支持配置一个需求趋势源）
            List<TrendSourceSetting> trendSourceSettings = trendSourceSettingService.listByPropertyId(propertyId);
            if (CollectionUtils.isEmpty(trendSourceSettings)) return Collections.emptyList();

            //查询市场需求趋势数据
            return list(new LambdaQueryWrapper<Trend>()
                    .eq(Trend::getTrendLocationId, trendSourceSettings.get(0).getLocationId())
                    .between(Trend::getCheckInDate, startDate, endDate));
        }

        /**
         * 查询指定地址ID、指定日期的需求趋势
         *
         * @param trendLocationId 指定地址ID
         * @param startDate       开始时间（yyyyMMdd）
         * @param endDate         结束时间（yyyyMMdd）
         * @return java.util.List<cloud.wconnect.rateshop.entity.rateshop.Trend>
         * @author lichen
         * @date 2025/4/4
         */
        @Override
        public List<Trend> listByLocationIdAndDataRange(Integer trendLocationId, Long startDate, Long endDate) {
            //查询市场需求趋势数据
            return list(new LambdaQueryWrapper<Trend>()
                    .eq(Trend::getTrendLocationId, trendLocationId)
                    .between(Trend::getCheckInDate, startDate, endDate));
        }
    }