跳到主要内容

SqlDBProducer

一、说明

SqlDBProducer适配关系数据库,可以定时/变化存储变量数据,也可以实时更新数据到实时表

通道只支持 Other

二、插件属性配置项

属性说明备注
启用实时表开启实时更新数据功能
启用历史表开始历史存储功能true
实时表名称实时表名称
历史表名称历史表名称
数据库类型数据库类型
链接字符串链接字符串server=.;uid=sa;pwd=111111;database=test;
实时表定时上传间隔实时表定时上传间隔
分组上传启用后,无论是定时还是变化模式,始终会上传变量分组属性为key分组的全部变量 。在变化模式时,每次变量变化都会触发一次组上传False
是否选择全部变量是否选择全部变量,true时不需要单个变量添加业务属性
上传模式间隔/变化/变化和间隔同时生效
定时上传间隔间隔执行时间
启用缓存是否启用缓存
缓存文件最大长度(mb)缓存文件最大长度
上传每页条数每一次上传的列表最大数量
内存队列最大数量内存队列的最大数量,超出或失败时转入文件缓存,根据数据量设定适当值
历史库动态脚本历史库动态脚本
实时库动态脚本实时库动态脚本

三、脚本与实体

3.1、脚本接口

查看脚本接口

3.2、实时库动态脚本方法传入参数实体类

/// <summary>
/// 变量业务变化数据
/// </summary>
public class VariableBasicData
{

/// <inheritdoc cref="PrimaryIdEntity.Id"/>
public long Id { get; set; }

/// <inheritdoc cref="Variable.Name"/>
public string Name { get; set; }

/// <inheritdoc cref="Variable.CollectGroup"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string CollectGroup { get; set; }

/// <inheritdoc cref="Variable.BusinessGroup"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string BusinessGroup { get; set; }

/// <inheritdoc cref="Variable.BusinessGroupUpdateTrigger"/>
public bool BusinessGroupUpdateTrigger { get; set; }

/// <inheritdoc cref="VariableRuntime.DeviceName"/>
public string DeviceName { get; set; }

/// <inheritdoc cref="VariableRuntime.RuntimeType"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string RuntimeType { get; set; }

[JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public bool IsNumber => Value?.GetType()?.IsNumber() == true;

/// <inheritdoc cref="VariableRuntime.Value"/>
public object Value { get; set; }
/// <inheritdoc cref="VariableRuntime.RawValue"/>
public object RawValue { get; set; }
/// <inheritdoc cref="VariableRuntime.LastSetValue"/>
public object LastSetValue { get; set; }

/// <inheritdoc cref="VariableRuntime.ChangeTime"/>
public DateTime ChangeTime { get; set; }

/// <inheritdoc cref="VariableRuntime.CollectTime"/>
public DateTime CollectTime { get; set; }

/// <inheritdoc cref="VariableRuntime.IsOnline"/>
public bool IsOnline { get; set; }

///// <inheritdoc cref="VariableRuntime.DeviceRuntime"/>
//[System.Text.Json.Serialization.JsonIgnore]
//[Newtonsoft.Json.JsonIgnore]
//public DeviceBasicData DeviceRuntime { get; set; }
/// <inheritdoc cref="Variable.DeviceId"/>
public long DeviceId { get; set; }
/// <inheritdoc cref="VariableRuntime.LastErrorMessage"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string? LastErrorMessage { get; set; }
/// <inheritdoc cref="Variable.RegisterAddress"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string? RegisterAddress { get; set; }

/// <inheritdoc cref="Variable.Unit"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string? Unit { get; set; }

/// <inheritdoc cref="Variable.Description"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string? Description { get; set; }

/// <inheritdoc cref="Variable.ProtectType"/>
public ProtectTypeEnum ProtectType { get; set; }

/// <inheritdoc cref="Variable.DataType"/>
public DataTypeEnum DataType { get; set; }

/// <inheritdoc cref="Device.Remark1"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string Remark1 { get; set; }

/// <inheritdoc cref="Device.Remark2"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string Remark2 { get; set; }

/// <inheritdoc cref="Device.Remark3"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string Remark3 { get; set; }

/// <inheritdoc cref="Device.Remark4"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string Remark4 { get; set; }

/// <inheritdoc cref="Device.Remark5"/>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
public string Remark5 { get; set; }
}


3.3、历史库动态脚本方法传入参数实体类

查看参数实体类