优化任务执行代码
This commit is contained in:
parent
877cba6f6b
commit
d6a94a8496
2
.idea/.gitignore
vendored
2
.idea/.gitignore
vendored
@ -17,9 +17,9 @@
|
||||
*.class
|
||||
|
||||
# 忽略日志文件
|
||||
/log/
|
||||
*.log
|
||||
|
||||
# 忽略系统生成文件
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package com.zhangy.skyeye.device.controller;
|
||||
|
||||
import com.zhangy.skyeye.device.dto.PayloadPageDTO;
|
||||
import com.zhangy.skyeye.device.dto.PayloadQueryDTO;
|
||||
import com.zhangy.skyeye.device.entity.SkyeyePayload;
|
||||
import com.zhangy.skyeye.device.service.IPayloadService;
|
||||
import com.zhangy.skyeye.device.dto.PayloadPageDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -14,11 +14,11 @@ import javax.validation.Valid;
|
||||
@RestController
|
||||
@RequestMapping("/skyeye/payload")
|
||||
public class PayloadController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private IPayloadService payloadService;
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
@ -26,7 +26,7 @@ public class PayloadController {
|
||||
return payloadService.selectPage(param);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 列表查询
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
@ -36,21 +36,22 @@ public class PayloadController {
|
||||
|
||||
/**
|
||||
* 查询可用的雷达(未执行任务且已连接)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getEnableList")
|
||||
public Object getEnableList() {
|
||||
return payloadService.getEnableList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
public Object selectById(@RequestParam Long id) {
|
||||
return payloadService.getOne(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@ -60,7 +61,7 @@ public class PayloadController {
|
||||
e.setDr(0);
|
||||
return payloadService.insert(e);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@ -69,7 +70,7 @@ public class PayloadController {
|
||||
e.setDr(0);
|
||||
return payloadService.update(e);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
|
||||
@ -6,7 +6,6 @@ import com.zhangy.skyeye.common.extend.dto.QueryDTO;
|
||||
import com.zhangy.skyeye.common.extend.enums.EnumUtil;
|
||||
import com.zhangy.skyeye.common.extend.exception.ServiceException;
|
||||
import com.zhangy.skyeye.common.extend.util.ObjectUtil;
|
||||
import com.zhangy.skyeye.redis.utils.RedisUtil;
|
||||
import com.zhangy.skyeye.device.consts.PayloadTypeEnum;
|
||||
import com.zhangy.skyeye.device.dto.PayloadQueryDTO;
|
||||
import com.zhangy.skyeye.device.entity.SkyeyePayload;
|
||||
@ -18,6 +17,7 @@ import com.zhangy.skyeye.jm.dto.JmUavStatusDTO;
|
||||
import com.zhangy.skyeye.jm.service.JmJobStatusService;
|
||||
import com.zhangy.skyeye.publics.consts.CacheKey;
|
||||
import com.zhangy.skyeye.publics.consts.ExecStatusEnum;
|
||||
import com.zhangy.skyeye.redis.utils.RedisUtil;
|
||||
import com.zhangy.skyeye.sar.service.ISarControlService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@ -37,7 +37,7 @@ public class PayloadServiceImpl implements IPayloadService {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
|
||||
@Autowired
|
||||
private PayloadMapper payloadMapper;
|
||||
|
||||
@ -46,7 +46,7 @@ public class PayloadServiceImpl implements IPayloadService {
|
||||
|
||||
@Autowired
|
||||
private ISarControlService sarControlService;
|
||||
|
||||
|
||||
@Override
|
||||
public IPage<SkyeyePayload> selectPage(PageDTO param) {
|
||||
return payloadMapper.selectPage(param);
|
||||
@ -57,9 +57,7 @@ public class PayloadServiceImpl implements IPayloadService {
|
||||
PayloadQueryDTO payloadQueryDTO = new PayloadQueryDTO();
|
||||
payloadQueryDTO.setType(PayloadTypeEnum.SAR.getCode());
|
||||
List<SkyeyePayload> sarList = selectList(payloadQueryDTO);
|
||||
sarList.forEach(e -> {
|
||||
cacheSar(e);
|
||||
});
|
||||
sarList.forEach(this::cacheSar);
|
||||
}
|
||||
|
||||
private void cacheSar(SkyeyePayload e) {
|
||||
@ -116,6 +114,7 @@ public class PayloadServiceImpl implements IPayloadService {
|
||||
|
||||
/**
|
||||
* 先判断该设备(同IP、编号)是否已删除过,是则更新,否则新增
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ -132,7 +131,7 @@ public class PayloadServiceImpl implements IPayloadService {
|
||||
cacheSar(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public SkyeyePayload update(SkyeyePayload e) {
|
||||
@ -151,6 +150,7 @@ public class PayloadServiceImpl implements IPayloadService {
|
||||
|
||||
/**
|
||||
* 保存前校验
|
||||
*
|
||||
* @param e
|
||||
* @return 返回已逻辑删除的载荷
|
||||
*/
|
||||
@ -167,7 +167,7 @@ public class PayloadServiceImpl implements IPayloadService {
|
||||
return local;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void delete(Long... id) {
|
||||
@ -176,7 +176,7 @@ public class PayloadServiceImpl implements IPayloadService {
|
||||
.stream()
|
||||
.flatMap(vo -> vo.getUavMap().values().stream())
|
||||
.filter(vo -> vo.getSarStatus() != ExecStatusEnum.OVER)
|
||||
.map(vo -> vo.getSarId())
|
||||
.map(JmUavStatusDTO::getSarId)
|
||||
.collect(Collectors.toList());
|
||||
// 任务中的不可删除
|
||||
for (Long sarId : id) {
|
||||
|
||||
@ -5,97 +5,101 @@ import com.zhangy.skyeye.common.extend.exception.ServiceException;
|
||||
import com.zhangy.skyeye.device.consts.PayloadTypeEnum;
|
||||
import com.zhangy.skyeye.jm.entity.JmAirline;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobPayload;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobUav;
|
||||
import com.zhangy.skyeye.publics.consts.ExecStatusEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 任务状态 - 任务
|
||||
*/
|
||||
@Data
|
||||
public class JmJobStatusDTO {
|
||||
|
||||
/**
|
||||
* 任务配置ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
private ExecStatusEnum status;
|
||||
|
||||
private Map<Long, JmUavStatusDTO> uavMap;
|
||||
|
||||
public static JmJobStatusDTO parse(JmJobDTO e) {
|
||||
/**
|
||||
* 将 JmJobDTO 转换为前端 DTO
|
||||
*/
|
||||
public static JmJobStatusDTO parse(JmJobDTO job) {
|
||||
if (job.getStatus() == null) throw ServiceException.noLog("任务状态不能为空");
|
||||
JmJobStatusDTO vo = new JmJobStatusDTO();
|
||||
long jobConfId = e.getConfId();
|
||||
vo.setId(jobConfId);
|
||||
Integer jobStatus = e.getStatus();
|
||||
if (jobStatus == null) {
|
||||
throw ServiceException.noLog("任务状态不能为空");
|
||||
vo.setId(job.getConfId());
|
||||
vo.setStatus(EnumUtil.parseEx(ExecStatusEnum.class, job.getStatus()));
|
||||
// 构建 UAV Map
|
||||
Map<Long, JmUavStatusDTO> uavMap = new HashMap<>();
|
||||
for (JmJobUav uav : job.getUavList()) {
|
||||
uavMap.put(uav.getUavId(), parseUav(uav, job));
|
||||
}
|
||||
vo.setStatus(EnumUtil.parseEx(ExecStatusEnum.class, jobStatus));
|
||||
vo.setUavMap(e.getUavList()
|
||||
.stream()
|
||||
.map(u -> {
|
||||
JmUavStatusDTO uVo = new JmUavStatusDTO();
|
||||
long uavId = u.getUavId();
|
||||
uVo.setUavId(uavId);
|
||||
// sar
|
||||
JmJobPayload sar = u.getPayloadList()
|
||||
.stream()
|
||||
.filter(p -> PayloadTypeEnum.SAR.getCode().equals(p.getType()))
|
||||
.findFirst()
|
||||
.get();
|
||||
long sarId = sar.getPayloadId();
|
||||
uVo.setSarId(sarId);
|
||||
uVo.setSarIp(sar.getIp());
|
||||
uVo.setSarImageLight(sar.getImageLight());
|
||||
// smp
|
||||
uVo.setHomeAlt(u.getStartAltitude());
|
||||
uVo.setHomeLon(u.getStartLon());
|
||||
uVo.setHomeLat(u.getStartLat());
|
||||
Integer sarStatus = sar.getStatus();
|
||||
if (sarStatus == null) {
|
||||
throw new ServiceException("sar状态不能为空");
|
||||
}
|
||||
// uVo.setSarStatus(ExecStatusEnum.parseEx(sarStatus));
|
||||
uVo.setAirlineList(u.getAirlineList()
|
||||
.stream()
|
||||
.map(a -> {
|
||||
JmAirlineStatusDTO aVo = new JmAirlineStatusDTO();
|
||||
aVo.setConfId(a.getConfId());
|
||||
aVo.setExecId(a.getExecId());
|
||||
aVo.setNo(a.getFlightNo());
|
||||
aVo.setDistance(a.getDistance());
|
||||
aVo.setStartLon(a.getStartLon());
|
||||
aVo.setStartLat(a.getStartLat());
|
||||
aVo.setStartHeight(a.getStartHeight());
|
||||
aVo.setTargetHeading(a.getTargetHeading());
|
||||
aVo.setDirection(a.getDirection());
|
||||
aVo.setJobId(jobConfId);
|
||||
aVo.setUavId(uavId);
|
||||
aVo.setPayloadId(sarId);
|
||||
Integer airlineStatus = a.getStatus();
|
||||
if (airlineStatus == null) {
|
||||
throw ServiceException.noLog("航线状态不能为空");
|
||||
}
|
||||
aVo.setStatus(EnumUtil.parseEx(ExecStatusEnum.class, airlineStatus));
|
||||
return aVo;
|
||||
})
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
uVo.setDistance(u.getAirlineList().stream().mapToInt(JmAirline::getDistance).sum());
|
||||
// 向前端推送图像时需要
|
||||
uVo.setJobId(jobConfId);
|
||||
uVo.setJobExecId(e.getExecId());
|
||||
uVo.setJobName(e.getName());
|
||||
uVo.setUavName(u.getUavName());
|
||||
uVo.setSarName(sar.getPayloadName());
|
||||
return uVo;
|
||||
})
|
||||
.collect(Collectors.toMap(uVo -> uVo.getUavId(), Function.identity()))
|
||||
);
|
||||
vo.setUavMap(uavMap);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将单个 UAV 对象转换为 DTO,包括 SAR 信息和航线列表
|
||||
*/
|
||||
private static JmUavStatusDTO parseUav(JmJobUav uav, JmJobDTO job) {
|
||||
JmUavStatusDTO uVo = new JmUavStatusDTO();
|
||||
// UAV 基本信息
|
||||
uVo.setUavId(uav.getUavId());
|
||||
uVo.setHomeAlt(uav.getStartAltitude());
|
||||
uVo.setHomeLon(uav.getStartLon());
|
||||
uVo.setHomeLat(uav.getStartLat());
|
||||
uVo.setJobId(job.getConfId());
|
||||
uVo.setJobExecId(job.getExecId());
|
||||
uVo.setJobName(job.getName());
|
||||
uVo.setUavName(uav.getUavName());
|
||||
// 找到 UAV 的 SAR Payload
|
||||
JmJobPayload sar = uav.getPayloadList().stream()
|
||||
.filter(p -> PayloadTypeEnum.SAR.getCode().equals(p.getType()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new ServiceException("SAR payload不存在"));
|
||||
uVo.setSarId(sar.getPayloadId());
|
||||
uVo.setSarIp(sar.getIp());
|
||||
uVo.setSarImageLight(sar.getImageLight());
|
||||
uVo.setSarName(sar.getPayloadName());
|
||||
// uVo.setSarStatus(ExecStatusEnum.parseEx(sar.getStatus()));
|
||||
// 构建航线 DTO 列表,同时计算总距离
|
||||
int totalDistance = 0;
|
||||
List<JmAirlineStatusDTO> airlines = new ArrayList<>();
|
||||
for (JmAirline a : uav.getAirlineList()) {
|
||||
airlines.add(parseAirline(a, job.getConfId(), uav.getUavId(), sar.getPayloadId()));
|
||||
totalDistance += a.getDistance();
|
||||
}
|
||||
uVo.setAirlineList(airlines);
|
||||
uVo.setDistance(totalDistance);
|
||||
|
||||
return uVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将单条航线对象转换为 DTO
|
||||
*/
|
||||
private static JmAirlineStatusDTO parseAirline(JmAirline a, long jobId, long uavId, long payloadId) {
|
||||
if (a.getStatus() == null) throw ServiceException.noLog("航线状态不能为空");
|
||||
JmAirlineStatusDTO aVo = new JmAirlineStatusDTO();
|
||||
// 航线基础信息
|
||||
aVo.setConfId(a.getConfId());
|
||||
aVo.setExecId(a.getExecId());
|
||||
aVo.setNo(a.getFlightNo());
|
||||
aVo.setDistance(a.getDistance());
|
||||
aVo.setStartLon(a.getStartLon());
|
||||
aVo.setStartLat(a.getStartLat());
|
||||
aVo.setStartHeight(a.getStartHeight());
|
||||
aVo.setTargetHeading(a.getTargetHeading());
|
||||
aVo.setDirection(a.getDirection());
|
||||
// 关联任务和 UAV
|
||||
aVo.setJobId(jobId);
|
||||
aVo.setUavId(uavId);
|
||||
aVo.setPayloadId(payloadId);
|
||||
// 状态枚举
|
||||
aVo.setStatus(EnumUtil.parseEx(ExecStatusEnum.class, a.getStatus()));
|
||||
return aVo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,10 @@ import com.zhangy.skyeye.common.extend.util.ObjectUtil;
|
||||
import com.zhangy.skyeye.device.service.IPayloadService;
|
||||
import com.zhangy.skyeye.jm.dto.JmJobDTO;
|
||||
import com.zhangy.skyeye.jm.dto.JmJobQueryDTO;
|
||||
import com.zhangy.skyeye.jm.entity.*;
|
||||
import com.zhangy.skyeye.jm.entity.JmAirlineExec;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobExec;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobPoint;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobUav;
|
||||
import com.zhangy.skyeye.jm.event.JmJobStatusInitEvent;
|
||||
import com.zhangy.skyeye.jm.mapper.JmJobExecMapper;
|
||||
import com.zhangy.skyeye.jm.service.*;
|
||||
@ -74,6 +77,7 @@ public class JmJobExecServiceImpl implements JmJobExecService {
|
||||
|
||||
/**
|
||||
* 查询进行中的任务
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@ -125,40 +129,36 @@ public class JmJobExecServiceImpl implements JmJobExecService {
|
||||
@Transactional
|
||||
@Override
|
||||
public void save(JmJobDTO dto) {
|
||||
Long jobConfigId = dto.getId();
|
||||
// 任务
|
||||
JmJobExec e = new JmJobExec();
|
||||
e.setStatus(dto.getStatus());
|
||||
e.setBeginTime(dto.getBeginTime());
|
||||
e.setConfId(jobConfigId);
|
||||
e.setType(dto.getType());
|
||||
jobExecMapper.insert(e);
|
||||
long execId = e.getId();
|
||||
// 航线
|
||||
List<JmAirlineExec> airlineExecList = dto.getUavList()
|
||||
.stream()
|
||||
.flatMap(uav -> {
|
||||
return uav.getAirlineList()
|
||||
.stream()
|
||||
.map(airline -> {
|
||||
JmAirlineExec ae = new JmAirlineExec();
|
||||
ae.setConfId(airline.getId());
|
||||
ae.setStatus(ExecStatusEnum.NOT.getValue());
|
||||
ae.setJobId(execId);
|
||||
return ae;
|
||||
});
|
||||
}).collect(Collectors.toList());
|
||||
// 1. 保存任务执行信息
|
||||
JmJobExec jobExec = new JmJobExec();
|
||||
jobExec.setConfId(dto.getId());
|
||||
jobExec.setStatus(dto.getStatus());
|
||||
jobExec.setBeginTime(dto.getBeginTime());
|
||||
jobExec.setType(dto.getType());
|
||||
jobExecMapper.insert(jobExec);
|
||||
long execId = jobExec.getId();
|
||||
// 2. 构建并保存航线执行列表
|
||||
List<JmAirlineExec> airlineExecList = dto.getUavList().stream()
|
||||
.flatMap(uav -> uav.getAirlineList().stream()
|
||||
.map(airline -> {
|
||||
JmAirlineExec ae = new JmAirlineExec();
|
||||
ae.setConfId(airline.getId());
|
||||
ae.setJobId(execId);
|
||||
ae.setStatus(ExecStatusEnum.NOT.getValue());
|
||||
return ae;
|
||||
}))
|
||||
.collect(Collectors.toList());
|
||||
jmAirlineExecService.insert(airlineExecList);
|
||||
// 回写航线执行ID
|
||||
// 键 航线配置ID,值 航线执行ID
|
||||
Map<Long, Long> airlineIdMap = airlineExecList.stream().collect(Collectors.toMap(a -> a.getConfId(), a -> a.getId(), (x, y) -> y));
|
||||
dto.getUavList().forEach(uav -> {
|
||||
uav.getAirlineList().forEach(a -> a.setExecId(airlineIdMap.get(a.getId())));
|
||||
});
|
||||
// 回写任务执行ID
|
||||
// 3. 回写航线执行ID
|
||||
Map<Long, Long> airlineIdMap = airlineExecList.stream()
|
||||
.collect(Collectors.toMap(JmAirlineExec::getConfId, JmAirlineExec::getId));
|
||||
dto.getUavList().forEach(uav -> uav.getAirlineList().forEach(airline ->
|
||||
airline.setExecId(airlineIdMap.get(airline.getId()))));
|
||||
// 4. 回写任务执行ID
|
||||
dto.setExecId(execId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateNotNull(JmJobExec e) {
|
||||
Long jobExecId = e.getId();
|
||||
@ -176,7 +176,7 @@ public class JmJobExecServiceImpl implements JmJobExecService {
|
||||
JmJobExec e = BeanUtil.copyProperties(dto, JmJobExec.class);
|
||||
jobExecMapper.updateNotNull(e);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteByJobConf(Long... jobConfId) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.zhangy.skyeye.jm.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zhangy.skyeye.common.extend.enums.EnumUtil;
|
||||
@ -378,11 +379,9 @@ public class JmJobServiceImpl implements JmJobService {
|
||||
// SarBackImageFrameDTO.i = 1;
|
||||
// 校验无人机、载荷
|
||||
jobStatusService.checkDeviceForNewJob(job.getUavList());
|
||||
Long jobId = job.getId();
|
||||
// 更新任务状态
|
||||
// 保存任务状态
|
||||
job.setStatus(ExecStatusEnum.PROCESSING.getValue());
|
||||
job.setBeginTime(new Date());
|
||||
// add exec
|
||||
job.setBeginTime(DateUtil.date());
|
||||
jmJobExecService.save(job);
|
||||
try {
|
||||
// 1.发送航线到雷达
|
||||
|
||||
@ -2,6 +2,7 @@ package com.zhangy.skyeye.jm.service.impl;
|
||||
|
||||
import com.zhangy.skyeye.common.extend.exception.ServiceException;
|
||||
import com.zhangy.skyeye.jm.dto.*;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobPayload;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobUav;
|
||||
import com.zhangy.skyeye.jm.event.JmAirlineStatusEvent;
|
||||
import com.zhangy.skyeye.jm.event.JmJobStatusEvent;
|
||||
@ -12,7 +13,6 @@ import com.zhangy.skyeye.publics.consts.ExecStatusEnum;
|
||||
import com.zhangy.skyeye.publics.consts.WebSocketKey;
|
||||
import com.zhangy.skyeye.publics.utils.CoordUtil;
|
||||
import com.zhangy.skyeye.sar.listen.SarImageUdpProcessor;
|
||||
// import com.zhangy.skyeye.smp.service.ISmpSubscriptService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@ -158,27 +158,29 @@ public class JmJobStatusServiceImpl implements JmJobStatusService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkDeviceForNewJob(List<JmJobUav> uavList) {
|
||||
// 查询未完成的无人机、载荷
|
||||
Set<Long> uavIds = new HashSet<>();
|
||||
Set<Long> sarIds = new HashSet<>();
|
||||
getAll().stream().flatMap(vo -> vo.getUavMap().values().stream())
|
||||
.forEach(vo -> {
|
||||
if (vo.getSarStatus() != ExecStatusEnum.OVER) {
|
||||
uavIds.add(vo.getUavId());
|
||||
sarIds.add(vo.getSarId());
|
||||
}
|
||||
});
|
||||
uavList.forEach(u -> {
|
||||
if (uavIds.contains(u.getUavId())) {
|
||||
public void checkDeviceForNewJob(List<JmJobUav> newJobUavs) {
|
||||
// 收集正在执行任务的无人机ID和载荷ID
|
||||
Set<Long> runningUavIds = new HashSet<>();
|
||||
Set<Long> runningPayloadIds = new HashSet<>();
|
||||
for (JmJobStatusDTO job : getAll()) {
|
||||
for (JmUavStatusDTO value : job.getUavMap().values()) {
|
||||
if (value.getSarStatus() != ExecStatusEnum.OVER) {
|
||||
runningUavIds.add(value.getUavId());
|
||||
runningPayloadIds.add(value.getSarId());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 校验新任务中的无人机和载荷是否冲突
|
||||
for (JmJobUav newUav : newJobUavs) {
|
||||
if (runningUavIds.contains(newUav.getUavId())) {
|
||||
throw ServiceException.warnLog("无人机正在任务中,无法执行新任务");
|
||||
}
|
||||
u.getPayloadList().forEach(p -> {
|
||||
if (sarIds.contains(p.getPayloadId())) {
|
||||
for (JmJobPayload payload : newUav.getPayloadList()) {
|
||||
if (runningPayloadIds.contains(payload.getPayloadId())) {
|
||||
throw ServiceException.warnLog("载荷正在任务中,无法执行新任务");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -296,7 +298,7 @@ public class JmJobStatusServiceImpl implements JmJobStatusService {
|
||||
|
||||
// 开启新航线
|
||||
private void startAirline(JmAirlineStatusDTO airline, JmJobStatusWsDTO ws) {
|
||||
log.info("开启航线" + airline.getNo() + ":id=" + airline.getExecId());
|
||||
log.info("开启航线" + airline.getNo() + ":id=" + airline.getExecId());
|
||||
updateAirline(airline, ExecStatusEnum.PROCESSING, ws);
|
||||
}
|
||||
|
||||
@ -314,6 +316,7 @@ public class JmJobStatusServiceImpl implements JmJobStatusService {
|
||||
|
||||
/**
|
||||
* 获取任务完成度
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private int getCompletion(JmJobStatusDTO job) {
|
||||
@ -339,7 +342,7 @@ public class JmJobStatusServiceImpl implements JmJobStatusService {
|
||||
* 结束sar
|
||||
*/
|
||||
private void endSar(JmUavStatusDTO uavVo, Long jobId, JmJobStatusWsDTO wsVo) {
|
||||
// uavVo.setSarStatus(ExecStatusEnum.OVER);
|
||||
// uavVo.setSarStatus(ExecStatusEnum.OVER);
|
||||
eventPublisher.publishEvent(new JmPayloadStatusEvent(jobId, uavVo.getSarId(), ExecStatusEnum.OVER));
|
||||
wsVo.setPayload(uavVo.getSarId(), ExecStatusEnum.OVER);
|
||||
log.info("结束sar,id=" + uavVo.getSarId() + ",任务ID=" + jobId);
|
||||
|
||||
@ -69,7 +69,7 @@ public class SarControlContext {
|
||||
|
||||
@PostConstruct
|
||||
public void log() {
|
||||
log.info("雷达传图类型:" + imgType);
|
||||
log.info("雷达传图类型:{}", imgType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.zhangy.skyeye.sar.listen;
|
||||
|
||||
import com.zhangy.skyeye.common.extend.exception.ServiceException;
|
||||
import com.zhangy.skyeye.jm.dto.JmAirlineStatusDTO;
|
||||
import com.zhangy.skyeye.jm.entity.JmImage;
|
||||
import com.zhangy.skyeye.jm.service.JmJobStatusService;
|
||||
@ -10,12 +9,10 @@ import com.zhangy.skyeye.sar.dto.SarImagePacketDTO;
|
||||
import com.zhangy.skyeye.sar.dto.SarImagePacketGroupDTO;
|
||||
import com.zhangy.skyeye.sar.service.ISarImageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tomcat.util.security.MD5Encoder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Map;
|
||||
@ -57,6 +54,7 @@ public class SarImageUdpProcessor extends SarAbstractUdpProcessor<SarImagePacket
|
||||
|
||||
/**
|
||||
* 判断是否可以合并回图帧,首包不能丢
|
||||
*
|
||||
* @param group
|
||||
* @return
|
||||
*/
|
||||
@ -72,6 +70,7 @@ public class SarImageUdpProcessor extends SarAbstractUdpProcessor<SarImagePacket
|
||||
* 合并后删除frameMap的分包数据
|
||||
* 使用ByteBuffer替代ByteArrayOutputStream,以减少内存分配。ByteArrayOutputStream 的 toByteArray()底层用Arrays.copyOf实现,
|
||||
* 有性能开销;ByteBuffer的array()无需拷贝数组
|
||||
*
|
||||
* @param group
|
||||
* @return
|
||||
*/
|
||||
@ -97,7 +96,6 @@ public class SarImageUdpProcessor extends SarAbstractUdpProcessor<SarImagePacket
|
||||
|
||||
@Override
|
||||
public SarImagePacketGroupDTO putPacket(String sourceIp, SarImagePacketDTO packet) {
|
||||
//System.out.println("udp:" + packet.getSessionId() + "," + packet.getPacketNo());
|
||||
// 1.包放入缓冲区
|
||||
long sessionId = packet.getSessionId();
|
||||
SarImagePacketGroupDTO group;
|
||||
@ -114,12 +112,11 @@ public class SarImageUdpProcessor extends SarAbstractUdpProcessor<SarImagePacket
|
||||
group.setAirlineExecId(currAirline.getExecId());
|
||||
put(sourceIp, sessionId, group);
|
||||
}
|
||||
//System.out.println(packet);
|
||||
// 2.判断是否全部包到达,是则合并
|
||||
SarImagePacketDTO last = group.getLastPacket();
|
||||
// 若所有包已收到则合并
|
||||
if (last != null && last.isLast() && group.getPackets().size() == group.getMaxNo() + 1) {
|
||||
log.info("[UDP] sesionid="+ packet.getSessionId() + "全部到达合并!");
|
||||
log.info("[UDP] sesionid=" + packet.getSessionId() + "全部到达合并!");
|
||||
byte[] framePacketData = join(group);
|
||||
afterJoin(framePacketData, group);
|
||||
remove(sourceIp, sessionId);
|
||||
@ -137,15 +134,16 @@ public class SarImageUdpProcessor extends SarAbstractUdpProcessor<SarImagePacket
|
||||
protected void expireProcess(SarImagePacketGroupDTO group) {
|
||||
// 定时判断:超过 PACKET_TIMEOUT 时间未收到新包且符合生成条件则合成图
|
||||
if (canJoin(group)) {
|
||||
log.info("[UDP] sesionid="+ group.getSessionId() + "超时合并!");
|
||||
log.info("[UDP] sesionid: {} 超时合并!", group.getSessionId());
|
||||
byte[] framePacketData = join(group);
|
||||
afterJoin(framePacketData, group);
|
||||
} else { // 超时且无法合并,丢弃
|
||||
} else {
|
||||
// 超时且无法合并,丢弃
|
||||
Map<Integer, SarImagePacketDTO> packets = group.getPackets();
|
||||
if (packets.size() == 1 && packets.values().iterator().next().isLast()) {
|
||||
// 雷达传图有bug,每帧的尾包会多发一个,丢弃且不打印日志
|
||||
} else {
|
||||
log.warn(getText() + "-移除超时帧: {}", group.getSessionId());
|
||||
log.warn("{}-移除超时帧: {}", getText(), group.getSessionId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
package com.zhangy.skyeye.sar.service.impl;
|
||||
|
||||
import com.zhangy.skyeye.jm.dto.JmAirlineStatusDTO;
|
||||
import com.zhangy.skyeye.jm.dto.JmUavStatusDTO;
|
||||
import com.zhangy.skyeye.jm.entity.JmImage;
|
||||
import com.zhangy.skyeye.jm.service.JmJobStatusService;
|
||||
import com.zhangy.skyeye.jm.dto.JmAirlineStatusDTO;
|
||||
import com.zhangy.skyeye.publics.consts.WebSocketKey;
|
||||
import com.zhangy.skyeye.publics.service.SysFileTypeService;
|
||||
import com.zhangy.skyeye.sar.dto.JmSarWaveWsDTO;
|
||||
import com.zhangy.skyeye.sar.dto.SarBackWaveFrameDTO;
|
||||
import com.zhangy.skyeye.sar.service.ISarBackWsService;
|
||||
import com.zhangy.skyeye.sar.service.SarWsAsyncService;
|
||||
import com.zhangy.skyeye.sar.dto.JmSarWaveWsDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
@ -20,10 +20,10 @@ import java.util.Date;
|
||||
/**
|
||||
* 雷达回传数据推送
|
||||
* 图像矩阵排列,非如此排列需要转置图像
|
||||
* 1————————————————————5
|
||||
* 2 6
|
||||
* 3 7
|
||||
* 4————————————————————8
|
||||
* 1————————————————————5
|
||||
* 2 6
|
||||
* 3 7
|
||||
* 4————————————————————8
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -59,7 +59,7 @@ public class SarBackWsServiceImpl implements ISarBackWsService {
|
||||
* 加载任务信息
|
||||
*
|
||||
* @param payloadIp 载荷IP
|
||||
* @param vo 包含通道信息的vo
|
||||
* @param vo 包含通道信息的vo
|
||||
* @return
|
||||
*/
|
||||
private JmSarWaveWsDTO loadJobDetail(String payloadIp, JmSarWaveWsDTO ws, byte[] frameData) {
|
||||
|
||||
@ -1,20 +1,23 @@
|
||||
package com.zhangy.skyeye.sar.service.impl;
|
||||
|
||||
import com.zhangy.skyeye.common.extend.util.JsonUtil;
|
||||
import com.zhangy.skyeye.redis.utils.RedisUtil;
|
||||
import com.zhangy.skyeye.jm.dto.JmJobDTO;
|
||||
import com.zhangy.skyeye.publics.consts.CacheKey;
|
||||
import com.zhangy.skyeye.sar.control.SarControlContext;
|
||||
import com.zhangy.skyeye.sar.enums.SarControlTypeEnum;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobPayload;
|
||||
import com.zhangy.skyeye.jm.dto.JmSarStatusDTO;
|
||||
import com.zhangy.skyeye.sar.service.ISarControlService;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobPayload;
|
||||
import com.zhangy.skyeye.jm.entity.JmJobUav;
|
||||
import com.zhangy.skyeye.publics.consts.CacheKey;
|
||||
import com.zhangy.skyeye.redis.utils.RedisUtil;
|
||||
import com.zhangy.skyeye.sar.control.SarControlContext;
|
||||
import com.zhangy.skyeye.sar.dto.SarControlParamDTO;
|
||||
import com.zhangy.skyeye.sar.enums.SarControlTypeEnum;
|
||||
import com.zhangy.skyeye.sar.service.ISarControlService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 控制指令
|
||||
*/
|
||||
@ -30,35 +33,34 @@ public class SarControlServiceImpl implements ISarControlService {
|
||||
|
||||
@Override
|
||||
public void sendUdp(JmJobDTO job) {
|
||||
if (job == null) {
|
||||
return;
|
||||
}
|
||||
if (job == null || job.getUavList() == null) return;
|
||||
job.getUavList().forEach(uav -> {
|
||||
JmJobPayload sar = uav.getSar0();
|
||||
if (sar == null) return;
|
||||
SarControlParamDTO param = new SarControlParamDTO();
|
||||
// 载荷参数 -> 雷达控制参数
|
||||
param.setIp(sar.getIp());
|
||||
param.setAirlineList(uav.getAirlineList());
|
||||
param.setAutoFocus(sar.getAutoFocus());
|
||||
param.setMoto(sar.getMoto());
|
||||
param.setImageBit(sar.getImageBit());
|
||||
|
||||
double startAltitude = uav.getStartAltitude();
|
||||
param.getAirlineList().forEach(a -> {
|
||||
// 雷达参数中的高度转为海拔高度
|
||||
a.setFlightEndHeight(a.getFlightEndHeight() + startAltitude);
|
||||
a.setFlightStartHeight(a.getFlightStartHeight() + startAltitude);
|
||||
a.setGroundStartHeight(a.getGroundStartHeight() + startAltitude);
|
||||
a.setTargetCentroidHeight(a.getTargetCentroidHeight() + startAltitude);
|
||||
});
|
||||
param.setResolution(sar.getResolution());
|
||||
param.setControlType(SarControlTypeEnum.AUTO);
|
||||
double startAltitude = uav.getStartAltitude();
|
||||
// 高度加上起始高度
|
||||
Optional.ofNullable(param.getAirlineList())
|
||||
.ifPresent(list -> list.forEach(a -> {
|
||||
a.setFlightStartHeight(a.getFlightStartHeight() + startAltitude);
|
||||
a.setFlightEndHeight(a.getFlightEndHeight() + startAltitude);
|
||||
a.setGroundStartHeight(a.getGroundStartHeight() + startAltitude);
|
||||
a.setTargetCentroidHeight(a.getTargetCentroidHeight() + startAltitude);
|
||||
}));
|
||||
param.checkOrSetData();
|
||||
log.info("上传雷达:" + JsonUtil.toString(param));
|
||||
log.info("上传雷达:{}", JsonUtil.toString(param));
|
||||
sendUdp(param);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendUdp(SarControlParamDTO param) {
|
||||
udpSendContext.execute(param);
|
||||
|
||||
1
frontend/.gitignore
vendored
1
frontend/.gitignore
vendored
@ -19,3 +19,4 @@ pack/
|
||||
package-lock.json
|
||||
.DS_Store
|
||||
.history
|
||||
/*.lock
|
||||
|
||||
Loading…
Reference in New Issue
Block a user