//package com.ruoyi.web.core.wvp;
//
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.ruoyi.common.utils.spring.SpringUtils;
//import com.ruoyi.web.core.nfid.MultiReaderNFIDProcessor;
//import com.ruoyi.web.core.wvp.domain.ApiResponse;
//import com.ruoyi.common.constant.Constants;
//import com.ruoyi.common.utils.StringUtils;
//import com.ruoyi.common.utils.http.HttpResponse;
//import com.ruoyi.common.utils.poi.ExcelUtil;
//import com.ruoyi.web.core.wvp.domain.DeviceChannelExtend;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import java.net.HttpURLConnection;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import static com.ruoyi.common.utils.http.HttpUtils.*;
//
//@Component
//public class DeviceHandler {
//    @Value(value = "${wvp.addr}")
//    private String addr;
//
//    private final SessionHandler sessionHandler = SpringUtils.getBean(SessionHandler.class);
//
//    public static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
//
//    public static final String VIDEO_PLAY_START = "start";
//
//    public static final String VIDEO_PLAY_STOP = "stop";
//
//    //播放
//    public Object playOrStop(String type,String deviceId,String channelId) throws Exception{
//            String url= addr+ "/api/play/"+type+"/" + deviceId + "/" + channelId;
//            Map<String, String> headers = new HashMap<>();
//            String token = sessionHandler.getToken();
//            if (StringUtils.isNotEmpty(token)) {
//                headers.put("access-token", sessionHandler.getToken());
//            }else{
//                throw new RuntimeException("登录WVP失败");
//            }
//            HttpResponse response = sendHttpGet(url, StringUtils.EMPTY, Constants.UTF8,headers);
//            if(response.getStatusCode() == HttpURLConnection.HTTP_OK){
//                // 处理响应
//                ApiResponse<Object> apiResponse = JsonParser.parseWithJavaType(response.getContent(), Object.class);
//
//                if (apiResponse.getCode()!=null && apiResponse.getCode() ==0) {
//                    return apiResponse.getData();
//                } else {
//                    throw new RuntimeException(apiResponse.getMsg());
//                }
//            }else if (response.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED){
//                //是否重新登录
//                if (sessionHandler.needRelogin()){
//                    //重新登录
//                    sessionHandler.refreshToken();
//                }
//            }
//            return null;
//    }
//
//    //设备清单
//    public List<DeviceChannelExtend> getDeviceList() throws Exception {
//        try {
//            String url= addr+ "/api/device/query/allChannels";
//            Map<String, String> headers = new HashMap<>();
//            String token = sessionHandler.getToken();
//            if (StringUtils.isNotEmpty(token)) {
//                headers.put("access-token", sessionHandler.getToken());
//            }else{
//                throw new RuntimeException("登录WVP失败");
//            }
//            HttpResponse response = sendHttpGet(url, StringUtils.EMPTY, Constants.UTF8,headers);
//            if(response.getStatusCode() == HttpURLConnection.HTTP_OK){
//                TypeReference<ApiResponse<List<DeviceChannelExtend>>> typeRef =
//                        new TypeReference<ApiResponse<List<DeviceChannelExtend>>>() {};
//                // 处理响应
//                ApiResponse<List<DeviceChannelExtend>> apiResponse = ApiResponseParser.parseFullResponse(response.getContent(), typeRef);
//
//                if (apiResponse.getCode()!=null && apiResponse.getCode() ==0) {
//                    return apiResponse.getData();
//                } else {
//                    throw new RuntimeException(apiResponse.getMsg());
//                }
//            }else if (response.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED){
//                //是否重新登录
//                if (sessionHandler.needRelogin()){
//                    //重新登录
//                    sessionHandler.refreshToken();
//                }
//                throw new Exception("重新登录");
//            }
//
//        }catch (Exception e){
//            log.error("请求失败: " + e.getMessage());
//            throw e;
//        }
//        return new ArrayList<>();
//    }
//}
