lss
3 天以前 f3c8f980269b7f8fd9556c9076e06ca1461796e8
HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -47,6 +47,7 @@
        /// <returns></returns>
        internal static Result Createtask(CreateTask model)
        {
            Result result = new Result() { code = "0", msg = "创建成功" };
            if (model == null)
            {
@@ -187,7 +188,7 @@
                                }
                            }
                        }
                        else
                        {
@@ -582,6 +583,15 @@
                                AddErrorInfo("库区查找失败", result.msg);
                                return result;
                            }
                            int pri = 1;
                            var area = Settings.wareLoc.Where(a => a.AreaCode == endloc.S_WH_CODE).First();
                            if (area != null)
                            {
                                if (area.XbAreaCodes.Contains(endloc.S_AREA_CODE))
                                {
                                    pri = 2;
                                }
                            }
                            //创建wcs任务
                            var wcsTask = new WCSTask
                            {
@@ -596,7 +606,7 @@
                                S_END_AREA = endloc.S_AREA_CODE,
                                N_SCHEDULE_TYPE = 1,
                                S_CNTR_CODE = CntrCode,
                                N_PRIORITY = taskData.priority,
                                N_PRIORITY = pri,
                                Z_TYPE = n_type,
                                N_START_LAYER = 1,
                                N_END_LAYER = 1,
@@ -787,6 +797,182 @@
        }
        public static object _Point = new object();
        /// <summary>
        /// 入平库
        /// </summary>
        /// <param name="model"></param>
        /// <param name="n_type">0:pda下发任务,5:mes下发任务</param>
        /// <returns></returns>
        internal static Result Point(PointModel model)
        {
            Result result = new Result() { code = "200", msg = "入平库任务下发成功" };
            string Source = "Mes";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
            var db = new SqlHelper<object>().GetInstance();
            Location loc = null;
            string Start = model.InitialLocation;  //起点货位
            string itemcode = model.PartNumber;    //物料编码
            string areacode = "";
            try
            {
                lock (_Putin)
                {
                    #region 入库检查托盘物料表有无数据
                    var cntritem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
                    if (cntritem == null)
                    {
                        result.code = "1";
                        result.msg = $"创建任务失败,托盘:{model.Rfid}无绑定物料数据";
                        LogHelper.Info($"ItemBack:{result.msg}");
                        AddErrorInfo("托盘绑定物料数据为空", result.msg, Source);
                        return result;
                    }
                    #endregion
                    #region 判断托盘绑定货位是否和下发绑定起点相同,如果没绑定托盘则绑定托盘
                    var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
                    if (CntrLoc != null)
                    {
                        if (CntrLoc.S_LOC_CODE != Start)
                        {
                            result.code = "1";
                            result.msg = $"创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}";
                            LogHelper.Info($"ItemBack:{result.msg}");
                            AddErrorInfo("托盘绑定位置不同", result.msg, Source);
                            return result;
                        }
                    }
                    else
                    {
                        LocationHelper.BindingLoc(Start, new List<string> { model.Rfid });
                    }
                    #endregion
                    #region 根据起点货位的仓库编码 获取平库编码,并计算入库货位
                    string End = "";
                    var startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == Start).First();
                    if (startloc != null)
                    {
                        //根据仓库 计算库区
                        var whcode = Settings.wareLoc.Where(a => a.AreaCode == startloc.S_WH_CODE).FirstOrDefault();
                        if (whcode != null)
                        {
                            areacode = whcode.PMK;
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"根据起点仓库编码:{startloc.S_WH_CODE}未找到对应配置文件";
                            LogHelper.Info($"Putin==> {result.msg}");
                            AddErrorInfo("查找库区失败", result.msg, Source);
                            return result;
                        }
                        loc = StorageCompute(itemcode, areacode);
                        if (loc != null)
                        {
                            End = loc.S_CODE;
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"库区:{areacode}无可用货位";
                            LogHelper.Info($"Putin==> {result.msg}");
                            AddErrorInfo("查找库区失败", result.msg, Source);
                            return result;
                        }
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = $"任务起点:{Start}找不到对应货位,请检查货位表";
                        LogHelper.Info($"Putin==> {result.msg}");
                        AddErrorInfo("查找货位失败", result.msg, Source);
                        return result;
                    }
                    #endregion
                    #region 创建任务
                    if (!string.IsNullOrEmpty(Start) && !string.IsNullOrEmpty(End))
                    {
                        if (startloc.N_LOCK_STATE != 0)
                        {
                            result.code = "1";
                            result.msg = $"创建任务失败,起点:{Start}有锁";
                            AddErrorInfo("货位有锁", result.msg, Source);
                            return result;
                        }
                        //创建wcs任务
                        var wcsTask = new WCSTask
                        {
                            S_CODE = WCSHelper.GenerateTaskNo(),
                            S_TYPE = "入平库",
                            S_EQ_NO = model.TaskNumber,
                            S_START_LOC = Start,
                            S_END_LOC = End,
                            S_START_WH = startloc.S_WH_CODE,
                            S_START_AREA = startloc.S_AREA_CODE,
                            S_END_WH = loc.S_WH_CODE,
                            S_END_AREA = loc.S_AREA_CODE,
                            N_CNTR_COUNT = 1,
                            N_SCHEDULE_TYPE = 1,
                            S_CNTR_CODE = model.Rfid,
                            N_START_LAYER = 1,
                            N_END_LAYER = 1,
                            N_PRIORITY = 1,
                            Z_TYPE = n_type
                        };
                        LogHelper.Info("创建入平库任务:" + JsonConvert.SerializeObject(wcsTask));
                        if (WCSHelper.CreateTask(wcsTask))
                        {
                            //LocationHelper.LockLoc(Start, 2);
                            //LocationHelper.LockLoc(End, 1);
                            LogHelper.Info("创建任务成功");
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"任务创建失败";
                            AddErrorInfo("任务创建失败", result.msg, Source);
                            return result;
                        }
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = "创建任务失败,未找到对应的取货点或卸货点";
                        return result;
                    }
                    #endregion
                }
                return result;
            }
            catch (Exception ex)
            {
                result.code = "1";
                result.msg = ex.ToString();
                LogHelper.Error("Putin Error:" + ex.ToString(), ex);
                return result;
            }
        }
        public static object _Putin = new object();
        /// <summary>
        /// 入平库
