From 6d9829c889a826d39cbc911ef5d01825edd1bffc Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 26 六月 2025 16:33:29 +0800
Subject: [PATCH] 添加设备交互日志

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/CommonProductionLineJob.cs |  117 ++++++++++++++++++++++++++--------------------------------
 1 files changed, 53 insertions(+), 64 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/CommonProductionLineJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/CommonProductionLineJob.cs"
index 8ff2a35..b83fbb7 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/CommonProductionLineJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/CommonProductionLineJob.cs"
@@ -8,6 +8,7 @@
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.Service;
 using WIDESEAWCS_Tasks.ProductionLineJob;
 using WIDESEAWCS_Tasks.StackerCraneJob;
@@ -30,81 +31,69 @@
             _taskRepository = taskRepository;
             _routerService = routerService;
         }
-        //static int i = 0;
+        //static int i = 1;
         public Task Execute(IJobExecutionContext context)
         {
             try
             {
-                //if (i < 1)
-                //{
-                //    i++;
-                //    ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO()
-                //    {
-                //        stationCode = "MDX01",
-                //        traytype = 4,
-                //        Barcode = "A0216",
-                //        batchNo = "20250113T2",
-                //    };
-                //    var content = ProductionLineToWMSRequest(MaterielGroupDTO);
-                //}
                 #region MyRegion
-                //OtherDevice ProductionLine = (OtherDevice)context.JobDetail.JobDataMap.Get("JobParams");
-                //if (ProductionLine != null)
-                //{
-                //    var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request);
-                //    if (request == 1)
-                //    {
-                //        var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType);
-                //        //var content = Request(ProductionLine, traytype, ProductionLine.DeviceCode);
-                //        if (traytype == 4)
-                //        {
-                //            var Barcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode);
-                //            var batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo);
-                //            ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO()
-                //            {
-                //                stationCode = ProductionLine.DeviceCode,
-                //                traytype = traytype,
-                //                Barcode = Barcode,
-                //                batchNo = batchNo,
-                //            };
-                //            var content = ProductionLineToWMSRequest(MaterielGroupDTO);
-                //            if (content.Status) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1);
-                //        }
-                //    }
-                //} 
-                #endregion
-                #region MyRegion
-                //short[] shorts = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 };
-                //ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO()
-                //{
-                //    Barcode = "A1001",
-                //    batchNo = "20241212001T1",
-                //    stationCode = "Z1",
-                //    productQty = string.Join(",", shorts),
-                //    traytype = 4
-                //};
-                //ProductionLineToWMSRequest(MaterielGroupDTO);
-                //if (ProductionLine != null)
-                //{
-                //    switch (ProductionLine.DeviceName)
-                //    {
-                //        case "鍏ュ簱浜х嚎":
-                //            ProductionLineIn(ProductionLine);
-                //            break;
-                //        case "鍑哄簱浜х嚎":
-                //            ProductionLineOut(ProductionLine);
-                //            break;
-                //        default:
-                //            throw new Exception("鏈畾涔変骇绾�");
-                //    }
-                //} 
+                OtherDevice ProductionLine = (OtherDevice)context.JobDetail.JobDataMap.Get("JobParams");
+                if (ProductionLine != null)
+                {
+                    #region MyRegion
+                    var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request);
+                    if (request == 1)
+                    {
+                        var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType);
+                        //var content = Request(ProductionLine, traytype, ProductionLine.DeviceCode);
+                        if (traytype == 4)
+                        {
+                            var Barcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode).Replace("\0", "");
+                            if (string.IsNullOrEmpty(Barcode)) throw new Exception("浜х嚎鐢宠鎵樼洏鍙蜂负绌猴紒");
+                            var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode);
+                            if (task == null)
+                            {
+                                var batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo).Replace("\0", "");
+                                if (string.IsNullOrEmpty(batchNo)) throw new Exception("浜х嚎鐢宠鎵瑰彿涓虹┖锛�");
+                                WriteDebug($"{ProductionLine.DeviceName}鐢宠鍏ュ簱", $"鎵樼洏鍙枫�恵Barcode}銆�,鎵规煖鍙枫�恵batchNo}銆�");
+                                ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO()
+                                {
+                                    stationCode = ProductionLine.DeviceCode,
+                                    traytype = traytype,
+                                    Barcode = Barcode,
+                                    batchNo = batchNo,
+                                };
+                                var content = ProductionLineToWMSRequest(MaterielGroupDTO);
+                                if (content.Status)
+                                    ProductionLine.SetValue(ProductionLineDBName.Wrequest, request);
+                            }
+                        }
+                    }
+                    #endregion
+                }
                 #endregion
             }
             catch (Exception ex)
             {
-                Console.Out.WriteLine(nameof(CommonProductionLineJob) + ":" + ex.ToString());
+                //Console.Out.WriteLine(nameof(CommonProductionLineJob) + ":" + ex.ToString());
             }
             return Task.CompletedTask;
         }
+
+        public string GetString<TEnum, TResult>(TEnum value, OtherDevice ProductionLine) where TEnum : Enum
+        {
+            TEnum value2 = value;
+            if (!ProductionLine.IsConnected)
+            {
+                throw new Exception("閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
+            }
+            DeviceProDTO deviceProDTO = ProductionLine.DeviceProDTOs.FirstOrDefault((DeviceProDTO x) => x.DeviceProParamName == value2.ToString());
+            if (deviceProDTO != null)
+            {
+                return Encoding.ASCII.GetString(ProductionLine.Communicator.Read(deviceProDTO.DeviceProAddress, deviceProDTO.DeviceProDataLength)).Replace("\0", "");
+                //return (TResult)Communicator.ReadAsObj(deviceProDTO.DeviceProAddress, deviceProDTO.DeviceDataType);
+            }
+            throw new Exception("璇诲彇鏁版嵁閿欒,鏈湪鍗忚淇℃伅閲岄潰鎵惧埌鍙傛暟" + value2.ToString());
+        }
     }
 }

--
Gitblit v1.9.3