[UI.Client]

删除选择查询,使用全部查询功能
[RT.EquipmentLibrary]
1删除旧的查询功能
2重写数据库查询语句
This commit is contained in:
hanqiangqiang 2023-08-10 16:18:48 +08:00
parent 8f0f96fd33
commit b80a24f978
5 changed files with 168 additions and 267 deletions

View File

@ -30,7 +30,6 @@ namespace MECF.Framework.Common.Aitex.Core.Common.DeviceData
set
{
_runVolume = value;
Volume = _runVolume + _ventVolume;
InvokePropertyChanged();
}
}
@ -46,7 +45,6 @@ namespace MECF.Framework.Common.Aitex.Core.Common.DeviceData
set
{
_ventVolume = value;
Volume = _runVolume + _ventVolume;
InvokePropertyChanged();
}
}

View File

@ -1,5 +1,7 @@
using Aitex.Core.RT.DBCore;
using MECF.Framework.Common.Aitex.Core.Common.DeviceData;
using MECF.Framework.Common.DataCenter;
using MECF.Framework.Common.Equipment;
using Sicentury.Core;
using System;
using System.Collections.Generic;
@ -15,64 +17,133 @@ namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
/// </summary>
public class GasFlowSqlHelp
{
/// <summary>
/// 根据名称和时间段查询结果
/// 查询当天的气体体积数据
/// </summary>
/// <param name="module">模块名称</param>
/// <param name="name"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="daySlices">拆分的天</param>
/// <param name="moduleName">PM名称</param>
/// <param name="gasFlowSumList">显示列表对象</param>
/// <returns></returns>
public static double Query(string module, string name, DateTime start, DateTime end)
public static List<GasFlowSum> GetDayGasFlowSum(DateRangeHelper daySlices, string moduleName, List<GasFlowSum> gasFlowSumList)
{
var daySlices = DateRangeHelper.SplitInToHours(new DateRangeHelper(start, end), 12);
string tableName = module;
string propertyCmd = "," + $"\"{module}.{name}.FeedBack\"";
string property = $"{module}.{name}.FeedBack";
List<DataTable> dataTableList = GetAllGasListDaySlices(daySlices, moduleName, gasFlowSumList);
return GetData(GetDataSetList(daySlices, tableName, propertyCmd, property), property);
}
private static List<DataTable> GetDataSetList(IEnumerable<DateRangeHelper> daySlices, string tableName, string propertyCmd, string property)
{
List<DataTable> dataTableList = new List<DataTable>();
foreach (var range in daySlices)
string rowStr;
List<GasFlowSum> GasFlowrRunVentList = new List<GasFlowSum>();
foreach (var item in gasFlowSumList)
{
var ts = range.Diff;
for (var day = 0; day <= ts.Days; day++)
GasFlowrRunVentList.Add(new GasFlowSum() { Name = $"{item.Name}_Run" });
GasFlowrRunVentList.Add(new GasFlowSum() { Name = $"{item.Name}_Vent" });
}
foreach (var table in dataTableList) { }
foreach (DataTable ds in dataTableList)
{
double timeDifference = 0;
for (int i = 0; i < ds.Rows.Count; i++)
{
var tblName = $"{range.Start.AddDays(day):yyyyMMdd}.{tableName}";
var sql = new StringBuilder();
// 检查表名是否存在否则SQL执行出错。
if (CheckTableExists(tblName))
foreach (var item in GasFlowrRunVentList)
{
sql.Append("select time AS InternalTimeStamp");
// 添加待查询的列
sql.Append(propertyCmd);
sql.Append($", \"time\"");
sql.Append($" from \"{tblName}\"");
if (day < ts.Days)
sql.Append(" UNION ");
sql.Append(
$" where time between {range.Start.Ticks} and {range.End.Ticks} and '{property}' is not NULL order by InternalTimeStamp asc");
try
{
var dataSet = QueryDataClient.Instance.Service.QueryData(sql.ToString());
if (dataSet is not null && dataSet.Rows.Count > 0)
dataTableList.Add(dataSet);
}
catch (Exception ex)//查询较早日期时,可能不存在属性会报错
//$"{moduleName}.GasRealTimeFlow.{item.Name}_Run.FeedBack"
string property = $"{moduleName}.GasRealTimeFlow.{item.Name}.FeedBack";
rowStr = ds.Rows[i][property].ToString();
if (rowStr is not null && rowStr.Length == 0)
continue;
double bd = double.Parse(ds.Rows[i][property].ToString());
if (bd > 0)
{
if (i != ds.Rows.Count - 1)//最后一个数据使用的时间差,是它前一个计算得到的
{
var startTime = new DateTime(long.Parse(ds.Rows[i]["time"].ToString()));
var endTime = new DateTime(long.Parse(ds.Rows[i + 1]["time"].ToString()));
timeDifference = (endTime - startTime).TotalSeconds;
}
item.Volume += bd * timeDifference;
}
}
}
}
return GasFlowrRunVentList;
}
/// <summary>
/// 根据拆分的天循查询数据
/// </summary>
/// <param name="daySlices">拆分的天</param>
/// <param name="moduleName">PM名称</param>
/// <param name="gasFlowSumList">显示集合列表</param>
/// <returns></returns>
private static List<DataTable> GetAllGasListDaySlices(DateRangeHelper daySlices, string moduleName, List<GasFlowSum> gasFlowSumList)
{
List<DataTable> dataTableList = new List<DataTable>();
var ts = daySlices.Diff;
for (var day = 0; day <= ts.Days; day++)
{
var tblName = $"{daySlices.Start.AddDays(day):yyyyMMdd}.{moduleName}";
var sql = new StringBuilder();
// 检查表名是否存在否则SQL执行出错。
if (CheckTableExists(tblName))
{
sql.Append("select time AS InternalTimeStamp");
// 添加待查询的列
// 添加待查询的列
foreach (var item in gasFlowSumList)
{
sql.Append("," + $"\"{moduleName}.GasRealTimeFlow.{item.Name}_Run.FeedBack\"");
sql.Append("," + $"\"{moduleName}.GasRealTimeFlow.{item.Name}_Vent.FeedBack\"");
}
sql.Append($", \"time\"");
sql.Append($" from \"{tblName}\"");
if (day < ts.Days)
sql.Append(" UNION ");
sql.Append(
$" where time between {daySlices.Start.Ticks} and {daySlices.End.Ticks} order by InternalTimeStamp asc");
try
{
var dataSet = QueryDataClient.Instance.Service.QueryData(sql.ToString());
if (dataSet is not null && dataSet.Rows.Count > 0)
dataTableList.Add(dataSet);
}
catch (Exception ex)//查询较早日期时,可能不存在属性会报错
{
}
}
}
return dataTableList;
}
public static List<DataTable> GetDataSetListDaySlices(DateRangeHelper daySlices, string tableName, string propertyCmd, string property)
private static bool CheckTableExists(string tableName)
{
var sql =
$"SELECT EXISTS ( SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = '{tableName}' )";
var table = QueryDataClient.Instance.Service.QueryData(sql);
if (table == null)
return false;
if (table.Rows.Count <= 0)
return false;
var value = table.Rows[0]["exists"].ToString();
if (value.ToLower() == "true")
return true;
return false;
}
public static List<DataTable> GetDataSetDaySlices(DateRangeHelper daySlices, string tableName, string propertyCmd, string property)
{
List<DataTable> dataTableList = new List<DataTable>();
var ts = daySlices.Diff;
@ -109,6 +180,9 @@ namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
return dataTableList;
}
public static double GetData(List<DataTable> dataTableList, string property)
{
double values = 0;
@ -138,22 +212,6 @@ namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
return values;
}
private static bool CheckTableExists(string tableName)
{
var sql =
$"SELECT EXISTS ( SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = '{tableName}' )";
var table = QueryDataClient.Instance.Service.QueryData(sql);
if (table == null)
return false;
if (table.Rows.Count <= 0)
return false;
var value = table.Rows[0]["exists"].ToString();
if (value.ToLower() == "true")
return true;
return false;
}
}
}