@@ -954,6 +1140,7 @@
                            S_CNTR_CODE = model.Rfid,
                            N_START_LAYER = 1,
                            N_END_LAYER = 1,
                            N_PRIORITY = 1,
                            Z_TYPE = n_type
                        };
                        LogHelper.Info("创建入平库任务:" + JsonConvert.SerializeObject(wcsTask));
@@ -1082,27 +1269,51 @@
                    #region 根据物料编码计算出库货位,送往线边位置
                    Location Endloc = null;
                    //根据物料编码计算出库货位
                    var loc = airlift(areacode, itemcode, model.PartLevel, model.PowderType);
                    if (loc != null)
                    {
                        Start = loc.S_CODE;
                        //根据出库货位找到绑定托盘,获取入机台货位
                        var CntrRel = LocationHelper.GetLocCntrRel(loc.S_CODE).FirstOrDefault();
                        CntrCode = CntrRel.S_CNTR_CODE;
                        Endloc = Computeloc(CntrCode, model.WorkCenter, cntrType);
                        if (Endloc != null)
                        //给终点用终点,没给终点用机台库区计算货位
                        if (string.IsNullOrEmpty(model.TargetLocation))
                        {
                            End = Endloc.S_CODE;
                            Endloc = Computeloc(CntrCode, model.WorkCenter, cntrType);
                            if (Endloc != null)
                            {
                                End = Endloc.S_CODE;
                            }
                            else
                            {
                                result.code = "1";
                                result.msg = $"Computeloc==》根据机台编码:{model.WorkCenter},工装类型:{cntrType} 未找到空货位数据,请检查货位表";
                                LogHelper.Info($"ItemBack:{result.msg}");
                                AddErrorInfo("查找库区失败", result.msg, Source);
                                return result;
                            }
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"Computeloc==》根据机台编码:{model.WorkCenter},工装类型:{cntrType} 未找到空货位数据,请检查货位表";
                            LogHelper.Info($"ItemBack:{result.msg}");
                            AddErrorInfo("查找库区失败", result.msg, Source);
                            return result;
                            Endloc = db.Queryable<Location>().Where(a => a.S_CODE == model.TargetLocation).First();
                            if (Endloc != null)
                            {
                                End = Endloc.S_CODE;
                            }
                            else
                            {
                                result.code = "1";
                                result.msg = $"Computeloc==》根据终点货位:{model.TargetLocation} 未找到货位数据,请检查货位表";
                                LogHelper.Info($"ItemBack:{result.msg}");
                                AddErrorInfo("查找库区失败", result.msg, Source);
                                return result;
                            }
                        }
                    }
                    else
                    {
@@ -1152,6 +1363,7 @@
                        S_CNTR_CODE = CntrCode,
                        N_START_LAYER = 1,
                        N_END_LAYER = 1,
                        N_PRIORITY = 1,
                        Z_TYPE = n_type
                    };
