@ -2,6 +2,7 @@ package com.hnac.hzinfo.inspect.ai.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import com.google.common.collect.Lists ;
import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient ;
@ -29,14 +30,17 @@ import com.hnac.hzinfo.inspect.ai.entity.RobotEntity;
import com.hnac.hzinfo.inspect.ai.mapper.RobotMapper ;
import com.hnac.hzinfo.inspect.ai.service.IRobotService ;
import org.springblade.core.mp.support.Condition ;
import org.springblade.core.mp.support.Query ;
import org.springblade.core.tool.api.R ;
import org.springblade.core.tool.utils.BeanUtil ;
import org.springblade.core.tool.utils.Func ;
import org.springblade.core.tool.utils.ObjectUtil ;
import org.springblade.core.tool.utils.StringUtil ;
import org.springblade.system.cache.ParamCache ;
import org.springframework.stereotype.Service ;
import org.springframework.util.Assert ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Collectors ;
@ -81,7 +85,9 @@ public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity>
device . setModelSignage ( Func . isNotEmpty ( device . getModelSignage ( ) ) ? device . getModelSignage ( ) : modelSignage ) ;
VirtualDeviceDTO req = BeanUtil . copy ( device , VirtualDeviceDTO . class ) ;
req . setIsStandard ( 1 ) ;
req . setProjectId ( device . getStationCode ( ) ) ;
req . setProtocolSignage ( "standard" ) ;
req . setSecretKey ( device . getSecretKey ( ) ) ;
R < Long > saveResult = deviceClient . saveVirtualDevice ( req ) ;
Assert . isTrue ( saveResult . isSuccess ( ) , ( ) - > {
throw new ServiceException ( "生成设备实例失败,报错信息为:" + saveResult . getMsg ( ) ) ;
@ -89,27 +95,46 @@ public class RobotServiceImpl extends BaseServiceImpl<RobotMapper, RobotEntity>
LambdaUpdateWrapper < RobotEntity > luw = Wrappers . < RobotEntity > lambdaUpdate ( )
. set ( RobotEntity : : getIsDeviceInstance , true )
. eq ( RobotEntity : : getCode , device . getDeviceCode ( ) ) ;
return this . update ( luw ) ;
this . update ( luw ) ;
return true ;
}
}
@Override
public List < RobotRealDataVO > getRealDataByRobotCode ( String robotCode ) {
Result < List < DeviceInstanceAttrVO > > attrResult = deviceClient . getDeviceInstaceAttrsByDeviceCodes ( Lists . newArrayList ( robotCode ) ) ;
Assert . isTrue ( attrResult . isSuccess ( ) , ( ) - > {
throw new ServiceException ( "获取设备实例物模型失败!" ) ;
} ) ;
DeviceRealDataPO po = new DeviceRealDataPO ( ) ;
po . setDeviceCode ( robotCode ) ;
po . setSignages ( attrResult . getData ( ) . stream ( ) . map ( DeviceInstanceAttrVO : : getSignage ) . collect ( Collectors . toList ( ) ) ) ;
Result < List < List < Map < String , RealDataRedisVO > > > > realDataResult = deviceDataClient . getDeviceRealDataByCodes ( Lists . newArrayList ( po ) ) ;
Assert . isTrue ( realDataResult . isSuccess ( ) , ( ) - > {
throw new ServiceException ( "获取设备实例实时数据失败!" ) ;
} ) ;
List < RobotRealDataVO > result = realDataResult . getData ( ) . stream ( )
. flatMap ( l - > l . stream ( ) )
. flatMap ( m - > m . entrySet ( ) . stream ( ) . map ( k - > BeanUtil . copy ( m . get ( k ) , RobotRealDataVO . class ) ) )
. collect ( Collectors . toList ( ) ) ;
. flatMap ( m - > m . entrySet ( ) . stream ( ) . map ( k - > {
RobotRealDataVO data = BeanUtil . copy ( k . getValue ( ) , RobotRealDataVO . class ) ;
data . setAttrName ( k . getValue ( ) . getN ( ) ) ;
return data ;
} ) ) . collect ( Collectors . toList ( ) ) ;
return result ;
}
@Override
public IPage getRobotSoeData ( String robotCode , String startTime , String endTime , Query query ) {
RobotEntity request = new RobotEntity ( ) ;
request . setCode ( robotCode ) ;
RobotEntity robot = this . getOne ( Wrappers . < RobotEntity > lambdaQuery ( ) . eq ( RobotEntity : : getCode , robotCode ) ) ;
Assert . isTrue ( ObjectUtil . isNotEmpty ( robot ) & & StringUtil . isNotBlank ( robot . getStationCode ( ) ) , ( ) - > {
throw new ServiceException ( "该机器人未绑定站点,无法获取告警数据!" ) ;
} ) ;
Result < Map < String , Object > > deviceSoeDataResult = deviceDataClient . getDeviceSoeData ( robot . getStationCode ( ) , 1 , robotCode , null ,
startTime , endTime , true , query . getCurrent ( ) , query . getSize ( ) ) ;
Assert . isTrue ( deviceSoeDataResult . isSuccess ( ) , ( ) - > {
throw new ServiceException ( "获取机器人告警信息失败!" ) ;
} ) ;
Map < String , Object > deviceSoeData = deviceSoeDataResult . getData ( ) ;
IPage result = Condition . getPage ( query ) ;
result . setRecords ( ( List ) deviceSoeData . get ( "data" ) ) ;
result . setTotal ( Long . valueOf ( ( int ) deviceSoeData . get ( "total" ) ) ) ;
return result ;
}