From dd286d5f6554a5f9187823c50d7e713beb5b03aa Mon Sep 17 00:00:00 2001 From: Gaussian Date: Tue, 10 Nov 2026 11:06:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=AD=9B=E9=80=89=E5=99=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E9=80=89=EF=BC=88=E6=96=B9=E6=A1=88B?= =?UTF-8?q?=EF=BC=9A=E4=B8=8B=E6=8B=89+checkbox=EF=BC=89+=20=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=207=20=E4=B8=AA=E6=8E=A5=E5=8F=A3=E6=94=B9=20OR=20?= =?UTF-8?q?=E5=A4=9A=E5=80=BC=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端: - 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 --- WebApi/Controllers/DeliverController.cs | 76 ++++-- .../Delivery/delivery_dashboard_risk.html | 112 ++++++++- WebApi/View/Delivery/material_delivery.html | 220 +++++++++++++++++- 3 files changed, 371 insertions(+), 37 deletions(-) diff --git a/WebApi/Controllers/DeliverController.cs b/WebApi/Controllers/DeliverController.cs index 5002d37..ac87d0a 100755 --- a/WebApi/Controllers/DeliverController.cs +++ b/WebApi/Controllers/DeliverController.cs @@ -117,6 +117,50 @@ namespace GXWebApi.Controllers } } + // ===== 多选筛选辅助(前端下拉传逗号分隔值,后端拆成 OR 条件)===== + + /// + /// 多值 LIKE 模糊匹配(OR 语义)。例:supplier=A,B → (Supplier LIKE '%A%' OR Supplier LIKE '%B%') + /// + 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}%'")) + ") "; + } + + /// + /// 多值精确匹配(OR 语义)。例:risk=断线,预警 → (Risk=N'断线' OR Risk=N'预警') + /// + 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}'")) + ") "; + } + + /// + /// 多值检查逗号拼接字段是否"包含"(OR 语义)。 + /// 例:ProductTypes='SI,M4' → productType=SI → (','+ISNULL(ProductTypes,'')+',') LIKE '%,SI,%' + /// productType=SI,M4 → (','+field+',' LIKE '%,SI,%' OR ','+field+',' LIKE '%,M4,%') + /// + 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, diff --git a/WebApi/View/Delivery/delivery_dashboard_risk.html b/WebApi/View/Delivery/delivery_dashboard_risk.html index a3ca099..c6a9cbc 100755 --- a/WebApi/View/Delivery/delivery_dashboard_risk.html +++ b/WebApi/View/Delivery/delivery_dashboard_risk.html @@ -9,6 +9,34 @@