package com.jiayue.insu.inclientqn.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.insu.common.core.util.R;
import com.jiayue.insu.inclientqn.entity.BackForeForecastData;
import com.jiayue.insu.inclientqn.entity.BackForeUsForecastData;
import com.jiayue.insu.inclientqn.service.BackForeForecastDataService;
import com.jiayue.insu.inclientqn.service.BackForeUsForecastDataService;
import com.jiayue.insu.inclientqn.util.DateTimeUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.cglib.core.Local;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


/**
 * backForeForecstData
 *
 * @author yh
 * @date 2022-03-18 15:48:48
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/backForeUsForecastData")
public class BackForeUsForecastDataController {

    private final BackForeUsForecastDataService backForeUsForecastDataService;

    /**
     * 分页查询
     *
     * @param page   分页对象
     * @param backForeUsForecastData backForeUsForecastData
     * @return
     */

    @GetMapping("/page")
    public R getPage(Page page, BackForeUsForecastData backForeUsForecastData) {
            LambdaQueryWrapper<BackForeUsForecastData> lambdaQueryWrapper = new LambdaQueryWrapper<>();


        if(backForeUsForecastData.getSignTime()!=null){
            String dateStr = LocalDateTimeUtil.formatNormal(backForeUsForecastData.getSignTime());
            DateTime dateTime = new DateTime(dateStr, DatePattern.NORM_DATETIME_FORMAT);
            long longTime = DateTimeUtils.get15min(dateTime.getTime());
            lambdaQueryWrapper.eq(BackForeUsForecastData::getSignTime, LocalDateTimeUtil.of(longTime));

        }
        lambdaQueryWrapper.orderByAsc(BackForeUsForecastData::getForecastTime);

        return R.ok(backForeUsForecastDataService.page(page, lambdaQueryWrapper));
    }





}
