feat: 优化初始化缓存及控件功能
This commit is contained in:
@@ -926,7 +926,15 @@ namespace Lskj.Business.Impl
|
||||
{
|
||||
string field = string.Empty;
|
||||
|
||||
DataTable dataTable = GetTableColumns("p_systembillsourcecond");
|
||||
DataTable dataTable;
|
||||
try
|
||||
{
|
||||
dataTable = InitialParamCache.GetTableColumns("p_systembillsourcecond", delegate { return GetTableColumns("p_systembillsourcecond"); });
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
dataTable = GetTableColumns("p_systembillsourcecond");
|
||||
}
|
||||
|
||||
if (dataTable.Columns.Contains("FontSize"))
|
||||
{
|
||||
@@ -1015,6 +1023,7 @@ namespace Lskj.Business.Impl
|
||||
/// <exception cref="System.NotImplementedException"></exception>
|
||||
public static DataTable GetSchemesList(int moduleId)
|
||||
{
|
||||
if (moduleId <= 0) return new DataTable();
|
||||
try
|
||||
{
|
||||
string sqlValue = "select * from P_SystemReportProjectTab where ProjectMode=1 and operatorId=@userid and ModuleId=@moduleId";
|
||||
@@ -1141,7 +1150,16 @@ namespace Lskj.Business.Impl
|
||||
switch (type)
|
||||
{
|
||||
case ModuleType.MrpClickBtn:
|
||||
if (BaseImpl.HasExistsColumn("P_systempopupmenu", "isMrpClickBtn", "int"))
|
||||
bool isMrpClickBtnExists;
|
||||
try
|
||||
{
|
||||
isMrpClickBtnExists = InitialParamCache.GetColumnExists("P_systempopupmenu", "isMrpClickBtn", "int", delegate { return BaseImpl.HasExistsColumn("P_systempopupmenu", "isMrpClickBtn", "int"); });
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
isMrpClickBtnExists = BaseImpl.HasExistsColumn("P_systempopupmenu", "isMrpClickBtn", "int");
|
||||
}
|
||||
if (isMrpClickBtnExists)
|
||||
{
|
||||
where = " and isnull(isMrpClickBtn,0)=1 and visible1=0 ";
|
||||
}
|
||||
@@ -1563,7 +1581,19 @@ namespace Lskj.Business.Impl
|
||||
//保存条件表
|
||||
public static DataTable GetClientCond(string MenuCode)
|
||||
{
|
||||
if (BaseImpl.HasExistsTable("P_SystemClientCondTab"))
|
||||
const string tableName = "P_SystemClientCondTab";
|
||||
bool tableExists;
|
||||
try
|
||||
{
|
||||
tableExists = InitialParamCache.GetTableExists(tableName, delegate { return BaseImpl.HasExistsTable(tableName); });
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 缓存未能正常读取或记录时,重新查询,避免影响原有功能。
|
||||
tableExists = BaseImpl.HasExistsTable(tableName);
|
||||
}
|
||||
|
||||
if (tableExists)
|
||||
{
|
||||
string sqlValue = string.Format(@"select * from P_SystemClientCondTab where tab='{0}' and disableflag=0 order by orderid ", MenuCode);
|
||||
return GetDataTableResult(sqlValue);
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace Lskj.Business.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// 单次模块初始化期间复用的参数缓存。
|
||||
/// </summary>
|
||||
public static class InitialParamCache
|
||||
{
|
||||
private static readonly object SyncRoot = new object();
|
||||
private static readonly Dictionary<string, bool> TableExistsCache =
|
||||
new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly Dictionary<string, bool> ColumnExistsCache =
|
||||
new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly Dictionary<string, DataTable> TableColumnsCache =
|
||||
new Dictionary<string, DataTable>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// 获取表是否存在。没有缓存时执行查询,并记录查询结果。
|
||||
/// </summary>
|
||||
public static bool GetTableExists(string tableName, Func<bool> query)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(tableName))
|
||||
{
|
||||
throw new ArgumentException("表名不能为空。", "tableName");
|
||||
}
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
lock (SyncRoot)
|
||||
{
|
||||
bool tableExists;
|
||||
if (TableExistsCache.TryGetValue(tableName, out tableExists))
|
||||
{
|
||||
return tableExists;
|
||||
}
|
||||
|
||||
tableExists = query();
|
||||
TableExistsCache[tableName] = tableExists;
|
||||
return tableExists;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字段是否存在。没有缓存时执行查询,并记录查询结果。
|
||||
/// </summary>
|
||||
public static bool GetColumnExists(string tableName, string columnName, string columnType, Func<bool> query)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(tableName))
|
||||
{
|
||||
throw new ArgumentException("表名不能为空。", "tableName");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(columnName))
|
||||
{
|
||||
throw new ArgumentException("字段名不能为空。", "columnName");
|
||||
}
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
string cacheKey = tableName + "|" + columnName + "|" + (columnType ?? string.Empty);
|
||||
lock (SyncRoot)
|
||||
{
|
||||
bool columnExists;
|
||||
if (ColumnExistsCache.TryGetValue(cacheKey, out columnExists))
|
||||
{
|
||||
return columnExists;
|
||||
}
|
||||
|
||||
columnExists = query();
|
||||
ColumnExistsCache[cacheKey] = columnExists;
|
||||
return columnExists;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表结构。没有缓存时执行查询,并缓存不包含数据的结构模板。
|
||||
/// </summary>
|
||||
public static DataTable GetTableColumns(string tableName, Func<DataTable> query)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(tableName))
|
||||
{
|
||||
throw new ArgumentException("表名不能为空。", "tableName");
|
||||
}
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
lock (SyncRoot)
|
||||
{
|
||||
DataTable tableColumns;
|
||||
if (!TableColumnsCache.TryGetValue(tableName, out tableColumns))
|
||||
{
|
||||
DataTable queryResult = query();
|
||||
if (queryResult == null)
|
||||
{
|
||||
throw new InvalidOperationException("获取表结构失败。" + tableName);
|
||||
}
|
||||
|
||||
tableColumns = queryResult.Clone();
|
||||
TableColumnsCache[tableName] = tableColumns;
|
||||
}
|
||||
|
||||
return tableColumns.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空上一次模块初始化记录的参数。
|
||||
/// </summary>
|
||||
public static void Clear()
|
||||
{
|
||||
lock (SyncRoot)
|
||||
{
|
||||
TableExistsCache.Clear();
|
||||
ColumnExistsCache.Clear();
|
||||
TableColumnsCache.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,7 @@
|
||||
<Compile Include="Impl\BillImpl.cs" />
|
||||
<Compile Include="Impl\ConditionalCaching.cs" />
|
||||
<Compile Include="Impl\ErrorMessage.cs" />
|
||||
<Compile Include="Impl\InitialParamCache.cs" />
|
||||
<Compile Include="Impl\LanguageTranslation.cs" />
|
||||
<Compile Include="Impl\MainImpl.cs" />
|
||||
<Compile Include="Impl\BillAuditImpl.cs" />
|
||||
|
||||
Reference in New Issue
Block a user