# RevenueOccForecastController.java

    package cloud.wconnect.rateshop.controller.revenue;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.rateshop.entity.revenue.OccJumpAlertFilterConfig;
    import cloud.wconnect.rateshop.pojo.dto.revenue.OccCompareDTO;
    import cloud.wconnect.rateshop.pojo.dto.revenue.OccJumpAlertFilterConfigDTO;
    import cloud.wconnect.rateshop.pojo.query.revenue.OccCompareQuery;
    import cloud.wconnect.rateshop.service.revenue.IOccForecastService;
    import cloud.wconnect.rateshop.service.revenue.IOccJumpAlertFilterConfigService;
    import jakarta.validation.Valid;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import java.util.Collections;
    import java.util.Map;
    import java.util.Objects;

    /**
     * <p>
     * 前端控制器
     * </p>
     *
     * @author zc
     * @since 2024-04-16
     */
    @RestController
    @RequestMapping("/revenue/occ")
    public class RevenueOccForecastController {

        @Autowired
        private IOccJumpAlertFilterConfigService filterConfigService;
        @Autowired
        private IOccForecastService occForecastService;

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private BeanMapper beanMapper;

        /**
         * 获取 occ jump alert 过滤配置
         *
         * @param property 资产标识
         * @return 过滤配置
         * @author zc
         * @date 2024/4/16
         */
        @ApiId(1146)
        @GetMapping("/jump-alert/filter-config")
        public OccJumpAlertFilterConfigDTO getFilterConfig(@RequestParam String property) {
            int propertyId = sessionContext.getPropertyId(property);
            OccJumpAlertFilterConfig filterConfig = filterConfigService.getFilterConfig(propertyId);
            if (Objects.isNull(filterConfig)) {
                return new OccJumpAlertFilterConfigDTO();
            }
            return beanMapper.map(filterConfig, OccJumpAlertFilterConfigDTO.class);
        }

        /**
         * 保存 occ jump alert 过滤配置
         *
         * @param property        资产标识
         * @param filterConfigDTO 过滤配置 DTO
         * @return empty map
         * @author zc
         * @date 2024/4/16
         */
        @ApiId(1147)
        @PostMapping("/jump-alert/filter-config")
        public Map<Object, Object> saveFilterConfig(@RequestParam String property,
                                                    @Valid @RequestBody OccJumpAlertFilterConfigDTO filterConfigDTO) {
            if (filterConfigDTO.getMaxValue().compareTo(filterConfigDTO.getMinValue()) <= 0) {
                throw new BadRequestException(CommonErrorI18nConstant.MIN_VALUE_CANNOT_GREATER_THAN_MAX_VALUE,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The max value should be greater than the min value");
            }
            int propertyId = sessionContext.getPropertyId(property);
            filterConfigService.saveFilterConfig(propertyId, sessionContext.getLoginUserId(), filterConfigDTO);

            return Collections.emptyMap();
        }

        /**
         * 删除 occ jump alert 过滤配置
         *
         * @param property 资产标识
         * @return empty map
         * @author zc
         * @date 2024/4/16
         */
        @ApiId(1148)
        @DeleteMapping("/jump-alert/filter-config")
        public Map<Object, Object> deleteFilterConfig(@RequestParam String property) {
            int propertyId = sessionContext.getPropertyId(property);
            filterConfigService.deleteFilterConfig(propertyId);
            return Collections.emptyMap();
        }

        /**
         * 获取 occ 比对数据
         *
         * @param property 资产
         * @param query    查询条件
         * @return OccCompareDTO
         * @author zc
         * @date 2024/4/17
         */
        @ApiId(1149)
        @GetMapping("/compare")
        public OccCompareDTO getCompare(@RequestParam String property, @Valid OccCompareQuery query) {
            // 校验查询条件
            long firstDate = Long.parseLong(query.getCompareFirstDate() + StringUtils.leftPad(query.getCompareFirstHour().toString(), 2, '0'));
            long secondDate = Long.parseLong(query.getCompareSecondDate() + StringUtils.leftPad(query.getCompareSecondHour().toString(), 2, '0'));
            if (firstDate >= secondDate) {
                throw new BadRequestException(CommonErrorI18nConstant.START_DATE_CANNOT_GREATER_THAN_END_DATE,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The firstDate cannot be greater than or equal to the secondDate");
            }
            int propertyId = sessionContext.getPropertyId(property);
            return occForecastService.getCompare(propertyId, query);
        }
    }