From 91030ca8300557a1e03e17fb34167c16577aad45 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周一, 12 5月 2025 11:46:16 +0800
Subject: [PATCH] 优化代码

---
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Services/IWorkPlanAppService.cs                |    3 
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs                              |    5 
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs                              |   10 
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanController.cs                                     |  260 ++++++++++++++--------------
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Dtos/WorkPlan/WorkPlanCreateOrUpdateDtoBase.cs |   13 +
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/WorkPlanAppService.cs                         |    5 
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems/ProjectService/PipeLineLemsProjectService.cs                         |  191 ++++++++++++++++----
 7 files changed, 306 insertions(+), 181 deletions(-)

diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Dtos/WorkPlan/WorkPlanCreateOrUpdateDtoBase.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Dtos/WorkPlan/WorkPlanCreateOrUpdateDtoBase.cs
index c2c1949..1d6ca30 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Dtos/WorkPlan/WorkPlanCreateOrUpdateDtoBase.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Dtos/WorkPlan/WorkPlanCreateOrUpdateDtoBase.cs
@@ -183,11 +183,16 @@
         /// 鍒涘缓浜篒D
         /// </summary>
         public string? CreatorId { get; set; }
+    /// <summary>
+    /// 鍒涘缓浜�
+    /// </summary>
+    public string CreatorName { get; set; }
 
-        /// <summary>
-        /// 淇敼浜篒D
-        /// </summary>
-        public string? LastModifierId { get; set; }
+
+    /// <summary>
+    /// 淇敼浜篒D
+    /// </summary>
+    public string? LastModifierId { get; set; }
 
         /// <summary>
         /// 鍒犻櫎鏃堕棿
diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Services/IWorkPlanAppService.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Services/IWorkPlanAppService.cs
index c836361..513b7bd 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Services/IWorkPlanAppService.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application.Contracts/Services/IWorkPlanAppService.cs
@@ -1,6 +1,7 @@
 using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan;
 using CMS.Plugin.PipeLineLems.Domain.WorkPlan;
 using Volo.Abp.Application.Services;
+using Volo.Abp.Users;
 
 namespace CMS.Plugin.PipeLineLems.Application.Contracts.Services;
 
@@ -45,7 +46,7 @@
     /// </summary> 
     /// <param name="input"></param> 
     /// <returns></returns> 
-    Task ImportAsync(WorkPlansImportModel input);
+    Task ImportAsync(WorkPlansImportModel input, string userId,string userAccount);
 
     /// <summary> 
     /// 瀵煎嚭浣滀笟璁″垝琛� 
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 eb3c6a9..4a053d1 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/MesAppService.cs
@@ -8,6 +8,7 @@
 using CMS.Plugin.ProductManagement.Abstractions;
 using Microsoft.Extensions.DependencyInjection;
 using Volo.Abp;
+using Volo.Abp.Users;
 
 namespace CMS.Plugin.PipeLineLems.Application.Implements;
 
@@ -30,9 +31,9 @@
         _sharedService = sharedService;
     }
 
-    public async Task<MesOrderResponse> CreateAsync(List<WorkPlanInput> input)
+    public async Task<MesOrderResponse> CreateAsync(List<WorkPlanInput> input, string userId, string userAccount)
     {
-        var response = await _sharedService.CommonCreatebyApsAsync(input, _serviceProvider, _workPlanAppService);
+        var response = await _sharedService.CommonCreatebyApsAsync(input, _serviceProvider, _workPlanAppService, userId, userAccount);
 
         return response;
     }
diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
index 96e46e2..b56150f 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
@@ -15,6 +15,7 @@
 using System.Text;
 using CMS.Plugin.PipeLineLems.Domain.WorkPlan;
 using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrderRecord;
+using Volo.Abp.Users;
 
 namespace CMS.Plugin.PipeLineLems.Application.Implements;
 
