模型通用接口List改为用left join
This commit is contained in:
@@ -8,52 +8,57 @@ namespace Tnb.Vengine.Domain
|
||||
private readonly IDataAccess _dataAccess;
|
||||
private readonly Vmodel _root;
|
||||
private List<string> _outputs;
|
||||
private Dictionary<string, OutputSelect> _selectProps = new Dictionary<string, OutputSelect>();
|
||||
private Dictionary<string, VmSelect> _selectProps = new Dictionary<string, VmSelect>();
|
||||
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();
|
||||
ParseOutputStr(output);
|
||||
}
|
||||
/// <summary>
|
||||
/// 按模型组织要输出的属性
|
||||
/// </summary>
|
||||
private void ParseOutputStr()
|
||||
private void ParseOutputStr(string output)
|
||||
{
|
||||
_outputs = output.Split(',').Distinct().ToList();
|
||||
_selectProps.Add(Vmodel.MAIN_ALIES, new VmSelect() { navModel = _root });
|
||||
foreach (var outStr in _outputs)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(outStr))
|
||||
if (string.IsNullOrWhiteSpace(outStr)) continue;
|
||||
var codes = outStr.Split('.');
|
||||
if (codes.Length == 1)
|
||||
{
|
||||
_selectProps[Vmodel.MAIN_ALIES].propCodes.Add(outStr);
|
||||
continue;
|
||||
}
|
||||
string vmPath;
|
||||
int n = outStr.LastIndexOf('.');
|
||||
if (n < 1)
|
||||
var vmPath = "";
|
||||
for (int i = 0; i < codes.Length - 1; i++)
|
||||
{
|
||||
vmPath = Vmodel.MAIN_ALIES;
|
||||
vmPath = i == 0 ? codes[i] : vmPath + "." + codes[i];
|
||||
if (!_selectProps.ContainsKey(vmPath))
|
||||
{
|
||||
_selectProps.Add(vmPath, new VmSelect(vmPath, i + 2));
|
||||
}
|
||||
if (i == codes.Length - 2)
|
||||
{
|
||||
_selectProps[vmPath].propCodes.Add(codes[i + 1]);
|
||||
}
|
||||
}
|
||||
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()
|
||||
{
|
||||
var keys = _selectProps.Keys.Where(a => a != Vmodel.MAIN_ALIES).OrderBy(a => a).ToList();
|
||||
foreach (var selVm in _selectProps.Values)
|
||||
{
|
||||
//if(selVm.navModel != null)
|
||||
if (_navModels.ContainsKey(selVm.path))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
var navProps = _root.navProps.Where(a => _selectProps.Values.Any(b => b.vmPath.StartsWith(a.code + "."))).ToList();
|
||||
var navProps = _root.navProps.Where(a => _selectProps.Values.Any(b => b.path.StartsWith(a.code + "."))).ToList();
|
||||
await LoadVmodelNavigateAsync(navProps);
|
||||
}
|
||||
private async Task LoadVmodelNavigateAsync(List<VmNavProp> navProps)
|
||||
@@ -65,30 +70,30 @@ namespace Tnb.Vengine.Domain
|
||||
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();
|
||||
navProp.naviModel.navProps.Where(a => _selectProps.Values.Any(b => b.path.StartsWith(a.code + "."))).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class OutputSelect
|
||||
internal class VmSelect
|
||||
{
|
||||
public Vmodel? navModel { get; set; }
|
||||
public string navPath { get; set; } = string.Empty;
|
||||
public string vmPath { get; set; } = string.Empty;
|
||||
public string path { get; set; } = Vmodel.MAIN_ALIES;
|
||||
public int level { get; set; } = 1;
|
||||
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 VmSelect()
|
||||
{
|
||||
|
||||
}
|
||||
public OutputSelect(Vmodel model)
|
||||
public VmSelect(string vmPath, int vmLevel)
|
||||
{
|
||||
vmPath = Vmodel.MAIN_ALIES;
|
||||
path = vmPath;
|
||||
level = vmLevel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -332,7 +332,7 @@ public partial class Vmodel : Entity
|
||||
if (navCode == VmSelectProp.MAIN_ALIES) continue;
|
||||
var navProp = navProps.First(a => a.code == navCode);
|
||||
if (navProp.naviModel == null || navProp.navType != eNavigateType.OneToOne) continue;
|
||||
JoinInfoParameter join = new JoinInfoParameter { TableName = navProp.naviModel.tableName, ShortName = navCode, Type = JoinType.Inner };
|
||||
JoinInfoParameter join = new JoinInfoParameter { TableName = navProp.naviModel.tableName, ShortName = navCode, Type = JoinType.Left };
|
||||
var fkField = navProp.naviModel.PropCodeToFieldCode(navProp.fkField);
|
||||
var refField = navProp.refField;
|
||||
if (navProp.refCode != VmSelectProp.MAIN_ALIES)
|
||||
|
||||
Reference in New Issue
Block a user