lss
9 小时以前 1319cb7072623dff12369a889af766db2d166def
HH.WCS.Mobox3 - ´ó³µ¼ä/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -1,9 +1,9 @@
using HH.WCS.JiaTong.device;
using HH.WCS.JiaTong.dispatch;
using HH.WCS.JiaTong.LISTA.models;
using HH.WCS.JiaTong.process;
using HH.WCS.JiaTong.util;
using HH.WCS.JiaTong.wms;
using HH.WCS.JiaTong_DCJ.device;
using HH.WCS.JiaTong_DCJ.dispatch;
using HH.WCS.JiaTong_DCJ.LISTA.models;
using HH.WCS.JiaTong_DCJ.process;
using HH.WCS.JiaTong_DCJ.util;
using HH.WCS.JiaTong_DCJ.wms;
using Newtonsoft.Json;
using NLog.Fluent;
using S7.Net;
@@ -17,12 +17,12 @@
using System.Threading;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using static HH.WCS.JiaTong.api.ApiModel;
using static HH.WCS.JiaTong.api.OtherModel;
using static HH.WCS.JiaTong.LISTA.process.HttpModel;
using static HH.WCS.JiaTong.util.Settings;
using static HH.WCS.JiaTong_DCJ.api.ApiModel;
using static HH.WCS.JiaTong_DCJ.api.OtherModel;
using static HH.WCS.JiaTong_DCJ.LISTA.process.HttpModel;
using static HH.WCS.JiaTong_DCJ.util.Settings;
namespace HH.WCS.JiaTong.api
namespace HH.WCS.JiaTong_DCJ.api
{
    /// <summary>
    /// api接口辅助类
@@ -92,7 +92,7 @@
                //    AddErrorInfo("寻找出库区失败", result.msg);
                //    return result;
                //}
                string state = "等待";
                int n_type = 0;  //任务来源 1.密炼立库  3.预备库 ,4.原材料库
                string Source = "";
                switch (taskData.source)
@@ -104,8 +104,9 @@
                    case "YBK":
                        n_type = 2;
                        Source = "预备库";
                        state = "等待推送";
                        break;
                }
                Console.WriteLine($"Createtask==>任务来源:{n_type}");
                if (n_type == 0)
