# HotelKpiMetricsOccService.java

    package cloud.wconnect.workperformance.service.hotelkpi.impl.metrics;

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.service.RoomsConfigInternalService;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.InternationalizationUtils;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.commonlib.util.YearMonthUtils;
    import cloud.wconnect.workperformance.cons.hotelkpi.*;
    import cloud.wconnect.workperformance.entity.hotelkpi.*;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.budgetdb.HotelKpiBudgetDatabaseDTO;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.kpiv2.HotelKpiMonthlyReportFieldConfigDTO;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.originkpi.HotelKpiOriginCalculationFactorDTO;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.originkpi.HotelKpiOriginCrawlValueIndexDTO;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.originkpiv2.HotelKpiV2OriginDetailDTO;
    import cloud.wconnect.workperformance.service.hotelkpi.*;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.google.common.collect.Lists;
    import jakarta.annotation.Resource;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.time.DayOfWeek;
    import java.time.LocalDate;
    import java.time.YearMonth;
    import java.time.ZoneId;
    import java.time.temporal.TemporalAdjusters;
    import java.util.List;
    import java.util.Map;
    import java.util.Objects;
    import java.util.function.Function;
    import java.util.stream.Collectors;

    /**
     * @author zc
     * @date 2025/08/20
     */
    @Service
    @DS("work_performance")
    public class HotelKpiMetricsOccService implements IHotelKpiMetricsService {

        @Resource
        private IHotelKpiService hotelKpiService;
        @Resource
        private IHotelKpiWeeklyService weeklyService;
        @Resource
        private IHotelKpiMonthlyService monthlyService;
        @Resource
        private IHotelKpiQuarterlyService quarterlyService;
        @Resource
        private IHotelKpiYearlyService yearlyService;
        @Resource
        private RoomsConfigInternalService roomsConfigInternalService;
        @Resource
        private IHotelKpiBudgetDatabaseService budgetDatabaseService;
        @Resource
        private IHotelKpiWconnectMonthlyReportService monthlyReportService;
        @Resource
        private IHotelKpiMonthlyReportFieldConfigService monthlyReportFieldConfigService;
        @Resource
        private IHotelKpiMetricsConfigService metricsConfigService;
        @Resource
        private IHotelKpiWeekStartDayService weekStartDayService;
        @Resource
        private IHotelKpiManagerFlashService managerFlashService;
        @Resource
        private IHotelKpiWconnectMonthlyRevenueService monthlyRevenueService;
        @Resource
        private ObjectMapper objectMapper;

        private static final int METRICS_TYPE = HotelKpiMetricsEnum.OCC.getMetricsType();

        /**
         * 支持的指标类型
         *
         * @param metricsType 指标类型
         * @return boolean
         * @author zc
         * @date 2025/8/20
         */
        @Override
        public boolean supports(int metricsType) {
            return METRICS_TYPE == metricsType;
        }

        /**
         * 初始化数据
         *
         * @param propertyDTO  资产
         * @param nowLocalDate 当前日期
         * @author zc
         * @date 2025/9/12
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void initData(PropertyDTO propertyDTO, LocalDate nowLocalDate) {
            HotelKpiMetricsConfig metricsConfig = metricsConfigService.getMetricsConfigByTypeForUpdate(propertyDTO.getId(), METRICS_TYPE);
            if (Objects.isNull(metricsConfig)) {
                return;
            }
            initWeekly(propertyDTO, nowLocalDate, metricsConfig);
            initMonthly(propertyDTO, nowLocalDate, metricsConfig);
            initQuarterly(propertyDTO, nowLocalDate, metricsConfig);
            initYearly(propertyDTO, nowLocalDate, metricsConfig);
        }

        /**
         * 初始化 for Weekly
         *
         * @param propertyDTO   资产
         * @param nowLocalDate  当前时间
         * @param metricsConfig 指标配置
         * @author zc
         * @date 2025/9/11
         */
        private void initWeekly(PropertyDTO propertyDTO, LocalDate nowLocalDate, HotelKpiMetricsConfig metricsConfig) {
            // 当前日期若是周起始日，则生成上一周期的数据
            DayOfWeek dayOfWeek = weekStartDayService.getWeekStartDay(propertyDTO.getId());
            if (nowLocalDate.getDayOfWeek().compareTo(dayOfWeek) != 0) {
                return;
            }
            // 获取上一周期的起始日期
            LocalDate lastWeekStartLocalDate = nowLocalDate.minusDays(7);
            // 设置数据
            setWeekly(propertyDTO, lastWeekStartLocalDate, lastWeekStartLocalDate, metricsConfig);
        }

        /**
         * 初始化 for Monthly
         *
         * @param propertyDTO   资产
         * @param nowLocalDate  当前时间
         * @param metricsConfig 指标配置
         * @author zc
         * @date 2025/9/11
         */
        private void initMonthly(PropertyDTO propertyDTO, LocalDate nowLocalDate, HotelKpiMetricsConfig metricsConfig) {
            // 获取当前日期，如果不是当月第一天，则不处理
            if (nowLocalDate.getDayOfMonth() != 1) {
                return;
            }
            // 当前时间生成上一周期数据，需要减去一个月
            LocalDate lastMonthLocalDate = nowLocalDate.minusMonths(1);
            // 设置数据
            setMonthly(propertyDTO, lastMonthLocalDate, lastMonthLocalDate, metricsConfig);
        }

        /**
         * 初始化 for Quarterly
         *
         * @param propertyDTO   资产
         * @param nowLocalDate  当前时间
         * @param metricsConfig 指标配置
         * @author zc
         * @date 2025/9/11
         */
        private void initQuarterly(PropertyDTO propertyDTO, LocalDate nowLocalDate, HotelKpiMetricsConfig metricsConfig) {
            LocalDate firstLocalDateOfQuarter = LocalDate.of(nowLocalDate.getYear(),
                    nowLocalDate.getMonth().firstMonthOfQuarter(), 1);
            // 获取当前日期，若不是季度的第一天，则不处理
            if (!firstLocalDateOfQuarter.isEqual(nowLocalDate)) {
                return;
            }
            // 当前时间生成上一周期数据，需要减去3个月
            LocalDate lastQuarterLocalDate = nowLocalDate.minusMonths(3);
            // 设置数据
            setQuarterly(propertyDTO, lastQuarterLocalDate, lastQuarterLocalDate, metricsConfig);
        }

        /**
         * 初始化 for Yearly
         *
         * @param propertyDTO   资产
         * @param nowLocalDate  当前时间
         * @param metricsConfig 指标配置
         * @author zc
         * @date 2025/9/11
         */
        private void initYearly(PropertyDTO propertyDTO, LocalDate nowLocalDate, HotelKpiMetricsConfig metricsConfig) {
            // 获取当前日期，如果不是当月第一天，则不处理
            if (nowLocalDate.getDayOfMonth() != 1) {
                return;
            }
            // 当前时间生成截至到上个月的 YTD 数据，需要减去一个月
            LocalDate lastMonthLocalDate = nowLocalDate.minusMonths(1);
            // 设置数据
            setYearly(propertyDTO, lastMonthLocalDate, lastMonthLocalDate, metricsConfig);
        }

        /**
         * 触发设置数据
         *
         * @param propertyDTO 资产
         * @param triggerType 触发类型，不同类型的日期格式不同
         * @param startDate   开始日期(yyyyMMdd,yyyyMM,yyyy)
         * @param endDate     结束日期(yyyyMMdd,yyyyMM,yyyy)
         * @author zc
         * @date 2025/9/12
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void triggerSetData(PropertyDTO propertyDTO, int triggerType, long startDate, long endDate) {
            HotelKpiMetricsConfig metricsConfig = metricsConfigService.getMetricsConfigByTypeForUpdate(propertyDTO.getId(), METRICS_TYPE);
            if (Objects.isNull(metricsConfig)) {
                return;
            }
            if (HotelKpiTriggerTypeCons.MONTHLY_REVENUE == triggerType) {
                LocalDate startLocalDate = DateTimeUtils.strToLocalDate(String.valueOf(startDate),
                        BaseConstant.DATE_FORMAT_YYYYMMDD);
                // 指标计算最小时间维度是 MTD，统计维度有重叠，结束日期需设置为该月份的月底
                LocalDate endLocalDate = DateTimeUtils.strToLocalDate(String.valueOf(endDate),
                        BaseConstant.DATE_FORMAT_YYYYMMDD).with(TemporalAdjusters.lastDayOfMonth());

                setWeekly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);

                // 触发设置次年数据
                setWeekly(propertyDTO, startLocalDate.plusYears(1), endLocalDate.plusYears(1), metricsConfig);
            } else if (HotelKpiTriggerTypeCons.BUDGET_DATABASE == triggerType) {
                LocalDate startLocalDate = YearMonth.of((int) startDate, 1).atDay(1);
                LocalDate endLocalDate = YearMonth.of((int) endDate, 12).atDay(1);

                setWeekly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setMonthly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setQuarterly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setYearly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
            } else if (HotelKpiTriggerTypeCons.MANAGER_FLASH == triggerType) {
                LocalDate startLocalDate = DateTimeUtils.strToLocalDate(String.valueOf(startDate),
                        BaseConstant.DATE_FORMAT_YYYYMMDD);
                LocalDate endLocalDate = DateTimeUtils.strToLocalDate(String.valueOf(endDate),
                        BaseConstant.DATE_FORMAT_YYYYMMDD);

                setMonthly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setQuarterly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setYearly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
            } else if (HotelKpiTriggerTypeCons.MONTHLY_REPORT == triggerType) {
                LocalDate startLocalDate = YearMonthUtils.getYearMonth(String.valueOf(startDate))
                        .plusYears(1).atDay(1);
                LocalDate endLocalDate = YearMonthUtils.getYearMonth(String.valueOf(endDate))
                        .plusYears(1).atDay(1);

                setMonthly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setQuarterly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setYearly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
            }
        }

        /**
         * 设置数据
         *
         * @param propertyDTO    属性信息
         * @param startLocalDate 开始日期
         * @param endLocalDate   结束日期
         * @param dateType       日期类型
         * @author zc
         * @date 2025/9/12
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void setData(PropertyDTO propertyDTO, int dateType, LocalDate startLocalDate, LocalDate endLocalDate) {
            HotelKpiMetricsConfig metricsConfig = metricsConfigService.getMetricsConfigByTypeForUpdate(propertyDTO.getId(), METRICS_TYPE);
            if (Objects.isNull(metricsConfig)) {
                return;
            }
            if (HotelKpiDateTypeCons.WEEKLY == dateType) {
                setWeekly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
            } else if (HotelKpiDateTypeCons.MONTHLY == dateType) {
                setMonthly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setQuarterly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
                setYearly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
            } else if (HotelKpiDateTypeCons.QUARTERLY == dateType) {
                setQuarterly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
            } else if (HotelKpiDateTypeCons.YEARLY == dateType) {
                setYearly(propertyDTO, startLocalDate, endLocalDate, metricsConfig);
            }
        }

        /**
         * 设置数据 for Weekly
         *
         * @param propertyDTO    资产
         * @param startLocalDate 起始日期
         * @param endLocalDate   结束日期
         * @param metricsConfig  指标配置
         * @author zc
         * @date 2025/9/11
         */
        private void setWeekly(PropertyDTO propertyDTO, LocalDate startLocalDate, LocalDate endLocalDate, HotelKpiMetricsConfig metricsConfig) {
            int dateType = HotelKpiDateTypeCons.WEEKLY;
            int propertyId = propertyDTO.getId();
            String factorConfigStr = metricsConfig.getCalculationFactorConfig();
            DayOfWeek dayOfWeek = weekStartDayService.getWeekStartDay(propertyId);
            RoundingMode roundingMode = InternationalizationUtils.getRoundingMode(propertyDTO
                    .getInternationalization().getNumber().getCalculationRule());
            // 获取资产房间数
            int rooms = roomsConfigInternalService.getRoomsConfig(propertyId).getRooms();

            // 转换为周的开始日期
            LocalDate startWeekLocalDate = startLocalDate.with(TemporalAdjusters.previousOrSame(dayOfWeek));
            LocalDate endWeekLocalDate = endLocalDate.with(TemporalAdjusters.previousOrSame(dayOfWeek));

            // 获取第一周的结束日期
            LocalDate startWeekLastLocalDate = startWeekLocalDate.plusDays(6);
            // 获取最后一周的结束日期
            LocalDate endWeekLastLocalDate = endWeekLocalDate.plusDays(6);

            LocalDate firstDayOfMonth = startWeekLastLocalDate.with(TemporalAdjusters.firstDayOfMonth());
            LocalDate lastDayOfMonth = endWeekLastLocalDate.with(TemporalAdjusters.lastDayOfMonth());
            // 获取 Monthly Revenue 数据
            long startDayOfMonth = Long.parseLong(DateTimeUtils.localDateToStr(firstDayOfMonth, BaseConstant.DATE_FORMAT_YYYYMMDD));
            long endDayOfMonth = Long.parseLong(DateTimeUtils.localDateToStr(lastDayOfMonth, BaseConstant.DATE_FORMAT_YYYYMMDD));
            List<HotelKpiWconnectMonthlyRevenue> monthlyRevenueList = monthlyRevenueService.listByDateRange(propertyId,
                    startDayOfMonth, endDayOfMonth);

            // 获取去年同月数据 Monthly Revenue 数据
            long startDateLy = Long.parseLong(DateTimeUtils.localDateToStr(firstDayOfMonth
                    .minusYears(1), BaseConstant.DATE_FORMAT_YYYYMMDD));
            long endDateLy = Long.parseLong(DateTimeUtils.localDateToStr(lastDayOfMonth
                    .minusYears(1).with(TemporalAdjusters.lastDayOfMonth()), BaseConstant.DATE_FORMAT_YYYYMMDD));
            List<HotelKpiWconnectMonthlyRevenue> lyMonthlyRevenueList = monthlyRevenueService.listByDateRange(propertyId,
                    startDateLy, endDateLy);

            // 获取 Budget Database 数据
            List<HotelKpiBudgetDatabaseDTO> budgetList = budgetDatabaseService.listByYearRange(propertyId,
                    startWeekLastLocalDate.getYear(), endWeekLastLocalDate.getYear());

            // 获取原始KPI数据
            long startWeekDate = Long.parseLong(DateTimeUtils.localDateToStr(startWeekLocalDate, BaseConstant.DATE_FORMAT_YYYYMMDD));
            long endWeekDate = Long.parseLong(DateTimeUtils.localDateToStr(endWeekLocalDate, BaseConstant.DATE_FORMAT_YYYYMMDD));
            Map<Long, String> date2OriginDetail = weeklyService.listByDateRangeAndMetricsType(propertyId,
                            startWeekDate, endWeekDate, METRICS_TYPE).stream()
                    .collect(Collectors.toMap(HotelKpiWeekly::getWeek, HotelKpiWeekly::getDetail));

            List<HotelKpiWeekly> saveList = Lists.newArrayList();
            for (LocalDate indexLocalDate = startWeekLocalDate; !indexLocalDate.isAfter(endWeekLocalDate); indexLocalDate = indexLocalDate.plusWeeks(1)) {
                long indexDate = Long.parseLong(DateTimeUtils.localDateToStr(indexLocalDate, BaseConstant.DATE_FORMAT_YYYYMMDD));

                String originDetail = date2OriginDetail.get(indexDate);
                List<HotelKpiV2OriginDetailDTO> originDetailDTOList = hotelKpiService.convert2V2OriginDetailDTOList(originDetail, dateType, factorConfigStr);

                LocalDate endIndexLocalDate = indexLocalDate.plusDays(6);
                // 月份的总房间数
                int monthRooms = endIndexLocalDate.lengthOfMonth() * rooms;
                // 去年同月的总房间数
                int lyMonthRooms = endIndexLocalDate.minusYears(1).lengthOfMonth() * rooms;

                LocalDate indexFirstDayOfMonth = endIndexLocalDate.withDayOfMonth(1);
                LocalDate indexEndDayOfMonth = endIndexLocalDate.with(TemporalAdjusters.lastDayOfMonth());
                long indexStartDate = Long.parseLong(DateTimeUtils.localDateToStr(indexFirstDayOfMonth, BaseConstant.DATE_FORMAT_YYYYMMDD));
                long indexEndDate = Long.parseLong(DateTimeUtils.localDateToStr(indexEndDayOfMonth, BaseConstant.DATE_FORMAT_YYYYMMDD));

                // 截取 Monthly Revenue 数据
                List<HotelKpiWconnectMonthlyRevenue> effectiveMonthlyRevList = monthlyRevenueList.stream().filter(item ->
                        item.getDate() >= indexStartDate && item.getDate() <= indexEndDate).toList();
                // 截取 LY Monthly Revenue 数据
                long indexLyStartDate = Long.parseLong(DateTimeUtils.localDateToStr(indexFirstDayOfMonth
                        .minusYears(1), BaseConstant.DATE_FORMAT_YYYYMMDD));
                long indexLyEndDate = Long.parseLong(DateTimeUtils.localDateToStr(indexEndDayOfMonth
                        .minusYears(1).with(TemporalAdjusters.lastDayOfMonth()), BaseConstant.DATE_FORMAT_YYYYMMDD));
                List<HotelKpiWconnectMonthlyRevenue> lyEffectiveMonthlyRevList = lyMonthlyRevenueList.stream().filter(item ->
                        item.getDate() >= indexLyStartDate && item.getDate() <= indexLyEndDate).toList();

                // 设置 total.actual
                BigDecimal totalActualValue = calculateForMonthlyRevenue(effectiveMonthlyRevList,
                        HotelKpiValueCategoryCons.CATEGORY_1, monthRooms, roundingMode);
                setMetricsValue(originDetailDTOList, totalActualValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.ACTUAL, roundingMode);

                // 设置 total.ly
                BigDecimal totalLyValue = calculateForMonthlyRevenue(lyEffectiveMonthlyRevList,
                        HotelKpiValueCategoryCons.CATEGORY_1, lyMonthRooms, roundingMode);
                setMetricsValue(originDetailDTOList, totalLyValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.LY, roundingMode);

                // 设置 transient.actual
                BigDecimal transientActualValue = calculateForMonthlyRevenue(effectiveMonthlyRevList,
                        HotelKpiValueCategoryCons.CATEGORY_2, monthRooms, roundingMode);
                setMetricsValue(originDetailDTOList, transientActualValue, HotelKpiValueCategoryCons.CATEGORY_2,
                        HotelKpiValueCategoryCons.ACTUAL, roundingMode);

                // 设置 transient.ly
                BigDecimal transientLyValue = calculateForMonthlyRevenue(lyEffectiveMonthlyRevList,
                        HotelKpiValueCategoryCons.CATEGORY_2, lyMonthRooms, roundingMode);
                setMetricsValue(originDetailDTOList, transientLyValue, HotelKpiValueCategoryCons.CATEGORY_2,
                        HotelKpiValueCategoryCons.LY, roundingMode);

                // 设置 group.actual
                BigDecimal groupActualValue = calculateForMonthlyRevenue(effectiveMonthlyRevList,
                        HotelKpiValueCategoryCons.CATEGORY_3, monthRooms, roundingMode);
                setMetricsValue(originDetailDTOList, groupActualValue, HotelKpiValueCategoryCons.CATEGORY_3,
                        HotelKpiValueCategoryCons.ACTUAL, roundingMode);

                // 设置 group.ly
                BigDecimal groupLyValue = calculateForMonthlyRevenue(lyEffectiveMonthlyRevList,
                        HotelKpiValueCategoryCons.CATEGORY_3, lyMonthRooms, roundingMode);
                setMetricsValue(originDetailDTOList, groupLyValue, HotelKpiValueCategoryCons.CATEGORY_3,
                        HotelKpiValueCategoryCons.LY, roundingMode);

                // 设置 contract.actual
                BigDecimal contractActualValue = calculateForMonthlyRevenue(effectiveMonthlyRevList,
                        HotelKpiValueCategoryCons.CATEGORY_4, monthRooms, roundingMode);
                setMetricsValue(originDetailDTOList, contractActualValue, HotelKpiValueCategoryCons.CATEGORY_4,
                        HotelKpiValueCategoryCons.ACTUAL, roundingMode);

                // 设置 contract.ly
                BigDecimal contractLyValue = calculateForMonthlyRevenue(lyEffectiveMonthlyRevList,
                        HotelKpiValueCategoryCons.CATEGORY_4, lyMonthRooms, roundingMode);
                setMetricsValue(originDetailDTOList, contractLyValue, HotelKpiValueCategoryCons.CATEGORY_4,
                        HotelKpiValueCategoryCons.LY, roundingMode);

                // 截取 Budget Database 数据
                HotelKpiBudgetDatabaseDTO budgetDTO = budgetList.stream().filter(item ->
                        item.getYear() == endIndexLocalDate.getYear()).findFirst().orElse(new HotelKpiBudgetDatabaseDTO());
                long indexMonth = Long.parseLong(DateTimeUtils.localDateToStr(endIndexLocalDate, BaseConstant.DATE_FORMAT_YYYYMM));
                // 设置 total.budget
                BigDecimal totalBudgetValue = calculateForBudgetDatabase(budgetDTO, indexMonth, indexMonth,
                        monthRooms, roundingMode, null);
                setMetricsValue(originDetailDTOList, totalBudgetValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.BUDGET, roundingMode);
                // 设置 transient.budget
                BigDecimal transientBudgetValue = calculateForBudgetDatabase(budgetDTO, indexMonth, indexMonth,
                        monthRooms, roundingMode, HotelKpiBudgetDatabaseCons.ROOM_TRANSIENT);
                setMetricsValue(originDetailDTOList, transientBudgetValue, HotelKpiValueCategoryCons.CATEGORY_2,
                        HotelKpiValueCategoryCons.BUDGET, roundingMode);
                // 设置 group.budget
                BigDecimal groupBudgetValue = calculateForBudgetDatabase(budgetDTO, indexMonth, indexMonth,
                        monthRooms, roundingMode, HotelKpiBudgetDatabaseCons.ROOM_GROUP);
                setMetricsValue(originDetailDTOList, groupBudgetValue, HotelKpiValueCategoryCons.CATEGORY_3,
                        HotelKpiValueCategoryCons.BUDGET, roundingMode);
                // 设置 contract.budget
                BigDecimal contractBudgetValue = calculateForBudgetDatabase(budgetDTO, indexMonth, indexMonth,
                        monthRooms, roundingMode, HotelKpiBudgetDatabaseCons.ROOM_CONTRACT);
                setMetricsValue(originDetailDTOList, contractBudgetValue, HotelKpiValueCategoryCons.CATEGORY_4,
                        HotelKpiValueCategoryCons.BUDGET, roundingMode);

                String detail = JsonUtils.convertObjListToString(objectMapper, originDetailDTOList);

                saveList.add(HotelKpiWeekly.builder()
                        .propertyId(propertyId)
                        .week(indexDate)
                        .metricsType(METRICS_TYPE)
                        .detail(detail)
                        .build());
            }
            weeklyService.insertOrUpdateBatch(saveList);
        }

        /**
         * 设置数据 for Monthly
         *
         * @param propertyDTO    资产
         * @param startLocalDate 起始日期
         * @param endLocalDate   结束日期
         * @param metricsConfig  指标配置
         * @author zc
         * @date 2025/9/11
         */
        private void setMonthly(PropertyDTO propertyDTO, LocalDate startLocalDate, LocalDate endLocalDate, HotelKpiMetricsConfig metricsConfig) {
            int dateType = HotelKpiDateTypeCons.MONTHLY;
            int propertyId = propertyDTO.getId();
            String factorConfigStr = metricsConfig.getCalculationFactorConfig();
            RoundingMode roundingMode = InternationalizationUtils.getRoundingMode(propertyDTO
                    .getInternationalization().getNumber().getCalculationRule());
            // 获取资产房间数
            int rooms = roomsConfigInternalService.getRoomsConfig(propertyId).getRooms();
            // 获取 W-connect - Monthly Report 字段映射配置
            HotelKpiMonthlyReportFieldConfigDTO fieldConfigDTO = monthlyReportFieldConfigService.get(propertyId);

            YearMonth startYearMonth = YearMonth.of(startLocalDate.getYear(), startLocalDate.getMonthValue());
            YearMonth endYearMonth = YearMonth.of(endLocalDate.getYear(), endLocalDate.getMonthValue());

            // 获取 Manager Flash 数据
            List<HotelKpiManagerFlash> managerFlashList = listManagerFlash(propertyId, startYearMonth, endYearMonth);

            // 获取 Budget Database 数据
            List<HotelKpiBudgetDatabaseDTO> budgetList = budgetDatabaseService.listByYearRange(propertyId, startLocalDate.getYear(), endLocalDate.getYear());

            // 获取去年的 W-connect - Monthly Report 数据
            long lyStartMonth = YearMonthUtils.parseYearMonthToLong(startYearMonth.minusYears(1));
            long lyEndMonth = YearMonthUtils.parseYearMonthToLong(endYearMonth.minusYears(1));
            List<HotelKpiWconnectMonthlyReport> monthlyReportList = monthlyReportService.listByDateRange(propertyId,
                    HotelKpiMonthlyReportCons.ROOM_REVENUE, lyStartMonth, lyEndMonth);

            // 获取原始KPI数据
            long startMonth = YearMonthUtils.parseYearMonthToLong(startYearMonth);
            long endMonth = YearMonthUtils.parseYearMonthToLong(endYearMonth);
            Map<Long, String> date2OriginDetail = monthlyService.listByDateRangeAndMetricsType(propertyId,
                    startMonth, endMonth, METRICS_TYPE).stream().collect(Collectors.toMap(HotelKpiMonthly::getMonth, HotelKpiMonthly::getDetail));

            List<HotelKpiMonthly> saveList = Lists.newArrayList();
            for (YearMonth indexYearMonth = startYearMonth; !indexYearMonth.isAfter(endYearMonth); indexYearMonth = indexYearMonth.plusMonths(1)) {
                long indexMonth = YearMonthUtils.parseYearMonthToLong(indexYearMonth);
                // 月份的总房间数
                int indexMonthRooms = indexYearMonth.lengthOfMonth() * rooms;

                String originDetail = date2OriginDetail.getOrDefault(indexMonth, null);
                List<HotelKpiV2OriginDetailDTO> originDetailDTOList = hotelKpiService.convert2V2OriginDetailDTOList(originDetail, dateType, factorConfigStr);

                // 截取 Manager Flash 数据
                long indexEndOfMonthDate = Long.parseLong(DateTimeUtils.localDateToStr(indexYearMonth.atEndOfMonth(), BaseConstant.DATE_FORMAT_YYYYMMDD));
                List<HotelKpiManagerFlash> effectiveManagerFlash = managerFlashList.stream()
                        .filter(item -> item.getDate().equals(indexEndOfMonthDate)).toList();
                BigDecimal totalActualValue = calculateForManagerFlash(effectiveManagerFlash, indexMonthRooms, roundingMode);
                // 设置 total.actual
                setMetricsValue(originDetailDTOList, totalActualValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.ACTUAL, roundingMode);

                // 截取 Budget Database 数据
                int year = indexYearMonth.getYear();
                HotelKpiBudgetDatabaseDTO budgetDTO = budgetList.stream().filter(item -> item.getYear() == year)
                        .findFirst().orElse(new HotelKpiBudgetDatabaseDTO());
                // 设置 total.budget
                BigDecimal totalBudgetValue = calculateForBudgetDatabase(budgetDTO, indexMonth, indexMonth,
                        indexMonthRooms, roundingMode, null);
                setMetricsValue(originDetailDTOList, totalBudgetValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.BUDGET, roundingMode);

                // 截取去年同月的 W-connect - Monthly Report 数据
                long lyMonth = YearMonthUtils.parseYearMonthToLong(indexYearMonth.minusYears(1));
                Map<String, HotelKpiWconnectMonthlyReport> filedName2MonthlyReport = monthlyReportList.stream()
                        .filter(item -> item.getMonth().equals(lyMonth))
                        .collect(Collectors.toMap(HotelKpiWconnectMonthlyReport::getName, Function.identity()));
                // 设置 total.ly
                BigDecimal totalLyValue = filedName2MonthlyReport.getOrDefault(fieldConfigDTO.getOccPercent(),
                        new HotelKpiWconnectMonthlyReport()).getActual();
                setMetricsValue(originDetailDTOList, totalLyValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.LY, roundingMode);

                String detail = JsonUtils.convertObjListToString(objectMapper, originDetailDTOList);

                saveList.add(HotelKpiMonthly.builder()
                        .propertyId(propertyId)
                        .month(indexMonth)
                        .metricsType(METRICS_TYPE)
                        .detail(detail)
                        .build());
            }
            monthlyService.insertOrUpdateBatch(saveList);
        }

        /**
         * 设置数据 for Quarterly
         *
         * @param propertyDTO    资产
         * @param startLocalDate 起始日期
         * @param endLocalDate   结束日期
         * @param metricsConfig  指标配置
         * @author zc
         * @date 2025/9/11
         */
        private void setQuarterly(PropertyDTO propertyDTO, LocalDate startLocalDate, LocalDate endLocalDate, HotelKpiMetricsConfig metricsConfig) {
            int dateType = HotelKpiDateTypeCons.QUARTERLY;
            int propertyId = propertyDTO.getId();
            String factorConfigStr = metricsConfig.getCalculationFactorConfig();
            RoundingMode roundingMode = InternationalizationUtils.getRoundingMode(propertyDTO
                    .getInternationalization().getNumber().getCalculationRule());
            // 资产房间数量
            int rooms = roomsConfigInternalService.getRoomsConfig(propertyId).getRooms();

            YearMonth startYearMonthOfQuarter = YearMonth.of(startLocalDate.getYear(), startLocalDate.getMonth().firstMonthOfQuarter());
            YearMonth endYearMonthOfQuarter = YearMonth.of(endLocalDate.getYear(), endLocalDate.getMonth().firstMonthOfQuarter());

            // 获取 Manager Flash 数据
            List<HotelKpiManagerFlash> managerFlashList = listManagerFlash(propertyId, startYearMonthOfQuarter,
                    endYearMonthOfQuarter.plusMonths(2));

            // 获取 Budget Database 数据
            List<HotelKpiBudgetDatabaseDTO> budgetList = budgetDatabaseService.listByYearRange(propertyId,
                    startLocalDate.getYear(), endLocalDate.getYear());

            // 获取去年的 Manager Flash 数据
            List<HotelKpiManagerFlash> lyManagerFlashList = listManagerFlash(propertyId,
                    startYearMonthOfQuarter.minusYears(1),
                    endYearMonthOfQuarter.minusYears(1).plusMonths(2));

            // 获取原始KPI数据
            long startQuarterDate = YearMonthUtils.parseYearMonthToLong(startYearMonthOfQuarter);
            long endQuarterDate = YearMonthUtils.parseYearMonthToLong(endYearMonthOfQuarter);
            Map<Long, String> month2OriginDetail = quarterlyService.listByDateRangeAndMetricsType(propertyId,
                            startQuarterDate, endQuarterDate, METRICS_TYPE).stream()
                    .collect(Collectors.toMap(HotelKpiQuarterly::getMonth, HotelKpiQuarterly::getDetail));

            List<HotelKpiQuarterly> saveList = Lists.newArrayList();
            for (YearMonth indexYearMonth = startYearMonthOfQuarter; !indexYearMonth.isAfter(endYearMonthOfQuarter); indexYearMonth = indexYearMonth.plusMonths(3)) {
                long indexStartMonth = YearMonthUtils.parseYearMonthToLong(indexYearMonth);
                long indexEndMonth = YearMonthUtils.parseYearMonthToLong(indexYearMonth.plusMonths(2));

                String originDetail = month2OriginDetail.get(indexStartMonth);
                List<HotelKpiV2OriginDetailDTO> originDetailDTOList = hotelKpiService.convert2V2OriginDetailDTOList(originDetail, dateType, factorConfigStr);

                List<LocalDate> effectiveLocalDateList = listEndOfLocalDate(indexYearMonth, 3);
                // 计算总房间数
                int roomsTotal = effectiveLocalDateList.stream().map(LocalDate::lengthOfMonth).reduce(Integer::sum).orElse(0) * rooms;

                // 截取 Manager Flash 数据
                List<Long> effectiveDateList = effectiveLocalDateList.stream().map(item ->
                        Long.parseLong(DateTimeUtils.localDateToStr(item, BaseConstant.DATE_FORMAT_YYYYMMDD))).toList();
                List<HotelKpiManagerFlash> effectiveManagerFlashList = managerFlashList.stream()
                        .filter(item -> effectiveDateList.contains(item.getDate())).toList();
                BigDecimal totalActualValue = calculateForManagerFlash(effectiveManagerFlashList, roomsTotal, roundingMode);
                // 设置 total.actual
                setMetricsValue(originDetailDTOList, totalActualValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.ACTUAL, roundingMode);

                // 截取 Budget Database 数据
                int year = indexYearMonth.getYear();
                HotelKpiBudgetDatabaseDTO budgetDTO = budgetList.stream().filter(item -> item.getYear() == year)
                        .findFirst().orElse(new HotelKpiBudgetDatabaseDTO());
                BigDecimal totalBudgetValue = calculateForBudgetDatabase(budgetDTO, indexStartMonth, indexEndMonth,
                        roomsTotal, roundingMode, null);
                // 设置 total.budget
                setMetricsValue(originDetailDTOList, totalBudgetValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.BUDGET, roundingMode);

                List<LocalDate> effectiveLyLocalDateList = listEndOfLocalDate(indexYearMonth.minusYears(1), 3);
                // 计算去年同期房间总数
                int lyRoomsTotal = effectiveLyLocalDateList.stream().map(LocalDate::lengthOfMonth).reduce(Integer::sum).orElse(0) * rooms;

                // 截取 LY Manager Flash 数据
                List<Long> effectiveLyDateList = effectiveLyLocalDateList.stream().map(item ->
                        Long.parseLong(DateTimeUtils.localDateToStr(item, BaseConstant.DATE_FORMAT_YYYYMMDD))).toList();
                List<HotelKpiManagerFlash> effectiveLyManagerFlashList = lyManagerFlashList.stream()
                        .filter(item -> effectiveLyDateList.contains(item.getDate())).toList();
                BigDecimal totalLyValue = calculateForManagerFlash(effectiveLyManagerFlashList, lyRoomsTotal, roundingMode);
                // 设置 total.ly
                setMetricsValue(originDetailDTOList, totalLyValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.LY, roundingMode);

                String detail = JsonUtils.convertObjListToString(objectMapper, originDetailDTOList);

                saveList.add(HotelKpiQuarterly.builder()
                        .propertyId(propertyId)
                        .month(indexStartMonth)
                        .metricsType(METRICS_TYPE)
                        .detail(detail)
                        .build());
            }
            quarterlyService.insertOrUpdateBatch(saveList);
        }

        /**
         * 设置数据 for Yearly
         *
         * @param propertyDTO    资产
         * @param startLocalDate 起始日期
         * @param endLocalDate   结束日期
         * @param metricsConfig  指标配置
         * @author zc
         * @date 2025/9/11
         */
        private void setYearly(PropertyDTO propertyDTO, LocalDate startLocalDate, LocalDate endLocalDate, HotelKpiMetricsConfig metricsConfig) {
            int dateType = HotelKpiDateTypeCons.YEARLY;
            int propertyId = propertyDTO.getId();
            String factorConfigStr = metricsConfig.getCalculationFactorConfig();
            RoundingMode roundingMode = InternationalizationUtils.getRoundingMode(propertyDTO
                    .getInternationalization().getNumber().getCalculationRule());
            // 资产房间数量
            int rooms = roomsConfigInternalService.getRoomsConfig(propertyId).getRooms();
            // 获取上个月的日期
            YearMonth lastMonthYearMonth = YearMonth.now(ZoneId.of(propertyDTO.getTimezone())).minusMonths(1);

            int startYear = startLocalDate.getYear();
            int endYear = endLocalDate.getYear();

            YearMonth startYearMonth = YearMonth.of(startYear, 1);
            YearMonth endYearMonth = YearMonth.of(endYear, 12);

            // 获取 Manager Flash 数据
            List<HotelKpiManagerFlash> managerFlashList = listManagerFlash(propertyId, startYearMonth, endYearMonth);

            // 获取 Budget Database 数据
            List<HotelKpiBudgetDatabaseDTO> budgetList = budgetDatabaseService.listByYearRange(propertyId,
                    startLocalDate.getYear(), endLocalDate.getYear());

            // 获取去年的 Manager Flash 数据
            List<HotelKpiManagerFlash> lyManagerFlashList = listManagerFlash(propertyId,
                    startYearMonth.minusYears(1), endYearMonth.minusYears(1));

            // 获取原始KPI数据
            Map<Long, String> year2OriginDetail = yearlyService.listByDateRangeAndMetricsType(propertyId,
                            startYear, endYear, METRICS_TYPE).stream()
                    .collect(Collectors.toMap(HotelKpiYearly::getYear, HotelKpiYearly::getDetail));

            List<HotelKpiYearly> saveList = Lists.newArrayList();
            for (int indexYear = startYear; indexYear <= endYear; indexYear++) {
                // 若年份大于当前上个月的年份，则跳过
                if (indexYear > lastMonthYearMonth.getYear()) {
                    continue;
                }
                String originDetail = year2OriginDetail.get((long) indexYear);
                List<HotelKpiV2OriginDetailDTO> originDetailDTOList = hotelKpiService.convert2V2OriginDetailDTOList(originDetail, dateType, factorConfigStr);

                YearMonth startMonthOfYear = YearMonth.of(indexYear, 1);
                int asOfMonth = indexYear < lastMonthYearMonth.getYear() ? 12 : lastMonthYearMonth.getMonthValue();

                List<LocalDate> effectiveLocalDateList = listEndOfLocalDate(startMonthOfYear, asOfMonth);
                // 计算总房间数
                int roomsTotal = effectiveLocalDateList.stream().map(LocalDate::lengthOfMonth).reduce(Integer::sum).orElse(0) * rooms;

                // 截取 Manager Flash 数据
                List<Long> effectiveDateList = effectiveLocalDateList.stream().map(item ->
                        Long.parseLong(DateTimeUtils.localDateToStr(item, BaseConstant.DATE_FORMAT_YYYYMMDD))).toList();
                List<HotelKpiManagerFlash> effectiveManagerFlashList = managerFlashList.stream()
                        .filter(item -> effectiveDateList.contains(item.getDate())).toList();
                BigDecimal totalActualValue = calculateForManagerFlash(effectiveManagerFlashList, roomsTotal, roundingMode);
                // 设置 total.actual
                setMetricsValue(originDetailDTOList, totalActualValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.ACTUAL, roundingMode);

                // 截取 Budget Database 数据
                HotelKpiBudgetDatabaseDTO budgetDTO = budgetList.stream().filter(item ->
                        item.getYear() == startMonthOfYear.getYear()).findFirst().orElse(new HotelKpiBudgetDatabaseDTO());
                long indexStartMonth = YearMonthUtils.parseYearMonthToLong(startMonthOfYear);
                long indexEndMonth = YearMonthUtils.parseYearMonthToLong(YearMonth.of(indexYear, asOfMonth));
                BigDecimal totalBudgetValue = calculateForBudgetDatabase(budgetDTO, indexStartMonth, indexEndMonth,
                        roomsTotal, roundingMode, null);
                // 设置 total.budget
                setMetricsValue(originDetailDTOList, totalBudgetValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.BUDGET, roundingMode);

                List<LocalDate> effectiveLyLocalDateList = listEndOfLocalDate(startMonthOfYear.minusYears(1), asOfMonth);
                // 计算去年同期的总房间数
                int lyRoomsTotal = effectiveLyLocalDateList.stream().map(LocalDate::lengthOfMonth).reduce(Integer::sum).orElse(0) * rooms;

                // 截取 LY Manager Flash 数据
                List<Long> effectiveLyDateList = effectiveLyLocalDateList.stream().map(item ->
                        Long.parseLong(DateTimeUtils.localDateToStr(item, BaseConstant.DATE_FORMAT_YYYYMMDD))).toList();
                List<HotelKpiManagerFlash> effectiveLyManagerFlashList = lyManagerFlashList.stream()
                        .filter(item -> effectiveLyDateList.contains(item.getDate())).toList();
                BigDecimal totalLyValue = calculateForManagerFlash(effectiveLyManagerFlashList, lyRoomsTotal, roundingMode);
                // 设置 total.ly
                setMetricsValue(originDetailDTOList, totalLyValue, HotelKpiValueCategoryCons.CATEGORY_1,
                        HotelKpiValueCategoryCons.LY, roundingMode);

                String detail = JsonUtils.convertObjListToString(objectMapper, originDetailDTOList);

                saveList.add(HotelKpiYearly.builder()
                        .propertyId(propertyId)
                        .year((long) indexYear)
                        .metricsType(METRICS_TYPE)
                        .detail(detail)
                        .build());
            }
            yearlyService.insertOrUpdateBatch(saveList);
        }

        /**
         * 获取指定数量的月末日期
         *
         * @param startYearMonth 开始年月
         * @param size           数量
         * @return List<LocalDate>
         * @author zc
         * @date 2025/8/29
         */
        private List<LocalDate> listEndOfLocalDate(YearMonth startYearMonth, int size) {
            List<LocalDate> dateList = Lists.newArrayListWithExpectedSize(size);
            for (int i = 0; i < size; i++) {
                dateList.add(startYearMonth.plusMonths(i).atEndOfMonth());
            }
            return dateList;
        }

        /**
         * 获取计算结果 for Manager Flash
         *
         * @param dataList     报告数据
         * @param roomsTotal   总房间数量
         * @param roundingMode 舍入模式
         * @return java.math.BigDecimal
         * @author zc
         * @date 2025/10/15
         */
        private BigDecimal calculateForManagerFlash(List<HotelKpiManagerFlash> dataList, int roomsTotal, RoundingMode roundingMode) {
            BigDecimal roomsOccupied = dataList.stream().filter(item ->
                            Objects.equals(item.getCategory(), HotelKpiManagerFlashCons.ROOMS_OCCUPIED))
                    .map(HotelKpiManagerFlash::getMtd).reduce(BigDecimal::add).orElse(null);
            Long roomsSoldTotal = Objects.isNull(roomsOccupied) ? null : roomsOccupied.longValue();
            return calculateOccPercent(roomsSoldTotal, roomsTotal, roundingMode);
        }

        /**
         * 获取计算结果 for Monthly Revenue
         *
         * @param dataList     报告数据
         * @param category     分类
         * @param roundingMode 舍入模式
         * @param roomsTotal   总房间数量
         * @return java.math.BigDecimal
         * @author zc
         * @date 2025/8/25
         */
        private BigDecimal calculateForMonthlyRevenue(List<HotelKpiWconnectMonthlyRevenue> dataList, int category,
                                                      int roomsTotal, RoundingMode roundingMode) {
            Long roomsSoldTotal;
            if (category == HotelKpiValueCategoryCons.CATEGORY_1) {
                roomsSoldTotal = dataList.stream().map(HotelKpiWconnectMonthlyRevenue::getRoomsSold)
                        .filter(Objects::nonNull).reduce(Integer::sum).map(Integer::longValue).orElse(null);
            } else if (category == HotelKpiValueCategoryCons.CATEGORY_2) {
                roomsSoldTotal = dataList.stream().map(HotelKpiWconnectMonthlyRevenue::getTransientSold)
                        .filter(Objects::nonNull).reduce(Integer::sum).map(Integer::longValue).orElse(null);
            } else if (category == HotelKpiValueCategoryCons.CATEGORY_3) {
                roomsSoldTotal = dataList.stream().map(HotelKpiWconnectMonthlyRevenue::getGroupSold)
                        .filter(Objects::nonNull).reduce(Integer::sum).map(Integer::longValue).orElse(null);
            } else {
                roomsSoldTotal = dataList.stream().map(HotelKpiWconnectMonthlyRevenue::getContractSold)
                        .filter(Objects::nonNull).reduce(Integer::sum).map(Integer::longValue).orElse(null);
            }
            return calculateOccPercent(roomsSoldTotal, roomsTotal, roundingMode);
        }

        /**
         * 计算数值 for Budget Database
         *
         * @param budgetDTO    Budget DTO
         * @param startDate    开始时间(yyyyMM)
         * @param endDate      结束时间(yyyyMM)
         * @param roomsTotal   总房间数量
         * @param roundingMode 舍入模式
         * @param type         数据类型（1：Transient 2：Group 3：Contract）
         * @return java.math.BigDecimal
         * @author zc
         * @date 2025/9/8
         */
        private BigDecimal calculateForBudgetDatabase(HotelKpiBudgetDatabaseDTO budgetDTO, long startDate, long endDate,
                                                      int roomsTotal, RoundingMode roundingMode, Integer type) {
            Long roomsSoldTotal = budgetDatabaseService.getRoomsSoldBudget(budgetDTO, startDate, endDate, type);
            return calculateOccPercent(roomsSoldTotal, roomsTotal, roundingMode);
        }

        /**
         * 计算数值 for Occ Percent
         *
         * @param roomsSoldTotal 房间 sold 总数
         * @param roomsTotal     总房间数量
         * @param roundingMode   舍入模式
         * @return java.math.BigDecimal
         * @author zc
         * @date 2025/8/27
         */
        private BigDecimal calculateOccPercent(Long roomsSoldTotal, int roomsTotal, RoundingMode roundingMode) {
            if (Objects.isNull(roomsSoldTotal) || roomsTotal == 0) {
                return null;
            }
            return new BigDecimal(roomsSoldTotal.toString()).multiply(new BigDecimal("100"))
                    .divide(new BigDecimal(Integer.toString(roomsTotal)),
                            BaseConstant.DATA_PRECISION, roundingMode);
        }

        /**
         * 根据日期范围获取 Manager Flash 数据
         *
         * @param propertyId     资产 id
         * @param startYearMonth 开始日期
         * @param endYearMonth   结束日期
         * @return HotelKpiManagerFlash 集合
         * @author zc
         * @date 2025/8/29
         */
        private List<HotelKpiManagerFlash> listManagerFlash(int propertyId, YearMonth startYearMonth, YearMonth endYearMonth) {
            return managerFlashService.listMonthEnd(propertyId, startYearMonth, endYearMonth,
                    List.of(HotelKpiManagerFlashCons.ROOMS_OCCUPIED));
        }

        /**
         * 设置指标值
         *
         * @param originDetailDTOList 原始数值
         * @param value               指标值
         * @param category            指标类别(1:Total 2:Transient 3:Group)
         * @param titleIndex          标题坐标(1:Actual 2:Budget 3:LY)
         * @param roundingMode        舍入模式
         * @author zc
         * @date 2025/8/25
         */
        private void setMetricsValue(List<HotelKpiV2OriginDetailDTO> originDetailDTOList, BigDecimal value, int category,
                                     int titleIndex, RoundingMode roundingMode) {
            if (Objects.nonNull(value)) {
                value = value.setScale(BaseConstant.DATA_PRECISION, roundingMode);
            }
            for (HotelKpiV2OriginDetailDTO originDetailDTO : originDetailDTOList) {
                if (Objects.equals(originDetailDTO.getCategory(), category)) {
                    // 组装新的计算因子 1
                    HotelKpiOriginCalculationFactorDTO factorIndex1 = new HotelKpiOriginCalculationFactorDTO()
                            .setIndex(1).setCrawl(value)
                            .setCrawlOrigin(List.of(HotelKpiOriginCrawlValueIndexDTO.builder().index(1).value(value).build()));

                    if (HotelKpiValueCategoryCons.ACTUAL == titleIndex) {
                        hotelKpiService.replaceOriginFactorList(originDetailDTO.getActual().getCalculationFactor(), factorIndex1);
                    } else if (HotelKpiValueCategoryCons.BUDGET == titleIndex) {
                        hotelKpiService.replaceOriginFactorList(originDetailDTO.getBudget().getCalculationFactor(), factorIndex1);
                    } else {
                        hotelKpiService.replaceOriginFactorList(originDetailDTO.getLy().getCalculationFactor(), factorIndex1);
                    }
                    return;
                }
            }
        }
    }