# ManagerFlashParseImplByShiji.java

    package cloud.wconnect.rateshop.service.revenue.managerflash;

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.SystemPlatformEnum;
    import cloud.wconnect.commonlib.exception.InternalServerErrorException;
    import cloud.wconnect.commonlib.exception.ParseReportException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.internationalization.InternationalizationNumberDTO;
    import cloud.wconnect.commonlib.util.InternationalizationUtils;
    import cloud.wconnect.commonlib.util.ShijiFileCheckUtils;
    import cloud.wconnect.rateshop.pojo.dto.revenue.ManagerFlashDTO;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.csv.CSVFormat;
    import org.apache.commons.csv.CSVRecord;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.stereotype.Service;

    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.util.Iterator;

    /**
     * Manager Flash报告的Shiji解析实现类
     *
     * @author lichen
     * @date 2025/7/5
     */
    @Service
    @Slf4j
    @DS("rate_shop")
    public class ManagerFlashParseImplByShiji implements IManagerFlashParse {

        /**
         * 判断支持的平台
         *
         * @param source 来源系统
         * @return boolean
         * @author lichen
         * @date 2025/7/5
         */
        @Override
        public boolean supports(String source) {
            return SystemPlatformEnum.SHI_JI.getDesc().equals(source);
        }

        /**
         * 解析报告
         *
         * @param in          报告文件流
         * @param propertyDTO 资产DTO
         * @return cloud.wconnect.rateshop.pojo.dto.revenue.ManagerFlashDTO
         * @author lichen
         * @date 2025/7/5
         */
        @Override
        public ManagerFlashDTO parse(InputStream in, PropertyDTO propertyDTO) throws ParseReportException {
            InternationalizationNumberDTO number = propertyDTO.getInternationalization().getNumber();
            RoundingMode roundingMode = InternationalizationUtils.getRoundingMode(number.getCalculationRule());
            try (InputStreamReader inputStreamReader = new InputStreamReader(in)) {
                ManagerFlashDTO managerFlashBO = new ManagerFlashDTO();
                //获取CSV数据迭代器
                Iterable<CSVRecord> iterable = CSVFormat.EXCEL.parse(inputStreamReader);
                Iterator<CSVRecord> iterator = iterable.iterator();

                //跳过标题行
                iterator.next();

                while (iterator.hasNext()) {
                    CSVRecord csvRecord = iterator.next();

                    String description = ShijiFileCheckUtils.get(csvRecord, "A");

                    if ("ADR".equalsIgnoreCase(description)) {
                        //Day CY
                        String value = ShijiFileCheckUtils.getAndFormatNumber(csvRecord, "B");
                        BigDecimal adr = StringUtils.isEmpty(value) ? null : new BigDecimal(value)
                                .setScale(BaseConstant.DATA_PRECISION, roundingMode);
                        managerFlashBO.setAdr(adr);
                    } else if ("No Show - Rooms".equalsIgnoreCase(description)) {
                        //Day CY
                        String value = ShijiFileCheckUtils.getAndFormatNumber(csvRecord, "B");
                        Integer noShow = StringUtils.isEmpty(value) ? null : Integer.valueOf(value);
                        managerFlashBO.setNoShow(noShow);
                    } else if ("Cancellations Made Today for Current Business Date - Rooms".equalsIgnoreCase(description)) {
                        //Day CY
                        String value = ShijiFileCheckUtils.getAndFormatNumber(csvRecord, "B");
                        Integer cancelled = StringUtils.isEmpty(value) ? null : Integer.valueOf(value);
                        managerFlashBO.setCancelled(cancelled);
                    }
                }
                return managerFlashBO;
            } catch (IOException e) {
                throw new InternalServerErrorException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(),
                        "Daily Revenue parse shiji [Manager Flash] report error", e);
            }
        }

    }