# WMRevenueAutoResolveCancellationSummaryMissService.java

    package cloud.wconnect.rateshop.service.weeklymonthlyrevenue.cancellationsummary;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.ParseReportException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.rateshop.cons.S3BucketFunctionCons;
    import cloud.wconnect.rateshop.cons.weeklymonthlyrevenue.MonthlyRevenueReportCategoryEnum;
    import cloud.wconnect.rateshop.entity.weeklymonthlyrevenue.WeeklyMonthlyRevenueImportLog;
    import cloud.wconnect.rateshop.pojo.bo.weeklymonthlyrevenue.WMRevenueCancellationSummaryBO;
    import cloud.wconnect.rateshop.service.AmazonS3Service;
    import cloud.wconnect.rateshop.service.weeklymonthlyrevenue.IWMRevenueAutoResolveReportMissService;
    import cloud.wconnect.rateshop.service.weeklymonthlyrevenue.IWeeklyMonthlyRevenueImportLogService;
    import cloud.wconnect.rateshop.service.weeklymonthlyrevenue.IWeeklyMonthlyRevenueReportService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.google.common.collect.Lists;
    import jakarta.annotation.Resource;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;

    import java.io.InputStream;
    import java.util.List;

    /**
     * Cancelltion Summary报告缺失，自动解决类
     *
     * @author lichen
     * @date 2025/12/12
     */
    @Slf4j
    @Component
    @DS("rate_shop")
    public class WMRevenueAutoResolveCancellationSummaryMissService implements IWMRevenueAutoResolveReportMissService {

        @Resource
        private IWeeklyMonthlyRevenueReportService reportService;
        @Resource
        private AmazonS3Service amazonS3Service;
        @Autowired
        private IWeeklyMonthlyRevenueImportLogService importLogService;

        /**
         * 根据来源和分类判断是否支持此报告
         *
         * @param reportType 报告分类
         * @return boolean
         * @author lichen
         * @date 2025/12/12
         */
        @Override
        public boolean supportsByReportType(int reportType) {
            return reportType == MonthlyRevenueReportCategoryEnum.CANCELLATION_SUMMARY.getCategory();
        }

        /**
         * 自动解决报告缺失的异常
         *
         * @param propertyDTO 资产
         * @param importLog   导入日志
         * @param operatorId  操作人 id
         * @param source      来源
         * @author lichen
         * @date 2025/12/12
         */
        @Override
        public void autoResolve(PropertyDTO propertyDTO, WeeklyMonthlyRevenueImportLog importLog, int operatorId, String source) {
            boolean handleResult = true;
            String url = importLog.getUrl();
            //从S3下载文件
            try (InputStream in = amazonS3Service.getFile(S3BucketFunctionCons.WEEKLY_MONTHLY_REVENUE_IMPORT_RECORD, url)) {
                List<Long> dateRange = Lists.newArrayList(importLog.getStartDate(), importLog.getEndDate());
                // 解析报告
                List<WMRevenueCancellationSummaryBO> boList = reportService.parseCancellationSummaryReport(propertyDTO, in, source, dateRange);
                // 处理报告
                reportService.handleCancellationSummary(propertyDTO, boList, operatorId);
            } catch (Exception e) {
                handleResult = false;
                throw new ParseReportException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(),
                        "Auto Resolve Weekly Monthly Revenue Cancelltion Summary report error, source=" + source, e);
            } finally {
                // 更新导入记录
                importLogService.autoSolve(importLog.getId(), handleResult, operatorId);
            }
        }
    }