feat: 筛选器支持多选(方案B:下拉+checkbox)+ 后端 7 个接口改 OR 多值筛选

后端:
- MultiLike/MultiExact/MultiCsvContains 三个 Helper
- .NET Framework 4.6 无 TrimEntries,改用 Select(v=>v.Trim()) 手动去空格
- 7 个接口 where 条件从单值改多值 OR 模式

前端:
- material_delivery.html + delivery_dashboard_risk.html 各 4 个下拉改 MultiSelect 组件
- 原生 select 隐藏,组件同步 .value 为逗号分隔,原页面 JS 零改动
- 支持动态 options 刷新 + reset/setValuesMulti/refreshMulti
This commit is contained in:
Gaussian committed 2026-11-10 11:07:46 +08:00
1 parent de4516ab5d
commit dd286d5f65
3 files changed
+371 -37

No files matched your search

+60 -16
View File
@@ -117,6 +117,50 @@ namespace GXWebApi.Controllers
}
}
// ===== 多选筛选辅助(前端下拉传逗号分隔值,后端拆成 OR 条件)=====
/// <summary>
/// 多值 LIKE 模糊匹配(OR 语义)。例:supplier=A,B → (Supplier LIKE '%A%' OR Supplier LIKE '%B%')
/// </summary>
private static string MultiLike(string field, string csv, bool useNVarChar = true)
{
if (string.IsNullOrEmpty(csv)) return "";
var parts = csv.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(v => v.Trim()).Where(v => !string.IsNullOrEmpty(v)).Distinct().ToList();
if (parts.Count == 0) return "";
string q = useNVarChar ? "N" : "";
if (parts.Count == 1) return $" AND ISNULL({field},'') LIKE {q}'%{parts[0]}%' ";
return " AND (" + string.Join(" OR ", parts.Select(v => $"ISNULL({field},'') LIKE {q}'%{v}%'")) + ") ";
}
/// <summary>
/// 多值精确匹配(OR 语义)。例:risk=断线,预警 → (Risk=N'断线' OR Risk=N'预警')
/// </summary>
private static string MultiExact(string field, string csv)
{
if (string.IsNullOrEmpty(csv)) return "";
var parts = csv.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(v => v.Trim()).Where(v => !string.IsNullOrEmpty(v)).Distinct().ToList();
if (parts.Count == 0) return "";
if (parts.Count == 1) return $" AND {field}=N'{parts[0]}' ";
return " AND (" + string.Join(" OR ", parts.Select(v => $"{field}=N'{v}'")) + ") ";
}
/// <summary>
/// 多值检查逗号拼接字段是否"包含"(OR 语义)。
/// 例:ProductTypes='SI,M4' → productType=SI → (','+ISNULL(ProductTypes,'')+',') LIKE '%,SI,%'
/// productType=SI,M4 → (','+field+',' LIKE '%,SI,%' OR ','+field+',' LIKE '%,M4,%')
/// </summary>
private static string MultiCsvContains(string field, string csv)
{
if (string.IsNullOrEmpty(csv)) return "";
var parts = csv.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(v => v.Trim()).Where(v => !string.IsNullOrEmpty(v)).Distinct().ToList();
if (parts.Count == 0) return "";
if (parts.Count == 1) return $" AND (','+ISNULL({field},'')+',') LIKE '%,{parts[0]},%' ";
return " AND (" + string.Join(" OR ", parts.Select(v => $"(','+ISNULL({field},'')+',') LIKE '%,{v},%'")) + ") ";
}
#endregion
#region ===== 产品BOM主数据 =====
@@ -588,7 +632,7 @@ namespace GXWebApi.Controllers
string where = " WHERE 1=1 ";
if (!string.IsNullOrEmpty(productCode)) where += $" AND S.ProductCode='{Sql(productCode)}' ";
if (!string.IsNullOrEmpty(bomVersion)) where += $" AND S.BOMVersion='{Sql(bomVersion)}' ";
if (!string.IsNullOrEmpty(productType)) where += $" AND ISNULL(S.ProductType,N'') LIKE '%{Sql(productType)}%' ";
if (!string.IsNullOrEmpty(productType)) where += MultiLike("S.ProductType", productType, useNVarChar: true);
if (!string.IsNullOrEmpty(status)) where += $" AND S.Status=N'{Sql(status)}' ";
if (!string.IsNullOrEmpty(keyword)) where += $" AND (S.ProductCode LIKE '%{Sql(keyword)}%' OR M.ProductName LIKE N'%{Sql(keyword)}%') ";
@@ -2377,10 +2421,10 @@ LEFT JOIN #SupByMat SP ON SP.MaterialCode=D.ChildMaterialId;
string todayStr = DateTime.Now.ToString("yyyy-MM-dd");
string where = " WHERE S.PlanEndDate>='" + todayStr + "' ";
if (!string.IsNullOrEmpty(productType)) where += $" AND (','+ISNULL(D.ProductTypes,'')+',') LIKE '%,{Sql(productType)},%' ";
if (!string.IsNullOrEmpty(supplier)) where += $" AND ISNULL(D.Supplier,'') LIKE N'%{Sql(supplier)}%' ";
if (!string.IsNullOrEmpty(purchaser)) where += $" AND ISNULL(D.Purchaser,'') LIKE N'%{Sql(purchaser)}%' ";
if (!string.IsNullOrEmpty(risk)) where += $" AND D.DeliveryRisk=N'{Sql(risk)}' ";
if (!string.IsNullOrEmpty(productType)) where += MultiCsvContains("D.ProductTypes", productType);
if (!string.IsNullOrEmpty(supplier)) where += MultiLike("D.Supplier", supplier);
if (!string.IsNullOrEmpty(purchaser)) where += MultiLike("D.Purchaser", purchaser);
if (!string.IsNullOrEmpty(risk)) where += MultiExact("D.DeliveryRisk", risk);
if (!string.IsNullOrEmpty(bomLevel)) where += $" AND D.BOMLevel={Int(bomLevel)} ";
if (!string.IsNullOrEmpty(keyword))
{
@@ -3498,8 +3542,8 @@ LEFT JOIN #SupByMat SP ON SP.MaterialCode=D.ChildMaterialId;
try
{
string where = " WHERE 1=1 ";
if (!string.IsNullOrEmpty(productType)) where += $" AND D.ProductTypes LIKE '%{Sql(productType)}%' ";
if (!string.IsNullOrEmpty(risk)) where += $" AND D.DeliveryRisk=N'{Sql(risk)}' ";
if (!string.IsNullOrEmpty(productType)) where += MultiCsvContains("D.ProductTypes", productType);
if (!string.IsNullOrEmpty(risk)) where += MultiExact("D.DeliveryRisk", risk);
DataTable dt = db.ExecuteTable($@"
SELECT
@@ -3592,8 +3636,8 @@ LEFT JOIN #SupByMat SP ON SP.MaterialCode=D.ChildMaterialId;
try
{
string where = " WHERE 1=1 ";
if (!string.IsNullOrEmpty(productType)) where += $" AND D.ProductTypes LIKE '%{Sql(productType)}%' ";
if (!string.IsNullOrEmpty(risk)) where += $" AND D.DeliveryRisk=N'{Sql(risk)}' ";
if (!string.IsNullOrEmpty(productType)) where += MultiCsvContains("D.ProductTypes", productType);
if (!string.IsNullOrEmpty(risk)) where += MultiExact("D.DeliveryRisk", risk);
if (!string.IsNullOrEmpty(keyword)) where += $" AND (D.ChildMaterialId LIKE '%{Sql(keyword)}%' OR D.MaterialName LIKE N'%{Sql(keyword)}%') ";
DataTable dtCount = db.ExecuteTable($"SELECT COUNT(*) AS CNT FROM Material_Delivery D {where}");
@@ -3667,7 +3711,7 @@ LEFT JOIN #SupByMat SP ON SP.MaterialCode=D.ChildMaterialId;
string end = dtRange.Rows.Count > 0 ? DateStr(dtRange.Rows[0]["EndD"]) : "";
string where = " WHERE 1=1 ";
if (!string.IsNullOrEmpty(productType)) where += $" AND D.ProductTypes LIKE '%{Sql(productType)}%' ";
if (!string.IsNullOrEmpty(productType)) where += MultiCsvContains("D.ProductTypes", productType);
if (!string.IsNullOrEmpty(risk))
{
string[] risks = risk.Split(',');
@@ -3791,10 +3835,10 @@ LEFT JOIN #SupByMat SP ON SP.MaterialCode=D.ChildMaterialId;
string todayStr = DateTime.Now.ToString("yyyy-MM-dd");
string where = " WHERE S.PlanEndDate>=@today ";
if (!string.IsNullOrEmpty(risk)) where += $" AND D.DeliveryRisk=N'{Sql(risk)}' ";
if (!string.IsNullOrEmpty(productType)) where += $" AND (','+ISNULL(D.ProductTypes,'')+',') LIKE '%,{Sql(productType)},%' ";
if (!string.IsNullOrEmpty(supplier)) where += $" AND ISNULL(D.Supplier,'') LIKE N'%{Sql(supplier)}%' ";
if (!string.IsNullOrEmpty(purchaser)) where += $" AND ISNULL(D.Purchaser,'') LIKE N'%{Sql(purchaser)}%' ";
if (!string.IsNullOrEmpty(risk)) where += MultiExact("D.DeliveryRisk", risk);
if (!string.IsNullOrEmpty(productType)) where += MultiCsvContains("D.ProductTypes", productType);
if (!string.IsNullOrEmpty(supplier)) where += MultiLike("D.Supplier", supplier);
if (!string.IsNullOrEmpty(purchaser)) where += MultiLike("D.Purchaser", purchaser);
if (!string.IsNullOrEmpty(keyword))
{
string kw = Sql(keyword);
@@ -4041,8 +4085,8 @@ LEFT JOIN #SupByMat SP ON SP.MaterialCode=D.ChildMaterialId;
// 2) 取物料清单(按风险/产品类型过滤)
string matWhere = $" WHERE S.PlanEndDate>='{todayStr}' ";
if (!string.IsNullOrEmpty(risk)) matWhere += $" AND D.DeliveryRisk=N'{Sql(risk)}' ";
if (!string.IsNullOrEmpty(productType)) matWhere += $" AND (','+ISNULL(D.ProductTypes,'')+',' LIKE '%,{Sql(productType)},%') ";
if (!string.IsNullOrEmpty(risk)) matWhere += MultiExact("D.DeliveryRisk", risk);
if (!string.IsNullOrEmpty(productType)) matWhere += MultiCsvContains("D.ProductTypes", productType);
DataTable matDt = db.ExecuteTable($@"
SELECT D.Id, D.ScheduleId, D.ChildMaterialId, D.MaterialName, D.BOMLevel, D.DeliveryRisk,