From 8de9513fb70ddbafa765d26dfb29fa420e5860f5 Mon Sep 17 00:00:00 2001 From: wxd <123@qq.com> Date: Mon, 6 May 2024 16:01:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=B1=BB=E5=88=AB=E3=80=81?= =?UTF-8?q?=E5=8C=BB=E7=94=9F=E8=AF=8A=E5=8F=B0=E9=A1=B9=E7=9B=AE=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationUnits/TreeChildViewDto.cs | 2 + .../ItemTypes/ItemTypeAppService.cs | 5 +- .../RegisterChecks/RegisterCheckAppService.cs | 2 +- .../ItemTypes/ItemTypeManager.cs | 48 +++++++++++++++++-- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/Shentun.Peis.Application.Contracts/OrganizationUnits/TreeChildViewDto.cs b/src/Shentun.Peis.Application.Contracts/OrganizationUnits/TreeChildViewDto.cs index 5555b70..06b4481 100644 --- a/src/Shentun.Peis.Application.Contracts/OrganizationUnits/TreeChildViewDto.cs +++ b/src/Shentun.Peis.Application.Contracts/OrganizationUnits/TreeChildViewDto.cs @@ -22,6 +22,8 @@ namespace Shentun.Peis.OrganizationUnits /// public string SimpleCode { get; set; } + public int DisplayOrder { get; set; } + public List TreeChildren { get; set; } } } diff --git a/src/Shentun.Peis.Application/ItemTypes/ItemTypeAppService.cs b/src/Shentun.Peis.Application/ItemTypes/ItemTypeAppService.cs index 99ceca5..84e5b74 100644 --- a/src/Shentun.Peis.Application/ItemTypes/ItemTypeAppService.cs +++ b/src/Shentun.Peis.Application/ItemTypes/ItemTypeAppService.cs @@ -75,6 +75,7 @@ namespace Shentun.Peis.ItemTypes var entity = await _manager.CreateAsync(createEntity); entity = await Repository.InsertAsync(entity); await _itemTypeCache.SetAsync(entity.Id, entity); + await _manager.UpdateDisplayOrder(); //全局更新 var dto = ObjectMapper.Map(entity); return dto; } @@ -118,7 +119,8 @@ namespace Shentun.Peis.ItemTypes ParentId = p.ParentId, Code = p.PathCode, DisplayName = p.DisplayName, - SimpleCode = p.SimpleCode + SimpleCode = p.SimpleCode, + DisplayOrder = p.DisplayOrder }; return GetTree(items.ToList(), 0, ""); } @@ -184,6 +186,7 @@ namespace Shentun.Peis.ItemTypes { return (from p in items where p.Code.StartsWith(prefix) && p.Code.Count(a => a == '.') == deep + orderby p.DisplayOrder ascending let subs = GetTree(items, deep + 1, p.Code) select new TreeChildViewDto() { diff --git a/src/Shentun.Peis.Application/RegisterChecks/RegisterCheckAppService.cs b/src/Shentun.Peis.Application/RegisterChecks/RegisterCheckAppService.cs index b947d80..f024be9 100644 --- a/src/Shentun.Peis.Application/RegisterChecks/RegisterCheckAppService.cs +++ b/src/Shentun.Peis.Application/RegisterChecks/RegisterCheckAppService.cs @@ -205,7 +205,7 @@ namespace Shentun.Peis.RegisterChecks if (asbitemIds.Any()) { - entlist = entlist.Where(m => asbitemIds.Contains(m.RegisterCheckAsbitems.FirstOrDefault().Id)); + entlist = entlist.Where(m => asbitemIds.Contains(m.RegisterCheckAsbitems.FirstOrDefault().AsbitemId)); } else { diff --git a/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs b/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs index da0b982..dfc638e 100644 --- a/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs +++ b/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs @@ -43,7 +43,7 @@ namespace Shentun.Peis.ItemTypes Verify(entity); await EntityHelper.CheckSameName(_repository, entity.DisplayName); var pathCode = await CreatePathCode(entity.ParentId); - if(pathCode.Length > 11 ) + if (pathCode.Length > 11) { throw new UserFriendlyException("项目类别只允许最多两级"); } @@ -102,7 +102,7 @@ namespace Shentun.Peis.ItemTypes DataHelper.CheckEntityIsNull(entity); DataHelper.CheckStringIsNull(entity.DisplayName, "名称"); - if( (entity.GuidTypeId - '0') < 0 || (entity.GuidTypeId - '0') > 10) + if ((entity.GuidTypeId - '0') < 0 || (entity.GuidTypeId - '0') > 10) { throw new UserFriendlyException("指引单类别无效"); } @@ -128,7 +128,8 @@ namespace Shentun.Peis.ItemTypes { //最大pathcode var LastPathCode = (await _repository.GetListAsync(o => o.ParentId == Guid.Empty || o.ParentId == null)) - .OrderByDescending(o => { + .OrderByDescending(o => + { var sortCode = o.PathCode.Replace(".", ""); return Convert.ToInt32(sortCode); }).FirstOrDefault(); @@ -151,7 +152,8 @@ namespace Shentun.Peis.ItemTypes //最大pathcode var LastPathCode = (await _repository.GetListAsync(o => o.ParentId == parentId)) - .OrderByDescending(o => { + .OrderByDescending(o => + { var sortCode = o.PathCode.Replace(".", ""); return Convert.ToInt32(sortCode); }).Select(s => s.PathCode).FirstOrDefault(); @@ -234,6 +236,42 @@ namespace Shentun.Peis.ItemTypes return itmeTypeIds; } - + + /// + /// 更新排序 + /// + /// + public async Task UpdateDisplayOrder() + { + List newItemTypeList = new List(); + + var itemTypeList = (await _repository.GetQueryableAsync()).OrderBy(o => o.DisplayOrder).ToList(); + foreach (var itemType in itemTypeList.Where(m => m.ParentId == null).OrderBy(o => o.DisplayOrder)) + { + newItemTypeList.Add(itemType); + GetChildItemType(itemTypeList, itemType.Id, newItemTypeList); + } + + + foreach (var itemType in newItemTypeList) + { + itemType.DisplayOrder = newItemTypeList.IndexOf(itemType) + 1; + } + + await _repository.UpdateManyAsync(newItemTypeList); + } + + private void GetChildItemType(List itemTypeList, Guid itemTypeId, List newItemTypeList) + { + if (itemTypeList.Where(m => m.ParentId == itemTypeId).Count() > 0) + { + foreach (var itemType in itemTypeList.Where(m => m.ParentId == itemTypeId).OrderBy(o => o.DisplayOrder)) + { + newItemTypeList.Add(itemType); + GetChildItemType(itemTypeList, itemType.Id, newItemTypeList); + } + } + } + } }