# HotelKpiSettingController.java

    package cloud.wconnect.workperformance.controller.hotelkpi.old;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.pojo.dto.jsonview.Views;
    import cloud.wconnect.workperformance.cons.hotelkpi.old.HotelKpiDateTypeCons;
    import cloud.wconnect.workperformance.entity.hotelkpi.old.HotelKpiMetricsConfig;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.old.setting.HotelKpiSettingCalculationDTO;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.old.setting.HotelKpiSettingDetailDTO;
    import cloud.wconnect.workperformance.pojo.query.hotelkpi.old.HotelKpiSettingRuleQuery;
    import cloud.wconnect.workperformance.service.hotelkpi.old.IHotelKpiMetricsConfigService;
    import cloud.wconnect.workperformance.service.hotelkpi.old.IHotelKpiMetricsSettingService;
    import com.fasterxml.jackson.annotation.JsonView;
    import jakarta.annotation.Resource;
    import jakarta.validation.Valid;
    import org.springframework.web.bind.annotation.*;

    import java.util.List;

    /**
     * <p>
     * Hotel KPI Setting 前端控制器
     * </p>
     *
     * @author zc
     * @since 2024-06-28
     */
    @RestController("hotelKpiSettingController_old")
    @RequestMapping("/hotel-kpi/history")
    public class HotelKpiSettingController {
        @Resource
        private IHotelKpiMetricsSettingService metricsSettingService;
        @Resource
        private IHotelKpiMetricsConfigService metricsConfigService;
        @Resource
        private SessionContext sessionContext;

        /**
         * 获取指定年的指标设置
         *
         * @param property 资产标识
         * @param year     年份(yyyy)
         * @return HotelKpiSettingDetailDTO 指标设置详情
         * @author zc
         * @date 2024/6/28
         */
        @ApiId(1357)
        @GetMapping("/{year:\\d+}/setting")
        public List<HotelKpiSettingDetailDTO> listSetting(@RequestParam String property, @PathVariable long year) {
            int propertyId = sessionContext.getPropertyId(property);
            return metricsSettingService.listSetting(propertyId, year);
        }

        /**
         * 获取 Setting Rule
         *
         * @param property 资产标识
         * @param year     年份(yyyy)
         * @param query    查询条件
         * @return HotelKpiSettingCalculationDTO
         * @author zc
         * @date 2025/1/14
         */
        @ApiId(1358)
        @GetMapping("/{year:\\d+}/setting/rule")
        @JsonView(Views.GeneralView.class)
        public HotelKpiSettingCalculationDTO getSettingRule(@RequestParam String property, @PathVariable long year,
                                                            @Valid HotelKpiSettingRuleQuery query) {
            int propertyId = sessionContext.getPropertyId(property);
            // 校验 metrics config 是否存在
            HotelKpiMetricsConfig metricsConfig = metricsConfigService.checkExistByDateAndMetricsType(propertyId,
                    HotelKpiDateTypeCons.YEARLY, year, query.getMetricsType(), Boolean.FALSE);
            return metricsSettingService.getSettingRule(metricsConfig, year, query.getValueCategory());
        }

    }