# HotelKpiV2MetricsDTO.java

    package cloud.wconnect.workperformance.pojo.dto.hotelkpi.kpiv2;

    import cloud.wconnect.workperformance.cons.hotelkpi.HotelKpiDateTypeCons;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.factorconfigv2.HotelKpiV2FactorConfigDTO;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.kpi.HotelKpiDataRangeDTO;
    import com.google.common.collect.Lists;
    import lombok.AllArgsConstructor;
    import lombok.Builder;
    import lombok.Data;
    import org.apache.commons.collections.CollectionUtils;

    import java.util.List;

    /**
     * DTO: Hotel KPI V2 Metrics
     *
     * @author zc
     * @date 2025/08/18
     */
    @Data
    @Builder
    @AllArgsConstructor
    public class HotelKpiV2MetricsDTO {

        /**
         * 日期
         */
        private Long date;

        /**
         * 指标类型
         */
        private Integer metricsType;

        /**
         * 指标名称
         */
        private String title;

        /**
         * 指标描述
         */
        private String description;

        /**
         * 指标数据范围
         */
        private HotelKpiDataRangeDTO dataRange;

        /**
         * 指标单位
         */
        private String unit;

        /**
         * 指标项分类列表
         */
        private List<HotelKpiV2MetricsCategoryDTO> list;

        public HotelKpiV2MetricsDTO(int dateType, HotelKpiV2FactorConfigDTO factorConfigDTO) {
            this.dataRange = new HotelKpiDataRangeDTO();
            if (HotelKpiDateTypeCons.WEEKLY == dateType) {
                this.list = factorConfigDTO.getWeekly().stream().map(item ->
                        new HotelKpiV2MetricsCategoryDTO().setCategory(item.getCategory())).toList();
            } else {
                this.list = factorConfigDTO.getMonthly().stream().map(item ->
                        new HotelKpiV2MetricsCategoryDTO().setCategory(item.getCategory())).toList();
            }
        }

        /**
         * 汇总用户 id
         *
         * @return 用户 id 集合
         * @author zc
         * @date 2025/8/19
         */
        public List<Integer> summaryUserIds() {
            List<Integer> userIds = Lists.newArrayList();
            if (CollectionUtils.isNotEmpty(list)) {
                list.forEach(item -> {
                    userIds.addAll(item.getActual().getCalculationFactor().stream().map(HotelKpiV2CalculationFactorDTO::getUpdatedBy)
                            .filter(userId -> userId > 0).toList());
                    userIds.addAll(item.getBudget().getCalculationFactor().stream().map(HotelKpiV2CalculationFactorDTO::getUpdatedBy)
                            .filter(userId -> userId > 0).toList());
                    userIds.addAll(item.getLy().getCalculationFactor().stream().map(HotelKpiV2CalculationFactorDTO::getUpdatedBy)
                            .filter(userId -> userId > 0).toList());
                });
            }
            return userIds;
        }

    }