package com.zcxk.charge.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcxk.charge.api.dto.query.CameraManagePageDto;
import com.zcxk.charge.api.enums.ChargeErrorEnum;
import com.zcxk.charge.web.common.Pagination;
import com.zcxk.charge.api.dto.CameraDto;
import com.zcxk.charge.core.entity.CameraManage;
import com.zcxk.charge.web.service.CameraManageService;
import com.zcxk.core.common.pojo.AjaxMessage;
import com.zcxk.core.common.util.BeanCopyUtils;
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 javax.validation.Valid;
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;

    @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 AjaxMessage.success(result);
        }
        return AjaxMessage.success(ChargeErrorEnum.ORG_INFO_ERROR, result);
    }

    @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 AjaxMessage.success(result);
        }
        return AjaxMessage.success(ChargeErrorEnum.ORG_INFO_ERROR, result);
    }

    @RequestMapping(value = "deleteAll", method = RequestMethod.POST)
    @ApiOperation(value = "查询设施配置列表")
    public AjaxMessage<Integer> deleteAll(@ApiParam(value = "删除的ids", required = true) @RequestBody List<Integer>ids) {
        return AjaxMessage.success(cameraManageService.deleteAll(ids));
    }

    @RequestMapping(value = "selectPage", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage<Pagination<CameraManage>> selectPage(@RequestBody @Valid  CameraManagePageDto dto) {
        CameraManage cameraManage = new CameraManage();
        BeanCopyUtils.copyProperties(dto, cameraManage, CameraManage.class);
        IPage<CameraManage> iPage = new Page<>(dto.getPageNum(), dto.getPageSize());
        iPage = cameraManageService.selectPage(cameraManage, iPage);
        Pagination<CameraManage> pages = new Pagination<>(iPage);
        return AjaxMessage.success(pages);
    }

    @RequestMapping(value = "appSelectPage", method = RequestMethod.POST)
    @ApiOperation(value = "app视频列表分页查询")
    public AjaxMessage<Pagination<CameraManage>> appSelectPage(@RequestBody @Valid  CameraManagePageDto dto) {
        CameraManage cameraManage = new CameraManage();
        BeanCopyUtils.copyProperties(dto, cameraManage, CameraManage.class);
        IPage<CameraManage> iPage = new Page<>(dto.getPageNum(), dto.getPageSize());
        iPage = cameraManageService.appSelectPage(cameraManage, iPage);
        Pagination<CameraManage> pages = new Pagination<>(iPage);
        return AjaxMessage.success(pages);
    }

    @RequestMapping(value = "selectBySceneId", method = RequestMethod.POST)
    @ApiOperation(value = "查询场景树下的摄像头")
    public AjaxMessage selectBySceneId(@RequestParam(required = false) Integer sceneId) {
        CameraManage cameraManage = new CameraManage();
        cameraManage.setSceneId(sceneId);
        List<CameraManage> cameraManages = cameraManageService.selectList(cameraManage);
        return AjaxMessage.success(cameraManages);
    }

    @RequestMapping(value = "get", method = RequestMethod.POST)
    @ApiOperation(value = "获取单个摄像头信息")
    public AjaxMessage selectById(@RequestParam(required = false) Integer id) {
        return AjaxMessage.success( cameraManageService.selectById(id));
    }

    @RequestMapping(value = "getCameraTree", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage getCameraTree() {
        return AjaxMessage.success(cameraManageService.getCameraTree(0L));
    }

    @RequestMapping(value = "getAllCameras", method = RequestMethod.POST)
    @ApiOperation(value = "查询摄像头列表")
    public AjaxMessage getAllCameras(Integer id) {
        return AjaxMessage.success(cameraManageService.getAllCameras(id));
    }

}