package com.huimv.video.controller;

import com.huimv.video.domain.CameraInfo;
import com.huimv.video.result.Result;
import com.huimv.video.service.CameraInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Project : huimv.shiwan
 * @Package : com.huimv.video.controller
 * @Description : TODO
 * @Author : yuxuexuan
 * @Create : 2021/1/7 0007 13:58
 **/
@CrossOrigin
@RestController
@RequestMapping("/cameraInfo")
public class CameraInfoController {

    @Autowired
    private CameraInfoService cameraInfoService;

    @RequestMapping("/add")
    private Result addCamera(CameraInfo cameraInfo){
        try {
            cameraInfoService.save(cameraInfo);
            return new Result(10000,"添加成功");
        }catch (Exception e){
            return new Result(10001,"添加失败");
        }
    }

    @RequestMapping("/update")
    private Result updateCamera(CameraInfo cameraInfo){
        try {
            if (cameraInfo.getId()==0){
                return new Result(10002,"请选择修改数据");
            }
            cameraInfoService.update(cameraInfo);
            return new Result(10000,"修改成功");
        }catch (Exception e){
            return new Result(10001,"修改失败");
        }
    }

    @RequestMapping("/delete")
    private Result deleteCamera(@RequestParam(required = false) List<Integer> ids){
        try {
            cameraInfoService.delete(ids);
            return new Result(10000,"删除成功");
        }catch (Exception e){
            return new Result(10001,"删除失败");
        }
    }

    @RequestMapping("/findAll")
    private Result findAll(){
        try {
            List<CameraInfo> list = cameraInfoService.findAll();
            if (list == null){
                return new Result(10002,"查询失败,地区信息有误",list);
            }
            return new Result(10000,"查询成功",list);
        }catch (Exception e){
            return new Result(10001,"查询失败");
        }
    }

    @RequestMapping("searchAll")
    private Result searchAll(String name){
        try {
            List list = cameraInfoService.searchAll(name);
            return new Result(10000,"查询成功",list);
        }catch (Exception e){
            return new Result(10001,"查询失败");
        }
    }

    @RequestMapping("/getCameraDetails")
    private Result getCameraDetails(@RequestParam(required = false) List<Integer> areaIds){
        try {
            List list =  cameraInfoService.getCameraDetails(areaIds);
            return new Result(10000,"查询成功",list);
        }catch (Exception e){
            return new Result(10001,"查询失败");
        }
    }

//    @RequestMapping("/getCameraDetailsByLqid")
//    private Result getCameraDetailsByLqid(Integer LQID){
//        try {
////            List list =  cameraInfoService.getCameraDetails(areaIds);
////            return new Result(10000,"查询成功",list);
//        }catch (Exception e){
//            return new Result(10001,"查询失败");
//        }
//    }
}
