czw
2025-07-06 f317e966ce0872e04d1455305845c3e19fb4a532
HH.WCS.QingXiNongfu/process/DeviceProcess.cs
@@ -1,28 +1,14 @@
using HH.WCS.QingXigongchang.core;
using HH.WCS.QingXigongchang.device;
using HH.WCS.QingXigongchang.device;
using HH.WCS.QingXigongchang.dispatch;
using HH.WCS.QingXigongchang.util;
using HH.WCS.QingXigongchang.wms;
using Microsoft.SqlServer.Server;
using Newtonsoft.Json;
using NLog.Time;
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Web.Http.Results;
using System.Web.Security;
using System.Web.UI.WebControls;
using static HH.WCS.QingXigongchang.dispatch.NDC;
using static HH.WCS.QingXigongchang.util.Settings;
namespace HH.WCS.QingXigongchang.process
@@ -158,7 +144,6 @@
            }
        }
        private static void Analysis13(string data, deviceInfo plc)
        {
            //用于  出库时 是否可以直达 提升机。  00 后面还需增加退料工单处理。 
@@ -327,7 +312,7 @@
                    si = "0";
                }
                else if (data.Contains("11"))// && (ods.Find(x => x.SQL_PLineNo.Contains("纸箱")) != null || plc.deviceName.Contains("T1"))
                if (data.Contains("11"))// && (ods.Find(x => x.SQL_PLineNo.Contains("纸箱")) != null || plc.deviceName.Contains("T1"))
                {
                    //if (!ods.Any())
                    //    return;
@@ -335,16 +320,28 @@
                    if (_cl.N_CURRENT_NUM > 0 || _clrel.Any())
                    {
                        LogHelper.Info($" time:{_clrel0?.T_CREATE} = s_type:{_clrel0.S_TYPE}");
                        //if (DateTime.Now.Subtract(_clrel0.T_CREATE).TotalSeconds < 10 || !string.IsNullOrEmpty(_clrel0.S_TYPE))
                        //    goto ballll;
                        //plg 2025年6月23日  去除10秒时间限制
                        if (_clrel.Any())
                            if (DateTime.Now.Subtract(_clrel0.T_CREATE).TotalSeconds < 10 || !string.IsNullOrEmpty(_clrel0.S_TYPE))
                                goto ballll;
                        LocationHelper.DoAction(db =>
                        {
                            db.Deleteable(_clrel).ExecuteCommand();
                            _cl.N_CURRENT_NUM = 0;
                            return db.Updateable(_cl).UpdateColumns(x => new { x.N_CURRENT_NUM }).ExecuteCommand() > 0;
                        });
                            if (od?.SQL_PLineNo == "T1提升机")
                            {
                                if (!string.IsNullOrEmpty(_clrel0.S_TYPE))
                                    goto ballll;
                            }
                            else
                            {
                                if (DateTime.Now.Subtract(_clrel0.T_CREATE).TotalSeconds < 3 || !string.IsNullOrEmpty(_clrel0.S_TYPE))
                                    goto ballll;
                            }
                        }
                        LocationHelper.DoAction(db =>
                            {
                                db.Deleteable(_clrel).ExecuteCommand();
                                _cl.N_CURRENT_NUM = 0;
                                return db.Updateable(_cl).UpdateColumns(x => new { x.N_CURRENT_NUM }).ExecuteCommand() > 0;
                            });
                    }
                    if (!plc.deviceName.Contains("T1"))
                        goto ballll;
@@ -379,8 +376,10 @@
                        if (sBit != null)
                        {
                            var sign = Settings.GetTimeStamp();
                            var res = TaskProcess.CreateTransport(sign, sBit.S_LOC_CODE, _cl.S_LOC_CODE, "原物料搬运-纸箱", new List<string> { _clrel.FirstOrDefault().S_CNTR_CODE }, sBit.N_CURRENT_NUM, 1, 1, 50);///, EdnRarea == "YWLYLTKQ" ? _clrel0.S_TYPE : "");
                            var res = TaskProcess.CreateTransport(sign, sBit.S_LOC_CODE, _cl.S_LOC_CODE, "原物料搬运-纸箱", new List<string> { _clrel.FirstOrDefault().S_CNTR_CODE }, sBit.N_CURRENT_NUM, 1, 1, 60);///, EdnRarea == "YWLYLTKQ" ? _clrel0.S_TYPE : "");
                            LogHelper.Info($"原物料搬运 上提升机。 {sign} 任务 ,创建{res} ");
                            //var res = TaskProcess.CreateTransport(sign, sBit.S_LOC_CODE, _cl.S_LOC_CODE, "原物料搬运-纸箱", new List<string> { _clrel.FirstOrDefault().S_CNTR_CODE }, sBit.N_CURRENT_NUM, 1, 1, 50);///, EdnRarea == "YWLYLTKQ" ? _clrel0.S_TYPE : "");
                            //LogHelper.Info($"原物料搬运 上提升机。 {sign} 任务 ,创建{res} ");
                        }
                    }
                }
