package com.zcxk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcxk.dto.CameraDto;
import com.zcxk.entity.CameraManage;
import com.zcxk.model.AjaxMessage;
import com.zcxk.model.Pagination;
import com.zcxk.model.ResultStatus;
import com.zcxk.service.CameraManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (CameraManage)控制层
 *
 * @author makejava
 * @since 2020-11-26 10:25:12
 */
@RestController
@RequestMapping("/cameraManage")
@Api(tags = "摄像头管理")
public class CameraManageController {
    /**
     * 服务对象
     */
    @Autowired
    private CameraManageService cameraManageService;



    /**
     * 新增一条数据
     *
     * @param cameraManage 实体类
     * @return Response对象
     */
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    @ApiOperation(value = "增加摄像头",notes = "stauts为300009，公司/部门信息错误")
    public AjaxMessage<Integer> insert(@ApiParam(value = "新增摄像头", required = true) @RequestBody CameraManage cameraManage) {
        int result = cameraManageService.insert(cameraManage);
        if(result==1){
            return new AjaxMessage<>(ResultStatus.OK, result);
        }else{
            return new AjaxMessage<>(ResultStatus.ORG_INFO_ERROR, result);
        }

    }

    /**
     * 修改一条数据
     *
     * @param cameraManage 实体类
     * @return Response对象
     */
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ApiOperation(value = "修改摄像头",notes = "stauts为300009，公司/部门信息错误")
    public AjaxMessage<Integer> update(@ApiParam(value = "修改摄像头", required = true) @RequestBody CameraManage cameraManage) {
        int result = cameraManageService.update(cameraManage);
        if(result==1){
            return new AjaxMessage<>(ResultStatus.OK, result);
        }else{
            return new AjaxMessage<>(ResultStatus.ORG_INFO_ERROR, result);
        }

    }

    /**
     * 删除一条数据
     *
     * @param ids 参数对象
     * @return Response对象
     */
    @RequestMapping(value = "deleteAll", method = RequestMethod.POST)
    @ApiOperation(value = "查询设施配置列表")
    public AjaxMessage<Integer> deleteAll(@ApiParam(value = "删除的ids", required = true) @RequestBody List<Integer>ids) {
        int result = cameraManageService.deleteAll(ids);
        return new AjaxMessage<>(ResultStatus.OK, result);
    }


    /**
     * 分页查询
     *
     * @param pageNum  偏移
     * @param pageSize 条数
     * @return Response对象
     */
    @RequestMapping(value = "selectPage", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage<Pagination<CameraManage>> selectPage(@RequestParam(required = false) Integer pageNum,
                                                            @RequestParam(required = false)Integer pageSize,
                                                            @RequestParam(required = false) Integer companyOrgId,
                                                            @RequestParam(required = false)Integer deptOrgId,
                                                            @RequestParam(required = false) Integer sceneId,
                                                            @RequestParam(required = false) String name) {
        CameraManage cameraManage = new CameraManage();
        cameraManage.setCompanyOrgId(companyOrgId);
        cameraManage.setDeptOrgId(deptOrgId);
        cameraManage.setSceneId(sceneId);
        cameraManage.setName(name);
        IPage<CameraManage> iPage = new Page<>(pageNum, pageSize);
        iPage = cameraManageService.selectPage(cameraManage, iPage);
        Pagination<CameraManage> pages = new Pagination<>(iPage);
        return new AjaxMessage<>(ResultStatus.OK, pages);
    }


    /**
     * app视频列表分页查询
     *
     * @param pageNum  偏移
     * @param pageSize 条数
     * @return Response对象
     */
    @RequestMapping(value = "appSelectPage", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage<Pagination<CameraManage>> appSelectPage(@RequestParam(required = false) Integer pageNum,
                                                            @RequestParam(required = false)Integer pageSize,
                                                            @RequestParam(required = false) Integer companyOrgId,
                                                            @RequestParam(required = false)Integer deptOrgId,
                                                            @RequestParam(required = false) Integer sceneId,
                                                            @RequestParam(required = false) String name) {
        CameraManage cameraManage = new CameraManage();
        cameraManage.setCompanyOrgId(companyOrgId);
        cameraManage.setDeptOrgId(deptOrgId);
        cameraManage.setParentSceneId(sceneId);
        cameraManage.setName(name);
        IPage<CameraManage> iPage = new Page<>(pageNum, pageSize);
        iPage = cameraManageService.appSelectPage(cameraManage, iPage);
        Pagination<CameraManage> pages = new Pagination<>(iPage);
        return new AjaxMessage<>(ResultStatus.OK, pages);
    }
    /**
     * 查询场景树下的摄像头
     *
     * @param sceneId  场景id
     * @param
     * @return Response对象
     */
    @RequestMapping(value = "selectBySceneId", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage<List<CameraManage>> selectBySceneId(@RequestParam(required = false) Integer sceneId) {
        CameraManage cameraManage = new CameraManage();
         cameraManage.setSceneId(sceneId);
        List<CameraManage> cameraManages = cameraManageService.selectList(cameraManage);
        return new AjaxMessage<>(ResultStatus.OK, cameraManages);
    }
    /**
     * 获取单个摄像头信息
     *
     * @param id  主键id
     * @param
     * @return Response对象
     */
    @RequestMapping(value = "get", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage<CameraManage> selectById(@RequestParam(required = false) Integer id) {
        CameraManage cameraManage =cameraManageService.selectById(id);
        return new AjaxMessage<>(ResultStatus.OK, cameraManage);
    }
    /**
     * 获取单个摄像头信息
     *
     * @param
     * @param
     * @return Response对象
     */
    @RequestMapping(value = "getCameraTree", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage<List<CameraDto>> getCameraTree() {
        List<CameraDto> cameraManages =cameraManageService.getCameraTree(0l);
        return new AjaxMessage<>(ResultStatus.OK, cameraManages);
    }
    /**
     * 获取单个摄像头信息
     *
     * @param  id 主键id
     * @param
     * @return Response对象
     */
    @RequestMapping(value = "getAllCameras", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage<List<CameraManage>> getAllCameras(Integer id) {
        List<CameraManage> cameraManages =cameraManageService.getAllCameras(id);
        return new AjaxMessage<>(ResultStatus.OK, cameraManages);
    }

}