package com.ruoyi.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HikHttpUtils;
import com.ruoyi.system.service.HikcService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Set;
import java.util.UUID;

@Service
public class HikcServiceImpl implements HikcService {


    /**
     * 获取编码设备在线状态
     * @return 设备集合
     */
    @Override
    public AjaxResult previewUrl(SysDept dept) {

        JSONObject body = new JSONObject();
        body.put("cameraIndexCode", dept.getCameraCode());
        body.put("action", 0);
        body.put("command", "GOTO_PRESET");
        body.put("presetIndex", dept.getPresetPoints());

        try {

            String msg = HikHttpUtils.getInstance().doPostStringArtemis("/api/video/v1/ptzs/controlling", body);

            if (StringUtils.isEmpty(msg)) {
                return AjaxResult.error();
            }

            JSONObject object = JSONObject.parseObject(msg);

            if (!"0".equals(object.getString("code"))) {
                return AjaxResult.error();
            }

            return AjaxResult.success();

        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }


}
