lss
4 天以前 ede3b3103cc39dbfff9c93e9a08fb1a9855387e4
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接口辅助类
@@ -39,13 +39,247 @@
        public static object _lockCreateTask = new object();
        /// <summary>
        /// ç«‹åº“任务下发=》创建任务
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        internal static Result Createtask(CreateTask model)
        {
            Result result = new Result() { code = "0", msg = "创建成功" };
            if (model == null)
            {
                LogHelper.Info($"Createtask==> å‚数为null");
                result.code = "1";
                result.msg = "参数为null值,请检查参数格式";
                AddErrorInfo("下发参数为null", result.msg);
                return result;
            }
            partData partData = model.partData;
            taskData taskData = model.taskData;
            try
            {
                var db = new SqlHelper<object>().GetInstance();
                string CntrCode = "";//托盘编码
                string ItemCode = "";//物料编码
                if (partData != null)
                {
                    CntrCode = partData.rfid;//托盘编码
                    ItemCode = partData.partNumber;//物料编码
                }
                string Start = ""; //取货点
                string End = "";
                string note = ""; //立库下发任务需要通知mes接口物料到位,用备注自动进行区分
                                  //根据物料获取对应库区
                #region æ ¹æ®ä»»åŠ¡æ¥æºå­—æ®µåˆ¤æ–­åº“åŒºæ¥æºæ¥æº
                //var iteminfo = db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE.Trim() == ItemCode).First();
                //if (iteminfo != null)
                //{
                //    //LogHelper.Info($"Createtask==>物料数据:{JsonConvert.SerializeObject(iteminfo)}");
                //    areacode = iteminfo.S_WH_CODE;
                //}
                //if (string.IsNullOrEmpty(areacode))
                //{
                //    LogHelper.Info($"Createtask==>根据物料编码:{ItemCode}未能找到物料来源,需同步物料数据");
                //    result.code = "1";
                //    result.msg = $"根据物料编码:{ItemCode}未能找到物料来源,需同步物料数据";
                //    AddErrorInfo("寻找出库区失败", result.msg);
                //    return result;
                //}
                string state = "等待";
                int n_type = 0;  //任务来源 1.密炼立库  3.预备库 ,4.原材料库
                string Source = "";
                switch (taskData.source)
                {
                    case "ML":
                        n_type = 1;
                        Source = "密炼";
                        break;
                    case "YBK":
                        n_type = 2;
                        Source = "预备库";
                        state = "等待推送";
                        break;
                }
                Console.WriteLine($"Createtask==>任务来源:{n_type}");
                if (n_type == 0)
                {
                    result.code = "1";
                    result.msg = $"任务来源:{taskData.source}属于未定义库区,请检查物料来源是否属于约定字段";
                    AddErrorInfo("任务来源未定义", result.msg);
                    return result;
                }
                #endregion
                Location endloc = null;
                Location startloc = null;
                lock (_lockCreateTask)
                {
                    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;
                    }
                    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 = $"任务创建失败";
                            AddErrorInfo("任务创建失败", result.msg, Source);
                            return result;
                        }
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = "创建任务失败,未找到对应的取货点或卸货点";
                        return result;
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                result.code = "1";
                result.msg = ex.ToString();
                LogHelper.Error("Createtask Error:" + ex.ToString() + "行号:" + ex.StackTrace, ex);
                return result;
            }
        }
        /// <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();
        /// <summary>
@@ -55,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)
@@ -108,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)
                    {
@@ -217,7 +451,7 @@
            }
        }
        /// <summary>
        /// è´§ä½ä¿¡æ¯ä¸Šä¼ 
        /// </summary>
@@ -243,7 +477,7 @@
                    result1.UseToken = "iFQ5fExGrLYLXliHYWzs";
                    upload.LocationNum = loc.S_CODE;
                    upload.Type = loc.S_TYPE;
                    upload.LockState =loc.S_LOCK_STATE;
                    upload.LockState = loc.S_LOCK_STATE;
                    upload.WorkCenter = loc.S_AREA_CODE;
                    upload.Warehouse = loc.S_AREA_CODE;
                    listuploadloc.Add(upload);
@@ -263,7 +497,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")
@@ -276,7 +510,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
@@ -298,8 +532,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)
@@ -321,7 +555,7 @@
                //    deviceInfos.Add(new DeviceInfos() { AgvNo = agv.agvNo, AgvInfo = agvErrorInfo });
                //}
            }
          //  device.DeviceInfos = deviceInfos;
            //  device.DeviceInfos = deviceInfos;
            return device;
        }
@@ -394,7 +628,23 @@
        #endregion
        #region åˆè‚¥ä½³é€šä¸šåŠ¡æ–¹æ³•
        /// <summary>
        /// ç«‹åº“任务下发创建托盘物料绑定关系
        /// </summary>
        internal static bool CreateCntrIteminfo(partData partData, taskData taskData)
        {
            if (partData == null && taskData == null)
            {
                LogHelper.Info($"CreateCntrIteminfo==> ç«‹åº“任务下发参数有空,创建物料托盘绑定关系失败");
                return false;
            }
            else
            {
                return ContainerHelper.CreateCntrItem(taskData.pickStation, partData.rfid, partData.partNumber, partData.partDesc, partData.partType, taskData.carrierType, partData.lotNumber, taskData.wmsLot, partData.weight, partData.unit,
                    taskData.tyreType, taskData.supplier, taskData.receiveLot, taskData.subpool, partData.productionTime, partData.maturityTime, taskData.level, partData.qty, partData.qtyCfg);
            }
        }
        /// <summary>
        /// æ‰˜ç›˜å…¥åº“算法 
@@ -527,7 +777,7 @@
            return result;
        }
        //internal static bool CreateCntrLoc(taskData taskData)
        //{