@@ -33,9 +34,11 @@
     /// <exception cref="UserFriendlyException"></exception>
 
     public async Task<MesOrderResponse> CommonCreatebyApsAsync(List<WorkPlanInput> input, IServiceProvider _serviceProvider,
-        WorkPlanAppService workPlanAppService
+        WorkPlanAppService workPlanAppService,
+        string userId, string userAccount
         )
     {
+      
         if (input == null)
         {
             throw new UserFriendlyException("杈撳叆鍙傛暟涓嶈兘涓虹┖");
@@ -62,6 +65,7 @@
         var orderManager = _serviceProvider.GetRequiredService<IOrderManager>();
         var productProvider = _serviceProvider.GetRequiredService<IProductProvider>();
         var formulaProvider = _serviceProvider.GetRequiredService<IFormulaProvider>();
+
         List<OrderModel> orderModels = new List<OrderModel>();
 
         #region 浜嬪姟
@@ -185,7 +189,7 @@
 
 
 
-
+            //throw new UserFriendlyException($"涓诲姩瑙﹀彂澶辫触");
             //淇濆瓨鍒�  scms_workplans 琛ㄤ腑
             foreach (var item in input)
             {
@@ -194,6 +198,8 @@
                 insertObj.CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.鏈墽琛�;
                 insertObj.WorkPlanStatus = Domain.Shared.Enums.WorkPlanStatusEnum.鏈敓浜�;
                 insertObj.Sort = 1;
+                insertObj.CreatorId = userId;
+                insertObj.CreatorName = userAccount;
                 await workPlanAppService.CreateAsync(insertObj);
             }
 
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 285fecf..b85d09c 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/WorkPlanAppService.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/WorkPlanAppService.cs
@@ -10,6 +10,7 @@
 using Volo.Abp.Data;
 using Volo.Abp.ObjectExtending;
 using Volo.Abp.ObjectMapping;
+using Volo.Abp.Users;
 
 namespace CMS.Plugin.PipeLineLems.Application.Implements;
 
@@ -307,13 +308,13 @@
     /// <param name="input"></param> 
     /// <returns></returns> 
     /// <exception cref="UserFriendlyException"></exception> 
-    public async Task ImportAsync(WorkPlansImportModel input)
+    public async Task ImportAsync(WorkPlansImportModel input, string userId,string userAccount)
     {
         //杞崲鏁版嵁
         var result = ObjectMapper.Map<List<WorkPlansImportModel.WorkPlanImportModel>, List<WorkPlanInput>>(input.WorkPlans);
 
         //await CreatebyApsAsync(result);
-        await _sharedService.CommonCreatebyApsAsync(result, _serviceProvider, this);
+        await _sharedService.CommonCreatebyApsAsync(result, _serviceProvider, this, userId, userAccount);
         //        Check.NotNull(input, nameof(input)); 
 
         //        var workPlanCreateDtos = new List<(int RowIndex, WorkPlanCreateDto Item)>(); 
diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanController.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanController.cs
index e792517..22406bb 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanController.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/Controller/WorkPlanController.cs
@@ -1,75 +1,78 @@
-using Ao.Lang; 
-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.Authorization; 
-using Microsoft.AspNetCore.Http; 
-using Microsoft.AspNetCore.Mvc; 
-using MiniExcelLibs; 
-using System.Reflection; 
-using Volo.Abp; 
-using Volo.Abp.Application.Dtos; 
- 
-namespace CMS.Plugin.PipeLineLems.Controller 
-{ 
+using Ao.Lang;
+using CMS.Extensions.Abp.AspNetCore.Mvc.Filters;
+using CMS.Framework.AspNetCore.Users;
+using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan;
+using CMS.Plugin.PipeLineLems.Application.Contracts.Services;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using MiniExcelLibs;
+using System.Reflection;
+using Volo.Abp;
+using Volo.Abp.Application.Dtos;
+
+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 WorkPlanController : ControllerBase 
-    { 
-        private readonly IWorkPlanAppService _workPlanAppService; 
- 
+    [ApiController]
+    [TypeFilter(typeof(CMSLanguageFilter))]
+    [TypeFilter(typeof(CMSUowActionFilter))]
+    [TypeFilter(typeof(CMSAuditActionFilter))]
+    [TypeFilter(typeof(CMSExceptionFilter))]
+    [Route("api/v{version:apiVersion}/PipeLineLems/[controller]")]
+    public class WorkPlanController : ControllerBase
+    {
+        private readonly IWorkPlanAppService _workPlanAppService;
+        private readonly ICurrentUser _currentUser;
+
         /// <summary> 
         /// Initializes a new instance of the <see cref="WorkPlanController"/> class. 
         /// </summary> 
         /// <param name="workPlanAppService">The workPlan application service.</param> 
-        public WorkPlanController(IWorkPlanAppService workPlanAppService) 
-        { 
-            _workPlanAppService = workPlanAppService; 
-        } 
- 
+        public WorkPlanController(IWorkPlanAppService workPlanAppService, ICurrentUser currentUser)
+        {
+            _workPlanAppService = workPlanAppService;
+            _currentUser = currentUser;
+        }
+
         /// <summary> 
         /// 鑾峰彇浣滀笟璁″垝琛� 
         /// </summary> 
         /// <param name="id">鏍囪瘑绗�.</param> 
         /// <returns></returns> 
-        [HttpGet] 
-        [Route("{id}")] 
-        public virtual Task<WorkPlanDto> GetAsync(Guid id) 
-        { 
-            return _workPlanAppService.GetAsync(id); 
-        } 
- 
+        [HttpGet]
+        [Route("{id}")]
+        public virtual Task<WorkPlanDto> GetAsync(Guid id)
+        {
+            return _workPlanAppService.GetAsync(id);
+        }
+
         /// <summary> 
         /// 鍒嗛〉鑾峰彇浣滀笟璁″垝琛ㄧ殑鍒楄〃. 
         /// </summary> 
         /// <param name="input">杈撳叆.</param> 
         /// <returns></returns> 
-        [HttpGet] 
-        [Route("Page")] 
-        public virtual Task<PagedResultDto<WorkPlanDto>> GetListAsync([FromQuery] GetWorkPlanInput input) 
-        { 
-            return _workPlanAppService.GetListAsync(input); 
-        } 
- 
+        [HttpGet]
+        [Route("Page")]
+        public virtual Task<PagedResultDto<WorkPlanDto>> GetListAsync([FromQuery] GetWorkPlanInput input)
+        {
+            return _workPlanAppService.GetListAsync(input);
+        }
+
         /// <summary> 
         /// 鍒涘缓浣滀笟璁″垝琛� 
         /// </summary> 
         /// <param name="input">杈撳叆.</param> 
         /// <returns></returns> 
         //[Authorize] 
-        [HttpPost] 
-        public virtual Task<WorkPlanDto> CreateAsync(WorkPlanCreateDto input) 
-        { 
-            return _workPlanAppService.CreateAsync(input); 
-        } 
- 
+        [HttpPost]
+        public virtual Task<WorkPlanDto> CreateAsync(WorkPlanCreateDto input)
+        {
+            return _workPlanAppService.CreateAsync(input);
+        }
+
         /// <summary> 
         /// 鏇存柊浣滀笟璁″垝琛� 
         /// </summary> 
@@ -77,112 +80,115 @@
         /// <param name="input">杈撳叆.</param> 
         /// <returns></returns> 
         //[Authorize] 
-        [HttpPut] 
-        [Route("{id}")] 
-        public virtual Task<WorkPlanDto> UpdateAsync(Guid id, WorkPlanUpdateDto input) 
-        { 
-            return _workPlanAppService.UpdateAsync(id, input); 
-        } 
- 
+        [HttpPut]
+        [Route("{id}")]
+        public virtual Task<WorkPlanDto> UpdateAsync(Guid id, WorkPlanUpdateDto input)
+        {
+            return _workPlanAppService.UpdateAsync(id, input);
+        }
+
         /// <summary> 
         /// 鍏嬮殕浣滀笟璁″垝琛� 
         /// </summary> 
         /// <param name="ids">Id闆嗗悎.</param> 
         /// <returns></returns> 
         //[Authorize] 
-        [HttpPost] 
-        [Route("Clone")] 
-        public virtual Task<List<WorkPlanDto>> CloneAsync([FromBody] IEnumerable<Guid> ids) 
-        { 
-            return _workPlanAppService.CloneAsync(ids); 
-        } 
- 
+        [HttpPost]
+        [Route("Clone")]
+        public virtual Task<List<WorkPlanDto>> CloneAsync([FromBody] IEnumerable<Guid> ids)
+        {
+            return _workPlanAppService.CloneAsync(ids);
+        }
+
         /// <summary> 
         /// 鍒犻櫎浣滀笟璁″垝琛� 
         /// </summary> 
         /// <param name="id">鏍囪瘑绗�.</param> 
         /// <returns></returns> 
         //[Authorize] 
-        [HttpDelete] 
-        [Route("{id}")] 
-        public virtual Task DeleteAsync(Guid id) 
-        { 
-            return _workPlanAppService.DeleteAsync(id); 
-        } 
- 
+        [HttpDelete]
+        [Route("{id}")]
+        public virtual Task DeleteAsync(Guid id)
+        {
+            return _workPlanAppService.DeleteAsync(id);
+        }
+
         /// <summary> 
         /// 鎵归噺鍒犻櫎浣滀笟璁″垝琛� 
         /// </summary> 
         /// <param name="ids">The ids.</param> 
         /// <returns></returns> 
         //[Authorize] 
-        [HttpDelete] 
-        public virtual Task DeleteAsync([FromBody] IEnumerable<Guid> ids) 
-        { 
-            return _workPlanAppService.DeleteManyAsync(ids); 
-        } 
- 
+        [HttpDelete]
+        public virtual Task DeleteAsync([FromBody] IEnumerable<Guid> ids)
+        {
+            return _workPlanAppService.DeleteManyAsync(ids);
+        }
+
         /// <summary> 
         /// 璋冩暣鎺掑簭浣滀笟璁″垝琛� 
         /// </summary> 
         /// <param name="id">鏍囪瘑绗�.</param> 
         /// <returns></returns> 
-        [HttpPut] 
-        [Route("{id}/AdjustSort/{sort}")] 
-        public virtual Task AdjustSortAsync(Guid id, int sort) 
-        { 
-            return _workPlanAppService.AdjustSortAsync(id, sort); 
-        } 
- 
+        [HttpPut]
+        [Route("{id}/AdjustSort/{sort}")]
+        public virtual Task AdjustSortAsync(Guid id, int sort)
+        {
+            return _workPlanAppService.AdjustSortAsync(id, sort);
+        }
+
         /// <summary> 
         /// 瀵煎叆浣滀笟璁″垝琛� 
         /// </summary> 
         /// <returns></returns> 
-        [Authorize] 
-        [HttpPost] 
-        [Route("Import")] 
-        public virtual async Task<IActionResult> ImportAsync(IFormFile file) 
-        { 
-            using var stream = new MemoryStream(); 
-            await file.CopyToAsync(stream); 
-            stream.Seek(0L, SeekOrigin.Begin); 
- 
-            var sheetNames = stream.GetSheetNames(); 
-            var workPlanRows = sheetNames.Contains("閰嶇疆") ? MiniExcel.Query<WorkPlansImportModel.WorkPlanImportModel>(stream, sheetName: "閰嶇疆").ToList() : new(); 
- 
-            if (!workPlanRows.Any()) 
-            { 
-                throw new UserFriendlyException("璇锋鏌ュ鍏ョ殑琛ㄦ牸"); 
-            } 
- 
-            await _workPlanAppService.ImportAsync(new WorkPlansImportModel 
-            { 
-                WorkPlans = workPlanRows, 
-            }); 
- 
-            return Ok(); 
-        } 
- 
+        [Authorize]
+        [HttpPost]
+        [Route("Import")]
+        public virtual async Task<IActionResult> ImportAsync(IFormFile file)
+        {
+            using var stream = new MemoryStream();
+            await file.CopyToAsync(stream);
+            stream.Seek(0L, SeekOrigin.Begin);
+
+            var userAccount = _currentUser.UserAccount;
+            var userId = _currentUser.UserId;
+
+            var sheetNames = stream.GetSheetNames();
+            var workPlanRows = sheetNames.Contains("閰嶇疆") ? MiniExcel.Query<WorkPlansImportModel.WorkPlanImportModel>(stream, sheetName: "閰嶇疆").ToList() : new();
+
+            if (!workPlanRows.Any())
+            {
+                throw new UserFriendlyException("璇锋鏌ュ鍏ョ殑琛ㄦ牸");
+            }
+
+            await _workPlanAppService.ImportAsync(new WorkPlansImportModel
+            {
+                WorkPlans = workPlanRows,
+            }, userId, userAccount);
+
+            return Ok();
+        }
+
         /// <summary> 
         /// 瀵煎嚭浣滀笟璁″垝琛� 
         /// </summary> 
         /// <returns></returns> 
-        [HttpGet] 
-        [Route("Export")] 
-        public virtual async Task<IActionResult> ExportAsync([FromQuery] GetWorkPlanInput input) 
-        { 
-            input.MaxResultCount = int.MaxValue; 
-            var exportData = await _workPlanAppService.ExportAsync(input); 
-            var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/WorkPlan瀵煎嚭妯℃澘.xlsx"); 
-            if (!System.IO.File.Exists(templatePath)) 
-            { 
-                templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/WorkPlan瀵煎嚭妯℃澘.xlsx"); 
-            } 
- 
-            var memoryStream = new MemoryStream(); 
-            await memoryStream.SaveAsByTemplateAsync(templatePath, exportData.Sheets); 
-            memoryStream.Seek(0L, SeekOrigin.Begin); 
-            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"{exportData.FileName}_{DateTime.Now:yyyyMMddhhmmss}.xlsx" }; 
-        } 
-    } 
-} 
+        [HttpGet]
+        [Route("Export")]
+        public virtual async Task<IActionResult> ExportAsync([FromQuery] GetWorkPlanInput input)
+        {
+            input.MaxResultCount = int.MaxValue;
+            var exportData = await _workPlanAppService.ExportAsync(input);
+            var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/WorkPlan瀵煎嚭妯℃澘.xlsx");
+            if (!System.IO.File.Exists(templatePath))
+            {
+                templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/WorkPlan瀵煎嚭妯℃澘.xlsx");
+            }
+
+            var memoryStream = new MemoryStream();
+            await memoryStream.SaveAsByTemplateAsync(templatePath, exportData.Sheets);
+            memoryStream.Seek(0L, SeekOrigin.Begin);
+            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"{exportData.FileName}_{DateTime.Now:yyyyMMddhhmmss}.xlsx" };
+        }
+    }
+}
diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/ProjectService/PipeLineLemsProjectService.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/ProjectService/PipeLineLemsProjectService.cs
index df8778c..e390ae1 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/ProjectService/PipeLineLemsProjectService.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems/ProjectService/PipeLineLemsProjectService.cs
@@ -20,6 +20,7 @@
 using CMS.Plugin.PipeLineLems.Domain.WorkPlan;
 using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrder;
 using System.Collections.Generic;
