This commit is contained in:
2023-05-31 10:19:05 +08:00
parent 1b65a7a9e5
commit 9c621c75cd
238 changed files with 9905 additions and 4034 deletions

View File

@@ -1,5 +1,4 @@
using System.Text.RegularExpressions;
using JNPF.Common.Const;
using JNPF.Common.Const;
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos;
using JNPF.Common.Extension;
@@ -22,7 +21,6 @@ using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
using JNPF.VisualDev.Interfaces;
using JNPF.WorkFlow.Entitys.Entity;
using Mapster;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json.Linq;
using SqlSugar;
@@ -55,53 +53,44 @@ public class FormDataParsing : ITransient
/// </summary>
private readonly ICacheManager _cacheManager;
/// <summary>
/// 缓存管理.
/// </summary>
private readonly IMemoryCache _memCache;
/// <summary>
/// 服务基础仓储.
/// </summary>
private readonly ISqlSugarRepository<VisualDevEntity> _db;
/// <summary>
/// 服务基础仓储.
/// </summary>
//private readonly ISqlSugarRepository<VisualDevEntity> _db;
private readonly ISqlSugarClient _sugar;
/// <summary>
/// 构造.
/// </summary>
/// <param name="userManager"></param>
/// <param name="cacheManager"></param>
/// <param name="databaseService"></param>
/// <param name="dataInterfaceService"></param>
/// <param name="context"></param>
public FormDataParsing(
IUserManager userManager,
ICacheManager cacheManager,
IDataBaseManager databaseService,
IDataInterfaceService dataInterfaceService,
ISqlSugarRepository<VisualDevEntity> context)
{
_userManager = userManager;
_cacheManager = cacheManager;
_databaseService = databaseService;
_dataInterfaceService = dataInterfaceService;
_db = context;
}
#endregion
/// <summary>
/// 构造.
/// </summary>
/// <param name="userManager"></param>
/// <param name="cacheManager"></param>
/// <param name="databaseService"></param>
/// <param name="dataInterfaceService"></param>
/// <param name="context"></param>
public FormDataParsing(
IUserManager userManager,
ICacheManager cacheManager,
IDataBaseManager databaseService,
IDataInterfaceService dataInterfaceService,
ISqlSugarRepository<VisualDevEntity> context,
IMemoryCache memCache)
{
_userManager = userManager;
_cacheManager = cacheManager;
_databaseService = databaseService;
_dataInterfaceService = dataInterfaceService;
_sugar = context.AsSugarClient().CopyNew();
//_db = context;
_memCache = memCache;
}
#endregion
#region
#region
/// <summary>
/// 控制模板数据转换.
/// </summary>
/// <param name="data">数据.</param>
/// <param name="fieldsModel">数据模板.</param>
/// <param name="actionType">操作类型(List-列表值,create-创建值,update-更新值,detail-详情值,transition-过渡值,query-查询).</param>
/// <returns>object.</returns>
public object TemplateControlsDataConversion(object data, FieldsModel fieldsModel, string? actionType = null)
/// <summary>
/// 控制模板数据转换.
/// </summary>
/// <param name="data">数据.</param>
/// <param name="fieldsModel">数据模板.</param>
/// <param name="actionType">操作类型(List-列表值,create-创建值,update-更新值,detail-详情值,transition-过渡值,query-查询).</param>
/// <returns>object.</returns>
public object TemplateControlsDataConversion(object data, FieldsModel fieldsModel, string? actionType = null)
{
if (fieldsModel == null || data == null || data.Equals("[]") || data.ToString().Equals("[]") || string.IsNullOrEmpty(data.ToString())) return string.Empty;
try
@@ -117,11 +106,20 @@ public class FormDataParsing : ITransient
if (fieldsModel.precision.IsNullOrEmpty()) fieldsModel.precision = 0; // 数字输入
if (data.ToString().Contains("."))
{
var len = data.ToString().Split('.').Last().Length;
if (fieldsModel.precision > len) fieldsModel.precision = len;
conversionData = data.ToString().Substring(0, data.ToString().IndexOf(".") + (int)fieldsModel.precision + 1);//modifyby zhoukeda 20230512 增加+1
conversionData = data.ParseToDouble();//modifyby zhoukeda 20230512
var dataList = data.ToString().Split('.');
if (fieldsModel.precision == 0)
{
conversionData = dataList.First();
}
else
{
if (fieldsModel.precision > dataList.Last().Length) fieldsModel.precision = dataList.Last().Length;
conversionData = dataList.First() + "." + dataList.Last().Substring(0, (int)fieldsModel.precision);
}
//conversionData = data.ToString().Substring(0, data.ToString().IndexOf(".") + (int)fieldsModel.precision + 1);//modifyby zhoukeda 20230512 增加+1
//conversionData = data.ParseToDouble();//modifyby zhoukeda 20230512
}
else if (fieldsModel.precision > 0) conversionData = data.ToString() + ".".PadRight((int)fieldsModel.precision + 1, '0');
else conversionData = data;
break;
case JnpfKeyConst.JNPFAMOUNT:
@@ -206,7 +204,10 @@ public class FormDataParsing : ITransient
conversionData = string.Format("{0:yyyy-MM-dd HH:mm:ss}", data.ToString().TimeStampToDateTime());
break;
case "create":
conversionData = string.Format("{0:yyyy-MM-dd HH:mm:ss}", data.ToString().TimeStampToDateTime());
if (fieldsModel.format.ToLower().Equals("yyyy-mm-dd"))
conversionData = string.Format("{0:yyyy-MM-dd}", data.ToString().TimeStampToDateTime());
else
conversionData = string.Format("{0:yyyy-MM-dd HH:mm:ss}", data.ToString().TimeStampToDateTime());
break;
case "detail":
conversionData = data;
@@ -435,6 +436,11 @@ public class FormDataParsing : ITransient
if (data.GetType().Name.ToLower().Equals("string")) conversionData = data;
else if (data.ToString().Contains("[")) conversionData = data.ToJsonString();
else conversionData = data;
break;
case "List":
if (fieldsModel.multiple) conversionData = data.ToString().ToObject<List<object>>();
else conversionData = data;
break;
default:
if (fieldsModel.multiple) conversionData = data.ToString().ToObject<List<object>>();
@@ -498,8 +504,9 @@ public class FormDataParsing : ITransient
/// <param name="data">插入的数据.</param>
/// <param name="_fieldsModelList">控件集合.</param>
/// <param name="actionType">操作类型.</param>
/// <param name="isShortLink">是否外链.</param>
/// <returns>string.</returns>
public object InsertValueHandle(string dbType, List<DbTableFieldModel> _tableList, string field, object data, List<FieldsModel> _fieldsModelList, string actionType = "create")
public object InsertValueHandle(string dbType, List<DbTableFieldModel> _tableList, string field, object data, List<FieldsModel> _fieldsModelList, string actionType = "create", bool isShortLink = false)
{
// 根据KEY查找模板
FieldsModel? model = _fieldsModelList.Find(f => f.__vModel__ == field);
@@ -514,7 +521,9 @@ public class FormDataParsing : ITransient
var res = TemplateControlsDataConversion(data, model, actionType);
if (actionType.Equals("create"))
{
if (model.__config__.jnpfKey.Equals(JnpfKeyConst.CREATETIME) || model.__config__.jnpfKey.Equals(JnpfKeyConst.DATE))
if (isShortLink && model.__config__.jnpfKey.Equals(JnpfKeyConst.CREATETIME))
return null;
else if(model.__config__.jnpfKey.Equals(JnpfKeyConst.CREATETIME) || model.__config__.jnpfKey.Equals(JnpfKeyConst.DATE))
return res.ToString().ParseToDateTime();
else if (model.__config__.jnpfKey.Equals(JnpfKeyConst.NUMINPUT) || model.__config__.jnpfKey.Equals(JnpfKeyConst.SWITCH))//modify by zhoukeda 2023427 开关默认数字
return res;
@@ -561,11 +570,23 @@ public class FormDataParsing : ITransient
if (vModelType.DYNAMIC.GetDescription() == configModel.dataType) list = await GetDynamicList(model);
if (vModelType.STATIC.GetDescription() == configModel.dataType)
{
foreach (Dictionary<string, object>? item in model.__slot__.options)
if (model.__slot__ != null && model.__slot__.options != null && model.__slot__.options.Any())
{
Dictionary<string, string> option = new Dictionary<string, string>();
option.Add(item[model.__config__.props.value].ToString(), item[model.__config__.props.label].ToString());
list.Add(option);
foreach (Dictionary<string, object>? item in model.__slot__.options)
{
Dictionary<string, string> option = new Dictionary<string, string>();
option.Add(item[model.__config__.props.value].ToString(), item[model.__config__.props.label].ToString());
list.Add(option);
}
}
else if (model.options != null && model.options.Any())
{
foreach (Dictionary<string, object>? item in model.options.ToObject<List<Dictionary<string, object>>>())
{
Dictionary<string, string> option = new Dictionary<string, string>();
option.Add(item[model.props.props.value].ToString(), item[model.props.props.label].ToString());
list.Add(option);
}
}
}
@@ -621,7 +642,7 @@ public class FormDataParsing : ITransient
case JnpfKeyConst.POSSELECT: // 岗位
if (!GetCacheValues(fieldCacheKey, templateData))
{
List<PositionEntity>? positionEntityList = await _sugar.Queryable<PositionEntity>().Where(u => u.DeleteMark == null).ToListAsync();
List<PositionEntity>? positionEntityList = await _db.AsSugarClient().Queryable<PositionEntity>().Where(u => u.DeleteMark == null).ToListAsync();
List<Dictionary<string, string>> positionList = new List<Dictionary<string, string>>();
foreach (PositionEntity? item in positionEntityList)
{
@@ -638,7 +659,7 @@ public class FormDataParsing : ITransient
case JnpfKeyConst.GROUPSELECT: // 分组
if (!GetCacheValues(fieldCacheKey, templateData))
{
List<GroupEntity>? positionEntityList = await _sugar.Queryable<GroupEntity>().Where(u => u.DeleteMark == null).ToListAsync();
List<GroupEntity>? positionEntityList = await _db.AsSugarClient().Queryable<GroupEntity>().Where(u => u.DeleteMark == null).ToListAsync();
List<Dictionary<string, string>> positionList = new List<Dictionary<string, string>>();
foreach (GroupEntity? item in positionEntityList)
{
@@ -655,7 +676,7 @@ public class FormDataParsing : ITransient
case JnpfKeyConst.ROLESELECT: // 角色
if (!GetCacheValues(fieldCacheKey, templateData))
{
List<RoleEntity>? positionEntityList = await _sugar.Queryable<RoleEntity>().Where(u => u.DeleteMark == null).ToListAsync();
List<RoleEntity>? positionEntityList = await _db.AsSugarClient().Queryable<RoleEntity>().Where(u => u.DeleteMark == null).ToListAsync();
List<Dictionary<string, string>> positionList = new List<Dictionary<string, string>>();
foreach (RoleEntity? item in positionEntityList)
{
@@ -689,7 +710,7 @@ public class FormDataParsing : ITransient
}
else
{
List<ProvinceEntity>? addressEntityList = await _sugar.Queryable<ProvinceEntity>().Select(x => new ProvinceEntity { Id = x.Id, ParentId = x.ParentId, Type = x.Type, FullName = x.FullName }).ToListAsync();
List<ProvinceEntity>? addressEntityList = await _db.AsSugarClient().Queryable<ProvinceEntity>().Select(x => new ProvinceEntity { Id = x.Id, ParentId = x.ParentId, Type = x.Type, FullName = x.FullName }).ToListAsync();
// 处理省市区树
addressEntityList.Where(x => x.Type == "1").ToList().ForEach(item => item.QuickQuery = item.FullName);
@@ -731,7 +752,7 @@ public class FormDataParsing : ITransient
}
else
{
List<ProvinceEntity>? addressEntityList = await _sugar.Queryable<ProvinceEntity>().Select(x => new ProvinceEntity { Id = x.Id, ParentId = x.ParentId, Type = x.Type, FullName = x.FullName }).ToListAsync();
List<ProvinceEntity>? addressEntityList = await _db.AsSugarClient().Queryable<ProvinceEntity>().Select(x => new ProvinceEntity { Id = x.Id, ParentId = x.ParentId, Type = x.Type, FullName = x.FullName }).ToListAsync();
// 处理省市区树
addressEntityList.Where(x => x.Type == "1").ToList().ForEach(item => item.QuickQuery = item.FullName);
@@ -787,7 +808,7 @@ public class FormDataParsing : ITransient
}
else
{
List<UserEntity>? userEntityList = await _sugar.Queryable<UserEntity>().Where(x => x.DeleteMark == null).Select(x => new UserEntity() { Id = x.Id, RealName = x.RealName, Account = x.Account }).ToListAsync();
List<UserEntity>? userEntityList = await _db.AsSugarClient().Queryable<UserEntity>().Where(x => x.DeleteMark == null).Select(x => new UserEntity() { Id = x.Id, RealName = x.RealName, Account = x.Account }).ToListAsync();
List<Dictionary<string, string>> userList = new List<Dictionary<string, string>>();
foreach (UserEntity? item in userEntityList)
@@ -813,32 +834,32 @@ public class FormDataParsing : ITransient
else
{
var addList = new List<Dictionary<string, string>>();
(await _sugar.Queryable<UserEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.RealName, x.Account }).ToListAsync()).ForEach(item =>
(await _db.AsSugarClient().Queryable<UserEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.RealName, x.Account }).ToListAsync()).ForEach(item =>
{
Dictionary<string, string> user = new Dictionary<string, string>();
user.Add(item.Id + "--user", item.RealName + "/" + item.Account);
addList.Add(user);
});
(await _sugar.Queryable<OrganizeEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.FullName }).ToListAsync()).ForEach(item =>
(await _db.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.FullName }).ToListAsync()).ForEach(item =>
{
Dictionary<string, string> user = new Dictionary<string, string>();
user.Add(item.Id + "--company", item.FullName);
user.Add(item.Id + "--department", item.FullName);
addList.Add(user);
});
(await _sugar.Queryable<RoleEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.FullName }).ToListAsync()).ForEach(item =>
(await _db.AsSugarClient().Queryable<RoleEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.FullName }).ToListAsync()).ForEach(item =>
{
Dictionary<string, string> user = new Dictionary<string, string>();
user.Add(item.Id + "--role", item.FullName);
addList.Add(user);
});
(await _sugar.Queryable<PositionEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.FullName }).ToListAsync()).ForEach(item =>
(await _db.AsSugarClient().Queryable<PositionEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.FullName }).ToListAsync()).ForEach(item =>
{
Dictionary<string, string> user = new Dictionary<string, string>();
user.Add(item.Id + "--position", item.FullName);
addList.Add(user);
});
(await _sugar.Queryable<GroupEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.FullName }).ToListAsync()).ForEach(item =>
(await _db.AsSugarClient().Queryable<GroupEntity>().Where(x => x.DeleteMark == null).Select(x => new { x.Id, x.FullName }).ToListAsync()).ForEach(item =>
{
Dictionary<string, string> user = new Dictionary<string, string>();
user.Add(item.Id + "--group", item.FullName);
@@ -884,7 +905,7 @@ public class FormDataParsing : ITransient
{
if (!GetCacheValues(fieldCacheKey, templateData))
{
List<OrganizeEntity>? dep_organizeEntityList = await _sugar.Queryable<OrganizeEntity>().Where(d => d.EnabledMark == 1 && d.DeleteMark == null)
List<OrganizeEntity>? dep_organizeEntityList = await _db.AsSugarClient().Queryable<OrganizeEntity>().Where(d => d.EnabledMark == 1 && d.DeleteMark == null)
.WhereIF(orgType.Equals(JnpfKeyConst.DEPSELECT), d => d.Category.Equals("department")).ToListAsync();
List<Dictionary<string, object>> vlist = new List<Dictionary<string, object>>();
@@ -954,7 +975,7 @@ public class FormDataParsing : ITransient
parameter.Add(new SugarParameter("@currentChargeorganizationAndSuborganization", subsidiary));
}
DbLinkEntity? linkEntity = await _sugar.Queryable<DbLinkEntity>().Where(m => m.Id == dynamic.DBLinkId && m.DeleteMark == null).FirstAsync();
DbLinkEntity? linkEntity = await _db.AsSugarClient().Queryable<DbLinkEntity>().Where(m => m.Id == dynamic.DBLinkId && m.DeleteMark == null).FirstAsync();
if (linkEntity == null) linkEntity = _databaseService.GetTenantDbLink(_userManager.TenantId, _userManager.TenantDbName);
_dataInterfaceService.ReplaceParameterValue(dynamic, new Dictionary<string, string>());
System.Data.DataTable? dt = _databaseService.GetInterFaceData(linkEntity, dynamic.Query, parameter.ToArray());
@@ -1064,7 +1085,7 @@ public class FormDataParsing : ITransient
/// <returns>List.</returns>
private async Task<List<Dictionary<string, string>>> GetDictionaryList(string? dictionaryTypeId = null)
{
List<DictionaryDataEntity> dictionaryDataEntityList = await _sugar.Queryable<DictionaryDataEntity, DictionaryTypeEntity>((a, b) => new JoinQueryInfos(JoinType.Left, b.Id == a.DictionaryTypeId))
List<DictionaryDataEntity> dictionaryDataEntityList = await _db.AsSugarClient().Queryable<DictionaryDataEntity, DictionaryTypeEntity>((a, b) => new JoinQueryInfos(JoinType.Left, b.Id == a.DictionaryTypeId))
.WhereIF(dictionaryTypeId.IsNotEmptyOrNull(), (a, b) => b.Id == dictionaryTypeId || b.EnCode == dictionaryTypeId).Where(a => a.DeleteMark == null).ToListAsync();
List<Dictionary<string, string>> dictionaryDataList = new List<Dictionary<string, string>>();
@@ -1141,7 +1162,7 @@ public class FormDataParsing : ITransient
Dictionary<string, object> dataMap = modelData.ToObject<Dictionary<string, object>>(); // 数据库保存的F_Data
// 序列化后时间戳转换处理
List<FieldsModel>? timeList = formData.Where(x => x.__config__.jnpfKey == "createTime" || x.__config__.jnpfKey == "modifyTime").ToList();
List<FieldsModel>? timeList = formData.Where(x => x.__config__.jnpfKey == JnpfKeyConst.CREATETIME || x.__config__.jnpfKey == JnpfKeyConst.MODIFYTIME).ToList();
if (timeList.Any())
{
timeList.ForEach(item =>
@@ -1185,10 +1206,10 @@ public class FormDataParsing : ITransient
break;
case JnpfKeyConst.CREATEUSER:
case JnpfKeyConst.MODIFYUSER:
dataMap[key] = await _sugar.Queryable<UserEntity>().Where(x => x.Id == dataValue).Select(x => SqlFunc.MergeString(x.RealName, "/", x.Account)).FirstAsync();
dataMap[key] = await _db.AsSugarClient().Queryable<UserEntity>().Where(x => x.Id == dataValue).Select(x => SqlFunc.MergeString(x.RealName, "/", x.Account)).FirstAsync();
break;
case JnpfKeyConst.CURRPOSITION:
dataMap[key] = (await _sugar.Queryable<PositionEntity>().FirstAsync(p => p.Id == dataMap[key].ToString()))?.FullName;
dataMap[key] = (await _db.AsSugarClient().Queryable<PositionEntity>().FirstAsync(p => p.Id == dataMap[key].ToString()))?.FullName;
if (dataMap[key].IsNullOrEmpty()) dataMap[key] = " ";
break;
case JnpfKeyConst.CURRORGANIZE:
@@ -1267,111 +1288,6 @@ public class FormDataParsing : ITransient
#endregion
#region
/// <summary>
/// 无表的数据筛选.
/// </summary>
/// <param name="list">数据列表.</param>
/// <param name="keyJsonMap">查询条件值.</param>
/// <param name="formData"></param>
/// <returns></returns>
public List<Dictionary<string, object>> GetNoTableFilteringData(List<VisualDevModelDataEntity> list, Dictionary<string, object> keyJsonMap, List<FieldsModel> formData)
{
List<Dictionary<string, object>> realList = new List<Dictionary<string, object>>();
foreach (var entity in list)
{
Dictionary<string, object> query = keyJsonMap;
Dictionary<string, object> realEntity = entity.Data.ToObject<Dictionary<string, object>>();
realEntity.Add("id", entity.Id);
if (query != null && query.Count != 0)
{
int m = 0;
int dicCount = query.Keys.Count;
string[] strKey = new string[dicCount];
query.Keys.CopyTo(strKey, 0);
for (int i = 0; i < strKey.Length; i++)
{
var keyValue = keyJsonMap[strKey[i]];
var queryEntity = realEntity.Where(e => e.Key == strKey[i]).FirstOrDefault();
var model = formData.Where(f => f.__vModel__ == strKey[i]).FirstOrDefault();
if (queryEntity.Value != null && !string.IsNullOrWhiteSpace(keyValue.ToString()))
{
var realValue = queryEntity.Value.ObjToString();
var type = model.__config__.jnpfKey;
switch (type)
{
case JnpfKeyConst.TIME:
{
var queryTime = new List<string>();
keyValue.ToObject<List<string>>().ForEach(item => { if (!string.IsNullOrWhiteSpace(item)) queryTime.Add(item.ParseToDateTime().ToLongTimeString()); });
if (Common.Extension.Extensions.IsInTimeRange(realValue.ParseToDateTime(), queryTime.First(), queryTime.Last(), 3)) m++;
}
break;
case JnpfKeyConst.DATE:
{
List<string> queryTime = keyValue.ToObject<List<string>>();
int formatType = 0;
if (model.format == "yyyy-MM") formatType = 1;
else if (model.format == "yyyy") formatType = 2;
string value1 = string.Format("{0:yyyy-MM-dd}", queryTime.First().ParseToDateTime());
string value2 = string.Format("{0:yyyy-MM-dd}", queryTime.Last().ParseToDateTime());
if (Common.Extension.Extensions.IsInTimeRange(realValue.ParseToDateTime(), value1, value2, formatType)) m++;
}
break;
case JnpfKeyConst.CREATETIME:
case JnpfKeyConst.MODIFYTIME:
{
List<string> dayTime1 = keyValue.ToObject<List<string>>();
string value1 = string.Format("{0:yyyy-MM-dd 00:00:00}", dayTime1.First().ParseToDateTime());
string value2 = string.Format("{0:yyyy-MM-dd 23:59:59}", dayTime1.Last().ParseToDateTime());
if (!string.IsNullOrEmpty(realValue) && Common.Extension.Extensions.IsInTimeRange(Convert.ToDateTime(realValue), value1, value2)) m++;
}
break;
case JnpfKeyConst.NUMINPUT:
case JnpfKeyConst.CALCULATE:
{
List<string> numArray = keyValue.ToObject<List<string>>();
var numA = numArray.First().ParseToInt();
var numB = numArray.Last() == null ? long.MaxValue : numArray.Last().ParseToInt();
var numC = realValue.ParseToInt();
if (numC >= numA && numC <= numB) m++;
}
break;
default:
if (realValue.IsNotEmptyOrNull() && keyValue != null)
{
string keyV = keyValue.ToString();
if (model.searchType == 2 && realValue.Contains(keyV)) m++;
else if (model.searchType == 1)
{
// 多选时为模糊查询
if ((model.multiple || type == "checkbox") && realValue.Contains(keyV)) m++;
else if (realValue.Equals(keyV)) m++;
}
else if (realValue.Replace(" ", "").Contains(keyV.Replace(" ", ""))) m++;
}
break;
}
}
if (m == dicCount) realList.Add(realEntity);
}
}
else
{
realList.Add(realEntity);
}
}
return realList;
}
#endregion
#region (Id Name)
/// <summary>
@@ -1383,17 +1299,31 @@ public class FormDataParsing : ITransient
/// <param name="actionType"></param>
/// <param name="webType">表单类型1-纯表单、2-普通表单、3-工作流表单.</param>
/// <param name="primaryKey">数据主键.</param>
/// <param name="mainData">子表解析时调用 (控件联动可能需要主表的数据).</param>
/// <param name="isShortLink">是否外链.</param>
/// <returns></returns>
public async Task<List<Dictionary<string, object>>> GetKeyData(
List<FieldsModel> formData,
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)
bool isShortLink = false)
{
if (isShortLink)
{
formData = formData.Where(x => x.__config__.jnpfKey == JnpfKeyConst.COMINPUT || x.__config__.jnpfKey == JnpfKeyConst.TEXTAREA
|| (x.__config__.jnpfKey == JnpfKeyConst.NUMINPUT && x.__config__.jnpfKey == JnpfKeyConst.SWITCH)
|| (x.__config__.jnpfKey == JnpfKeyConst.RADIO && x.__config__.dataType.Equals("static"))
|| (x.__config__.jnpfKey == JnpfKeyConst.CHECKBOX && x.__config__.dataType.Equals("static"))
|| (x.__config__.jnpfKey == JnpfKeyConst.SELECT && x.__config__.dataType.Equals("static"))
|| (x.__config__.jnpfKey == JnpfKeyConst.CASCADER && x.__config__.dataType.Equals("static"))
|| (x.__config__.jnpfKey == JnpfKeyConst.TREESELECT && x.__config__.dataType.Equals("static"))
|| x.__config__.jnpfKey == JnpfKeyConst.DATE || x.__config__.jnpfKey == JnpfKeyConst.TIME || x.__config__.jnpfKey == JnpfKeyConst.COLORPICKER
|| x.__config__.jnpfKey == JnpfKeyConst.RATE || x.__config__.jnpfKey == JnpfKeyConst.SLIDER || x.__config__.jnpfKey == JnpfKeyConst.EDITOR
|| x.__config__.jnpfKey == JnpfKeyConst.LINK || x.__config__.jnpfKey == JnpfKeyConst.JNPFTEXT || x.__config__.jnpfKey == JnpfKeyConst.ALERT)
.Where(x => !x.__config__.jnpfKey.Equals(JnpfKeyConst.POPUPTABLESELECT)).ToList();
}
// 获取控件缓存数据
Dictionary<string, object> templateData = await GetVisualDevCaCheData(formData);
@@ -1418,12 +1348,13 @@ public class FormDataParsing : ITransient
List<Dictionary<string, string>>? roleTemplateValue = new List<Dictionary<string, string>>(); // 角色
Dictionary<string, List<Dictionary<string, string>>>? templateValues = new Dictionary<string, List<Dictionary<string, string>>>(); // 其他
if (webType == 3)
if (webType == 3 && list.Any(x => x.ContainsKey(primaryKey)))
{
var ids = list.Select(x => x[primaryKey]).ToList();
var flowTaskList = await _sugar.Queryable<FlowTaskEntity>().Where(x => ids.Contains(x.Id)).Select(x => new FlowTaskEntity() { Id = x.Id, Status = x.Status }).ToListAsync();
var flowTaskList = await _db.AsSugarClient().Queryable<FlowTaskEntity>().Where(x => ids.Contains(x.Id)).Select(x => new FlowTaskEntity() { Id = x.Id, Status = x.Status }).ToListAsync();
list.ForEach(item =>
{
if (item.ContainsKey("F_FlowId")) item["flowId"] = item["F_FlowId"];
if (flowTaskList.Any(x => x.Id.Equals(item[primaryKey].ToString())))
{
var flowTask = flowTaskList.Where(x => x.Id.Equals(item[primaryKey].ToString())).FirstOrDefault();
@@ -1442,7 +1373,6 @@ 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;
@@ -1455,7 +1385,6 @@ public class FormDataParsing : ITransient
if (!(dataMap[strKey[i]] is null))
{
FieldsModel? form = formData.Where(f => f.__vModel__ == strKey[i]).FirstOrDefault();
if (form != null)
{
if (form.__vModel__.Contains(form.__config__.jnpfKey + "Field")) dataMap[strKey[i]] = TemplateControlsDataConversion(dataMap[strKey[i]], form);
@@ -1707,30 +1636,18 @@ public class FormDataParsing : ITransient
}
break;
case JnpfKeyConst.CURRDEPT:
dataMap[key] = await _memCache.GetOrCreateAsync($"organizeId_{dataValue}", async entry =>
{
entry.SlidingExpiration = TimeSpan.FromSeconds(60);
return (await _sugar.Queryable<OrganizeEntity>().FirstAsync(x => x.Id == dataValue.ToString()))?.FullName;
});
dataMap[key] = (await _db.AsSugarClient().Queryable<OrganizeEntity>().FirstAsync(x => x.Id == dataValue.ToString()))?.FullName;
break;
case JnpfKeyConst.MODIFYUSER:
case JnpfKeyConst.CREATEUSER:
dataMap[key] = await _memCache.GetOrCreateAsync($"userId_{dataValue}", async entry =>
{
entry.SlidingExpiration = TimeSpan.FromSeconds(60);
return await _sugar.Queryable<UserEntity>().Where(x => x.Id == dataValue.ToString()).Select(x => SqlFunc.MergeString(x.RealName, "/", x.Account)).FirstAsync();
});
dataMap[key] = await _db.AsSugarClient().Queryable<UserEntity>().Where(x => x.Id == dataValue.ToString()).Select(x => SqlFunc.MergeString(x.RealName, "/", x.Account)).FirstAsync();
break;
case JnpfKeyConst.MODIFYTIME:
case JnpfKeyConst.CREATETIME:
dataMap[key] = string.Format("{0:yyyy-MM-dd HH:mm:ss}", dataMap[key].ToString().ParseToDateTime());
dataMap[key] = string.Format("{0:yyyy-MM-dd HH:mm}", dataMap[key].ToString().ParseToDateTime());
break;
case JnpfKeyConst.CURRPOSITION:
dataMap[key] = await _memCache.GetOrCreateAsync($"positionId_{dataValue}", async entry =>
{
entry.SlidingExpiration = TimeSpan.FromSeconds(60);
return (await _sugar.Queryable<PositionEntity>().FirstAsync(x => x.Id == dataValue.ToString()))?.FullName;
});
dataMap[key] = (await _db.AsSugarClient().Queryable<PositionEntity>().FirstAsync(x => x.Id == dataValue.ToString()))?.FullName;
break;
case JnpfKeyConst.POPUPTABLESELECT:
case JnpfKeyConst.POPUPSELECT:
@@ -1883,7 +1800,7 @@ public class FormDataParsing : ITransient
else
{
// 根据可视化功能ID获取该模板全部数据
var relationFormModel = await _sugar.Queryable<VisualDevEntity>().FirstAsync(v => v.Id == model.modelId);
var relationFormModel = await _db.AsSugarClient().Queryable<VisualDevEntity>().FirstAsync(v => v.Id == model.modelId);
var newFieLdsModelList = relationFormModel.FormData.ToObject<FormDataModel>().fields.FindAll(x => model.relationField.Equals(x.__vModel__));
VisualDevModelListQueryInput listQueryInput = new VisualDevModelListQueryInput
{
@@ -1892,27 +1809,21 @@ public class FormDataParsing : ITransient
sort = columnDesign.sort,
pageSize = 999999
};
//Scoped.Create(async (_, scope) =>
//{
// var services = scope.ServiceProvider;
// var _runService = App.GetService<IRunService>(services);
// var res = await _runService.GetRelationFormList(relationFormModel, listQueryInput);
// _cacheManager.Set(redisName, res.list.ToList(), TimeSpan.FromMinutes(10)); // 缓存10分钟
//});
var cacheStr = _cacheManager.Get(redisName);
if (cacheStr.IsNotEmptyOrNull()) relationFormDataList = cacheStr.ToObject<List<Dictionary<string, object>>>();
//modified by PhilPan
if (string.IsNullOrEmpty(cacheStr))
else
{
await Scoped.CreateAsync(async (_, scope) =>
Scoped.Create((_, scope) =>
{
var services = scope.ServiceProvider;
var _runService = App.GetService<IRunService>(services);
var res = await _runService.GetRelationFormList(relationFormModel, listQueryInput);
_cacheManager.Set(redisName, res.list.ToList(), TimeSpan.FromMinutes(10)); // 缓存10分钟
cacheStr = _cacheManager.Get(redisName);
});
var res = _runService.GetRelationFormList(relationFormModel, listQueryInput).WaitAsync(TimeSpan.FromMinutes(2)).Result;
relationFormDataList = res.list.ToList();
_cacheManager.Set(redisName, relationFormDataList, TimeSpan.FromMinutes(10)); // 缓存10分钟
});
}
if (cacheStr.IsNotEmptyOrNull()) relationFormDataList = cacheStr.ToObject<List<Dictionary<string, object>>>();
}
var relationFormRealData = relationFormDataList.Where(it => it["id"].Equals(dataMap[key])).FirstOrDefault();
@@ -1990,36 +1901,16 @@ 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;
}
}
});
form.__config__.templateJson.ForEach(x => x.defaultValue = (dataMap.ContainsKey(x.relationField) && dataMap[x.relationField] != null) ? dataMap[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>>>();
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());
if (comData != null) data.Add(comData[form.__config__.props.label].ToString());
else data.Add(item.ToString());
}
}
@@ -2055,7 +1946,7 @@ public class FormDataParsing : ITransient
/// <param name="_dataMap"></param>
public void GetBARAndQR(List<FieldsModel> fieldsModels, Dictionary<string, object> _newDataMap, Dictionary<string, object> _dataMap)
{
fieldsModels.Where(x => x.__config__.jnpfKey == "barcode" || x.__config__.jnpfKey == "qrcode").Where(x => !string.IsNullOrWhiteSpace(x.relationField)).ToList().ForEach(item =>
fieldsModels.Where(x => x.__config__.jnpfKey == JnpfKeyConst.BARCODE || x.__config__.jnpfKey == JnpfKeyConst.QRCODE).Where(x => !string.IsNullOrWhiteSpace(x.relationField)).ToList().ForEach(item =>
{
if (!_newDataMap.ContainsKey(item.relationField + "_id") && _dataMap.ContainsKey(item.relationField))
_newDataMap.Add(item.relationField + "_id", _dataMap[item.relationField]);