分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-04-27 0b5ccdca6263cf7a2cee460f30c76ef1efea2811
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs
@@ -1,4 +1,5 @@
using FreeSql.Internal.Model;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
@@ -434,7 +435,8 @@
                            var Wheel_SN = client.ReadByOrder<string>("R_Wheel_id", name);//车轮SN号
                            if (string.IsNullOrEmpty(Wheel_SN))
                            {
                                WriteDBLog.Error(name + "放料完成", $"读取桁架信息:\n车轮SN号为空", "PCS");
                                //WriteDBLog.Error(name + "放料完成", $"读取桁架信息:\n车轮SN号为空", "PCS");
                                WriteLog.Write_Log(name + "放料完成出错", "车轮SN号为空", "读取桁架信息:", $"车轮SN号:{Wheel_SN}为空");
                                continue;
                            }
@@ -443,7 +445,8 @@
                            if (Mes_Work == null)
                            {
                                #region æ—¥å¿—记录
                                WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN号:{Wheel_SN}\n\n未查询到工单详情", "PCS");
                                //WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN号:{Wheel_SN}\n\n未查询到工单详情", "PCS");
                                WriteLog.Write_Log(name + "放料完成出错", Wheel_SN, "读取桁架信息:", $"车轮SN号:{Wheel_SN}未查询到工单信息");
                                #endregion
                                continue;
                            }
@@ -511,10 +514,14 @@
                            client.WriteByOrder("W_IndexNr", (Int16)0, name);//托盘上的第几个车轮
                            client.WriteByOrder("W_Storage_Type", (Int16)0, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                            client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                            WriteDBLog.Success(name + "桁架下料完成",
                                $"读取桁架信息:\nR_load_finished:{finished}\n车轮SN:{Wheel_SN}\n轮型ID:{WheelType}\n下料位号:{AreaNr}\n\n" +
                                $"处理写入桁架信息:\nW_AreaNr:{0}\nW_IndexNr:{0}\nW_Storage_Type:{0}\n\n" +
                                $"写入桁架信息:\nW_Storage_update:{true}\nW_Enabl_Load:{false}", "PCS");
                            WriteLog.Write_Log(name + "放料完成", Wheel_SN, "成功!",
                                $"读取桁架信息:\n放料完成信号:{finished}\n车轮SN:{Wheel_SN}\n轮型ID:{WheelType}\n下料位号:{AreaNr}\n\n" +
                                $"处理写入桁架信息:\n区域货位号:{0}\n托盘上的第几个车轮:{0}\n托盘类型:{0}\n\n" +
                                $"写入桁架信息:\n货位状态更新信号:{true}\n是否允许下料:{false}");
                            //WriteDBLog.Success(name + "桁架下料完成",
                            //    $"读取桁架信息:\nR_load_finished:{finished}\n车轮SN:{Wheel_SN}\n轮型ID:{WheelType}\n下料位号:{AreaNr}\n\n" +
                            //    $"处理写入桁架信息:\nW_AreaNr:{0}\nW_IndexNr:{0}\nW_Storage_Type:{0}\n\n" +
                            //    $"写入桁架信息:\nW_Storage_update:{true}\nW_Enabl_Load:{false}", "PCS");
                            #endregion
@@ -547,7 +554,9 @@
                        {
                            client.WriteByOrder("W_Storage_update", false, name);//货位状态更新
                            #region æ—¥å¿—记录
                            WriteDBLog.Success(name + "货位状态更新复位", $"读取桁架信息:\nR_load_finished:{finished}\n\n写入桁架信息:\nW_Storage_update:{false}", "PCS");
                            //WriteDBLog.Success(name + "货位状态更新复位", $"读取桁架信息:\nR_load_finished:{finished}\n\n写入桁架信息:\nW_Storage_update:{false}", "PCS");
                            WriteLog.Write_Log(name + "放料完成", name + "货位状态更新信号复位", "成功!",
                                $"读取桁架信息:\n放料完成信号:{finished}\n\n写入桁架信息:\n货位状态更新信号:{false}");
                            #endregion
                        }
                        #endregion
@@ -561,13 +570,19 @@
                        #region è¯»å–桁架信息
                        var Wheel_Type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//车轮类型
                        var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);//车轮SN号
                        if (string.IsNullOrEmpty(Wheel_id)) continue;
                        if (string.IsNullOrEmpty(Wheel_id))
                        {
                            WriteLog.Write_Log(name + "申请放料异常", "车轮SN号为空", "", $"读取桁架信息:\n车轮SN号:{Wheel_id}为空");
                            continue;
                        }
                        var Work = workinfoRepository.Find(x => x.SN == Wheel_id && x.processCode == "17").FirstOrDefault();
                        if (Work == null)
                        {
                            client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                            WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单信息", "PCS");
                            //WriteDBLog.Error(name, $"读取桁架信息:\n车轮SN:{Wheel_id}\n\n未查询到工单信息", "PCS");
                            WriteLog.Write_Log(name + "申请放料异常", Wheel_id, "查询机加工工单", $"读取桁架信息:\n车轮SN号:{Wheel_id}未查询到工单信息\n写入桁架信息:\n是否允许下料:{false}");
                        }
                        #region MyRegion