+using CMS.Framework.AspNetCore.Users;
 
 namespace CMS.Plugin.PipeLineLems.ProjectService
 {
@@ -31,6 +32,7 @@
         private IServiceProvider _serviceProvider;
         private readonly ILogger<PipeLineLemsProjectService> _logger;
         private readonly IVariableDataCache _variableDataCache;
+
 
         /// <summary>
         /// 鍙橀噺鏈嶅姟
@@ -84,6 +86,7 @@
             _monitorVariableNames = new Dictionary<string, string>
             {
                 { "鎵撶爜杩涚珯淇″彿", "鎵撶爜杩涚珯淇″彿(鎻忚堪)" },
+                { "璇锋眰鐢熸垚鎵撶爜浜у搧鐮佷俊鍙�", "璇锋眰鐢熸垚鎵撶爜浜у搧鐮佷俊鍙�(鎻忚堪)" },
                 { "鍒囧壊杩涚珯淇″彿", "鍒囧壊杩涚珯淇″彿(鎻忚堪)" },
             };
 
@@ -142,6 +145,30 @@
 
                 _logger.LogInformation($"{changed.Name} 鍙橀噺鍊煎彂鐢熷彉鍖栵紝鏃у�納oldValue}=鏂板�納newValue}锛孴raceId={traceId}");
 
+                if (changed.Name == "璇锋眰鐢熸垚鎵撶爜浜у搧鐮佷俊鍙�" && changed.New?.Value.SafeString().ToBool() == true)
+                {
+
+                    // TODO: 澶勭悊鍙橀噺鍊煎彉鍖�
+                    // Tips锛歨ttps://cms-docs.shengyc.com/cms/api/%E5%90%8E%E7%AB%AF#3-%E5%8F%98%E9%87%8F%E6%A8%A1%E5%9D%97
+                    /* 璇存槑锛氶�氳繃璁㈤槄 IVariableDataCache.TagChanged 浜嬩欢锛屾偍鍙互瀹炴椂鐩戞帶鍙橀噺鐨勫彉鍖栥�傛浜嬩欢浼氫紶閫掓墍鏈夊彉閲忚嚦浜嬩欢澶勭悊鍑芥暟锛屽洜姝わ紝涓氬姟灞傞渶鍦ㄥ嚱鏁颁腑绛涢�夊叧娉ㄧ殑鍙橀噺銆�
+                        娉ㄦ剰浜嬮」锛�
+                        锛�1锛夋�ц兘褰卞搷锛� 鍙戝竷浜嬩欢鏃讹紝浜嬩欢鐨勫彂閫佽�呭皢闃诲娴佺▼銆傚洜姝わ紝寮虹儓寤鸿閬垮厤鍦ㄤ簨浠跺鐞嗗嚱鏁颁腑鎵ц I/ O 鎿嶄綔銆丠TTP 鎺ュ彛璁块棶鎴栧叾浠栬�楁椂鎿嶄綔锛屼互闃叉瀵圭郴缁熸�ц兘浜х敓涓ラ噸褰卞搷锛屽鑷存暣涓郴缁熷搷搴斿欢杩熴��
+                        锛�2锛夐珮棰戠巼瑙﹀彂锛� 鐢变簬浜嬩欢璁㈤槄浜嗗叏閲忓彉閲忥紝瑙﹀彂棰戠巼鍙兘闈炲父楂樸��
+                        锛�3锛夊紓姝ュ鐞嗭細 閴翠簬浜嬩欢瑙﹀彂棰戠巼寰堥珮锛屽缓璁笟鍔″眰鍦ㄧ瓫閫夊叧娉ㄥ彉閲忓悗锛屼娇鐢� Task 鍚姩鏂扮嚎绋嬪鐞嗕笟鍔¢�昏緫锛屼互閬垮厤闃诲鏍稿績鐨勫彉閲忕洃鍚姛鑳斤紝瀹炵幇涓氬姟灞備笌骞冲彴鍩哄骇鐨勮В鑰︺��
+                        锛�4锛夊苟鍙戠鐞嗭細 濡傛灉涓氬姟灞傚苟鍙戦噺澶э紝蹇呴』浼樺寲浠g爜璁捐鍜屽疄鏂斤紝浠ュ噺灏戝湪楂樺苟鍙戞儏鍐典笅鐨勭郴缁熻祫婧愭秷鑰楋紝闃叉绯荤粺鎬ц兘闂銆�
+                        锛�5锛変唬鐮佸畨鍏細 瀹夎骞朵娇鐢� CMS.CodeAnalysis 鍒嗘瀽鍣ㄦ潵鍒嗘瀽 IVariableDataCache.TagChanged 鐨勪娇鐢ㄦ儏鍐点�傝宸ュ叿鑳藉湪浣跨敤涓嶅綋鏃舵彁渚涚紪璇戦敊璇紝甯姪鎮ㄦ彁楂樹唬鐮佽川閲忋��*/
+
+                    _ = Task.Run(async () =>
+                    {
+                        await HanlderForPringBarCodeByCreateProductAsync();
+                        // 渚�1锛氬悓姝ュ鐞�
+                        //await ProcessAsync();
+
+                        // 渚�2锛氳皟鐢ㄥ閮ˋPI
+                        //await ExecuteExternalApiAsync();
+                    });
+                }
+
                 if (changed.Name == "鎵撶爜杩涚珯淇″彿" && changed.New?.Value.SafeString().ToBool() == true)
                 {
 
@@ -165,6 +192,8 @@
                         //await ExecuteExternalApiAsync();
                     });
                 }
