feat(control): add module-backed extended return search

This commit is contained in:
2026-07-29 16:47:42 +08:00
parent 1bbe9c9a4c
commit 9c0fdac9ba
6 changed files with 118 additions and 109 deletions
@@ -0,0 +1,49 @@
using Lskj.Control.MultiModelLookUp;
using System;
using System.Collections.Generic;
namespace Lskj.Control
{
/// <summary>
/// 按模块编号延迟读取模块数据源 SQL。只缓存 SQL 文本,不加载业务数据。
/// </summary>
internal sealed class ExtendedReturnModuleSourceResolver
{
private readonly object syncRoot = new object();
private readonly Dictionary<string, string> sourceSqlByModule =
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
public string Resolve(string moduleCode)
{
moduleCode = (moduleCode ?? string.Empty).Trim();
if (moduleCode.Length == 0)
{
throw new InvalidOperationException("扩展模块搜索的模块编号不能为空。");
}
lock (syncRoot)
{
string cachedSql;
if (sourceSqlByModule.TryGetValue(moduleCode, out cachedSql))
{
return cachedSql;
}
using (FrmModelLookUp lookup = new FrmModelLookUp(moduleCode, true))
{
string sourceSql = lookup.SysModel == null
? string.Empty
: lookup.SysModel.MenuSql;
if (string.IsNullOrWhiteSpace(sourceSql))
{
throw new InvalidOperationException(
string.Format("模块“{0}”未配置数据源 SQL。", moduleCode));
}
sourceSqlByModule.Add(moduleCode, sourceSql);
return sourceSql;
}
}
}
}
}
@@ -18,7 +18,7 @@ using System.Windows.Forms;
namespace Lskj.Control
{
/// <summary>
/// MyControl 中的 181 扩展搜索控件。业务实际值与界面显示文本相互独立,
/// MyControl 中的 173/174 扩展搜索控件。业务实际值与界面显示文本相互独立,
/// 数据源仅在弹出框打开或用户执行查询时按需访问。
/// </summary>
public sealed class LabelExtendedReturnSearchEdit : BaseUserControl
@@ -152,7 +152,7 @@ namespace Lskj.Control
/// <summary>
/// BaseUserControl 的 EditText 仍用于常规赋值入口;读取时返回界面显示文本,
/// MyControl.GetControlValue 对 181 会显式读取 EditValue。
/// MyControl.GetControlValue 对 173/174 会显式读取 EditValue。
/// </summary>
public override string EditText
{
@@ -472,7 +472,14 @@ namespace Lskj.Control
{
if (Model == null) throw new InvalidOperationException("扩展返回控件配置不存在。");
if (ControlObj == null) throw new InvalidOperationException("扩展返回控件未关联 MyControl。");
if (string.IsNullOrWhiteSpace(Model.SourceSql))
if (Model.FieldType == ControlType.LabModuleSelectReturnIdExtended)
{
if (string.IsNullOrWhiteSpace(Model.AddModuleId))
{
throw new InvalidOperationException("扩展模块搜索的模块编号不能为空。");
}
}
else if (string.IsNullOrWhiteSpace(Model.SourceSql))
{
throw new InvalidOperationException("搜索数据源 SQL 不能为空。");
}
@@ -576,7 +583,7 @@ namespace Lskj.Control
private string BuildSourceSql()
{
string sourceSql = Model.SourceSql;
string sourceSql = GetBaseSourceSql();
if (ControlObj != null)
{
sourceSql = ControlObj.ReplaceControlValue(sourceSql);
@@ -585,6 +592,27 @@ namespace Lskj.Control
return ReplaceHelper.ReplaceParam(sourceSql);
}
private string GetBaseSourceSql()
{
if (Model == null)
{
throw new InvalidOperationException("扩展返回控件配置不存在。");
}
if (Model.FieldType == ControlType.LabModuleSelectReturnIdExtended)
{
if (ControlObj == null)
{
throw new InvalidOperationException("扩展返回控件未关联 MyControl。");
}
return ControlObj.ResolveExtendedReturnModuleSourceSql(Model.AddModuleId);
}
if (string.IsNullOrWhiteSpace(Model.SourceSql))
{
throw new InvalidOperationException("搜索数据源 SQL 不能为空。");
}
return Model.SourceSql;
}
private void StartSearch(string keyword)
{
SearchRequest request = new SearchRequest();