# WMRevenueManagerFlashParseServiceByOther.java

    package cloud.wconnect.rateshop.service.weeklymonthlyrevenue.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.util.CellUtils;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.InternationalizationUtils;
    import cloud.wconnect.rateshop.pojo.bo.weeklymonthlyrevenue.WMRevenueManagerFlashBO;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.google.common.collect.Lists;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.lang3.StringUtils;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.ss.usermodel.WorkbookFactory;
    import org.springframework.stereotype.Component;

    import java.io.IOException;
    import java.io.InputStream;
    import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.util.ArrayList;
    import java.util.List;

    /**
     * 解析 Other 的 Manager Flash/Service 报告
     *
     * @author lichen
     * @date 2025/12/12
     */
    @Slf4j
    @Component
    @DS("rate_shop")
    public class WMRevenueManagerFlashParseServiceByOther implements IWMRevenueManagerFlashParseService {

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

        /**
         * 解析报告
         *
         * @param propertyDTO 资产
         * @param in          报告文件流
         * @param dateRange   报告数据日期范围(yyyyMMdd)
         * @return WMRevenueCancellationSummaryBO 集合
         * @author lichen
         * @date 2025/12/12
         */
        @Override
        public List<WMRevenueManagerFlashBO> parse(PropertyDTO propertyDTO, InputStream in, List<Long> dateRange) throws ParseReportException {
            try (Workbook workbook = WorkbookFactory.create(in)) {
                long startDate = dateRange.get(0);
                long endDate = dateRange.get(1);

                RoundingMode roundingMode = InternationalizationUtils.getRoundingMode(propertyDTO
                        .getInternationalization().getNumber().getCalculationRule());

                Sheet sheet = workbook.getSheetAt(0);
                // 获取最大行数
                int lastRowNum = sheet.getLastRowNum();
                ArrayList<WMRevenueManagerFlashBO> boList = Lists.newArrayListWithCapacity(lastRowNum);

                for (int i = 1; i <= lastRowNum; i++) {
                    Row row = sheet.getRow(i);

                    // Date
                    String dateStr = CellUtils.convertCellStr(row.getCell(0));
                    long date = Long.parseLong(DateTimeUtils.localDateToStr(DateTimeUtils.strToLocalDate(dateStr,
                            BaseConstant.DATE_FORMAT_YYYY_MM_DD), BaseConstant.DATE_FORMAT_YYYYMMDD));
                    // 判断数据日期是否在开始日期 和 结束日期之间
                    if (date < startDate || date > endDate) {
                        continue;
                    }

                    boList.add(convert2Bo(row, roundingMode));
                }

                return boList;
            } catch (IOException e) {
                log.error(e.getMessage(), e);
                throw new InternalServerErrorException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(),
                        "Handle parse Weekly Monthly Revenue Manager Flash Other report error.", e);
            }
        }

        /**
         * 转换为BO
         *
         * @param row          行
         * @param roundingMode 舍入模式
         * @return cloud.wconnect.rateshop.pojo.bo.weeklymonthlyrevenue.WMRevenueManagerFlashBO
         * @author lichen
         * @date 2025/12/15
         */
        private WMRevenueManagerFlashBO convert2Bo(Row row, RoundingMode roundingMode) {
            WMRevenueManagerFlashBO bo = new WMRevenueManagerFlashBO();

            int scale = BaseConstant.DATA_PRECISION;
            String dateStr = CellUtils.convertCellStr(row.getCell(0));
            bo.setTheDay(dateStr);

            // Occ
            String occStr = CellUtils.convertCellStr(row.getCell(1));
            bo.setOcc(StringUtils.isEmpty(occStr) ? null : new BigDecimal(occStr)
                    .setScale(scale, roundingMode));

            // ADR
            String adrStr = CellUtils.convertCellStr(row.getCell(2));
            bo.setAdr(StringUtils.isEmpty(adrStr) ? null : new BigDecimal(adrStr)
                    .setScale(scale, roundingMode));

            // Comp room
            String compRoomStr = CellUtils.convertCellStr(row.getCell(3));
            bo.setComplimentaryRooms(StringUtils.isBlank(compRoomStr) ? null : Integer.parseInt(compRoomStr));

            // No Show
            String noShowStr = CellUtils.convertCellStr(row.getCell(4));
            bo.setNoShowRooms(StringUtils.isBlank(noShowStr) ? null : Integer.parseInt(noShowStr));

            // OOO Rooms
            String oooRoomsStr = CellUtils.convertCellStr(row.getCell(5));
            bo.setOoo(StringUtils.isBlank(oooRoomsStr) ? null : Integer.parseInt(oooRoomsStr));

            // Room revenue
            String roomRevenueStr = CellUtils.convertCellStr(row.getCell(6));
            bo.setRoomRevenue(StringUtils.isEmpty(roomRevenueStr) ? null :
                    new BigDecimal(roomRevenueStr).setScale(scale, roundingMode));

            // Rooms Occupied
            String roomsSoldStr = CellUtils.convertCellStr(row.getCell(7));
            bo.setRoomsSold(StringUtils.isBlank(roomsSoldStr) ? null : Integer.parseInt(roomsSoldStr));

            // Total Rooms
            String totalRoomsStr = CellUtils.convertCellStr(row.getCell(8));
            bo.setTotalRooms(StringUtils.isBlank(totalRoomsStr) ? null : Integer.parseInt(totalRoomsStr));
            return bo;
        }
    }