修改自检存放逻辑

This commit is contained in:
孙小云 2026-02-25 13:17:42 +08:00
parent 5cd7f39d6e
commit 2d5076351b
1 changed files with 28 additions and 8 deletions

View File

@ -4,18 +4,12 @@ import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.device.domain.impl.tuohengmqtt.callback.IAirportFlyControlDataCallback; import com.ruoyi.device.domain.impl.tuohengmqtt.callback.IAirportFlyControlDataCallback;
import com.ruoyi.device.mapper.entity.FlightEntity; import com.ruoyi.device.mapper.entity.FlightEntity;
import com.ruoyi.device.mapper.entity.FlightLogEntity; import com.ruoyi.device.mapper.entity.FlightLogEntity;
import com.ruoyi.device.mapper.entity.PreCheckLogEntity;
import com.ruoyi.device.service.FlightService; import com.ruoyi.device.service.FlightService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* 飞行事件回调处理器
* 处理飞行事件日志如起飞返航等
*
* @author ruoyi
* @date 2026-02-25
*/
@Slf4j @Slf4j
@Component @Component
public class FlightEventCallback implements IAirportFlyControlDataCallback { public class FlightEventCallback implements IAirportFlyControlDataCallback {
@ -50,7 +44,11 @@ public class FlightEventCallback implements IAirportFlyControlDataCallback {
} }
if (msg != null && !msg.isEmpty()) { if (msg != null && !msg.isEmpty()) {
if (msg.contains("自检")) {
handlePreCheckLog(deviceSn, msg, data, flight);
} else {
handleFlightLog(deviceSn, msg, flight); handleFlightLog(deviceSn, msg, flight);
}
handleFlightStatus(deviceSn, action, data, flight); handleFlightStatus(deviceSn, action, data, flight);
} }
} catch (Exception e) { } catch (Exception e) {
@ -84,6 +82,28 @@ public class FlightEventCallback implements IAirportFlyControlDataCallback {
} }
} }
private void handlePreCheckLog(String deviceSn, String msg, JSONObject data, FlightEntity flight) {
if (flight == null) {
log.warn("飞行记录为空,无法保存自检日志: deviceSn={}, msg={}", deviceSn, msg);
return;
}
try {
Boolean success = msg.contains("通过") || msg.contains("成功");
PreCheckLogEntity logEntity = new PreCheckLogEntity();
logEntity.setFlightId(flight.getFlightId());
logEntity.setLogContent(msg);
logEntity.setSuccess(success);
flightService.insertPreCheckLog(logEntity);
log.info("保存自检日志: deviceSn={}, flightId={}, msg={}, success={}",
deviceSn, flight.getFlightId(), msg, success);
} catch (Exception e) {
log.error("保存自检日志失败: deviceSn={}, msg={}, error={}",
deviceSn, msg, e.getMessage(), e);
}
}
private void handleFlightStatus(String deviceSn, String action, JSONObject data, FlightEntity flight) { private void handleFlightStatus(String deviceSn, String action, JSONObject data, FlightEntity flight) {
if (flight == null) { if (flight == null) {
log.warn("飞行记录为空,无法更新状态: deviceSn={}, action={}", deviceSn, action); log.warn("飞行记录为空,无法更新状态: deviceSn={}, action={}", deviceSn, action);