|
|
@@ -3,6 +3,7 @@ package com.usky.cdi.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.usky.cdi.domain.CdiDefenseProject;
|
|
|
import com.usky.cdi.domain.CdiDeliveryLog;
|
|
|
import com.usky.cdi.domain.DmpDevice;
|
|
|
@@ -149,7 +150,7 @@ public class IotDataTransferService {
|
|
|
|
|
|
// ✅ 在空数据时也记录一条日志(可选)
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
- saveLog(transferVO, now, startTime, endTime, totalDevices, 0, totalDevices, 0, 0);
|
|
|
+ saveLog(transferVO, now, startTime, endTime, totalDevices, 0, totalDevices, 0, 0, SecurityUtils.getUsername());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -194,7 +195,7 @@ public class IotDataTransferService {
|
|
|
int failure = result.get("failureCount");
|
|
|
int pending = totalDevices - success - failure;
|
|
|
|
|
|
- saveLog(transferVO, now, startTime, endTime, totalDevices, success, failure, pending, success > 0 ? 1 : 0);
|
|
|
+ saveLog(transferVO, now, startTime, endTime, totalDevices, success, failure, pending, success > 0 ? 1 : 0, SecurityUtils.getUsername());
|
|
|
|
|
|
log.info("水浸状态数据推送完成,设备类型:{},成功:{},失败:{}",
|
|
|
deviceType, success, failure);
|
|
|
@@ -206,7 +207,7 @@ public class IotDataTransferService {
|
|
|
|
|
|
// ✅ 异常时也记录一条日志
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
- saveLog(transferVO, now, startTime, endTime, transferVO.getDevices().size(), 0, transferVO.getDevices().size(), 0, 0);
|
|
|
+ saveLog(transferVO, now, startTime, endTime, transferVO.getDevices().size(), 0, transferVO.getDevices().size(), 0, 0, SecurityUtils.getUsername());
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
@@ -279,7 +280,7 @@ public class IotDataTransferService {
|
|
|
endTime = System.currentTimeMillis();
|
|
|
|
|
|
// ✅ 确保这里会被执行,且deviceType被正确记录
|
|
|
- saveLog(transferVO, now, startTime, endTime, totalDevices, success, failure, notSynced, 1);
|
|
|
+ saveLog(transferVO, now, startTime, endTime, totalDevices, success, failure, notSynced, 1, SecurityUtils.getUsername());
|
|
|
|
|
|
log.info("空气质量推送完成,设备类型:{},成功:{},失败:{},未同步:{}",
|
|
|
deviceType, success, failure, notSynced);
|
|
|
@@ -296,7 +297,7 @@ public class IotDataTransferService {
|
|
|
|
|
|
// ✅ 异常情况下也要记录日志
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices, success, failure,
|
|
|
- totalDevices - success - failure, 0);
|
|
|
+ totalDevices - success - failure, 0, SecurityUtils.getUsername());
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
@@ -304,10 +305,14 @@ public class IotDataTransferService {
|
|
|
|
|
|
@Async("asyncServiceExecutor")
|
|
|
public void saveLog(IotDataTransferVO transferVO, LocalDateTime now, long startTime, long endTime,
|
|
|
- int total, int success, int failure, int notSynced, int pushFlag) {
|
|
|
+ int total, int success, int failure, int notSynced, int pushFlag, String userName) {
|
|
|
|
|
|
Integer deviceType = transferVO.getDeviceType();
|
|
|
|
|
|
+ if (StringUtils.isBlank(userName)) {
|
|
|
+ userName = "自动同步";
|
|
|
+ }
|
|
|
+
|
|
|
SyncTaskStatisticsVO vo = new SyncTaskStatisticsVO();
|
|
|
vo.setDataType(4);
|
|
|
vo.setTotal(total);
|
|
|
@@ -325,8 +330,8 @@ public class IotDataTransferService {
|
|
|
log.setDataType(4);
|
|
|
log.setTopic(vo.getTopic());
|
|
|
log.setDataTypeName(vo.getDataTypeName());
|
|
|
- log.setUserName(SecurityUtils.getUsername() == null ? "自动同步" : SecurityUtils.getUsername());
|
|
|
- log.setNickName(SecurityUtils.getUsername() == null ? "自动同步" : SecurityUtils.getLoginUser().getSysUser().getNickName());
|
|
|
+ log.setUserName(userName);
|
|
|
+ log.setNickName(userName);
|
|
|
log.setCreateTime(now);
|
|
|
log.setTenantId(getTenantId(transferVO.getEngineeringId()));
|
|
|
log.setPushFlag(pushFlag);
|
|
|
@@ -379,7 +384,7 @@ public class IotDataTransferService {
|
|
|
// 记录一条汇总日志
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
- 0, totalDevices, 0, 0);
|
|
|
+ 0, totalDevices, 0, 0, SecurityUtils.getUsername());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -425,7 +430,7 @@ public class IotDataTransferService {
|
|
|
int status = (success > 0) ? 1 : 0; // 1=部分或全部成功,0=全失败
|
|
|
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
- success, failure, pending, status);
|
|
|
+ success, failure, pending, status, SecurityUtils.getUsername());
|
|
|
|
|
|
log.info("人员闯入情况数据推送完成,设备类型:{},成功:{},失败:{}",
|
|
|
deviceType, success, failure);
|
|
|
@@ -440,7 +445,7 @@ public class IotDataTransferService {
|
|
|
// 异常时也记录一条日志
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
- 0, totalDevices, 0, 0);
|
|
|
+ 0, totalDevices, 0, 0, SecurityUtils.getUsername());
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
@@ -479,7 +484,7 @@ public class IotDataTransferService {
|
|
|
// 记录一条汇总日志
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
- 0, totalDevices, 0, 0);
|
|
|
+ 0, totalDevices, 0, 0, SecurityUtils.getUsername());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -540,7 +545,7 @@ public class IotDataTransferService {
|
|
|
int status = (success > 0) ? 1 : 0; // 1=有成功,0=全失败
|
|
|
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
- success, failure, pending, status);
|
|
|
+ success, failure, pending, status, SecurityUtils.getUsername());
|
|
|
|
|
|
log.info("人防用电负荷情况数据推送完成,设备类型:{},成功:{},失败:{}",
|
|
|
deviceType, success, failure);
|
|
|
@@ -555,7 +560,7 @@ public class IotDataTransferService {
|
|
|
// 异常时也记录一条日志
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
- 0, totalDevices, 0, 0);
|
|
|
+ 0, totalDevices, 0, 0, SecurityUtils.getUsername());
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
@@ -902,7 +907,7 @@ public class IotDataTransferService {
|
|
|
endTime = System.currentTimeMillis();
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
result.get("successCount"), result.get("failureCount"),
|
|
|
- totalDevices - result.get("successCount") - result.get("failureCount"), 1);
|
|
|
+ totalDevices - result.get("successCount") - result.get("failureCount"), 1, SecurityUtils.getUsername());
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
log.error("位移数据推送发生异常", e);
|
|
|
@@ -910,7 +915,7 @@ public class IotDataTransferService {
|
|
|
endTime = System.currentTimeMillis();
|
|
|
saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
result.get("successCount"), result.get("failureCount"),
|
|
|
- totalDevices - result.get("successCount") - result.get("failureCount"), 0);
|
|
|
+ totalDevices - result.get("successCount") - result.get("failureCount"), 0, SecurityUtils.getUsername());
|
|
|
return result;
|
|
|
}
|
|
|
}
|