cjy 3 months ago
commit d7f90d98b1

@ -1,4 +1,6 @@
using System.ComponentModel; using System.Collections.Concurrent;
using System.ComponentModel;
using System.Reflection;
using DS.Module.Core.Data; using DS.Module.Core.Data;
using Newtonsoft.Json; using Newtonsoft.Json;
using SqlSugar; using SqlSugar;
@ -7,6 +9,36 @@ namespace DS.Module.Core.Extensions;
public static partial class 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>
/// 多排序方法 /// 多排序方法
/// </summary> /// </summary>
@ -41,7 +73,7 @@ public static partial class Extensions
PageCondition page) PageCondition page)
{ {
page.NotNull(nameof(page)); page.NotNull(nameof(page));
var result = page.IsExport? source.WhereNoPage(page.SortConditions) : source.Where(page.PageIndex, page.PageSize, page.SortConditions); var result = page.IsExport ? source.WhereNoPage(page.SortConditions) : source.Where(page.PageIndex, page.PageSize, page.SortConditions);
var list = result.data; var list = result.data;
var total = result.totalNumber; var total = result.totalNumber;
return DataResult<List<TEntity>>.PageList(total, list, MultiLanguageConst.DataQuerySuccess); return DataResult<List<TEntity>>.PageList(total, list, MultiLanguageConst.DataQuerySuccess);
@ -78,7 +110,7 @@ public static partial class Extensions
if (source.Count() == 0) if (source.Count() == 0)
{ {
//return new Exception("没有数据操作权限!"); //return new Exception("没有数据操作权限!");
Check.ExceptionEasy("NO Operation", "没有数据操作权限!"); Check.ExceptionEasy("NO Operation", "没有数据操作权限!");
} }
return source; return source;
} }
@ -101,9 +133,11 @@ public static partial class Extensions
ISugarQueryable<TEntity> orderSource; ISugarQueryable<TEntity> orderSource;
if (orderConditions == null || orderConditions.Length == 0) if (orderConditions == null || orderConditions.Length == 0)
{ {
// orderSource = source.OrderBy("Id ascending"); orderSource = source;
orderSource = source.OrderBy("CreateTime desc");
// orderSource = source.OrderBy("GID"); var orderFields = GetOrderFields<TEntity>();
if (orderFields?.Count > 0)
orderSource = source.OrderBy(orderFields);
} }
else else
{ {
@ -117,15 +151,18 @@ public static partial class Extensions
? source.ToPageList(pageIndex, pageSize, ref total) ? source.ToPageList(pageIndex, pageSize, ref total)
: Enumerable.Empty<TEntity>().ToList(), 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(); var total = source.Count();
ISugarQueryable<TEntity> orderSource; ISugarQueryable<TEntity> orderSource;
if (orderConditions == null || orderConditions.Length == 0) if (orderConditions == null || orderConditions.Length == 0)
{ {
//orderSource = source.OrderBy("Id"); orderSource = source;
orderSource = source.OrderBy("CreateTime desc");
var orderFields = GetOrderFields<TEntity>();
if (orderFields?.Count > 0)
orderSource = source.OrderBy(orderFields);
} }
else else
{ {
@ -145,8 +182,11 @@ public static partial class Extensions
ISugarQueryable<TEntity> orderSource; ISugarQueryable<TEntity> orderSource;
if (orderConditions == null || orderConditions.Length == 0) if (orderConditions == null || orderConditions.Length == 0)
{ {
//orderSource = source.OrderBy("Id"); orderSource = source;
orderSource = source.OrderBy("CreateTime desc");
var orderFields = GetOrderFields<TEntity>();
if (orderFields?.Count > 0)
orderSource = source.OrderBy(orderFields);
} }
else else
{ {
@ -165,7 +205,11 @@ public static partial class Extensions
ISugarQueryable<TEntity> orderSource; ISugarQueryable<TEntity> orderSource;
if (orderConditions == null || orderConditions.Length == 0) 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 else
{ {

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

@ -25,16 +25,22 @@ namespace DS.WMS.Core.Fee.Entity
public string BusinessTypeText => BusinessType.GetDescription(); public string BusinessTypeText => BusinessType.GetDescription();
/// <summary> /// <summary>
/// 费用类型 /// 结算对象Id
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "费用类型")] [SugarColumn(ColumnDescription = "结算对象Id")]
public FeeType FeeType { get; set; } public long? CustomerId { get; set; }
/// <summary> /// <summary>
/// 费用类型文本 /// 结算对象
/// </summary> /// </summary>
[SugarColumn(IsIgnore = true)] [SugarColumn(ColumnDescription = "结算对象", Length = 100, IsNullable = true)]
public string FeeTypeText => FeeType.GetDescription(); public string? CustomerName { get; set; }
/// <summary>
/// 结算对象类型
/// </summary>
[SugarColumn(ColumnDescription = "结算对象类型", IsNullable = true)]
public CustomerTypeEnum? CustomerType { get; set; }
/// <summary> /// <summary>
/// 名称 /// 名称

@ -1,4 +1,5 @@
using DS.Module.Core; using DS.Module.Core;
using Masuit.Tools.Systems;
using SqlSugar; using SqlSugar;
namespace DS.WMS.Core.Fee.Entity namespace DS.WMS.Core.Fee.Entity
@ -14,6 +15,7 @@ namespace DS.WMS.Core.Fee.Entity
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "模板ID", IsNullable = false)] [SugarColumn(ColumnDescription = "模板ID", IsNullable = false)]
public long TemplateId { get; set; } public long TemplateId { get; set; }
/// <summary> /// <summary>
/// 所属模板 /// 所属模板
/// </summary> /// </summary>
@ -24,21 +26,23 @@ namespace DS.WMS.Core.Fee.Entity
/// </summary> /// </summary>
[SugarColumn(IsPrimaryKey = true)] [SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; } public long Id { get; set; }
/// <summary> /// <summary>
/// 结算对象Id /// 结算对象Id
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "结算对象Id")] [SugarColumn(ColumnDescription = "结算对象Id", IsNullable = false)]
public long CustomerId { get; set; } public long CustomerId { get; set; }
/// <summary> /// <summary>
/// 结算对象 /// 结算对象
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "结算对象", Length = 100, IsNullable = true)] [SugarColumn(ColumnDescription = "结算对象", Length = 100, IsNullable = false)]
public string? CustomerName { get; set; } public string CustomerName { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 结算对象类型 /// 结算对象类型
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "结算对象类型", IsNullable = true)] [SugarColumn(ColumnDescription = "结算对象类型", IsNullable = true)]
public CustomerTypeEnum? CustomerType { get; set; } public CustomerTypeEnum? CustomerType { get; set; }
/// <summary> /// <summary>
/// 费用Id /// 费用Id
/// </summary> /// </summary>
@ -52,14 +56,19 @@ namespace DS.WMS.Core.Fee.Entity
/// <summary> /// <summary>
/// 费用名称 /// 费用名称
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "费用名称", Length = 100, IsNullable = true)] [SugarColumn(ColumnDescription = "费用名称", Length = 100, IsNullable = false)]
public string? FeeName { get; set; } public string FeeName { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 收付类型(收、付) /// 费用类型
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "收付类型(收、付)", IsNullable = false, DefaultValue = "1")] [SugarColumn(ColumnDescription = "费用类型", IsNullable = false)]
public FeeType FeeType { get; set; } public FeeType FeeType { get; set; }
/// <summary> /// <summary>
/// 费用类型文本
/// </summary>
[SugarColumn(IsIgnore = true)]
public string FeeTypeText => FeeType.GetDescription();
/// <summary>
/// 费用标准 /// 费用标准
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "费用标准", Length = 20, IsNullable = true)] [SugarColumn(ColumnDescription = "费用标准", Length = 20, IsNullable = true)]

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

