1
cjs
1 天以前 ff48949f706e899725c1ef7d0426c12c2b3e674f
ams/Hanhe.iWCS.JingmenGEMTwoProtocol/ProcessHelper.cs
@@ -15,6 +15,7 @@
using System.Linq;
using System.Net.Configuration;
using System.Text;
using System.Threading;
using System.Web.UI.WebControls.WebParts;
using static Hanhe.iWCS.JingmenGEMTwoProtocol.ApiHelper;
using static Hanhe.iWCS.JingmenGEMTwoProtocol.EnentListen;
@@ -131,22 +132,6 @@
            if(mst.CN_S_STATUS=="未执行" || mst.CN_S_STATUS == "待推送")
            {
                mst = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", mst.CN_S_TASK_NO), "TN_I_TASK_MST");
                if (mst.CN_S_BUSS_TYPE == "辅材回库")
                {
                    var CBTableList = MongoDBSingleton.Instance.FindAll<ConnectingBits>("ConnectingBits");
                    foreach (var a in CBTableList)
                    {
                        if (string.IsNullOrEmpty(a.trayCode))
                        {
                            string cntrType = mst.transportInfo[0].trayCode;
                            MongoDBSingleton.Instance.Update<ConnectingBits>(Query.EQ("Bit", a.Bit), Update.Set("trayCode", cntrType).Set("END_LOC", mst.CN_S_END_BIT), UpdateFlags.None);
                            MongoDBSingleton.Instance.Update<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", mst.CN_S_TASK_NO), Update.Set("CN_S_END_BIT", a.Bit), UpdateFlags.None);
                            new SqlHelper<object>().ExecuteSql($"update dbo.tn_am_task_mst set CN_S_END_BIT='{a.Bit}',CN_S_END_AGVBIT = '{StockInstance.Instance.GetAGVCodeForBitCode(a.Bit)}' where CN_S_TASK_NO = '{mst.CN_S_TASK_NO}'");
                        }
                    }
                }
                StringBuilder sbMsg = new StringBuilder();
                var start = StockInstance.Instance.GetLocationInfoTwo(mst.CN_S_START_BIT);
@@ -158,11 +143,27 @@
                    //两个接驳平台
                    if (mst.CN_S_START_BIT == conn[0].locCode || mst.CN_S_START_BIT == conn[1].locCode)
                    {
                        start.CN_N_AGV_LOCATION = Settings.GetConnectingbitsList().Where(a => a.locCode == mst.CN_S_START_BIT).First().agvSite[1];
                        if(mst.CN_S_BUSS_TYPE == "辅材出库(二段)")
                        {
                            start.CN_N_AGV_LOCATION = Settings.GetConnectingbitsList().Where(a => a.locCode == mst.CN_S_START_BIT).First().agvSite[0];
                        }
                        else
                        {
                            start.CN_N_AGV_LOCATION = Settings.GetConnectingbitsList().Where(a => a.locCode == mst.CN_S_START_BIT).First().agvSite[1];
                        }
                    }
                    if (mst.CN_S_END_BIT == conn[0].locCode || mst.CN_S_END_BIT == conn[1].locCode)
                    {
                        end.CN_N_AGV_LOCATION = Settings.GetConnectingbitsList().Where(a => a.locCode == mst.CN_S_END_BIT).First().agvSite[0];
                        if(mst.CN_S_BUSS_TYPE == "辅材出库(二段)")
                        {
                            end.CN_N_AGV_LOCATION = Settings.GetConnectingbitsList().Where(a => a.locCode == mst.CN_S_END_BIT).First().agvSite[1];
                        }
                        else
                        {
                            end.CN_N_AGV_LOCATION = Settings.GetConnectingbitsList().Where(a => a.locCode == mst.CN_S_END_BIT).First().agvSite[0];
                        }
                    }
                }
                if (conn.Count == 1)
