package com.jiayue.ipp.idp.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.FileAnalysisRecord;
import com.jiayue.ipp.idp.service.FileAnalysisRecordService;
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_file_analysis_record
 *
 * @author whc
 * @date 2022-03-18 15:48:51
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/fileanalysisrecord")
@Api(value = "fileanalysisrecord", tags = "idp_file_analysis_record管理")
public class FileAnalysisRecordController {

    private final FileAnalysisRecordService fileAnalysisRecordService;

    /**
     * 分页查询
     *
     * @param page               分页对象
     * @param fileAnalysisRecord idp_file_analysis_record
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    //@PreAuthorize("@pms.hasPermission('idp_fileanalysisrecord_get')")
    public R getFileAnalysisRecordPage(Page page, FileAnalysisRecord fileAnalysisRecord) {
        return R.ok(fileAnalysisRecordService.page(page, Wrappers.query(fileAnalysisRecord)));
    }

    /**
     * 根据场站编号 创建时间 文件状态 分页查询
     *
     * @param currentPage
     * @param pageSize
     * @param stationCode
     * @param createDate
     * @param fileStatus
     * @return
     */
    @ApiOperation(value = "根据场站编号分页查询", notes = "分页查询")
    @PostMapping("/getByStationCodeAndCreateTimeAndFileStatus")
    //@PreAuthorize("@pms.hasPermission('idp_weatherstationinfo_get')")
    public R getByStationCode(Long currentPage, Long pageSize, String stationCode, Long createDate, String fileStatus) {
        Page page = new Page(currentPage, pageSize);
        page.setMaxLimit((long) -1);
        return R.ok(fileAnalysisRecordService.page(page, fileAnalysisRecordService.findByStationCodeAndCreateDateAndFileStatus(stationCode, new Date(createDate), new Date(createDate + 60 * 60 * 24 * 1000 - 1000), fileStatus)));
    }

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

    /**
     * 新增idp_file_analysis_record
     *
     * @param fileAnalysisRecord idp_file_analysis_record
     * @return R
     */
    @ApiOperation(value = "新增idp_file_analysis_record", notes = "新增idp_file_analysis_record")
    //    @SysLog("新增idp_file_analysis_record")
    @PostMapping
    //@PreAuthorize("@pms.hasPermission('idp_fileanalysisrecord_add')")
    public R save(@RequestBody FileAnalysisRecord fileAnalysisRecord) {
        return R.ok(fileAnalysisRecordService.save(fileAnalysisRecord));
    }

    /**
     * 修改idp_file_analysis_record
     *
     * @param fileAnalysisRecord idp_file_analysis_record
     * @return R
     */
    @ApiOperation(value = "修改idp_file_analysis_record", notes = "修改idp_file_analysis_record")
    //    @SysLog("修改idp_file_analysis_record")
    @PutMapping
    //@PreAuthorize("@pms.hasPermission('idp_fileanalysisrecord_edit')")
    public R updateById(@RequestBody FileAnalysisRecord fileAnalysisRecord) {
        return R.ok(fileAnalysisRecordService.updateById(fileAnalysisRecord));
    }

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

}
