😎代码优化
This commit is contained in:
parent
a0d49e9aa9
commit
c38e4f87f9
@ -13,7 +13,7 @@ namespace Admin.NET.Core;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class RedisQueue
|
public static class RedisQueue
|
||||||
{
|
{
|
||||||
private static ICacheProvider _cacheProvider = App.GetService<ICacheProvider>();
|
private static ICacheProvider _cacheProvider = App.GetRequiredService<ICacheProvider>();
|
||||||
|
|
||||||
/// <summary>创建Redis消息队列。默认消费一次,指定消费者group时使用STREAM结构,支持多消费组共享消息</summary>
|
/// <summary>创建Redis消息队列。默认消费一次,指定消费者group时使用STREAM结构,支持多消费组共享消息</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
|||||||
@ -276,25 +276,25 @@ public static class CommonUtil
|
|||||||
// 整理导入对象的属性名称,<字典数据,原属性信息,目标属性信息>
|
// 整理导入对象的属性名称,<字典数据,原属性信息,目标属性信息>
|
||||||
var propMappings = new Dictionary<string, Tuple<Dictionary<string, object>, PropertyInfo, PropertyInfo>>();
|
var propMappings = new Dictionary<string, Tuple<Dictionary<string, object>, PropertyInfo, PropertyInfo>>();
|
||||||
|
|
||||||
var dictService = App.GetService<SqlSugarRepository<SysDictData>>();
|
var dictService = App.GetRequiredService<SqlSugarRepository<SysDictData>>();
|
||||||
var tSourceProps = typeof(TSource).GetProperties().ToList();
|
var tSourceProps = typeof(TSource).GetProperties().ToList();
|
||||||
var tTargetProps = typeof(TTarget).GetProperties().ToDictionary(m => m.Name);
|
var tTargetProps = typeof(TTarget).GetProperties().ToDictionary(u => u.Name);
|
||||||
foreach (var propertyInfo in tSourceProps)
|
foreach (var propertyInfo in tSourceProps)
|
||||||
{
|
{
|
||||||
var attrs = propertyInfo.GetCustomAttribute<ImportDictAttribute>();
|
var attrs = propertyInfo.GetCustomAttribute<ImportDictAttribute>();
|
||||||
if (attrs != null && !string.IsNullOrWhiteSpace(attrs.TypeCode))
|
if (attrs != null && !string.IsNullOrWhiteSpace(attrs.TypeCode))
|
||||||
{
|
{
|
||||||
var targetProp = tTargetProps[attrs.TargetPropName];
|
var targetProp = tTargetProps[attrs.TargetPropName];
|
||||||
var mappingValues = dictService.Context.Queryable<SysDictType, SysDictData>((a, b) =>
|
var mappingValues = dictService.Context.Queryable<SysDictType, SysDictData>((u, a) =>
|
||||||
new JoinQueryInfos(JoinType.Inner, a.Id == b.DictTypeId))
|
new JoinQueryInfos(JoinType.Inner, u.Id == a.DictTypeId))
|
||||||
.Where(a => a.Code == attrs.TypeCode)
|
.Where(u => u.Code == attrs.TypeCode)
|
||||||
.Where((a, b) => a.Status == StatusEnum.Enable && b.Status == StatusEnum.Enable)
|
.Where((u, a) => u.Status == StatusEnum.Enable && a.Status == StatusEnum.Enable)
|
||||||
.Select((a, b) => new
|
.Select((u, a) => new
|
||||||
{
|
{
|
||||||
Label = b.Value,
|
Label = a.Value,
|
||||||
Value = b.Code
|
Value = a.Code
|
||||||
}).ToList()
|
}).ToList()
|
||||||
.ToDictionary(m => m.Label, m => m.Value.ParseTo(targetProp.PropertyType));
|
.ToDictionary(u => u.Label, u => u.Value.ParseTo(targetProp.PropertyType));
|
||||||
propMappings.Add(propertyInfo.Name, new Tuple<Dictionary<string, object>, PropertyInfo, PropertyInfo>(mappingValues, propertyInfo, targetProp));
|
propMappings.Add(propertyInfo.Name, new Tuple<Dictionary<string, object>, PropertyInfo, PropertyInfo>(mappingValues, propertyInfo, targetProp));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -318,25 +318,25 @@ public static class CommonUtil
|
|||||||
// 整理导入对象的属性名称,<字典数据,原属性信息,目标属性信息>
|
// 整理导入对象的属性名称,<字典数据,原属性信息,目标属性信息>
|
||||||
var propMappings = new Dictionary<string, Tuple<Dictionary<object, string>, PropertyInfo, PropertyInfo>>();
|
var propMappings = new Dictionary<string, Tuple<Dictionary<object, string>, PropertyInfo, PropertyInfo>>();
|
||||||
|
|
||||||
var dictService = App.GetService<SqlSugarRepository<SysDictData>>();
|
var dictService = App.GetRequiredService<SqlSugarRepository<SysDictData>>();
|
||||||
var targetProps = typeof(TTarget).GetProperties().ToList();
|
var targetProps = typeof(TTarget).GetProperties().ToList();
|
||||||
var sourceProps = typeof(TSource).GetProperties().ToDictionary(m => m.Name);
|
var sourceProps = typeof(TSource).GetProperties().ToDictionary(u => u.Name);
|
||||||
foreach (var propertyInfo in targetProps)
|
foreach (var propertyInfo in targetProps)
|
||||||
{
|
{
|
||||||
var attrs = propertyInfo.GetCustomAttribute<ImportDictAttribute>();
|
var attrs = propertyInfo.GetCustomAttribute<ImportDictAttribute>();
|
||||||
if (attrs != null && !string.IsNullOrWhiteSpace(attrs.TypeCode))
|
if (attrs != null && !string.IsNullOrWhiteSpace(attrs.TypeCode))
|
||||||
{
|
{
|
||||||
var targetProp = sourceProps[attrs.TargetPropName];
|
var targetProp = sourceProps[attrs.TargetPropName];
|
||||||
var mappingValues = dictService.Context.Queryable<SysDictType, SysDictData>((a, b) =>
|
var mappingValues = dictService.Context.Queryable<SysDictType, SysDictData>((u, a) =>
|
||||||
new JoinQueryInfos(JoinType.Inner, a.Id == b.DictTypeId))
|
new JoinQueryInfos(JoinType.Inner, u.Id == a.DictTypeId))
|
||||||
.Where(a => a.Code == attrs.TypeCode)
|
.Where(u => u.Code == attrs.TypeCode)
|
||||||
.Where((a, b) => a.Status == StatusEnum.Enable && b.Status == StatusEnum.Enable)
|
.Where((u, a) => u.Status == StatusEnum.Enable && a.Status == StatusEnum.Enable)
|
||||||
.Select((a, b) => new
|
.Select((u, a) => new
|
||||||
{
|
{
|
||||||
Label = b.Value,
|
Label = a.Value,
|
||||||
Value = b.Code
|
Value = a.Code
|
||||||
}).ToList()
|
}).ToList()
|
||||||
.ToDictionary(m => m.Value.ParseTo(targetProp.PropertyType), m => m.Label);
|
.ToDictionary(u => u.Value.ParseTo(targetProp.PropertyType), u => u.Label);
|
||||||
propMappings.Add(propertyInfo.Name, new Tuple<Dictionary<object, string>, PropertyInfo, PropertyInfo>(mappingValues, targetProp, propertyInfo));
|
propMappings.Add(propertyInfo.Name, new Tuple<Dictionary<object, string>, PropertyInfo, PropertyInfo>(mappingValues, targetProp, propertyInfo));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user