@ -17,13 +17,12 @@ import com.bellmann.common.result.ResultCode;
import com.bellmann.converter.DeviceStaticConverter ;
import com.bellmann.manger.* ;
import com.bellmann.mapper.* ;
import com.bellmann.model.bo.DownloadInfo ;
import com.bellmann.model.bo.EquipmentBO ;
import com.bellmann.model.bo.RemoteEquipmentBO ;
import com.bellmann.model.dto.OperationTask ;
import com.bellmann.model.entity.* ;
import com.bellmann.model.form.EquipmentAddForm ;
import com.bellmann.model.form.EquipmentDetailForm ;
import com.bellmann.model.form.PrivateProfileForm ;
import com.bellmann.model.form.UnBindingForm ;
import com.bellmann.model.form.* ;
import com.bellmann.model.query.DevOuiSnoQuery ;
import com.bellmann.model.query.SelectQuery ;
import com.bellmann.model.vo.* ;
@ -48,11 +47,13 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.time.LocalDateTime ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
import java.util.Map ;
import java.util.* ;
import java.util.concurrent.TimeUnit ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import java.util.stream.Collectors ;
@Service
@ -93,6 +94,10 @@ public class DeviceStaticServiceImpl implements DeviceStaticService {
private final DeviceServiceArgsMapper deviceServiceArgsMapper ;
private final OperateResult2Mapper operateResult2Mapper ;
private final DeviceLogMapper deviceLogMapper ;
@Override
public Page < EquipmentVO > resourcePage ( SelectQuery query ) {
@ -500,4 +505,375 @@ public class DeviceStaticServiceImpl implements DeviceStaticService {
}
return result ;
}
@Override
public Long remoteIpPing ( PingForm ping ) {
long taskId = 0 ;
DOperTask2DetailStruct detailStruct = new DOperTask2DetailStruct ( ) ;
DOperTask2Struct operTaskStruct = new DOperTask2Struct ( ) ;
operTaskStruct . devId = ping . getDeviceId ( ) ;
operTaskStruct . operName = RemoteOperateMsgEnum . IP_PING . getValue ( ) ;
operTaskStruct . operTaskCreateTime = ( new Date ( ) ) . getTime ( ) ;
operTaskStruct . operTaskDesc = RemoteOperateMsgEnum . IP_PING . getLabel ( ) ;
operTaskStruct . operTaskId = Utils . LONG_NULL ;
operTaskStruct . userName = SecurityUtils . getUsername ( ) ;
detailStruct . operTask = operTaskStruct ;
DOperTaskArgsStruct [ ] argsStruct = new DOperTaskArgsStruct [ 4 ] ;
argsStruct [ 0 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 0 ] . argsName = "host" ;
argsStruct [ 0 ] . argsValue = ping . getHost ( ) = = null ? "8.8.8.8" : ping . getHost ( ) ;
argsStruct [ 0 ] . operTaskId = Utils . LONG_NULL ;
argsStruct [ 1 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 1 ] . argsName = "pingNumber" ;
argsStruct [ 1 ] . argsValue = ping . getPingNumber ( ) = = null ? "3" : ping . getPingNumber ( ) ;
argsStruct [ 1 ] . operTaskId = Utils . LONG_NULL ;
argsStruct [ 2 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 2 ] . argsName = "packSize" ;
argsStruct [ 2 ] . argsValue = ping . getPackSize ( ) = = null ? "32" : ping . getPackSize ( ) ;
argsStruct [ 2 ] . operTaskId = Utils . LONG_NULL ;
argsStruct [ 3 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 3 ] . argsName = "pingInterface" ;
argsStruct [ 3 ] . argsValue = ping . getPingInterface ( ) = = null ? "INTERNET" : ping . getPingInterface ( ) ;
argsStruct [ 3 ] . operTaskId = Utils . LONG_NULL ;
detailStruct . operTaskArgsList = argsStruct ;
DOperTask2DetailStructHolder detailStructHolder = new DOperTask2DetailStructHolder (
detailStruct ) ;
int result = OAMManager . sendDeviceOper2Task ( detailStructHolder ) ;
if ( result ! = 0 ) {
throw new BusinessException ( ResultCode . OAM_INTERFACE_ERROR ) ;
}
taskId = detailStructHolder . value . operTask . operTaskId ;
return taskId ;
}
@Override
public Long remoteDeviceMonitor ( DeviceMonitorForm form ) {
DOperTask2DetailStruct detailStruct = new DOperTask2DetailStruct ( ) ;
DOperTask2Struct operTaskStruct = new DOperTask2Struct ( ) ;
operTaskStruct . devId = form . getDevId ( ) ;
operTaskStruct . operName = RemoteOperateMsgEnum . DEVICE_MONITOR . getValue ( ) ;
operTaskStruct . operTaskCreateTime = ( new Date ( ) ) . getTime ( ) ;
operTaskStruct . operTaskDesc = RemoteOperateMsgEnum . DEVICE_MONITOR . getLabel ( ) ;
operTaskStruct . operTaskId = Utils . LONG_NULL ;
operTaskStruct . userName = SecurityUtils . getUsername ( ) ;
detailStruct . operTask = operTaskStruct ;
DOperTaskArgsStruct [ ] argsStruct = new DOperTaskArgsStruct [ 2 ] ;
argsStruct [ 0 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 0 ] . argsName = "MONITOR_PERIOD" ;
argsStruct [ 0 ] . argsValue = String . valueOf ( Long . parseLong ( form
. getMonitorPeriod ( ) ) * 1000 ) ;
argsStruct [ 0 ] . operTaskId = Utils . LONG_NULL ;
argsStruct [ 1 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 1 ] . argsName = "MONITOR_INTERVAL" ;
argsStruct [ 1 ] . argsValue = String . valueOf ( Long . parseLong ( form
. getMonitorInterval ( ) ) * 1000 ) ;
argsStruct [ 1 ] . operTaskId = Utils . LONG_NULL ;
detailStruct . operTaskArgsList = argsStruct ;
DOperTask2DetailStructHolder detailStructHolder = new DOperTask2DetailStructHolder (
detailStruct ) ;
int result = OAMManager . sendDeviceOper2Task ( detailStructHolder ) ;
if ( result ! = 0 ) {
throw new BusinessException ( ResultCode . OAM_INTERFACE_ERROR ) ;
}
return detailStructHolder . value . operTask . operTaskId ;
}
@Override
public Long remoteCheckConnType ( Long devId ) {
DOperTask2DetailStruct detailStruct = new DOperTask2DetailStruct ( ) ;
DOperTask2Struct operTaskStruct = new DOperTask2Struct ( ) ;
operTaskStruct . devId = devId ;
operTaskStruct . operName = RemoteOperateMsgEnum . GetConnType . getValue ( ) ;
operTaskStruct . operTaskCreateTime = ( new Date ( ) ) . getTime ( ) ;
operTaskStruct . operTaskDesc = RemoteOperateMsgEnum . GetConnType . getLabel ( ) ;
operTaskStruct . operTaskId = - 999 ;
operTaskStruct . userName = "system" ;
detailStruct . operTask = operTaskStruct ;
DOperTaskArgsStruct [ ] argsStruct = new DOperTaskArgsStruct [ 1 ] ;
argsStruct [ 0 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 0 ] . argsName = "" ;
argsStruct [ 0 ] . argsValue = "" ;
argsStruct [ 0 ] . operTaskId = operTaskStruct . operTaskId ;
detailStruct . operTaskArgsList = argsStruct ;
DOperTask2DetailStructHolder detailStructHolder = new DOperTask2DetailStructHolder ( detailStruct ) ;
int result = OAMManager . sendDeviceOper2Task ( detailStructHolder ) ;
if ( result ! = 0 ) {
throw new BusinessException ( ResultCode . OAM_INTERFACE_ERROR ) ;
}
return detailStructHolder . value . operTask . operTaskId ;
}
@Override
public String remoteConnType ( Long taskId , Long devId ) {
boolean found = true ;
int attempt = 0 ;
String connType = "v不在线" ;
while ( attempt < 5 & & found ) {
OperateResult2 operateResult2 = operateResult2Mapper . selectOne (
new QueryWrapper < OperateResult2 > ( )
. eq ( "oper_task_id" , taskId )
) ;
if ( operateResult2 = = null ) {
throw new BusinessException ( ResultCode . TASK_NOT_FOUND ) ;
}
String state = operateResult2 . getResultState ( ) ;
if ( OperateTaskStateEnum . NOT_EXECUTED . getValue ( ) . equals ( state ) ) {
throw new BusinessException ( ResultCode . TASK_NOT_EXE ) ;
}
if ( ! OperateTaskStateEnum . ONGOING . getValue ( ) . equals ( state ) ) {
if ( OperateTaskStateEnum . THE_EXECUTION_WAS_SUCCESSFUL . getValue ( ) . equals ( state ) ) {
String desc = deviceLogMapper . getTaskResultByTaskId ( taskId , RemoteOperateMsgEnum . GetConnType . getValue ( ) ) ;
String regex = SystemConstants . CONN_TYPE_REGEX ;
Pattern pattern = Pattern . compile ( regex ) ;
Matcher matcher = pattern . matcher ( desc ) ;
String connectionType = "" ;
if ( matcher . find ( ) ) {
connectionType = matcher . group ( 1 ) . trim ( ) ;
if ( "IP_Routed" . equals ( connectionType ) ) {
connType = SystemConstants . CONN_TYPE_IP_ROUTED ;
} else if ( "PPPoE_Bridged" . equals ( connectionType ) ) {
connType = SystemConstants . CONN_TYPE_PPPOE_BRIDGE ;
}
} else {
connType = "v不在线" ;
}
} else {
connType = "v不在线" ;
}
found = false ;
}
if ( found ) {
try {
TimeUnit . MILLISECONDS . sleep ( SystemConstants . TASK_TIME_OUT_CONST2 ) ;
} catch ( InterruptedException e ) {
Thread . currentThread ( ) . interrupt ( ) ;
connType = "v不在线" ;
return connType ;
}
}
attempt + + ;
}
return connType ;
}
@Override
public Long TR143Speed ( Long devId , String downloadUrl ) {
OperationTask operationTask = new OperationTask ( ) ;
operationTask . setDeviceId ( devId ) ;
operationTask . setOperationName ( RemoteOperateMsgEnum . SET_TR143_PARAMETER . getValue ( ) ) ;
operationTask . setOperationTaskDescription ( "SetTR143Parameter test" ) ;
operationTask . setCreateUser ( SecurityUtils . getUsername ( ) ) ;
DOperTask2DetailStruct detailStruct = new DOperTask2DetailStruct ( ) ;
DOperTask2Struct operTaskStruct = new DOperTask2Struct ( ) ;
operTaskStruct . devId = operationTask . getDeviceId ( ) = = 0 ? Utils . LONG_NULL : operationTask . getDeviceId ( ) ;
operTaskStruct . operName = operationTask . getOperationName ( ) = = null ? "" : operationTask . getOperationName ( ) ;
operTaskStruct . operTaskCreateTime = ( new Date ( ) ) . getTime ( ) ;
operTaskStruct . operTaskDesc = RemoteOperateMsgEnum . SET_TR143_PARAMETER . getLabel ( ) ;
operTaskStruct . operTaskId = operationTask . getOperationTaskId ( ) = = 0 ? Utils . LONG_NULL : operationTask
. getOperationTaskId ( ) ;
operTaskStruct . userName = operationTask . getCreateUser ( ) = = null ? "" : operationTask . getCreateUser ( ) ;
detailStruct . operTask = operTaskStruct ;
DOperTaskArgsStruct [ ] argsStruct = new DOperTaskArgsStruct [ 3 ] ;
argsStruct [ 0 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 0 ] . argsName = "speed_source" ;
argsStruct [ 0 ] . argsValue = "1" ;
argsStruct [ 0 ] . operTaskId = operTaskStruct . operTaskId ;
argsStruct [ 1 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 1 ] . argsName = "downloadUrl" ;
argsStruct [ 1 ] . argsValue = downloadUrl ;
argsStruct [ 1 ] . operTaskId = operTaskStruct . operTaskId ;
argsStruct [ 2 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 2 ] . argsName = "time" ;
argsStruct [ 2 ] . argsValue = "5" ; //默认测速时间
argsStruct [ 2 ] . operTaskId = operTaskStruct . operTaskId ;
detailStruct . operTaskArgsList = argsStruct ;
DOperTask2DetailStructHolder detailStructHolder = new DOperTask2DetailStructHolder ( detailStruct ) ;
int result = OAMManager . sendDeviceOper2Task ( detailStructHolder ) ;
if ( result ! = 0 ) {
throw new BusinessException ( ResultCode . OAM_INTERFACE_ERROR ) ;
}
return detailStructHolder . value . operTask . operTaskId ;
}
@Override
public RemoteOperateResult checkTR143Speed ( Long taskId , Long devId ) {
boolean found = true ;
int attempt = 0 ;
RemoteOperateResult result = new RemoteOperateResult ( ) ;
while ( attempt < 5 & & found ) {
OperateResult2 operateResult2 = operateResult2Mapper . selectOne (
new QueryWrapper < OperateResult2 > ( )
. eq ( "oper_task_id" , taskId )
) ;
if ( operateResult2 = = null ) {
throw new BusinessException ( ResultCode . TASK_NOT_FOUND ) ;
}
String state = operateResult2 . getResultState ( ) ;
if ( OperateTaskStateEnum . NOT_EXECUTED . getValue ( ) . equals ( state ) ) {
result . setResultState ( OperateTaskStateEnum . NOT_EXECUTED . getValue ( ) ) ;
result . setResultCode ( SystemConstants . SPEED_FAIL ) ;
return result ;
}
if ( ! OperateTaskStateEnum . ONGOING . getValue ( ) . equals ( state ) ) {
if ( OperateTaskStateEnum . THE_EXECUTION_WAS_SUCCESSFUL . getValue ( ) . equals ( state ) ) {
result . setResultState ( OperateTaskStateEnum . THE_EXECUTION_WAS_SUCCESSFUL . getValue ( ) ) ;
result . setResultCode ( OperateTaskStateEnum . THE_EXECUTION_WAS_SUCCESSFUL . getLabel ( ) ) ;
} else {
result . setResultState ( state ) ;
result . setResultCode ( SystemConstants . SPEED_FAIL ) ;
}
found = false ;
}
if ( found ) {
try {
TimeUnit . MILLISECONDS . sleep ( SystemConstants . TASK_TIME_OUT_CONST2 ) ;
} catch ( InterruptedException e ) {
Thread . currentThread ( ) . interrupt ( ) ;
}
}
attempt + + ;
}
return result ;
}
@Override
public RemoteOperateResult checkTr143SpeedResult ( Long devId , Long taskId ) {
boolean found = true ;
int attempt = 0 ;
RemoteOperateResult result = new RemoteOperateResult ( ) ;
while ( attempt < 5 & & found ) {
OperateResult2 operateResult2 = operateResult2Mapper . selectOne (
new QueryWrapper < OperateResult2 > ( )
. eq ( "oper_task_id" , taskId )
) ;
if ( operateResult2 = = null ) {
throw new BusinessException ( ResultCode . TASK_NOT_FOUND ) ;
}
String state = operateResult2 . getResultState ( ) ;
if ( OperateTaskStateEnum . NOT_EXECUTED . getValue ( ) . equals ( state ) ) {
result . setResultState ( OperateTaskStateEnum . NOT_EXECUTED . getValue ( ) ) ;
result . setResultCode ( SystemConstants . SPEED_FAIL ) ;
return result ;
}
if ( ! OperateTaskStateEnum . ONGOING . getValue ( ) . equals ( state ) ) {
if ( OperateTaskStateEnum . THE_EXECUTION_WAS_SUCCESSFUL . getValue ( ) . equals ( state ) ) {
String desc = deviceLogMapper . getTaskResultByTaskId ( taskId , RemoteOperateMsgEnum . DOWNLOAD_DIAGNOSTICS_QUERY . getValue ( ) ) ;
String regex = SystemConstants . DOWNLOAD_INFO_REGEX ;
Pattern pattern = Pattern . compile ( regex ) ;
Matcher matcher = pattern . matcher ( desc ) ;
if ( matcher . find ( ) ) {
String input = matcher . group ( 1 ) . trim ( ) ;
DownloadInfo downloadInfo = parseFromString ( input ) ;
String state1 = downloadInfo . getState ( ) ;
if ( state1 . equalsIgnoreCase ( "Completed" ) ) {
Long eomTime = downloadInfo . getEomTime ( ) ;
Long bomTime = downloadInfo . getBomTime ( ) ;
Long totalBytesReceived = downloadInfo . getTotalBytesReceived ( ) ;
long speedResult = 8 * 1000 * totalBytesReceived / ( eomTime - bomTime ) / 1024 / 1024 ;
BigDecimal value = new BigDecimal ( speedResult ) ;
String speed = value . divide ( new BigDecimal ( 1 ) , 3 , RoundingMode . HALF_UP ) . toString ( ) ;
result . setResultState ( state ) ;
result . setResultCode ( speed ) ;
} else {
result . setResultState ( "5" ) ;
result . setResultCode ( SystemConstants . SPEED_FAIL ) ;
}
}
} else {
result . setResultState ( state ) ;
result . setResultCode ( SystemConstants . SPEED_FAIL ) ;
}
found = false ;
}
if ( found ) {
try {
TimeUnit . MILLISECONDS . sleep ( SystemConstants . TASK_TIME_OUT_CONST2 ) ;
} catch ( InterruptedException e ) {
Thread . currentThread ( ) . interrupt ( ) ;
}
}
attempt + + ;
}
return result ;
}
private static DownloadInfo parseFromString ( String input ) {
DownloadInfo downloadInfo = new DownloadInfo ( ) ;
Map < String , String > properties = new HashMap < > ( ) ;
// 使用"^"作为分隔符分割字符串,并填充到Map中
for ( String part : input . split ( "\\^" ) ) {
String [ ] keyValue = part . split ( "=" ) ;
if ( keyValue . length = = 2 ) {
properties . put ( keyValue [ 0 ] , keyValue [ 1 ] ) ;
}
}
// 从Map中提取值并设置到DownloadInfo对象中
downloadInfo . setState ( properties . getOrDefault ( "state" , null ) ) ;
downloadInfo . setRomTime ( properties . getOrDefault ( "romTime" , null ) ) ;
downloadInfo . setBomTime ( parseLong ( properties . get ( "bomTime" ) ) ) ;
downloadInfo . setEomTime ( parseLong ( properties . get ( "eomTime" ) ) ) ;
downloadInfo . setTestBytesReceived ( parseLong ( properties . get ( "testBytesReceived" ) ) ) ;
downloadInfo . setTotalBytesReceived ( parseLong ( properties . get ( "totalBytesReceived" ) ) ) ;
downloadInfo . setTcpOpenRequestTime ( parseLong ( properties . get ( "tcpOpenRequestTime" ) ) ) ;
downloadInfo . setTcpOpenResponseTime ( parseLong ( properties . get ( "tcpOpenResponseTime" ) ) ) ;
return downloadInfo ;
}
private static Long parseLong ( String value ) {
if ( value = = null | | "null" . equals ( value ) ) {
return null ;
}
return Long . parseLong ( value ) ;
}
@Override
public Long remoteOpenRegister ( Long devId ) {
long taskId = 0 ;
DOperTask2DetailStruct detailStruct = new DOperTask2DetailStruct ( ) ;
DOperTask2Struct operTaskStruct = new DOperTask2Struct ( ) ;
operTaskStruct . devId = devId ;
operTaskStruct . operName = RemoteOperateMsgEnum . X_REGISTER . getValue ( ) ;
operTaskStruct . operTaskCreateTime = ( new Date ( ) ) . getTime ( ) ;
operTaskStruct . operTaskDesc = RemoteOperateMsgEnum . X_REGISTER . getLabel ( ) ;
operTaskStruct . operTaskId = Utils . LONG_NULL ;
operTaskStruct . userName = SecurityUtils . getUsername ( ) ;
detailStruct . operTask = operTaskStruct ;
DOperTaskArgsStruct [ ] argsStruct = new DOperTaskArgsStruct [ 2 ] ;
argsStruct [ 0 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 0 ] . argsName = "BIND_STATUS" ;
argsStruct [ 0 ] . argsValue = "99" ;
argsStruct [ 0 ] . operTaskId = Utils . LONG_NULL ;
argsStruct [ 1 ] = new DOperTaskArgsStruct ( ) ;
argsStruct [ 1 ] . argsName = "BIND_RESULT" ;
argsStruct [ 1 ] . argsValue = "99" ;
argsStruct [ 1 ] . operTaskId = Utils . LONG_NULL ;
detailStruct . operTaskArgsList = argsStruct ;
DOperTask2DetailStructHolder detailStructHolder = new DOperTask2DetailStructHolder (
detailStruct ) ;
int result = OAMManager . sendDeviceOper2Task ( detailStructHolder ) ;
if ( result ! = 0 ) {
throw new BusinessException ( ResultCode . OAM_INTERFACE_ERROR ) ;
}
return detailStructHolder . value . operTask . operTaskId ;
}
}