# ManagerFlashParseImplByPep.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.CsvFileUtils;
    import cloud.wconnect.commonlib.util.InternationalizationUtils;
    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 报告的 PPP 解析实现类
     *
     * @author yyt
     * @date 2026/3/4
     */
    @Service
    @Slf4j
    @DS("rate_shop")
    public class ManagerFlashParseImplByPep implements IManagerFlashParse {

        /**
         * 判断支持的平台
         *
         * @param source 来源系统
         * @return boolean
         * @author yyt
         * @date 2026/3/4
         */
        @Override
        public boolean supports(String source) {
            return SystemPlatformEnum.PEP.getDesc().equals(source);
        }

        /**
         * 解析报告
         *
         * @param in          报告文件流
         * @param propertyDTO 资产DTO
         * @return cloud.wconnect.rateshop.pojo.dto.revenue.ManagerFlashDTO
         * @author yyt
         * @date 2026/3/4
         */
        @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 = CsvFileUtils.get(csvRecord, "A");

                    if ("ADR INCLUDING COMP, HOUSE USE ROOMS".equalsIgnoreCase(description)) {
                        //Day CY
                        String value = CsvFileUtils.getAndFormatNumber(csvRecord, "B");
                        BigDecimal adr = StringUtils.isEmpty(value) ? null : new BigDecimal(value)
                                .setScale(BaseConstant.DATA_PRECISION, roundingMode);
                        managerFlashBO.setAdr(adr);
                    } else if ("NO SHOWS".equalsIgnoreCase(description)) {
                        //Day CY
                        String value = CsvFileUtils.getAndFormatNumber(csvRecord, "B");
                        Integer noShow = StringUtils.isEmpty(value) ? null : Integer.valueOf(value);
                        managerFlashBO.setNoShow(noShow);
                    } else if ("CANCELLATIONS FOR TODAY".equalsIgnoreCase(description)) {
                        //Day CY
                        String value = CsvFileUtils.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 pep [Manager Flash] report error", e);
            }
        }

    }