@@ -280,7 +281,7 @@
                var endLoc = MongoDBSingleton.Instance.FindOne<MongoTN_AB_STOCK_LOCATION>(Query.EQ("CN_S_LOCATION_CODE", mst.CN_S_END_BIT), "MongoTN_AB_STOCK_LOCATION");
                if(startLoc != null && endLoc != null)
                {
                    if(startLoc.CN_S_AREA_CODE == "CKHJ" || endLoc.CN_S_AREA_CODE == "CKHJ")
                    if(startLoc.CN_S_AREA_CODE == "CKHJ" || endLoc.CN_S_AREA_CODE == "CKHJ" || endLoc.CN_S_AREA_CODE == "CPTPFCHJ" || startLoc.CN_S_AREA_CODE == "CPTPFCHJ")
                    {
                        TRow = "1";
                    }
@@ -424,11 +425,12 @@
                if (code == 1012)
                {
                    //卸货申请,先判断设备是否允许进料,如果是直接改参数,并通知设备
                    if (mst.CN_S_BUSS_TYPE == "3楼包装取料" || mst.CN_S_BUSS_TYPE == "PDA打包下线") PLCControl.PickUpFullDoorUnload(plc.ip, mst.CN_S_TASK_NO);//进入3楼包装取料流程1012,ip:{plc.ip},task:{mst.CN_S_TASK_NO}
                    if (mst.CN_S_BUSS_TYPE == "3楼包装取料" || mst.CN_S_BUSS_TYPE == "PDA打包下线") PLCControl.PickUpFullDoorUnload(plc.ip, mst.CN_S_TASK_NO, mst.CN_S_BUSS_TYPE);//进入3楼包装取料流程1012,ip:{plc.ip},task:{mst.CN_S_TASK_NO}
                    if (mst.CN_S_BUSS_TYPE == "3楼复称入缓存架" || mst.CN_S_BUSS_TYPE == "3楼复称入缓存架NG") PLCControl.SecondWeightInCache1012(plc.ip, mst.CN_S_TASK_NO);//二期:直接改参数
                    if (mst.CN_S_BUSS_TYPE == "3楼缓存架入叠托") TSHelper.GoToAGV(mst.CN_S_TASK_NO, 10, 1);
                    if (mst.CN_S_BUSS_TYPE == "3楼叠盘下线") PLCControl.StackingReqUnload(plc.deviceType, mst.CN_S_TASK_NO);
                    if (mst.CN_S_BUSS_TYPE == "3楼打包下线") PLCControl.PackingLineUnload1012(plc.ip, mst.CN_S_TASK_NO);
                    if (mst.CN_S_BUSS_TYPE == "辅材入库") PLCControl.fcrk(plc, true, mst.CN_S_TASK_NO);
                    if (mst.CN_S_BUSS_TYPE == "烘干机满托下线" || mst.CN_S_BUSS_TYPE == "剪切机空托下线" || mst.CN_S_BUSS_TYPE == "包装机满托下线") PLCControl.DGMachine(plc,mst.CN_S_TASK_NO,true);
                }
                if (code == 4)
@@ -440,7 +442,7 @@
                    if (mst.CN_S_BUSS_TYPE == "3楼打包下线") PLCControl.PackingLineComplete4(plc.ip, mst.CN_S_SOURCE_NO);
                    if (mst.CN_S_BUSS_TYPE != "3楼包装取料") WMSHelper.ExecuteState(mst.CN_S_SOURCE_NO, 4);
                    if (mst.CN_S_BUSS_TYPE == "3楼缓存架入叠托NG") PLCControl.CacheStackingMouth6(plc);
                    if (mst.CN_S_BUSS_TYPE == "辅材入库") PLCControl.fcrk(plc);
                    if (mst.CN_S_BUSS_TYPE == "辅材入库") PLCControl.fcrk(plc, false);
                    if (mst.CN_S_BUSS_TYPE == "烘干机满托下线" || mst.CN_S_BUSS_TYPE == "剪切机空托下线" || mst.CN_S_BUSS_TYPE == "包装机满托下线") PLCControl.DGMachine(plc, mst.CN_S_TASK_NO, false);
                }