View File

@ -33,17 +33,12 @@ namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
DATA.Subscribe($"{ModuleName}.PMGasNameList", () => GasNameList);
DATA.Subscribe($"{ModuleName}.PMGasFlowSumList", () => GasFlowSumList);
OP.Subscribe($"{ModuleName}.GasFlowSum.Query", (string cmd, object[] args) => Query(args));
OP.Subscribe($"{ModuleName}.GasFlowSum.QueryAll", (string cmd, object[] args) => QueryAll(args));
var _thread = new PeriodicJob(1000, OnTimer, $"{moduleName}.ModuleGsaFlow", true);
}
private bool OnTimer()
{
foreach (var Unit in GasFlowUnitList)
foreach (GasFlowUnit Unit in GasFlowUnitList)
{
Unit.GetGasFlowFeedBack();
}
@ -62,7 +57,7 @@ namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
GasNameList = new() { "All" };//添加总的查询选项
//单气体初始化
//单气体初始化
foreach (var unit in GasFlowUnitList)
{
unit.Initialize(moduleName);
@ -79,70 +74,5 @@ namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
}
}
/// <summary>
/// 单种气体体积使用查询
/// </summary>
/// <param name="objects"></param>
/// <returns></returns>
private bool Query(object[] objects)
{
Task.Run(() =>
{
string flowName = objects[0].ToString();
start = Convert.ToDateTime(objects[1]);
end = Convert.ToDateTime(objects[2]);
QueryRunVentVolume(flowName + "_Run");
QueryRunVentVolume(flowName + "_Vent");
});
return true;
}
/// <summary>
/// 所有气体使用体积查询
/// </summary>
/// <param name="objects"></param>
/// <returns></returns>
private bool QueryAll(object[] objects)
{
Task.Run(() =>
{
start = Convert.ToDateTime(objects[0]);
end = Convert.ToDateTime(objects[1]);
foreach (var item in GasFlowSumList)
{
QueryRunVentVolume(item.Name + "_Run");
QueryRunVentVolume(item.Name + "_Vent");
}
});
return true;
}
private void QueryRunVentVolume(string flowName)
{
Task.Run(() =>
{
double values = GasFlowSqlHelp.Query(ModuleName, "GasRealTimeFlow." + flowName, start, end);
foreach (var item in GasFlowSumList)
{
if (flowName.Contains(item.Name))
{
if (flowName.Contains("Run"))
item.RunVolume = values * 1.66667 * Math.Pow(10, -7);
else
item.VentVolume = values * 1.66667 * Math.Pow(10, -7);
return;
}
}
});
}
}
}

