@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource ;
import javax.validation.Valid ;
import java.io.IOException ;
import java.lang.reflect.Field ;
import java.util.* ;
/ * *
@ -210,6 +211,7 @@ public class DcDeviceController extends BaseController {
/ * *
* 查询当天设备指定属性列表
*
* @param deviceId 设备id
* @param propertyId 属性id
* @return 属性列表
@ -217,7 +219,7 @@ public class DcDeviceController extends BaseController {
@ApiOperation ( "查询当天设备指定属性列表" )
@GetMapping ( "/properties/history/day/{deviceId}/{propertyId}" )
public AjaxResult queryDevicePropertiesOneDay ( @PathVariable @Parameter ( description = "设备ID" ) String deviceId ,
@PathVariable @Parameter ( description = "属性ID" ) String propertyId ) throws HttpException , IOException {
@PathVariable @Parameter ( description = "属性ID" ) String propertyId ) throws HttpException , IOException {
HashMap < String , Object > props = new HashMap < > ( ) ;
// 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内
@ -229,8 +231,8 @@ public class DcDeviceController extends BaseController {
// 将日期列表以逗号分隔并设置为查询条件的值
props . put ( "terms[0].value" , String . join ( "," , dateList ) ) ;
props . put ( "paging" , false ) ;
props . put ( "sorts[0].order" , "asc" ) ;
props . put ( "sorts[0].name" , "timestamp" ) ;
props . put ( "sorts[0].order" , "asc" ) ;
props . put ( "sorts[0].name" , "timestamp" ) ;
AjaxResult ajaxResult = queryDeviceProperties ( deviceId , propertyId , props ) ;
if ( ! ajaxResult . get ( "code" ) . equals ( 200 ) ) {
return ajaxResult ;
@ -240,12 +242,12 @@ public class DcDeviceController extends BaseController {
JSONArray dataArray = JSON . parseArray ( data . toString ( ) ) ;
List < Object > list = new ArrayList < > ( ) ;
dataArray . forEach ( o - > {
Map < String , Object > map = new HashMap < > ( ) ;
Map < String , Object > map = new HashMap < > ( ) ;
JSONObject jsonObject = JSON . parseObject ( o . toString ( ) ) ;
JSONObject formatValue = JSON . parseObject ( jsonObject . get ( "formatValue" ) . toString ( ) ) ;
map . put ( "1" , formatValue . get ( "1" ) ) ;
map . put ( "3" , formatValue . get ( "3" ) ) ;
map . put ( "timestamp" , jsonObject . get ( "timestamp" ) ) ;
map . put ( "1" , formatValue . get ( "1" ) ) ;
map . put ( "3" , formatValue . get ( "3" ) ) ;
map . put ( "timestamp" , jsonObject . get ( "timestamp" ) ) ;
list . add ( map ) ;
} ) ;
return AjaxResult . success ( list ) ;
@ -430,7 +432,7 @@ public class DcDeviceController extends BaseController {
. data ( requestParams )
. post ( ) ; // 请求方法
return JSON . parseObject ( response . body ( ) . string ( ) , AjaxResult . class ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
return AjaxResult . error ( "请求失败" ) ;
}
@ -454,21 +456,61 @@ public class DcDeviceController extends BaseController {
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 ) ;
resultArray . add ( getResult ( device , iotDeviceId , functionId , jsonObject ) ) ;
}
}
return AjaxResult . success ( resultArray ) ;
}
private JSONObject getResult ( DcDevice device , String iotDeviceId , String functionId , JSONObject jsonObject ) throws HttpException , IOException {
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 ) ) ;
}
return result ;
}
/ * *
* 批量设备功能调用
*
* @param props 调用参数列表
* @return 调用结果
* /
@ApiOperation ( "批量激光疲劳设备功能调用" )
@PostMapping ( "/batchLaserFatigueInvokedFunction" )
public AjaxResult batchLaserFatigueInvokedFunction ( @RequestBody Map < String , Object > props ) throws HttpException , IOException , InterruptedException {
String deviceId = ( String ) props . get ( "deviceId" ) ;
String functionId = ( String ) props . get ( "functionId" ) ;
ArrayList params = ( ArrayList ) props . get ( "params" ) ;
JSONArray resultArray = new JSONArray ( ) ;
for ( Object param : params ) {
resultArray . add ( invokedFunction ( deviceId , functionId , ( HashMap < String , Object > ) param ) ) ;
}
HashMap < String , Object > hashMap = new HashMap < > ( ) ;
hashMap . put ( "SET" , "7" ) ;
invokedFunction ( deviceId , "SETMD" , hashMap ) ;
return AjaxResult . success ( resultArray ) ;
}
public HashMap < String , Object > objectToMap ( Object obj ) {
Map < String , Object > map = new HashMap < > ( ) ;
for ( Field field : obj . getClass ( ) . getDeclaredFields ( ) ) {
try {
field . setAccessible ( true ) ;
map . put ( field . getName ( ) , field . get ( obj ) ) ;
} catch ( IllegalAccessException e ) {
e . printStackTrace ( ) ;
}
}
return ( HashMap < String , Object > ) map ;
}
/ * *
* 查询物联设备事件数据
*