# RateShopMarketSegmentSummaryServiceByOther.java

    package cloud.wconnect.rateshop.service.rateshop.marketsegmentsummary;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.SystemPlatformEnum;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.UploadUtils;
    import cloud.wconnect.rateshop.cons.S3BucketFunctionCons;
    import cloud.wconnect.rateshop.entity.rateshop.ReportImportLog;
    import cloud.wconnect.rateshop.service.AmazonS3Service;
    import cloud.wconnect.rateshop.service.rateshop.IPropertyOperationsOtherReportService;
    import cloud.wconnect.rateshop.service.rateshop.IReportImportLogService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    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.transaction.annotation.Transactional;
    import org.springframework.web.multipart.MultipartFile;

    import java.io.IOException;

    /**
     * 解析Other报告
     *
     * @author yyt
     * @date 2026/3/10
     */
    @Component
    @DS("rate_shop")
    @Slf4j
    public class RateShopMarketSegmentSummaryServiceByOther implements IRateShopMarketSegmentSummaryService {

        @Autowired
        private IPropertyOperationsOtherReportService propertyOperationsReportCommonService;
        @Autowired
        private IReportImportLogService reportImportLogService;
        @Autowired
        private AmazonS3Service amazonS3Service;

        @Value("${aws-s3.third-party.key.rate-shop.market-segment-summary}")
        private String s3FilePath;

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

        /**
         * 校验文件内容是否合法
         *
         * @param file 文件
         * @author yyt
         * @date 2024/8/14
         */
        @Override
        public void checkFile(MultipartFile file) {
            propertyOperationsReportCommonService.checkFile(file);
        }

        /**
         * 处理数据
         *
         * @param propertyDTO     资产DTO
         * @param file            文件
         * @param reportImportLog 导入记录
         * @param userId          操作人ID
         * @author yyt
         * @date 2026/3/10
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void handleData(PropertyDTO propertyDTO, MultipartFile file, ReportImportLog reportImportLog, int userId) {
            toS3(propertyDTO, file, reportImportLog);

            propertyOperationsReportCommonService.handleData(propertyDTO, file, reportImportLog, userId);
        }

        /**
         * 上传文件到S3
         *
         * @param propertyDTO     资产DTO
         * @param file            文件
         * @param reportImportLog 导入记录
         * @author yyt
         * @date 2026/3/10
         */
        private void toS3(PropertyDTO propertyDTO, MultipartFile file, ReportImportLog reportImportLog) {
            String tenantSymbol = propertyDTO.getTenantSymbol();
            String abbr = propertyDTO.getAbbr();
            String key = tenantSymbol + "/" + abbr + "/" + s3FilePath +
                    UploadUtils.getRandomFileName(file.getOriginalFilename());
            try {
                amazonS3Service.uploadFile(S3BucketFunctionCons.RATE_SHOP_IMPORT_RECORD, file, key);
                reportImportLogService.updateById(new ReportImportLog().setId(reportImportLog.getId()).setUrl(key));
            } catch (IOException e) {
                throw new BadRequestException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(), "Uploading to s3 failure", e);
            }
        }

    }