fix:太阳能网控,后台代码修改完善。
This commit is contained in:
@@ -317,6 +317,10 @@ public class DeviceController extends BaseController {
|
|||||||
data.setSalinityCompensation(device.getSalinityCompensation());
|
data.setSalinityCompensation(device.getSalinityCompensation());
|
||||||
data.setInputVoltage(device.getInputVoltage());
|
data.setInputVoltage(device.getInputVoltage());
|
||||||
data.setVoltageWarnOpen(device.getVoltageWarnOpen());
|
data.setVoltageWarnOpen(device.getVoltageWarnOpen());
|
||||||
|
data.setBatteryWarnCallOpen(device.getBatteryWarnCallOpen());
|
||||||
|
data.setBatteryWarnCallNoDis(device.getBatteryWarnCallNoDis());
|
||||||
|
data.setBatteryWarnLower(device.getBatteryWarnLower());
|
||||||
|
|
||||||
|
|
||||||
// 设置塘口信息
|
// 设置塘口信息
|
||||||
if (device.getPondId() != null && device.getPondId() > 0) {
|
if (device.getPondId() != null && device.getPondId() > 0) {
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ public class PondController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 根据塘口ID查询设备列表
|
* 根据塘口ID查询设备列表
|
||||||
* 返回数据按设备类型分类:
|
* 返回数据按设备类型分类:
|
||||||
* - listDetector: 水质检测仪列表(deviceType=1)+ 开启溶氧检测的测控一体机(deviceType=2 && isOxygenUsed=1)
|
* - listDetector: 水质检测仪列表(deviceType=1)+ 开启溢氧检测的测控一体机(deviceType=2 && isOxygenUsed=1)+ 太阳能网控(deviceType=3)
|
||||||
* - listController: 测控一体机列表(deviceType=2),包含开关列表
|
* - listController: 测控一体机列表(deviceType=2),包含开关列表
|
||||||
*
|
*
|
||||||
* @param pondId 塘口ID
|
* @param pondId 塘口ID
|
||||||
@@ -294,10 +294,11 @@ public class PondController extends BaseController {
|
|||||||
// 9. 处理探测器列表(严格从 pondDevices 取,与 C# pond.ListDevice 保持一致,不包含仅开关挂塘口的设备)
|
// 9. 处理探测器列表(严格从 pondDevices 取,与 C# pond.ListDevice 保持一致,不包含仅开关挂塘口的设备)
|
||||||
List<DeviceVo> detectorList = new ArrayList<>();
|
List<DeviceVo> detectorList = new ArrayList<>();
|
||||||
for (Device device : pondDevices) {
|
for (Device device : pondDevices) {
|
||||||
// 水质检测仪 或 开启溶氧检测的测控一体机
|
// 水质检测仪 或 开启溢氧检测的测控一体机 或 太阳能网控
|
||||||
if ((device.getDeviceType() != null && device.getDeviceType() == 1)
|
if ((device.getDeviceType() != null && device.getDeviceType() == 1)
|
||||||
|| (device.getDeviceType() != null && device.getDeviceType() == 2
|
|| (device.getDeviceType() != null && device.getDeviceType() == 2
|
||||||
&& device.getIsOxygenUsed() != null && device.getIsOxygenUsed() == 1)) {
|
&& device.getIsOxygenUsed() != null && device.getIsOxygenUsed() == 1)
|
||||||
|
|| (device.getDeviceType() != null && device.getDeviceType() == 3)) {
|
||||||
|
|
||||||
DeviceVo deviceVo = MapstructUtils.convert(device, DeviceVo.class);
|
DeviceVo deviceVo = MapstructUtils.convert(device, DeviceVo.class);
|
||||||
|
|
||||||
|
|||||||
@@ -238,5 +238,10 @@ public class Device extends TenantEntity {
|
|||||||
*/
|
*/
|
||||||
private Long batteryWarnLower;
|
private Long batteryWarnLower;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电量值(太阳能网控专用,0-100)
|
||||||
|
*/
|
||||||
|
private Integer valueBattery;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -306,6 +306,12 @@ public class DeviceVo implements Serializable {
|
|||||||
@ExcelProperty(value = "电量电话告警下限")
|
@ExcelProperty(value = "电量电话告警下限")
|
||||||
private Long batteryWarnLower;
|
private Long batteryWarnLower;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电量值(太阳能网控专用,0-100)
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "电量值")
|
||||||
|
private Integer valueBattery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号
|
* 手机号
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -109,6 +109,21 @@ public class PublicDeviceBaseData implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer voltageWarnOpen;
|
private Integer voltageWarnOpen;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 低电量电话告警开关(太阳能网控专用)
|
||||||
|
*/
|
||||||
|
private Long batteryWarnCallOpen;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 低电量告警免打扰(太阳能网控专用)
|
||||||
|
*/
|
||||||
|
private Long batteryWarnCallNoDis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 低电量告警下限(太阳能网控专用,0-100)
|
||||||
|
*/
|
||||||
|
private Long batteryWarnLower;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开关列表(仅测控一体机)
|
* 开关列表(仅测控一体机)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1704,15 +1704,18 @@ public class IotController extends BaseController {
|
|||||||
// 初始化警告码
|
// 初始化警告码
|
||||||
int warnCode = 0;
|
int warnCode = 0;
|
||||||
|
|
||||||
|
// 判断是否离线
|
||||||
|
boolean isOffline = status != null && "OFFLINE".equalsIgnoreCase(status);
|
||||||
|
|
||||||
// 如果设备离线,添加离线警告
|
// 如果设备离线,添加离线警告
|
||||||
if (status != null && "OFFLINE".equalsIgnoreCase(status)) {
|
if (isOffline) {
|
||||||
warnCode |= 0x0080; // 设备离线
|
warnCode |= 0x0080; // 设备离线
|
||||||
}
|
}
|
||||||
|
|
||||||
device.setWarnCode(warnCode);
|
device.setWarnCode(warnCode);
|
||||||
|
|
||||||
// 验证 ICCID 是否存在
|
// 验证 ICCID 是否存在:设备离线时属性无法读取,允许跳过,上线后会通过数据上报补全
|
||||||
if (device.getIccId() == null || device.getIccId().isEmpty()) {
|
if (!isOffline && (device.getIccId() == null || device.getIccId().isEmpty())) {
|
||||||
return R.fail("设备缺少物联网卡号(ICCID)");
|
return R.fail("设备缺少物联网卡号(ICCID)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2215,8 +2215,8 @@ public class DeviceDataHandler {
|
|||||||
: params.getDouble("phasedifference");
|
: params.getDouble("phasedifference");
|
||||||
sensorData.setPhaseDifference(value);
|
sensorData.setPhaseDifference(value);
|
||||||
}
|
}
|
||||||
if (params.containsKey("battery")) {
|
if (params.containsKey("ChargeFlag")) {
|
||||||
sensorData.setBattery(params.getDouble("battery"));
|
sensorData.setBattery(params.getDouble("ChargeFlag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 如果需要设置 deviceId、userId 等标签字段,需要从设备管理系统查询
|
// TODO: 如果需要设置 deviceId、userId 等标签字段,需要从设备管理系统查询
|
||||||
@@ -2271,6 +2271,9 @@ public class DeviceDataHandler {
|
|||||||
if (sensorData.getSalinity() != null) {
|
if (sensorData.getSalinity() != null) {
|
||||||
updateDevice.setValueSalinity(sensorData.getSalinity());
|
updateDevice.setValueSalinity(sensorData.getSalinity());
|
||||||
}
|
}
|
||||||
|
if (sensorData.getBattery() != null) {
|
||||||
|
updateDevice.setValueBattery(sensorData.getBattery().intValue());
|
||||||
|
}
|
||||||
int updated = deviceMapper.updateById(updateDevice);
|
int updated = deviceMapper.updateById(updateDevice);
|
||||||
if (updated > 0) {
|
if (updated > 0) {
|
||||||
log.debug("设备实时数据已更新: {}", deviceName);
|
log.debug("设备实时数据已更新: {}", deviceName);
|
||||||
|
|||||||
@@ -139,33 +139,36 @@ public class DeviceSensorDataService implements IDeviceSensorDataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 打印第一条数据的详细信息
|
// 按 serialNum 分组,对每个设备单独检查并确保子表存在
|
||||||
if (!dataList.isEmpty()) {
|
java.util.Map<String, DeviceSensorData> firstBySerial = new java.util.LinkedHashMap<>();
|
||||||
DeviceSensorData firstData = dataList.get(0);
|
for (DeviceSensorData data : dataList) {
|
||||||
// 检查子表是否存在(使用缓存优化)
|
String sn = data.getSerialNum();
|
||||||
String serialNum = firstData.getSerialNum();
|
if (sn != null && !sn.isEmpty() && !firstBySerial.containsKey(sn)) {
|
||||||
|
firstBySerial.put(sn, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (java.util.Map.Entry<String, DeviceSensorData> entry : firstBySerial.entrySet()) {
|
||||||
|
String serialNum = entry.getKey();
|
||||||
String tableName = "t_" + serialNum;
|
String tableName = "t_" + serialNum;
|
||||||
|
|
||||||
// 先检查缓存,避免重复查询数据库
|
|
||||||
if (!CREATED_TABLES.containsKey(serialNum)) {
|
if (!CREATED_TABLES.containsKey(serialNum)) {
|
||||||
try {
|
try {
|
||||||
Integer exists = deviceSensorDataMapper.checkTableExists(serialNum);
|
Integer exists = deviceSensorDataMapper.checkTableExists(serialNum);
|
||||||
if (exists == null || exists == 0) {
|
if (exists == null || exists == 0) {
|
||||||
deviceSensorDataMapper.createTable(firstData);
|
deviceSensorDataMapper.createTable(entry.getValue());
|
||||||
log.debug("子表 {} 已创建", tableName);
|
log.debug("子表 {} 已创建", tableName);
|
||||||
}
|
}
|
||||||
// 加入缓存
|
|
||||||
CREATED_TABLES.put(serialNum, true);
|
CREATED_TABLES.put(serialNum, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 检查表不存在是正常情况,使用 USING 语法会自动创建
|
|
||||||
String errorMsg = e.getMessage();
|
String errorMsg = e.getMessage();
|
||||||
if (errorMsg != null && errorMsg.contains("Table does not exist")) {
|
if (errorMsg != null && errorMsg.contains("Table does not exist")) {
|
||||||
log.debug("子表 {} 不存在,将自动创建", tableName);
|
log.debug("子表 {} 不存在,将自动创建", tableName);
|
||||||
} else {
|
} else {
|
||||||
log.warn("检查子表失败: {}", errorMsg != null && errorMsg.length() > 100 ? errorMsg.substring(0, 100) : errorMsg);
|
log.warn("检查子表失败[{}]: {}", tableName,
|
||||||
|
errorMsg != null && errorMsg.length() > 100 ? errorMsg.substring(0, 100) : errorMsg);
|
||||||
}
|
}
|
||||||
// 即使失败也加入缓存,避免重复尝试
|
// 建表异常时不加入缓存,下次重试
|
||||||
CREATED_TABLES.put(serialNum, true);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("子表 {} 已在缓存中", tableName);
|
log.debug("子表 {} 已在缓存中", tableName);
|
||||||
|
|||||||
Reference in New Issue
Block a user