# RateShopHistoryAndForecastServiceByPep.java

    package cloud.wconnect.rateshop.service.rateshop.historyandforecast;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.SystemPlatformEnum;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.exception.InternalServerErrorException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.FileCheckUtils;
    import cloud.wconnect.commonlib.util.PepFileCheckUtils;
    import cloud.wconnect.commonlib.util.UploadUtils;
    import cloud.wconnect.rateshop.cons.EventSubjectEnum;
    import cloud.wconnect.rateshop.entity.rateshop.ReportImportLog;
    import cloud.wconnect.rateshop.service.rateshop.IRateShopReportCommonService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.google.common.collect.Lists;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Component;
    import org.springframework.web.multipart.MultipartFile;

    import java.io.InputStream;

    /**
     * 解析 History And Forecast 报告
     *
     * @author yyt
     * @date 2026/3/10
     */
    @Component
    @DS("rate_shop")
    @Slf4j
    public class RateShopHistoryAndForecastServiceByPep implements IRateShopHistoryAndForecastService {

        @Autowired
        private IRateShopReportCommonService rateShopReportCommonService;

        @Value("${aws-s3.third-party.key.rate-shop.history-and-forecast}")
        private String s3FilePath;

        @Value("${file-max-size.import-report.rate-shop}")
        private long fileMaxSize;

        /**
         * 支持的报告来源
         *
         * @param source 报告来源
         * @return boolean
         * @author yyt
         * @date 2026/3/10
         */
        @Override
        public boolean supports(String source) {
            return SystemPlatformEnum.PEP.getDesc().equals(source);
        }

        /**
         * 校验文件内容是否合法
         *
         * @param file 文件
         * @author yyt
         * @date 2026/3/10
         */
        @Override
        public void checkFile(MultipartFile file) {
            // 限制文件大小
            FileCheckUtils.checkFileSize(file, fileMaxSize);
            //校验文件格式
            UploadUtils.checkFileFormat(file, Lists.newArrayList("csv"));
            //校验文件内容
            try (InputStream inputStream = file.getInputStream()) {
                PepFileCheckUtils.checkOccupancyForecast(inputStream);
            } catch (BadRequestException exception) {
                throw exception;
            } catch (Exception e2) {
                throw new InternalServerErrorException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(), "Check pep [History And Forecast] report error", e2);
            }
        }

        /**
         * 处理数据
         *
         * @param propertyDTO     资产DTO
         * @param file            文件
         * @param reportImportLog 导入记录
         * @param userId          操作人ID
         * @author yyt
         * @date 2026/3/10
         */
        @Override
        public void handleData(PropertyDTO propertyDTO, MultipartFile file, ReportImportLog reportImportLog,  int userId) {
            rateShopReportCommonService.sendReportEvent(propertyDTO, EventSubjectEnum.HISTORY_AND_FORECAST_SERVICE_YESTERDAY_NINETY_DAY.getSubject(), s3FilePath, file, reportImportLog, userId);
        }
    }