View File

@ -2000,20 +2000,18 @@
</Grid>
</TabItem>
<TabItem Header="Gas Flow History">
<TabItem Header="Gas Flow History" FontSize="12">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="89.667"/>
<ColumnDefinition Width="38.666"/>
<ColumnDefinition Width="171.667"/>
<ColumnDefinition Width="280"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.ColumnSpan="3">
<StackPanel Width="260" Margin="0,5">
<StackPanel Orientation="Vertical" >
<StackPanel Width="260" Margin="5,5">
<StackPanel.Resources>
<Style TargetType="xctk:DateTimeUpDown">
<Setter Property="Width" Value="180" />
@ -2066,19 +2064,11 @@
</StackPanel>
<StackPanel Orientation="Horizontal">
<ComboBox
Width="100"
Height="30"
Margin="25,10"
ItemsSource="{Binding GasNameList}"
SelectedItem="{Binding SelectGasName}">
</ComboBox>
<StackPanel HorizontalAlignment="Right">
<Button
Width="100"
Height="30"
Margin="10"
HorizontalAlignment="Right"
Margin="25,20"
Content="Query">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
@ -2120,19 +2110,12 @@
<GridViewColumn Width="80" Header="Name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<!--<Border Width="60"
Margin="3"
BorderThickness="1"
CornerRadius="3"
BorderBrush="#91b0cd" >
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontFamily="Bold" />
</Border>-->
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Bold" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="220" Header="Run(m³)" DisplayMemberBinding="{Binding RunVolume, StringFormat=F3}" />
<GridViewColumn Width="220" Header="Vent(m³)" DisplayMemberBinding="{Binding VentVolume, StringFormat=F3}" />
<GridViewColumn Width="230" Header="Run(m³)" DisplayMemberBinding="{Binding RunVolume, StringFormat=F3}" />
<GridViewColumn Width="230" Header="Vent(m³)" DisplayMemberBinding="{Binding VentVolume, StringFormat=F3}" />
<GridViewColumn Width="300" Header="Total(m³)" DisplayMemberBinding="{Binding Volume, StringFormat=F3}" />
</GridView>
</ListView.View>

