From 4209c8ff313ce8bac44bc9fe0b2260111a3fb388 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周六, 10 5月 2025 15:22:13 +0800 Subject: [PATCH] 优化接口 --- PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs | 4 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs | 153 +++++++++++++++++++++ PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/WorkPlanAppService.cs | 138 +------------------ PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanPublicController.cs | 78 +++++----- 4 files changed, 201 insertions(+), 172 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 a051028..c9f2648 100644 --- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs +++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs @@ -11,14 +11,14 @@ namespace CMS.Plugin.PipeLineLems.Application.Implements; -public class SharedService : CMSPluginAppService +public class MesAppService : CMSPluginAppService { private readonly IServiceProvider _serviceProvider; private readonly IWorkPlanAppService _workPlanAppService; //private readonly IEventBus _eventBus; - public SharedService(IServiceProvider serviceProvider + public MesAppService(IServiceProvider serviceProvider , IWorkPlanAppService workPlanAppService //, IEventBus eventBus ) diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs new file mode 100644 index 0000000..2e16c41 --- /dev/null +++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs @@ -0,0 +1,153 @@ +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.ProductManagement.Abstractions; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Microsoft.Extensions.DependencyInjection; + +namespace CMS.Plugin.PipeLineLems.Application.Implements; + +/// <summary> +/// 浣滀笟璁″垝琛ㄥ簲鐢ㄦ湇鍔� +/// </summary> +public class SharedService: CMSPluginAppService +{ + + public async Task<MesOrderResponse> CommonCreatebyApsAsync(List<WorkPlanInput> input, IServiceProvider _serviceProvider, WorkPlanAppService workPlanAppService) + { + if (input == null) + { + throw new UserFriendlyException("杈撳叆鍙傛暟涓嶈兘涓虹┖"); + } + + if (input.Count == 0) + { + throw new UserFriendlyException("杈撳叆鍙傛暟Data涓嶈兘涓虹┖"); + } + + 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}]宸插瓨鍦�"); + } + + + //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) + { + 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 orderForCut = await orderManager.GetByCodeAsync(orderModelForCut.Code); + if (orderForCut != null) + { + //throw new UserFriendlyException($"宸ュ崟[{orderModelForCut.Code}]宸插瓨鍦�"); + //涓嶅啀鎶涘紓甯革紝鐩存帴璺宠繃 + break; + } + + var orderModelResultForCut = await orderManager.CreateAsync(orderModelForCut); + if (orderModelResultForCut == null) + { + throw new UserFriendlyException($"宸ュ崟[{orderModelForCut.Code}]鍒涘缓澶辫触"); + } + orderModels.Add(orderModelResultForCut); + + + //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 item in input) + { + var insertObj = ObjectMapper.Map<WorkPlanInput, WorkPlanCreateDto>(item); + //insertObj.OrgMaterialCode = "1111"; + insertObj.Sort = 1; + await workPlanAppService.CreateAsync(insertObj); + } + + + // 鍙戝竷浜嬩欢 + //await _eventBus.PublishAsync(new EntityChangedEto("MESCREATE", input, null, EntityChangeType.Add, true)); + + var response = new MesOrderResponse + { + Code = "000000", + Data = orderModels, + Fail = false, + Mesg = "澶勭悊鎴愬姛", + Success = true, + Time = DateTime.UtcNow + }; + return response; + } + +} diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/WorkPlanAppService.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/WorkPlanAppService.cs index dccb3af..0b1715d 100644 --- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/WorkPlanAppService.cs +++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/WorkPlanAppService.cs @@ -26,15 +26,17 @@ { private readonly IWorkPlanRepository workPlanRepository; private readonly IServiceProvider _serviceProvider; + private readonly SharedService _sharedService; /// <summary> /// Initializes a new instance of the <see cref="WorkPlanAppService"/> class. /// </summary> /// <param name="WorkPlanRepository">The task job repository.</param> - public WorkPlanAppService(IWorkPlanRepository _WorkPlanRepository, IServiceProvider serviceProvider) + public WorkPlanAppService(IWorkPlanRepository _WorkPlanRepository, IServiceProvider serviceProvider, SharedService sharedService) { workPlanRepository = _WorkPlanRepository; _serviceProvider = serviceProvider; + _sharedService = sharedService; } /// <summary> @@ -305,141 +307,15 @@ //杞崲鏁版嵁 var result = ObjectMapper.Map<List<WorkPlansImportModel.WorkPlanImportModel>, List<WorkPlanInput>>(input.WorkPlans); - await CreatebyApsAsync(result); + //await CreatebyApsAsync(result); + await _sharedService.CommonCreatebyApsAsync(result, _serviceProvider, this); } public async Task<MesOrderResponse> CreatebyApsAsync(List<WorkPlanInput> input) { - if (input == null) - { - throw new UserFriendlyException("杈撳叆鍙傛暟涓嶈兘涓虹┖"); - } - - if (input.Count == 0) - { - throw new UserFriendlyException("杈撳叆鍙傛暟Data涓嶈兘涓虹┖"); - } - - 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}]宸插瓨鍦�"); - } - - - //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) - { - 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 orderForCut = await orderManager.GetByCodeAsync(orderModelForCut.Code); - if (orderForCut != null) - { - //throw new UserFriendlyException($"宸ュ崟[{orderModelForCut.Code}]宸插瓨鍦�"); - //涓嶅啀鎶涘紓甯革紝鐩存帴璺宠繃 - break; - } - - var orderModelResultForCut = await orderManager.CreateAsync(orderModelForCut); - if (orderModelResultForCut == null) - { - throw new UserFriendlyException($"宸ュ崟[{orderModelForCut.Code}]鍒涘缓澶辫触"); - } - orderModels.Add(orderModelResultForCut); - - - //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 item in input) - { - var insertObj = ObjectMapper.Map<WorkPlanInput, WorkPlanCreateDto>(item); - //insertObj.OrgMaterialCode = "1111"; - insertObj.Sort = 1; - await CreateAsync(insertObj); - } - - - // 鍙戝竷浜嬩欢 - //await _eventBus.PublishAsync(new EntityChangedEto("MESCREATE", input, null, EntityChangeType.Add, true)); - - var response = new MesOrderResponse - { - Code = "000000", - Data = orderModels, - Fail = false, - Mesg = "澶勭悊鎴愬姛", - Success = true, - Time = DateTime.UtcNow - }; + var response=await _sharedService.CommonCreatebyApsAsync(input, _serviceProvider, this); + return response; } diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanPublicController.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanPublicController.cs index 354df06..49f808e 100644 --- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanPublicController.cs +++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanPublicController.cs @@ -1,44 +1,44 @@ -using CMS.Extensions.Abp.AspNetCore.Mvc.Filters; -using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan; -using CMS.Plugin.PipeLineLems.Application.Contracts.Services; -using Microsoft.AspNetCore.Mvc; -using System.Reflection; +//using CMS.Extensions.Abp.AspNetCore.Mvc.Filters; +//using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan; +//using CMS.Plugin.PipeLineLems.Application.Contracts.Services; +//using Microsoft.AspNetCore.Mvc; +//using System.Reflection; -namespace CMS.Plugin.PipeLineLems.Controller -{ - /// <summary> - /// 浣滀笟璁″垝鏈嶅姟 - /// </summary> - [ApiController] - [TypeFilter(typeof(CMSLanguageFilter))] - [TypeFilter(typeof(CMSUowActionFilter))] - [TypeFilter(typeof(CMSAuditActionFilter))] - [TypeFilter(typeof(CMSExceptionFilter))] - [Route("api/v{version:apiVersion}/PipeLineLems/[controller]")] - public class WorkPlanPublicController : ControllerBase - { +//namespace CMS.Plugin.PipeLineLems.Controller +//{ +// /// <summary> +// /// 浣滀笟璁″垝鏈嶅姟 +// /// </summary> +// [ApiController] +// [TypeFilter(typeof(CMSLanguageFilter))] +// [TypeFilter(typeof(CMSUowActionFilter))] +// [TypeFilter(typeof(CMSAuditActionFilter))] +// [TypeFilter(typeof(CMSExceptionFilter))] +// [Route("api/v{version:apiVersion}/PipeLineLems/[controller]")] +// public class WorkPlanPublicController : ControllerBase +// { - private readonly IMesAppService _mesAppService; - /// <summary> - /// Initializes a new instance of the <see cref="TestEntityNameController"/> class. - /// </summary> - /// <param name="testentitynameAppService">The testentityname application service.</param> - public WorkPlanPublicController(IMesAppService mesAppService) - { - _mesAppService = mesAppService; - } +// private readonly IMesAppService _mesAppService; +// /// <summary> +// /// Initializes a new instance of the <see cref="TestEntityNameController"/> class. +// /// </summary> +// /// <param name="testentitynameAppService">The testentityname application service.</param> +// public WorkPlanPublicController(IMesAppService mesAppService) +// { +// _mesAppService = mesAppService; +// } - /// <summary> - /// 鑾峰彇鐢熶骇璁″垝. - /// </summary> - /// <param name="input">鏍囪瘑绗�.</param> - /// <returns></returns> - [HttpPost] - public virtual async Task<MesOrderResponse> GetWorkPlanAsync([FromBody] List<WorkPlanInput> input) - { - return await _mesAppService.CreateAsync(input); - } +// /// <summary> +// /// 鑾峰彇鐢熶骇璁″垝. +// /// </summary> +// /// <param name="input">鏍囪瘑绗�.</param> +// /// <returns></returns> +// [HttpPost] +// public virtual async Task<MesOrderResponse> GetWorkPlanAsync([FromBody] List<WorkPlanInput> input) +// { +// return await _mesAppService.CreateAsync(input); +// } - } -} +// } +//} -- Gitblit v1.9.3