From 9bec4dcae002f36aa23231da11cb03a156b40110 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周三, 30 4月 2025 16:24:16 +0800 Subject: [PATCH] 222 --- PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs | 378 ++++++++++++++++------------------------------------- 1 files changed, 114 insertions(+), 264 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..edb8a13 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,158 @@ +using CMS.Plugin.FormulaManagement.Abstractions; +using CMS.Plugin.MesSuite.Abstractions.Events; +using CMS.Plugin.OrderManagement.Abstractions.Enums; +using CMS.Plugin.OrderManagement.Abstractions.Models; +using CMS.Plugin.OrderManagement.Abstractions; 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 CMS.Plugin.ProductManagement.Abstractions; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Data; using Volo.Abp.ObjectExtending; +using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan; +using Volo.Abp.EventBus; namespace CMS.Plugin.PipeLineLems.Application.Implements; -/// <inheritdoc /> -public class MesAppService : CMSPluginAppService, IMesAppService +public class MesAppService : IMesAppService { - private readonly IMyTestEntityNameRepository _mytestentitynameRepository; + private readonly IServiceProvider _serviceProvider; - /// <summary> - /// Initializes a new instance of the <see cref="MyTestEntityNameAppService"/> class. - /// </summary> - /// <param name="mytestentitynameRepository">The task job repository.</param> - public MesAppService(IMyTestEntityNameRepository mytestentitynameRepository) + //private readonly IEventBus _eventBus; + + public MesAppService(IServiceProvider serviceProvider + //, IEventBus eventBus + ) { - _mytestentitynameRepository = mytestentitynameRepository; + _serviceProvider = serviceProvider; + // _eventBus = eventBus; } - /// <inheritdoc /> - public virtual async Task<MyTestEntityNameDto> GetAsync(Guid id) + public async Task<MesOrderResponse> CreateAsync(List<WorkPlanInput> input) { - return ObjectMapper.Map<MyTestEntityName, MyTestEntityNameDto>(await _mytestentitynameRepository.GetAsync(id)); - } - - /// <inheritdoc /> - public virtual async Task<PagedResultDto<MyTestEntityNameDto>> GetListAsync(GetMyTestEntityNamesInput input) - { - Check.NotNull(input, nameof(input)); - - if (input.Sorting.IsNullOrWhiteSpace()) + if (input == null) { - input.Sorting = nameof(MyTestEntityName.Sort); + throw new UserFriendlyException("杈撳叆鍙傛暟涓嶈兘涓虹┖"); } - 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); - - 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 exist = await _mytestentitynameRepository.NameExistAsync(input.Name); - if (exist) + if (input.Count == 0) { - throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.Name]); + throw new UserFriendlyException("杈撳叆鍙傛暟Data涓嶈兘涓虹┖"); } - 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); - - await _mytestentitynameRepository.InsertAsync(mytestentityname); - - if (input.Sort.HasValue && mytestentityname.Sort != maxSort) + 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) { - await AdjustSortAsync(mytestentityname.Id, mytestentityname.Sort); - } - - return ObjectMapper.Map<MyTestEntityName, MyTestEntityNameDto>(mytestentityname); - } - - /// <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); - - mytestentityname.Update(input.Code, input.Name, input.Remark); - - await _mytestentitynameRepository.UpdateAsync(mytestentityname); - - 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 taskCode = gTask.Key; + var order = await orderManager.GetByCodeAsync(taskCode); + if (order != null) { - 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); + throw new UserFriendlyException($"宸ュ崟[{taskCode}]宸插瓨鍦�"); } - #endregion - foreach (var mytestentityname in mytestentitynames) + //var product = await productProvider.FindByNameAsync(orderItem.PipeSectionName); + //if (product == null) + //{ + // throw new UserFriendlyException($"浜у搧鍚嶇О[{orderItem.PipeSectionName}]涓嶅瓨鍦�"); + //} + + //var formula = await formulaProvider.GetFormulaAsync(product.Id); + //if (formula == null) + //{ + // throw new UserFriendlyException($"浜у搧鍨嬪彿[{orderItem.MaterialCode}]鏃犲叧鑱旈厤鏂�"); + //} + //棣栧厛瑕佸垱寤� 鎵撶爜鍒囧壊鐨勫伐鍗� + var productForCut = await productProvider.FindByNameAsync("鍒囧壊鍘熸枡绠�"); + if (productForCut == null) { - if (mytestentityname.Code.IsNullOrWhiteSpace() && mytestentityname.Name.IsNullOrWhiteSpace()) + 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() { - continue; + 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 orderForCut = await orderManager.GetByCodeAsync(orderModelForCut.Code); + if (orderForCut != null) + { + //throw new UserFriendlyException($"宸ュ崟[{orderModelForCut.Code}]宸插瓨鍦�"); + //涓嶅啀鎶涘紓甯革紝鐩存帴璺宠繃 + break; } - if (mytestentityname.Name.IsNullOrWhiteSpace()) + var orderModelResultForCut = await orderManager.CreateAsync(orderModelForCut); + if (orderModelResultForCut == null) { - var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝绗瑊mytestentityname.RowIndex}琛岋細MyTestEntityName鍚嶇О涓嶈兘涓虹┖"; - throw new UserFriendlyException(errorMsg); + throw new UserFriendlyException($"宸ュ崟[{orderModelForCut.Code}]鍒涘缓澶辫触"); } + orderModels.Add(orderModelResultForCut); - 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)); - } + //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); } + } - // 鏂板 - foreach (var mytestentitynameDto in mytestentitynameCreateDtos) + // 鍙戝竷浜嬩欢 + //await _eventBus.PublishAsync(new EntityChangedEto("MESCREATE", input, null, EntityChangeType.Add, true)); + + var response = new MesOrderResponse { - 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(), + Code = "000000", + Data = orderModels, + Fail = false, + Mesg = "澶勭悊鎴愬姛", + Success = true, + Time = DateTime.UtcNow }; - - 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; + return response; } } -- Gitblit v1.9.3