using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Common.Helpers; namespace JiShe.CollectBus.IoTDB.Options { /// /// 查询条件 /// public class QueryCondition { /// /// 字段 /// public string Field { get; set; } /// /// 操作符,>,=,< /// public string Operator { get; set; } /// /// 是否数值,如果是数值,则进行数值比较,否则进行字符串比较 /// public bool IsNumber { get; set; } = false; private object _rawValue; /// /// 值 /// public object Value { get => ApplyValueConversion(_rawValue); set => _rawValue = value; } /// /// 值转换 /// /// /// private object ApplyValueConversion(object rawValue) { string declaredTypeName = rawValue.GetType().Name; Func converter = GetQueryConditionValue(declaredTypeName); return converter(rawValue); } /// /// 查询条件值转换委托 /// /// /// private Func GetQueryConditionValue(string declaredTypeName) { return declaredTypeName?.ToUpper() switch { "DATETIME" => v => v != null ? ((DateTime)v).ToUniversalTime().Ticks : null, "BOOLEAN" => v => v != null && (bool)v ? 1 : 0, "STRING" => v => v != null ? $"'{v}'" : "''", _ => v => v }; } } }