增加同时获取多个字典类型数据接口
This commit is contained in:
105
visualdev/Tnb.Vengine/Domain/VmQueryParser.cs
Normal file
105
visualdev/Tnb.Vengine/Domain/VmQueryParser.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Extension;
|
||||
using Tnb.Vengine.DataAccess;
|
||||
|
||||
namespace Tnb.Vengine.Domain
|
||||
{
|
||||
public class VmQueryParser
|
||||
{
|
||||
private readonly IDataAccess _dataAccess;
|
||||
private readonly Vmodel _root;
|
||||
private List<string> _outputs;
|
||||
private Dictionary<string, OutputSelect> _selectProps = new Dictionary<string, OutputSelect>();
|
||||
private Dictionary<string, Vmodel?> _navModels = new Dictionary<string, Vmodel?>();
|
||||
public VmQueryParser(IDataAccess dataAccess, Vmodel rootModel, string output)
|
||||
{
|
||||
_dataAccess = dataAccess;
|
||||
_root = rootModel;
|
||||
_outputs = output.Split(',').Distinct().ToList();
|
||||
ParseOutputStr();
|
||||
}
|
||||
/// <summary>
|
||||
/// 按模型组织要输出的属性
|
||||
/// </summary>
|
||||
private void ParseOutputStr()
|
||||
{
|
||||
foreach (var outStr in _outputs)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(outStr))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string vmPath;
|
||||
int n = outStr.LastIndexOf('.');
|
||||
if (n < 1)
|
||||
{
|
||||
vmPath = Vmodel.MAIN_ALIES;
|
||||
}
|
||||
else
|
||||
{
|
||||
vmPath = outStr.Substring(0, n);
|
||||
}
|
||||
if (!_selectProps.ContainsKey(vmPath))
|
||||
{
|
||||
_selectProps.Add(vmPath, new OutputSelect { navPaths = vmPath.Split(',').ToList(), vmPath = vmPath });
|
||||
}
|
||||
var outSelect = _selectProps[vmPath];
|
||||
outSelect.propCodes.Add(outStr.Substring(n + 1));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadNavModel()
|
||||
{
|
||||
foreach (var selVm in _selectProps.Values)
|
||||
{
|
||||
//if(selVm.navModel != null)
|
||||
}
|
||||
var navProps = _root.navProps.Where(a => _selectProps.Values.Any(b => b.vmPath.StartsWith(a.code + "."))).ToList();
|
||||
await LoadVmodelNavigateAsync(navProps);
|
||||
}
|
||||
private async Task LoadVmodelNavigateAsync(List<VmNavProp> navProps)
|
||||
{
|
||||
var db = _dataAccess.GetSqlSugar();
|
||||
|
||||
var vmids = navProps.Select(a => a.vmid).Distinct().ToList();
|
||||
var navs = await db.Queryable<Vmodel>().Where(a => vmids.Contains(a.id)).ToDictionaryAsync(a => a.id, a => a);
|
||||
foreach (var navProp in navProps)
|
||||
{
|
||||
navProp.naviModel = (Vmodel)navs.GetOrDefault(navProp.vmid);
|
||||
navProp.naviModel.navProps.Where(a => _selectProps.Values.Any(b => b.vmPath.StartsWith(a.code + "."))).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class OutputSelect
|
||||
{
|
||||
public Vmodel? navModel { get; set; }
|
||||
public string navPath { get; set; } = string.Empty;
|
||||
public string vmPath { get; set; } = string.Empty;
|
||||
public eNavigateType navType { get; set; } = eNavigateType.None;
|
||||
public List<string> navPaths { get; set; } = new List<string>();
|
||||
|
||||
public List<string> propCodes { get; set; } = new List<string>();
|
||||
public List<string> fieldCodes { get; set; } = new List<string>();
|
||||
|
||||
public OutputSelect()
|
||||
{
|
||||
|
||||
}
|
||||
public OutputSelect(Vmodel model)
|
||||
{
|
||||
vmPath = Vmodel.MAIN_ALIES;
|
||||
}
|
||||
}
|
||||
|
||||
internal class NavigateVmodel
|
||||
{
|
||||
public Vmodel? navModel { get; set; }
|
||||
public string navPath { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user