@@ -1411,6 +1623,8 @@
                            S_CNTR_CODE = model.Rfid,
                            N_START_LAYER = 1,
                            N_END_LAYER = endlayer,
                            N_PRIORITY = 1,
                            S_B_STATE = "等待推送",
                            Z_TYPE = 5
                        };
                        LogHelper.Info("创建空托回库任务:" + JsonConvert.SerializeObject(wcsTask));
@@ -1590,6 +1804,7 @@
                            N_START_LAYER = 1,
                            N_END_LAYER = 1,
                            Z_TYPE = 5,
                            N_PRIORITY = 1,
                            S_NOTE = "粉料"
                        };
                        LogHelper.Info("创建呼叫空托任务:" + JsonConvert.SerializeObject(wcsTask));
@@ -1814,6 +2029,7 @@
                            S_CNTR_CODE = model.Rfid,
                            N_START_LAYER = 1,
                            N_END_LAYER = 1,
                            N_PRIORITY = 1,
                            Z_TYPE = 5
                        };
@@ -2065,6 +2281,7 @@
                        S_CNTR_CODE = CntrCode,
                        N_START_LAYER = 1,
                        N_END_LAYER = 1,
                        N_PRIORITY = 1,
                        //  N_TYPE = n_type
@@ -2201,6 +2418,7 @@
                        S_CNTR_CODE = cntr.S_CNTR_CODE,
                        N_END_LAYER = 1,
                        Z_TYPE = 6,
                        N_PRIORITY = 1,
                        S_B_STATE = "电梯推送"
                    };