@@ -1734,18 +1733,51 @@
               状态2   送空完成之后为状态2
               状态3   满托取走,送空之前为状态3,开机默认状态也为状态3
           */
            //3F 00 12 22 0D 0A--无任务信号
            //3F 00 11 22 0D 0A--A口工作信号
            //3F 00 12 21 0D 0A--B口信号
            //3F 00 11 21 0D 0A--A、B口工作信号
            //A口复位信号 - 3F 00 10 0D 0A
            //B口复位信号 - 3F 00 20 0D 0A
            if (data.Length == 4)
            {
                if (data.Substring(1, 1) == "1")
                if (data == "1122")//A口工作信号
                {
                    if (BottlePEMInfoFull(plc, plc.location[0]))
                    if (BottlePEMInfoFullTwo(plc, plc.location[0]))
                    {
                        //设备没有托盘,或者已经有任务,不处理满托信号,返回已经取货完成
                        //3F 00 11 0d 0a
                        //PlcHelper.SendHex(plc.address, "3F00110d0a");
                    }
                }
                else if (data == "1221")//B口工作信号
                {
                    if (BottlePEMInfoFullTwo(plc, plc.location[1]))
                    {
                    }
                }
                else if (data == "1121")//B口工作信号
                {
                    if (BottlePEMInfoFullTwo(plc, plc.location[0]))
                    {
                    }
                    if (BottlePEMInfoFullTwo(plc, plc.location[1]))
                    {
                    }
                }
                //if (data.Substring(1, 1) == "1")
                //{
                //    if (BottlePEMInfoFull(plc, plc.location[0]))
                //    {
                //        //设备没有托盘,或者已经有任务,不处理满托信号,返回已经取货完成
                //        //3F 00 11 0d 0a
                //        //PlcHelper.SendHex(plc.address, "3F00110d0a");
                //    }
                //}
                //else if (data.Substring(1, 1) == "3")
                //{
                //    if (BottleCapInfoEmpty(plc, plc.location[0]))
@@ -1754,13 +1786,13 @@
                //    }
                //}
                if (data.Substring(3, 1) == "1")
                {
                    if (BottlePEMInfoFull(plc, plc.location[1]))
                    {
                        //PlcHelper.SendHex(plc.address, "3F00210d0a");
                    }
                }
                //if (data.Substring(3, 1) == "1")
                //{
                //    if (BottlePEMInfoFull(plc, plc.location[1]))
                //    {
                //        //PlcHelper.SendHex(plc.address, "3F00210d0a");
                //    }
                //}
                //else if (data.Substring(3, 1) == "3")
                //{
                //    if (BottleCapInfoEmpty(plc, plc.location[1]))
@@ -1963,6 +1995,54 @@
                        }
                    }
                }
            }
        }
        private static object locko = new object();
        static bool BottlePEMInfoFullTwo(Settings.deviceInfo plc, string location)
        {
            try
            {
                lock (locko)
                {
                    var chi = new SqlHelper<object>().GetInstance();
                    var newDb = chi.CopyNew();
                    Location endBit = null;
                    if (location == "")
                    {
                        throw new Exception("货位为空");
                    }
                    var workOrder = WCSHelper.GetWorkOrder(plc.deviceName);
                    if (workOrder == null)
                    {
                        throw new Exception("没有【执行中】的工单");
                    }
                    if (workOrder.SQL_UsingNow == "Y")//即产即用
                    {
                        //查询 半成品区域表 BcpQyOrder
                    }
                    else//非即产即用
                    {
                    }
                    if (endBit != null)
                    {
                        var _ctrl = LocationHelper.GetLocCntrRel(location);
                        int endLayer = endBit.N_CURRENT_NUM + 1;
                        var carryCntrs = new List<string> { _ctrl.FirstOrDefault().S_CNTR_CODE };//DateTime.Now.ToString("yyMMddHHmmss") };
                        var bb = TaskProcess.CreateTransport(workOrder.SQL_WorkNo, location, endBit.S_LOC_CODE, "满瓶坯-入库", carryCntrs, 1, endLayer, carryCntrs.Count, plc.taskPri);
                    }
                    return true;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info(plc.deviceName + $" 报错: {ex.Message}");
                return false;
            }
        }
@@ -2721,7 +2801,6 @@
            //就查看有没有空的排了。 
            //if (endBit != null) ///  寻找未满排, 直接返回结果。 
            return endBit;
        //LogHelper.Info(" _tempList over!");
        //这里开始 寻找空排
        Empty:
@@ -3492,26 +3571,27 @@
                                        }
                                    if (endBit == null && _tempList.Any())
                                    {
                                        LogHelper.Info(" ar_RplaceRow over!");
                                        var ar_RplaceRows = LocationHelper.GetLocList(x => x.S_AREA_CODE != area1 && x.S_AREA_CODE.Contains(are) && x.S_LOCK_STATE != "报废");//.Select(x => x.N_ROW).Distinct();
                                                                                                                                                                            //var ar_RplaceRow1 = ar_RplaceRows.FindAll(x => x.S_LOCK_STATE != "无").Select(x => x.N_ROW).Distinct();
                                        IEnumerable<int> ar_RplaceRow1 = ar_RplaceRows.FindAll(x => "入库锁;出库锁".Contains(x.S_LOCK_STATE?.Trim())).Select(x => x.N_ROW).Distinct();
                                        LogHelper.Info(" 有锁排 - " + JsonConvert.SerializeObject(ar_RplaceRow1));                                                                                        //LogHelper.Info(" 有锁排 - " + JsonConvert.SerializeObject(ar_RplaceRow1));
                                        var ar_RplaceRow2 = ar_RplaceRows.FindAll(x => x.N_CURRENT_NUM > 0).Select(x => x.N_ROW).Distinct();
                                        LogHelper.Info(" 有货排: - " + JsonConvert.SerializeObject(ar_RplaceRow2));
                                        var ar_RplaceRow_rowlock = LocationHelper.GetRowLock(x => x.S_AREA_CODE.Contains(are))?.Select(x => x.N_ROW);
                                        LogHelper.Info(" ar_RplaceRow over!" + JsonConvert.SerializeObject(_tempList.Select(x => x.N_ROW).Distinct()));
                                        //var ar_RplaceRows = LocationHelper.GetLocList(x => x.S_AREA_CODE != area1 && x.S_AREA_CODE.Contains(are) && x.S_LOCK_STATE != "报废");//.Select(x => x.N_ROW).Distinct();
                                        //                                                                                                                                    //var ar_RplaceRow1 = ar_RplaceRows.FindAll(x => x.S_LOCK_STATE != "无").Select(x => x.N_ROW).Distinct();
                                        //IEnumerable<int> ar_RplaceRow1 = ar_RplaceRows.FindAll(x => "入库锁;出库锁".Contains(x.S_LOCK_STATE?.Trim())).Select(x => x.N_ROW).Distinct();
                                        //LogHelper.Info(" 有锁排 - " + JsonConvert.SerializeObject(ar_RplaceRow1));                                                                                        //LogHelper.Info(" 有锁排 - " + JsonConvert.SerializeObject(ar_RplaceRow1));
                                        //var ar_RplaceRow2 = ar_RplaceRows.FindAll(x => x.N_CURRENT_NUM > 0).Select(x => x.N_ROW).Distinct();
                                        //LogHelper.Info(" 有货排: - " + JsonConvert.SerializeObject(ar_RplaceRow2));
                                        //var ar_RplaceRow_rowlock = LocationHelper.GetRowLock(x => x.S_AREA_CODE.Contains(are))?.Select(x => x.N_ROW);
                                        var ar_RplaceRow = ar_RplaceRow1.Concat(ar_RplaceRow2).Concat(ar_RplaceRow_rowlock).Distinct();
                                        //var ar_RplaceRow = ar_RplaceRow1.Concat(ar_RplaceRow2).Concat(ar_RplaceRow_rowlock).Distinct();
                                        if (ar_RplaceRow.Any())
                                        {
                                            LogHelper.Info("排除非空排 - " + JsonConvert.SerializeObject(ar_RplaceRow));
                                            _tempList.RemoveAll(x => ar_RplaceRow.Contains(x.N_ROW));
                                        }
                                        if (_tempList.Any())//三个库区的交集空排
                                        {
                                            endBit = _tempList.OrderBy(x => x.N_ROW).ThenBy(x => x.N_COL).FirstOrDefault();
                                        }
                                        //if (ar_RplaceRow.Any())
                                        //{
                                        //    LogHelper.Info("排除非空排 - " + JsonConvert.SerializeObject(ar_RplaceRow));
                                        //    _tempList.RemoveAll(x => ar_RplaceRow.Contains(x.N_ROW));
                                        //}
                                        //if (_tempList.Any())//三个库区的交集空排
                                        //{
                                        //    endBit = _tempList.OrderBy(x => x.N_ROW).ThenBy(x => x.N_COL).FirstOrDefault();
                                        //}
                                        endBit = _tempList.OrderBy(x => x.N_ROW).ThenBy(x => x.N_COL).FirstOrDefault();
                                    }
                                    #endregion