/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.xrtygis.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.xrtygis.entity.TfScadaMonitor;
import com.tofly.xrtygis.service.TfScadaMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
/**
 * 存储最新值
 *
 * @author JF
 * @date Sat May 07 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfscadamonitor")
@Api(tags="存储最新值接口")
public class TfScadaMonitorController {

    private final TfScadaMonitorService tfScadaMonitorService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param tfScadaMonitor 存储最新值
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getTfScadaMonitorPage(Page page, @ModelAttribute TfScadaMonitor tfScadaMonitor) {
      return ResultRespone.success(tfScadaMonitorService.page(page, Wrappers.query(tfScadaMonitor)));
    }


    /**
     * 通过id查询存储最新值
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(tfScadaMonitorService.getById(id));
    }

    /**
     * 新增存储最新值
     * @param tfScadaMonitor 存储最新值
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增存储最新值" )
    @ApiOperation(value = "新增存储最新值")
    @PostMapping
    public ResultRespone save(@RequestBody TfScadaMonitor tfScadaMonitor) {
      return ResultRespone.success(tfScadaMonitorService.save(tfScadaMonitor));
    }

    /**
     * 修改存储最新值
     * @param tfScadaMonitor 存储最新值
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改存储最新值" )
    @ApiOperation(value = "修改存储最新值")
    @PutMapping
    public ResultRespone updateById(@RequestBody TfScadaMonitor tfScadaMonitor) {
      return ResultRespone.success(tfScadaMonitorService.updateById(tfScadaMonitor));
    }

    /**
     * 通过id删除存储最新值
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除存储最新值" )
    @ApiOperation(value = "通过ID删除存储最新值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(tfScadaMonitorService.removeById(id));
    }

    /**
     * 通过id批量删除存储最新值
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id批量删除存储最新值" )
    @ApiOperation(value = "通过ID批量删除存储最新值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(tfScadaMonitorService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