@@ -2471,10 +2689,9 @@
                    var location = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First();
                    if (location != null)
                    {
                        var loccntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc).ToList();
                        var loccntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc.Trim()).ToList();
                        if (loccntr.Count > 0)
                        {
                            var cntrcodes = loccntr.Select(a => a.S_CNTR_CODE.Trim()).ToList();
                            if (LocationHelper.Clear(loc, cntrcodes))
                            {
@@ -2545,12 +2762,12 @@
            if (agvDeviceInfo.Count > 0)
            {
                device.AgvQty = agvDeviceInfo.Count;
                device.AgvErrorQty = agvDeviceInfo.FindAll(a => a.agvErrCode != "0" || a.agvErrCode != "0" || a.faildCode != "0").Count;
                device.AgvChargeQty = agvDeviceInfo.FindAll(a => a.agvErrCode == "1").Count;
                device.AgvRunQty = agvDeviceInfo.FindAll(a => a.agvErrCode == "1").Count;
                device.AgvErrorQty = agvDeviceInfo.FindAll(a => a.agvErrCode != "0" || int.Parse(a.errCode2) > 1 || int.Parse(a.faildCode) > 1).Count;
                device.AgvChargeQty = agvDeviceInfo.FindAll(a => a.errCode2 == "1").Count;
                device.AgvRunQty = agvDeviceInfo.FindAll(a => a.agvErrCode == "0"&& a.errCode2 == "0" && a.faildCode == "1").Count;
                foreach (var agv in agvDeviceInfo)
                {
                    string agvErrorInfo = GetAgvAlarmSendCodeTwo(agv.agvErrCode, agv.errCode2, agv.faildCode);
                    string agvErrorInfo = GetAgvAlarmSendCodeTwo(agv.agvNo, agv.agvErrCode, agv.errCode2, agv.faildCode);
                    deviceInfos.Add(new DeviceInfos() { AgvNo = agv.agvNo, AgvInfo = agvErrorInfo });
                }
            }
@@ -2562,56 +2779,65 @@
        /// <summary>
        /// agv小车故障码处理
        /// </summary>
        ///<param name="agvNo">车号</param>
        /// <param name="errCode1">错误码1</param>
        /// <param name="errCode2">错误码2</param>
        /// <param name="faildCode">错误码3</param>
        /// <returns></returns>
        private static string GetAgvAlarmSendCodeTwo(string errCode1, string errCode2, string faildCode)
        private static string GetAgvAlarmSendCodeTwo(string agvNo, string errCode1, string errCode2, string faildCode)
        {
            string result = "";
            //将报警信息整合
            string binSW1 = Convert.ToString(int.Parse(errCode1), 2).PadLeft(22, '0');
            string binSW1 = Convert.ToString(int.Parse(errCode1), 2).PadLeft(25, '0');
            string binSW2 = Convert.ToString(int.Parse(errCode1), 2).PadLeft(20, '0');
            string binFc = Convert.ToString(int.Parse(errCode1), 2).PadLeft(16, '0');
            var arr1 = binSW1.ToArray();
            var arr2 = binSW2.ToArray();
            var arr3 = binFc.ToArray();
            for (int i = 0; i <= arr1.Length; i++)
            var AgvError = Settings.agvError.Where(a => a.agvNo.Contains(agvNo)).FirstOrDefault();
            if (AgvError != null)
            {
                if (arr1[i] == '1')
                for (int i = 0; i <= arr1.Length; i++)
                {
                    var ErrorInfo = Settings.agvErrorCode1.Where(a => a.ErrorCode == i).FirstOrDefault();
                    if (ErrorInfo != null)
                    if (arr1[i] == '1')
                    {
                        result = result + "," + $"{ErrorInfo.ErrorInfo}";
                    }
                        var ErrorInfo = AgvError.AgvErrorCode1.Find(a => a.ErrorCode == i);
                        if (ErrorInfo != null)
                        {
                            result = result + "," + $"{ErrorInfo.ErrorInfo}";
                        }
                    }
                }
                for (int i = 0; i <= arr2.Length; i++)
                {
                    if (arr1[i] == '1')
                    {
                        var ErrorInfo = AgvError.AgvErrorCode2.Find(a => a.ErrorCode == i);
                        if (ErrorInfo != null)
                        {
                            result = result + "," + $"{ErrorInfo.ErrorInfo}";
                        }
                    }
                }
                for (int i = 0; i <= arr3.Length; i++)
                {
                    if (arr1[i] == '1')
                    {
                        var ErrorInfo = AgvError.AgvFaildCode.Find(a => a.ErrorCode == i);
                        if (ErrorInfo != null)
                        {
                            result = result + "," + $"{ErrorInfo.ErrorInfo}";
                        }
                    }
                }
            }
            for (int i = 0; i <= arr2.Length; i++)
            else
            {
                if (arr1[i] == '1')
                {
                    var ErrorInfo = Settings.agvErrorCode2.Where(a => a.ErrorCode == i).FirstOrDefault();
                    if (ErrorInfo != null)
                    {
                        result = result + "," + $"{ErrorInfo.ErrorInfo}";
                    }
                }
            }
            for (int i = 0; i <= arr3.Length; i++)
            {
                if (arr1[i] == '1')
                {
                    var ErrorInfo = Settings.agvFaildCode.Where(a => a.ErrorCode == i).FirstOrDefault();
                    if (ErrorInfo != null)
                    {
                        result = result + "," + $"{ErrorInfo.ErrorInfo}";
                    }
                }
            }
            return result;
        }
@@ -2660,7 +2886,8 @@
        /// <param name="level">物料等级</param>
        /// <param name="powderType">机型</param>
        /// <returns></returns>
        internal static Location airlift(string areacode, string itemcode, string level, string powderType)
        internal static Location
            airlift(string areacode, string itemcode, string level, string powderType)
        {
            var db = new SqlHelper<object>().GetInstance();
            Location result = null;
@@ -2800,13 +3027,17 @@
            lock (_lockLocation)
            {
                var loc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无").First();
                if (loc != null)
                if (string.IsNullOrEmpty(cntrType))
                {
                    End = loc;
                    End = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无").First();
                }
                else
                {
                    End = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无").First();
                }
                if (End == null)
                {
                    LogHelper.Info($"Computeloc==》根据机台分组:{jtcode},工装类型:{cntrType} 未找到空货位数据,请检查货位表");
                }