@@ -619,7 +634,8 @@
                        {
                            #region æ—¥å¿—记录
                            client.WriteByOrder("W_Enabl_Load", false, name);//信号为false桁架停止进入
                            WriteDBLog.Error(name, $"未查询到车轮信息!", "PCS");
                            //WriteDBLog.Error(name, $"未查询到车轮信息!", "PCS");
                            WriteLog.Write_Log(name + "申请放料异常", Wheel_id, $"查询{Work.drawingNo}车轮参数", $"读取桁架信息:\n车轮SN号:{Wheel_id}未查询到工单信息\n写入桁架信息:\n是否允许下料:{false}");
                            #endregion
                            continue;
                        }
@@ -628,7 +644,8 @@
                        var load_zone = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_zone").First(), client);
                        #region æ—¥å¿—记录
                        WriteDBLog.Success(name + "申请放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:{PartStatus}\n是否进入下料区:{load_zone}", "PCS");
                        //WriteDBLog.Success(name + "申请放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:{PartStatus}\n是否进入下料区:{load_zone}", "PCS");
                        WriteLog.Write_Log(name + "申请放料", Wheel_id, "申请放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:{PartStatus}\n是否进入下料区:{load_zone}");
                        if (load_zone) continue;
                        #endregion
                        if ((Int16)PartStatus == 1)
@@ -664,6 +681,7 @@
                            if (Stationinfo == null)
                            {
                                #region ä¸‹æ–™ä½æ¡ä»¶ä¸åŒ¹é…ç›´æŽ¥è§¦å‘入库任务
                                //var stationinfos = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
                                //foreach (var stationinfo in stationinfos)
@@ -783,23 +801,32 @@
                                    client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                                    client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                                    #region æ—¥å¿—记录
                                    WriteDBLog.Success(name + "允许放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:OK" +
                                    //WriteDBLog.Success(name + "允许放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:OK" +$"\n读取托盘光电信号:{PalletSignal}" +
                                    //    $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                    WriteLog.Write_Log(name + "申请放料", Wheel_id, "允许放料",
                                        $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:合格" +
                                        $"\n读取托盘光电信号:{PalletSignal}" +
                                        $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                        $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\n是否允许下料:true");
                                    #endregion
                                    continue;
                                }
                            }
                            //else
                            //{
                            //    #region æ²¡æ‰˜ç›˜å¯ç”¨,触发入库任务
                            //    var stationinfos = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
                            //    foreach (var stationinfo in stationinfos)
                            //    {
                            //        agvtask(stationinfoRepository, stationinfo, Work, name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                            //    }
                            //    #endregion
                            //}
                            else
                            {
                                #region æ²¡æ‰˜ç›˜å¯ç”¨,触发入库任务
                                if (!Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state != LocationStateEnum.Stroge.ToString()).Any())
                                {
                                    var station = Stations.Where(x => x.enable && x.stationCode != NGStation).OrderBy(x => x.lastUpdateTime).FirstOrDefault();
                                    agvtask(stationinfoRepository, station, Work, name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                }
                                //var stationinfos = Stations.Where(x => x.enable && x.Number != Work.workOrder && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
                                //foreach (var stationinfo in stationinfos)
                                //{
                                //    agvtask(stationinfoRepository, stationinfo, Work, name == "3单元下料区" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                //}
                                #endregion
                            }
                        }
                        else if ((Int16)PartStatus == 2)
