@ -40,9 +40,7 @@ import org.springframework.util.CollectionUtils;
import java.net.URL ;
import java.net.URL ;
import java.sql.SQLException ;
import java.sql.SQLException ;
import java.time.Instant ;
import java.time.* ;
import java.time.LocalDateTime ;
import java.time.ZoneId ;
import java.util.* ;
import java.util.* ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
@ -74,23 +72,29 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
@Autowired
@Autowired
private IFileService fileService ;
private IFileService fileService ;
private Optional < WaylineJobDTO > insertWaylineJob ( WaylineJobEntity jobEntity ) {
int id = mapper . insert ( jobEntity ) ;
if ( id < = 0 ) {
return Optional . empty ( ) ;
}
return Optional . ofNullable ( this . entity2Dto ( jobEntity ) ) ;
}
@Override
@Override
public Optional < WaylineJobDTO > createWaylineJob ( CreateJobParam param , CustomClaim customClaim ) {
public Optional < WaylineJobDTO > createWaylineJob ( CreateJobParam param , String workspaceId , String username , Long beginTime , Long endTime ) {
if ( Objects . isNull ( param ) ) {
if ( Objects . isNull ( param ) ) {
return Optional . empty ( ) ;
return Optional . empty ( ) ;
}
}
// Immediate tasks, allocating time on the backend.
// Immediate tasks, allocating time on the backend.
if ( Objects . isNull ( param . getExecuteTime ( ) ) ) {
param . setExecuteTime ( System . currentTimeMillis ( ) ) ;
}
WaylineJobEntity jobEntity = WaylineJobEntity . builder ( )
WaylineJobEntity jobEntity = WaylineJobEntity . builder ( )
. name ( param . getName ( ) )
. name ( param . getName ( ) )
. dockSn ( param . getDockSn ( ) )
. dockSn ( param . getDockSn ( ) )
. fileId ( param . getFileId ( ) )
. fileId ( param . getFileId ( ) )
. username ( c ustomClaim . getUs ername( ) )
. username ( username )
. workspaceId ( customClaim . getWorkspaceId ( ) )
. workspaceId ( workspaceId )
. jobId ( UUID . randomUUID ( ) . toString ( ) )
. jobId ( UUID . randomUUID ( ) . toString ( ) )
. executeTime ( param . getExecuteTime ( ) )
. beginTime ( beginTime )
. endTime ( endTime )
. status ( WaylineJobStatusEnum . PENDING . getVal ( ) )
. status ( WaylineJobStatusEnum . PENDING . getVal ( ) )
. taskType ( param . getTaskType ( ) )
. taskType ( param . getTaskType ( ) )
. waylineType ( param . getWaylineType ( ) )
. waylineType ( param . getWaylineType ( ) )
@ -98,16 +102,35 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
. rthAltitude ( param . getRthAltitude ( ) )
. rthAltitude ( param . getRthAltitude ( ) )
. mediaCount ( 0 )
. mediaCount ( 0 )
. build ( ) ;
. build ( ) ;
int id = mapper . insert ( jobEntity ) ;
if ( id < = 0 ) {
return insertWaylineJob ( jobEntity ) ;
}
@Override
public Optional < WaylineJobDTO > createWaylineJobByParent ( String workspaceId , String parentId ) {
Optional < WaylineJobDTO > parentJobOpt = this . getJobByJobId ( workspaceId , parentId ) ;
if ( parentJobOpt . isEmpty ( ) ) {
return Optional . empty ( ) ;
return Optional . empty ( ) ;
}
}
return Optional . ofNullable ( this . entity2Dto ( jobEntity ) ) ;
WaylineJobEntity jobEntity = this . dto2Entity ( parentJobOpt . get ( ) ) ;
jobEntity . setJobId ( UUID . randomUUID ( ) . toString ( ) ) ;
jobEntity . setErrorCode ( null ) ;
jobEntity . setCompletedTime ( null ) ;
jobEntity . setExecuteTime ( null ) ;
jobEntity . setStatus ( WaylineJobStatusEnum . PENDING . getVal ( ) ) ;
jobEntity . setParentId ( parentId ) ;
return this . insertWaylineJob ( jobEntity ) ;
}
}
@Override
@Override
public ResponseResult publishFlightTask ( CreateJobParam param , CustomClaim customClaim ) throws SQLException {
public ResponseResult publishFlightTask ( CreateJobParam param , CustomClaim customClaim ) throws SQLException {
Optional < WaylineJobDTO > waylineJobOpt = this . createWaylineJob ( param , customClaim ) ;
if ( WaylineTaskTypeEnum . IMMEDIATE . getVal ( ) = = param . getTaskType ( ) ) {
param . setExecuteTime ( System . currentTimeMillis ( ) ) ;
}
Optional < WaylineJobDTO > waylineJobOpt = this . createWaylineJob ( param ,
customClaim . getWorkspaceId ( ) , customClaim . getUsername ( ) ,
param . getExecuteTime ( ) , param . getExecuteTime ( ) ) ;
if ( waylineJobOpt . isEmpty ( ) ) {
if ( waylineJobOpt . isEmpty ( ) ) {
throw new SQLException ( "Failed to create wayline job." ) ;
throw new SQLException ( "Failed to create wayline job." ) ;
}
}
@ -127,14 +150,14 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
// get file url
// get file url
URL url = waylineFileService . getObjectUrl ( waylineJob . getWorkspaceId ( ) , waylineFile . get ( ) . getWaylineId ( ) ) ;
URL url = waylineFileService . getObjectUrl ( waylineJob . getWorkspaceId ( ) , waylineFile . get ( ) . getWaylineId ( ) ) ;
FlightTaskCreateDTO flightTask = Flight TaskCreateDTO. builder ( )
WaylineTaskCreateDTO flightTask = Wayline TaskCreateDTO. builder ( )
. flightId ( waylineJob . getJobId ( ) )
. flightId ( waylineJob . getJobId ( ) )
. executeTime ( waylineJob . getExecute Time ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) )
. executeTime ( waylineJob . getBegin Time ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) )
. taskType ( waylineJob . getTaskType ( ) )
. taskType ( waylineJob . getTaskType ( ) )
. waylineType ( waylineJob . getWaylineType ( ) )
. waylineType ( waylineJob . getWaylineType ( ) )
. rthAltitude ( waylineJob . getRthAltitude ( ) )
. rthAltitude ( waylineJob . getRthAltitude ( ) )
. outOfControlAction ( waylineJob . getOutOfControlAction ( ) )
. outOfControlAction ( waylineJob . getOutOfControlAction ( ) )
. file ( Flight TaskFileDTO. builder ( )
. file ( Wayline TaskFileDTO. builder ( )
. url ( url . toString ( ) )
. url ( url . toString ( ) )
. fingerprint ( waylineFile . get ( ) . getSign ( ) )
. fingerprint ( waylineFile . get ( ) . getSign ( ) )
. build ( ) )
. build ( ) )
@ -156,22 +179,24 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
this . updateJob ( WaylineJobDTO . builder ( )
this . updateJob ( WaylineJobDTO . builder ( )
. workspaceId ( waylineJob . getWorkspaceId ( ) )
. workspaceId ( waylineJob . getWorkspaceId ( ) )
. jobId ( waylineJob . getJobId ( ) )
. jobId ( waylineJob . getJobId ( ) )
. executeTime ( LocalDateTime . now ( ) )
. status ( WaylineJobStatusEnum . FAILED . getVal ( ) )
. status ( WaylineJobStatusEnum . FAILED . getVal ( ) )
. en dTime( LocalDateTime . now ( ) )
. complete dTime( LocalDateTime . now ( ) )
. code ( serviceReply . getResult ( ) ) . build ( ) ) ;
. code ( serviceReply . getResult ( ) ) . build ( ) ) ;
return ResponseResult . error ( "Prepare task ====> Error code: " + serviceReply . getResult ( ) ) ;
return ResponseResult . error ( "Prepare task ====> Error code: " + serviceReply . getResult ( ) ) ;
}
}
// Issue an immediate task execution command.
// Issue an immediate task execution command.
if ( WaylineTaskTypeEnum . IMMEDIATE . getVal ( ) = = waylineJob . getTaskType ( ) ) {
if ( WaylineTaskTypeEnum . IMMEDIATE . getVal ( ) = = waylineJob . getTaskType ( ) ) {
if ( ! executeFlightTask ( waylineJob . getJobId ( ) ) ) {
if ( ! executeFlightTask ( waylineJob . getWorkspaceId ( ) , waylineJob . get JobId ( ) ) ) {
return ResponseResult . error ( "Failed to execute job." ) ;
return ResponseResult . error ( "Failed to execute job." ) ;
}
}
}
}
if ( WaylineTaskTypeEnum . TIMED . getVal ( ) = = waylineJob . getTaskType ( ) ) {
if ( WaylineTaskTypeEnum . TIMED . getVal ( ) = = waylineJob . getTaskType ( ) ) {
boolean isAdd = RedisOpsUtils . zAdd ( RedisConst . WAYLINE_JOB , waylineJob . getJobId ( ) ,
boolean isAdd = RedisOpsUtils . zAdd ( RedisConst . WAYLINE_JOB_TIMED_EXECUTE ,
waylineJob . getExecuteTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
waylineJob . getWorkspaceId ( ) + RedisConst . DELIMITER + waylineJob . getDockSn ( ) + RedisConst . DELIMITER + waylineJob . getJobId ( ) ,
waylineJob . getBeginTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
if ( ! isAdd ) {
if ( ! isAdd ) {
return ResponseResult . error ( "Failed to create scheduled job." ) ;
return ResponseResult . error ( "Failed to create scheduled job." ) ;
}
}
@ -181,9 +206,9 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
}
}
@Override
@Override
public Boolean executeFlightTask ( String jobId ) {
public Boolean executeFlightTask ( String workspaceId , String jobId ) {
// get job
// get job
Optional < WaylineJobDTO > waylineJob = this . getJobByJobId ( jobId ) ;
Optional < WaylineJobDTO > waylineJob = this . getJobByJobId ( workspaceId , jobId ) ;
if ( waylineJob . isEmpty ( ) ) {
if ( waylineJob . isEmpty ( ) ) {
throw new IllegalArgumentException ( "Job doesn't exist." ) ;
throw new IllegalArgumentException ( "Job doesn't exist." ) ;
}
}
@ -194,7 +219,7 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
}
}
WaylineJobDTO job = waylineJob . get ( ) ;
WaylineJobDTO job = waylineJob . get ( ) ;
FlightTaskCreateDTO flightTask = Flight TaskCreateDTO. builder ( ) . flightId ( jobId ) . build ( ) ;
WaylineTaskCreateDTO flightTask = Wayline TaskCreateDTO. builder ( ) . flightId ( jobId ) . build ( ) ;
String topic = TopicConst . THING_MODEL_PRE + TopicConst . PRODUCT +
String topic = TopicConst . THING_MODEL_PRE + TopicConst . PRODUCT +
job . getDockSn ( ) + TopicConst . SERVICES_SUF ;
job . getDockSn ( ) + TopicConst . SERVICES_SUF ;
@ -211,53 +236,45 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
log . info ( "Execute job ====> Error code: {}" , serviceReply . getResult ( ) ) ;
log . info ( "Execute job ====> Error code: {}" , serviceReply . getResult ( ) ) ;
this . updateJob ( WaylineJobDTO . builder ( )
this . updateJob ( WaylineJobDTO . builder ( )
. jobId ( jobId )
. jobId ( jobId )
. executeTime ( LocalDateTime . now ( ) )
. status ( WaylineJobStatusEnum . FAILED . getVal ( ) )
. status ( WaylineJobStatusEnum . FAILED . getVal ( ) )
. en dTime( LocalDateTime . now ( ) )
. complete dTime( LocalDateTime . now ( ) )
. code ( serviceReply . getResult ( ) ) . build ( ) ) ;
. code ( serviceReply . getResult ( ) ) . build ( ) ) ;
return false ;
return false ;
}
}
this . updateJob ( WaylineJobDTO . builder ( )
this . updateJob ( WaylineJobDTO . builder ( )
. jobId ( jobId )
. jobId ( jobId )
. executeTime ( LocalDateTime . now ( ) )
. status ( WaylineJobStatusEnum . IN_PROGRESS . getVal ( ) )
. status ( WaylineJobStatusEnum . IN_PROGRESS . getVal ( ) )
. build ( ) ) ;
. build ( ) ) ;
RedisOpsUtils . setWithExpire ( jobId ,
RedisOpsUtils . setWithExpire ( RedisConst . WAYLINE_JOB_RUNNING_PREFIX + job . getDockSn ( ) ,
EventsReceiver . < Flight TaskProgressReceiver> builder ( ) . bid ( jobId ) . sn ( job . getDockSn ( ) ) . build ( ) ,
EventsReceiver . < Wayline TaskProgressReceiver> builder ( ) . bid ( jobId ) . sn ( job . getDockSn ( ) ) . build ( ) ,
RedisConst . DEVICE_ALIVE_SECOND * RedisConst . DEVICE_ALIVE_SECOND ) ;
RedisConst . DEVICE_ALIVE_SECOND * RedisConst . DEVICE_ALIVE_SECOND ) ;
return true ;
return true ;
}
}
@Override
@Override
public void cancelFlightTask ( String workspaceId , Collection < String > jobIds ) {
public void cancelFlightTask ( String workspaceId , Collection < String > jobIds ) {
List < WaylineJobEntity > waylineJobs = mapper . selectList (
List < WaylineJobDTO > waylineJobs = getJobsByConditions ( workspaceId , jobIds , WaylineJobStatusEnum . PENDING ) ;
new LambdaQueryWrapper < WaylineJobEntity > ( )
. or ( wrapper - > jobIds . forEach ( id - > wrapper . eq ( WaylineJobEntity : : getJobId , id ) ) ) ) ;
// Check if the job have ended.
Set < String > waylineJobIds = waylineJobs . stream ( ) . map ( WaylineJobDTO : : getJobId ) . collect ( Collectors . toSet ( ) ) ;
List < String > endJobs = waylineJobs . stream ( )
// Check if the task status is correct.
. filter ( job - > WaylineJobStatusEnum . find ( job . getStatus ( ) ) . getEnd ( ) )
boolean isErr = ! jobIds . removeAll ( waylineJobIds ) | | ! jobIds . isEmpty ( ) ;
. map ( WaylineJobEntity : : getName )
if ( isErr ) {
. collect ( Collectors . toList ( ) ) ;
throw new IllegalArgumentException ( "These tasks have an incorrect status and cannot be canceled. "
if ( ! CollectionUtils . isEmpty ( endJobs ) ) {
+ Arrays . toString ( jobIds . toArray ( ) ) ) ;
throw new IllegalArgumentException ( "There are jobs that have ended." + Arrays . toString ( endJobs . toArray ( ) ) ) ;
}
Set < String > ids = waylineJobs . stream ( ) . map ( WaylineJobEntity : : getJobId ) . collect ( Collectors . toSet ( ) ) ;
for ( String id : jobIds ) {
if ( ! ids . contains ( id ) ) {
throw new IllegalArgumentException ( "Job id " + id + " doesn't exist." ) ;
}
}
}
// Group job id by dock sn.
// Group job id by dock sn.
Map < String , List < String > > dockJobs = waylineJobs . stream ( )
Map < String , List < String > > dockJobs = waylineJobs . stream ( )
. collect ( Collectors . groupingBy ( WaylineJobEntity : : getDockSn ,
. collect ( Collectors . groupingBy ( WaylineJobDTO : : getDockSn ,
Collectors . mapping ( WaylineJobEntity : : getJobId , Collectors . toList ( ) ) ) ) ;
Collectors . mapping ( WaylineJobDTO : : getJobId , Collectors . toList ( ) ) ) ) ;
dockJobs . forEach ( ( dockSn , idList ) - > this . publishCancelTask ( workspaceId , dockSn , idList ) ) ;
dockJobs . forEach ( ( dockSn , idList ) - > this . publishCancelTask ( workspaceId , dockSn , idList ) ) ;
}
}
private void publishCancelTask ( String workspaceId , String dockSn , List < String > jobIds ) {
public void publishCancelTask ( String workspaceId , String dockSn , List < String > jobIds ) {
boolean isOnline = deviceService . checkDeviceOnline ( dockSn ) ;
boolean isOnline = deviceService . checkDeviceOnline ( dockSn ) ;
if ( ! isOnline ) {
if ( ! isOnline ) {
throw new RuntimeException ( "Dock is offline." ) ;
throw new RuntimeException ( "Dock is offline." ) ;
@ -283,17 +300,30 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
. workspaceId ( workspaceId )
. workspaceId ( workspaceId )
. jobId ( jobId )
. jobId ( jobId )
. status ( WaylineJobStatusEnum . CANCEL . getVal ( ) )
. status ( WaylineJobStatusEnum . CANCEL . getVal ( ) )
. en dTime( LocalDateTime . now ( ) )
. complete dTime( LocalDateTime . now ( ) )
. build ( ) ) ;
. build ( ) ) ;
RedisOpsUtils . zRemove ( RedisConst . WAYLINE_JOB , jobId ) ;
RedisOpsUtils . zRemove ( RedisConst . WAYLINE_JOB_TIMED_EXECUTE , workspaceId + RedisConst . DELIMITER + dockSn + RedisConst . DELIMITER + jobId ) ;
}
}
}
}
public List < WaylineJobDTO > getJobsByConditions ( String workspaceId , Collection < String > jobIds , WaylineJobStatusEnum status ) {
return mapper . selectList (
new LambdaQueryWrapper < WaylineJobEntity > ( )
. eq ( WaylineJobEntity : : getWorkspaceId , workspaceId )
. eq ( Objects . nonNull ( status ) , WaylineJobEntity : : getStatus , status . getVal ( ) )
. and ( ! CollectionUtils . isEmpty ( jobIds ) ,
wrapper - > jobIds . forEach ( id - > wrapper . eq ( WaylineJobEntity : : getJobId , id ) . or ( ) ) ) )
. stream ( )
. map ( this : : entity2Dto )
. collect ( Collectors . toList ( ) ) ;
}
@Override
@Override
public Optional < WaylineJobDTO > getJobByJobId ( String jobId ) {
public Optional < WaylineJobDTO > getJobByJobId ( String workspaceId , String jobId ) {
WaylineJobEntity jobEntity = mapper . selectOne (
WaylineJobEntity jobEntity = mapper . selectOne (
new LambdaQueryWrapper < WaylineJobEntity > ( )
new LambdaQueryWrapper < WaylineJobEntity > ( )
. eq ( WaylineJobEntity : : getWorkspaceId , workspaceId )
. eq ( WaylineJobEntity : : getJobId , jobId ) ) ;
. eq ( WaylineJobEntity : : getJobId , jobId ) ) ;
return Optional . ofNullable ( entity2Dto ( jobEntity ) ) ;
return Optional . ofNullable ( entity2Dto ( jobEntity ) ) ;
}
}
@ -336,7 +366,8 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
String topic = headers . get ( MqttHeaders . RECEIVED_TOPIC ) . toString ( ) + TopicConst . _REPLY_SUF ;
String topic = headers . get ( MqttHeaders . RECEIVED_TOPIC ) . toString ( ) + TopicConst . _REPLY_SUF ;
Optional < WaylineJobDTO > waylineJobOpt = this . getJobByJobId ( jobId ) ;
DeviceDTO device = ( DeviceDTO ) RedisOpsUtils . get ( RedisConst . DEVICE_ONLINE_PREFIX + receiver . getGateway ( ) ) ;
Optional < WaylineJobDTO > waylineJobOpt = this . getJobByJobId ( device . getWorkspaceId ( ) , jobId ) ;
if ( waylineJobOpt . isEmpty ( ) ) {
if ( waylineJobOpt . isEmpty ( ) ) {
builder . data ( RequestsReply . error ( CommonErrorEnum . ILLEGAL_ARGUMENT ) ) ;
builder . data ( RequestsReply . error ( CommonErrorEnum . ILLEGAL_ARGUMENT ) ) ;
messageSender . publish ( topic , builder . build ( ) ) ;
messageSender . publish ( topic , builder . build ( ) ) ;
@ -357,8 +388,8 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
URL url = null ;
URL url = null ;
try {
try {
url = waylineFileService . getObjectUrl ( waylineJob . getWorkspaceId ( ) , waylineFile . get ( ) . getWaylineId ( ) ) ;
url = waylineFileService . getObjectUrl ( waylineJob . getWorkspaceId ( ) , waylineFile . get ( ) . getWaylineId ( ) ) ;
builder . data ( RequestsReply . success ( Flight TaskCreateDTO. builder ( )
builder . data ( RequestsReply . success ( Wayline TaskCreateDTO. builder ( )
. file ( Flight TaskFileDTO. builder ( )
. file ( Wayline TaskFileDTO. builder ( )
. url ( url . toString ( ) )
. url ( url . toString ( ) )
. fingerprint ( waylineFile . get ( ) . getSign ( ) )
. fingerprint ( waylineFile . get ( ) . getSign ( ) )
. build ( ) )
. build ( ) )
@ -377,14 +408,15 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
@Override
@Override
public void uploadMediaHighestPriority ( String workspaceId , String jobId ) {
public void uploadMediaHighestPriority ( String workspaceId , String jobId ) {
Optional < WaylineJobDTO > jobOpt = getJobByJobId ( jobId ) ;
Optional < WaylineJobDTO > jobOpt = getJobByJobId ( workspaceId , jobId ) ;
if ( jobOpt . isEmpty ( ) ) {
if ( jobOpt . isEmpty ( ) ) {
throw new RuntimeException ( CommonErrorEnum . ILLEGAL_ARGUMENT . getErrorMsg ( ) ) ;
throw new RuntimeException ( CommonErrorEnum . ILLEGAL_ARGUMENT . getErrorMsg ( ) ) ;
}
}
String dockSn = jobOpt . get ( ) . getDockSn ( ) ;
String dockSn = jobOpt . get ( ) . getDockSn ( ) ;
String key = RedisConst . MEDIA_HIGHEST_PRIORITY_PREFIX + dockSn ;
String key = RedisConst . MEDIA_HIGHEST_PRIORITY_PREFIX + dockSn ;
if ( RedisOpsUtils . checkExist ( key ) & & jobId . equals ( RedisOpsUtils . get ( key ) . toString ( ) ) ) {
if ( RedisOpsUtils . checkExist ( key ) & &
jobId . equals ( ( ( MediaFileCountDTO ) RedisOpsUtils . get ( key ) ) . getJobId ( ) ) ) {
return ;
return ;
}
}
@ -399,7 +431,6 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
if ( ResponseResult . CODE_SUCCESS ! = reply . getResult ( ) ) {
if ( ResponseResult . CODE_SUCCESS ! = reply . getResult ( ) ) {
throw new RuntimeException ( "Failed to set media job upload priority. Error Code: " + reply . getResult ( ) ) ;
throw new RuntimeException ( "Failed to set media job upload priority. Error Code: " + reply . getResult ( ) ) ;
}
}
RedisOpsUtils . setWithExpire ( key , jobId , RedisConst . DEVICE_ALIVE_SECOND * 5 ) ;
}
}
private WaylineJobEntity dto2Entity ( WaylineJobDTO dto ) {
private WaylineJobEntity dto2Entity ( WaylineJobDTO dto ) {
@ -407,16 +438,32 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
if ( dto = = null ) {
if ( dto = = null ) {
return builder . build ( ) ;
return builder . build ( ) ;
}
}
if ( Objects . nonNull ( dto . getBeginTime ( ) ) ) {
builder . beginTime ( dto . getBeginTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
}
if ( Objects . nonNull ( dto . getEndTime ( ) ) ) {
if ( Objects . nonNull ( dto . getEndTime ( ) ) ) {
builder . endTime ( dto . getEndTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
builder . endTime ( dto . getEndTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
}
}
if ( Objects . nonNull ( dto . getExecuteTime ( ) ) ) {
if ( Objects . nonNull ( dto . getExecuteTime ( ) ) ) {
builder . executeTime ( dto . getExecuteTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
builder . executeTime ( dto . getExecuteTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
}
}
if ( Objects . nonNull ( dto . getCompletedTime ( ) ) ) {
builder . completedTime ( dto . getCompletedTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
}
return builder . status ( dto . getStatus ( ) )
return builder . status ( dto . getStatus ( ) )
. mediaCount ( dto . getMediaCount ( ) )
. mediaCount ( dto . getMediaCount ( ) )
. name ( dto . getJobName ( ) )
. name ( dto . getJobName ( ) )
. errorCode ( dto . getCode ( ) )
. errorCode ( dto . getCode ( ) )
. jobId ( dto . getJobId ( ) )
. fileId ( dto . getFileId ( ) )
. dockSn ( dto . getDockSn ( ) )
. workspaceId ( dto . getWorkspaceId ( ) )
. taskType ( dto . getTaskType ( ) )
. waylineType ( dto . getWaylineType ( ) )
. username ( dto . getUsername ( ) )
. rthAltitude ( dto . getRthAltitude ( ) )
. outOfControlAction ( dto . getOutOfControlAction ( ) )
. parentId ( dto . getParentId ( ) )
. build ( ) ;
. build ( ) ;
}
}
@ -436,9 +483,17 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
. orElse ( DeviceDTO . builder ( ) . build ( ) ) . getNickname ( ) )
. orElse ( DeviceDTO . builder ( ) . build ( ) ) . getNickname ( ) )
. username ( entity . getUsername ( ) )
. username ( entity . getUsername ( ) )
. workspaceId ( entity . getWorkspaceId ( ) )
. workspaceId ( entity . getWorkspaceId ( ) )
. status ( entity . getStatus ( ) )
. status ( WaylineJobStatusEnum . IN_PROGRESS . getVal ( ) = = entity . getStatus ( ) & &
RedisOpsUtils . checkExist ( RedisConst . WAYLINE_JOB_PAUSED_PREFIX + entity . getJobId ( ) ) ?
WaylineJobStatusEnum . PAUSED . getVal ( ) : entity . getStatus ( ) )
. code ( entity . getErrorCode ( ) )
. code ( entity . getErrorCode ( ) )
. executeTime ( LocalDateTime . ofInstant ( Instant . ofEpochMilli ( entity . getExecuteTime ( ) ) , ZoneId . systemDefault ( ) ) )
. beginTime ( LocalDateTime . ofInstant ( Instant . ofEpochMilli ( entity . getBeginTime ( ) ) , ZoneId . systemDefault ( ) ) )
. endTime ( Objects . nonNull ( entity . getEndTime ( ) ) ?
LocalDateTime . ofInstant ( Instant . ofEpochMilli ( entity . getEndTime ( ) ) , ZoneId . systemDefault ( ) ) : null )
. executeTime ( Objects . nonNull ( entity . getExecuteTime ( ) ) ?
LocalDateTime . ofInstant ( Instant . ofEpochMilli ( entity . getExecuteTime ( ) ) , ZoneId . systemDefault ( ) ) : null )
. completedTime ( WaylineJobStatusEnum . find ( entity . getStatus ( ) ) . getEnd ( ) ?
LocalDateTime . ofInstant ( Instant . ofEpochMilli ( entity . getUpdateTime ( ) ) , ZoneId . systemDefault ( ) ) : null )
. taskType ( entity . getTaskType ( ) )
. taskType ( entity . getTaskType ( ) )
. waylineType ( entity . getWaylineType ( ) )
. waylineType ( entity . getWaylineType ( ) )
. rthAltitude ( entity . getRthAltitude ( ) )
. rthAltitude ( entity . getRthAltitude ( ) )
@ -449,7 +504,7 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
builder . endTime ( LocalDateTime . ofInstant ( Instant . ofEpochMilli ( entity . getEndTime ( ) ) , ZoneId . systemDefault ( ) ) ) ;
builder . endTime ( LocalDateTime . ofInstant ( Instant . ofEpochMilli ( entity . getEndTime ( ) ) , ZoneId . systemDefault ( ) ) ) ;
}
}
if ( WaylineJobStatusEnum . IN_PROGRESS . getVal ( ) = = entity . getStatus ( ) & & RedisOpsUtils . getExpire ( entity . getJobId ( ) ) > 0 ) {
if ( WaylineJobStatusEnum . IN_PROGRESS . getVal ( ) = = entity . getStatus ( ) & & RedisOpsUtils . getExpire ( entity . getJobId ( ) ) > 0 ) {
EventsReceiver < Flight TaskProgressReceiver> taskProgress = ( EventsReceiver < Flight TaskProgressReceiver> ) RedisOpsUtils . get ( entity . getJobId ( ) ) ;
EventsReceiver < Wayline TaskProgressReceiver> taskProgress = ( EventsReceiver < Wayline TaskProgressReceiver> ) RedisOpsUtils . get ( RedisConst . WAYLINE_JOB_RUNNING_PREFIX + entity . getDockSn ( ) ) ;
if ( Objects . nonNull ( taskProgress . getOutput ( ) ) & & Objects . nonNull ( taskProgress . getOutput ( ) . getProgress ( ) ) ) {
if ( Objects . nonNull ( taskProgress . getOutput ( ) ) & & Objects . nonNull ( taskProgress . getOutput ( ) . getProgress ( ) ) ) {
builder . progress ( taskProgress . getOutput ( ) . getProgress ( ) . getPercent ( ) ) ;
builder . progress ( taskProgress . getOutput ( ) . getProgress ( ) . getPercent ( ) ) ;
}
}
@ -465,7 +520,7 @@ public class WaylineJobServiceImpl implements IWaylineJobService {
Object mediaFileCount = RedisOpsUtils . hashGet ( countKey , entity . getJobId ( ) ) ;
Object mediaFileCount = RedisOpsUtils . hashGet ( countKey , entity . getJobId ( ) ) ;
if ( Objects . nonNull ( mediaFileCount ) ) {
if ( Objects . nonNull ( mediaFileCount ) ) {
builder . uploadedCount ( ( ( MediaFileCountDTO ) mediaFileCount ) . getUploadedCount ( ) )
builder . uploadedCount ( ( ( MediaFileCountDTO ) mediaFileCount ) . getUploadedCount ( ) )
. uploading ( RedisOpsUtils . checkExist ( key ) & & entity . getJobId ( ) . equals ( RedisOpsUtils . get ( key ) ) ) ;
. uploading ( RedisOpsUtils . checkExist ( key ) & & entity . getJobId ( ) . equals ( ( ( MediaFileCountDTO ) RedisOpsUtils . get ( key ) ) . getJobId ( ) ) ) ;
return builder . build ( ) ;
return builder . build ( ) ;
}
}