From 3e778155459a2d5a2f0214f57ff83c3760ed8381 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 10 二月 2025 14:36:43 +0800
Subject: [PATCH] 添加WMSapi接口调用接口日志记录、添加WMSswagger访问接口账号密码、添加WMS到期时间6-30

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/ProductionLineExtend/ProductionLineExtend.cs |  205 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 198 insertions(+), 7 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/ProductionLineExtend/ProductionLineExtend.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/ProductionLineExtend/ProductionLineExtend.cs"
index 47629ef..a39cf67 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/ProductionLineExtend/ProductionLineExtend.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/ProductionLineExtend/ProductionLineExtend.cs"
@@ -1,9 +1,16 @@
-锘縰sing System;
+锘縰sing Newtonsoft.Json;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.WMSInfo;
+using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DTO;
+using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_Tasks.ProductionLineJob;
 
 namespace WIDESEAWCS_Tasks
@@ -11,16 +18,200 @@
     public partial class CommonProductionLineJob
     {
         /// <summary>
-        /// 浜х嚎
+        /// 鍏ュ簱浜х嚎
         /// </summary>
         /// <param name="conveyorLine"></param>
         /// <returns></returns>
-        public List<Task> ProductionLineExtend(OtherDevice ProductionLine)
+        public void ProductionLineIn(OtherDevice ProductionLine)
         {
-            var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType);
-            ProductionLine.SetValue(ProductionLineDBName.trayType, traytype);
-            List<Task> tasks = new List<Task>();
-            return tasks;
+            foreach (var item in ProductionLine.DeviceProDTOs.GroupBy(x => x.DeviceChildCode))
+            {
+                var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request, item.Key);
+                if (request == 1)
+                {
+                    var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType, item.Key);
+                    var content = Request(ProductionLine, traytype, item.Key);
+
+                    if (content.Status) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1, item.Key);
+                }
+            }
+        }
+        /// <summary>
+        /// 鍑哄簱浜х嚎
+        /// </summary>
+        /// <param name="ProductionLine"></param>
+        public void ProductionLineOut(OtherDevice ProductionLine)
+        {
+            foreach (var item in ProductionLine.DeviceProDTOs.GroupBy(x => x.DeviceChildCode))
+            {
+                var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request, item.Key);
+                if (request == 1)
+                {
+                    bool ok = false;
+                    var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType, item.Key);
+                    if (traytype == 2 || traytype == 4 || traytype == 6)
+                        ok = Request(ProductionLine, traytype, item.Key).Status;
+                    else
+                    {
+                        var task = _taskService.QuertOutProductionLineTask(true);
+                        if (task != null)
+                        {
+                            //if (task.Remark.ObjToInt() == traytype)
+                            if (!string.IsNullOrEmpty(task.Remark) && traytype == 5)
+                            {
+                                task.TargetAddress = item.Key;
+                                task.NextAddress = item.Key;
+                                ok = _taskService.UpdateData(task).Status;
+                            }
+                        }
+                    }
+                    if (ok) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1, item.Key);
+                }
+            }
+        }
+        /// <summary>
+        /// 鐢宠
+        /// </summary>
+        /// <param name="ProductionLine">浜х嚎</param>
+        /// <param name="traytype">鎵樼洏绫诲瀷</param>
+        /// <param name="station">绔欏彴鍙�</param>
+        /// <returns></returns>
+        public WebResponseContent Request(OtherDevice ProductionLine, short traytype, string station)
+        {
+            WebResponseContent response = new WebResponseContent();
+            ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO();
+            try
+            {
+                switch (traytype)
+                {
+                    case 1://鏀剧┖鎵�
+                    case 3://鏀剧┖鐩�
+                           //case 5://鏀炬弧鐩�
+                        {
+                            MaterielGroupDTO.stationCode = station;
+                            MaterielGroupDTO.traytype = traytype;
+                        }
+                        break;
+                    case 2://鍙栫┖鎵�
+                    case 4://鍙栨弧鐩�
+                    case 6://鍙栫┖鐩�
+                        {
+                            MaterielGroupDTO.Barcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode, station);
+                            MaterielGroupDTO.stationCode = station;
+                            MaterielGroupDTO.traytype = traytype;
+                            if (traytype == 4)
+                            {
+                                #region 璇诲彇鏁伴噺
+                                var productQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.productQty.ToString() && x.DeviceChildCode == station);
+                                var productQty = ProductionLine.Communicator.Read<short>(productQtyadd.DeviceProAddress, (ushort)productQtyadd.DeviceProDataLength);
+                                #endregion
+
+                                #region 鍐欏叆鏁伴噺
+                                var WproductQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.WproductQty.ToString() && x.DeviceChildCode == station);
+                                ProductionLine.Communicator.Write(WproductQtyadd.DeviceProAddress, productQty);
+                                #endregion
+
+                                MaterielGroupDTO.batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo, station);
+                                MaterielGroupDTO.productQty = string.Join(",", productQty);
+                            }
+                        }
+                        break;
+                    #region MyRegion
+                    //case 3://鏀剧┖鐩�
+                    //    {
+                    //        MaterielGroupDTO.stationCode = station;
+                    //        MaterielGroupDTO.traytype = traytype;
+                    //    }
+                    //    break; 
+                    //case 4://鍙栨弧鐩�
+                    //    {
+                    //        //var productQty = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.productQty, station);
+                    //        #region 璇诲彇鏁伴噺
+                    //        var productQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.productQty.ToString() && x.DeviceChildCode == station);
+                    //        var productQty = ProductionLine.Communicator.Read<short>(productQtyadd.DeviceProAddress, (ushort)productQtyadd.DeviceProDataLength);
+                    //        #endregion
+
+                    //        #region 鍐欏叆鏁伴噺
+                    //        var WproductQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.WproductQty.ToString() && x.DeviceChildCode == station);
+                    //        ProductionLine.Communicator.Write(WproductQtyadd.DeviceProAddress, productQty);
+                    //        #endregion
+
+                    //        var batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo, station);
+                    //        var trayBarcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode, station);
+
+                    //        MaterielGroupDTO.batchNo = batchNo;
+                    //        MaterielGroupDTO.Barcode = trayBarcode;
+                    //        MaterielGroupDTO.stationCode = station;
+                    //        MaterielGroupDTO.traytype = traytype;
+                    //        MaterielGroupDTO.productQty = string.Join(",", productQty);
+                    //    }
+                    //    break;
+                    //case 5://鏀炬弧鐩�
+                    //    {
+                    //        MaterielGroupDTO.stationCode = station;
+                    //        MaterielGroupDTO.traytype = traytype;
+                    //    }
+                    //    break; 
+                    //case 6://鍙栫┖鐩�
+                    //    {
+
+                    //    }
+                    //    break;
+                    #endregion
+                    default:
+                        throw new Exception("鏈畾涔夋墭鐩樼被鍨�");
+                }
+
+                response = ProductionLineToWMSRequest(MaterielGroupDTO);
+            }
+            catch (Exception ex)
+            {
+                response.Error(ex.Message);
+            }
+            return response;
+        }
+
+        public WebResponseContent ProductionLineToWMSRequest(ProductionLineDTO MaterielGroupDTO)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                content = RequestWMS.PostWMSLog(WMSInterfaceAddress.ProductionlineRequest, MaterielGroupDTO.ToJson(), "浜х嚎鍚慦MS璇锋眰", headers: new Dictionary<string, string>());
+                if (!content.Status) throw new Exception(content.Message);
+                //var ResultData = HttpHelper.PostAsync(WMSInterfaceAddress.ProductionlineRequest, MaterielGroupDTO.ToJson(), headers: new Dictionary<string, string>());
+                //if (ResultData.Result == null) throw new Exception($"浜х嚎鍚慦MS璇锋眰瓒呮椂");
+
+                //content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
+
+                #region 浜х嚎鐢宠鍏ュ簱浠诲姟
+                if (content != null && content.Status)//浠诲姟杞崲
+                {
+                    var task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToJson());
+                    if (task != null)
+                    {
+                        List<int> TaskNums = new List<int>();
+                        List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.TargetAddress);
+                        if (routers.Count > 0)
+                        {
+                            task.NextAddress = routers.FirstOrDefault().ChildPosi;
+                        }
+                        task.WMSId = task.TaskId;
+                        task.Creater = "WMS";
+                        task.Dispatchertime = null;
+                        task.CreateDate = DateTime.Now;
+                        content = _taskService.AddData(task);
+                        TaskNums.Add(task.TaskNum);
+                        _taskExecuteDetailService.AddTaskExecuteDetail(TaskNums, "鎺ユ敹WMS浠诲姟");
+                    }
+                }
+                #endregion
+
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
         }
     }
 }

--
Gitblit v1.9.3