From 3def0fddd09a6e1b19dc2047a9e44a7075b4d108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=8D=E9=94=90?= <1565842059@qq.com> Date: Fri, 10 Jul 2026 14:02:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(trade):=20=E6=B7=BB=E5=8A=A0=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E7=A1=AE=E8=AE=A4=E6=96=87=E6=A1=A3=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 TradeConfirmationDocumentQueryItem 查询项类 - 实现 TradeConfirmationDocumentQuery.Create 查询方法 - 添加按交易日期范围过滤功能 - 重构 tradeController 中的文档查询逻辑 - 集成文档、合同关系和交易数据的联合查询 - 优化查询性能通过预过滤有效合同关系 --- .../TradeConfirmationDocumentQuery.cs | 42 +++++++++++++++++++ YLErpWeb/Controllers/tradeController.cs | 17 ++++---- 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 YLErpDAL/Modules/TradeModule/QueryModule/TradeConfirmationDocumentQuery.cs diff --git a/YLErpDAL/Modules/TradeModule/QueryModule/TradeConfirmationDocumentQuery.cs b/YLErpDAL/Modules/TradeModule/QueryModule/TradeConfirmationDocumentQuery.cs new file mode 100644 index 00000000..d43a4553 --- /dev/null +++ b/YLErpDAL/Modules/TradeModule/QueryModule/TradeConfirmationDocumentQuery.cs @@ -0,0 +1,42 @@ +namespace YLErp.Modules.TradeModule.QueryModule +{ + public sealed class TradeConfirmationDocumentQueryItem + { + public trade_contract_document Document { get; set; } + + public trade_contract_r Relation { get; set; } + } + + public static class TradeConfirmationDocumentQuery + { + public static IQueryable Create( + IQueryable documents, + IQueryable relations, + IQueryable trades, + DateTime? tradeDateStart, + DateTime? tradeDateEnd) + { + if (tradeDateStart.HasValue) + { + trades = trades.Where(t => t.TradeDate >= tradeDateStart.Value); + } + + if (tradeDateEnd.HasValue) + { + var tradeDateEndExclusive = tradeDateEnd.Value.Date.AddDays(1); + trades = trades.Where(t => t.TradeDate < tradeDateEndExclusive); + } + + return from document in documents + join relation in relations.Where(r => r.IsValid) + on document.Code equals relation.ContractCode + join trade in trades + on relation.TradeId equals trade.id + select new TradeConfirmationDocumentQueryItem + { + Document = document, + Relation = relation + }; + } + } +} diff --git a/YLErpWeb/Controllers/tradeController.cs b/YLErpWeb/Controllers/tradeController.cs index 428a4c66..726e93b5 100644 --- a/YLErpWeb/Controllers/tradeController.cs +++ b/YLErpWeb/Controllers/tradeController.cs @@ -6299,14 +6299,17 @@ namespace YLErp.Web.Controllers return ShowError("请选择文档类型!"); } - if (req.TradeDateStart == null) { req.TradeDateStart = DateTime.MinValue; } - if (req.TradeDateEnd == null) { req.TradeDateEnd = DateTime.MaxValue; } - var db_trade_contract_r = yldb.trade_contract_r.AsQueryable(); + var documentQuery = TradeConfirmationDocumentQuery.Create( + yldb.trade_contract_document, + yldb.trade_contract_r, + yldb.trade, + req.TradeDateStart, + req.TradeDateEnd); - var query = from doc in yldb.trade_contract_document - join r in db_trade_contract_r - on doc.Code equals r.ContractCode - where doc.Type == ContractTypeEnum.Trade && doc.ValueDate >= req.TradeDateStart && doc.ValueDate <= req.TradeDateEnd && r.IsValid + var query = from item in documentQuery + let doc = item.Document + let r = item.Relation + where doc.Type == ContractTypeEnum.Trade select new { doc.ClientId,