# RateShopReportCommonServiceImpl.java

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

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.EventBodyParamEnum;
    import cloud.wconnect.commonlib.exception.InternalServerErrorException;
    import cloud.wconnect.commonlib.pojo.dto.EventBodyDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.commonlib.util.UploadUtils;
    import cloud.wconnect.rateshop.cons.BusinessEnum;
    import cloud.wconnect.rateshop.entity.rateshop.ReportImportLog;
    import cloud.wconnect.rateshop.service.AmazonS3Service;
    import cloud.wconnect.rateshop.service.rateshop.IRateShopReportCommonService;
    import cloud.wconnect.sns.http.processor.Sender;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.google.common.collect.Lists;
    import com.google.common.collect.Maps;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.stereotype.Service;
    import org.springframework.web.multipart.MultipartFile;

    import java.util.Map;

    /**
     *
     * @author: yyt
     * 2026-03-10
     */
    @DS("rate_shop")
    @Service
    public class RateShopReportCommonServiceImpl implements IRateShopReportCommonService {

        @Autowired
        private AmazonS3Service amazonS3Service;
        @Autowired
        private ObjectMapper objectMapper;

        @Autowired
        @Qualifier("3pSender")
        private Sender snsSender;

        /**
         * 发送报告事件
         *
         * @param propertyDTO     资产
         * @param subject         subject
         * @param businessKey     business key
         * @param file            报告
         * @param reportImportLog 导入记录
         * @param userId          操作人
         */
        @Override
        public void sendReportEvent(PropertyDTO propertyDTO, String subject, String businessKey, MultipartFile file, ReportImportLog reportImportLog, int userId) {
            try {
                String key = propertyDTO.getTenantSymbol() + "/" + propertyDTO.getAbbr() + "/" + businessKey
                        + UploadUtils.getRandomFileName(file.getOriginalFilename());
                // 上传报告到 S3 服务器，用于事件监听解析报告
                amazonS3Service.uploadFile(file, key);

                // 设置事件体
                Map<String, Object> params = Maps.newHashMapWithExpectedSize(7);
                params.put(EventBodyParamEnum.TENANT_SYMBOL.getDesc(), propertyDTO.getTenantSymbol());
                params.put(EventBodyParamEnum.PROPERTY_ABBR.getDesc(), Lists.newArrayList(propertyDTO.getAbbr()));
                params.put(EventBodyParamEnum.SOURCE.getDesc(), propertyDTO.getPmsType());
                params.put(EventBodyParamEnum.ORIGINATE_FROM.getDesc(), BusinessEnum.RATE_SHOP.getBusiness());
                params.put(EventBodyParamEnum.UID.getDesc(), userId);
                params.put(EventBodyParamEnum.ID.getDesc(), reportImportLog.getId());
                params.put(EventBodyParamEnum.START_DATE.getDesc(), reportImportLog.getStartDate());
                params.put(EventBodyParamEnum.END_DATE.getDesc(), reportImportLog.getEndDate());

                snsSender.publish(subject, JsonUtils.convertObjToString(objectMapper, new EventBodyDTO(key, params)));
            } catch (Exception e) {
                throw new InternalServerErrorException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(), "send report event exception", e);
            }
        }

    }