分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-03-05 db6156a92cc59467bde608a00c76952ebc75e488
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs
@@ -15,6 +15,7 @@
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Extensions;
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Jobs;
using WIDESEA_WCS.Repositories;
@@ -85,7 +86,7 @@
                ///查找上料区的货位
                var Stations = stationinfoRepository.Find(x => x.area == "6");
                var Stations = stationinfoRepository.Find(x => x.area == area_code(number));
                //缓存架未启用禁止桁架进入
                foreach (var station in Stations)
                {
@@ -93,12 +94,18 @@
                        Gantry_client.WriteByOrder("W_RequestUnload", false, number);//信号为false桁架停止进入
                }
                var Station = Stations?.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.quantity).First();
                var Station = Stations?.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.quantity).FirstOrDefault();
                if (Station != null)
                {
                    var SNS = Station.bindSN.Split(",");
                    List<string> list = new List<string>();
                    foreach (var SN in SNS)
                    {
                        if (!string.IsNullOrEmpty(SN))
                            list.Add(SN);
                    }
                    //缓存架上车轮数量与SN号数量不一致
                    if (SNS.Length != Station.quantity)
                    if (list.Count != Station.quantity)
                    {
                        Station.location_state = LocationStateEnum.Abnormal.ToString();
                        stationinfoRepository.Update(Station, true);
@@ -114,7 +121,7 @@
                        Gantry_client.WriteByOrder("W_AreaNr", (Int16)area, number);//区域货位号
                        Gantry_client.WriteByOrder("W_IndexNr", (Int16)SNS.Length, number);//托盘上的第几个车轮
                        Gantry_client.WriteByOrder("W_Storage_Type", (Int16)1, number); //托盘类型1-横放;2-竖放
                        Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(Station.stationType), number);//车轮类型
                        Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(QueryMateriel(Station.stationType)), number);//车轮类型
                        Gantry_client.WriteByOrder("W_Wheel_id", SNS[SNS.Length - 1], number);//车轮SN号
                        Gantry_client.WriteByOrder("W_RequestUnload", true, number);
                    }
@@ -139,22 +146,47 @@
                        }
                    }
                    var finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);//夹取完成
                    if (finished)
                    var updatefinished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "W_Storage_update").First(), Gantry_client);//货位状态更新
                    if (!finished && updatefinished)
                        Gantry_client.WriteByOrder("W_Storage_update", false, number);//货位状态更新
                    if (finished && !updatefinished)
                    {
                        Station.quantity = Station.quantity - 1;
                        Station.bindSN = OperStr(SNS);
                        if (Station.quantity <= 0)
                        {
                            Station.stationType = string.Empty;
                            //Station.location_state = LocationStateEnum.Empty.ToString();
                            Station.Number = string.Empty;
                            Station.heatNumber = string.Empty;
                        }
                        var count = stationinfoRepository.Update(Station, true);
                        if (count < 1)
                            throw new Exception($"上料位信息更新失败!上料位编号:{Station.stationCode}");
                        Gantry_client.WriteByOrder("W_Storage_update", true, number);//货位状态更新
                        Gantry_client.WriteByOrder("W_RequestUnload", false, number);//信号为false桁架停止进入
                        //finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);
                        //while (finished)
                        //{
                        //    finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);
                        //    Gantry_client.WriteByOrder("W_Storage_update", false, number);//货位状态更新
                        //}
                    }
                    //else if (!finished && updatefinished)
                    //    Gantry_client.WriteByOrder("W_Storage_update", false, number);//货位状态更新
                }
            }
            catch (Exception ex)
            {
                //WritePCSLog.LogAdd(requestin.AreaNr.ToString(), respone.success == 1 ? "成功 " : "失败", "WMS", "AGV", json, JsonConvert.SerializeObject(respone), remark, "检测线上料区", ex.Message);
            }
        }
        public static string area_code(string area_name)
        {
            FreeDB freeDB = new FreeDB();
            var areainfo = freeDB.Select<dt_areainfo>().Where(x => x.area_name == area_name).First();
            return areainfo.area_code.ToString();
        }
        private string OperStr(string[] strArrty)
@@ -164,5 +196,19 @@
            return Newsn;
        }
        private int QueryMateriel(string type)
        {
            VOLContext Context = new VOLContext();
            Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
            var materielinfo = dataRepository.FindFirst(x => x.Description == type);
            return materielinfo.TypeId;
        }
        public static string QueryMateriel(int  typeId)
        {
            VOLContext Context = new VOLContext();
            Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
            var materielinfo = dataRepository.FindFirst(x => x.TypeId == typeId);
            return materielinfo.Description;
        }
    }
}