From 0349681275c12573f3e2091f1a2b2ada0d729b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Fri, 30 Aug 2024 15:54:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BE=85=E5=AE=A1=E6=A0=B8=E8=B4=B9?= =?UTF-8?q?=E7=94=A8=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E7=BB=84=E8=A3=85?= =?UTF-8?q?=E6=88=90=E6=8C=89=E8=B4=B9=E7=94=A8=E5=88=86=E7=BB=84=E7=9A=84?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/QueryableExtensions.cs | 74 +++++++++++++++---- .../DS.WMS.Core/Fee/Dtos/FeeAudit.cs | 4 +- .../DS.WMS.Core/Fee/Method/FeeAuditService.cs | 20 ++--- .../Fee/Method/FeeRecordService.cs | 2 +- 4 files changed, 73 insertions(+), 27 deletions(-) diff --git a/ds-wms-service/DS.Module.Core/Extensions/QueryableExtensions.cs b/ds-wms-service/DS.Module.Core/Extensions/QueryableExtensions.cs index 2124dec9..83a3e599 100644 --- a/ds-wms-service/DS.Module.Core/Extensions/QueryableExtensions.cs +++ b/ds-wms-service/DS.Module.Core/Extensions/QueryableExtensions.cs @@ -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 OrderFieldCache = []; + + internal static List GetOrderFields(OrderByType orderByType = OrderByType.Desc) + { + Type type = typeof(T); + if (!OrderFieldCache.TryGetValue(type, out string[]? fields)) + { + List list = new List(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(); + } + /// /// 多排序方法 /// @@ -40,8 +72,8 @@ public static partial class Extensions public static DataResult> ToQueryPage(this ISugarQueryable 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>.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; } /// @@ -101,9 +133,11 @@ public static partial class Extensions ISugarQueryable 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(); + 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().ToList(), total); } - private static (List data, int totalNumber) WhereNoPage(this ISugarQueryable source,SortCondition[] orderConditions) + private static (List data, int totalNumber) WhereNoPage(this ISugarQueryable source, SortCondition[] orderConditions) { var total = source.Count(); ISugarQueryable orderSource; if (orderConditions == null || orderConditions.Length == 0) { - //orderSource = source.OrderBy("Id"); - orderSource = source.OrderBy("CreateTime desc"); + orderSource = source; + + var orderFields = GetOrderFields(); + 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().ToList(), total); - } + } private static async Task, int>> WhereAsync(this ISugarQueryable source, int pageIndex, int pageSize, SortCondition[] orderConditions) { ISugarQueryable orderSource; if (orderConditions == null || orderConditions.Length == 0) { - //orderSource = source.OrderBy("Id"); - orderSource = source.OrderBy("CreateTime desc"); + orderSource = source; + + var orderFields = GetOrderFields(); + if (orderFields?.Count > 0) + orderSource = source.OrderBy(orderFields); } else { @@ -165,7 +205,11 @@ public static partial class Extensions ISugarQueryable orderSource; if (orderConditions == null || orderConditions.Length == 0) { - orderSource = source.OrderBy("CreateTime desc"); + orderSource = source; + + var orderFields = GetOrderFields(); + if (orderFields?.Count > 0) + orderSource = source.OrderBy(orderFields); } else { diff --git a/ds-wms-service/DS.WMS.Core/Fee/Dtos/FeeAudit.cs b/ds-wms-service/DS.WMS.Core/Fee/Dtos/FeeAudit.cs index 32d39c04..8ee44672 100644 --- a/ds-wms-service/DS.WMS.Core/Fee/Dtos/FeeAudit.cs +++ b/ds-wms-service/DS.WMS.Core/Fee/Dtos/FeeAudit.cs @@ -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 /// /// 待审核费用项 /// + [DebuggerDisplay("FeeType={FeeType}, FeeName={FeeName}")] public class AuditItem { /// diff --git a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeAuditService.cs b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeAuditService.cs index cbc9c94c..238f19ce 100644 --- a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeAuditService.cs +++ b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeAuditService.cs @@ -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); + } } } diff --git a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs index a4cee310..16db8832 100644 --- a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs +++ b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeRecordService.cs @@ -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)); From c4e38104bb2f4c0406d5e5c6a6ca5319bf7d2359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Fri, 30 Aug 2024 18:05:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BE=80=E6=9D=A5=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E8=B4=B9=E7=94=A8=E6=A8=A1=E6=9D=BF=E7=BB=93=E6=9E=84=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DS.WMS.Core/Fee/Entity/FeeCustTemplate.cs | 18 ++++++++++----- .../Fee/Entity/FeeCustTemplateDetail.cs | 23 +++++++++++++------ .../Fee/Method/FeeCustTemplateService.cs | 20 +++++++++++++--- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/Fee/Entity/FeeCustTemplate.cs b/ds-wms-service/DS.WMS.Core/Fee/Entity/FeeCustTemplate.cs index 8100b98a..6cc6e134 100644 --- a/ds-wms-service/DS.WMS.Core/Fee/Entity/FeeCustTemplate.cs +++ b/ds-wms-service/DS.WMS.Core/Fee/Entity/FeeCustTemplate.cs @@ -25,16 +25,22 @@ namespace DS.WMS.Core.Fee.Entity public string BusinessTypeText => BusinessType.GetDescription(); /// - /// 费用类型 + /// 结算对象Id /// - [SugarColumn(ColumnDescription = "费用类型")] - public FeeType FeeType { get; set; } + [SugarColumn(ColumnDescription = "结算对象Id")] + public long? CustomerId { get; set; } /// - /// 费用类型文本 + /// 结算对象 /// - [SugarColumn(IsIgnore = true)] - public string FeeTypeText => FeeType.GetDescription(); + [SugarColumn(ColumnDescription = "结算对象", Length = 100, IsNullable = true)] + public string? CustomerName { get; set; } + + /// + /// 结算对象类型 + /// + [SugarColumn(ColumnDescription = "结算对象类型", IsNullable = true)] + public CustomerTypeEnum? CustomerType { get; set; } /// /// 名称 diff --git a/ds-wms-service/DS.WMS.Core/Fee/Entity/FeeCustTemplateDetail.cs b/ds-wms-service/DS.WMS.Core/Fee/Entity/FeeCustTemplateDetail.cs index c9229695..bc02adf0 100644 --- a/ds-wms-service/DS.WMS.Core/Fee/Entity/FeeCustTemplateDetail.cs +++ b/ds-wms-service/DS.WMS.Core/Fee/Entity/FeeCustTemplateDetail.cs @@ -1,4 +1,5 @@ using DS.Module.Core; +using Masuit.Tools.Systems; using SqlSugar; namespace DS.WMS.Core.Fee.Entity @@ -14,6 +15,7 @@ namespace DS.WMS.Core.Fee.Entity /// [SugarColumn(ColumnDescription = "模板ID", IsNullable = false)] public long TemplateId { get; set; } + /// /// 所属模板 /// @@ -24,21 +26,23 @@ namespace DS.WMS.Core.Fee.Entity /// [SugarColumn(IsPrimaryKey = true)] public long Id { get; set; } + /// /// 结算对象Id /// - [SugarColumn(ColumnDescription = "结算对象Id")] + [SugarColumn(ColumnDescription = "结算对象Id", IsNullable = false)] public long CustomerId { get; set; } /// /// 结算对象 /// - [SugarColumn(ColumnDescription = "结算对象", Length = 100, IsNullable = true)] - public string? CustomerName { get; set; } + [SugarColumn(ColumnDescription = "结算对象", Length = 100, IsNullable = false)] + public string CustomerName { get; set; } = string.Empty; /// /// 结算对象类型 /// [SugarColumn(ColumnDescription = "结算对象类型", IsNullable = true)] public CustomerTypeEnum? CustomerType { get; set; } + /// /// 费用Id /// @@ -52,14 +56,19 @@ namespace DS.WMS.Core.Fee.Entity /// /// 费用名称 /// - [SugarColumn(ColumnDescription = "费用名称", Length = 100, IsNullable = true)] - public string? FeeName { get; set; } + [SugarColumn(ColumnDescription = "费用名称", Length = 100, IsNullable = false)] + public string FeeName { get; set; } = string.Empty; /// - /// 收付类型(收、付) + /// 费用类型 /// - [SugarColumn(ColumnDescription = "收付类型(收、付)", IsNullable = false, DefaultValue = "1")] + [SugarColumn(ColumnDescription = "费用类型", IsNullable = false)] public FeeType FeeType { get; set; } /// + /// 费用类型文本 + /// + [SugarColumn(IsIgnore = true)] + public string FeeTypeText => FeeType.GetDescription(); + /// /// 费用标准 /// [SugarColumn(ColumnDescription = "费用标准", Length = 20, IsNullable = true)] diff --git a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeCustTemplateService.cs b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeCustTemplateService.cs index dad97938..e577d90c 100644 --- a/ds-wms-service/DS.WMS.Core/Fee/Method/FeeCustTemplateService.cs +++ b/ds-wms-service/DS.WMS.Core/Fee/Method/FeeCustTemplateService.cs @@ -46,10 +46,16 @@ namespace DS.WMS.Core.Fee.Method // break; //} + var order = await TenantDb.Queryable().Where(x => x.Id == bsId).Select( + x => new { x.CustomerId }).FirstAsync(); + if (order == null) + return; + try { var list = await TenantDb.Queryable() - .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 { x.Id, @@ -152,7 +158,9 @@ namespace DS.WMS.Core.Fee.Method { Id = x.Id, BusinessType = x.BusinessType, - FeeType = x.FeeType, + CustomerId = x.CustomerId, + CustomerName = x.CustomerName, + CustomerType = x.CustomerType, Name = x.Name, IsShared = x.IsShared, Note = x.Note, @@ -187,7 +195,13 @@ namespace DS.WMS.Core.Fee.Method foreach (var item in model.Details) { 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.CreateTime = dt; }