| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 | using ServiceCenter.Logs;using ServiceCenter.Redis;using ServiceCenter.SqlSugars;using System.ComponentModel;using WCS.Core;using WCS.Entity;using WCS.WorkEngineering.Extensions;using WCS.WorkEngineering.WebApi.Controllers;using WCS.WorkEngineering.Worlds;using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;namespace WCS.WorkEngineering.Systems{    /// <summary>    /// 出库站台交互    /// </summary>    [BelongTo(typeof(MainWorld))]    [Description("一楼出库工位处理系统")]    public class 一楼出库工位处理系统 : DeviceSystem<Station>    {        protected override bool ParallelDo => true;        protected override bool SaveLogsToFile => true;        public override void Do(Station obj)        {            var key = $"WCS:Lock:{obj.Entity.Code}";            try            {                if (RedisHub.Default.Get(key) != null)                {                    throw new KnownException($"[{obj.Entity.Code}]--触发并发管控", LogLevelEnum.High);                }                RedisHub.Default.Set(key, obj.Entity.Code);                if (!obj.Data3.Status.HasFlag(Entity.Protocol.Station.StatusEunm.PH_Status) && !obj.Data3.Status.HasFlag(Entity.Protocol.Station.StatusEunm.OT_Status))                {                    bool result = true; //是否需要申请出库任务,默认需要                    SqlSugarHelper.Do(db =>                    {                        //当前站台是否有任务在执行                        var task = db.Default.Queryable<WCS_TaskInfo>().Where(v => v.AddrTo == obj.Entity.Code && v.Status < Entity.TaskStatus.AGVExecution).OrderByDescending(v => v.AddTime).First();                        if (task != null) //有任务                        {                            if (task.AgvTaskID == 0) throw new KnownException($"WCS任务[{task.ID}],等待AGV申请任务", LogLevelEnum.Mid);                            else                            {                                //检查对应的AGV任务状态是否大于退出储位状态                                var agv = db.Default.Queryable<WCS_AgvTaskInfo>().SplitTable(v => v.Take(2)).First(v => v.ID == task.ID) ?? throw new KnownException($"未找到AGV中间表任务[{task.AgvTaskID}],请检查异常原因", LogLevelEnum.Mid);                                if (agv == null)                                {                                }                                else if (agv.AgvStatus >= AGVTaskStatus.Complete3)                                {                                    result = true;                                }                                else                                {                                    result = false;                                }                            }                        }                        else //无任务                        {                            result = true;                        }                    });                    if (result) WmsApi.ApplyStockOutTask(obj.Entity.Code);                }            }            finally            {                RedisHub.Default.Del(key);            }        }        public override bool Select(Device dev)        {            return dev.HasFlag(DeviceFlags.一楼出库口);        }    }}
 |