# HotelKpiAnalysisController.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.ListPagedDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.workperformance.cons.hotelkpi.old.HotelKpiDateTypeCons;
    import cloud.wconnect.workperformance.entity.hotelkpi.old.HotelKpiMetricsConfig;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.old.analysis.HotelKpiAnalysisDTO;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.old.kpi.HotelKpiCommentDTO;
    import cloud.wconnect.workperformance.pojo.query.hotelkpi.old.HotelKpiAnalysisQuery;
    import cloud.wconnect.workperformance.pojo.query.hotelkpi.old.HotelKpiCommentQuery;
    import cloud.wconnect.workperformance.service.hotelkpi.old.IHotelKpiAnalysisCommentService;
    import cloud.wconnect.workperformance.service.hotelkpi.old.IHotelKpiAnalysisService;
    import cloud.wconnect.workperformance.service.hotelkpi.old.IHotelKpiMetricsConfigService;
    import jakarta.annotation.Resource;
    import jakarta.validation.Valid;
    import org.springframework.web.bind.annotation.*;

    import java.util.List;

    /**
     * <p>
     * Hotel KPI Analysis 前端控制器
     * </p>
     *
     * @author zc
     * @since 2024-06-27
     */
    @RestController("hotelKpiAnalysisController_old")
    @RequestMapping("/hotel-kpi/history")
    public class HotelKpiAnalysisController {

        @Resource
        private IHotelKpiMetricsConfigService metricsConfigService;
        @Resource
        private IHotelKpiAnalysisService analysisService;
        @Resource
        private IHotelKpiAnalysisCommentService analysisCommentService;
        @Resource
        private PropertyI18nRedisService propertyI18nRedisService;
        @Resource
        private SessionContext sessionContext;

        /**
         * 获取指标对比分析数据
         *
         * @param property 资产标识
         * @param query    查询条件
         * @return HotelKpiAnalysisDTO 集合
         * @author zc
         * @date 2024/6/27
         */
        @ApiId(1355)
        @GetMapping("/analysis")
        public List<HotelKpiAnalysisDTO> list(@RequestParam String property, @Valid HotelKpiAnalysisQuery query) {
            int propertyId = sessionContext.getPropertyId(property);
            PropertyDTO propertyDTO = propertyI18nRedisService.get(propertyId);

            // 校验指标配置是否存在
            HotelKpiMetricsConfig metricsConfig = metricsConfigService.checkExistByDateAndMetricsType(propertyDTO.getId(),
                    HotelKpiDateTypeCons.YEARLY, query.getTargetYear(), query.getMetricsType(), Boolean.FALSE);

            return analysisService.listAnalysis(propertyDTO, query, metricsConfig);
        }

        /**
         * 获取指标对比分析评论
         *
         * @param property 资产标识
         * @param year     年份(yyyy)
         * @param query    查询条件
         * @return HotelKpiCommentDTO 集合
         * @author zc
         * @date 2024/6/28
         */
        @ApiId(1356)
        @GetMapping("/{year:\\d+}/analysis/comment")
        public ListPagedDTO<HotelKpiCommentDTO> listComment(@RequestParam String property, @PathVariable long year,
                                                            @Valid HotelKpiCommentQuery query) {
            int propertyId = sessionContext.getPropertyId(property);
            PropertyDTO propertyDTO = propertyI18nRedisService.get(propertyId);
            return analysisCommentService.listComment(propertyDTO, year, query);
        }
    }