@ -46,10 +46,16 @@ namespace DS.WMS.Core.Fee.Method
// break; // break;
//} //}
var order = await TenantDb.Queryable<SeaExport>().Where(x => x.Id == bsId).Select(
x => new { x.CustomerId }).FirstAsync();
if (order == null)
return;
try try
{ {
var list = await TenantDb.Queryable<FeeCustTemplate>() var list = await TenantDb.Queryable<FeeCustTemplate>()
.Where(x => x.BusinessType == businessType && !SqlFunc.IsNullOrEmpty(x.Condition)) .Where(x => x.BusinessType == businessType && !SqlFunc.IsNullOrEmpty(x.Condition) &&
(x.IsShared || x.CustomerId == order.CustomerId))
.Select(x => new .Select(x => new
{ {
x.Id, x.Id,
@ -152,7 +158,9 @@ namespace DS.WMS.Core.Fee.Method
{ {
Id = x.Id, Id = x.Id,
BusinessType = x.BusinessType, BusinessType = x.BusinessType,
FeeType = x.FeeType, CustomerId = x.CustomerId,
CustomerName = x.CustomerName,
CustomerType = x.CustomerType,
Name = x.Name, Name = x.Name,
IsShared = x.IsShared, IsShared = x.IsShared,
Note = x.Note, Note = x.Note,
@ -187,7 +195,13 @@ namespace DS.WMS.Core.Fee.Method
foreach (var item in model.Details) foreach (var item in model.Details)
{ {
item.TemplateId = model.Id; item.TemplateId = model.Id;
item.FeeType = model.FeeType; if (item.CustomerId == 0 && model.CustomerId.HasValue)
item.CustomerId = model.CustomerId.Value;
if (item.CustomerName.IsNullOrEmpty() && !model.CustomerName.IsNullOrEmpty())
item.CustomerName = model.CustomerName;
item.CustomerType = model.CustomerType;
item.CreateBy = userId; item.CreateBy = userId;
item.CreateTime = dt; item.CreateTime = dt;
} }

@ -478,7 +478,7 @@ namespace DS.WMS.Core.Fee.Method
if (sb.Length > 0) if (sb.Length > 0)
return DataResult.Failed(sb.ToString(), MultiLanguageConst.Operation_Failed); 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) if (template == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TemplateNotFound)); return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TemplateNotFound));

Loading…
Cancel
Save