添加日志
This commit is contained in:
parent
b4809cf94d
commit
b509f5e997
|
|
@ -19,43 +19,59 @@ public class FlightEventCallback implements IAirportFlyControlDataCallback {
|
|||
|
||||
@Override
|
||||
public void onAirportFlyControlData(String deviceSn, String payload, String topic) {
|
||||
log.info("【FlightEventCallback】收到飞行事件: deviceSn={}, topic={}, payload={}", deviceSn, topic, payload);
|
||||
|
||||
try {
|
||||
|
||||
log.info("处理飞行事件: deviceSn={}, topic={}, payload={}", deviceSn, topic, payload);
|
||||
|
||||
JSONObject data = JSONObject.parseObject(payload);
|
||||
if (data == null) {
|
||||
log.warn("【FlightEventCallback】解析payload失败: deviceSn={}, topic={}, payload={}", deviceSn, topic, payload);
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = data.getString("msg");
|
||||
String messageID = data.getString("messageID");
|
||||
|
||||
String action = data.getString("action");
|
||||
|
||||
log.info("【FlightEventCallback】解析飞行事件数据: deviceSn={}, messageID={}, msg=, action={}", deviceSn, messageID, msg, action);
|
||||
|
||||
if (action == null || action.isEmpty()) {
|
||||
JSONObject dataObj = data.getJSONObject("data");
|
||||
if (dataObj != null) {
|
||||
action = dataObj.getString("action");
|
||||
log.info("【FlightEventCallback】从data对象中获取action: deviceSn={}, action={}", deviceSn, action);
|
||||
}
|
||||
}
|
||||
|
||||
FlightEntity flight;
|
||||
if (messageID != null && !messageID.isEmpty()) {
|
||||
log.info("【FlightEventCallback】通过messageID获取飞行记录: deviceSn={}, messageID={}", deviceSn, messageID);
|
||||
flight = handleFlightIdExternal(deviceSn, messageID);
|
||||
} else {
|
||||
log.info("【FlightEventCallback】获取当前飞行记录: deviceSn={}", deviceSn);
|
||||
flight = flightService.getOrCreateCurrentFlight(deviceSn);
|
||||
}
|
||||
|
||||
if (flight == null) {
|
||||
log.error("【FlightEventCallback】获取飞行记录失败: deviceSn={}, messageID={}", deviceSn, messageID);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("【FlightEventCallback】获取到飞行记录: deviceSn={}, flightId={}, status={}", deviceSn, flight.getFlightId(), flight.getStatus());
|
||||
|
||||
if (msg != null && !msg.isEmpty()) {
|
||||
if (msg.contains("自检")) {
|
||||
log.info("【FlightEventCallback】检测到自检消息: deviceSn={}, msg={}", deviceSn, msg);
|
||||
handlePreCheckLog(deviceSn, msg, data, flight);
|
||||
} else {
|
||||
log.info("【FlightEventCallback】检测到飞行日志消息: deviceSn={}, msg={}", deviceSn, msg);
|
||||
handleFlightLog(deviceSn, msg, flight);
|
||||
}
|
||||
handleFlightStatus(deviceSn, action, data, flight);
|
||||
} else {
|
||||
log.warn("【FlightEventCallback】消息内容为空: deviceSn={}, messageID={}", deviceSn, messageID);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理飞行事件失败: deviceSn={}, topic={}, error={}", deviceSn, topic, e.getMessage(), e);
|
||||
log.error("【FlightEventCallback】处理飞行事件失败: deviceSn={}, topic={}, error={}", deviceSn, topic, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,27 +85,35 @@ public class FlightEventCallback implements IAirportFlyControlDataCallback {
|
|||
|
||||
private void handleFlightLog(String deviceSn, String message, FlightEntity flight) {
|
||||
if (flight == null) {
|
||||
log.warn("飞行记录为空,无法保存飞行日志: deviceSn={}, message={}", deviceSn, message);
|
||||
log.error("【FlightEventCallback】飞行记录为空,无法保存飞行日志: deviceSn={}, message={}", deviceSn, message);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("【FlightEventCallback】准备保存飞行日志: deviceSn={}, flightId={}, message={}", deviceSn, flight.getFlightId(), message);
|
||||
|
||||
try {
|
||||
FlightLogEntity logEntity = new FlightLogEntity();
|
||||
logEntity.setFlightId(flight.getFlightId());
|
||||
logEntity.setLogContent(message);
|
||||
|
||||
flightService.insertFlightLog(logEntity);
|
||||
log.info("保存飞行日志: deviceSn={}, flightId={}, message={}",
|
||||
deviceSn, flight.getFlightId(), message);
|
||||
|
||||
log.info("【FlightEventCallback】成功保存飞行日志: deviceSn={}, flightId={}, logId={}, message={}",
|
||||
deviceSn, flight.getFlightId(), logEntity.getLogId(), message);
|
||||
} catch (Exception e) {
|
||||
log.error("保存飞行日志失败: deviceSn={}, message={}, error={}",
|
||||
deviceSn, message, e.getMessage(), e);
|
||||
log.error("【FlightEventCallback】保存飞行日志失败: deviceSn={}, flightId={}, message={}, error={}",
|
||||
deviceSn, flight.getFlightId(), message, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePreCheckLog(String deviceSn, String msg, JSONObject data, FlightEntity flight) {
|
||||
if (flight == null) {
|
||||
log.warn("飞行记录为空,无法保存自检日志: deviceSn={}, msg={}", deviceSn, msg);
|
||||
log.error("【FlightEventCallback】飞行记录为空,无法保存自检日志: deviceSn={}, msg={}", deviceSn, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("【FlightEventCallback】准备保存自检日志: deviceSn={}, flightId={}, msg={}", deviceSn, flight.getFlightId(), msg);
|
||||
|
||||
try {
|
||||
Boolean success = msg.contains("通过") || msg.contains("成功");
|
||||
|
||||
|
|
@ -97,36 +121,44 @@ public class FlightEventCallback implements IAirportFlyControlDataCallback {
|
|||
logEntity.setFlightId(flight.getFlightId());
|
||||
logEntity.setLogContent(msg);
|
||||
logEntity.setSuccess(success);
|
||||
|
||||
flightService.insertPreCheckLog(logEntity);
|
||||
|
||||
log.info("保存自检日志: deviceSn={}, flightId={}, msg={}, success={}",
|
||||
deviceSn, flight.getFlightId(), msg, success);
|
||||
log.info("【FlightEventCallback】成功保存自检日志: deviceSn={}, flightId={}, logId={}, msg={}, success={}",
|
||||
deviceSn, flight.getFlightId(), logEntity.getLogId(), msg, success);
|
||||
} catch (Exception e) {
|
||||
log.error("保存自检日志失败: deviceSn={}, msg={}, error={}",
|
||||
deviceSn, msg, e.getMessage(), e);
|
||||
log.error("【FlightEventCallback】保存自检日志失败: deviceSn={}, flightId={}, msg={}, error={}",
|
||||
deviceSn, flight.getFlightId(), msg, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFlightStatus(String deviceSn, String action, JSONObject data, FlightEntity flight) {
|
||||
if (flight == null) {
|
||||
log.warn("飞行记录为空,无法更新状态: deviceSn={}, action={}", deviceSn, action);
|
||||
log.error("【FlightEventCallback】飞行记录为空,无法更新状态: deviceSn={}, action={}", deviceSn, action);
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("【FlightEventCallback】检查是否需要更新飞行状态: deviceSn={}, flightId={}, action={}", deviceSn, flight.getFlightId(), action);
|
||||
|
||||
try {
|
||||
String msg = data.getString("msg");
|
||||
String dataContent = data.getString("data");
|
||||
|
||||
if ((msg != null && msg.contains("起飞成功")) || (dataContent != null && dataContent.contains("起飞成功"))) {
|
||||
log.info("【FlightEventCallback】检测到起飞成功,更新状态为飞行中: deviceSn={}, flightId={}", deviceSn, flight.getFlightId());
|
||||
flightService.updateFlightStatus(flight.getFlightId(), "飞行中");
|
||||
log.info("飞行状态更新: deviceSn={}, status=飞行中", deviceSn);
|
||||
log.info("【FlightEventCallback】飞行状态更新成功: deviceSn={}, flightId={}, status=飞行中", deviceSn, flight.getFlightId());
|
||||
} else if ((msg != null && msg.contains("返航成功")) || (dataContent != null && dataContent.contains("返航成功")) ||
|
||||
(dataContent != null && dataContent.contains("任务飞行完成"))) {
|
||||
log.info("【FlightEventCallback】检测到返航成功,更新状态为已返航: deviceSn={}, flightId={}", deviceSn, flight.getFlightId());
|
||||
flightService.updateFlightStatus(flight.getFlightId(), "已返航");
|
||||
log.info("飞行状态更新: deviceSn={}, status=已返航", deviceSn);
|
||||
log.info("【FlightEventCallback】飞行状态更新成功: deviceSn={}, flightId={}, status=已返航", deviceSn, flight.getFlightId());
|
||||
} else {
|
||||
log.debug("【FlightEventCallback】无需更新飞行状态: deviceSn={}, flightId={}, msg={}", deviceSn, flight.getFlightId(), msg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新飞行状态失败: deviceSn={}, action={}, error={}",
|
||||
deviceSn, action, e.getMessage(), e);
|
||||
log.error("【FlightEventCallback】更新飞行状态失败: deviceSn={}, flightId={}, action={}, error={}",
|
||||
deviceSn, flight.getFlightId(), action, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,58 +32,89 @@ public class FlightLogCallback implements IDroneRealTimeCallback {
|
|||
@Override
|
||||
public void onDroneRealTimeData(String deviceSn, DroneRealTimeData data) {
|
||||
|
||||
if (data == null || data.getData() == null) {
|
||||
if (data == null) {
|
||||
log.warn("【FlightLogCallback】收到空数据: deviceSn={}", deviceSn);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("处理实时消息: deviceSn={}, messageId={} data={}", deviceSn, data.getMessageID(),JSON.toJSONString(data.getData()));
|
||||
if (data.getData() == null) {
|
||||
log.warn("【FlightLogCallback】收到空数据体: deviceSn={}, messageId={}", deviceSn, data.getMessageID());
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("【FlightLogCallback】处理实时消息: deviceSn={}, messageId={}, data={}", deviceSn, data.getMessageID(), JSON.toJSONString(data.getData()));
|
||||
|
||||
DroneRealTimeData.DroneInfo droneInfo = data.getData();
|
||||
|
||||
try {
|
||||
if (droneInfo.getJiancha() != null && !droneInfo.getJiancha().isEmpty()) {
|
||||
log.info("处理实时自检消息: deviceSn={}, messageId={}, checkBody={}", deviceSn, data.getMessageID(),data.getData().getJiancha());
|
||||
log.info("【FlightLogCallback】检测到自检数据: deviceSn={}, messageId={}, checkBody={}", deviceSn, data.getMessageID(), data.getData().getJiancha());
|
||||
handlePreCheckLog(deviceSn, data.getMessageID(), droneInfo.getJiancha());
|
||||
} else {
|
||||
log.debug("【FlightLogCallback】实时消息中无自检数据: deviceSn={}, messageId={}", deviceSn, data.getMessageID());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理自检日志失败: deviceSn={}, error={}", deviceSn, e.getMessage(), e);
|
||||
log.error("【FlightLogCallback】处理自检日志失败: deviceSn={}, messageId={}, error={}", deviceSn, data.getMessageID(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePreCheckLog(String deviceSn, String messageID, String jianchaJson) {
|
||||
log.info("【FlightLogCallback】开始处理自检日志: deviceSn={}, messageId={}, jianchaJson={}", deviceSn, messageID, jianchaJson);
|
||||
|
||||
try {
|
||||
FlightEntity flight;
|
||||
|
||||
if (messageID != null && !messageID.isEmpty()) {
|
||||
log.info("【FlightLogCallback】通过messageId获取飞行记录: deviceSn={}, messageId={}", deviceSn, messageID);
|
||||
flight = flightService.getOrCreateFlightByMessageId(deviceSn, messageID);
|
||||
} else {
|
||||
log.info("【FlightLogCallback】获取当前飞行记录: deviceSn={}", deviceSn);
|
||||
flight = flightService.getOrCreateCurrentFlight(deviceSn);
|
||||
}
|
||||
|
||||
JSONArray checkItems = JSON.parseArray(jianchaJson);
|
||||
if (checkItems != null && !checkItems.isEmpty()) {
|
||||
for (int i = 0; i < checkItems.size(); i++) {
|
||||
JSONObject item = checkItems.getJSONObject(i);
|
||||
PreCheckLogEntity logEntity = new PreCheckLogEntity();
|
||||
logEntity.setFlightId(flight.getFlightId());
|
||||
|
||||
String check = item.getString("check");
|
||||
String value = item.getString("value");
|
||||
Boolean result = item.getBoolean("result");
|
||||
|
||||
String statusText = result != null && result ? "自检成功" : "自检失败";
|
||||
String logContent = check + " " + value + " " + statusText;
|
||||
|
||||
logEntity.setLogContent(logContent);
|
||||
logEntity.setSuccess(result != null ? result : false);
|
||||
flightService.insertPreCheckLog(logEntity);
|
||||
}
|
||||
log.info("保存自检日志: deviceSn={}, flightId={}, 检查项数量={}",
|
||||
deviceSn, flight.getFlightId(), checkItems.size());
|
||||
if (flight == null) {
|
||||
log.error("【FlightLogCallback】获取飞行记录失败,无法保存自检日志: deviceSn={}, messageId={}", deviceSn, messageID);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("【FlightLogCallback】获取到飞行记录: deviceSn={}, flightId={}, status={}", deviceSn, flight.getFlightId(), flight.getStatus());
|
||||
|
||||
JSONArray checkItems = JSON.parseArray(jianchaJson);
|
||||
if (checkItems == null || checkItems.isEmpty()) {
|
||||
log.warn("【FlightLogCallback】自检数据为空或解析失败: deviceSn={}, jianchaJson={}", deviceSn, jianchaJson);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("【FlightLogCallback】解析到{}个自检项: deviceSn={}, flightId={}", checkItems.size(), deviceSn, flight.getFlightId());
|
||||
|
||||
for (int i = 0; i < checkItems.size(); i++) {
|
||||
JSONObject item = checkItems.getJSONObject(i);
|
||||
PreCheckLogEntity logEntity = new PreCheckLogEntity();
|
||||
logEntity.setFlightId(flight.getFlightId());
|
||||
|
||||
String check = item.getString("check");
|
||||
String value = item.getString("value");
|
||||
Boolean result = item.getBoolean("result");
|
||||
|
||||
String statusText = result != null && result ? "自检成功" : "自检失败";
|
||||
String logContent = check + " " + value + " " + statusText;
|
||||
|
||||
logEntity.setLogContent(logContent);
|
||||
logEntity.setSuccess(result != null ? result : false);
|
||||
|
||||
log.info("【FlightLogCallback】准备插入自检日志[{}/{}]: deviceSn={}, flightId={}, check={}, value={}, result={}",
|
||||
i + 1, checkItems.size(), deviceSn, flight.getFlightId(), check, value, result);
|
||||
|
||||
flightService.insertPreCheckLog(logEntity);
|
||||
|
||||
log.info("【FlightLogCallback】成功插入自检日志[{}/{}]: deviceSn={}, flightId={}, logId={}",
|
||||
i + 1, checkItems.size(), deviceSn, flight.getFlightId(), logEntity.getLogId());
|
||||
}
|
||||
log.info("【FlightLogCallback】完成保存自检日志: deviceSn={}, flightId={}, 检查项数量={}",
|
||||
deviceSn, flight.getFlightId(), checkItems.size());
|
||||
} catch (Exception e) {
|
||||
log.error("保存自检日志失败: deviceSn={}, jiancha={}, error={}",
|
||||
deviceSn, jianchaJson, e.getMessage(), e);
|
||||
log.error("【FlightLogCallback】保存自检日志失败: deviceSn={}, messageId={}, jiancha={}, error={}",
|
||||
deviceSn, messageID, jianchaJson, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,11 +148,33 @@ public class FlightServiceImpl implements FlightService
|
|||
|
||||
@Override
|
||||
public void insertPreCheckLog(PreCheckLogEntity logEntity) {
|
||||
preCheckLogMapper.insertPreCheckLog(logEntity);
|
||||
log.info("【FlightServiceImpl】准备插入自检日志: flightId={}, logContent={}, success={}",
|
||||
logEntity.getFlightId(), logEntity.getLogContent(), logEntity.getSuccess());
|
||||
|
||||
int rows = preCheckLogMapper.insertPreCheckLog(logEntity);
|
||||
|
||||
if (rows > 0) {
|
||||
log.info("【FlightServiceImpl】成功插入自检日志: flightId={}, logId={}, rows={}",
|
||||
logEntity.getFlightId(), logEntity.getLogId(), rows);
|
||||
} else {
|
||||
log.error("【FlightServiceImpl】插入自检日志失败,影响行数为0: flightId={}, logContent={}",
|
||||
logEntity.getFlightId(), logEntity.getLogContent());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertFlightLog(FlightLogEntity logEntity) {
|
||||
flightLogMapper.insertFlightLog(logEntity);
|
||||
log.info("【FlightServiceImpl】准备插入飞行日志: flightId={}, logContent={}",
|
||||
logEntity.getFlightId(), logEntity.getLogContent());
|
||||
|
||||
int rows = flightLogMapper.insertFlightLog(logEntity);
|
||||
|
||||
if (rows > 0) {
|
||||
log.info("【FlightServiceImpl】成功插入飞行日志: flightId={}, logId={}, rows={}",
|
||||
logEntity.getFlightId(), logEntity.getLogId(), rows);
|
||||
} else {
|
||||
log.error("【FlightServiceImpl】插入飞行日志失败,影响行数为0: flightId={}, logContent={}",
|
||||
logEntity.getFlightId(), logEntity.getLogContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue