分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-05-31 53d6a24cb335b0c9b4449e1211ce8ea644d68d67
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/Common/Pipeline.cs
@@ -16,6 +16,7 @@
using WIDESEA_Comm.TaskNo;
using WIDESEA_WCS.JobsPart.Common;
using System.Xml.Linq;
using WIDESEA_Common;
namespace WIDESEA_WCS
{
@@ -84,9 +85,9 @@
                        {
                            #region åˆ¤æ–­åŒºåŸŸå·æ˜¯å¦ä¸€è‡´
                            var area = Gantry_client.ReadByOrder<Int16>("place_prog", number);//放料完成的区域号
                            //var area = Gantry_client.ReadByOrder<Int16>("place_prog", number);//放料完成的区域号
                            WriteLog.Write_Log(number + "取料完成出错", bindSNS[bindSNS.Length - 1], "判断区域号是否一致", $"PCS区域号:{AreaNr};\n桁架区域号:{area}\n错误信息:PCS区域号与桁架区域号不一致!");
                            //WriteLog.Write_Log(number + "取料完成出错", bindSNS[bindSNS.Length - 1], "判断区域号是否一致", $"PCS区域号:{AreaNr};\n桁架区域号:{area}\n错误信息:PCS区域号与桁架区域号不一致!");
                            //if (AreaNr != area)
                            //{
                            //    client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//报警
@@ -97,9 +98,9 @@
                            #endregion
                            #region åˆ¤æ–­è½¦è½®æ•°é‡æ˜¯å¦ä¸€è‡´
                            var quantity = Gantry_client.ReadByOrder<Int16>("pos_prog", number);//桁架记录的车轮数量
                            //var quantity = Gantry_client.ReadByOrder<Int16>("pos_prog", number);//桁架记录的车轮数量
                            WriteLog.Write_Log(number + "取料完成出错", bindSNS[bindSNS.Length - 1], "判断车轮数量是否一致", $"区域号:{AreaNr};\n桁架车轮数:{quantity}\nPCS车轮数:{station.quantity}\n错误信息:PCS区域号与桁架区域号不一致!");
                            //WriteLog.Write_Log(number + "取料完成出错", bindSNS[bindSNS.Length - 1], "判断车轮数量是否一致", $"区域号:{AreaNr};\n桁架车轮数:{quantity}\nPCS车轮数:{station.quantity}\n错误信息:PCS区域号与桁架区域号不一致!");
                            //if (quantity != station.quantity)
                            //{
                            //    client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//报警
@@ -163,10 +164,10 @@
                        {
                            Station.location_state = LocationStateEnum.Abnormal.ToString();
                            Station.remark = "车轮数量与SN号数量不一致";
                            stationinfoRepository.Update(Station, true);
                            stationinfoRepository.Update(Station, x => new { x.location_state, x.remark }, true);
                            Gantry_client.WriteByOrder("W_RequestUnload", false, number);//信号为false桁架停止进入
                            #region æ—¥å¿—记录
                            WriteDBLog.Error("上料区", $"写入桁架信息:\nW_RequestUnload:false\n\n{Station.stationCode}车轮数量与SN号数量不一致", "PCS");
                            //WriteDBLog.Error("上料区", $"写入桁架信息:\nW_RequestUnload:false\n\n{Station.stationCode}车轮数量与SN号数量不一致", "PCS");
                            #endregion
                            return;
                        }
@@ -177,7 +178,15 @@
                        if (PalletSignal == 1 && MaterialSignal == 1)
                        {
                            Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(QueryMateriel(Station.stationType) == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId), number);//车轮类型
                            var geometry = QueryMateriel(Station.stationType);
                            if (geometry == null)
                            {
                                Station.remark = "未找到车轮信息";
                                stationinfoRepository.Update(Station, x => new { x.remark }, true);
                                Gantry_client.WriteByOrder("W_RequestUnload", false, number);//信号为false桁架停止进入
                                return;
                            }
                            Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(geometry.TypeId), number);//车轮类型
                            var area = Convert.ToInt16(Station.stationCode.Substring(Station.stationCode.Length - 1, 1));
                            Gantry_client.WriteByOrder("W_AreaNr", (Int16)area, number);//区域货位号
                            Gantry_client.WriteByOrder("W_IndexNr", (Int16)SNS.Length, number);//托盘上的第几个车轮
@@ -186,7 +195,7 @@
                            Gantry_client.WriteByOrder("W_RequestUnload", true, number);
                            #region æ—¥å¿—记录
                            WriteDBLog.Success("上料区申请", $"读取托盘光电信号:{PalletSignal}\n读取第一个车轮光电信号:{MaterialSignal}\n\n" +
                                $"写入桁架信息:\n区域货位号:{area}\n托盘上的第几个车轮:{SNS.Length}\n托盘类型:{1}\n车轮类型:{(QueryMateriel(Station.stationType) == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId)}" +
                                $"写入桁架信息:\n区域货位号:{area}\n托盘上的第几个车轮:{SNS.Length}\n托盘类型:{1}\n车轮类型:{geometry.TypeId}" +
                                $"\n车轮SN号:{SNS[SNS.Length - 1]}\nW_RequestUnload:true", "PCS");
                            #endregion
                        }
