From fdf4cdbf9723d9d05938fe56d2014769dd7ece4c Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周六, 10 5月 2025 12:17:19 +0800 Subject: [PATCH] 修复 模糊查询bug --- PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs | 432 ++++++++++++++++++------------------------------------ 1 files changed, 144 insertions(+), 288 deletions(-) diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs index 427de9f..ab32c0c 100644 --- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs +++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs @@ -1,308 +1,164 @@ -using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.MyTestEntityNames; -using CMS.Plugin.PipeLineLems.Application.Contracts.Services; -using CMS.Plugin.PipeLineLems.Domain.MyTestEntityNames; -using CMS.Plugin.PipeLineLems.Domain.Shared; -using CMS.Plugin.PipeLineLems.Domain.Shared.MyTestEntityNames; -using Volo.Abp; -using Volo.Abp.Application.Dtos; -using Volo.Abp.Data; -using Volo.Abp.ObjectExtending; +//using CMS.Plugin.FormulaManagement.Abstractions; +//using CMS.Plugin.OrderManagement.Abstractions; +//using CMS.Plugin.OrderManagement.Abstractions.Enums; +//using CMS.Plugin.OrderManagement.Abstractions.Models; +//using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan; +//using CMS.Plugin.PipeLineLems.Application.Contracts.Services; +//using CMS.Plugin.PipeLineLems.Domain.WorkPlan; +//using CMS.Plugin.ProductManagement.Abstractions; +//using Microsoft.Extensions.DependencyInjection; +//using Volo.Abp; -namespace CMS.Plugin.PipeLineLems.Application.Implements; +//namespace CMS.Plugin.PipeLineLems.Application.Implements; -/// <inheritdoc /> -public class MesAppService : CMSPluginAppService, IMesAppService -{ - private readonly IMyTestEntityNameRepository _mytestentitynameRepository; +//public class MesAppService : CMSPluginAppService, IMesAppService +//{ +// private readonly IServiceProvider _serviceProvider; +// private readonly IWorkPlanAppService _workPlanAppService; - /// <summary> - /// Initializes a new instance of the <see cref="MyTestEntityNameAppService"/> class. - /// </summary> - /// <param name="mytestentitynameRepository">The task job repository.</param> - public MesAppService(IMyTestEntityNameRepository mytestentitynameRepository) - { - _mytestentitynameRepository = mytestentitynameRepository; - } +// //private readonly IEventBus _eventBus; - /// <inheritdoc /> - public virtual async Task<MyTestEntityNameDto> GetAsync(Guid id) - { - return ObjectMapper.Map<MyTestEntityName, MyTestEntityNameDto>(await _mytestentitynameRepository.GetAsync(id)); - } +// public MesAppService(IServiceProvider serviceProvider +// , IWorkPlanAppService workPlanAppService +// //, IEventBus eventBus +// ) +// { +// _serviceProvider = serviceProvider; +// // _eventBus = eventBus; +// _workPlanAppService = workPlanAppService; +// } - /// <inheritdoc /> - public virtual async Task<PagedResultDto<MyTestEntityNameDto>> GetListAsync(GetMyTestEntityNamesInput input) - { - Check.NotNull(input, nameof(input)); +// public async Task<MesOrderResponse> CreateAsync(List<WorkPlanInput> input) +// { +// if (input == null) +// { +// throw new UserFriendlyException("杈撳叆鍙傛暟涓嶈兘涓虹┖"); +// } - if (input.Sorting.IsNullOrWhiteSpace()) - { - input.Sorting = nameof(MyTestEntityName.Sort); - } +// if (input.Count == 0) +// { +// throw new UserFriendlyException("杈撳叆鍙傛暟Data涓嶈兘涓虹┖"); +// } - var specification = new MyTestEntityNameSpecification(input.Name); - var count = await _mytestentitynameRepository.GetCountAsync(input.Filter, specification); - var list = await _mytestentitynameRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification); +// var orderManager = _serviceProvider.GetRequiredService<IOrderManager>(); +// var productProvider = _serviceProvider.GetRequiredService<IProductProvider>(); +// var formulaProvider = _serviceProvider.GetRequiredService<IFormulaProvider>(); +// List<OrderModel> orderModels = new List<OrderModel>(); +// //鎸夌収浠诲姟缂栧彿鍒嗙粍 +// var groupTask = input.GroupBy(x => x.TaskCode); +// foreach (var gTask in groupTask) +// { +// var taskCode = gTask.Key; +// var order = await orderManager.GetByCodeAsync(taskCode); +// if (order != null) +// { +// throw new UserFriendlyException($"浠诲姟缂栧彿[{taskCode}]宸插瓨鍦�"); +// } - return new PagedResultDto<MyTestEntityNameDto>(count, ObjectMapper.Map<List<MyTestEntityName>, List<MyTestEntityNameDto>>(list)); - } - /// <inheritdoc /> - public virtual async Task<MyTestEntityNameDto> CreateAsync(MyTestEntityNameCreateDto input) - { - await CheckCreateOrUpdateDtoAsync(input); +// //var product = await productProvider.FindByNameAsync(orderItem.PipeSectionName); +// //if (product == null) +// //{ +// // throw new UserFriendlyException($"浜у搧鍚嶇О[{orderItem.PipeSectionName}]涓嶅瓨鍦�"); +// //} - var exist = await _mytestentitynameRepository.NameExistAsync(input.Name); - if (exist) - { - throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.Name]); - } +// //var formula = await formulaProvider.GetFormulaAsync(product.Id); +// //if (formula == null) +// //{ +// // throw new UserFriendlyException($"浜у搧鍨嬪彿[{orderItem.MaterialCode}]鏃犲叧鑱旈厤鏂�"); +// //} +// //棣栧厛瑕佸垱寤� 鎵撶爜鍒囧壊鐨勫伐鍗� +// var productForCut = await productProvider.FindByNameAsync("鍒囧壊鍘熸枡绠�"); +// if (productForCut == null) +// { +// throw new UserFriendlyException($"浜у搧鍚嶇О[鍒囧壊鍘熸枡绠涓嶅瓨鍦�"); +// } +// var formulaForCut = await formulaProvider.GetFormulaAsync(productForCut.Id); +// if (formulaForCut == null) +// { +// throw new UserFriendlyException($"浜у搧鍚嶇О[鍒囧壊鍘熸枡绠鏃犲叧鑱旈厤鏂�"); +// } +// //鍒嗙粍鏁版嵁 +// var group = gTask.ToList().GroupBy(x => x.DataIdentifier); +// foreach (var item in group) +// { +// OrderModel orderModelForCut = new OrderModel() +// { +// Id = Guid.NewGuid(), +// Code = "Cut_" + taskCode, +// Source = "APS鎺ㄩ��", +// PlanStartTime = gTask.ToList().First().PlannedStartTime, +// PlanFinishTime = gTask.ToList().First().PlannedEndTime, +// PlanQty = (ulong)item.ToList().Count, +// Status = OrderStatus.NotActive, +// Product = new AssociationProductModel() { Id = productForCut.Id, Name = productForCut.Name, Model = productForCut.Model, ShortNumber = productForCut.ShortNumber }, +// Formula = new AssociationFormulaModel() { Id = formulaForCut.Id, Code = formulaForCut.Code, Name = formulaForCut.Name } +// }; +// orderModelForCut.ExtraProperties["OuterDiameter"] = gTask.ToList().First().OuterDiameter;//澶栧緞 +// orderModelForCut.ExtraProperties["Material"] = gTask.ToList().First().Material;//鏉愯川 +// orderModelForCut.ExtraProperties["Length"] = gTask.ToList().First().Length;//闀垮害 - var maxSort = await _mytestentitynameRepository.GetMaxSortAsync(); - var sort = input.Sort ?? maxSort; - var mytestentityname = new MyTestEntityName(GuidGenerator.Create(), input.Code, input.Name, sort, input.Remark); - input.MapExtraPropertiesTo(mytestentityname, MappingPropertyDefinitionChecks.None); +// var orderForCut = await orderManager.GetByCodeAsync(orderModelForCut.Code); +// if (orderForCut != null) +// { +// //throw new UserFriendlyException($"宸ュ崟[{orderModelForCut.Code}]宸插瓨鍦�"); +// //涓嶅啀鎶涘紓甯革紝鐩存帴璺宠繃 +// break; +// } - await _mytestentitynameRepository.InsertAsync(mytestentityname); +// var orderModelResultForCut = await orderManager.CreateAsync(orderModelForCut); +// if (orderModelResultForCut == null) +// { +// throw new UserFriendlyException($"宸ュ崟[{orderModelForCut.Code}]鍒涘缓澶辫触"); +// } +// orderModels.Add(orderModelResultForCut); - if (input.Sort.HasValue && mytestentityname.Sort != maxSort) - { - await AdjustSortAsync(mytestentityname.Id, mytestentityname.Sort); - } - return ObjectMapper.Map<MyTestEntityName, MyTestEntityNameDto>(mytestentityname); - } +// //OrderModel orderModel = new OrderModel(); +// //orderModel.Id = Guid.NewGuid(); +// //orderModel.Code = orderItem.TaskCode; +// //orderModel.Source = "APS鎺ㄩ��"; +// //orderModel.Product = new AssociationProductModel() { Id = product.Id, Name = product.Name, Model = product.Model, ShortNumber = product.ShortNumber }; +// ////orderModel.Formula = new AssociationFormulaModel() { Id = formula.Id, Code = formula.Code, Name = formula.Name }; +// //orderModel.PlanStartTime = orderItem.PlannedStartTime; +// //orderModel.PlanFinishTime = orderItem.PlannedEndTime; +// //orderModel.PlanQty = (ulong?)orderItem.OrderQty; +// //orderModel.Status = OrderStatus.NotActive; +// //orderModel.ExtraProperties["Source"] = "ddd"; +// //var source = orderModel.ExtraProperties["Source"]; +// //var orderModelResult = await orderManager.CreateAsync(orderModel); +// //if (orderModelResult == null) +// //{ +// // throw new UserFriendlyException($"宸ュ崟[{orderItem.TaskCode}]鍒涘缓澶辫触"); +// //} +// //orderModels.Add(orderModelResult); +// } - /// <inheritdoc /> - public virtual async Task<MyTestEntityNameDto> UpdateAsync(Guid id, MyTestEntityNameUpdateDto input) - { - await CheckCreateOrUpdateDtoAsync(input); +// } - var mytestentityname = await _mytestentitynameRepository.GetAsync(id); - var exist = await _mytestentitynameRepository.NameExistAsync(input.Name, mytestentityname.Id); - if (exist) - { - throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.Name]); - } - mytestentityname.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); - input.MapExtraPropertiesTo(mytestentityname, MappingPropertyDefinitionChecks.None); +// //淇濆瓨鍒拌〃涓� +// foreach (var item in input) +// { +// var insertObj = ObjectMapper.Map<WorkPlanInput, WorkPlanCreateDto>(item); +// insertObj.OrgMaterialCode = "1111"; +// insertObj.Sort = 1; +// await _workPlanAppService.CreateAsync(insertObj); +// } - mytestentityname.Update(input.Code, input.Name, input.Remark); - await _mytestentitynameRepository.UpdateAsync(mytestentityname); +// // 鍙戝竷浜嬩欢 +// //await _eventBus.PublishAsync(new EntityChangedEto("MESCREATE", input, null, EntityChangeType.Add, true)); - return ObjectMapper.Map<MyTestEntityName, MyTestEntityNameDto>(mytestentityname); - } - - /// <inheritdoc /> - public async Task<List<MyTestEntityNameDto>> CloneAsync(IEnumerable<Guid> ids) - { - var mytestentitynames = new List<MyTestEntityName>(); - if (ids != null) - { - var sort = await _mytestentitynameRepository.GetMaxSortAsync(); - foreach (var id in ids) - { - var mytestentityname = await _mytestentitynameRepository.FindAsync(id); - if (mytestentityname != null) - { - var name = mytestentityname.Name + MyTestEntityNameConsts.CloneTag; - var notExist = false; - while (!notExist) - { - var exist = await _mytestentitynameRepository.NameExistAsync(name); - if (exist || mytestentitynames.Any(x => x.Name == name)) - { - name += MyTestEntityNameConsts.CloneTag; - continue; - } - - notExist = true; - } - - mytestentityname = await _mytestentitynameRepository.InsertAsync(mytestentityname.Clone(GuidGenerator.Create(), name, sort++)); - mytestentitynames.Add(mytestentityname); - } - } - } - - return ObjectMapper.Map<List<MyTestEntityName>, List<MyTestEntityNameDto>>(mytestentitynames); - } - - /// <inheritdoc /> - public virtual Task DeleteAsync(Guid id) - { - return _mytestentitynameRepository.DeleteAsync(id); - } - - /// <inheritdoc /> - public async Task DeleteManyAsync(IEnumerable<Guid> ids) - { - foreach (var id in ids) - { - await DeleteAsync(id); - } - } - - /// <inheritdoc /> - public virtual async Task AdjustSortAsync(Guid id, int sort) - { - var list = await _mytestentitynameRepository.GetListAsync(nameof(MyTestEntityName.Sort)); - if (list != null && list.Any()) - { - var initSort = 1; - list.ForEach(x => x.AdjustSort(initSort++)); - var entity = list.FirstOrDefault(x => x.Id == id); - if (entity != null) - { - if (sort == 1) - { - list.Where(x => x.Id != id).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1)); - } - else if (entity.Sort > sort) - { - list.Where(x => x.Id != id && x.Sort >= sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1)); - list.Where(x => x.Id != id && x.Sort < sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort - 1)); - } - else if (entity.Sort < sort) - { - list.Where(x => x.Id != id && x.Sort > sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1)); - list.Where(x => x.Id != id && x.Sort <= sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort - 1)); - } - - entity.AdjustSort(sort); - } - } - - await _mytestentitynameRepository.UpdateManyAsync(list); - } - - /// <inheritdoc /> - public async Task ImportAsync(MyTestEntityNamesImportModel input) - { - Check.NotNull(input, nameof(input)); - - var mytestentitynameCreateDtos = new List<(int RowIndex, MyTestEntityNameCreateDto Item)>(); - var mytestentitynameUpdateDtos = new List<(int RowIndex, Guid Id, MyTestEntityNameUpdateDto Item)>(); - var mytestentitynames = input.MyTestEntityNames; - - if (mytestentitynames != null && mytestentitynames.Any()) - { - #region 瀵煎叆鏍¢獙 - - // 鍒ゆ柇鍚嶇О鏄惁閲嶅锛屽苟杈撳嚭绗嚑琛岄噸澶� - var duplicateMyTestEntityNames = mytestentitynames.GroupBy(x => x.Name).Where(x => x.Count() > 1).ToList(); - if (duplicateMyTestEntityNames?.Any() == true) - { - var duplicateMyTestEntityNameMsgs = duplicateMyTestEntityNames.Select(x => $"绗� {string.Join(",", x.Select(x => x.RowIndex))} 琛岋細{x.Key} 鍚嶇О閲嶅"); - var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝 {string.Join(",", duplicateMyTestEntityNameMsgs)}锛岀粓姝㈠鍏�"; - throw new UserFriendlyException(errorMsg); - } - - #endregion - - foreach (var mytestentityname in mytestentitynames) - { - if (mytestentityname.Code.IsNullOrWhiteSpace() && mytestentityname.Name.IsNullOrWhiteSpace()) - { - continue; - } - - if (mytestentityname.Name.IsNullOrWhiteSpace()) - { - var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝绗瑊mytestentityname.RowIndex}琛岋細MyTestEntityName鍚嶇О涓嶈兘涓虹┖"; - throw new UserFriendlyException(errorMsg); - } - - var oldMyTestEntityName = await _mytestentitynameRepository.FindByNameAsync(mytestentityname.Name); - if (oldMyTestEntityName != null) - { - var mytestentitynameUpdateDto = new MyTestEntityNameUpdateDto - { - Code = mytestentityname.Code, - Name = mytestentityname.Name, - Remark = mytestentityname.Remark, - }; - - mytestentitynameUpdateDtos.Add((mytestentityname.RowIndex, oldMyTestEntityName.Id, mytestentitynameUpdateDto)); - } - else - { - var mytestentitynameCreateDto = new MyTestEntityNameCreateDto - { - Code = mytestentityname.Code, - Name = mytestentityname.Name, - Remark = mytestentityname.Remark, - }; - - mytestentitynameCreateDtos.Add((mytestentityname.RowIndex, mytestentitynameCreateDto)); - } - } - } - - // 鏂板 - foreach (var mytestentitynameDto in mytestentitynameCreateDtos) - { - try - { - await CreateAsync(mytestentitynameDto.Item); - } - catch (Exception e) - { - var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝绗瑊mytestentitynameDto.RowIndex}琛岋細{e.Message}锛岀粓姝㈠鍏�"; - throw new UserFriendlyException(errorMsg); - } - } - - // 鏇存柊 - foreach (var mytestentitynameDto in mytestentitynameUpdateDtos) - { - try - { - await UpdateAsync(mytestentitynameDto.Id, mytestentitynameDto.Item); - } - catch (Exception e) - { - var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝绗瑊mytestentitynameDto.RowIndex}琛岋細{e.Message}锛岀粓姝㈠鍏�"; - throw new UserFriendlyException(errorMsg); - } - } - } - - /// <inheritdoc /> - public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetMyTestEntityNamesInput input) - { - Check.NotNull(input, nameof(input)); - - if (input.Sorting.IsNullOrWhiteSpace()) - { - input.Sorting = nameof(MyTestEntityName.Sort); - } - - var specification = new MyTestEntityNameSpecification(input.Name); - var list = await _mytestentitynameRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification, includeDetails: true); - var result = ObjectMapper.Map<List<MyTestEntityName>, List<MyTestEntityNameDto>>(list); - - var sheets = new Dictionary<string, object> - { - ["閰嶇疆"] = result.Select(x => x.GetExportData()).ToList(), - }; - - var fileName = result.Count > 1 ? "MyTestEntityName鍒楄〃" : result.Count == 1 ? result.First()?.Name : "MyTestEntityName妯$増"; - return (sheets, fileName); - } - - /// <summary> - /// Checks the create or update dto asynchronous. - /// </summary> - /// <param name="input">The input.</param> - protected Task CheckCreateOrUpdateDtoAsync(MyTestEntityNameCreateOrUpdateDtoBase input) - { - Check.NotNull(input, nameof(input)); - Check.NotNullOrWhiteSpace(input.Code, "缂栧彿", MyTestEntityNameConsts.MaxCodeLength); - Check.NotNullOrWhiteSpace(input.Name, "鍚嶇О", MyTestEntityNameConsts.MaxNameLength); - Check.Length(input.Remark, "澶囨敞", MyTestEntityNameConsts.MaxRemarkLength); - return Task.CompletedTask; - } -} +// var response = new MesOrderResponse +// { +// Code = "000000", +// Data = orderModels, +// Fail = false, +// Mesg = "澶勭悊鎴愬姛", +// Success = true, +// Time = DateTime.UtcNow +// }; +// return response; +// } +//} -- Gitblit v1.9.3