package com.huimv.video.video.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.huimv.common.utils.Result;
import com.huimv.video.video.entity.Camera;
import com.huimv.video.video.entity.CameraArea;
import com.huimv.video.video.entity.CameraFunction;
import com.huimv.video.video.service.ICameraAreaService;
import com.huimv.video.video.service.ICameraFuntcionService;
import com.huimv.video.video.service.ICameraService;
import com.huimv.video.video.utils.IpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-09-13
 */
@RestController
@RequestMapping("/cameraFunction")
public class CameraFunctionController {
    @Autowired
    private ICameraFuntcionService cameraFuntcionService;


    @PostMapping("/list")
    public Result list(@RequestBody Map<String, Object> params) {
        return cameraFuntcionService.cameraList(params);
    }

    @PostMapping("/add")
    public Result add(@RequestBody CameraFunction cameraFunction) {
        int brandName = cameraFuntcionService.count(new QueryWrapper<CameraFunction>().eq("function_name", cameraFunction.getFunctionName()).eq("farm_id", cameraFunction.getFarmId()));
        if (brandName > 0) {
            return new Result(100001, "区域名称重复", false);
        }
        cameraFuntcionService.save(cameraFunction);
        return new Result(10000, "添加成功", true);
    }

    @PostMapping("/update")
    public Result update(@RequestBody CameraFunction cameraArea) {
        cameraFuntcionService.updateById(cameraArea);
        int brandName = cameraFuntcionService.count(new QueryWrapper<CameraFunction>().eq("function_name", cameraArea.getFunctionName()));
        if (brandName > 1) {
            return new Result(100001, "区域名称重复", false);
        }

        return new Result(10000, "修改成功", true);
    }

    @GetMapping("/remove")
    public Result remove(@RequestParam(value = "ids") List<Integer> ids) {

        return cameraFuntcionService.removeIds(ids);

    }


    @GetMapping("/lsitAndCamera")
    public Result lsitAndCamera(@RequestParam(value = "farmId") Integer farmId) {

        return cameraFuntcionService.lsitAndCamera(farmId);

    }
    @PostMapping("/addCamera")
    public Result addCamera(@RequestBody Map<String, String> params) {

        return cameraFuntcionService.addCamera(params);

    }
    @PostMapping("/listCamera")
    public Result listCamera(@RequestBody Map<String, String> params) {

        return cameraFuntcionService.listCamera(params);

    }

    @PostMapping("/deleteCamera")
    public Result deleteCamera(@RequestBody Map<String, String> params) {

        return cameraFuntcionService.deleteCamera(params);

    }



}
