feat(trade): 添加交易确认文档查询功能
- 新增 TradeConfirmationDocumentQueryItem 查询项类 - 实现 TradeConfirmationDocumentQuery.Create 查询方法 - 添加按交易日期范围过滤功能 - 重构 tradeController 中的文档查询逻辑 - 集成文档、合同关系和交易数据的联合查询 - 优化查询性能通过预过滤有效合同关系
This commit is contained in:
@@ -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<TradeConfirmationDocumentQueryItem> Create(
|
||||
IQueryable<trade_contract_document> documents,
|
||||
IQueryable<trade_contract_r> relations,
|
||||
IQueryable<trade> 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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user