@@ -887,6 +914,7 @@
                                        Stationinfo.remark = "车轮数量与光电不匹配";
                                        stationinfoRepository.Update(Stationinfo, true);
                                        WriteDBLog.Error(name + "报警", $"货位编号:{Stationinfo.stationCode};错误信息:{Stationinfo.remark}", "PCS");
                                        //WriteDBLog.Error(name+"申请下料",$"{Stationinfo.stationCode}的货位","PCS");
                                    }
                                    else if (list.Count < 1 && MaterialSignal == 1)
@@ -916,9 +944,12 @@
                                    client.WriteByOrder("W_Storage_Type", (Int16)1, name);//托盘类型1-横放;2-竖放(暂时只有横放托盘)
                                    client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
                                    #region æ—¥å¿—记录
                                    WriteDBLog.Success(name + "允许放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:NG" +
                                    //WriteDBLog.Success(name + "允许放料", $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:NG" +$"\n读取托盘光电信号:{PalletSignal}" +
                                    //    $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                    WriteLog.Write_Log(name + "申请放料", Wheel_id, "允许放料",
                                        $"读取桁架信息:\n车轮SN:{Wheel_id}\n轮型ID:{Wheel_Type}\n车轮状态:合格" +
                                        $"\n读取托盘光电信号:{PalletSignal}" +
                                        $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\nW_Enabl_Load:true", "PCS");
                                        $"\n\n写入桁架信息:\n下料位号:{area}\n第几个车轮:{(Stationinfo.quantity + 1)}\n托盘类型:1\n是否允许下料:true");
                                    #endregion
                                    continue;
                                }
