From 3865194441f1e1da34c0be9034d86c8d0d68706c Mon Sep 17 00:00:00 2001
From: lss <2538410689@qq.com>
Date: 星期五, 04 七月 2025 17:26:23 +0800
Subject: [PATCH] 接口调用中间表开发

---
 HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs |  202 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 181 insertions(+), 21 deletions(-)

diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs
index 9d644c9..29f1da9 100644
--- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs
+++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/process/DeviceProcess.cs
@@ -4,11 +4,14 @@
 using HH.WCS.JiaTong.util;
 using HH.WCS.JiaTong.wms;
 using Newtonsoft.Json;
+using S7.Net;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Threading;
 using static HH.WCS.JiaTong.LISTA.process.HttpModel;
+using static System.Collections.Specialized.BitVector32;
 
 namespace HH.WCS.JiaTong.process
 {
@@ -31,7 +34,7 @@
                     {
                         if (data == "")
                         {
-                            Traystacker(plc);
+                            // Traystacker(plc);
                         }
                     }
                 }
@@ -45,42 +48,52 @@
         /// <summary>
         /// 鍙犵洏鏈虹┖鎵樿繑鍥�         /// </summary>    
-        internal static void Traystacker(Settings.deviceInfo device)
+        internal static void Traystacker(string loc, int qty, int type,string cntrcode="")
         {
             try
             {
                 //涓婁紶鏁版嵁
-                Result<Traystacker> result1 = new Result<Traystacker>();
-                Traystacker traystacker = new Traystacker() { station = device.TN_Location[0], taskSource = 1, Qty = 7 };
-                result1.data.Add(traystacker);
+                Traystacker result1 = new Traystacker() { station = loc, taskSource = 1, Qty = qty, dpType = type };
+
                 HttpHelper httpHelper = new HttpHelper();
                 Result result = new Result();
                 string date = JsonConvert.SerializeObject(result1);
-                string url = Settings.tableUrls.Find(a => a.id == 2).url;
-                LogHelper.Info($"鍙犵洏鏈虹┖鎵樿繑鍥烇細鍦板潃:{url}锛屽唴瀹癸細{date}");
-                var r = httpHelper.WebPost(url, date);
-                result = JsonConvert.DeserializeObject<Result>(r);
-                if (result.code == "0")
+                var url = Settings.tableUrls.Find(a => a.id == 3);
+                if (url != null)
                 {
+                    LogHelper.Info($"鍙犵洏鏈虹┖鎵樿繑鍥烇細鍦板潃:{url.url}锛屽唴瀹癸細{date}");
+                    var r = httpHelper.WebPost(url.url, date);
+                    result = JsonConvert.DeserializeObject<Result>(r);
+                    if (result.code == "0")
+                    {
 
-                    LogHelper.Info($"鍙犵洏鏈虹┖鎵樿繑鍥炶姹傛垚鍔�);
+                        LogHelper.Info($"鍙犵洏鏈虹┖鎵樿繑鍥炶姹傛垚鍔�);
+                    }
+                    else
+                    {
+                        LogHelper.Info($"鍙犵洏鏈虹┖鎵樿繑鍥炶姹傚け璐�>msg:{result.msg}");
+                    }
                 }
                 else
                 {
-                    LogHelper.Info($"鍙犵洏鏈虹┖鎵樿繑鍥炶姹傚け璐�>msg:{result.msg}");
+                    LogHelper.Info($"鍙犵洏鏈虹┖鎵�鏍规嵁id=3锛屾湭鎵惧埌閰嶇疆閾炬帴锛岃妫�煡閰嶇疆鏂囦欢");
                 }
 
             }
             catch (Exception ex)
             {
-                LogHelper.Info($"鍙犵洏鏈虹┖鎵樿繑鍥� Error=>{ex.ToString()}");
+                LogHelper.Error($"鍙犵洏鏈虹┖鎵樿繑鍥� Error=>{ex.ToString()}", ex);
             }
         }
 
+        /// <summary>
+        /// 鍘熸潗鏂欏簱agv鍙犵洏鍥炲簱
+        /// </summary>
         internal static void Traffic()
         {
+            Console.WriteLine("寮�鍘熸潗鏂欏彔鐩樹綅缃垽鏂�);
             var db = new SqlHelper<object>().GetInstance();
-            List<string> locs = new List<string>() { "LCDP-001" };
+            List<string> locs = new List<string>() { "LCDP-001", "BADPW-01" };
             var location = db.Queryable<Location>().Where(a => locs.Contains(a.S_CODE)).ToList();
             if (location.Count > 0)
             {
@@ -93,8 +106,8 @@
                         var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == item.S_CODE).ToList();
                         if (cntr.Count > 0)
                         {
-                            var cntrcodes = cntr.Select(a => a.S_CNTR_CODE).ToArray();
-                            cntrcode = string.Join(",", cntrcodes);
+                             cntrcode = cntr.OrderBy(a=>a.T_CREATE).First().S_CNTR_CODE;
+                           // cntrcode = string.Join(",", cntrcodes);
                         }
 
                         //鍒涘缓杩囨湭瀹屾垚鐨勪换鍔′笉鍙戣捣璇锋眰
@@ -106,15 +119,153 @@
                     }
                 }
             }
-
-
         }
 
         /// <summary>