@@ -196,18 +205,18 @@
                        }
                        #region æ›´æ–°ä¸€ä¸ªæ£€æµ‹ä¸Šæ–™ä»»åŠ¡
                        Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
                        if (!agvtaskService.Find(x => x.agv_toaddress == Station.stationCode).Any())
                        {
                            var task = agvtaskService.Find(x => x.agv_taskstate == "Queue" && (x.agv_tasktype == "TaskType_OutsourceOutbound" || x.agv_tasktype == "TaskType_Outbound") && x.agv_toaddress == "").OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
                            if (task != null)
                            {
                                task.agv_taskstate = "Create";
                                task.agv_toaddress = Station.stationCode;
                                agvtaskService.Update(task, true);
                                WriteDBLog.Success("更新一个检测上料任务", $"任务编号:{task.agv_tasknum}", "PCS");
                            }
                        }
                        //Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
                        //if (!agvtaskService.Find(x => x.agv_toaddress == Station.stationCode).Any())
                        //{
                        //    var task = agvtaskService.Find(x => x.agv_taskstate == "Queue" && (x.agv_tasktype == "TaskType_OutsourceOutbound" || x.agv_tasktype == "TaskType_Outbound") && x.agv_toaddress == "").OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
                        //    if (task != null)
                        //    {
                        //        task.agv_taskstate = "Create";
                        //        task.agv_toaddress = Station.stationCode;
                        //        agvtaskService.Update(task, true);
                        //        WriteDBLog.Success("更新一个检测上料任务", $"任务编号:{task.agv_tasknum}", "PCS");
                        //    }
                        //}
                        #endregion
                    }
                }
