1
czw
2025-07-02 3492292c4f006945781714b731303a12b0f1dd3a
2025Äê6ÔÂ12ÈÕ/AuxAllWCS/Build/Project/´úÂë/×Ô¶¨ÒåÀà.cs
@@ -28,6 +28,8 @@
using GZ.DB.Repository.OIDATABASE;
using GZ.DB.IRepository.OIDATABASE;
using GZ.DB.Entity.OIDATABASE;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using NLog.Fluent;
namespace GZ.Projects.AuxAllWCS
{
    public class Settings
@@ -170,11 +172,11 @@
            // æ·»åŠ target-console
            var consoleTarget = new ColoredConsoleTarget();
            consoleTarget.Layout = @"${longdate} | ${level:uppercase=false:padding=-5} | ${message} ${onexception:${exception:format=tostring} ${newline} ${stacktrace} ${newline}";
            //var consoleTarget = new ColoredConsoleTarget();
            //consoleTarget.Layout = @"${longdate} | ${level:uppercase=false:padding=-5} | ${message} ${onexception:${exception:format=tostring} ${newline} ${stacktrace} ${newline}";
            config.AddTarget("console", consoleTarget);
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleTarget);
            //config.AddTarget("console", consoleTarget);
            //config.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleTarget);
            //添加target-info
            var infoFileTarget = new FileTarget();
@@ -563,7 +565,7 @@
        internal static bool CreateTask(string no, string from, string to, string taskType, int pri, List<string> cntrs, string workMode = "AGV", int cntrCount = 1, int startLayer = 1, int endLayer = 1)
        {
            LogHelper.Info($"输送线RGV空托任务 from:{from}>to {to}开始创建>");
            LogHelper.Info($"创建任务 from:{from}>to {to}开始创建>");
            var cntrInfo = string.Join(",", cntrs);
            ILocRepository locc = new LocRepository();
            var fromLoc = locc.FindEntity(x => x.S_LOC_CODE == from);
@@ -571,10 +573,14 @@
            var s = Settings.deviceInfos.Find(x => x.location.Contains(from)) != null;
            var e = Settings.deviceInfos.Find(x => x.location.Contains(to)) != null;
            string t = "F01";
            if (s && !e) t = "A002";
            if (!s && e) t = "A003";
            if (s && e) t = "A004";
            string t = "";
            if (workMode == "AGV")
            {
                t = "F01";
                if (s && !e) t = "A002";
                if (!s && e) t = "A003";
                if (s && e) t = "A004";
            }
            try
            {
@@ -613,7 +619,7 @@
                    locc.Update(endLoc);
                }
                LogHelper.Info($"输送线RGV空托任务 from:{from}>to {to} åˆ›å»º{wmsTask.S_TASK_NO}成功");
                LogHelper.Info($"创建任务 from:{from}>to {to} åˆ›å»º{wmsTask.S_TASK_NO}成功");
                return true;
            }
            catch (Exception ex)
@@ -693,7 +699,7 @@
                        S_DEPART_NAME = "",
                        S_START_LOC = model.startBit,
                        S_END_LOC = model.endBit,
                        S_TYPE = model.reqCode,
                        S_TYPE = model.taskType,
                        S_SRC_NO = "",//
                        N_PRIORITY = -88,
                        S_WORK_MODE = "agv",
