|
|
@ -1,12 +1,15 @@ |
|
|
|
package com.zc.business.controller; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
import com.ruoyi.common.annotation.Log; |
|
|
|
import com.ruoyi.common.core.controller.BaseController; |
|
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
import com.ruoyi.common.core.page.TableDataInfo; |
|
|
|
import com.ruoyi.common.enums.BusinessType; |
|
|
|
import com.zc.business.constant.DeviceTypeConstants; |
|
|
|
import com.zc.business.domain.DcDevice; |
|
|
|
import com.zc.business.request.DeviceGetPropertiesOperateRequest; |
|
|
|
import com.zc.business.service.IDcDeviceService; |
|
|
@ -25,9 +28,7 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.validation.Valid; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 设备Controller |
|
|
@ -45,6 +46,9 @@ public class DcDeviceController extends BaseController { |
|
|
|
@Value("${iot.address}") |
|
|
|
private String iotAddress; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private BroadcastController broadcastController; |
|
|
|
|
|
|
|
//*********************************设备增删改查******************************************
|
|
|
|
|
|
|
|
/** |
|
|
@ -368,16 +372,28 @@ public class DcDeviceController extends BaseController { |
|
|
|
@ApiOperation("批量设备功能调用") |
|
|
|
@PostMapping("/batchFunctions") |
|
|
|
public AjaxResult batchInvokedFunction(@RequestBody Map<String, Object> props) throws HttpException, IOException, InterruptedException { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(props); |
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.url(iotAddress + "/api/iot/device/batchFunctions") // 请求地址
|
|
|
|
.data(requestParams) |
|
|
|
.post(); // 请求方法
|
|
|
|
return JSON.parseObject(response.body().string(), AjaxResult.class); |
|
|
|
List<DcDevice> devices = (List<DcDevice>) props.get("devices"); |
|
|
|
JSONArray functions = (JSONArray) props.get("functions"); |
|
|
|
JSONArray resultArray = new JSONArray(); |
|
|
|
for (DcDevice device : devices) { |
|
|
|
String iotDeviceId = device.getIotDeviceId(); |
|
|
|
for (Object function : functions) { |
|
|
|
JSONObject functionJSONObject = JSONObject.parseObject(String.valueOf(function)); |
|
|
|
String functionId = functionJSONObject.getString("functionId"); |
|
|
|
JSONObject jsonObject = functionJSONObject.getJSONObject("params"); |
|
|
|
HashMap<String, Object> params = jsonObject.toJavaObject(new TypeReference<HashMap<String, Object>>() { |
|
|
|
}); |
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
result.put("device", device.getId()); |
|
|
|
if (device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { |
|
|
|
result.put("result", broadcastController.nearCamListDistance(jsonObject)); |
|
|
|
} else { |
|
|
|
result.put("result", invokedFunction(iotDeviceId, functionId, params)); |
|
|
|
} |
|
|
|
resultArray.add(result); |
|
|
|
} |
|
|
|
} |
|
|
|
return AjaxResult.success(resultArray); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|