package com.huimv.video.dhicc.controller.ClientController;

import com.alibaba.fastjson.JSON;
import com.dahuatech.hutool.http.Method;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.http.DefaultClient;
import com.dahuatech.icc.oauth.http.IClient;
import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

//其实可以整合到一起去了
@RestController
@RequestMapping("/accident")
public class ClientXixiaoController {

    /**
     * 洗消数据查询的接口，三个洗消的摄像头是固定的
     *
     * @param params
     * @return   183.148.150.65
     * @throws ClientException
     */
    @RequestMapping("/accident_record_xixiao")
    public GeneralResponse getAccidentRecord(@RequestBody Map<String, Object> params) throws ClientException {
        Integer farmId = (int) params.get("farmId");
        if (farmId != 1) {
            //返回为空数据
            return null;
        }
        String URL = "/evo-apigw/evo-event/1.2.0/alarm-record/page";  //获取事件URL    post请求
        IClient iClient = new DefaultClient();
        GeneralRequest generalRequest = new GeneralRequest(URL, Method.POST);
        generalRequest.header("Content-Type", " application/json");
        generalRequest.body(JSON.toJSONString(params));
        GeneralResponse generalResponse = iClient.doAction(generalRequest, generalRequest.getResponseClass());

        return generalResponse;

    }

    /**
     * 洗消数据查询的接口，三个洗消的摄像头是固定的--页数接口
     *
     * @param params
     * @return
     * @throws ClientException
     */
    @RequestMapping("/accident_record_xixiao_totalpage")
    public GeneralResponse getAccidentRecordTotalPage(@RequestBody Map<String, Object> params) throws ClientException {
        Integer farmId = (int) params.get("farmId");
        if (farmId != 1) {
            //返回为空数据
            return new GeneralResponse();
        }
        String URL = "/evo-apigw/evo-event/1.0.0/alarm-record/count-num";  //获取事件URL    post请求
        IClient iClient = new DefaultClient();
        GeneralRequest generalRequest = new GeneralRequest(URL, Method.POST);
        generalRequest.header("Content-Type", " application/json");
        generalRequest.body(JSON.toJSONString(params));
        GeneralResponse generalResponse = iClient.doAction(generalRequest, generalRequest.getResponseClass());
        return generalResponse;
    }
}