- 在 margin_template_v2 模型中新增 BookScopeName 属性用于显示簿记账户名称 - 更新客户端和服务端列表视图以显示适用簿记账户列 - 实现 SetBookScopeNames 方法将簿记账户ID转换为名称显示 - 添加 ParseBookIdsForDisplay 方法解析簿记账户ID列表 - 新增 MarginTemplateV2BookScopeTest 单元测试验证簿记账户范围逻辑
145 lines
4.4 KiB
C#
145 lines
4.4 KiB
C#
using BaseOUDAL;
|
||
using System.Globalization;
|
||
using YLErp.Model;
|
||
|
||
namespace YLErp.Modules.MarginModule
|
||
{
|
||
public class MarginTemplateService : YLBaseService
|
||
{
|
||
public MarginTemplateService(OptUserInfo userInfo) : base(userInfo)
|
||
{
|
||
}
|
||
|
||
public MarginTemplateService(YLBaseService baseService) : base(baseService)
|
||
{
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询margin_template列表
|
||
/// </summary>
|
||
public SearchListResult<margin_template> SearchTradeMarginList(margin_templateReq req)
|
||
{
|
||
var query = from margin_template in DbContext.margin_template
|
||
select margin_template;
|
||
|
||
if (!string.IsNullOrEmpty(req.Name))
|
||
{
|
||
query = query.Where(d => d.Name == req.Name);
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(req.sidx))
|
||
{
|
||
req.sidx = "id";
|
||
req.sord = "desc";
|
||
}
|
||
|
||
var retListResult = query.ToSearchList(req);
|
||
|
||
return retListResult;
|
||
}
|
||
|
||
public SearchListResult<margin_template_v2> SearchMarginTemplateV2List(margin_template_v2Req req)
|
||
{
|
||
var query = from margin_template_v2 in DbContext.margin_template_v2
|
||
select margin_template_v2;
|
||
|
||
if (!string.IsNullOrEmpty(req.Name))
|
||
{
|
||
query = query.Where(d => d.Name.Contains(req.Name));
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(req.TradeType))
|
||
{
|
||
query = query.Where(d => d.TradeTypes.Contains(req.TradeType));
|
||
}
|
||
|
||
if (req.RuleType != null)
|
||
{
|
||
query = query.Where(d => d.RuleType == req.RuleType.Value);
|
||
}
|
||
|
||
if (req.MarginType != null)
|
||
{
|
||
query = query.Where(d => d.MarginType == req.MarginType.Value);
|
||
}
|
||
|
||
if(req.IsValid.HasValue)
|
||
{
|
||
query = query.Where(d => d.IsValid == req.IsValid.Value);
|
||
}
|
||
|
||
query = query.Where(d => d.IsDefault == req.IsDefault);
|
||
query = query.Where(d => d.IsForClient == req.IsForClient);
|
||
|
||
if (string.IsNullOrEmpty(req.sidx))
|
||
{
|
||
req.sidx = "id";
|
||
req.sord = "desc";
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
}
|