47 lines
1.5 KiB
C#
Raw Normal View History

2025-04-21 14:20:49 +08:00
using JiShe.CollectBus.IoTDB.Model;
namespace JiShe.CollectBus.IoTDB.Provider
2025-04-02 14:06:40 +08:00
{
/// <summary>
/// 设备路径构建器
/// </summary>
public static class DevicePathBuilder
{
/// <summary>
2025-04-03 16:46:26 +08:00
/// 构建设备路径,由于路径的层级约束规范不能是纯数字字符,所以需要做特殊处理。
2025-04-02 14:06:40 +08:00
/// </summary>
/// <typeparam name="T"></typeparam>
2025-04-02 17:23:52 +08:00
/// <param name="entity"></param>
2025-04-02 14:06:40 +08:00
/// <returns></returns>
2025-04-07 16:44:25 +08:00
public static string GetDevicePath<T>(T entity) where T : IoTEntity
2025-04-02 14:06:40 +08:00
{
2025-04-21 09:45:30 +08:00
return $"root.{entity.SystemName.ToLower()}.`{entity.ProjectCode}`.`{entity.DeviceType}`.`{entity.DeviceId}`";
2025-04-02 14:06:40 +08:00
}
2025-04-02 17:23:52 +08:00
2025-04-02 14:06:40 +08:00
/// <summary>
2025-04-02 17:23:52 +08:00
/// 获取表名称
2025-04-02 14:06:40 +08:00
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity"></param>
/// <returns></returns>
2025-04-02 17:23:52 +08:00
public static string GetTableName<T>() where T : IoTEntity
2025-04-02 14:06:40 +08:00
{
2025-04-02 17:23:52 +08:00
var type = typeof(T);
2025-04-03 16:46:26 +08:00
return $"{type.Name.ToLower()}";
2025-04-02 14:06:40 +08:00
}
/// <summary>
/// 获取表名称,用作单侧点表模型特殊处理。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity"></param>
/// <returns></returns>
public static string GetDeviceTableName<T>(T entity) where T : IoTEntity
{
return $"{entity.SystemName.ToLower()}.`{entity.ProjectCode}`.`{entity.DeviceType}`.`{entity.DeviceId}`";
}
2025-04-02 14:06:40 +08:00
}
}