@@ -546,7 +548,7 @@
                    //    }
                    //}
                }
                if (mst.CN_S_BUSS_TYPE == "3楼成品出库" || mst.CN_S_BUSS_TYPE == "辅材出库")
                if (mst.CN_S_BUSS_TYPE == "3楼成品出库")
                {
                    //3楼成品出库任务拦截
                    if (!OutWareTask(mst))
@@ -561,6 +563,10 @@
                    {
                        result = true;
                    }
                }
                if (mst.CN_S_BUSS_TYPE == "辅材出库")
                {
                    FCOutTask(mst);
                }
                if (mst.CN_S_BUSS_TYPE == "电钴生产退库")
                {
@@ -629,6 +635,48 @@
        }
        /// <summary>
        /// 辅材出库
        /// </summary>
        /// <param name="mst"></param>
        private static void FCOutTask(TN_I_TASK_MST mst)
        {
            var CBInfo = Settings.GetConnectingbitsList().Where(a => a.enable == 1).ToList();
            if (CBInfo != null)
            {
                foreach (var a in CBInfo)
                {
                    if (!string.IsNullOrEmpty(a.locCode))
                    {
                        //在中间表中查找点位
                        var CBTable = MongoDBSingleton.Instance.FindOne<ConnectingBits>(Query.EQ("Bit", a.locCode), "ConnectingBits");
                        if (CBTable != null)
                        {
                            if (string.IsNullOrEmpty(CBTable.trayCode))
                            {
                                //修改任务终点,并且将点位写入中间表
                                MongoDBSingleton.Instance.Update<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", mst.CN_S_TASK_NO), Update.Set("CN_S_END_BIT", a.locCode), UpdateFlags.None);
                                new SqlHelper<object>().ExecuteSql($"update dbo.tn_am_task_mst set CN_S_END_BIT='{a.locCode}',CN_S_END_AGVBIT = '{StockInstance.Instance.GetAGVCodeForBitCode(a.locCode)}' where CN_S_TASK_NO = '{mst.CN_S_TASK_NO}'");
                                MongoDBSingleton.Instance.Update<ConnectingBits>(Query.EQ("Bit", a.locCode), Update.Set("trayCode", mst.CN_S_BATCH_NO).Set("END_LOC", a.locCode), UpdateFlags.None);
                            }
                        }
                        else
                        {
                            //修改任务终点,并且将点位写入中间表
                            MongoDBSingleton.Instance.Update<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", mst.CN_S_TASK_NO), Update.Set("CN_S_END_BIT", a.locCode), UpdateFlags.None);
                            new SqlHelper<object>().ExecuteSql($"update dbo.tn_am_task_mst set CN_S_END_BIT='{a.locCode}',CN_S_END_AGVBIT = '{StockInstance.Instance.GetAGVCodeForBitCode(a.locCode)}' where CN_S_TASK_NO = '{mst.CN_S_TASK_NO}'");
                            MongoDBSingleton.Instance.Insert<ConnectingBits>(new ConnectingBits { Bit = a.locCode, trayCode = mst.CN_S_BATCH_NO, state = "0", END_LOC = a.locCode });
                        }
                    }
                    else CMMLog.Debug("接驳位点位未配置");
                }
            }
        }
        /// <summary>
        /// 四钴生产退库
        /// 将任务拆分成两段任务,第一段任务终点改为接驳平台
        /// 二段任务从接驳平台入库
@@ -688,90 +736,77 @@
        {
            //1、判断辅材入库终点是否有任务
            //2、判断输送线模式和中间表模式都是入库模式
            bool action = true;
            var plc = Settings.GetPlcInfo().Where(a => a.deviceType == "18" && a.enable == 1).ToList();
            if (plc.Count > 0)
            CMMLog.Debug("辅材入库流程 开始");
            bool action = false;
            var plc = Settings.GetPlcInfo().Where(a => a.location == mst.CN_S_START_BIT && a.enable == 1).First();
            if (plc != null)
            {
                foreach(var a in plc)
                var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                {
                    if(CheckStartFree(a.location) && CheckEndFree(a.location))
                    dataNum = 1,
                    addr = plc.readAddr + 3,
                    host = plc.ip,
                    port = plc.port
                });
                if (result != null && result.errCode == 0)
                {
                    CMMLog.Debug($"辅材入库流程:读取滚筒机{plc.ip}通道号为:{plc.readAddr + 3}的值为:{result.result[0]}");
                    if (result.result[0] == 1)
                    {
                        var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                        CMMLog.Debug($"辅材入库流程:输送线为 出库模式,输送线点位:{plc.location}");
                        return action;
                    }
                    if (result.result[0] == 2)
                    {
                        //读取中间表模式
                        var modelInfo = MongoDBSingleton.Instance.FindOne<ModeList>("ModeList");
                        if (modelInfo != null)
                        {
                            dataNum = 1,
                            addr = a.readAddr + 3,
                            host = a.ip,
                            port = a.port
                        });
                        if (result != null && result.errCode == 0)
                        {
                            CMMLog.Debug($"辅材入库流程:读取滚筒机{a.ip}通道号为:{a.readAddr + 3}的值为:{result.result[0]}");
                            if (result.result[0] == 1)
                            if (modelInfo.Mode == "出库模式")
                            {
                                action = false;
                                CMMLog.Debug($"辅材入库流程:输送线为 出库模式,输送线点位:{a.location}");
                                break;
                                CMMLog.Debug($"辅材入库流程:中间表 ModeList为 出库模式");
                                return action;
                            }
                            else
                            {
                                //读取中间表模式
                                var modelInfo = MongoDBSingleton.Instance.FindOne<ModeList>("ModeList");
                                if(modelInfo != null)
                                {
                                    if(modelInfo.Mode == "出库模式")
                                    {
                                        action = false;
                                        CMMLog.Debug($"辅材入库流程:中间表 ModeList为 出库模式");
                                        break;
                                    }
                                }
                                else
                                {
                                    action = false;
                                    CMMLog.Debug("辅材入库流程:中间表 ModeList 为空");
                                    break;
                                }
                                action = true;
                            }
                        }
                        else
                        {
                            CMMLog.Debug("辅材入库流程:中间表 ModeList 为空");
                            return action;
                        }
                    }
                    else
                    {
                        action = false;
                        CMMLog.Debug($"辅材入库流程:当前点位有任务,点位:{a.location}");
                        break;
                    }
                };
                }
                if (action)
                {
                    //入库模式核验正确 判断货物是否到位
                    var startPlc = plc.Where(a => a.location == mst.CN_S_START_BIT).First();
                    if(startPlc != null)
                    result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                    {
                        var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                        {
                            dataNum = 1,
                            addr = startPlc.readAddr + 1,
                            host = startPlc.ip,
                            port = startPlc.port
                        });
                        dataNum = 1,
                        addr = plc.readAddr + 1,
                        host = plc.ip,
                        port = plc.port
                    });
                        if (result != null && result.errCode == 0)
                    if (result != null && result.errCode == 0)
                    {
                        CMMLog.Debug($"辅材入库流程:读取滚筒机{plc.ip}通道号为:{plc.readAddr + 1}的值为:{result.result[0]}");
                        if (result.result[0] == 2)
                        {
                            CMMLog.Debug($"辅材入库流程:读取滚筒机{startPlc.ip}通道号为:{startPlc.readAddr + 3}的值为:{result.result[0]}");
                            if (result.result[0] == 2)
                            int[] num = new int[2] { 2, 1 };
                            var wirteal = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
                            {
                                int[] num = new int[2] { 2, 1 };
                                var wirteal = OITcpHelper.RegisterWriteOutPutMulti(new OITcpHelper.RegisterWriteOutPutModelMulti
                                {
                                    addr = startPlc.writeAddr + 1,
                                    host = startPlc.ip,
                                    data = num,
                                    port = startPlc.port
                                });
                                addr = plc.writeAddr + 1,
                                host = plc.ip,
                                data = num,
                                port = plc.port
                            });
                                return true;
                            }
                            return true;
                        }
                    }
                }
