@ -1,5 +1,9 @@
package com.fastbee.data.service.devicedetail.impl ;
import cn.hutool.core.date.DateTime ;
import cn.hutool.core.date.DateUtil ;
import com.alibaba.fastjson2.JSON ;
import com.alibaba.fastjson2.JSONObject ;
import com.fastbee.common.core.domain.CommonResult ;
import com.fastbee.common.model.vo.iot.QueryLogVo ;
import com.fastbee.common.utils.DevParamsUtils ;
@ -9,11 +13,14 @@ import com.fastbee.data.domain.vo.AnfangInfoVo;
import com.fastbee.data.service.devicedetail.IDeviceDetailService ;
import com.fastbee.iot.anfang.service.IUploadedPhotosService ;
import com.fastbee.iot.domain.Device ;
import com.fastbee.iot.domain.DeviceLog ;
import com.fastbee.iot.domain.ThingsModel ;
import com.fastbee.iot.haiwei.service.HaiWeiService ;
import com.fastbee.iot.mapper.DeviceMapper ;
import com.fastbee.iot.model.anfang.UploadedPhotos ;
import com.fastbee.iot.model.haiwei.CmdHaiWeiVo ;
import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto ;
import com.fastbee.iot.service.IDeviceLogService ;
import com.fastbee.iot.service.IDeviceService ;
import com.fastbee.iot.service.IThingsModelService ;
import com.fastbee.waterele.domain.MaWatereleRecord ;
@ -28,6 +35,7 @@ import org.springframework.stereotype.Service;
import javax.xml.crypto.Data ;
import java.util.* ;
import java.util.stream.Collectors ;
@Service
public class DeviceDetailServiceImpl implements IDeviceDetailService {
@ -47,6 +55,10 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
@Autowired
private IUploadedPhotosService uploadedPhotosService ;
@Autowired
private IDeviceLogService logService ;
public DeviceDetailServiceImpl ( DeviceMapper deviceMapper ) {
this . deviceMapper = deviceMapper ;
}
@ -97,6 +109,7 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
return deviceLogAllCurves ;
}
@Override
public List < XjInspectionRecords > xunjianRecord ( QueryLogVo queryLogVo ) {
//todo
@ -112,7 +125,7 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
xjInspectionRoutes . setEngineeringObjectId ( deviceId ) ;
xjInspectionRoutes . setEngineeringObjectType ( " 1 " ) ;
List < XjInspectionRoutes > xjInspectionRoutes1 = xjInspectionRoutesMapper . selectXjInspectionRoutesList ( xjInspectionRoutes ) ;
if ( xjInspectionRoutes1 . size ( ) > 0 ) {
if ( xjInspectionRoutes1 . size ( ) > 0 ) {
List < XjInspectionRecords > xjInspectionRecordsList = new ArrayList < > ( ) ;
XjInspectionRecords xjInspectionRecords = new XjInspectionRecords ( ) ;
xjInspectionRecords . setInspectionRouteId ( xjInspectionRoutes1 . get ( 0 ) . getId ( ) ) ;
@ -136,44 +149,129 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
Map < String , Object > devParams = DevParamsUtils . getDevParams ( device . getDevParams ( ) ) ;
//安防设备
String jiankongIds = devParams . get ( " jiankongIds " ) . toString ( ) ;
if ( StringUtils . isNotEmpty ( jiankongIds ) ) {
if ( StringUtils . isNotEmpty ( jiankongIds ) ) {
Device jiankongDevice = iDeviceService . selectDeviceByDeviceId ( Long . parseLong ( jiankongIds ) ) ;
anfangInfoVo . setJiankongDevice ( jiankongDevice ) ;
}
//安防设备
String anfangIds = devParams . get ( " anfangIds " ) . toString ( ) ;
//获取设备安防状态
if ( StringUtils . isNotEmpty ( anfangIds ) ) {
if ( StringUtils . isNotEmpty ( anfangIds ) ) {
Device anfangDevice = iDeviceService . selectDeviceByDeviceId ( Long . parseLong ( anfangIds ) ) ;
//获取当前安防告警状态
UploadedPhotos uploadedPhotos = new UploadedPhotos ( ) ;
uploadedPhotos . setSn ( anfangDevice . getSerialNumber ( ) ) ;
List < UploadedPhotos > uploadedPhotos1 = uploadedPhotosService . selectUploadedPhotosList ( uploadedPhotos ) ;
int doorStatus = 0 ; //0=正常, 1=箱门振动, 2=箱门打开
if ( uploadedPhotos1 . size ( ) > 0 ) {
if ( uploadedPhotos1 . size ( ) > 0 ) {
UploadedPhotos temp = uploadedPhotos1 . get ( 0 ) ;
if ( new Date ( ) . getTime ( ) - temp . getUploadTime ( ) . getTime ( ) < 36000000 ) {
if ( temp . getShakeState ( ) . equals ( " 1 " ) ) {
if ( new Date ( ) . getTime ( ) - temp . getUploadTime ( ) . getTime ( ) < 36000000 ) {
if ( temp . getShakeState ( ) . equals ( " 1 " ) ) {
doorStatus = 1 ;
}
if ( temp . getDoorState ( ) . equals ( " 1 " ) ) {
if ( temp . getDoorState ( ) . equals ( " 1 " ) ) {
doorStatus = 2 ;
}
}
}
if ( uploadedPhotos1 . size ( ) > 5 ) {
uploadedPhotos1 = uploadedPhotos1 . subList ( 0 , 5 ) ;
if ( uploadedPhotos1 . size ( ) > 5 ) {
uploadedPhotos1 = uploadedPhotos1 . subList ( 0 , 5 ) ;
}
anfangInfoVo . setDoorStatus ( doorStatus ) ;
anfangInfoVo . setAnfangList ( uploadedPhotos1 ) ;
}
//安防设备
String guimenIds = devParams . get ( " guimenIds " ) . toString ( ) ;
if ( StringUtils . isNotEmpty ( guimenIds ) ) {
if ( StringUtils . isNotEmpty ( guimenIds ) ) {
anfangInfoVo . setGuimenId ( devParams . get ( " guimenIds " ) . toString ( ) ) ;
}
return anfangInfoVo ;
}
@Override
public List < HashMap < Object , Object > > gongdianRealData ( QueryLogVo queryLogVo ) {
Long deviceId = queryLogVo . getDeviceId ( ) ;
if ( deviceId = = null ) {
throw new RuntimeException ( " 请上传devicerId " ) ;
}
Device device = iDeviceService . selectDeviceByDeviceId ( deviceId ) ;
if ( device = = null ) {
throw new RuntimeException ( " 未查到该设备 " ) ;
}
DateTime dateTime = DateUtil . date ( new Date ( ) ) ;
Map < String , Object > devParams = DevParamsUtils . getDevParams ( device . getDevParams ( ) ) ;
//太阳能设备
String taiyangnengIds = devParams . get ( " taiyangnIds " ) . toString ( ) ;
ThingsModel thingsModel1 = new ThingsModel ( ) ;
thingsModel1 . setProductId ( 138L ) ;
List < ThingsModel > taiyangnengModels = thingsModelService . selectThingsModelList ( thingsModel1 ) ;
taiyangnengModels . sort ( Comparator . comparing ( ThingsModel : : getModelOrder ) ) ;
List < HashMap < Object , Object > > list = new ArrayList < > ( ) ;
if ( StringUtils . isNotEmpty ( taiyangnengIds ) ) {
Device taiyangnengDevice = deviceMapper . selectDeviceByDeviceId ( Long . parseLong ( taiyangnengIds ) ) ;
List < DeviceLog > deviceLogs = logService . selectDeviceLogList ( new DeviceLog ( ) { {
setSerialNumber ( taiyangnengDevice . getSerialNumber ( ) ) ;
setBeginTime ( DateUtil . beginOfDay ( DateUtil . offsetDay ( dateTime , - 1 ) ) . toString ( ) ) ;
setEndTime ( DateUtil . endOfDay ( dateTime ) . toString ( ) ) ;
} } ) ;
Map < String , List < DeviceLog > > taiyangnengCollect = deviceLogs . stream ( ) . sorted ( Comparator
. comparing ( DeviceLog : : getCreateTime , Comparator
. nullsFirst ( Comparator . naturalOrder ( ) ) ) . reversed ( ) ) . collect ( Collectors . groupingBy ( t - > t . getIdentity ( ) ) ) ;
for ( ThingsModel thingsModel : taiyangnengModels ) {
HashMap < Object , Object > hashMap = new HashMap < Object , Object > ( ) { {
put ( " upType " , 0 ) ;
put ( " identifier " , thingsModel . getIdentifier ( ) ) ;
put ( " unit " , " " ) ;
put ( " value " , 0 ) ;
put ( " name " , thingsModel . getModelName ( ) ) ;
} } ;
if ( StringUtils . isNotEmpty ( thingsModel . getSpecs ( ) ) ) {
String specs = thingsModel . getSpecs ( ) ;
JSONObject parse = ( JSONObject ) JSON . parse ( specs ) ;
if ( parse . containsKey ( " unit " ) ) {
hashMap . put ( " unit " , parse . get ( " unit " ) ) ;
}
}
if ( hashMap . size ( ) > 1 ) {
List < DeviceLog > deviceLogs1 = taiyangnengCollect . get ( thingsModel . getIdentifier ( ) ) ;
if ( deviceLogs1 ! = null ) {
if ( StringUtils . isNotEmpty ( deviceLogs1 . get ( 0 ) . getLogValue ( ) ) ) {
if ( Float . parseFloat ( deviceLogs1 . get ( 0 ) . getLogValue ( ) ) = = Float . parseFloat ( deviceLogs1 . get ( 1 ) . getLogValue ( ) ) ) {
hashMap . put ( " upType " , 1 ) ;
} else if ( Float . parseFloat ( deviceLogs1 . get ( 0 ) . getLogValue ( ) ) < Float . parseFloat ( deviceLogs1 . get ( 1 ) . getLogValue ( ) ) ) {
hashMap . put ( " upType " , - 1 ) ;
}
hashMap . put ( " value " , deviceLogs1 . get ( 0 ) . getLogValue ( ) ) ;
} else {
hashMap . put ( " value " , " -- " ) ;
hashMap . put ( " upType " , 0 ) ;
}
}
} else if ( hashMap . size ( ) > 0 ) {
List < DeviceLog > deviceLogs2 = taiyangnengCollect . get ( thingsModel . getIdentifier ( ) ) ;
if ( deviceLogs2 ! = null ) {
hashMap . put ( " value " , deviceLogs2 . get ( 0 ) . getLogValue ( ) ) ;
}
}
list . add ( hashMap ) ;
}
} else {
for ( ThingsModel thingsModel : taiyangnengModels ) {
HashMap < Object , Object > hashMap = new HashMap < Object , Object > ( ) { {
put ( " upType " , 0 ) ;
put ( " identifier " , thingsModel . getIdentifier ( ) ) ;
put ( " unit " , " " ) ;
put ( " value " , 0 ) ;
put ( " name " , thingsModel . getModelName ( ) ) ;
} } ;
list . add ( hashMap ) ;
}
}
return list ;
}
@Override
public CommonResult < CmdHaiWeiVo > cmdDevices ( CmdHaiWeiDto cmdHaiWeiDto ) {
String url = " https://cloud.haiwell.com/api/project/machine/datagroup/setTagsValue " ;