package com.jiayue.insu.inclientqn.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.insu.common.core.util.R;
import com.jiayue.insu.inclientqn.entity.CorrforeSt;
import com.jiayue.insu.inclientqn.service.CorrforeStService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * ForecastDataController
 *
 * @author yh
 * @date 2022-03-18 15:48:48
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/corrforeSt")
public class CorrforeStController {

    private final CorrforeStService corrforeStService;

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

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


        if(corrforeSt.getStartTime()!=null && corrforeSt.getEndTime()!=null){
            lambdaQueryWrapper.between(CorrforeSt::getForecastTime,corrforeSt.getStartTime(),corrforeSt.getEndTime());
        }

        page.addOrder(OrderItem.asc("forecast_time"));

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


    /**
     * 新增corrforeSt
     *
     * @param corrforeSt corrforeSt
     * @return R
     */

    @PostMapping
    public R save(@RequestBody CorrforeSt corrforeSt) {
        return R.ok(corrforeStService.save(corrforeSt));
    }

    /**
     * 修改corrforeSt
     *
     * @param corrforeSt corrforeSt
     * @return R
     */

    @PutMapping
    public R updateById(@RequestBody CorrforeSt corrforeSt) {
        return R.ok(corrforeStService.updateById(corrforeSt));
    }

    /**
     * 通过id删除
     *
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Long id) {
        return R.ok(corrforeStService.removeById(id));
    }


}