@@ -123,222 +124,101 @@
                Location startloc = null;
                lock (_lockCreateTask)
                {
                    if (taskData.taskType == 1) //出库流程,通过物料机台计算线边货位
                    note = "出库";
                    //创建托盘物料绑定信息,并计算终点货位
                    startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                    if (startloc != null)
                    {
                        note = "出库";
                        startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                        if (startloc != null)
                        {
                            //创建托盘物料绑定信息,并计算终点货位
                            Start = taskData.pickStation;
                            if (CreateCntrIteminfo(partData, taskData))
                            {
                                endloc = Computeloc(CntrCode, taskData.dropStation, taskData.carrierType);
                                if (endloc != null)
                                {
                                    End = endloc.S_CODE;
                                }
                                else
                                {
                                    result.code = "1";
                                    result.msg = $"机台编码:{taskData.dropStation},未找到可用货位";
                                    AddErrorInfo("寻找出库货位失败", result.msg, Source);
                                    return result;
                                }
                                //endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
                                //if (endloc != null)
                                //{
                                //    End = taskData.dropStation;
                                //}
                                //else
                                //{
                                //    result.code = "1";
                                //    result.msg = $"根据终点{End},找不到对应货位,请检查货位表";
                                //    AddErrorInfo("货位查找失败", result.msg, Source);
                                //    return result;
                                //}
                            }
                            else
                            {
                                result.code = "1";
                                result.msg = "创建托盘物料信息失败";
                                AddErrorInfo("创建托盘失败", result.msg, Source);
                                return result;
                            }
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"Putin==> ä»»åŠ¡èµ·ç‚¹:{taskData.pickStation}找不到对应货位,请检查货位表";
                            LogHelper.Info($"Putin==> {result.msg}");
                            AddErrorInfo("货位查找失败", result.msg, Source);
                            return result;
                        }
                        Start = taskData.pickStation;
                    }
                    else if (taskData.taskType == 2)//入库流程,直接使用起点货位和终点货位生成任务,起点需要有托盘
                    {
                        note = "入库";
                        startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                        if (startloc != null)
                        {
                            Start = startloc.S_CODE;
                            var CntrRel = LocationHelper.GetLocCntrRel(startloc.S_CODE).OrderBy(a => a.T_CREATE).FirstOrDefault();
                            if (CntrRel != null)
                            {
                                if (CntrRel.S_CNTR_CODE != partData.rfid)
                                {
                                    result.code = "1";
                                    result.msg = $"根据起点:{Start}获取托盘:{CntrRel.S_CNTR_CODE}与下发托盘:{partData.rfid}不一致,请检查托盘码是否正确";
                                    AddErrorInfo("托盘码校检失败", result.msg, Source);
                                    return result;
                                }
                                else
                                {
                                    CntrCode = CntrRel.S_CNTR_CODE;
                                }
                            }
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"根据起点{taskData.pickStation},找不到对应货位,请检查货位表";
                            AddErrorInfo("货位查找失败", result.msg, Source);
                            return result;
                        }
                        endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
                        if (endloc != null)
                        {
                            End = taskData.dropStation;
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"根据终点{End},找不到对应货位,请检查货位表";
                            AddErrorInfo("货位查找失败", result.msg, Source);
                            return result;
                        }
                    }
                    else if (taskData.taskType == 3)//移库流程,直接使用起点货位和终点货位生成任务,
                    {
                        note = "出库";
                        //创建托盘物料绑定信息,并计算终点货位
                        startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                        if (startloc != null)
                        {
                            Start = taskData.pickStation;
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"根据起点{taskData.pickStation},找不到对应货位,请检查货位表";
                            AddErrorInfo("货位查找失败", result.msg, Source);
                            return result;
                        }
                        endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
                        if (endloc != null)
                        {
                            End = taskData.dropStation;
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"根据终点{taskData.dropStation},找不到对应货位,请检查货位表";
                            AddErrorInfo("货位查找失败", result.msg, Source);
                            return result;
                        }
                    }
                    else
                    {
                        LogHelper.Info($"Createtask==> ä»»åŠ¡ç±»åž‹æœ‰è¯¯");
                        result.code = "1";
                        result.msg = "任务类型:{taskData.taskType}不在规定范围内";
                        AddErrorInfo("任务类型错误", result.msg, Source);
                        result.msg = $"根据起点{taskData.pickStation},找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                        if (!string.IsNullOrEmpty(Start) && !string.IsNullOrEmpty(End))
                        {
                            if (startloc.N_LOCK_STATE != 0)
                            {
                                result.code = "1";
                                result.msg = $"创建任务失败,起点{Start}有锁";
                                AddErrorInfo("货位有锁", result.msg);
                                return result;
                            }
                            var startArea = db.Queryable<Area>().Where(a => a.S_CODE.Trim() == startloc.S_AREA_CODE.Trim()).First();
                            var endArea = db.Queryable<Area>().Where(a => a.S_CODE.Trim() == endloc.S_AREA_CODE.Trim()).First();
                            if (startArea == null || endArea == null)
                            {
                                LogHelper.Info($"起点:{JsonConvert.SerializeObject(startArea)}");
                                LogHelper.Info($"终点:{JsonConvert.SerializeObject(endArea)}");
                                result.code = "1";
                                result.msg = $"创建任务失败,起点:{startloc.S_AREA_CODE},终点{endloc.S_AREA_CODE}未找到对应库区";
                                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
                            {
                                S_CODE = WCSHelper.GenerateTaskNo(),
                                S_TYPE = startArea.S_NAME + "->" + endArea.S_NAME,
                                S_EQ_NO = taskData.taskNum,
                                S_START_LOC = Start,
                                S_END_LOC = End,
                                N_CNTR_COUNT = 1,
                                S_START_WH = startloc.S_WH_CODE,
                                S_END_WH = endloc.S_WH_CODE,
                                S_END_AREA = endloc.S_AREA_CODE,
                                N_SCHEDULE_TYPE = 1,
                                S_CNTR_CODE = CntrCode,
                                N_PRIORITY = pri,
                                Z_TYPE = n_type,
                                N_START_LAYER = 1,
                                N_END_LAYER = 1,
                                S_WMS_NO = taskData.wmsTaskNo,
                                S_NOTE = note,
                                S_MES_NO = taskData.mesTaskNo
                    endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
                    if (endloc != null)
                    {
                        End = taskData.dropStation;
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = $"根据终点{taskData.dropStation},找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                            };
                            LogHelper.Info("创建任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
                            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;
                            }
                    if (!string.IsNullOrEmpty(Start) && !string.IsNullOrEmpty(End))
                    {
                        if (startloc.N_LOCK_STATE != 0)
                        {
                            result.code = "1";
                            result.msg = $"创建任务失败,起点{Start}有锁";
                            AddErrorInfo("货位有锁", result.msg);
                            return result;
                        }
                        var startArea = db.Queryable<Area>().Where(a => a.S_CODE.Trim() == startloc.S_AREA_CODE.Trim()).First();
                        var endArea = db.Queryable<Area>().Where(a => a.S_CODE.Trim() == endloc.S_AREA_CODE.Trim()).First();
                        if (startArea == null || endArea == null)
                        {
                            LogHelper.Info($"起点:{JsonConvert.SerializeObject(startArea)}");
                            LogHelper.Info($"终点:{JsonConvert.SerializeObject(endArea)}");
                            result.code = "1";
                            result.msg = $"创建任务失败,起点:{startloc.S_AREA_CODE},终点{endloc.S_AREA_CODE}未找到对应库区";
                            AddErrorInfo("库区查找失败", result.msg);
                            return result;
                        }
                        //创建wcs任务
                        var wcsTask = new WCSTask
                        {
                            S_CODE = WCSHelper.GenerateTaskNo(),
                            S_TYPE = startArea.S_NAME + "->" + endArea.S_NAME,
                            S_EQ_NO = taskData.taskNum,
                            S_START_LOC = Start,
                            S_END_LOC = End,
                            N_CNTR_COUNT = 1,
                            S_START_WH = startloc.S_WH_CODE,
                            S_END_WH = endloc.S_WH_CODE,
                            S_END_AREA = endloc.S_AREA_CODE,
                            N_SCHEDULE_TYPE = 1,
                            S_CNTR_CODE = CntrCode,
                            N_PRIORITY = 1,
                            Z_TYPE = n_type,
                            N_START_LAYER = 1,
                            N_END_LAYER = 1,
                            S_WMS_NO = taskData.wmsTaskNo,
                            S_NOTE = note,
                            S_B_STATE = state,
                            S_MES_NO = taskData.mesTaskNo
                        };
                        LogHelper.Info("创建任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
                        if (WCSHelper.CreateTask(wcsTask))
                        {
                            // LocationHelper.LockLoc(Start, 2);
                            //LocationHelper.LockLoc(End, 1);
                            LogHelper.Info("创建任务成功");
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = "创建任务失败,未找到对应的取货点或卸货点";
                            result.msg = $"任务创建失败";
                            AddErrorInfo("任务创建失败", result.msg, Source);
                            return result;
                        }
                }
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = "创建任务失败,未找到对应的取货点或卸货点";
                        return result;
                    }
                }
                return result;
            }
@@ -355,7 +235,50 @@
        }
        /// <summary>
        /// é¢„备库任务状态下发
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        internal static Result MstStateInquire(MstStateInquire model)
        {
            Result result = new Result() { code = "200", msg = "状态下发成功" };
            var db = new SqlHelper<object>().GetInstance();
            if (model == null)
            {
                LogHelper.Info($"MstStateInquire==> å‚数为null");
                result.code = "1";
                result.msg = "参数为null值,请检查参数格式";
                AddErrorInfo("参数为空", result.msg);
                return result;
            }
            try
            {
                //找到任务,修改任务状态
                var task = db.Queryable<WCSTask>().Where(a => a.S_EQ_NO.Trim() == model.taskNum).First();
                if (task != null)
                {
                    task.S_B_STATE ="等待";
                    db.Updateable(task).UpdateColumns(a => new { a.S_B_STATE}).ExecuteCommand();
                }
                else
                {
                    result.code = "1";
                    result.msg = $"根据下发任务号{model.taskNum}未找到对应任务";
                    AddErrorInfo("未找到任务", result.msg);
                    return result;
                }
                return result;
            }
            catch (Exception ex)
            {
                result.code = "1";
                result.msg = ex.ToString();
                LogHelper.Error("TrayItembind Error:" + ex.ToString(), ex);
                return result;
            }
        }
        public static object _Point = new object();
@@ -366,7 +289,7 @@
        /// <returns></returns>
        internal static Result Point(PointModel model)
        {
            Result result = new Result() { code = "200", msg = "入平库任务下发成功" };
            Result result = new Result() { code = "200", msg = "任务下发成功" };
            string Source = "Mes";
            if (model == null)
@@ -419,25 +342,25 @@
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                    else
                    {
                        //判断起点是否绑定其他托盘
                        var CntrRel = LocationHelper.GetLocCntrRel(startloc.S_CODE).OrderBy(a => a.T_CREATE).FirstOrDefault();
                        if (CntrRel != null)
                        {
                            if (CntrRel.S_CNTR_CODE != model.Rfid)
                            {
                                result.code = "1";
                                result.msg = $"根据起点:{model.InitialLocation}获取托盘:{CntrRel.S_CNTR_CODE}与下发托盘:{model.Rfid}不一致,请检查托盘码是否正确";
                                AddErrorInfo("托盘码校检失败", result.msg, Source);
                                return result;
                            }
                        }
                        else
                        {
                            LocationHelper.BindingLoc(startloc.S_CODE, new List<string> { model.Rfid });
                        }
                    }
                    //else
                    //{
                    //    //判断起点是否绑定其他托盘
                    //    var CntrRel = LocationHelper.GetLocCntrRel(startloc.S_CODE).OrderBy(a => a.T_CREATE).FirstOrDefault();
                    //    if (CntrRel != null)
                    //    {
                    //        if (CntrRel.S_CNTR_CODE != model.Rfid)
                    //        {
                    //            result.code = "1";
                    //            result.msg = $"根据起点:{model.InitialLocation}获取托盘:{CntrRel.S_CNTR_CODE}与下发托盘:{model.Rfid}不一致,请检查托盘码是否正确";
                    //            AddErrorInfo("托盘码校检失败", result.msg, Source);
                    //            return result;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        LocationHelper.BindingLoc(startloc.S_CODE, new List<string> { model.Rfid });
                    //    }
                    //}
                    endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.TargetLocation).First();
                    if (endloc == null)
                    {
@@ -528,7 +451,7 @@
            }
        }
        /// <summary>
        /// è´§ä½ä¿¡æ¯ä¸Šä¼ 
        /// </summary>
@@ -542,21 +465,22 @@
            RequestList<UploadLoc> result1 = new RequestList<UploadLoc>();
            List<UploadLoc> listuploadloc = new List<UploadLoc>();
            var db = new SqlHelper<object>().GetInstance();
            //获取时间戳
            var time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
            result1.RequestId = "杭叉AGV" + time;
            result1.UseToken = "iFQ5fExGrLYLXliHYWzs";
            foreach (var item in model)
            {
                var loc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == item.Location).First();
                if (loc != null)
                {
                    UploadLoc upload = new UploadLoc();
                    //获取时间戳
                    var time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
                    result1.RequestId = "杭叉AGV" + time;
                    result1.UseToken = "iFQ5fExGrLYLXliHYWzs";
                    upload.LocationNum = loc.S_CODE;
                    upload.Type = loc.S_TYPE;
                    upload.LockState =loc.S_LOCK_STATE;
                    upload.WorkCenter = loc.S_AREA_CODE;
                    upload.Warehouse = loc.S_AREA_CODE;
                    upload.locationNum = loc.S_CODE;
                    upload.type = loc.S_TYPE;
                    upload.lockState = loc.S_LOCK_STATE;
                    upload.workCenter = loc.S_AREA_CODE;
                    upload.warehouse = loc.S_AREA_CODE;
                    listuploadloc.Add(upload);
                }
                else
@@ -574,7 +498,7 @@
            var url = Settings.tableUrls.Find(a => a.id == 3);
            if (url != null)
            {
                LogHelper.Info($"货位上报上报:地址:{url},内容:{date}");
                LogHelper.Info($"货位上报上报:地址:{url.url},内容:{date}");
                var r = httpHelper.MesWebPost(url.url, date);
                result = JsonConvert.DeserializeObject<Result>(r);
                if (result.code == "200")
@@ -587,7 +511,7 @@
                    result.code = "1";
                    result.msg = result.msg;
                }
                ApiHelper.AddInfo("Mes", "Mes点对点任务下发", JsonConvert.SerializeObject(date), JsonConvert.SerializeObject(result), "Post", url.url);
                ApiHelper.AddInfo("Mes", "货位同步", JsonConvert.SerializeObject(date), JsonConvert.SerializeObject(result), "Post", url.url);
            }
            else
@@ -609,8 +533,8 @@
            var db = new SqlHelper<HangChaAGV>().GetInstance();
            DeviceInfoModel device = new DeviceInfoModel();
           // List<DeviceInfos> deviceInfos = new List<DeviceInfos>();//叠盘机报错信息
                                                                    // List<AgvInfos> agvInfos = new List<AgvInfos>();//agv报错信息
            // List<DeviceInfos> deviceInfos = new List<DeviceInfos>();//叠盘机报错信息
            // List<AgvInfos> agvInfos = new List<AgvInfos>();//agv报错信息
            //获取内存中叠盘机的报错信息
            //foreach (var dpjInfo in DeviceProcess.DpjInfoDirectory)
@@ -632,7 +556,7 @@
                //    deviceInfos.Add(new DeviceInfos() { AgvNo = agv.agvNo, AgvInfo = agvErrorInfo });
                //}
            }
          //  device.DeviceInfos = deviceInfos;
            //  device.DeviceInfos = deviceInfos;
            return device;
        }
@@ -854,7 +778,7 @@
            return result;
        }
        //internal static bool CreateCntrLoc(taskData taskData)
        //{