# DbAutoResolveDbManagerFlashService.java

    package cloud.wconnect.workperformance.service.database.managerflash;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.ParseReportException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.workperformance.cons.S3BucketFunctionCons;
    import cloud.wconnect.workperformance.cons.database.DbPmsReportTypeEnum;
    import cloud.wconnect.workperformance.entity.database.DbReportImportLog;
    import cloud.wconnect.workperformance.pojo.bo.database.managerflash.DbPmsManagerFlashBO;
    import cloud.wconnect.workperformance.service.AmazonS3Service;
    import cloud.wconnect.workperformance.service.database.IDbAutoResolveReportService;
    import cloud.wconnect.workperformance.service.database.IDbPmsManagerFlashService;
    import cloud.wconnect.workperformance.service.database.IDbReportImportLogService;
    import cloud.wconnect.workperformance.service.database.IDbReportService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.google.common.collect.Lists;
    import jakarta.annotation.Resource;
    import org.springframework.stereotype.Component;
    import org.springframework.transaction.annotation.Transactional;

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

    /**
     * 自动解决 Manager Flash/Service 报告
     *
     * @author zc
     * @date 2025/12/02
     */
    @Component
    @DS("database")
    public class DbAutoResolveDbManagerFlashService implements IDbAutoResolveReportService {

        @Resource
        private IDbReportImportLogService importLogService;
        @Resource
        private AmazonS3Service amazonS3Service;
        @Resource
        private IDbReportService reportService;
        @Resource
        private IDbPmsManagerFlashService managerFlashService;

        /**
         * 根据判断是否支持此报告类型
         *
         * @param reportType 报告分类
         * @return boolean
         * @author zc
         * @date 2025/12/02
         */
        @Override
        public boolean supports(int reportType) {
            return reportType == DbPmsReportTypeEnum.MANAGER_FLASH.getType();
        }

        /**
         * 解决报告异常
         *
         * @param propertyDTO 资产
         * @param importLog   导入日志
         * @param operatorId  操作人 id
         * @param source      来源
         * @author zc
         * @date 2025/12/02
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void autoResolve(PropertyDTO propertyDTO, DbReportImportLog importLog, int operatorId, String source) {
            // 处理是否成功
            boolean handleResult = true;
            try (InputStream in = amazonS3Service.getFile(S3BucketFunctionCons.DATABASE_IMPORT_RECORD, importLog.getUrl())) {
                List<Long> dateRange = Lists.newArrayList(importLog.getStartDate(), importLog.getEndDate());
                // 解析报告
                DbPmsManagerFlashBO bo = reportService.parseManagerFlashReport(propertyDTO, in, source, dateRange);
                // 处理报告
                managerFlashService.handle(propertyDTO, bo, operatorId);
            } catch (Exception e) {
                handleResult = false;
                throw new ParseReportException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(),
                        "Auto Resolve Database Manager Flash report error, source=" + source, e);
            } finally {
                // 更新导入记录
                importLogService.autoSolve(importLog.getId(), handleResult, operatorId);
            }
        }
    }