|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.jiagutech.ams.constant.UserConstants; |
|
|
import com.jiagutech.ams.constant.UserConstants; |
|
|
|
|
|
import com.jiagutech.ams.event.JobFinishEvent; |
|
|
import com.jiagutech.ams.exception.BizCode; |
|
|
import com.jiagutech.ams.exception.BizCode; |
|
|
import com.jiagutech.ams.exception.BusinessException; |
|
|
import com.jiagutech.ams.exception.BusinessException; |
|
|
import com.jiagutech.ams.mapper.*; |
|
|
import com.jiagutech.ams.mapper.*; |
|
@ -25,9 +26,12 @@ import com.jiagutech.ams.utils.ExcelUtil; |
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
import java.util.Collections; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Optional; |
|
|
import java.util.Optional; |
|
|
import java.util.function.Predicate; |
|
|
import java.util.function.Predicate; |
|
@ -57,6 +61,8 @@ public class JobServiceImpl implements JobService { |
|
|
|
|
|
|
|
|
private final TrackImageMapper trackImageMapper; |
|
|
private final TrackImageMapper trackImageMapper; |
|
|
|
|
|
|
|
|
|
|
|
private final ApplicationContext applicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JobCreateResponse createJob(JobCreateRequest jobCreateRequest) { |
|
|
public JobCreateResponse createJob(JobCreateRequest jobCreateRequest) { |
|
@ -80,7 +86,9 @@ public class JobServiceImpl implements JobService { |
|
|
public void updateJobStatus(Long jobId, Integer status) { |
|
|
public void updateJobStatus(Long jobId, Integer status) { |
|
|
JobDTO jobDTO = new JobDTO().setId(jobId).setStatus(status).setEndTime(System.currentTimeMillis()); |
|
|
JobDTO jobDTO = new JobDTO().setId(jobId).setStatus(status).setEndTime(System.currentTimeMillis()); |
|
|
jobMapper.updateById(jobDTO); |
|
|
jobMapper.updateById(jobDTO); |
|
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(status) && status == 2) { |
|
|
|
|
|
applicationContext.publishEvent(new JobFinishEvent(this, jobId)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -88,6 +96,7 @@ public class JobServiceImpl implements JobService { |
|
|
public PageResult<JobItem> getPages(PageRequest<JobPageRequest> pageRequest) { |
|
|
public PageResult<JobItem> getPages(PageRequest<JobPageRequest> pageRequest) { |
|
|
JobPageRequest requestParam = pageRequest.getRequest(); |
|
|
JobPageRequest requestParam = pageRequest.getRequest(); |
|
|
QueryWrapper<JobItem> queryWrapper = buildQueryWrapper(requestParam); |
|
|
QueryWrapper<JobItem> queryWrapper = buildQueryWrapper(requestParam); |
|
|
|
|
|
queryWrapper.orderByDesc("j.start_time"); |
|
|
Page<JobItem> page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize()); |
|
|
Page<JobItem> page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize()); |
|
|
Page<JobItem> result = jobMapper.jobPage(page, queryWrapper); |
|
|
Page<JobItem> result = jobMapper.jobPage(page, queryWrapper); |
|
|
return PageResult.of((int) result.getTotal(), (int) result.getSize(), (int) result.getCurrent(), result.getRecords()); |
|
|
return PageResult.of((int) result.getTotal(), (int) result.getSize(), (int) result.getCurrent(), result.getRecords()); |
|
@ -128,16 +137,23 @@ public class JobServiceImpl implements JobService { |
|
|
if (jobId != null) { |
|
|
if (jobId != null) { |
|
|
JobDTO job = jobMapper.selectById(jobId); |
|
|
JobDTO job = jobMapper.selectById(jobId); |
|
|
DeviceDTO deviceDTO = deviceMapper.selectById(job.getDeviceId()); |
|
|
DeviceDTO deviceDTO = deviceMapper.selectById(job.getDeviceId()); |
|
|
|
|
|
if (ObjectUtil.isEmpty(job) || ObjectUtil.isEmpty(deviceDTO)) { |
|
|
|
|
|
return Collections.emptyList(); |
|
|
|
|
|
} |
|
|
List<Locus> locusList = trackRestClient.getTractorByDroneIdAndTime(deviceDTO.getBoxNum(), job.getStartTime(), job.getEndTime()); |
|
|
List<Locus> locusList = trackRestClient.getTractorByDroneIdAndTime(deviceDTO.getBoxNum(), job.getStartTime(), job.getEndTime()); |
|
|
QueryWrapper<TrackImageDTO> query = Wrappers.query(); |
|
|
QueryWrapper<TrackImageDTO> query = Wrappers.query(); |
|
|
List<TrackImageDTO> trackImageDTOS = trackImageMapper.selectList( |
|
|
List<TrackImageDTO> trackImageDTOS = trackImageMapper.selectList( |
|
|
query.eq("device_id", job.getDeviceId()) |
|
|
query.eq("device_id", job.getDeviceId()) |
|
|
.between("ts", job.getStartTime(), job.getEndTime()) |
|
|
.between("ts", job.getStartTime(), job.getEndTime()) |
|
|
); |
|
|
); |
|
|
|
|
|
if (locusList == null && CollectionUtil.isEmpty(locusList)) { |
|
|
|
|
|
return Collections.emptyList(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
List<TrackItem> trackItems = new ArrayList<>(locusList.size()); |
|
|
List<TrackItem> trackItems = new ArrayList<>(locusList.size()); |
|
|
for (Locus locus : locusList) { |
|
|
for (Locus locus : locusList) { |
|
|
TrackItem trackItem = TrackMapping.INSTANCE.convertToTrackItemByLocus(locus); |
|
|
TrackItem trackItem = TrackMapping.INSTANCE.convertToTrackItemByLocus(locus); |
|
|
Optional<TrackImageDTO> imageDTOOptional = trackImageDTOS.stream().filter(t -> t.getTs() .equals( locus.getTimestamp())).findFirst(); |
|
|
|
|
|
|
|
|
Optional<TrackImageDTO> imageDTOOptional = trackImageDTOS.stream().filter(t -> t.getTs().equals(locus.getTimestamp())).findFirst(); |
|
|
if (imageDTOOptional.isPresent()) { |
|
|
if (imageDTOOptional.isPresent()) { |
|
|
trackItem.setImageUrl(imageDTOOptional.get().getImageUrl()); |
|
|
trackItem.setImageUrl(imageDTOOptional.get().getImageUrl()); |
|
|
|
|
|
|
|
|