+
+
 
                 if (changed.Name == "鍒囧壊杩涚珯淇″彿" && changed.New?.Value.SafeString().ToBool() == true)
                 {
@@ -229,10 +258,128 @@
         }
 
         /// <summary>
-        /// 鎵撶爜
+        /// 鎵撶爜杩涚珯淇″彿
         /// </summary>
         /// <returns></returns>
         private async Task HanlderForPringBarCodeAsync()
+        {
+
+            var workPlanAppService = _serviceProvider.GetRequiredService<IWorkPlanAppService>();
+            var workPlanRepository = _serviceProvider.GetRequiredService<IWorkPlanRepository>();
+            var callMaterialOrderAppService = _serviceProvider.GetRequiredService<ICallMaterialOrderAppService>();
+
+            using var scope = _serviceProvider.CreateScope();
+            var unitOfWorkManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
+            using var uow = unitOfWorkManager.Begin(requiresNew: true);
+
+            var plcTaskNo = await _variableService.ReadValueAsync("鎵撶爜杩涚珯PLC浠诲姟鍙�");
+
+            if (string.IsNullOrEmpty(plcTaskNo?.Content?.Value.SafeString().ToString()))
+            {
+
+            }
+            else
+            {
+
+
+
+                var myTaskNo = plcTaskNo.Content.Value.SafeString().ToString();
+                CallMaterialOrder callMaterialOrder = null;
+                try
+                {
+                    //鏍规嵁wms浠诲姟鍙峰鎵� 鍙枡宸ュ崟
+                    callMaterialOrder = await callMaterialOrderAppService.FindByWmsTaskNoAsync(myTaskNo);
+                    if (callMaterialOrder == null) return;//缁撴潫
+
+
+
+                    //鏍规嵁鍘熸枡鏍囪瘑瀵绘壘 浣滀笟璁″垝
+                    var workPlanList = await workPlanAppService.FindByDataIdentifierAsync(callMaterialOrder.DataIdentifier);
+                    if (workPlanList?.Count == 0) return;//缁撴潫
+
+                    ////TODO:鏆傛椂鐢熸垚浜у搧ID
+                    ////var productID = DateTime.Now.ToString("yyyyMMddHHmmssfff");
+                    //var productID = workPlanList.First().PipeSpecCode;
+                    //Dictionary<string, object?> keyValuePairs_productID = new Dictionary<string, object?>
+                    //{
+                    //    { "鎵撶爜_ProductID", productID},
+                    //};
+                    //var ret = _variableService.WriteValueAsync(keyValuePairs_productID);
+
+                    ////鏇存柊涓虹敓浜т腑 
+                    //foreach (var item in workPlanList)
+                    //{
+                    //    item.WorkPlanStatus = Domain.Shared.Enums.WorkPlanStatusEnum.鐢熶骇涓�;
+                    //}
+                    //await workPlanRepository.UpdateManyAsync(workPlanList);
+
+                    //寰楀埌鐮佸��
+                    var code1 = "";
+                    var code2 = "";
+                    var code3 = "";
+                    var pipeSpecCode1 = "";
+                    var pipeSpecCode2 = "";
+                    var pipeSpecCode3 = "";
+                    var new_workPlanList = workPlanList.Where(x => x.ProcessRouteNumber == "鍒囧壊").ToList();
+                    for (int i = 0; i < new_workPlanList.Count; i++)
+                    {
+                        if (i == 0)
+                        {
+                            code1 = new_workPlanList[i].MarkingContent;
+                            pipeSpecCode1 = new_workPlanList[i].PipeSpecCode;
+                        }
+                        if (i == 1)
+                        {
+                            code2 = new_workPlanList[i].MarkingContent;
+                            pipeSpecCode2 = new_workPlanList[i].PipeSpecCode;
+                        }
+                        if (i == 2)
+                        {
+                            code3 = new_workPlanList[i].MarkingContent;
+                            pipeSpecCode3 = new_workPlanList[i].PipeSpecCode;
+                        }
+                    }
+                    Dictionary<string, object?> keyValuePairs = new Dictionary<string, object?>
+                    {
+                        { "鎵撶爜宸ヤ欢1",code1},
+                        { "鎵撶爜宸ヤ欢2", code2},
+                        { "鎵撶爜宸ヤ欢3", code3 },
+                        { "鎵撶爜绠℃缂栫爜1",pipeSpecCode1},
+                        { "鎵撶爜绠℃缂栫爜2", pipeSpecCode2},
+                        { "鎵撶爜绠℃缂栫爜3", pipeSpecCode3 },
+                        { "鎵撶爜绠℃缂栫爜", new_workPlanList.First().PipeSpecCode },
+                        { "鎵撶爜绠℃鍚嶇О", new_workPlanList.First().PipeSectionName },
+                        { "鎵撶爜鍘熸枡绠″瀷鍙�", new_workPlanList.First().MaterialMode },
+                        { "鎵撶爜鍘熸枡鏍囪瘑", new_workPlanList.First().DataIdentifier }
+                    };
+                    _variableService.WriteValueAsync(keyValuePairs);
+
+                    //TODO:妯℃嫙閲囬泦鍙傛暟
+                    keyValuePairs = new Dictionary<string, object?>
+                    {
+                        { "鎵撶爜閫熷害", 100},
+                        { "鎵撶爜璐ㄩ噺", 2},
+                    };
+                    var ret2 = _variableService.WriteValueAsync(keyValuePairs);
+
+
+
+
+                    uow.CompleteAsync();
+                }
+                catch (Exception)
+                {
+                    uow.RollbackAsync();
+                    throw;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 璇锋眰鐢熸垚鎵撶爜浜у搧鐮佷俊鍙�
+        /// </summary>
+        /// <returns></returns>
+        private async Task HanlderForPringBarCodeByCreateProductAsync()
         {
 
             var workPlanAppService = _serviceProvider.GetRequiredService<IWorkPlanAppService>();
@@ -283,48 +430,6 @@
                         item.WorkPlanStatus = Domain.Shared.Enums.WorkPlanStatusEnum.鐢熶骇涓�;
                     }
                     await workPlanRepository.UpdateManyAsync(workPlanList);
-
-                    //寰楀埌鐮佸��
-                    var code1 = "";
-                    var code2 = "";
-                    var code3 = "";
-                    var new_workPlanList = workPlanList.Where(x => x.ProcessRouteNumber == "鍒囧壊").ToList();
-                    for (int i = 0; i < new_workPlanList.Count; i++)
-                    {
-                        if (i == 0)
-                        {
-                            code1 = new_workPlanList[i].MarkingContent;
-                        }
-                        if (i == 1)
-                        {
-                            code2 = new_workPlanList[i].MarkingContent;
-                        }
-                        if (i == 2)
-                        {
-                            code3 = new_workPlanList[i].MarkingContent;
-                        }
-                    }
-                    Dictionary<string, object?> keyValuePairs = new Dictionary<string, object?>
-                    {
-                        { "鎵撶爜宸ヤ欢1",code1},
-                        { "鎵撶爜宸ヤ欢2", code2},
-                        { "鎵撶爜宸ヤ欢3", code3 },
-                        { "鎵撶爜绠℃缂栫爜", new_workPlanList.First().PipeSpecCode },
-                        { "鎵撶爜绠℃鍚嶇О", new_workPlanList.First().PipeSectionName },
-                        { "鎵撶爜鍘熸枡绠″瀷鍙�", new_workPlanList.First().MaterialMode },
-                        { "鎵撶爜鍘熸枡鏍囪瘑", new_workPlanList.First().DataIdentifier }
-                    };
-                    _variableService.WriteValueAsync(keyValuePairs);
-
-                    //TODO:妯℃嫙閲囬泦鍙傛暟
-                    keyValuePairs = new Dictionary<string, object?>
-                    {
-                        { "鎵撶爜閫熷害", 100},
-                        { "鎵撶爜璐ㄩ噺", 2},
-                    };
-                    var ret2 = _variableService.WriteValueAsync(keyValuePairs);
-
-
 
 
                     uow.CompleteAsync();

--
Gitblit v1.9.3