+        /// 浜曟澗agv鍙犵洏鍥炲簱
+        /// </summary>
+        internal static void KjTraffic()
+        {
+
+            Console.WriteLine("寮�浜曟澗agv鍙犵洏鍥炲簱浣嶇疆鍒ゆ柇");
+            var db = new SqlHelper<object>().GetInstance();
+            List<string> locs = new List<string>() { "AGV12DP-001", "AGV01DP-001", "AGV05DP-001" };
+            var location = db.Queryable<Location>().Where(a => locs.Contains(a.S_CODE)).ToList();
+            if (location.Count > 0)
+            {
+                // string cntrcode = "";
+                foreach (var item in location)
+                {
+
+                    if (item.N_CURRENT_NUM >= 6)
+                    {
+                        //var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == item.S_CODE).ToList();
+                        //if (cntr.Count > 0)
+                        //{
+                        //    var cntrcodes = cntr.Select(a => a.S_CNTR_CODE).ToArray();
+                        //    cntrcode = string.Join(",", cntrcodes);
+                        //}
+                        string cntrcode = "";
+                        var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == item.S_CODE).ToList();
+                        if (cntr.Count > 0)
+                        {
+                            cntrcode = cntr.OrderBy(a => a.T_CREATE).First().S_CNTR_CODE;
+                            // cntrcode = string.Join(",", cntrcodes);
+                        }
+                        LogHelper.Info($"璐т綅{item.S_CODE}鍙犳弧6涓紑濮嬪洖璋冩帴鍙�);
+                        //鍒涘缓杩囨湭瀹屾垚鐨勪换鍔′笉鍙戣捣璇锋眰
+                        var mst = WCSHelper.GetTaskByStartloc(item.S_CODE);
+                        if (mst == null)
+                        {
+                            Traystacker(item.S_CODE, item.N_CURRENT_NUM, 2, cntrcode);
+                        }
+                        else
+                        {
+                            LogHelper.Info($"鏈夋墽琛屼腑鐨勫彔鐩樺洖搴撲换鍔mst.S_CODE}锛屼笉瑙﹀彂鍙犵洏浠诲姟");
+                        }
+                    }
+                }
+            }
+        }
+
+
+        public static Dictionary<string, DpjErrorInfo> DpjInfoDirectory = new Dictionary<string, DpjErrorInfo>();
+        /// <summary>
+        /// 浜曟澗鍙犵洏鏈哄彔鐩樺洖搴�+        /// </summary>
+        internal static void DpjTraffic()
+        {
+            var devices = Settings.deviceInfos.Where(a => a.deviceType == 1).ToList();
+            //var db = new SqlHelper<object>().GetInstance();
+            //var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM > 0  && a.N_LOCK_STATE == 0).OrderByDescending(a => a.N_COL).Take(1).PartitionBy(a => a.N_ROW).ToList();
+            try
+            {
+                if (devices.Count > 0)
+                {
+                    foreach (var device in devices)
+                    {
+                        var IsDp = S7Helper.ReadDpj(device.address, 2001, S7.Net.VarType.Byte);
+                        var value = S7Helper.ReadDpj(device.address, 2014, S7.Net.VarType.Int);
+                        var ErrorCode = S7Helper.ReadDpj(device.address, 2016, S7.Net.VarType.Int);
+                        //璁板綍鍙犵洏鏈烘姤閿欎俊鎭�+                        if (DpjInfoDirectory.ContainsKey(device.address))
+                        {
+                            DpjInfoDirectory[device.address].Address = device.address;
+                            DpjInfoDirectory[device.address].DeviceName = device.deviceName;
+                            var ErrorInfo = Settings.dpjErrorInfos.Where(a => a.ErrorCode == ErrorCode).First();
+                            if (ErrorInfo != null)
+                            {
+                                DpjInfoDirectory[device.address].ErrorInfo = ErrorInfo.ErrorInfo;
+                            }
+                        }
+                        else
+                        {
+                            string errorinfo = "";
+                            var ErrorInfo = Settings.dpjErrorInfos.Where(a => a.ErrorCode == ErrorCode).First();
+                            if (ErrorInfo != null)
+                            {
+                                errorinfo = ErrorInfo.ErrorInfo;
+                            }
+                            DpjInfoDirectory.Add(device.address, new DpjErrorInfo() { Address = device.address, DeviceName = device.deviceName, ErrorInfo = errorinfo });
+                        }
+                        if (value >= 1 && IsDp == 1)
+                        {
+                            //var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == item.S_CODE).ToList();
+                            //if (cntr.Count > 0)
+                            //{
+                            //    var cntrcodes = cntr.Select(a => a.S_CNTR_CODE).ToArray();
+                            //    cntrcode = string.Join(",", cntrcodes);
+                            //}
+
+                            //鍒涘缓杩囨湭瀹屾垚鐨勪换鍔′笉鍙戣捣璇锋眰
+                            var mst = WCSHelper.GetTaskByStartloc(device.TN_Location);
+                            if (mst == null)
+                            {
+                                Traystacker(device.TN_Location, value, 2);
+                            }
+                            else
+                            {
+                                LogHelper.Info($"鏈夋墽琛屼腑鐨勫彔鐩樺洖搴撲换鍔mst.S_CODE}锛屼笉瑙﹀彂鍙犵洏浠诲姟");
+                            }
+                            //var loc = LocationHelper.GetLocByLoc(device.TN_Location);
+                            //if (loc != null)
+                            //{
+                            //    if (loc.N_LOCK_STATE == 0) {
+                            //        Traystacker(device.TN_Location, value, 2);
+                            //    }
+                            //    else
+                            //    {
+                            //        LogHelper.Info($"璁惧璧风偣锛歿device.TN_Location}鏈夐攣锛屼笉鐢熸垚浠诲姟");
+                            //    }
+                            //}
+                            //else
+                            //{
+                            //    LogHelper.Info($"鏍规嵁璁惧锛歿device.deviceName}锛岃捣鐐癸細{device.TN_Location},鏈壘鍒拌揣浣�);
+                            //}
+                        }
+                        else
+                        {
+                            LogHelper.Info($"鍙犵洏鏈烘暟閲忥細{value},鍙犵洏淇″彿锛歿IsDp}锛屼笉瑙﹀彂鍙犵洏浠诲姟");
+                        }
+                        Thread.Sleep(8000);
+                    }
+                }
+
+            }
+            catch (Exception ex)
+            {
+               
+                LogHelper.Error($"ReadDpj DpjTraffic:{ex}", ex);
+
+            }
+
+        }
+        /// <summary>
         /// 鍘熸潗鏂欏簱鎺ュ彛璁块棶
         /// </summary>    