@@ -991,66 +1022,80 @@
        }
        #endregion
        /// <summary>
        /// AGV任务
        /// </summary>
        public void agvtask(Idt_stationinfoRepository stationinfoRepository, dt_stationinfo stationinfo, VV_Mes_Workinfo Work, string tasktype)
        {
            VOLContext Context = new VOLContext();
            Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
            Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
            var task = agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).FirstOrDefault();
            if (task != null) return;
            //var mes_Head = mes_HeadRepository.Find(x => x.jobID == Work.jobID).FirstOrDefault();
            //if (mes_Head == null)
            //{
            //    stationinfo.remark = "触发入库任务,但未找到工单头表!";
            //    stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
            //    stationinfoRepository.Update(stationinfo, true);
            //    return;
            //}
            dt_stationinfo TargetLocation = null;
            //int CompeletedNum = Convert.ToInt32(mes_Head.quantity) - Convert.ToInt32(mes_Head.finishNum);
            //if (mes_Head.quantity <= 50) tasktype = "TaskType_OutsourceInbound";
            if (tasktype == "TaskType_OutsourceInbound" || !string.IsNullOrEmpty(Work.area))
                TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository);
            else if (tasktype == "TaskType_Inbound")
                TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, Work, stationinfo);
            //TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, mes_Head, stationinfo);
            if (TargetLocation != null)
            {
                dt_agvtask agvtask = new dt_agvtask()
                {
                    agv_fromaddress = stationinfo.stationCode,
                    agv_id = Guid.NewGuid(),
                    agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                    agv_grade = 1,
                    agv_createtime = DateTime.Now,
                    agv_taskstate = "Create",
                    agv_materielid = stationinfo.stationType,
                    agv_qty = stationinfo.quantity,
                    agv_tasktype = tasktype,
                    agv_toaddress = TargetLocation.stationCode,
                    agv_userid = "系统",
                    bindSN = stationinfo.bindSN,
                    agv_worktype = Convert.ToInt32(Work.processCode),
                    agv_materbarcode = Work.materialCode,
                    agv_Traytype = stationinfo.tray_type,
                    jobID = stationinfo.Number,
                    agv_TrayStatus = stationinfo.tray_status
                };
                agvtaskRepository.Add(agvtask, true);
                stationinfo.location_state = LocationStateEnum.InBusy.ToString();
                stationinfoRepository.Update(stationinfo, true);
                TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
                TargetLocation.stationType = agvtask.agv_materielid;
                TargetLocation.heatNumber = stationinfo.heatNumber;
                TargetLocation.Number = agvtask.jobID;
                stationinfoRepository.Update(TargetLocation, true);
            }
            if (!string.IsNullOrEmpty(Work.area))
                tasktype = "TaskType_OutsourceInbound";
            AGVTask.AddQueueTask(stationinfoRepository, agvtaskRepository, stationinfo, tasktype, Work);
        }
        #region MyRegion
        /// <summary>
        /// AGV任务
        /// </summary>
        //public void agvtask(Idt_stationinfoRepository stationinfoRepository, dt_stationinfo stationinfo, VV_Mes_Workinfo Work, string tasktype)
        //{
        //    VOLContext Context = new VOLContext();
        //    Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
        //    Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
        //    var task = agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).FirstOrDefault();
        //    if (task != null) return;
        //    //var mes_Head = mes_HeadRepository.Find(x => x.jobID == Work.jobID).FirstOrDefault();
        //    //if (mes_Head == null)
        //    //{
        //    //    stationinfo.remark = "触发入库任务,但未找到工单头表!";
        //    //    stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
        //    //    stationinfoRepository.Update(stationinfo, true);
        //    //    return;
        //    //}
        //    dt_stationinfo TargetLocation = null;
        //    //int CompeletedNum = Convert.ToInt32(mes_Head.quantity) - Convert.ToInt32(mes_Head.finishNum);
        //    //if (mes_Head.quantity <= 50) tasktype = "TaskType_OutsourceInbound";
        //    if (tasktype == "TaskType_OutsourceInbound" || !string.IsNullOrEmpty(Work.area))
        //        TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository);
        //    else if (tasktype == "TaskType_Inbound")
        //        TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, Work, stationinfo);
        //    //TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, mes_Head, stationinfo);
        //    if (TargetLocation != null)
        //    {
        //        dt_agvtask agvtask = new dt_agvtask()
        //        {
        //            agv_fromaddress = stationinfo.stationCode,
        //            agv_id = Guid.NewGuid(),
        //            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
        //            agv_grade = 1,
        //            agv_createtime = DateTime.Now,
        //            agv_taskstate = "Create",
        //            agv_materielid = stationinfo.stationType,
        //            agv_qty = stationinfo.quantity,
        //            agv_tasktype = tasktype,
        //            agv_toaddress = TargetLocation.stationCode,
        //            agv_userid = "系统",
        //            bindSN = stationinfo.bindSN,
        //            agv_worktype = Convert.ToInt32(Work.processCode),
        //            agv_materbarcode = Work.materialCode,
        //            agv_Traytype = stationinfo.tray_type,
        //            jobID = stationinfo.Number,
        //            agv_TrayStatus = stationinfo.tray_status
        //        };
        //        agvtaskRepository.Add(agvtask, true);
        //        stationinfo.location_state = LocationStateEnum.InBusy.ToString();
        //        stationinfoRepository.Update(stationinfo, true);
        //        TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
        //        TargetLocation.stationType = agvtask.agv_materielid;
        //        TargetLocation.heatNumber = stationinfo.heatNumber;
        //        TargetLocation.Number = agvtask.jobID;
        //        stationinfoRepository.Update(TargetLocation, true);
        //    }
        //}
        #endregion
    }
}