20260329:网关计算物模型无法找到对应设备bug修复(模板改回来)

This commit is contained in:
George 2026-03-29 15:46:02 +08:00
parent 3f3d14f492
commit 60cb958daa
4 changed files with 12 additions and 7 deletions

View File

@ -57,6 +57,7 @@ public class RedisKeyBuilder {
/** /**
* 物模型缓存key(产品级) * 物模型缓存key(产品级)
* 物模型命名空间:Key:TSL:{productId} hkey: identity value: thingsModel * 物模型命名空间:Key:TSL:{productId} hkey: identity value: thingsModel
* TSL:222
*/ */
public static String buildTSLCacheKey(Long productId) { public static String buildTSLCacheKey(Long productId) {
return FastBeeConstant.REDIS.TSL_PRE_KEY + productId; return FastBeeConstant.REDIS.TSL_PRE_KEY + productId;
@ -65,6 +66,7 @@ public class RedisKeyBuilder {
/** /**
* 设备级计算物模型缓存key * 设备级计算物模型缓存key
* 物模型命名空间:Key:TSLD:{SerialNumber} hkey: identity value: thingsModel * 物模型命名空间:Key:TSLD:{SerialNumber} hkey: identity value: thingsModel
* TSLD:D199Y030XTSQ
*/ */
public static String buildDeviceTSLCacheKey(String serialNumber) { public static String buildDeviceTSLCacheKey(String serialNumber) {
return FastBeeConstant.REDIS.TSLD_PRE_KEY + serialNumber; return FastBeeConstant.REDIS.TSLD_PRE_KEY + serialNumber;

View File

@ -206,12 +206,12 @@ public class ThingsModelPushHandler {
List<String> varNames = extractVarNames(msgParams.getContent()); List<String> varNames = extractVarNames(msgParams.getContent());
Map<String, String> map = new LinkedHashMap<>(); Map<String, String> map = new LinkedHashMap<>();
String deviceDisplay = StringUtils.isNotEmpty(config.getDeviceName()) // String deviceDisplay = StringUtils.isNotEmpty(config.getDeviceName())
? config.getDeviceName() : serialNumber; // ? config.getDeviceName() : serialNumber;
for (int i = 0; i < varNames.size(); i++) { for (int i = 0; i < varNames.size(); i++) {
String varName = varNames.get(i); String varName = varNames.get(i);
if (i == 0) { if (i == 0) {
map.put(varName, deviceDisplay); map.put(varName, serialNumber);
} else if (i == 1) { } else if (i == 1) {
map.put(varName, level.getLabel()); map.put(varName, level.getLabel());
} else if (i == 2) { } else if (i == 2) {

View File

@ -36,6 +36,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
@ -107,7 +108,8 @@ public class ModbusProtocol implements IProtocol {
//起始地址 //起始地址
String address0304 = getCacheModbusAddress(productId, slaveId, code); String address0304 = getCacheModbusAddress(productId, slaveId, code);
//读输入、保持寄存器 //读输入、保持寄存器
handleRead0304(deviceData.getSerialNumber(), productId, message, address0304, values, hexDump); String sn = StringUtils.isEmpty(serialNumber) ? deviceData.getSerialNumber() : serialNumber;
handleRead0304(sn, productId, message, address0304, values, hexDump);
break; break;
case Write06: case Write06:
case Write05: case Write05:
@ -186,7 +188,7 @@ public class ModbusProtocol implements IProtocol {
/** /**
* 处理读保持寄存器/输入寄存器 * 处理读保持寄存器/输入寄存器
* *
* @param serialNumber 设备序列号 * @param serialNumber 设备序列号(如果是网关设备会找到自身的子设备ID)
* @param productId 产品id * @param productId 产品id
* @param message 数据 * @param message 数据
* @param address 起始地址 * @param address 起始地址
@ -330,13 +332,14 @@ public class ModbusProtocol implements IProtocol {
Map<String, ThingsModelValueItem> calculatedModelMap = itslCache.getDeviceCalculatedModelMap(serialNumber); Map<String, ThingsModelValueItem> calculatedModelMap = itslCache.getDeviceCalculatedModelMap(serialNumber);
// 构造 ThingsModelSimpleItem,值为 "0" // 构造 ThingsModelSimpleItem,值为 "0"
Date nowDate = DateUtils.getNowDate(); // 统一当前时间
for (Map.Entry<String, ThingsModelValueItem> entry : calculatedModelMap.entrySet()) { for (Map.Entry<String, ThingsModelValueItem> entry : calculatedModelMap.entrySet()) {
String identifier = entry.getKey(); String identifier = entry.getKey();
ThingsModelSimpleItem simpleItem = new ThingsModelSimpleItem(); ThingsModelSimpleItem simpleItem = new ThingsModelSimpleItem();
simpleItem.setId(identifier); simpleItem.setId(identifier);
simpleItem.setValue("0"); // 初始值设为0,后续在计算环节会重新计算 simpleItem.setValue("0"); // 初始值设为0,后续在计算环节会重新计算
simpleItem.setTs(DateUtils.getNowDate()); simpleItem.setTs(nowDate);
simpleItem.setCalculated(true); simpleItem.setCalculated(true);
simpleItemList.add(simpleItem); simpleItemList.add(simpleItem);
log.debug("=>添加纯计算物模型到上报列表,设备:[{}],标识符:[{}]", serialNumber, identifier); log.debug("=>添加纯计算物模型到上报列表,设备:[{}],标识符:[{}]", serialNumber, identifier);

View File

@ -1639,7 +1639,7 @@ public class DeviceServiceImpl implements IDeviceService {
ILocationService service = locationServiceFactory.getLocationService(); ILocationService service = locationServiceFactory.getLocationService();
// Modbus设备采用LBS定位(从设备获取经纬度) // Modbus设备采用LBS定位(从设备获取经纬度)
if (Objects.equals(1, device.getLocationWay()) && FastBeeConstant.PROTOCOL.ModbusRtu.equals(device.getTransport())) { if (/*Objects.equals(1, device.getLocationWay()) && */FastBeeConstant.PROTOCOL.ModbusRtu.equals(device.getTransport())) {
log.info("Modbus设备采用LBS定位{}", device.getSerialNumber()); log.info("Modbus设备采用LBS定位{}", device.getSerialNumber());
// 将经纬度转换为地址编码 networkAddress // 将经纬度转换为地址编码 networkAddress
if (StringUtils.isEmpty(device.getNetworkAddress()) && device.getLongitude() != null && device.getLatitude() != null) { if (StringUtils.isEmpty(device.getNetworkAddress()) && device.getLongitude() != null && device.getLatitude() != null) {