-        internal static void AgvEmptyBack(string loc, string cntrcode)
+        internal static Resultmobox AgvEmptyBack(string loc, string cntrcode)
         {
+            Resultmobox result = new Resultmobox();
             try
             {
                 string partNumber = "";
@@ -124,7 +275,7 @@
                 result1.data = traystacker;
                 HttpHelper httpHelper = new HttpHelper();
                 //璋冪敤鎺ュ彛
-                Resultmobox result = new Resultmobox();
+             
                 string date = JsonConvert.SerializeObject(result1);
                 string url = Settings.tableUrls.Find(a => a.id == 11).url;
                 LogHelper.Info($"绌烘墭杩斿洖锛氬湴鍧�{url}锛屽唴瀹癸細{date}");
@@ -139,12 +290,21 @@
                 {
                     LogHelper.Info($"绌烘墭杩斿洖璇锋眰澶辫触=>msg:{result.err_msg}");
                 }
-
+                return result;
             }
             catch (Exception ex)
             {
                 LogHelper.Info($"绌烘墭杩斿洖  Error=>{ex.ToString()}");
+                return result;
             }
         }
+
+        public class DpjErrorInfo
+        {
+
+            public string Address { get; set; }
+            public string DeviceName { get; set; }
+            public string ErrorInfo { get; set; }
+        }
     }
 }

--
Gitblit v1.9.1