将Engine中的CodeGen移入到VisualDev
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using JNPF.Common.Const;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Dtos;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Filter;
|
||||
using JNPF.Common.Manager;
|
||||
using JNPF.Common.Models;
|
||||
using JNPF.Common.Security;
|
||||
@@ -18,6 +20,7 @@ using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using JNPF.WorkFlow.Entitys.Entity;
|
||||
using Mapster;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
|
||||
@@ -1368,8 +1371,16 @@ public class FormDataParsing : ITransient
|
||||
/// <param name="actionType"></param>
|
||||
/// <param name="webType">表单类型1-纯表单、2-普通表单、3-工作流表单.</param>
|
||||
/// <param name="primaryKey">数据主键.</param>
|
||||
/// <param name="mainData">子表解析时调用 (控件联动可能需要主表的数据).</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Dictionary<string, object>>> GetKeyData(List<FieldsModel> formData, List<Dictionary<string, object>> list, ColumnDesignModel? columnDesign = null, string actionType = "List", int webType = 2, string primaryKey = "F_Id")
|
||||
public async Task<List<Dictionary<string, object>>> GetKeyData(
|
||||
List<FieldsModel> formData,
|
||||
List<Dictionary<string, object>> list,
|
||||
ColumnDesignModel? columnDesign = null,
|
||||
string actionType = "List",
|
||||
int webType = 2,
|
||||
string primaryKey = "F_Id",
|
||||
Dictionary<string, object>? mainData = null)
|
||||
{
|
||||
// 获取控件缓存数据
|
||||
Dictionary<string, object> templateData = await GetVisualDevCaCheData(formData);
|
||||
@@ -1386,6 +1397,7 @@ public class FormDataParsing : ITransient
|
||||
List<Dictionary<string, string>>? userselectTemplateValue = new List<Dictionary<string, string>>(); // 用户
|
||||
List<Dictionary<string, string>>? usersselectTemplateValue = new List<Dictionary<string, string>>(); // 用户组件
|
||||
List<Dictionary<string, string>>? posselectTemplateValue = new List<Dictionary<string, string>>(); // 岗位
|
||||
List<Dictionary<string, string>>? radioTemplateValue = new List<Dictionary<string, string>>(); // 单选框
|
||||
List<Dictionary<string, string>>? checkboxTemplateValue = new List<Dictionary<string, string>>(); // 复选框
|
||||
List<Dictionary<string, string>>? selectTemplateValue = new List<Dictionary<string, string>>(); // 下拉框
|
||||
List<Dictionary<string, string>>? treeSelectTemplateValue = new List<Dictionary<string, string>>(); // 树
|
||||
@@ -1417,6 +1429,8 @@ public class FormDataParsing : ITransient
|
||||
// 转换列表数据
|
||||
foreach (Dictionary<string, object>? dataMap in list)
|
||||
{
|
||||
var oldDataMap = dataMap.Copy();
|
||||
if (mainData != null) oldDataMap.Add("JnpfKeyConst_MainData", mainData);
|
||||
if (dataMap.ContainsKey(primaryKey)) dataMap["id"] = dataMap[primaryKey].ToString(); // 主键
|
||||
|
||||
int dicCount = dataMap.Keys.Count;
|
||||
@@ -1571,17 +1585,20 @@ public class FormDataParsing : ITransient
|
||||
case JnpfKeyConst.POSSELECT:
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(posselectTemplateValue, templateValue, moreValue, form);
|
||||
break;
|
||||
case JnpfKeyConst.RADIO:
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(radioTemplateValue, templateValue, moreValue, form, formData, oldDataMap);
|
||||
break;
|
||||
case JnpfKeyConst.CHECKBOX:
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(checkboxTemplateValue, templateValue, moreValue, form);
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(checkboxTemplateValue, templateValue, moreValue, form, formData, oldDataMap);
|
||||
break;
|
||||
case JnpfKeyConst.SELECT:
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(selectTemplateValue, templateValue, moreValue, form);
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(selectTemplateValue, templateValue, moreValue, form, formData, oldDataMap);
|
||||
break;
|
||||
case JnpfKeyConst.TREESELECT:
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(treeSelectTemplateValue, templateValue, moreValue, form);
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(treeSelectTemplateValue, templateValue, moreValue, form, formData, oldDataMap);
|
||||
break;
|
||||
case JnpfKeyConst.CASCADER:
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(cascaderTemplateValue, templateValue, moreValue, form);
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(cascaderTemplateValue, templateValue, moreValue, form, formData, oldDataMap);
|
||||
break;
|
||||
case JnpfKeyConst.GROUPSELECT:
|
||||
dataMap[strKey[i]] = GetTemplateDataValueByKey(groupTemplateValue, templateValue, moreValue, form);
|
||||
@@ -1892,8 +1909,10 @@ public class FormDataParsing : ITransient
|
||||
/// <param name="tValue">所有的缓存</param>
|
||||
/// <param name="mValue">要转换的key</param>
|
||||
/// <param name="form">组件</param>
|
||||
/// <param name="fieldList">所有组件(控件联动会用到)</param>
|
||||
/// <param name="dataMap">当前行数据(控件联动会用到)</param>
|
||||
/// <returns></returns>
|
||||
private string GetTemplateDataValueByKey(List<Dictionary<string, string>> keyTData, KeyValuePair<string, object> tValue, IEnumerable<object> mValue, FieldsModel? form)
|
||||
private string GetTemplateDataValueByKey(List<Dictionary<string, string>> keyTData, KeyValuePair<string, object> tValue, IEnumerable<object> mValue, FieldsModel? form, List<FieldsModel>? fieldList = null, Dictionary<string, object>? dataMap = null)
|
||||
{
|
||||
List<string>? data = new List<string>();
|
||||
if (keyTData.Count < 1) keyTData = tValue.Value.ToObject<List<Dictionary<string, string>>>();
|
||||
@@ -1909,6 +1928,7 @@ public class FormDataParsing : ITransient
|
||||
if (cascaderData != null) sb.Add(cascaderData[items]);
|
||||
});
|
||||
if (sb.Count != 0) data.Add(string.Join("/", sb));
|
||||
else data.Add(item.ToString());
|
||||
}
|
||||
}
|
||||
else if (form.IsNotEmptyOrNull() && form.__config__.IsNotEmptyOrNull() && form.__config__.props.IsNotEmptyOrNull() && form.__config__.props.value.IsNotEmptyOrNull() && form.__config__.props.label.IsNotEmptyOrNull())
|
||||
@@ -1930,6 +1950,45 @@ public class FormDataParsing : ITransient
|
||||
}
|
||||
}
|
||||
|
||||
// 控件联动
|
||||
if (data.ToJsonString().Equals(mValue.ToJsonString()) && (form.__config__.templateJson != null && form.__config__.templateJson.Any()))
|
||||
{
|
||||
data.Clear();
|
||||
form.__config__.templateJson.ForEach(x =>
|
||||
{
|
||||
if (x.relationField.ToLower().Contains("tablefield") && x.relationField.Contains("-"))
|
||||
{
|
||||
var rField = x.relationField.Split("-").Last();
|
||||
if (dataMap.ContainsKey(rField)) x.defaultValue = dataMap[rField] != null ? dataMap[rField]?.ToString() : x.defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dataMap.ContainsKey(x.relationField))
|
||||
{
|
||||
x.defaultValue = dataMap[x.relationField] != null ? dataMap[x.relationField]?.ToString() : x.defaultValue;
|
||||
}
|
||||
else if (dataMap.ContainsKey("JnpfKeyConst_MainData"))
|
||||
{
|
||||
var mainData = dataMap["JnpfKeyConst_MainData"].ToObject<Dictionary<string, object>>();
|
||||
if (mainData.ContainsKey(x.relationField)) x.defaultValue = mainData[x.relationField] != null ? mainData[x.relationField]?.ToString() : x.defaultValue;
|
||||
}
|
||||
}
|
||||
});
|
||||
_databaseService.ChangeDataBase(_databaseService.GetTenantDbLink(_userManager.TenantId, _userManager.TenantDbName));
|
||||
var res = _dataInterfaceService.GetResponseByType(form.__config__.propsUrl, 0, string.Empty, new Common.Dtos.VisualDev.VisualDevDataFieldDataListInput() { paramList = form.__config__.templateJson.Adapt<List<DataInterfaceReqParameterInfo>>(), pageSize = 500, currentPage = 1 }).Result;
|
||||
var resList = res.ToObject<PageResult<Dictionary<string,object>>>();
|
||||
if (resList != null && resList.list.Any())
|
||||
{
|
||||
foreach (object? item in mValue)
|
||||
{
|
||||
var comData = resList.list.Where(a => a.ContainsValue(item.ToString())).FirstOrDefault();
|
||||
var props = form.__config__.props != null ? form.__config__.props.label : form.props.props.label;
|
||||
if (comData != null) data.Add(comData[props].ToString());
|
||||
else data.Add(item.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string.Join(form.separator, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -282,6 +282,7 @@ public class TemplateParsingBase
|
||||
/// <param name="uploaderKey">导入导出数据列名集合.</param>
|
||||
/// <param name="_dataType">导入类型 1 新增, 2 新增和修改.</param>
|
||||
/// <param name="enableFlow">是否开启流程 1 开启.</param>
|
||||
/// <param name="flowFormId">流程表单Id.</param>
|
||||
public TemplateParsingBase(
|
||||
DbLinkEntity dblink,
|
||||
List<FieldsModel> fieldList,
|
||||
@@ -290,9 +291,11 @@ public class TemplateParsingBase
|
||||
int webType,
|
||||
int primaryKeyPolicy,
|
||||
List<string> uploaderKey,
|
||||
string _dataType, int enableFlow = 0)
|
||||
string _dataType,
|
||||
int enableFlow = 0,
|
||||
string flowFormId = "")
|
||||
{
|
||||
if (enableFlow.Equals(1)) visualDevEntity = new VisualDevEntity() { EnableFlow = 1 };
|
||||
if (enableFlow.Equals(1)) visualDevEntity = new VisualDevEntity() { EnableFlow = 1, Id = flowFormId };
|
||||
DbLink = dblink;
|
||||
AllTable = tables.ToObject<List<TableModel>>(); // 所有表
|
||||
FieldsModelList = fieldList;
|
||||
|
||||
@@ -24,9 +24,7 @@ using JNPF.VisualDev.Interfaces;
|
||||
using JNPF.WorkFlow.Entitys.Entity;
|
||||
using JNPF.WorkFlow.Interfaces.Repository;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using SqlSugar;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace JNPF.VisualDev;
|
||||
|
||||
@@ -205,7 +203,9 @@ public class RunService : IRunService, ITransient
|
||||
|
||||
if (realList.list.Any())
|
||||
{
|
||||
realList.list = await _formDataParsing.GetKeyData(templateInfo.SingleFormData, realList.list, templateInfo.ColumnData, actionType, templateInfo.WebType, primaryKey);
|
||||
if (templateInfo.SingleFormData.Any(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()))
|
||||
realList.list = await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()).ToList(), realList.list, templateInfo.ColumnData, actionType, templateInfo.WebType, primaryKey);
|
||||
realList.list = await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => x.__config__.templateJson == null).ToList(), realList.list, templateInfo.ColumnData, actionType, templateInfo.WebType, primaryKey);
|
||||
|
||||
// 如果是无表数据并且排序字段不为空,再进行数据排序
|
||||
if (!templateInfo.IsHasTable && input.sidx.IsNotEmptyOrNull())
|
||||
@@ -338,7 +338,9 @@ public class RunService : IRunService, ITransient
|
||||
|
||||
if (realList.list.Any())
|
||||
{
|
||||
realList.list = await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => !x.__config__.jnpfKey.Equals(JnpfKeyConst.RELATIONFORM)).ToList(), realList.list, templateInfo.ColumnData, actionType, templateInfo.WebType.ParseToInt(), primaryKey);
|
||||
if (templateInfo.SingleFormData.Any(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()))
|
||||
realList.list = await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()).ToList(), realList.list, templateInfo.ColumnData, actionType, templateInfo.WebType, primaryKey);
|
||||
realList.list = await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => !x.__config__.jnpfKey.Equals(JnpfKeyConst.RELATIONFORM) && x.__config__.templateJson == null).ToList(), realList.list, templateInfo.ColumnData, actionType, templateInfo.WebType.ParseToInt(), primaryKey);
|
||||
|
||||
if (input.queryJson.IsNotEmptyOrNull())
|
||||
{
|
||||
@@ -539,14 +541,23 @@ public class RunService : IRunService, ITransient
|
||||
if (childModelData.Count > 0)
|
||||
{
|
||||
// 将关键字查询传输的id转换成名称
|
||||
newDataMap[strKey[i]] = await _formDataParsing.GetKeyData(model.__config__.children, childModelData, templateInfo.ColumnData.ToObject<ColumnDesignModel>());
|
||||
if (model.__config__.children.Any(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()))
|
||||
newDataMap[strKey[i]] = await _formDataParsing.GetKeyData(model.__config__.children.Where(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()).ToList(), childModelData, templateInfo.ColumnData, "List", 2, "F_Id", dataMap);
|
||||
newDataMap[strKey[i]] = await _formDataParsing.GetKeyData(model.__config__.children.Where(x => x.__config__.templateJson == null).ToList(), childModelData, templateInfo.ColumnData.ToObject<ColumnDesignModel>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Dictionary<string, object>> listEntity = new List<Dictionary<string, object>>() { dataMap };
|
||||
|
||||
foreach (var entryMap in (await _formDataParsing.GetKeyData(templateInfo.SingleFormData, listEntity, templateInfo.ColumnData)).FirstOrDefault())
|
||||
// 控件联动
|
||||
var tempDataMap = new Dictionary<string, object>();
|
||||
if (templateInfo.SingleFormData.Any(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()))
|
||||
tempDataMap = (await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()).ToList(), listEntity, templateInfo.ColumnData)).FirstOrDefault();
|
||||
tempDataMap = (await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => x.__config__.templateJson == null).ToList(), listEntity, templateInfo.ColumnData)).FirstOrDefault();
|
||||
|
||||
// 将关键字查询传输的id转换成名称
|
||||
foreach (var entryMap in tempDataMap)
|
||||
{
|
||||
if (entryMap.Value != null)
|
||||
{
|
||||
@@ -820,7 +831,6 @@ public class RunService : IRunService, ITransient
|
||||
templateInfo.DbLink = await GetDbLink(templateEntity.DbLinkId);
|
||||
return await GetUpdateSqlByTemplate(templateInfo, visualdevModelDataUpForm, id);
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetUpdateSqlByTemplate(TemplateParsingBase templateInfo, VisualDevModelDataUpInput visualdevModelDataUpForm, string id)
|
||||
{
|
||||
Dictionary<string, object>? allDataMap = visualdevModelDataUpForm.data.ToObject<Dictionary<string, object>>();
|
||||
@@ -2207,6 +2217,7 @@ public class RunService : IRunService, ITransient
|
||||
|
||||
var idField = templateInfo.AllTable.Where(x => x.table.Equals(item.Key)).First().tableField;
|
||||
var itemSql = string.Format(sqlStr, idField.IsNullOrEmpty() ? primaryKey : idField, item.Key);
|
||||
dataPermissionsList = GetIConditionalModelListByTableName(dataPermissionsList, item.Key);// 删除非当前表条件
|
||||
var itemWhere = _visualDevRepository.AsSugarClient().SqlQueryable<dynamic>("@").Where(item.Value).Where(dataPermissionsList).ToSqlString();
|
||||
if (itemWhere.Contains("WHERE"))
|
||||
{
|
||||
@@ -2348,6 +2359,32 @@ public class RunService : IRunService, ITransient
|
||||
|
||||
return sql;
|
||||
}
|
||||
private List<IConditionalModel> GetIConditionalModelListByTableName(List<IConditionalModel> cList, string tableName)
|
||||
{
|
||||
for (int i = 0; i < cList.Count; i++)
|
||||
{
|
||||
if (cList[i] is ConditionalTree)
|
||||
{
|
||||
var newItem = (ConditionalTree)cList[i];
|
||||
for (int j = 0; j < newItem.ConditionalList.Count; j++)
|
||||
{
|
||||
var value = GetIConditionalModelListByTableName(new List<IConditionalModel>() { newItem.ConditionalList[j].Value }, tableName);
|
||||
if (value != null && value.Any()) newItem.ConditionalList[j] = new KeyValuePair<WhereType, IConditionalModel>(newItem.ConditionalList[j].Key, value.First());
|
||||
else newItem.ConditionalList.RemoveAt(j);
|
||||
}
|
||||
|
||||
if(newItem.ConditionalList.Any()) cList[i] = newItem;
|
||||
else cList.RemoveAt(i);
|
||||
}
|
||||
else if (cList[i] is ConditionalModel)
|
||||
{
|
||||
var newItem = (ConditionalModel)cList[i];
|
||||
if (!newItem.FieldName.Contains(tableName)) cList.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
return cList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 组装单条信息查询sql.
|
||||
@@ -3050,8 +3087,9 @@ public class RunService : IRunService, ITransient
|
||||
});
|
||||
if (pList.Any())
|
||||
{
|
||||
var json = pList.ToJsonString();
|
||||
json = json.Replace(item.Key + ".", string.Empty);
|
||||
dataPermissionsList = _visualDevRepository.AsSugarClient().Utilities.JsonToConditionalModels(pList.ToJsonString());
|
||||
dataPermissionsList = GetIConditionalModelListByTableName(dataPermissionsList, item.Key);
|
||||
var json = dataPermissionsList.ToJsonString().Replace(item.Key + ".", string.Empty);
|
||||
dataPermissionsList = _visualDevRepository.AsSugarClient().Utilities.JsonToConditionalModels(json);
|
||||
}
|
||||
}
|
||||
@@ -3066,7 +3104,11 @@ public class RunService : IRunService, ITransient
|
||||
{
|
||||
var rows = dt.Where(x => x[relationField[item.Key]].ToString().Equals(it[primaryKey].ToString())).ToList();
|
||||
var childTableModel = templateInfo.ChildTableFieldsModelList.First(x => x.__vModel__.Equals(vModel));
|
||||
var datas = await _formDataParsing.GetKeyData(childTableModel.__config__.children, rows, templateInfo.ColumnData.ToObject<ColumnDesignModel>());
|
||||
|
||||
var datas = new List<Dictionary<string, object>>();
|
||||
if (childTableModel.__config__.children.Any(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()))
|
||||
datas = (await _formDataParsing.GetKeyData(childTableModel.__config__.children.Where(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()).ToList(), rows, templateInfo.ColumnData, "List",2, "F_Id", it));
|
||||
datas = await _formDataParsing.GetKeyData(childTableModel.__config__.children.Where(x => x.__config__.templateJson == null).ToList(), rows, templateInfo.ColumnData);
|
||||
var newDatas = datas.Copy();
|
||||
newDatas.ForEach(x => x.Remove(relationField[item.Key]));
|
||||
it.Add(vModel, newDatas);
|
||||
|
||||
Reference in New Issue
Block a user