@@ -761,134 +767,11 @@
        }
        public static void ResMesTask()
        {
            AutoThread.InvokeMethod(AutoThread.Instance, "ResolveMesTask");
            ///1.
            TaskRepository taskservice = new TaskRepository();
            var tasks = taskservice.FindList(x => (x.S_B_STATE == "MES" || x.S_B_STATE == "People") && x.N_PRIORITY == -88);
            var VERXs = Settings.deviceInfos?.FindAll(x => x.deviceType == 2);
            //if (VERXs.Any())
            foreach (var task in tasks)
            {
                var sx = VERXs?.Find(x => x.location.Contains(task.S_END_LOC));
                if (sx == null)
                {
                    //直接生成对应任务。
                    var res = TaskProcess.CreateTask(task.S_TASK_NO, task.S_START_LOC, task.S_END_LOC, task.S_TYPE, 6, task.S_CNTRS.Split(',').ToList());
                    if (res)
                    {
                        //task.N_PRIORITY = 0;
                        taskservice.dbcontext.Set<TaskEntity>().Attach(task);
                        taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).CurrentValue = 0;
                        taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).IsModified = true;
                        taskservice.dbcontext.SaveChanges();
                    }
                }
                else
                {
                    var sindex = sx.location.ToList().IndexOf(task.S_END_LOC);
                    LocRepository locRepository = new LocRepository();
                    //生成跳跃任务。  -- æ‰˜ç›˜è´§ä½è¡¨ã€‚
                    var t1s = taskservice.FindList(x => x.S_SRC_NO == task.S_TASK_NO);
                    if (t1s.Any())
                    {
                        var t1 = t1s.OrderBy(x => x.T_CREATE).LastOrDefault();
                        if (t1.S_END_LOC == task.S_END_LOC)
                        {
                            task.N_PRIORITY = 0;
                            task.S_B_STATE = "MES_完成";
                            taskservice.Update(task);
                            continue;
                        }
                        if (t1.S_B_STATE == "完成")
                        {
                            //1.终点是否有托盘。 ä¾æ®æ˜¯ç»ˆç‚¹çš„任务是 ä½œä¸ºç»ˆç‚¹ï¼Œè¿˜æ˜¯èµ·ç‚¹ã€‚
                            //var ec = taskservice.FindList(x => (x.S_START_LOC == task.S_START_LOC || x.S_END_LOC == task.S_END_LOC) /*&& DateTime.Now.Subtract(x.T_CREATE).TotalHours < 5*/).OrderByDescending(x => x.T_CREATE).FirstOrDefault();//($"select top 1 * from TN_TASK WHERE S_START_LOC='{task.S_END_LOC}' OR S_END_LOC='{task.S_END_LOC}' ORDER BY T_CREATE DESC");
                            //var ec = taskservice.FindList(x => x.S_START_LOC == task.S_START_LOC && x.S_END_LOC == task.S_START_LOC, new Common.Data.Pagination
                            //                        {
                            //                            page = 1,
                            //                            sidx = "T_CREATE",
                            //                            sord = "desc",
                            //                            rows = 1
                            //                        }).FirstOrDefault();
                            TaskEntity ec = null;
                            var dev = Conn.默认Redis.GetValue(sx.deviceName + "." + (sindex == 0 ? "D1224" : "D1225"));
                            if (dev?.Trim() == "1")
                                ec = taskservice.FindList(x => x.S_END_LOC == task.S_END_LOC && x.S_B_STATE == "完成", new Common.Data.Pagination
                                {
                                    page = 1,
                                    sidx = "T_CREATE",
                                    sord = "desc",
                                    rows = 1
                                }).FirstOrDefault();
                            if (t1.S_START_LOC == task.S_START_LOC && ec != null)//!= task.S_END_LOC)
                            {
                                //第二段。
                                LocEntity endLoc = null;
                                var di = sx;
                                if (di != null)
                                {
                                    foreach (var ssloc in di.deviceNo)
                                    {
                                        var endloc = locRepository.FindEntity(x => x.S_LOC_CODE == ssloc);
                                        if (endloc != null && endloc.N_CURRENT_NUM == 0 && endloc.S_LOCK_STATE == "无")
                                        {
                                            endLoc = endloc;
                                            break;
                                        }
                                    }
                                    if (endLoc != null)
                                    {
                                        var res = TaskProcess.CreateTask(task.S_TASK_NO, task.S_END_LOC, endLoc.S_LOC_CODE, task.S_TYPE + "下空", 7, ec.S_CNTRS.Split(',').ToList());
                                        if (res)
                                        {
                                            task.N_PRIORITY = 0; taskservice.Update(task);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                var res = TaskProcess.CreateTask(task.S_TASK_NO, t1.S_END_LOC, task.S_END_LOC, task.S_TYPE + "补满", 6, task.S_CNTRS.Split(',').ToList());
                                if (res)
                                {
                                    task.N_PRIORITY = 0; taskservice.Update(task);
                                }
                            }
                        }
                    }
                    else
                    {
                        //生成第一段。
                        LocEntity endLoc = null;
                        var di = sx;
                        if (di != null)
                        {
                            foreach (var ssloc in di.deviceNo)
                            {
                                var endloc = locRepository.FindEntity(x => x.S_LOC_CODE == ssloc);
                                if (endloc != null && endloc.N_CURRENT_NUM == 0 && endloc.S_LOCK_STATE == "无")
                                {
                                    endLoc = endloc;
                                    break;
                                }
                            }
                            if (endLoc != null)
                            {
                                var res = TaskProcess.CreateTask("", task.S_START_LOC, endLoc.S_LOC_CODE, task.S_TYPE + "满转", 8, task.S_CNTRS.Split(',').ToList());
                                if (res)
                                {
                                    task.N_PRIORITY = 0; taskservice.Update(task);
                                }
                            }
                        }
                    }
                }
            }
            //var VERX = Settings.deviceInfos?.FindAll(x => x.deviceName.Contains("捷瞬抓臂"));
            //if ()
            ///2  çœ‹ç¼“存区。 æ²¡æ»¡çš„。
        }