# OooRoomHandleFileServiceImpl.java

    package cloud.wconnect.frontoffice.service.oooroom.impl;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.EventBodyParamEnum;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.bo.SymbolBO;
    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.frontoffice.cons.BusinessEnum;
    import cloud.wconnect.frontoffice.cons.EventSubjectEnum;
    import cloud.wconnect.frontoffice.entity.oooroom.OooImportLog;
    import cloud.wconnect.frontoffice.service.AmazonS3Service;
    import cloud.wconnect.frontoffice.service.oooroom.IOooRoomHandleFileService;
    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.Qualifier;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Service;
    import org.springframework.web.multipart.MultipartFile;

    import java.util.Map;

    /**
     *
     * @author: yyt
     * 2026-01-29
     */
    @Service
    @DS("ratelog_manage")
    public class OooRoomHandleFileServiceImpl implements IOooRoomHandleFileService {

        private final AmazonS3Service amazonS3Service;
        private final Sender snsSender;
        private final ObjectMapper objectMapper;

        public OooRoomHandleFileServiceImpl(AmazonS3Service amazonS3Service, @Qualifier("3pSender") Sender snsSender,
                                            ObjectMapper objectMapper) {
            this.amazonS3Service = amazonS3Service;
            this.snsSender = snsSender;
            this.objectMapper = objectMapper;
        }

        @Value("${aws-s3.third-party.key.ooo-room.out-of-order}")
        private String operaOutOfOrderS3key;

        /**
         * 发送 out of order 报告事件
         *
         * @param tenantBO    租户信息
         * @param propertyDTO 资产信息
         * @param file        文件信息
         * @param pms         pms 类型
         * @param importLog   导入记录
         * @param userId      操作人
         * @author yyt
         * @date 2026/1/29
         **/
        @Override
        public void sendOutOfOrderEvent(SymbolBO tenantBO, PropertyDTO propertyDTO, MultipartFile file, String pms, OooImportLog importLog, Integer userId) {
            try {
                // 设置事件体
                Map<String, Object> params = Maps.newHashMapWithExpectedSize(7);
                params.put(EventBodyParamEnum.TENANT_SYMBOL.getDesc(), tenantBO.getSymbol());
                params.put(EventBodyParamEnum.PROPERTY_ABBR.getDesc(), Lists.newArrayList(propertyDTO.getAbbr()));
                params.put(EventBodyParamEnum.SOURCE.getDesc(), pms);
                params.put(EventBodyParamEnum.UID.getDesc(), userId);
                params.put(EventBodyParamEnum.ID.getDesc(), importLog.getId());
                params.put(EventBodyParamEnum.DATE.getDesc(), importLog.getTheDate());
                params.put(EventBodyParamEnum.ORIGINATE_FROM.getDesc(), BusinessEnum.OUT_OF_ORDER.getBusiness());

                // 上传文件
                String key = tenantBO.getSymbol() + "/" + propertyDTO.getAbbr() + "/" + operaOutOfOrderS3key +
                        UploadUtils.getRandomFileName(file.getOriginalFilename());
                amazonS3Service.uploadFile(file, key);

                snsSender.publish(EventSubjectEnum.OUT_OF_ORDER.getSubject(),
                        JsonUtils.convertObjToString(objectMapper, new EventBodyDTO(key, params)));
            } catch (Exception e) {
                throw new BadRequestException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(), "Failed to send out of order report event", e);
            }
        }
    }