feat(margin_template_v2): 添加簿记账户显示功能
- 在 margin_template_v2 模型中新增 BookScopeName 属性用于显示簿记账户名称 - 更新客户端和服务端列表视图以显示适用簿记账户列 - 实现 SetBookScopeNames 方法将簿记账户ID转换为名称显示 - 添加 ParseBookIdsForDisplay 方法解析簿记账户ID列表 - 新增 MarginTemplateV2BookScopeTest 单元测试验证簿记账户范围逻辑
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using BaseOUDAL;
|
||||
using System.Globalization;
|
||||
using YLErp.Model;
|
||||
|
||||
namespace YLErp.Modules.MarginModule
|
||||
@@ -77,8 +78,67 @@ namespace YLErp.Modules.MarginModule
|
||||
}
|
||||
|
||||
var retListResult = query.ToSearchList(req);
|
||||
SetBookScopeNames(retListResult);
|
||||
|
||||
return retListResult;
|
||||
}
|
||||
|
||||
private void SetBookScopeNames(SearchListResult<margin_template_v2> result)
|
||||
{
|
||||
var rows = result?.rows?.ToList();
|
||||
if (rows == null || rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var parsedRows = rows.Select(row => new
|
||||
{
|
||||
Row = row,
|
||||
BookIds = row == null ? new List<int>() : ParseBookIdsForDisplay(row.BookIds)
|
||||
}).ToList();
|
||||
var bookIds = parsedRows.SelectMany(item => item.BookIds).Distinct().ToList();
|
||||
var bookNames = bookIds.Count == 0
|
||||
? new Dictionary<int, string>()
|
||||
: DbContext.assetunit
|
||||
.AsNoTracking()
|
||||
.Where(book => bookIds.Contains(book.id))
|
||||
.Select(book => new { book.id, book.Name })
|
||||
.ToDictionary(book => book.id, book => book.Name);
|
||||
|
||||
foreach (var item in parsedRows)
|
||||
{
|
||||
if (item.Row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
item.Row.BookScopeName = string.IsNullOrWhiteSpace(item.Row.BookIds)
|
||||
? "全部"
|
||||
: string.Join(",", item.BookIds
|
||||
.Where(bookId => bookNames.ContainsKey(bookId))
|
||||
.Select(bookId => bookNames[bookId]));
|
||||
}
|
||||
|
||||
result.rows = rows;
|
||||
}
|
||||
|
||||
private static List<int> ParseBookIdsForDisplay(string bookIds)
|
||||
{
|
||||
var ids = new List<int>();
|
||||
if (string.IsNullOrWhiteSpace(bookIds))
|
||||
{
|
||||
return ids;
|
||||
}
|
||||
|
||||
foreach (var rawId in bookIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (int.TryParse(rawId.Trim(), NumberStyles.None, CultureInfo.InvariantCulture, out var id) && id > 0)
|
||||
{
|
||||
ids.Add(id);
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user