# RevenueWidgetController.java

    package cloud.wconnect.rateshop.controller.revenue;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.rateshop.pojo.dto.revenue.FutureStayInformationDTO;
    import cloud.wconnect.rateshop.pojo.dto.revenue.OtbRevenueTrendsDTO;
    import cloud.wconnect.rateshop.pojo.dto.revenue.RevenueCompletionDTO;
    import cloud.wconnect.rateshop.pojo.query.revenue.OtbRevenueQuery;
    import cloud.wconnect.rateshop.service.revenue.IRevenueWidgetService;
    import jakarta.validation.Valid;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;

    import java.util.Collections;
    import java.util.List;
    import java.util.stream.Collectors;

    /**
     * 控制层：Revenue Widget
     *
     * @author yyt
     * 2023/12/14
     */
    @RestController
    @RequestMapping("/revenue/widget")
    public class RevenueWidgetController {

        @Autowired
        private IRevenueWidgetService revenueWidgetService;
        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private PropertyI18nRedisService propertyI18nRedisService;

        /**
         * 获取不同资产下当天的 Revenue 和 Occ% 完成度
         *
         * @param propertyIds 选择资产
         * @return Revenue 和 Occ% 完成度
         * @author yyt
         * @date 2023/12/14
         */
        @ApiId(1000)
        @GetMapping("/revenue-completion")
        public List<RevenueCompletionDTO> listRevenueCompletions(@RequestParam List<Integer> propertyIds) {
            List<Integer> effectivePropertyIds = sessionContext.getPropertyIds().stream()
                    .filter(propertyIds::contains).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(effectivePropertyIds)) {
                return Collections.emptyList();
            }

            return revenueWidgetService.listRevenueCompletions(propertyI18nRedisService.list(effectivePropertyIds));
        }

        /**
         * 获取不同资产下 OTB Revenue 的走势
         *
         * @param query 检索条件
         * @return OTB Revenue
         * @author yyt
         * @date 2023/12/14
         */
        @ApiId(1001)
        @GetMapping("/otb-revenue")
        public List<OtbRevenueTrendsDTO> listOtbRevenue(@Valid OtbRevenueQuery query) {
            List<Integer> propertyIds = query.getPropertyIds();
            List<Integer> effectivePropertyIds = sessionContext.getPropertyIds().stream()
                    .filter(propertyIds::contains).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(effectivePropertyIds)) {
                return Collections.emptyList();
            }

            return revenueWidgetService.listOtbRevenue(propertyI18nRedisService.list(effectivePropertyIds), query);
        }

        /**
         * 获取未来14天的入住信息（occ%, Room available, 自身官网最低房价）
         *
         * @param property     资产
         * @param datasourceId 数据源ID
         * @param platformId   平台ID
         * @return 未来14天的入住信息
         * @author yyt
         * @date 2023/12/14
         */
        @ApiId(1002)
        @GetMapping("/future-stay-information")
        public FutureStayInformationDTO listFutureStayInformation(String property, @RequestParam(required = false) Integer datasourceId, @RequestParam(required = false) Integer platformId) {
            return revenueWidgetService.listFutureStayInformation(sessionContext.getPropertyId(property), datasourceId, platformId);
        }

    }