|
|
@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ruoyi.common.core.controller.BaseController; |
|
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
import com.zc.business.domain.DcDevice; |
|
|
|
import com.zc.business.service.IDcDeviceService; |
|
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
|
import com.zc.common.core.httpclient.request.RequestParams; |
|
|
@ -11,10 +13,12 @@ import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
import okhttp3.Response; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
@ -45,6 +49,9 @@ public class VideoController extends BaseController { |
|
|
|
|
|
|
|
public static final Integer ERROR = 500; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private IDcDeviceService iDcDeviceService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询附近相机 |
|
|
|
*/ |
|
|
@ -96,6 +103,84 @@ public class VideoController extends BaseController { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/*** |
|
|
|
* 根据相机中的设备状态,修改数据平台设备的设备状态 |
|
|
|
*/ |
|
|
|
@Scheduled(cron = "0 0/5 * * * ?") |
|
|
|
public void updateDeviceState() throws HttpException, IOException { |
|
|
|
logger.debug("开始执行:同步数据平台设备的设备状态!!"); |
|
|
|
JSONObject cameraData = synchronizeCameraData(); |
|
|
|
if (cameraData.get("code").equals(200)) { |
|
|
|
JSONObject data =JSONObject.parseObject(JSONArray.parseArray(cameraData.get("data").toString()).get(0).toString()); |
|
|
|
JSONObject dataChildren =JSONObject.parseObject(JSONArray.parseArray(data.get("children").toString()).get(0).toString()); |
|
|
|
JSONObject qiLuGaoSu =JSONObject.parseObject(JSONArray.parseArray(dataChildren.get("children").toString()).get(0).toString()); |
|
|
|
JSONObject jiHeYunGuan =JSONObject.parseObject(JSONArray.parseArray(qiLuGaoSu.get("children").toString()).get(0).toString()); |
|
|
|
JSONArray jiHeYunGuanG35 = JSONArray.parseArray(jiHeYunGuan.get("children").toString()); |
|
|
|
List<DcDevice> list = new ArrayList<>(); |
|
|
|
for (Object json: jiHeYunGuanG35) { |
|
|
|
JSONObject item = JSONObject.parseObject(json.toString()); |
|
|
|
DcDevice device = new DcDevice(); |
|
|
|
if (item.get("status").equals("0")) { |
|
|
|
device.setDeviceState("1"); |
|
|
|
}else { |
|
|
|
device.setDeviceState("0"); |
|
|
|
} |
|
|
|
device.setIotDeviceId(item.get("camId").toString()); |
|
|
|
list.add(device); |
|
|
|
} |
|
|
|
|
|
|
|
iDcDeviceService.batchUpdate(list); |
|
|
|
logger.debug("执行:同步数据平台设备的设备状态成功!!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询同步相机数据 |
|
|
|
*/ |
|
|
|
public JSONObject synchronizeCameraData() throws HttpException, IOException { |
|
|
|
|
|
|
|
JSONObject jsonResult = null; |
|
|
|
|
|
|
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
Map<String, String> header = new HashMap<>(); |
|
|
|
|
|
|
|
if (VideoController.TOKEN == null) { |
|
|
|
getToken(); |
|
|
|
} |
|
|
|
|
|
|
|
header.put("Authorization", TOKEN); |
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(header) |
|
|
|
.url(URL + "/system/dept/camTreeselect") // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.get(); // 请求方法
|
|
|
|
|
|
|
|
if (response.body() != null) { |
|
|
|
jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
|
|
|
|
if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { |
|
|
|
getToken(); |
|
|
|
okHttp.get(); |
|
|
|
if (response.body() != null) { |
|
|
|
jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return jsonResult; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据桩号查询附近相机 |
|
|
|
*/ |
|
|
|