# WMRevenueReservationForecastParseServiceByOther.java

    package cloud.wconnect.rateshop.service.weeklymonthlyrevenue.reservationforecast;

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.SystemPlatformEnum;
    import cloud.wconnect.commonlib.exception.ParseReportException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.*;
    import cloud.wconnect.rateshop.pojo.bo.weeklymonthlyrevenue.WMRevenueReservationForecastBO;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.google.common.collect.Lists;
    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.time.LocalDate;
    import java.util.List;

    /**
     * 解析 Other 的 Reservation Forecast/Service 报告
     *
     * @author zc
     * @date 2024/05/20
     */
    @Component
    @DS("rate_shop")
    public class WMRevenueReservationForecastParseServiceByOther implements IWMRevenueReservationForecastParseService {

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

        /**
         * 解析报告
         *
         * @param in          报告文件流
         * @param propertyDTO 资产
         * @param dateRange   报告数据日期范围(yyyyMMdd)
         * @return WMRevenueReservationForecastBO 集合
         * @author zc
         * @date 2024/8/22
         */
        @Override
        public List<WMRevenueReservationForecastBO> parse(PropertyDTO propertyDTO, InputStream in, List<Long> dateRange) throws ParseReportException {
            RoundingMode roundingMode = InternationalizationUtils.getRoundingMode(propertyDTO
                    .getInternationalization().getNumber().getCalculationRule());
            int scale = BaseConstant.DATA_PRECISION;
            try(Workbook workbook = WorkbookFactory.create(in)) {
                List<WMRevenueReservationForecastBO> reservationForecastBOList = Lists.newArrayList();

                long startDate = dateRange.get(0);
                long endDate = dateRange.get(1);

                Sheet sheet = workbook.getSheetAt(0);
                // 跳过第 0 行标题
                for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                    Row row = sheet.getRow(i);

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

                    WMRevenueReservationForecastBO reservationForecastBO = new WMRevenueReservationForecastBO();
                    reservationForecastBO.setTheDay(theDateStr);
                    // Transient Rooms Sold
                    String transientSoldStr = CellUtils.convertCellStr(row.getCell(1));
                    Integer transientSold = StringUtils.isBlank(transientSoldStr) ? null : Integer.parseInt(transientSoldStr);
                    reservationForecastBO.setTransientSold(transientSold);
                    // Transient Revenue
                    String transientRevenueStr = CellUtils.convertCellStr(row.getCell(2));
                    BigDecimal transientRevenue = StringUtils.isBlank(transientRevenueStr) ? null :
                            new BigDecimal(transientRevenueStr).setScale(scale, roundingMode);
                    reservationForecastBO.setTransientRevenue(transientRevenue);
                    // Group Rooms Sold
                    String groupSoldStr = CellUtils.convertCellStr(row.getCell(3));
                    Integer groupSold = StringUtils.isBlank(groupSoldStr) ? null : Integer.parseInt(groupSoldStr);
                    reservationForecastBO.setGroupSold(groupSold);
                    // Group Revenue
                    String groupRevenueStr = CellUtils.convertCellStr(row.getCell(4));
                    BigDecimal groupRevenue = StringUtils.isBlank(groupRevenueStr) ? null :
                            new BigDecimal(groupRevenueStr).setScale(scale, roundingMode);
                    reservationForecastBO.setGroupRevenue(groupRevenue);
                    // Contract Rooms Sold
                    String contractSoldStr = CellUtils.convertCellStr(row.getCell(5));
                    Integer contractSold = StringUtils.isBlank(contractSoldStr) ? null : Integer.parseInt(contractSoldStr);
                    reservationForecastBO.setContractSold(contractSold);
                    // Contract Revenue
                    String contractRevenueStr = CellUtils.convertCellStr(row.getCell(6));
                    BigDecimal contractRevenue = StringUtils.isBlank(contractRevenueStr) ? null :
                            new BigDecimal(contractRevenueStr).setScale(scale, roundingMode);
                    reservationForecastBO.setContractRevenue(contractRevenue);

                    reservationForecastBOList.add(reservationForecastBO);
                }

                return reservationForecastBOList;
            } catch (IOException e) {
                throw new ParseReportException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(),
                        "Handle parse Weekly Monthly Revenue Reservation Forecast Other report error.", e);
            }
        }

    }