@@ -377,6 +386,7 @@
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                List<string> stationCodes = new List<string>() { "S01001001", "S01001002", "W01001001", "W01001002", "W01001003" };
                dt_stationinfo EmptyStation = null;
                string remark = "";
                foreach (var stationCode in stationCodes)
                {
@@ -410,66 +420,105 @@
                                agvtaskService.Update(task, true);
                                station.location_state = LocationStateEnum.Busy.ToString();
                                stationinfoRepository.Update(station, true);
                                WriteDBLog.Success("更新空托队列任务", $"任务编号:{task.agv_tasknum},托盘信号:{PalletSignal},货物信号:{MaterialSignal}", "PCS");
                                WriteDBLog.Success("更新补空托队列任务", $"任务编号:{task.agv_tasknum},托盘信号:{PalletSignal},货物信号:{MaterialSignal}", "PCS");
                                continue;
                            }
                            remark = "查询空托叠盘位";
                            #region ç©ºæ‰˜å ç›˜
                            var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity < 5 && x.enable).ToList();
                            var EmptyStation = EmptyStations.Where(x => x.tray_type == station.tray_type && x.location_state == LocationStateEnum.Stroge.ToString()).FirstOrDefault();
                            if (EmptyStation == null)
                                EmptyStation = EmptyStations.Where(x => x.location_state == LocationStateEnum.Empty.ToString() && x.quantity == 0).FirstOrDefault();
                            #region æ£€æµ‹ä¸Šæ–™çš„空托叠盘
                            //remark = "查询空托叠盘位";
                            //var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.enable).ToList();
                            //if (stationCode.Contains("S"))
                            //{
                            //    //var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity < 5 && x.enable).ToList();
                            //    EmptyStation = EmptyStations.Where(x => x.tray_type == station.tray_type && x.quantity < 5 && x.location_state == LocationStateEnum.Stroge.ToString()).FirstOrDefault();
                            //    if (EmptyStation == null)
                            //        EmptyStation = EmptyStations.Where(x => x.location_state == LocationStateEnum.Empty.ToString() && x.quantity == 0).FirstOrDefault();
                            //    if (EmptyStation == null)
                            //    {
                            //        EmptyStation = EmptyStations.Where(x => x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderByDescending(x => x.quantity).FirstOrDefault();
                            //        if (EmptyStation != null) EmptyTray.CreateEmptyTrayIn(stationinfoRepository, EmptyStation);
                            //    }
                            //}
                            //EmptyStation = EmptyStations.Where(x => x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 5).FirstOrDefault();
                            //if (EmptyStation != null) EmptyTray.CreateEmptyTrayIn(stationinfoRepository, EmptyStation);
                            #endregion
                            remark = "查找库内空托位";
                            if (EmptyStation == null)//查找库内空托盘
                                EmptyStation = GetStation.EmptyPalletStation(area);
                            if (EmptyStation != null)
                            #region åˆ›å»ºå–空托队列任务
                            dt_agvtask agvtask = new dt_agvtask()
                            {
                                #region åŒä¸€ä¸ªç©ºæ‰˜ä½åªèƒ½åŒæ—¶ç”Ÿæˆä¸€ä¸ªç©ºæ‰˜ä»»åŠ¡
                                remark = "查询空托位是否存在任务";
                                if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any())
                                    return;
                                #endregion
                                dt_agvtask agvtask = new dt_agvtask()
                                {
                                    agv_fromaddress = station.stationCode,
                                    agv_id = Guid.NewGuid(),
                                    agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                                    agv_grade = station.stationCode.Contains("S0100100") ? 3 : 1,
                                    agv_createtime = DateTime.Now,
                                    agv_taskstate = "Create",
                                    //agv_materielid = station.stationType,
                                    agv_qty = 1,
                                    StarQuantity = 0,
                                    EndQuantity = EmptyStation.quantity,
                                    agv_tasktype = "TaskType_EmptyPallet",
                                    agv_toaddress = EmptyStation.stationCode,
                                    agv_userid = "系统",
                                    agv_TrayStatus = "EmptyTray",//station.tray_status,
                                    agv_Traytype = station.tray_type,
                                };
                                agvtaskService.Add(agvtask, true);
                                station.location_state = LocationStateEnum.Busy.ToString();
                                stationinfoRepository.Update(station, true);
                                EmptyStation.location_state = LocationStateEnum.Busy.ToString();
                                stationinfoRepository.Update(EmptyStation, true);
                                WriteDBLog.Success("创建自动取空托任务", $"任务编号:{agvtask.agv_tasknum},托盘信号:{PalletSignal},货物信号:{MaterialSignal}", "PCS");
                            }
                                agv_fromaddress = station.stationCode,
                                agv_id = Guid.NewGuid(),
                                agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                                agv_grade = station.stationCode.Contains("S0100100") ? 3 : 1,
                                agv_createtime = DateTime.Now,
                                agv_taskstate = AGVTaskStateEnum.Queue.ToString(),
                                //agv_materielid = station.stationType,
                                agv_qty = 1,
                                StarQuantity = 0,
                                EndQuantity = 0,//EmptyStation.quantity,
                                agv_tasktype = AGVTaskTypeEnum.TaskType_EmptyPallet.ToString(),
                                agv_toaddress = "",//EmptyStation.stationCode,
                                agv_userid = "系统",
                                agv_TrayStatus = "EmptyTray",//station.tray_status,
                                agv_Traytype = station.tray_type,
                            };
                            agvtaskService.Add(agvtask, true);
                            station.location_state = LocationStateEnum.Busy.ToString();
                            stationinfoRepository.Update(station, true);
                            //EmptyStation.location_state = LocationStateEnum.Busy.ToString();
                            //stationinfoRepository.Update(EmptyStation, true);
                            WriteDBLog.Success("创建自动取空托队列任务", $"任务编号:{agvtask.agv_tasknum},托盘信号:{PalletSignal},货物信号:{MaterialSignal}", "PCS");
                            #endregion
                            #region åˆ›å»ºå–空托新建任务
                            //else
                            //{
                            //    remark = "查找库内空托位";
                            //    EmptyStation = GetStation.EmptyPalletStation(area);
                            //    if (EmptyStation != null)
                            //        if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any()) return;
                            //}
                            //if (EmptyStation != null)
                            //{
                            //    dt_agvtask agvtask = new dt_agvtask()
                            //    {
                            //        agv_fromaddress = station.stationCode,
                            //        agv_id = Guid.NewGuid(),
                            //        agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                            //        agv_grade = station.stationCode.Contains("S0100100") ? 3 : 1,
                            //        agv_createtime = DateTime.Now,
                            //        agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                            //        //agv_materielid = station.stationType,
                            //        agv_qty = 1,
                            //        StarQuantity = 0,
                            //        EndQuantity = EmptyStation.quantity,
                            //        agv_tasktype = "TaskType_EmptyPallet",
                            //        agv_toaddress = EmptyStation.stationCode,
                            //        agv_userid = "系统",
                            //        agv_TrayStatus = "EmptyTray",//station.tray_status,
                            //        agv_Traytype = station.tray_type,
                            //    };
                            //    agvtaskService.Add(agvtask, true);
                            //    station.location_state = LocationStateEnum.Busy.ToString();
                            //    stationinfoRepository.Update(station, true);
                            //    EmptyStation.location_state = LocationStateEnum.Busy.ToString();
                            //    stationinfoRepository.Update(EmptyStation, true);
                            //    WriteDBLog.Success("创建自动取空托任务", $"任务编号:{agvtask.agv_tasknum},托盘信号:{PalletSignal},货物信号:{MaterialSignal}", "PCS");
                            //}
                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        //WriteDBLog.Error("创建自动取空托任务", $"{stationCode}:{remark}错误信息:{ex.Message}", "PCS");
                        WriteLog.Write_Log("报错日志", "创建自动取空托任务", "错误信息!", $"{stationCode}:{remark}错误信息:{ex.Message}");
                        WriteLog.Write_Log("报错日志", "创建自动取空托队列任务", "错误信息!", $"{stationCode}:{remark}错误信息:{ex.Message}");
                    }
                }
            }
            catch (Exception ex)
            {
                //WriteDBLog.Error("创建自动取空托任务", $"错误信息:{ex.Message}", "PCS");
                WriteLog.Write_Log("报错日志", "创建自动取空托任务", "错误信息!", $"错误信息:{ex.Message}");
                WriteLog.Write_Log("报错日志", "创建自动取空托队列任务", "错误信息!", $"错误信息:{ex.Message}");
            }
        }