package com.jiayue.ipp.idp.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.Nwp;
import com.jiayue.ipp.idp.service.NwpService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


/**
 * idp_nwp
 *
 * @author whc
 * @date 2022-03-18 15:49:17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/nwp")
@Api(value = "nwp", tags = "idp_nwp管理")
public class NwpController {

    private final NwpService nwpService;


    @ApiOperation(value = "根据条件查询", notes = "分页查询")
    @PostMapping("/queryTableData")
    //@PreAuthorize("@pms.hasPermission('idp_nwp_get')")
    public R queryTableData(Long currentPage, Long pageSize, String stationCode, Long startTime, Long endTime, String forecastManufactor) {
        Page page = new Page(currentPage, pageSize);
        page.addOrder(OrderItem.asc("pre_time"));
        page.setMaxLimit((long) -1);
        return R.ok(nwpService.page(page, nwpService.getPageByStationCodeAndeTimeBetween(stationCode, new Date(startTime), new Date(endTime),forecastManufactor)));
    }

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param nwp  idp_nwp
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    //@PreAuthorize("@pms.hasPermission('idp_nwp_get')")
    public R getNwpPage(Page page, Nwp nwp) {
        return R.ok(nwpService.page(page, Wrappers.query(nwp)));
    }

    /**
     * 通过id查询idp_nwp
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_nwp_get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(nwpService.getById(id));
    }

    /**
     * 新增idp_nwp
     *
     * @param nwp idp_nwp
     * @return R
     */
    @ApiOperation(value = "新增idp_nwp", notes = "新增idp_nwp")
    //    @SysLog("新增idp_nwp")
    @PostMapping
    //@PreAuthorize("@pms.hasPermission('idp_nwp_add')")
    public R save(@RequestBody Nwp nwp) {
        return R.ok(nwpService.save(nwp));
    }

    /**
     * 修改idp_nwp
     *
     * @param nwp idp_nwp
     * @return R
     */
    @ApiOperation(value = "修改idp_nwp", notes = "修改idp_nwp")
    //    @SysLog("修改idp_nwp")
    @PutMapping
    //@PreAuthorize("@pms.hasPermission('idp_nwp_edit')")
    public R updateById(@RequestBody Nwp nwp) {
        return R.ok(nwpService.updateById(nwp));
    }

    /**
     * 通过id删除idp_nwp
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除idp_nwp", notes = "通过id删除idp_nwp")
    //    @SysLog("通过id删除idp_nwp")
    @DeleteMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_nwp_del')")
    public R removeById(@PathVariable String id) {
        return R.ok(nwpService.removeById(id));
    }

}