@@ -813,50 +848,50 @@
                {
                    #region 判断输送线模式 变更注释
                    //foreach(var a in plc)
                    //{
                    //    bool action = false;
                    //    var modeResult = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                    //    {
                    //        dataNum = 1,
                    //        addr = a.readAddr + 3,
                    //        host = a.ip,
                    //        port = a.port
                    //    });
                    //    if (modeResult != null && modeResult.errCode == 0)
                    //    {
                    //        CMMLog.Debug($"OutWareTask:读取滚筒机{a.ip}通道号为:{a.readAddr + 3}的值为:{modeResult.result[0]}");
                    //        if (modeResult.result[0] == 2)
                    //        {
                    //            CMMLog.Debug($"OutWareTask:输送线为 入库模式,输送线点位:{a.location}");
                    //            break;
                    //        }
                    //        else
                    //        {
                    //            //读取中间表模式
                    //            var modelInfo = MongoDBSingleton.Instance.FindOne<ModeList>("ModeList");
                    //            if (modelInfo != null)
                    //            {
                    //                if (modelInfo.Mode == "入库模式")
                    //                {
                    //                    CMMLog.Debug($"OutWareTask:中间表 ModeList为 入库模式");
                    //                }
                    //                else
                    //                {
                    //                    action = true;
                    //                }
                    //            }
                    //            else
                    //            {
                    //                CMMLog.Debug("OutWareTask:中间表 ModeList 为空");
                    //            }
                    //        }
                    //    }
                    //    if (!action)
                    //    {
                    //        return false;
                    //    }
                    //};
                    foreach(var a in plc)
                    {
                        bool action = false;
                        var modeResult = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                        {
                            dataNum = 1,
                            addr = a.readAddr + 3,
                            host = a.ip,
                            port = a.port
                        });
                        if (modeResult != null && modeResult.errCode == 0)
                        {
                            CMMLog.Debug($"OutWareTask:读取滚筒机{a.ip}通道号为:{a.readAddr + 3}的值为:{modeResult.result[0]}");
                            if (modeResult.result[0] == 2)
                            {
                                CMMLog.Debug($"OutWareTask:输送线为 入库模式,输送线点位:{a.location}");
                                break;
                            }
                            else
                            {
                                //读取中间表模式
                                var modelInfo = MongoDBSingleton.Instance.FindOne<ModeList>("ModeList");
                                if (modelInfo != null)
                                {
                                    if (modelInfo.Mode == "入库模式")
                                    {
                                        CMMLog.Debug($"OutWareTask:中间表 ModeList为 入库模式");
                                    }
                                    else
                                    {
                                        action = true;
                                    }
                                }
                                else
                                {
                                    CMMLog.Debug("OutWareTask:中间表 ModeList 为空");
                                }
                            }
                        }
                        if (!action)
                        {
                            return false;
                        }
                    };
                    #endregion