 package com.huimv.management.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huimv.management.entity.CameraBrandEntity;
import com.huimv.management.service.CameraBrandService;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.R;



/**
 * 
 *
 * @author yinhao
 * @version ${version}
 * @date 2021-07-08 17:02:38
 */
@RestController
@RequestMapping("management/camerabrand")
@Api(tags = "摄像头品牌")
public class CameraBrandController {
    @Autowired
    private CameraBrandService cameraBrandService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = cameraBrandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CameraBrandEntity cameraBrand = cameraBrandService.getById(id);

        return R.ok().put("cameraBrand", cameraBrand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CameraBrandEntity cameraBrand){
		cameraBrandService.save(cameraBrand);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CameraBrandEntity cameraBrand){
		cameraBrandService.updateById(cameraBrand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        if (cameraBrandService.delete(ids)){
            cameraBrandService.removeByIds(Arrays.asList(ids));
        }else {
            return R.error("有该品牌的摄像头，删除失败");
        }


        return R.ok();
    }

    /**
     * 查询所有
     */
    @RequestMapping("/findAll")
    public R findAll(){


        return R.ok().put("data",cameraBrandService.list());
    }

}
