merge from 2023-03-14
This commit is contained in:
@@ -15,9 +15,6 @@ using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.RemoteRequest.Extensions;
|
||||
using JNPF.Systems.Entitys.Model.DataInterFace;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Spire.Pdf.Lists;
|
||||
using Senparc.NeuChar.Entities;
|
||||
|
||||
namespace JNPF.Common.CodeGen.DataParsing;
|
||||
|
||||
@@ -43,11 +40,6 @@ public class ControlParsing : ITransient
|
||||
/// </summary>
|
||||
private readonly IDataInterfaceService _dataInterfaceService;
|
||||
|
||||
/// <summary>
|
||||
/// 解析控件的控件属性 (vModel , Attr).
|
||||
/// </summary>
|
||||
private Dictionary<string, FieldsModel>? ControlAttr;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数.
|
||||
/// </summary>
|
||||
@@ -74,9 +66,6 @@ public class ControlParsing : ITransient
|
||||
/// <returns></returns>
|
||||
public async Task<List<Dictionary<string, object>>> GetParsDataList(List<Dictionary<string, object>> oldDatas, string vModelStr, string jnpfKeyConst, string tenantId, List<FieldsModel>? vModelAttr = null)
|
||||
{
|
||||
ControlAttr = new Dictionary<string, FieldsModel>();
|
||||
if (vModelAttr != null) vModelAttr.ForEach(it => ControlAttr.Add(it.__vModel__, it));
|
||||
|
||||
var vModels = new Dictionary<string, object>();
|
||||
var vModelList = vModelStr.Split(',');
|
||||
oldDatas.ForEach(items =>
|
||||
@@ -91,45 +80,54 @@ public class ControlParsing : ITransient
|
||||
var ctOldDatas = item.Value.ToObject<List<Dictionary<string, object>>>();
|
||||
ctOldDatas.ForEach(ctItems =>
|
||||
{
|
||||
foreach (var ctItem in ctItems) if (vModelList.Contains(ctItem.Key) && !vModels.ContainsKey(ctItem.Key)) vModels.Add(ctItem.Key, jnpfKeyConst);
|
||||
foreach (var ctItem in ctItems)
|
||||
{
|
||||
if (vModelList.Contains(item.Key + "-" + ctItem.Key) && !vModels.ContainsKey(item.Key + "-" + ctItem.Key))
|
||||
vModels.Add(item.Key + "-" + ctItem.Key, jnpfKeyConst);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return await GetParsDataByList(oldDatas, vModels, tenantId);
|
||||
return await GetParsDataByList(vModelAttr, oldDatas, vModels, tenantId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解析数据.
|
||||
/// </summary>
|
||||
/// <param name="fields">模板集合.</param>
|
||||
/// <param name="oldDatas">原数据集合.</param>
|
||||
/// <param name="vModels">需解析的字段 (字段名,JnpfKeyConst/子表dictionary).</param>
|
||||
/// <param name="tenantId">租户Id.</param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<Dictionary<string, object>>> GetParsDataByList(List<Dictionary<string, object>> oldDatas, Dictionary<string, object> vModels, string tenantId)
|
||||
private async Task<List<Dictionary<string, object>>> GetParsDataByList(List<FieldsModel> fields, List<Dictionary<string, object>> oldDatas, Dictionary<string, object> vModels, string tenantId)
|
||||
{
|
||||
var cacheData = await GetCaCheData(vModels, tenantId);
|
||||
var usersselectDatas = cacheData.Where(t => t.Key.Equals(CommonConst.CodeGenDynamic + "_usersSelect_" + tenantId)).FirstOrDefault().Value.ToObject<Dictionary<string, string>>(); // 用户组件
|
||||
|
||||
oldDatas.ForEach(async items =>
|
||||
foreach (var items in oldDatas)
|
||||
{
|
||||
foreach (var item in items)
|
||||
for(var i = 0; i < items.Count; i++)
|
||||
{
|
||||
if (vModels.Any(x => x.Key.Equals(item.Key)))
|
||||
var item = items.ToList()[i];
|
||||
|
||||
if (vModels.Any(x => x.Key.Equals(item.Key)) && items[item.Key] != null)
|
||||
{
|
||||
FieldsModel model = ControlAttr.ContainsKey(item.Key) ? ControlAttr[item.Key] : new FieldsModel();
|
||||
FieldsModel model = fields.Any(x=>x.__vModel__.Equals(item.Key)) ? fields.Find(x=> x.__vModel__.Equals(item.Key)) : (fields.Any(x => x.__vModel__.Equals(item.Key.Replace("_name", string.Empty))) ? fields.Find(x => x.__vModel__.Equals(item.Key.Replace("_name", string.Empty))) : new FieldsModel());
|
||||
model.separator = ",";
|
||||
var jnpfKey = vModels.FirstOrDefault(x => x.Key.Equals(item.Key)).Value;
|
||||
switch (jnpfKey)
|
||||
{
|
||||
case JnpfKeyConst.USERSSELECT:
|
||||
{
|
||||
if (item.Value != null)
|
||||
var itemValue = item.Value;
|
||||
if (itemValue == null && items.ContainsKey(item.Key.Replace("_name", string.Empty))) itemValue = items[item.Key.Replace("_name", string.Empty)];
|
||||
if (itemValue != null)
|
||||
{
|
||||
var vList = new List<string>();
|
||||
if (item.Value.ToString().Contains("[")) vList = item.Value.ToString().ToObject<List<string>>();
|
||||
else vList.Add(item.Value.ToString());
|
||||
if (itemValue.ToString().Contains("[")) vList = itemValue.ToString().ToObject<List<string>>();
|
||||
else vList.Add(itemValue.ToString());
|
||||
var itemValues = new List<string>();
|
||||
vList.ForEach(it =>
|
||||
{
|
||||
@@ -140,7 +138,6 @@ public class ControlParsing : ITransient
|
||||
}
|
||||
|
||||
break;
|
||||
case JnpfKeyConst.POPUPTABLESELECT:
|
||||
case JnpfKeyConst.POPUPSELECT: // 弹窗选择
|
||||
{
|
||||
if (model.interfaceId.IsNullOrEmpty()) continue;
|
||||
@@ -193,62 +190,45 @@ public class ControlParsing : ITransient
|
||||
{
|
||||
case 1: // SQL数据
|
||||
{
|
||||
var specificData = popupselectDataList.Where(it => it.ContainsKey(model.propsValue) && it.ContainsValue(items[item.Key].ToString())).FirstOrDefault();
|
||||
var specificData = popupselectDataList.Where(it => it.ContainsKey(model.propsValue) && it.ContainsValue(items[item.Key] == null ? model.interfaceId : items[item.Key].ToString())).FirstOrDefault();
|
||||
if (specificData != null)
|
||||
{
|
||||
// 要用模板的 “显示字段 - relationField”来展示数据
|
||||
items[item.Key + "_id"] = items[item.Key];
|
||||
items[item.Key] = specificData[model.relationField];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (model.multiple)
|
||||
{
|
||||
var nameList = new List<string>();
|
||||
items[item.Key].ToObject<List<string>>().ForEach(strIt =>
|
||||
{
|
||||
var specificData = popupselectDataList.Where(it => it.ContainsKey(model.propsValue) && it.ContainsValue(strIt)).FirstOrDefault();
|
||||
if (specificData != null)
|
||||
{
|
||||
// 要用模板的 “显示字段 - relationField”来展示数据
|
||||
if (model.relationField.IsNotEmptyOrNull())
|
||||
nameList.Add(specificData[model.relationField]);
|
||||
}
|
||||
});
|
||||
if (nameList.Any())
|
||||
{
|
||||
items[item.Key + "_id"] = items[item.Key];
|
||||
items[item.Key] = string.Join(model.separator, nameList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
items[item.Key] = items[item.Key].ToString().Contains("[") ? string.Join(model.separator, items[item.Key].ToObject<List<object>>()) : items[item.Key];
|
||||
}
|
||||
|
||||
// 弹窗选择属性
|
||||
if (model.relational.IsNotEmptyOrNull())
|
||||
foreach (var fItem in model.relational.Split(",")) items[model.__vModel__ + "_" + fItem] = specificData[fItem];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2: // 静态数据
|
||||
{
|
||||
List<string> dataList = items[item.Key].ToJsonString().ToObject<List<string>>();
|
||||
List<string> cascaderList = new List<string>();
|
||||
foreach (var it in dataList)
|
||||
var vara = popupselectDataList.Where(a => a.ContainsValue(items[item.Key] == null ? model.interfaceId : items[item.Key].ToString())).FirstOrDefault();
|
||||
if (vara != null)
|
||||
{
|
||||
var vara = popupselectDataList.Where(a => a.ContainsValue(it)).FirstOrDefault();
|
||||
if (vara != null) cascaderList.Add(vara[model.props.props.label]);
|
||||
}
|
||||
items[item.Key + "_id"] = items[item.Key];
|
||||
items[item.Key] = vara[items[item.Key].ToString()];
|
||||
|
||||
items[item.Key + "_id"] = items[item.Key];
|
||||
items[item.Key] = string.Join(model.separator, cascaderList);
|
||||
// 弹窗选择属性
|
||||
if (model.relational.IsNotEmptyOrNull())
|
||||
foreach (var fItem in model.relational.Split(",")) items[model.__vModel__ + "_" + fItem] = vara[fItem];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3: // Api数据
|
||||
{
|
||||
List<object> cascaderList = new List<object>();
|
||||
if (popupselectDataList != null) popupselectDataList.ForEach(obj => { if (obj[model.propsValue] == items[item.Key].ToString()) cascaderList.Add(obj[model.relationField]); });
|
||||
var vara = popupselectDataList.Where(a => a.ContainsValue(items[item.Key] == null ? model.interfaceId : items[item.Key].ToString())).FirstOrDefault();
|
||||
if (vara != null)
|
||||
{
|
||||
items[item.Key + "_id"] = items[item.Key];
|
||||
items[item.Key] = vara[items[item.Key].ToString()];
|
||||
|
||||
items[item.Key + "_id"] = items[item.Key];
|
||||
items[item.Key] = string.Join(model.separator, cascaderList);
|
||||
// 弹窗选择属性
|
||||
if (model.relational.IsNotEmptyOrNull())
|
||||
foreach (var fItem in model.relational.Split(",")) items[model.__vModel__ + "_" + fItem] = vara[fItem];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -293,6 +273,10 @@ public class ControlParsing : ITransient
|
||||
{
|
||||
items[item.Key + "_id"] = relationFormRealData["id"];
|
||||
items[item.Key] = relationFormRealData.ContainsKey(model.relationField) ? relationFormRealData[model.relationField] : string.Empty;
|
||||
|
||||
// 关联表单属性
|
||||
if (model.relational.IsNotEmptyOrNull())
|
||||
foreach (var fItem in model.relational.Split(",")) items[model.__vModel__ + "_" + fItem] = relationFormRealData[fItem];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -309,11 +293,15 @@ public class ControlParsing : ITransient
|
||||
{
|
||||
var ctList = item.Value.ToObject<List<Dictionary<string, object>>>();
|
||||
var ctVModels = new Dictionary<string, object>();
|
||||
vModels.Where(x => x.Key.Contains(item.Key)).ToList().ForEach(ctItem => ctVModels.Add(ctItem.Key.Split("-").LastOrDefault(), ctItem.Value));
|
||||
if (ctList.Any()) items[item.Key] = await GetParsDataByList(ctList, ctVModels, tenantId);
|
||||
foreach (var ctItem in vModels.Where(x => x.Key.Contains(item.Key)).ToList())
|
||||
{
|
||||
ctVModels.Add(ctItem.Key.Split("-").LastOrDefault(), ctItem.Value);
|
||||
var ctFields = fields.Find(x => x.__vModel__.Equals(ctItem.Key.Split("-").FirstOrDefault())).__config__.children;
|
||||
if (ctList.Any()) items[item.Key] = await GetParsDataByList(ctFields, ctList, ctVModels, tenantId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return oldDatas;
|
||||
}
|
||||
@@ -493,5 +481,4 @@ public class ControlParsing : ITransient
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user