From 7d410c1f0d4e36f8281ce2277f355c9abf1c231b Mon Sep 17 00:00:00 2001
From: zs <zhousong@weben-smart.com>
Date: 周五, 16 5月 2025 16:19:36 +0800
Subject: [PATCH] Merge branch 'master' of http://222.71.245.114:9086/r/HIA24016N_PipeLineDemo

---
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs |  110 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 93 insertions(+), 17 deletions(-)

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 c3dc2d5..58720e2 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/SharedService.cs
@@ -25,6 +25,12 @@
 using CMS.Plugin.TraceManagement.Abstractions;
 using CMS.Plugin.ProductManagement.Abstractions.Models;
 using CMS.Plugin.MaterialManagement.Abstractions;
+using CMS.Plugin.HIAWms.Application.Contracts.Services;
+using CMS.Plugin.HIAWms.Application.Contracts.Dtos.CommonDto;
+using System.Collections.Generic;
+using CMS.Plugin.HIAWms.Abstractions;
+using Newtonsoft.Json;
+using CmsQueryExtensions;
 
 namespace CMS.Plugin.PipeLineLems.Application.Implements;
 
@@ -34,12 +40,20 @@
 public class SharedService : CMSPluginAppService
 {
 
-
+    /// <summary>
+    /// 鍒嗘嫞鍔熻兘
+    /// </summary>
+    /// <param name="_serviceProvider"></param>
+    /// <param name="input"></param>
+    /// <param name="myCurrentUser"></param>
+    /// <returns></returns>
     public async Task<MesOrderResponse> CommonPick(IServiceProvider _serviceProvider, PickInput input, MyCurrentUser myCurrentUser)
     {
         //1銆佽褰曞垎鎷h褰曡〃
         //2銆佹洿鏂颁綔涓氳鍒掕〃鐨勭姸鎬� =宸插垎鎷�
         //3銆佸啓鍏� 鍒嗘嫞鍙橀噺
+        //4銆佸啓鍏ヨ拷婧姤琛�
+        //5銆佺墿鏂欑粍鐩�
 
         VariableService _variableService = _serviceProvider.GetRequiredService<VariableService>();
         var _workSectionManager = _serviceProvider.GetRequiredService<IWorkSectionManager>();
@@ -48,13 +62,13 @@
         var materialProvider = _serviceProvider.GetRequiredService<IMaterialProvider>();
         var workPlanAppService = _serviceProvider.GetRequiredService<IWorkPlanAppService>();
 
-        Dictionary<string, object?> keyValuePairs = new Dictionary<string, object?>
-                    {
-                        { "鍒嗘嫞鎵樼洏鍙�","鎵樼洏1"},
-                        { "鍒嗘嫞鏂瑰悜", "鐭瑁呴厤"},
-                        { "鍒嗘嫞浜�", myCurrentUser.UserAccount }
-                    };
-        _variableService.WriteValueAsync(keyValuePairs);
+        //Dictionary<string, object?> keyValuePairs = new Dictionary<string, object?>
+        //            {
+        //                { "鍒嗘嫞鎵樼洏鍙�","鎵樼洏1"},
+        //                { "鍒嗘嫞鏂瑰悜", "鐭瑁呴厤"},
+        //                { "鍒嗘嫞浜�", myCurrentUser.UserAccount }
+        //            };
+        //_variableService.WriteValueAsync(keyValuePairs);
 
         //鏍规嵁宸ュ簭鍚嶈幏鍙栧伐搴忓璞�
         var workSection = await _workSectionManager.GetByNameAsync("鍒嗘嫞宸ュ簭");
@@ -89,12 +103,13 @@
         var firstWorkPlans = await workPlanAppService.GetListByFilterAsync(x => x.PipeSpecCode == input.PipeSpecCode);
 
         var firstWorkPlan = await workPlanAppService.GetSingleByFilterAsync(x => x.PipeSpecCode == input.PipeSpecCode);
-        var rawPipe_DataIdentifier = await materialProvider.FindByNameAsync("鍒嗘嫞鍘熸枡绠℃爣璇�");
-        var rawPipe_MaterialMode = await materialProvider.FindByNameAsync("鍒嗘嫞鍘熸枡绠″瀷鍙�");
+        var rawPipe_DataIdentifier = await materialProvider.FindByNameAsync("鍘熸枡绠℃爣璇�");
+        var rawPipe_MaterialMode = await materialProvider.FindByNameAsync("鍘熸枡绠″瀷鍙�");
+        var rawPipe_Batch = await materialProvider.FindByNameAsync("鍘熸枡绠℃壒娆�");
         List<TraceMaterialModel> _MaterialParams = new List<TraceMaterialModel>();
         foreach (var item in workSection.MaterialParameters)
         {
-            if (item.Name == "鍒嗘嫞鍘熸枡绠″瀷鍙�")
+            if (item.Name == "鍘熸枡绠″瀷鍙�")
             {
                 _MaterialParams.Add(new TraceMaterialModel()
                 {
@@ -106,7 +121,7 @@
 
                 });
             }
-            if (item.Name == "鍒嗘嫞鍘熸枡绠℃爣璇�")
+            if (item.Name == "鍘熸枡绠℃爣璇�")
             {
                 _MaterialParams.Add(new TraceMaterialModel()
                 {
@@ -115,6 +130,18 @@
                     MaterialId = rawPipe_DataIdentifier.MaterialId,
                     MaterialDetailId = rawPipe_DataIdentifier.MaterialDetails.First().Id,
                     Value = firstWorkPlan.DataIdentifier,
+
+                });
+            }
+            if (item.Name == "鍘熸枡绠℃壒娆�")
+            {
+                _MaterialParams.Add(new TraceMaterialModel()
+                {
+                    Key = item.Key,
+                    Quantity = 1,
+                    MaterialId = rawPipe_Batch.MaterialId,
+                    MaterialDetailId = rawPipe_Batch.MaterialDetails.First().Id,
+                    Value = "111",//鎵规鏆傛椂鍐欐
 
                 });
             }
@@ -128,6 +155,14 @@
             if (item.Name == "鍒嗘嫞鏂瑰悜")
             {
                 _value = "鐭瑁呴厤";
+            }
+            if (item.Name == "鍒嗘嫞鎵樼洏鍙�")
+            {
+                _value = input.ContinerNo;
+            }
+            if (item.Name == "鍒嗘嫞浜�")
+            {
+                _value = myCurrentUser.UserAccount;
             }
             //item.Key
             TraceParamModel traceParamModel = new TraceParamModel()
@@ -408,9 +443,9 @@
     /// <param name="_serviceProvider">鏈嶅姟鎻愪緵鑰�</param>
     /// <returns>鎿嶄綔缁撴灉</returns>
     /// <exception cref="UserFriendlyException">褰撴暟鎹笉瀛樺湪鎴栫姸鎬佷笉鍏佽鍙枡鏃舵姏鍑�</exception>
-    public async Task<MesOrderResponse> CallMaterialByDataIdentifier(Guid id, IServiceProvider _serviceProvider)
+    public async Task<MesOrderResponse> CallMaterial(CallMaterialByDataIdentifierInput input, IServiceProvider _serviceProvider, MyCurrentUser myCurrentUser)
     {
-        if (string.IsNullOrEmpty(id.ToString()))
+        if (string.IsNullOrEmpty(input.Id.ToString()))
         {
             throw new UserFriendlyException("鍘熸枡鏍囪瘑涓嶈兘涓虹┖");
         }
@@ -422,7 +457,7 @@
 
         // 鏌ユ壘鏁版嵁
 
-        var callMaterialOrder = await callMaterialOrderRepository.GetAsync(id);
+        var callMaterialOrder = await callMaterialOrderRepository.GetAsync(input.Id);
         if (callMaterialOrder == null)
         {
             throw new UserFriendlyException($"鎵句笉鍒板彨鏂欒褰�");
@@ -431,10 +466,41 @@
         // 楠岃瘉鐘舵��
         if (callMaterialOrder.CallMaterialStatus != Domain.Shared.Enums.CallMaterialStatusEnum.鏈墽琛�)
         {
-            throw new UserFriendlyException($"鍘熸枡鏍囪瘑涓� '{callMaterialOrder.DataIdentifier}' 鐨勫彨鏂欒褰曠姸鎬佷负 '{callMaterialOrder.CallMaterialStatus}'锛屼笉鍏佽鍙枡");
+            //throw new UserFriendlyException($"鍘熸枡鏍囪瘑涓� '{callMaterialOrder.DataIdentifier}' 鐨勫彨鏂欒褰曠姸鎬佷负 '{callMaterialOrder.CallMaterialStatus}'锛屼笉鍏佽鍙枡");
         }
 
+        //TODO:杩欓噷璋冪敤wms鐨勫彨鏂欐帴鍙�
+        try
+        {
+            List<LMesCallMaterialInput> param = new List<LMesCallMaterialInput>() {
+             new LMesCallMaterialInput(){
+                     DataIdentifier=callMaterialOrder.DataIdentifier,
+                      MaterialMode="Q235B-桅89脳4",
+             }
+        };
+            string baseUrl = @"http://127.0.0.1:18000/api/v1/HIAWms/";
+            string url = baseUrl + "lMesOperate/LMesCallMaterial";
+            string json = JsonConvert.SerializeObject(param);
+            var result = HttpApiRequest.HttpPost(url, json);
+            var res = JsonConvert.DeserializeObject<CmsApiResponse<List<MyCallMaterialOutput>>>(result);
+            if (res.Code == 200)
+            {
+                var retData = res.Data;
+                callMaterialOrder.MaterialBatch = retData[0].MaterialBatch;
+            }
+            else {
+                throw new UserFriendlyException(res.Message);
+            }
+        }
+        catch (Exception)
+        {
+
+            throw;
+        }
+
+
         // 鏇存柊鏁版嵁
+        callMaterialOrder.MaterialBatch = GenerateRandomBatch();//wms杩斿洖鐨勫師鏂欐壒娆�
         callMaterialOrder.WmsRetResult = "鎴愬姛";
         callMaterialOrder.WmsTaskNo = GenerateRandomTaskNo();
         callMaterialOrder.CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.鍙枡瀹屾垚;
@@ -443,7 +509,7 @@
         await callMaterialOrderRepository.UpdateAsync(callMaterialOrder);
 
         //鏇存柊浣滀笟璁″垝琛�
-        var workPlanList = await workPlanRepository.FindByDataIdentifierAsync(callMaterialOrder.DataIdentifier);
+        var workPlanList = await workPlanRepository.GetListByFilterAsync(x => x.DataIdentifier == callMaterialOrder.DataIdentifier);
         foreach (var item in workPlanList)
         {
             item.CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.鍙枡瀹屾垚;
@@ -455,6 +521,7 @@
         var callMaterialOrderRecord = new CallMaterialOrderRecord()
         {
             CallMaterialStatus = Domain.Shared.Enums.CallMaterialStatusEnum.鍙枡瀹屾垚,
+            MaterialBatch = callMaterialOrder.MaterialBatch,
             MaterialMode = callMaterialOrder.MaterialMode,
             DataIdentifier = callMaterialOrder.DataIdentifier,
             Quantity = 1,
@@ -500,4 +567,13 @@
         // 鐢熸垚鍓嶇紑
         return $"WMS{timestamp}";
     }
+
+    private string GenerateRandomBatch()
+    {
+        // 鑾峰彇褰撳墠鏃堕棿鎴筹紙浠�1970-01-01 00:00:00 UTC鍒扮幇鍦ㄧ殑绉掓暟锛�
+        long timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
+
+        // 鐢熸垚鍓嶇紑
+        return $"Batch{timestamp}";
+    }
 }

--
Gitblit v1.9.3