View File

@ -51,6 +51,7 @@ namespace MECF.Framework.UI.Client.CenterViews.Modules.PM
private IProgress<int> _progressRecipeStepChanged;
private IProgress<string> _progressLoadRecipe;
private readonly object _lockerLoadingRecipe = new object();
CancellationTokenSource cts = new CancellationTokenSource();
public string title { get; set; } = "123";
@ -1657,12 +1658,7 @@ namespace MECF.Framework.UI.Client.CenterViews.Modules.PM
get => _gasNameList;
set
{
if (_gasNameList == null)
{
_gasNameList = value;
SelectGasName = _gasNameList[0];
}
//_gasNameList = value;
_gasNameList ??= value;
}
}
@ -1676,8 +1672,7 @@ namespace MECF.Framework.UI.Client.CenterViews.Modules.PM
get => _RTgasFlowSumList;
set
{
if (_RTgasFlowSumList == null)
_RTgasFlowSumList = value;
_RTgasFlowSumList ??= value;
}
}
@ -1686,21 +1681,17 @@ namespace MECF.Framework.UI.Client.CenterViews.Modules.PM
{
get
{
if (_gasFlowSumList == null)
_gasFlowSumList = _RTGasFlowSumList;
_gasFlowSumList ??= _RTGasFlowSumList;//使用真值表初始化集合
return _gasFlowSumList;
}
set
{
_gasFlowSumList = value;
NotifyOfPropertyChange(nameof(GasFlowSumList));
}
}
public string SelectGasName { get; set; }
private bool _isBusyGasFlowSum;
public bool IsBusyGasFlowSum
{
@ -1739,79 +1730,13 @@ namespace MECF.Framework.UI.Client.CenterViews.Modules.PM
}
cts = new CancellationTokenSource();
_busyIndicatorContentExport.Report(new ProgressUpdatingEventArgs(20, 100, "Exporting Start ..."));
Task.Run(() =>
Task.Run(() =>
{
if (SelectGasName == "All")
QueryGasAll();
else
QueryGas(SelectGasName);
_busyIndicatorContentExport.Report(new ProgressUpdatingEventArgs(100, 100, ""));
_busyIndicatorContentExport.Report(new ProgressUpdatingEventArgs(20, 100, "Exporting Start ..."));
Query(SystemName, StartDateTime, EndDateTime);
});
}
CancellationTokenSource cts = new CancellationTokenSource();
List<Task> QueryGasFlowTaskList = new List<Task>();
/// <summary>
/// 单种气体体积使用查询
/// </summary>
/// <param name="objects"></param>
/// <returns></returns>
private async void QueryGasTask(string flowName)
{
QueryGasFlowTaskList.Clear();
QueryGasFlowTaskList.Add(Task.Run(() =>
{
QueryRunVentVolume(flowName + "_Run");
}));
QueryGasFlowTaskList.Add(Task.Run(() =>
{
QueryRunVentVolume(flowName + "_Vent");
}));
await Task.WhenAll(QueryGasFlowTaskList.ToArray());
}
private void QueryGas(string flowName)
{
QueryRunVentVolume(flowName + "_Run");
QueryRunVentVolume(flowName + "_Vent");
}
/// <summary>
/// 所有气体使用体积查询
/// </summary>
/// <param name="objects"></param>
/// <returns></returns>
private async void QueryGasAllTask()
{
QueryGasFlowTaskList.Clear();
foreach (var item in GasFlowSumList)
{
QueryGasFlowTaskList.Add(Task.Run(() =>
{
QueryRunVentVolume(item.Name + "_Run");
}));
QueryGasFlowTaskList.Add(Task.Run(() =>
{
QueryRunVentVolume(item.Name + "_Vent");
}));
}
await Task.WhenAll(QueryGasFlowTaskList.ToArray());
}
private void QueryGasAll()
{
foreach (var item in GasFlowSumList)
{
QueryRunVentVolume(item.Name + "_Run");
QueryRunVentVolume(item.Name + "_Vent");
}
}
public void CancelQuery()
@ -1828,42 +1753,49 @@ namespace MECF.Framework.UI.Client.CenterViews.Modules.PM
});
}
public double Query(string module, string propertyName, string gasName, DateTime start, DateTime end)
public void Query(string module, DateTime start, DateTime end)
{
double values = 0;
var daySlices = DateRangeHelper.SplitInToHours(new DateRangeHelper(start, end), 12);
string tableName = module;
string propertyCmd = "," + $"\"{module}.{propertyName}.FeedBack\"";
string property = $"{module}.{propertyName}.FeedBack";
List<List<GasFlowSum>> gasFlowRunVent = new List<List<GasFlowSum>>();
//按天查询数据库单天返回数据类型为List<GasFlowSum>
foreach (var daySlice in daySlices)
{
if (cts.IsCancellationRequested)
return values;
values += GasFlowSqlHelp.GetData(GasFlowSqlHelp.GetDataSetListDaySlices(daySlice, tableName, propertyCmd, property), property);
BusyIndicatorContent = $"{daySlice}";
_busyIndicatorContentExport.Report(new ProgressUpdatingEventArgs(200, 200, $"{gasName} {daySlice}"));
return ;
gasFlowRunVent.Add( GasFlowSqlHelp.GetDayGasFlowSum(daySlice, SystemName, GasFlowSumList));
_busyIndicatorContentExport.Report(new ProgressUpdatingEventArgs(200, 200, $"{daySlice}"));
}
return values;
}
private void QueryRunVentVolume(string flowName)
{
double values = Query(SystemName, "GasRealTimeFlow." + flowName, flowName, StartDateTime, EndDateTime) * 1.66667 * Math.Pow(10, -7);
List<GasFlowSum> dayGasFlowList = _RTGasFlowSumList;
var gasFlowSum = GasFlowSumList.Where(obj => flowName.Contains(obj.Name)).First();
if (flowName.Contains("Run"))
gasFlowSum.RunVolume = values;
else
gasFlowSum.VentVolume = values;
//解析数据库返回的数据
foreach (var items in gasFlowRunVent)
{
foreach (var item in items)
{
var gasFlowSum = dayGasFlowList.Where(obj => item.Name.Contains(obj.Name)).First();
if (item.Name.Contains("Run"))
gasFlowSum.RunVolume += item.Volume;
else
gasFlowSum.VentVolume += item.Volume;
}
}
//使用公式转换单位
double baseValue= 1.66667 * Math.Pow(10, -7);
foreach (var item in dayGasFlowList)
{
item.RunVolume = item.RunVolume * baseValue;
item.VentVolume = item.VentVolume * baseValue;
item.Volume = item.RunVolume + item.VentVolume;
}
GasFlowSumList = dayGasFlowList;
_busyIndicatorContentExport.Report(new ProgressUpdatingEventArgs(100, 100, ""));
}
public void Exporting()
{
BusyIndicatorContent = "Exporting Start ...";
IsBusyGasFlowSum = true;
}
#endregion