/*
 * 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.TfCameraManage;
import com.tofly.xrtygis.service.TfCameraManageService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;

/**
 * 摄像头管理
 *
 * @author admin
 * @date Fri Mar 11 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfcameramanage")
@Api(tags="摄像头管理接口")
public class TfCameraManageController {

    private final  TfCameraManageService tfCameraManageService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param tfCameraManage 摄像头管理
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    @ToFlyAppLog(title="分页查询" )
    public ResultRespone getTfCameraManagePage(Page page, @ModelAttribute TfCameraManage tfCameraManage) {
        try{
            return ResultRespone.success(tfCameraManageService.page(page, Wrappers.query(tfCameraManage)));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }


    /**
     * 通过id查询摄像头管理
     * @param waterId id
     * @return ResultRespone
     */
    @GetMapping("/{waterId}" )
    @ApiOperation(value = "通过ID查询")
    @ToFlyAppLog(title="通过ID查询" )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "waterId", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("waterId" ) Long waterId) {
        try{
            return ResultRespone.success(tfCameraManageService.getById(waterId));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }

    /**
     * 新增摄像头管理
     * @param tfCameraManage 摄像头管理
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增摄像头管理" )
    @ApiOperation(value = "新增摄像头管理")
    @PostMapping
    public ResultRespone save(@RequestBody TfCameraManage tfCameraManage) {
        try{
            return ResultRespone.success(tfCameraManageService.save(tfCameraManage));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }

    /**
     * 修改摄像头管理
     * @param tfCameraManage 摄像头管理
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改摄像头管理" )
    @ApiOperation(value = "修改摄像头管理")
    @PutMapping
    public ResultRespone updateById(@RequestBody TfCameraManage tfCameraManage) {
        try{
            return ResultRespone.success(tfCameraManageService.updateById(tfCameraManage));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }

    /**
     * 通过id删除摄像头管理
     * @param waterId id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除摄像头管理" )
    @ApiOperation(value = "通过ID删除摄像头管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "waterId", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{waterId}" )
    public ResultRespone removeById(@PathVariable Long waterId) {
        try{
            return ResultRespone.success(tfCameraManageService.removeById(waterId));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }

    /**
     * 通过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) {
        try{
            return ResultRespone.success(tfCameraManageService.removeByIds(Arrays.asList(ids.split(","))));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed();
        }
    }
}
