|
|
@@ -14,7 +14,6 @@ using YSAI.Model.@enum;
|
|
|
using YSAI.Model.@interface;
|
|
|
using YSAI.Model.tool;
|
|
|
using YSAI.Unility;
|
|
|
-using static YSAI.DB.DBData;
|
|
|
|
|
|
namespace YSAI.DB
|
|
|
{
|
|
|
@@ -456,48 +455,27 @@ namespace YSAI.DB
|
|
|
/// <param name="Data"></param>
|
|
|
/// <param name="Columns"></param>
|
|
|
/// <returns></returns>
|
|
|
- private List<ConcurrentDictionary<string, AddressValue>> Analysis(JArray Data, List<string> Columns, AddressDetails addressDetails)
|
|
|
+ private ConcurrentDictionary<string, AddressValue> Analysis(AddressDetails addressDetails, JArray? Data = null)
|
|
|
{
|
|
|
+ ConcurrentDictionary<string, AddressValue> retData = new ConcurrentDictionary<string, AddressValue>();
|
|
|
+
|
|
|
+ //值
|
|
|
+ object? value = Data != null ? Data.ToJson() : null;
|
|
|
+
|
|
|
//判断是不是虚拟点
|
|
|
if (VAM.IsVirtualAddress(addressDetails))
|
|
|
{
|
|
|
- List<ConcurrentDictionary<string, AddressValue>> retDatas = new List<ConcurrentDictionary<string, AddressValue>>();
|
|
|
- ConcurrentDictionary<string, AddressValue> retData = new ConcurrentDictionary<string, AddressValue>();
|
|
|
//值
|
|
|
- object? value = VAM.Read(addressDetails);
|
|
|
-
|
|
|
- //处理
|
|
|
- AddressValue? addressValue = YSAI.Core.handler.AddressHandler.ExecuteDispose(addressDetails, value);
|
|
|
-
|
|
|
- //添加进字典
|
|
|
- retData.AddOrUpdate(addressDetails.AddressName, addressValue, (k, v) => addressValue);
|
|
|
-
|
|
|
- //添加到字典集合
|
|
|
- retDatas.Add(retData);
|
|
|
-
|
|
|
- return retDatas; //组织好数据返回
|
|
|
+ value = VAM.Read(addressDetails);
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- List<ConcurrentDictionary<string, AddressValue>> retDatas = new List<ConcurrentDictionary<string, AddressValue>>();
|
|
|
- foreach (var item in Data)
|
|
|
- {
|
|
|
- ConcurrentDictionary<string, AddressValue> retData = new ConcurrentDictionary<string, AddressValue>();
|
|
|
- foreach (var column in Columns)
|
|
|
- {
|
|
|
- //值
|
|
|
- object? value = Convert.ToString(item[column]);
|
|
|
|
|
|
- //处理
|
|
|
- AddressValue? addressValue = YSAI.Core.handler.AddressHandler.ExecuteDispose(addressDetails, value);
|
|
|
+ //处理
|
|
|
+ AddressValue? addressValue = YSAI.Core.handler.AddressHandler.ExecuteDispose(addressDetails, value);
|
|
|
|
|
|
- //添加进字典 哪个表的哪个字段 值
|
|
|
- retData.AddOrUpdate(column, addressValue, (k, v) => addressValue);
|
|
|
- }
|
|
|
- retDatas.Add(retData);
|
|
|
- }
|
|
|
- return retDatas; //组织好数据返回
|
|
|
- }
|
|
|
+ //添加进字典
|
|
|
+ retData.AddOrUpdate(addressDetails.AddressName, addressValue, (k, v) => addressValue);
|
|
|
+
|
|
|
+ return retData;
|
|
|
}
|
|
|
|
|
|
#region 同步队列形式执行SQL,确保执行此sql在此程序中是唯一执行
|
|
|
@@ -656,13 +634,23 @@ namespace YSAI.DB
|
|
|
{
|
|
|
//开始记录运行时间
|
|
|
string SN = Depart("Read");
|
|
|
+ if (!GetStatus().State)
|
|
|
+ {
|
|
|
+ return Break(SN, false, "未连接");
|
|
|
+ }
|
|
|
try
|
|
|
{
|
|
|
+ //失败信息
|
|
|
+ List<string> FailMessage = new List<string>();
|
|
|
List<ConcurrentDictionary<string, AddressValue>> RetData = new List<ConcurrentDictionary<string, AddressValue>>();
|
|
|
foreach (var item in address.AddressArray)
|
|
|
{
|
|
|
if (!item.IsEnable) continue;
|
|
|
-
|
|
|
+ if (string.IsNullOrWhiteSpace(item.AddressName))
|
|
|
+ {
|
|
|
+ FailMessage.Add("[ AddressName ] 不能为空,DB操作时此属性为SQL语句");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
//是不是虚拟地址
|
|
|
bool IsVA = false;
|
|
|
//初始化虚拟地址
|
|
|
@@ -670,19 +658,13 @@ namespace YSAI.DB
|
|
|
|
|
|
if (IsVA)
|
|
|
{
|
|
|
- RetData.AddRange(Analysis(null, null, item));
|
|
|
+ RetData.Add(Analysis(item));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- ExtendParam.Read read = item.AddressExtendParam as ExtendParam.Read;
|
|
|
- if (read == null)
|
|
|
- {
|
|
|
- read = JsonTool.StringToJsonEntity<ExtendParam.Read>(item.AddressExtendParam.ToString());
|
|
|
- }
|
|
|
- //列名
|
|
|
- List<string> ColumnName = read.ColumnName;
|
|
|
//组织sql
|
|
|
- string sql = (item.AddressExtendParam as ExtendParam.Read).Sql;
|
|
|
+ string sql = item.AddressName;
|
|
|
+
|
|
|
//查询结果对象
|
|
|
object obj = null;
|
|
|
try
|
|
|
@@ -699,20 +681,27 @@ namespace YSAI.DB
|
|
|
}
|
|
|
if (obj == null) //查询结果为空
|
|
|
{
|
|
|
- return Break(SN, false, "查询结果为空");
|
|
|
+ FailMessage.Add($"[ {item.AddressName} ] 查询结果为空");
|
|
|
}
|
|
|
|
|
|
- RetData.AddRange(Analysis(JArray.FromObject(obj), ColumnName, item));
|
|
|
+ RetData.Add(Analysis(item, JArray.FromObject(obj)));
|
|
|
}
|
|
|
}
|
|
|
- if (RetData.Count > 0)
|
|
|
+ if (FailMessage.Count > 0)
|
|
|
{
|
|
|
- //返回数据
|
|
|
- return Break(SN, true, RData: RetData, RType: ResultType.KeyValueArray);
|
|
|
+ return Break(SN, false, $"存在 {FailMessage.Count} 失败信息", FailMessage, ResultType.Object);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Break(SN, false, "查询结果为空");
|
|
|
+ if (RetData.Count > 0)
|
|
|
+ {
|
|
|
+ //返回数据
|
|
|
+ return Break(SN, true, RData: RetData, RType: ResultType.KeyValueArray);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break(SN, false, "查询结果为空");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -729,6 +718,10 @@ namespace YSAI.DB
|
|
|
public OperateResult Subscribe(Address address)
|
|
|
{
|
|
|
string SN = Depart("Subscribe");
|
|
|
+ if (!GetStatus().State)
|
|
|
+ {
|
|
|
+ return Break(SN, false, "未连接");
|
|
|
+ }
|
|
|
try
|
|
|
{
|
|
|
if (subscribeOperate == null)
|
|
|
@@ -768,6 +761,10 @@ namespace YSAI.DB
|
|
|
public OperateResult UnSubscribe(Address address)
|
|
|
{
|
|
|
string SN = Depart("UnSubscribe");
|
|
|
+ if (!GetStatus().State)
|
|
|
+ {
|
|
|
+ return Break(SN, false, "未连接");
|
|
|
+ }
|
|
|
try
|
|
|
{
|
|
|
if (subscribeOperate != null)
|
|
|
@@ -815,10 +812,14 @@ namespace YSAI.DB
|
|
|
{
|
|
|
return Task.Run(() => On());
|
|
|
}
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 连接状态
|
|
|
+ /// </summary>
|
|
|
+ private bool ConnectionStatus = false;
|
|
|
public OperateResult On()
|
|
|
{
|
|
|
- return Break(Depart("On"), true);
|
|
|
+ ConnectionStatus = true;
|
|
|
+ return Break(Depart("On"), ConnectionStatus);
|
|
|
}
|
|
|
|
|
|
public Task<OperateResult> OffAsync()
|
|
|
@@ -829,6 +830,10 @@ namespace YSAI.DB
|
|
|
public OperateResult Off()
|
|
|
{
|
|
|
string SN = Depart("Off");
|
|
|
+ if (!GetStatus().State)
|
|
|
+ {
|
|
|
+ return Break(SN, false, "未连接");
|
|
|
+ }
|
|
|
if (subscribeOperate != null)
|
|
|
{
|
|
|
OperateResult operateResult = subscribeOperate.Off();
|
|
|
@@ -838,12 +843,13 @@ namespace YSAI.DB
|
|
|
}
|
|
|
subscribeOperate = null;
|
|
|
}
|
|
|
+ ConnectionStatus = false;
|
|
|
return Break(SN, true);
|
|
|
}
|
|
|
|
|
|
public OperateResult GetStatus()
|
|
|
{
|
|
|
- return Break(Depart("GetStatus"), true, "已连接", OutputLog: false);
|
|
|
+ return Break(Depart("GetStatus"), ConnectionStatus, ConnectionStatus ? "已连接" : "未连接", OutputLog: false);
|
|
|
}
|
|
|
|
|
|
public Task<OperateResult> GetStatusAsync()
|