待审核费用查询结果组装成按费用分组的结构

usertest
嵇文龙 4 months ago
parent 19797c5919
commit 0349681275

@ -1,4 +1,6 @@
using System.ComponentModel;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Reflection;
using DS.Module.Core.Data;
using Newtonsoft.Json;
using SqlSugar;
@ -7,6 +9,36 @@ namespace DS.Module.Core.Extensions;
public static partial class Extensions
{
static readonly ConcurrentDictionary<Type, string[]> OrderFieldCache = [];
internal static List<OrderByModel> GetOrderFields<T>(OrderByType orderByType = OrderByType.Desc)
{
Type type = typeof(T);
if (!OrderFieldCache.TryGetValue(type, out string[]? fields))
{
List<string> list = new List<string>(2);
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
//查找ID或创建时间暂时只设置一个默认排序字段
var propId = Array.Find(properties, x => x.Name == "Id");
if (propId != null)
{
list.Add(propId.Name);
}
else
{
var propCT = Array.Find(properties, x => x.Name == "CreateTime");
if (propCT != null)
list.Add(propCT.Name);
}
fields = [.. list];
OrderFieldCache.AddOrUpdate(type, fields, (k, v) => v = fields);
}
return fields.Select(x => new OrderByModel { FieldName = x, OrderByType = orderByType }).ToList();
}
/// <summary>
/// 多排序方法
/// </summary>
@ -40,8 +72,8 @@ public static partial class Extensions
public static DataResult<List<TEntity>> ToQueryPage<TEntity>(this ISugarQueryable<TEntity> source,
PageCondition page)
{
page.NotNull(nameof(page));
var result = page.IsExport? source.WhereNoPage(page.SortConditions) : source.Where(page.PageIndex, page.PageSize, page.SortConditions);
page.NotNull(nameof(page));
var result = page.IsExport ? source.WhereNoPage(page.SortConditions) : source.Where(page.PageIndex, page.PageSize, page.SortConditions);
var list = result.data;
var total = result.totalNumber;
return DataResult<List<TEntity>>.PageList(total, list, MultiLanguageConst.DataQuerySuccess);
@ -78,9 +110,9 @@ public static partial class Extensions
if (source.Count() == 0)
{
//return new Exception("没有数据操作权限!");
Check.ExceptionEasy("NO Operation", "没有数据操作权限!");
Check.ExceptionEasy("NO Operation", "没有数据操作权限!");
}
return source;
return source;
}
/// <summary>
@ -101,9 +133,11 @@ public static partial class Extensions
ISugarQueryable<TEntity> orderSource;
if (orderConditions == null || orderConditions.Length == 0)
{
// orderSource = source.OrderBy("Id ascending");
orderSource = source.OrderBy("CreateTime desc");
// orderSource = source.OrderBy("GID");
orderSource = source;
var orderFields = GetOrderFields<TEntity>();
if (orderFields?.Count > 0)
orderSource = source.OrderBy(orderFields);
}
else
{
@ -117,15 +151,18 @@ public static partial class Extensions
? source.ToPageList(pageIndex, pageSize, ref total)
: Enumerable.Empty<TEntity>().ToList(), total);
}
private static (List<TEntity> data, int totalNumber) WhereNoPage<TEntity>(this ISugarQueryable<TEntity> source,SortCondition[] orderConditions)
private static (List<TEntity> data, int totalNumber) WhereNoPage<TEntity>(this ISugarQueryable<TEntity> source, SortCondition[] orderConditions)
{
var total = source.Count();
ISugarQueryable<TEntity> orderSource;
if (orderConditions == null || orderConditions.Length == 0)
{
//orderSource = source.OrderBy("Id");
orderSource = source.OrderBy("CreateTime desc");
orderSource = source;
var orderFields = GetOrderFields<TEntity>();
if (orderFields?.Count > 0)
orderSource = source.OrderBy(orderFields);
}
else
{
@ -138,15 +175,18 @@ public static partial class Extensions
source.Count() != 0
? source.ToList()
: Enumerable.Empty<TEntity>().ToList(), total);
}
}
private static async Task<Tuple<List<TEntity>, int>> WhereAsync<TEntity>(this ISugarQueryable<TEntity> source,
int pageIndex, int pageSize, SortCondition[] orderConditions)
{
ISugarQueryable<TEntity> orderSource;
if (orderConditions == null || orderConditions.Length == 0)
{
//orderSource = source.OrderBy("Id");
orderSource = source.OrderBy("CreateTime desc");
orderSource = source;
var orderFields = GetOrderFields<TEntity>();
if (orderFields?.Count > 0)
orderSource = source.OrderBy(orderFields);
}
else
{
@ -165,7 +205,11 @@ public static partial class Extensions
ISugarQueryable<TEntity> orderSource;
if (orderConditions == null || orderConditions.Length == 0)
{
orderSource = source.OrderBy("CreateTime desc");
orderSource = source;
var orderFields = GetOrderFields<TEntity>();
if (orderFields?.Count > 0)
orderSource = source.OrderBy(orderFields);
}
else
{

@ -1,4 +1,5 @@
using DS.Module.Core;
using System.Diagnostics;
using DS.Module.Core;
using DS.WMS.Core.Op.Entity;
using Masuit.Tools.Systems;
@ -440,6 +441,7 @@ namespace DS.WMS.Core.Fee.Dtos
/// <summary>
/// 待审核费用项
/// </summary>
[DebuggerDisplay("FeeType={FeeType}, FeeName={FeeName}")]
public class AuditItem
{
/// <summary>

@ -13,6 +13,7 @@ using DS.WMS.Core.Sys.Entity;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using static AnyDiff.DifferenceLines;
namespace DS.WMS.Core.Fee.Method
{
@ -421,11 +422,11 @@ namespace DS.WMS.Core.Fee.Method
//将查询结果组装成按费用分组的结构
pendingAudit.ItemGroups = [];
foreach (var item in list)
for (int i = 0; i < list.Count; i++)
{
AuditItemGroup? group;
var groups = pendingAudit.ItemGroups.FindAll(x => x.FeeName == item.FeeName);
if (groups.Count == 0)
var item = list[i];
AuditItemGroup? group = pendingAudit.ItemGroups.Find(x => x.FeeName == item.FeeName && x.Items?.Count < 2);
if (group == null)
{
group = new AuditItemGroup
{
@ -437,12 +438,7 @@ namespace DS.WMS.Core.Fee.Method
continue;
}
group = groups.Find(x => x.Items != null && x.Items.Count(y => y.FeeType == item.FeeType) == 1);
if (group != null)
{
group.Items.Add(item);
}
else
if (group.Items.Exists(x => x.FeeType == item.FeeType))
{
group = new AuditItemGroup
{
@ -451,6 +447,10 @@ namespace DS.WMS.Core.Fee.Method
};
pendingAudit.ItemGroups.Add(group);
}
else
{
group.Items.Add(item);
}
}
}

@ -478,7 +478,7 @@ namespace DS.WMS.Core.Fee.Method
if (sb.Length > 0)
return DataResult.Failed(sb.ToString(), MultiLanguageConst.Operation_Failed);
var template = await FindTemplateAsync(TaskBaseTypeEnum.FEE_MODIFY_AUDIT);
var template = await FindTemplateAsync(TaskBaseTypeEnum.FEE_AUDIT);
if (template == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TemplateNotFound));

Loading…
Cancel
Save