陈勇
2026-03-10 fc9cba5f058089887aa7061d2e6b4006b9e04a9a
同步
已添加11个文件
已修改15个文件
1886 ■■■■■ 文件已修改
项目代码/WCS/WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCS/WCSServer/WIDESEAWCS_ITaskInfoService/ITaskService.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCS/WCSServer/WIDESEAWCS_TaskInfoService/TaskService.cs 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCS/WCSServer/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCS/WCSServer/WIDESEAWCS_Tasks/ConveyorLineJobTZ/CommonConveyorLineTZJob.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCS/WCSServer/WIDESEAWCS_Tasks/TT/CommonConveyorLineTTJob.cs 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Core/Quartz/ISchedulerCenter.cs 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Core/Quartz/JobFactory.cs 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Core/Quartz/JobSetup.cs 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Core/Quartz/ResponseContent.cs 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Core/Quartz/SchedulerCenterServer.cs 470 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Core/Quartz/TaskInfoDto.cs 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Core/Quartz/TasksQz.cs 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Core/WIDESEA_Core.csproj 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Model/Models/BasicInfo/Dt_MESLockInfo_hty.cs 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Model/Models/BasicModel/Stock/VV_MesLockInfo.cs 216 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_Model/Models/BasicModel/Stock/VV_StockInfo.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_StoragIntegrationServices/MES/Partial/removeWorkOrderInfo.cs 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_StoragIntegrationServices/WCS/Partial/Queue.cs 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_StoragIntegrationServices/WCS/Partial/TZPassZZ.cs 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_StoragIntegrationServices/WCS/WCSService.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_StorageTaskServices/AutoTask/AspNetCoreSchedule.cs 327 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_StorageTaskServices/AutoTask/BackgroundJob.cs 327 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_StorageTaskServices/AutoTask/QuartzJobMildd.cs 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_StorageTaskServices/WIDESEA_StorageTaskServices.csproj 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WMS/WMSServer/WIDESEA_WMSServer/Program.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ÏîÄ¿´úÂë/WCS/WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs
@@ -57,12 +57,10 @@
                                };
                                iTenant.AddConnection(connectionConfig);
                            }
                            return iTenant.GetConnection(tenant.TenantId);
                        }
                    }
                }
                return db;
            }
        }
ÏîÄ¿´úÂë/WCS/WCSServer/WIDESEAWCS_ITaskInfoService/ITaskService.cs
@@ -229,7 +229,7 @@
        /// å°†ä»»åŠ¡çŠ¶æ€ä¿®æ”¹ä¸ºä¸‹ä¸€ä¸ªçŠ¶æ€
        /// </summary>
        /// <param name="taskNum">任务号</param>
        WebResponseContent UpdateTaskStatusToNext(int taskNum);
        WebResponseContent UpdateTaskStatusToNext(int taskNum, int taskStatus = -1);
        WebResponseContent TCSendTask([NotNull] Dt_Task task, string Position);
ÏîÄ¿´úÂë/WCS/WCSServer/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -380,12 +380,16 @@
        /// å°†ä»»åŠ¡çŠ¶æ€ä¿®æ”¹ä¸ºä¸‹ä¸€ä¸ªçŠ¶æ€
        /// </summary>
        /// <param name="taskNum">任务号</param>
        public WebResponseContent UpdateTaskStatusToNext(int taskNum)
        public WebResponseContent UpdateTaskStatusToNext(int taskNum, int taskStatus = -1)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (taskStatus > 0)
                {
                    task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskState == taskStatus);
                }
                if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
                return UpdateTaskStatusToNext(task);
            }
ÏîÄ¿´úÂë/WCS/WCSServer/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -210,7 +210,7 @@
            }
            finally
            {
                WriteDebug("CommonConveyorLineJob", "test");
                //WriteDebug("CommonConveyorLineJob", "test");
                //Console.Out.WriteLine(DateTime.Now);
            }
            return;
ÏîÄ¿´úÂë/WCS/WCSServer/WIDESEAWCS_Tasks/ConveyorLineJobTZ/CommonConveyorLineTZJob.cs
@@ -330,7 +330,6 @@
            }
            finally
            {
                WriteDebug("CommonConveyorLineTZJob", "test");
                //Console.Out.WriteLine(DateTime.Now);
            }
            return;
ÏîÄ¿´úÂë/WCS/WCSServer/WIDESEAWCS_Tasks/TT/CommonConveyorLineTTJob.cs
@@ -105,11 +105,24 @@
                            Dt_Task task = null;
                            if (station.stationChildCode == "TC05")
                            {
                                //var executeTaks =  _taskRepository.QueryData(x => (x.Roadway == "SC02" || x.Roadway == "SC04") && x.TaskState <= (int)TaskOutStatusEnum.SC_OutFinish).OrderBy(x => x.CreateDate).FirstOrDefault();
                                var leftTask = _taskRepository.QueryData(x => (x.Roadway == "SC02" || x.Roadway == "SC04") && x.TaskState <= (int)TaskOutStatusEnum.SC_OutFinish).OrderBy(x => x.CreateDate).FirstOrDefault();
                                if (leftTask != null && leftTask.TaskState == (int)TaskOutStatusEnum.SC_OutFinish)
                                {
                                    task = leftTask;
                                }
                                if (task != null)
                                {
                                    _taskService.UpdateTaskStatusToNext(task.TaskNum, (int)TaskOutStatusEnum.SC_OutFinish);
                                    var sattion = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                                    WriteDebug("CommonConveyorLineTTJob任务", $"任务:{task.Serialize()},站台信息:{sattion.Serialize()}");
                                    conveyorLine.SetValue<ConveyorLineDBName, Int16>(ConveyorLineDBName.GetConvNo, Convert.ToInt16(sattion.stationTCLocation), station.stationChildCode);
                                    conveyorLine.SetValue<ConveyorLineDBName, string>(ConveyorLineDBName.PVI_W, task.PVI, station.stationChildCode);
                                    //conveyorLine.SetValue<ConveyorLineDBName, Int16>(ConveyorLineDBName.AllowRelease, 1, station.stationChildCode);
                                }
                            }
                            else if (station.stationChildCode == "TC06")
@@ -120,18 +133,18 @@
                                {
                                    task = rightTask;
                                }
                            }
                            //var task = _taskRepository.QueryData(X => X.NextAddress == station.stationChildCode).OrderBy(x => x.CreateDate).FirstOrDefault();
                            if (task != null)
                            {
                                _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                var sattion = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                                conveyorLine.SetValue<ConveyorLineDBName, Int16>(ConveyorLineDBName.GetConvNo, Convert.ToInt16(sattion.stationTCLocation), station.stationChildCode);
                                conveyorLine.SetValue<ConveyorLineDBName, string>(ConveyorLineDBName.PVI_W, task.PVI, station.stationChildCode);
                                //conveyorLine.SetValue<ConveyorLineDBName, Int16>(ConveyorLineDBName.AllowRelease, 1, station.stationChildCode);
                                if (task != null)
                                {
                                    _taskService.UpdateTaskStatusToNext(task.TaskNum, (int)TaskOutStatusEnum.SC_OutFinish);
                                    var sattion = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                                    WriteDebug("CommonConveyorLineTTJob任务", $"任务:{task.Serialize()},站台信息:{sattion.Serialize()}");
                                    conveyorLine.SetValue<ConveyorLineDBName, Int16>(ConveyorLineDBName.GetConvNo, Convert.ToInt16(sattion.stationTCLocation), station.stationChildCode);
                                    conveyorLine.SetValue<ConveyorLineDBName, string>(ConveyorLineDBName.PVI_W, task.PVI, station.stationChildCode);
                                    //conveyorLine.SetValue<ConveyorLineDBName, Int16>(ConveyorLineDBName.AllowRelease, 1, station.stationChildCode);
                                }
                            }
                            //;
                        }
                        var Putrequest = conveyorLine.GetValue<ConveyorLineDBName, bool>(ConveyorLineDBName.Spare2, station.stationChildCode);//横移机载货放车信号
@@ -144,9 +157,13 @@
                            {
                                if (station.stationChildCode == "TC05")
                                {
                                    var task = _taskRepository.QueryData(X => X.TargetAddress == "RB043" && (X.NextAddress == station.stationChildCode /*|| X.CurrentAddress == station.stationChildCode*/)).OrderBy(x => x.CreateDate).FirstOrDefault();
                                    _taskService.UpdatePosition(task.TaskNum, station.stationChildCode);
                                    conveyorLine.SetValue<ConveyorLineDBName, Int16>(ConveyorLineDBName.AllowRelease, 1, station.stationChildCode);
                                    var task = _taskRepository.QueryData(X => X.TargetAddress == "RB043" && (X.NextAddress == station.stationChildCode && X.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting/*|| X.CurrentAddress == station.stationChildCode*/)).OrderBy(x => x.CreateDate).FirstOrDefault();
                                    if (task != null)
                                    {
                                        _taskService.UpdatePosition(task.TaskNum, station.stationChildCode);
                                        conveyorLine.SetValue<ConveyorLineDBName, Int16>(ConveyorLineDBName.AllowRelease, 1, station.stationChildCode);
                                    }
                                }
                                else
                                {
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Core/Quartz/ISchedulerCenter.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace WIDESEA.QuartzJob
{
    public interface ISchedulerCenter
    {
        /// <summary>
        /// å¼€å¯ä»»åŠ¡è°ƒåº¦
        /// </summary>
        /// <returns></returns>
        Task<ResponseContent> StartScheduleAsync();
        /// <summary>
        /// åœæ­¢ä»»åŠ¡è°ƒåº¦
        /// </summary>
        /// <returns></returns>
        Task<ResponseContent> StopScheduleAsync();
        /// <summary>
        ///
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <returns></returns>
        Task<ResponseContent> AddScheduleJobAsync(TasksQz sysSchedule);
        /// <summary>
        /// åœæ­¢ä¸€ä¸ªä»»åŠ¡
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <returns></returns>
        Task<ResponseContent> StopScheduleJobAsync(TasksQz sysSchedule);
        /// <summary>
        /// æ£€æµ‹ä»»åŠ¡æ˜¯å¦å­˜åœ¨
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <returns></returns>
        Task<bool> IsExistScheduleJobAsync(TasksQz sysSchedule);
        /// <summary>
        /// æš‚停指定的计划任务
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <returns></returns>
        Task<ResponseContent> PauseJob(TasksQz sysSchedule);
        /// <summary>
        /// æ¢å¤ä¸€ä¸ªä»»åŠ¡
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <returns></returns>
        Task<ResponseContent> ResumeJob(TasksQz sysSchedule);
        /// <summary>
        /// èŽ·å–ä»»åŠ¡è§¦å‘å™¨çŠ¶æ€
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <returns></returns>
        Task<List<TaskInfoDto>> GetTaskStaus(TasksQz sysSchedule);
        /// <summary>
        /// èŽ·å–è§¦å‘å™¨æ ‡è¯†
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        string GetTriggerState(string key);
        /// <summary>
        /// ç«‹å³æ‰§è¡Œ ä¸€ä¸ªä»»åŠ¡
        /// </summary>
        /// <param name="tasksQz"></param>
        /// <returns></returns>
        Task<ResponseContent> ExecuteJobAsync(TasksQz tasksQz);
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Core/Quartz/JobFactory.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,51 @@
using Quartz;
using Microsoft.Extensions.DependencyInjection;
using Quartz.Spi;
using System;
using System.Collections.Generic;
using System.Text;
namespace WIDESEA.QuartzJob
{
    public class JobFactory : IJobFactory
    {
        /// <summary>
        /// æ³¨å…¥åå°„获取依赖对象
        /// </summary>
        private readonly IServiceProvider _serviceProvider;
        public JobFactory(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }
        /// <summary>
        /// å®žçŽ°æŽ¥å£Job
        /// </summary>
        /// <param name="bundle"></param>
        /// <param name="scheduler"></param>
        /// <returns></returns>
        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            try
            {
                var serviceScope = _serviceProvider.CreateScope();
                var job = serviceScope.ServiceProvider.GetService(bundle.JobDetail.JobType) as IJob;
                return job;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void ReturnJob(IJob job)
        {
            var disposable = job as IDisposable;
            if (disposable != null)
            {
                disposable.Dispose();
            }
        }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Core/Quartz/JobSetup.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,26 @@
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.Spi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace WIDESEA.QuartzJob
{
    /// <summary>
    /// ä»»åŠ¡è°ƒåº¦ å¯åŠ¨æœåŠ¡
    /// </summary>
    public static class JobSetup
    {
        public static void AddJobSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
            //services.AddSingleton<IJobFactory, JobFactory>();
            //services.AddTransient<AgvTaskJob>();//Job使用瞬时依赖注入
            //services.AddSingleton<ISchedulerCenter, SchedulerCenterServer>();
        }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Core/Quartz/ResponseContent.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WIDESEA.QuartzJob
{
    public class ResponseContent
    {
        public ResponseContent()
        {
        }
        public ResponseContent(bool status)
        {
            Status = status;
        }
        public bool Status { get; set; }
        public string Code { get; set; }
        public string Message { get; set; }
        public object Data { get; set; }
        public ResponseContent OK()
        {
            Status = true;
            return this;
        }
        public static ResponseContent Instance
        {
            get { return new ResponseContent(); }
        }
        public ResponseContent OK(string message = null, object data = null)
        {
            Status = true;
            Message = message;
            Data = data;
            return this;
        }
        public ResponseContent Error(string message = null)
        {
            Status = false;
            Message = message;
            return this;
        }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Core/Quartz/SchedulerCenterServer.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,470 @@
using Quartz;
using Quartz.Impl;
using Quartz.Impl.Triggers;
using Quartz.Spi;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.Helper;
namespace WIDESEA.QuartzJob
{
    public class SchedulerCenterServer : ISchedulerCenter
    {
        private Task<IScheduler> _scheduler;
        private readonly IJobFactory _iocjobFactory;
        public SchedulerCenterServer(IJobFactory jobFactory)
        {
            _iocjobFactory = jobFactory;
            _scheduler = GetSchedulerAsync();
        }
        private Task<IScheduler> GetSchedulerAsync()
        {
            if (_scheduler != null)
                return _scheduler;
            else
            {
                // ä»ŽFactory中获取Scheduler实例
                NameValueCollection collection = new NameValueCollection
                {
                    { "quartz.serializer.type", "binary" },
                };
                StdSchedulerFactory factory = new StdSchedulerFactory(collection);
                return _scheduler = factory.GetScheduler();
            }
        }
        /// <summary>
        /// å¼€å¯ä»»åŠ¡è°ƒåº¦
        /// </summary>
        /// <returns></returns>
        public async Task<ResponseContent> StartScheduleAsync()
        {
            var result = new ResponseContent();
            try
            {
                _scheduler.Result.JobFactory = _iocjobFactory;
                if (!_scheduler.Result.IsStarted)
                {
                    //等待任务运行完成
                    await _scheduler.Result.Start();
                    ConsoleHelper.WriteSuccessLine("任务调度开启!");
                    result = ResponseContent.Instance.OK($"任务调度开启成功");
                    return result;
                }
                else
                {
                    result = ResponseContent.Instance.OK($"任务调度已经开启");
                    return result;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// åœæ­¢ä»»åŠ¡è°ƒåº¦
        /// </summary>
        /// <returns></returns>
        public async Task<ResponseContent> StopScheduleAsync()
        {
            var result = new ResponseContent();
            try
            {
                if (!_scheduler.Result.IsShutdown)
                {
                    //等待任务运行完成
                    await _scheduler.Result.Shutdown();
                    //await Console.Out.WriteLineAsync("任务调度停止!");
                    result = ResponseContent.Instance.OK($"任务调度停止成功");
                    return result;
                }
                else
                {
                    result = ResponseContent.Instance.OK($"任务调度已经停止");
                    return result;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// æ·»åŠ ä¸€ä¸ªè®¡åˆ’ä»»åŠ¡ï¼ˆæ˜ å°„ç¨‹åºé›†æŒ‡å®šIJob实现类)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tasksQz"></param>
        /// <returns></returns>
        public async Task<ResponseContent> AddScheduleJobAsync(TasksQz tasksQz)
        {
            var result = new ResponseContent();
            if (tasksQz != null)
            {
                try
                {
                    JobKey jobKey = new JobKey(tasksQz.Id.ToString(), tasksQz.JobGroup);
                    if (await _scheduler.Result.CheckExists(jobKey))
                    {
                        result = ResponseContent.Instance.OK($"该任务计划已经在执行:【{tasksQz.Name}】,请勿重复启动!");
                        return result;
                    }
                    #region è®¾ç½®å¼€å§‹æ—¶é—´å’Œç»“束时间
                    if (tasksQz.BeginTime == null)
                    {
                        tasksQz.BeginTime = DateTime.Now;
                    }
                    DateTimeOffset starRunTime = DateBuilder.NextGivenSecondDate(tasksQz.BeginTime, 1);//设置开始时间
                    if (tasksQz.EndTime == null)
                    {
                        tasksQz.EndTime = DateTime.MaxValue.AddDays(-1);
                    }
                    DateTimeOffset endRunTime = DateBuilder.NextGivenSecondDate(tasksQz.EndTime, 1);//设置暂停时间
                    #endregion
                    #region é€šè¿‡åå°„获取程序集类型和类
                    Assembly assembly = Assembly.Load(new AssemblyName(tasksQz.AssemblyName));
                    Type jobType = assembly.GetType(tasksQz.AssemblyName + "." + tasksQz.ClassName);
                    #endregion
                    //判断任务调度是否开启
                    //if (!_scheduler.Result.IsStarted)
                    //{
                    //    await StartScheduleAsync();
                    //}
                    //传入反射出来的执行程序集
                    IJobDetail job = new JobDetailImpl(tasksQz.Id.ToString(), tasksQz.JobGroup, jobType);
                    job.JobDataMap.Add("JobParam", tasksQz.JobParams);
                    ITrigger trigger;
                    #region æ³›åž‹ä¼ é€’
                    //IJobDetail job = JobBuilder.Create<T>()
                    //    .WithIdentity(sysSchedule.Name, sysSchedule.JobGroup)
                    //    .Build();
                    #endregion
                    if (tasksQz.Cron != null && CronExpression.IsValidExpression(tasksQz.Cron) && tasksQz.TriggerType > 0)
                    {
                        trigger = CreateCronTrigger(tasksQz);
                        ((CronTriggerImpl)trigger).MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
                    }
                    else
                    {
                        trigger = CreateSimpleTrigger(tasksQz);
                    }
                    // å‘Šè¯‰Quartz使用我们的触发器来安排作业
                    await _scheduler.Result.ScheduleJob(job, trigger);
                    //await Task.Delay(TimeSpan.FromSeconds(120));
                    //await Console.Out.WriteLineAsync("关闭了调度器!");
                    //await _scheduler.Result.Shutdown();
                    result = ResponseContent.Instance.OK($"【{tasksQz.Name}】成功");
                    return result;
                }
                catch (Exception ex)
                {
                    result = ResponseContent.Instance.Error($"任务计划异常:【{ex.Message}】");
                    return result;
                }
            }
            else
            {
                result = ResponseContent.Instance.Error($"任务计划不存在:【{tasksQz?.Name}】");
                return result;
            }
        }
        /// <summary>
        /// ä»»åŠ¡æ˜¯å¦å­˜åœ¨?
        /// </summary>
        /// <returns></returns>
        public async Task<bool> IsExistScheduleJobAsync(TasksQz sysSchedule)
        {
            JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup);
            if (await _scheduler.Result.CheckExists(jobKey))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// æš‚停一个指定的计划任务
        /// </summary>
        /// <returns></returns>
        public async Task<ResponseContent> StopScheduleJobAsync(TasksQz sysSchedule)
        {
            var result = new ResponseContent();
            try
            {
                JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup);
                if (!await _scheduler.Result.CheckExists(jobKey))
                {
                    result = ResponseContent.Instance.Error($"未找到要暂停的任务:【{sysSchedule.Name}】");
                    return result;
                }
                else
                {
                    await _scheduler.Result.DeleteJob(jobKey);
                    result = ResponseContent.Instance.OK($"【{sysSchedule.Name}】成功");
                    return result;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// æ¢å¤æŒ‡å®šçš„计划任务
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <returns></returns>
        public async Task<ResponseContent> ResumeJob(TasksQz sysSchedule)
        {
            var result = new ResponseContent();
            try
            {
                JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup);
                if (!await _scheduler.Result.CheckExists(jobKey))
                {
                    result = ResponseContent.Instance.Error($"未找到要恢复的任务:【{sysSchedule.Name}】");
                    return result;
                }
                await _scheduler.Result.ResumeJob(jobKey);
                result = ResponseContent.Instance.OK($"【{sysSchedule.Name}】成功");
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// æš‚停指定的计划任务
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <returns></returns>
        public async Task<ResponseContent> PauseJob(TasksQz sysSchedule)
        {
            var result = new ResponseContent();
            try
            {
                JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup);
                if (!await _scheduler.Result.CheckExists(jobKey))
                {
                    result = ResponseContent.Instance.Error($"未找到要暂停的任务:【{sysSchedule.Name}】");
                    return result;
                }
                await _scheduler.Result.PauseJob(jobKey);
                result = ResponseContent.Instance.Error($"【{sysSchedule.Name}】成功");
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }
        #region çŠ¶æ€çŠ¶æ€å¸®åŠ©æ–¹æ³•
        public async Task<List<TaskInfoDto>> GetTaskStaus(TasksQz sysSchedule)
        {
            var ls = new List<TaskInfoDto>();
            var noTask = new List<TaskInfoDto>{ new TaskInfoDto {
                jobId = sysSchedule.Id.ToString(),
                jobGroup = sysSchedule.JobGroup,
                triggerId = "",
                triggerGroup = "",
                triggerStatus = "不存在"
            } };
            JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup);
            IJobDetail job = await _scheduler.Result.GetJobDetail(jobKey);
            if (job == null)
            {
                return noTask;
            }
            //info.Append(string.Format("任务ID:{0}\r\n任务名称:{1}\r\n", job.Key.Name, job.Description));
            var triggers = await _scheduler.Result.GetTriggersOfJob(jobKey);
            if (triggers == null || triggers.Count == 0)
            {
                return noTask;
            }
            foreach (var trigger in triggers)
            {
                var triggerStaus = await _scheduler.Result.GetTriggerState(trigger.Key);
                string state = GetTriggerState(triggerStaus.ToString());
                ls.Add(new TaskInfoDto
                {
                    jobId = job.Key.Name,
                    jobGroup = job.Key.Group,
                    triggerId = trigger.Key.Name,
                    triggerGroup = trigger.Key.Group,
                    triggerStatus = state
                });
                //info.Append(string.Format("触发器ID:{0}\r\n触发器名称:{1}\r\n状态:{2}\r\n", item.Key.Name, item.Description, state));
            }
            return ls;
        }
        public string GetTriggerState(string key)
        {
            string state = null;
            if (key != null)
                key = key.ToUpper();
            switch (key)
            {
                case "1":
                    state = "暂停";
                    break;
                case "2":
                    state = "完成";
                    break;
                case "3":
                    state = "出错";
                    break;
                case "4":
                    state = "阻塞";
                    break;
                case "0":
                    state = "正常";
                    break;
                case "-1":
                    state = "不存在";
                    break;
                case "BLOCKED":
                    state = "阻塞";
                    break;
                case "COMPLETE":
                    state = "完成";
                    break;
                case "ERROR":
                    state = "出错";
                    break;
                case "NONE":
                    state = "不存在";
                    break;
                case "NORMAL":
                    state = "正常";
                    break;
                case "PAUSED":
                    state = "暂停";
                    break;
            }
            return state;
        }
        #endregion
        #region åˆ›å»ºè§¦å‘器帮助方法
        /// <summary>
        /// åˆ›å»ºSimpleTrigger触发器(简单触发器)
        /// </summary>
        /// <param name="sysSchedule"></param>
        /// <param name="starRunTime"></param>
        /// <param name="endRunTime"></param>
        /// <returns></returns>
        private ITrigger CreateSimpleTrigger(TasksQz sysSchedule)
        {
            if (sysSchedule.CycleRunTimes > 0)
            {
                ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity(sysSchedule.Id.ToString(), sysSchedule.JobGroup)
                .StartAt(sysSchedule.BeginTime.Value)
                .WithSimpleSchedule(x => x
                    .WithIntervalInSeconds(sysSchedule.IntervalSecond)
                    .WithRepeatCount(sysSchedule.CycleRunTimes - 1))
                .EndAt(sysSchedule.EndTime.Value)
                .Build();
                return trigger;
            }
            else
            {
                ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity(sysSchedule.Id.ToString(), sysSchedule.JobGroup)
                .StartAt(sysSchedule.BeginTime.Value)
                .WithSimpleSchedule(x => x
                    .WithIntervalInSeconds(sysSchedule.IntervalSecond)
                    .RepeatForever()
                )
                .EndAt(sysSchedule.EndTime.Value)
                .Build();
                return trigger;
            }
            // è§¦å‘作业立即运行,然后每10秒重复一次,无限循环
        }
        /// <summary>
        /// åˆ›å»ºç±»åž‹Cron的触发器
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        private ITrigger CreateCronTrigger(TasksQz sysSchedule)
        {
            // ä½œä¸šè§¦å‘器
            return TriggerBuilder.Create()
                   .WithIdentity(sysSchedule.Id.ToString(), sysSchedule.JobGroup)
                   .StartAt(sysSchedule.BeginTime.Value)//开始时间
                   .EndAt(sysSchedule.EndTime.Value)//结束数据
                   .WithCronSchedule(sysSchedule.Cron)//指定cron表达式
                   .ForJob(sysSchedule.Id.ToString(), sysSchedule.JobGroup)//作业名称
                   .Build();
        }
        #endregion
        /// <summary>
        /// ç«‹å³æ‰§è¡Œ ä¸€ä¸ªä»»åŠ¡
        /// </summary>
        /// <param name="tasksQz"></param>
        /// <returns></returns>
        public async Task<ResponseContent> ExecuteJobAsync(TasksQz tasksQz)
        {
            var result = new ResponseContent();
            try
            {
                JobKey jobKey = new JobKey(tasksQz.Id.ToString(), tasksQz.JobGroup);
                //判断任务是否存在,存在则 è§¦å‘一次,不存在则先添加一个任务,触发以后再 åœæ­¢ä»»åŠ¡
                if (!await _scheduler.Result.CheckExists(jobKey))
                {
                    //不存在 åˆ™ æ·»åŠ ä¸€ä¸ªè®¡åˆ’ä»»åŠ¡
                    await AddScheduleJobAsync(tasksQz);
                    //触发执行一次
                    await _scheduler.Result.TriggerJob(jobKey);
                    //停止任务
                    await StopScheduleJobAsync(tasksQz);
                    result = ResponseContent.Instance.OK($"立即执行计划任务:【{tasksQz.Name}】成功");
                }
                else
                {
                    await _scheduler.Result.TriggerJob(jobKey);
                    result = ResponseContent.Instance.OK($"立即执行计划任务:【{tasksQz.Name}】成功");
                }
            }
            catch (Exception ex)
            {
                result = ResponseContent.Instance.Error($"立即执行计划任务失败:【{ex.Message}】");
            }
            return result;
        }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Core/Quartz/TaskInfoDto.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WIDESEA.QuartzJob
{
    public class TaskInfoDto
    {
        /// <summary>
        /// ä»»åŠ¡ID
        /// </summary>
        public string jobId { get; set; }
        /// <summary>
        /// ä»»åŠ¡åç§°
        /// </summary>
        public string jobName { get; set; }
        /// <summary>
        /// ä»»åŠ¡åˆ†ç»„
        /// </summary>
        public string jobGroup { get; set; }
        /// <summary>
        /// è§¦å‘器ID
        /// </summary>
        public string triggerId { get; set; }
        /// <summary>
        /// è§¦å‘器名称
        /// </summary>
        public string triggerName { get; set; }
        /// <summary>
        /// è§¦å‘器分组
        /// </summary>
        public string triggerGroup { get; set; }
        /// <summary>
        /// è§¦å‘器状态
        /// </summary>
        public string triggerStatus { get; set; }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Core/Quartz/TasksQz.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WIDESEA.QuartzJob
{
    /// <summary>
    /// ä»»åŠ¡è®¡åˆ’è¡¨
    /// </summary>
    public class TasksQz
    {
        /// <summary>
        /// ä»»åŠ¡åç§°
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// ä»»åŠ¡åˆ†ç»„
        /// </summary>
        public string JobGroup { get; set; }
        /// <summary>
        /// ä»»åŠ¡è¿è¡Œæ—¶é—´è¡¨è¾¾å¼
        /// </summary>
        public string Cron { get; set; }
        /// <summary>
        /// ä»»åŠ¡æ‰€åœ¨DLL对应的程序集名称
        /// </summary>
        public string AssemblyName { get; set; }
        /// <summary>
        /// ä»»åŠ¡æ‰€åœ¨ç±»
        /// </summary>
        public string ClassName { get; set; }
        /// <summary>
        /// ä»»åŠ¡æè¿°
        /// </summary>
        public string Remark { get; set; }
        /// <summary>
        /// æ‰§è¡Œæ¬¡æ•°
        /// </summary>
        public int RunTimes { get; set; }
        /// <summary>
        /// å¼€å§‹æ—¶é—´
        /// </summary>
        public DateTime? BeginTime { get; set; }
        /// <summary>
        /// ç»“束时间
        /// </summary>
        public DateTime? EndTime { get; set; }
        /// <summary>
        /// è§¦å‘器类型(0、simple 1、cron)
        /// </summary>
        public int TriggerType { get; set; }
        /// <summary>
        /// æ‰§è¡Œé—´é𔿗¶é—´, ç§’为单位
        /// </summary>
        public int IntervalSecond { get; set; }
        /// <summary>
        /// å¾ªçŽ¯æ‰§è¡Œæ¬¡æ•°
        /// </summary>
        public int CycleRunTimes { get; set; }
        /// <summary>
        /// æ˜¯å¦å¯åЍ
        /// </summary>
        public bool IsStart { get; set; } = true;
        /// <summary>
        /// æ‰§è¡Œä¼ å‚
        /// </summary>
        public string JobParams { get; set; }
        public bool? IsDeleted { get; set; }
        /// <summary>
        /// åˆ›å»ºæ—¶é—´
        /// </summary>
        public DateTime CreateTime { get; set; } = DateTime.Now;
        /// <summary>
        /// ä»»åŠ¡å†…å­˜ä¸­çš„çŠ¶æ€
        /// </summary>
        public List<TaskInfoDto> Triggers { get; set; }
        public int Id { get; set; }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Core/WIDESEA_Core.csproj
@@ -25,6 +25,7 @@
    <PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.3.8" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="OfficeOpenXml.Core.ExcelPackage" Version="1.0.0" />
    <PackageReference Include="Quartz" Version="3.16.1" />
    <PackageReference Include="SkiaSharp" Version="2.88.8" />
    <PackageReference Include="SqlSugarCore" Version="5.1.4.152" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />
@@ -36,6 +37,7 @@
  <ItemGroup>
    <Folder Include="Attribute\" />
    <Folder Include="ServiceExtensions\" />
    <Folder Include="Quartz\" />
  </ItemGroup>
</Project>
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Model/Models/BasicInfo/Dt_MESLockInfo_hty.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,73 @@
using Magicodes.ExporterAndImporter.Core;
using Org.BouncyCastle.Crypto.Utilities;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.DB.Models;
namespace WIDESEA_Model.Models
{
    /// <summary>
    /// æ‹‰åŠ¨é”è½¦åŽ†å²
    /// </summary>
    public class Dt_MESLockInfo_hty : BaseEntity
    {
        /// <summary>
        /// ä¸»é”®
        /// </summary>
        [ImporterHeader(Name = "主键")]
        [ExporterHeader(DisplayName = "主键")]
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "主键")]
        public int Id { get; set; }
        /// <summary>
        /// è½¦èº«ID
        /// </summary>
        [ImporterHeader(Name = "车身ID")]
        [ExporterHeader(DisplayName = "车身ID")]
        [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "车身ID")]
        public int carBodyID { get; set; }
        /// <summary>
        /// è½¦èº«å¯¹è±¡
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(carBodyID), nameof(Dt_CarBodyInfo.Id))]
        public Dt_CarBodyInfo CarBodyInfo { get; set; }
        /// <summary>
        /// çŠ¶æ€ 0-未下发任务  1-已下发任务
        /// </summary>
        [SugarColumn(IsNullable = false, Length = 20, ColumnDescription = "状态")]
        public int LockStatue { get; set; }
        /// <summary>
        /// æ‰€å±žæ¨ªç§»æœºäº§çº¿
        /// </summary>
        public string TCLine { get; set; }
        /// <summary>
        /// é¡ºåºå·
        /// </summary>
        public int sequenceNo { get; set; }
        ///// <summary>
        ///// åº“位
        ///// </summary>
        //[ImporterHeader(Name = "库位")]
        //[ExporterHeader(DisplayName = "库位")]
        //[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "库位")]
        //public int locaitonCode { get; set; }
        ///// <summary>
        ///// PVI
        ///// </summary>
        //[ImporterHeader(Name = "PVI")]
        //[ExporterHeader(DisplayName = "PVI")]
        //[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "PVI")]
        //public int PVI { get; set; }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Model/Models/BasicModel/Stock/VV_MesLockInfo.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,216 @@
using Magicodes.ExporterAndImporter.Core;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.DB.Models;
namespace WIDESEA_Model.Models
{
    [SugarTable(nameof(VV_MesLockInfo), "锁车队列信息")]
    public class VV_MesLockInfo
    {
        /// <summary>
        /// ä¸»é”®
        /// </summary>
        [ImporterHeader(Name = "主键")]
        [ExporterHeader(DisplayName = "主键")]
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "主键")]
        public int Id { get; set; }
        /// <summary>
        ///  1-初始化  2-已下发
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDescription = "拉动状态")]
        public int LockStatue { get; set; }
        /// <summary>
        ///  æ¨ªç§»æœºäº§çº¿ 1-4为左侧横移机  4-7为右侧横移机
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDescription = " æ¨ªç§»æœºäº§çº¿")]
        public int TCLine { get; set; }
        /// <summary>
        /// åˆ›å»ºè€…
        /// </summary>
        [ImporterHeader(Name = "创建者")]
        [ExporterHeader(DisplayName = "创建者")]
        [SugarColumn(IsNullable = false, IsOnlyIgnoreUpdate = true, ColumnDescription = "创建者")]
        public string Creater { get; set; } = "Systeam";
        /// <summary>
        /// åˆ›å»ºæ—¶é—´
        /// </summary>
        [ImporterHeader(Name = "创建时间")]
        [ExporterHeader(DisplayName = "创建时间")]
        [SugarColumn(IsNullable = false, IsOnlyIgnoreUpdate = true, ColumnDescription = "创建时间")]
        public DateTime CreateDate { get; set; }   //= DateTime.Now;
        /// <summary>
        /// æ›´æ–°è€…
        /// </summary>
        [ImporterHeader(Name = "修改人")]
        [ExporterHeader(DisplayName = "修改人")]
        [SugarColumn(IsNullable = true, IsOnlyIgnoreInsert = true, ColumnDescription = "修改人")]
        public string Modifier { get; set; } = "System";
        /// <summary>
        /// ä¿®æ”¹æ—¥æœŸ
        /// </summary>
        [ImporterHeader(Name = "修改日期")]
        [ExporterHeader(DisplayName = "修改日期")]
        [SugarColumn(IsNullable = true, IsOnlyIgnoreInsert = true, ColumnDescription = "修改日期")]
        public DateTime? ModifyDate { get; set; }  //= DateTime.Now;
        /// <summary>
        /// é¡ºåºå·
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDescription = "顺序号")]
        public int sequenceNo { get; set; }
        /// <summary>
        /// æ‰€å±žå··é“
        /// </summary>
        [ImporterHeader(Name = "所属巷道")]
        [ExporterHeader(DisplayName = "所属巷道")]
        [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "所属巷道")]
        public string RoadwayNo { get; set; }
        /// <summary>
        /// è´§ä½ç¼–号
        /// </summary>
        [ImporterHeader(Name = "货位编号")]
        [ExporterHeader(DisplayName = "货位编号")]
        [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "货位编号")]
        public string LocationCode { get; set; }
        /// <summary>
        /// è½¦èº«ID
        /// </summary>
        [ImporterHeader(Name = "车身ID")]
        [ExporterHeader(DisplayName = "车身ID")]
        [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "车身ID")]
        public int carBodyID { get; set; }
        /// <summary>
        /// PVI码
        /// </summary>
        [ImporterHeader(Name = "PVI码")]
        [ExporterHeader(DisplayName = "PVI码")]
        [SugarColumn(IsNullable = true, ColumnDescription = "PVI码")]
        public string PVI { get; set; }
        /// <summary>
        /// æ»‘橇号
        /// </summary>
        [ImporterHeader(Name = "滑橇号")]
        [ExporterHeader(DisplayName = "滑橇号")]
        [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "滑橇号")]
        public string PalletCode { get; set; }
        /// <summary>
        /// è½¦åž‹
        /// </summary>
        [ImporterHeader(Name = "车型")]
        [ExporterHeader(DisplayName = "车型")]
        [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "车型")]
        public string vehicleCharacteristic { get; set; }
        /// <summary>
        /// è½¦èº«ç±»åž‹  1-白 2-彩 3-空滑橇 4-空撬组
        /// </summary>
        [ImporterHeader(Name = "车身类型")]
        [ExporterHeader(DisplayName = "车身类型")]
        [SugarColumn(IsNullable = true, ColumnDescription = "车身类型")]
        public int CarType { get; set; }
        /// <summary>
        /// è®¢å•类型
        /// </summary>
        [ImporterHeader(Name = "订单类型")]
        [ExporterHeader(DisplayName = "订单类型")]
        [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "订单类型")]
        public string workOrderType { get; set; }
        /// <summary>
        /// å¤©çª—特征
        /// </summary>
        [ImporterHeader(Name = "天窗特征")]
        [ExporterHeader(DisplayName = "天窗特征")]
        [SugarColumn(IsNullable = true, Length = 40, ColumnDescription = "天窗特征")]
        public string skylightCharacteristic { get; set; }
        /// <summary>
        /// è½¦èº«é¢œè‰²
        /// </summary>
        [ImporterHeader(Name = "车身颜色")]
        [ExporterHeader(DisplayName = "车身颜色")]
        [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "车身颜色")]
        public string carBodyCharacteristic { get; set; }
        /// <summary>
        /// ç™½è½¦èº«ç‰©æ–™å·
        /// </summary>
        [ImporterHeader(Name = "白车身物料号")]
        [ExporterHeader(DisplayName = "白车身物料号")]
        [SugarColumn(IsNullable = true, Length = 40, ColumnDescription = "白车身物料号")]
        public string biwMaterialCode { get; set; }
        /// <summary>
        /// å½©è½¦èº«ç‰©æ–™å·
        /// </summary>
        [ImporterHeader(Name = "彩车身物料号")]
        [ExporterHeader(DisplayName = "彩车身物料号")]
        [SugarColumn(IsNullable = true, Length = 40, ColumnDescription = "彩车身物料号")]
        public string pbMaterial { get; set; }
        /// <summary>
        /// ç„Šè£…上线时间
        /// </summary>
        [ImporterHeader(Name = "焊装上线时间")]
        [ExporterHeader(DisplayName = "焊装上线时间")]
        [SugarColumn(IsNullable = true, Length = 40, ColumnDescription = "焊装上线时间")]
        public DateTime? biwInPassTime { get; set; }
        /// <summary>
        /// é”å®šçŠ¶æ€   0-未锁定 1-锁定
        /// </summary>
        [ImporterHeader(Name = "锁定状态")]
        [ExporterHeader(DisplayName = "锁定状态")]
        [SugarColumn(IsNullable = true, ColumnDescription = "锁定状态")]
        public int StockStatus { get; set; }
        /// <summary>
        /// æ‹‰åŠ¨é”å®š  0-未拉动 1-拉动
        /// </summary>
        [ImporterHeader(Name = "拉动锁定")]
        [ExporterHeader(DisplayName = "拉动锁定")]
        [SugarColumn(IsNullable = true, ColumnDescription = "拉动锁定")]
        public int LockOrder { get; set; }
        /// <summary>
        /// ä»»åŠ¡çŠ¶æ€ 0-无任务 1-任务中
        /// </summary>
        [ImporterHeader(Name = "任务状态")]
        [ExporterHeader(DisplayName = "任务状态")]
        [SugarColumn(IsNullable = true, ColumnDescription = "任务状态")]
        public int TaskStatus { get; set; }
        /// <summary>
        /// ä¿ç•™çŠ¶æ€
        /// </summary>
        [ImporterHeader(Name = "保留状态")]
        [ExporterHeader(DisplayName = "保留状态")]
        [SugarColumn(IsNullable = true, ColumnDescription = "保留状态")]
        public int StayStatus { get; set; }
        /// <summary>
        /// æ‰€å±žå·¥å•(预绑定)
        /// </summary>
        //[ImporterHeader(Name = "所属工单")]
        //[ExporterHeader(DisplayName = "所属工单")]
        //[SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "所属工单")]
        //public string OrderID { get; set; }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_Model/Models/BasicModel/Stock/VV_StockInfo.cs
@@ -9,7 +9,7 @@
namespace WIDESEA_Model.Models
{
    [SugarTable(nameof(VV_StockInfo), "库存信息")]
    //[SugarTable(nameof(VV_StockInfo), "库存信息")]
    public class VV_StockInfo
    {
        /// <summary>
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StoragIntegrationServices/MES/Partial/removeWorkOrderInfo.cs
@@ -44,6 +44,9 @@
                    {
                        var orderinfo = _assemblyOrderInfoRepository.QueryFirst(x => x.workOrderNo == item.workOrderNo && x.orderType == item.orderType);
                        if (orderinfo == null) throw new Exception($"未找到工单号{item.workOrderNo}工单类型为{item.orderType}的总装工单");
                        if (!string.IsNullOrEmpty(orderinfo.pvi)) throw new Exception($"总装工单号{item.workOrderNo}已拉动锁车的车身工单不支持撤排");
                        _assemblyOrderInfoRepository.DeleteData(orderinfo);
                    }
                }
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StoragIntegrationServices/WCS/Partial/Queue.cs
@@ -9,6 +9,7 @@
using WIDESEA_Common.MES;
using WIDESEA_Core;
using WIDESEA_DTO;
using WIDESEA_StorageBasicRepository;
namespace WIDESEA_StoragIntegrationServices
{
@@ -49,7 +50,7 @@
                //过点信息
                WebResponseContent content1 = _mesService.PassPoint(json);
                if (!content1.Status) throw new Exception($"过点失败:{content1.msg},请求信息:{{json.ToJson()");
                if (!content1.Status) throw new Exception($"过点失败:{content1.msg},请求信息:{json.ToJson()}");
                //获取VIN号
                WebResponseContent responseContent = _mesService.getCharacteristic(json);
@@ -64,6 +65,13 @@
                    VechicleModel = carinfo.vehicleCharacteristic,
                };
                var mesLock = _mesLockInfoRepository.QueryFirst(x => x.carBodyID == carinfo.Id);
                if (mesLock != null)
                {
                    mesLock.LockStatue = 2;
                    _mesLockInfoRepository.UpdateData(mesLock);
                }
                content.OK(data: respon);
            }
            catch (Exception ex)
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StoragIntegrationServices/WCS/Partial/TZPassZZ.cs
@@ -17,7 +17,7 @@
            WebResponseContent content = new WebResponseContent();
            try
            {
                var carInfo = _carBodyInfoRepository.QueryFirst(x => x.RFID == json.Rfid);  ///*x.PalletCode == json.PalletCode ||*/
                var carInfo = _carBodyInfoRepository.QueryFirst(x => x.RFID == json.PVI);  ///*x.PalletCode == json.PalletCode ||*/
                if (carInfo != null) throw new Exception($"涂装直通总装失败:PVI{json.Rfid}已存在。");
                WebResponseContent responseContent = _mesService.issuedCharacter(json.PVI, json.Position, json.PalletCode);
@@ -30,20 +30,20 @@
                //json.PVI = json.PVI.Substring(0, 9);
                json.Position = "RB001";
                WebResponseContent content1 = _mesService.PassPoint(json);
                if (!content1.Status) throw new Exception($"过点失败:{content1.msg}");
                if (!content1.Status) throw new Exception($"BDC02过点失败:{content1.msg}");
                WebResponseContent webResponse = _mesService.bindWorkOrder("EL01RB", json.PVI);
                if (!responseContent.Status) throw new Exception($"绑定失败:{webResponse.msg}");
                if (!responseContent.Status) throw new Exception($"焊涂绑定失败:{webResponse.msg}");
                //过点信息 -BDC02
                json.Position = "EL01RB";
                WebResponseContent BDC02 = _mesService.PassPoint(json);
                if (!BDC02.Status) throw new Exception($"过点失败:{BDC02.msg}");
                if (!BDC02.Status) throw new Exception($"BDC02过点失败:{BDC02.msg}");
                ////过点信息 -BDC03
                json.Position = "EL01RB01";
                WebResponseContent BDC03 = _mesService.PassPoint(json);
                if (!BDC03.Status) throw new Exception($"过点失败:{BDC03.msg}");
                if (!BDC03.Status) throw new Exception($"BDC03过点失败:{BDC03.msg}");
                content.OK();
            }
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StoragIntegrationServices/WCS/WCSService.cs
@@ -32,7 +32,7 @@
        private readonly LogFactory LogFactory = new LogFactory();
        public WCSService(ILocationInfoRepository locationRepository, IDt_TaskRepository taskRepository, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository, IMESService mesService, IDt_PalletStockInfoRepository palletStockInfoRepository, IDt_CarBodyInfoRepository carBodyInfoRepository, IDt_RoadWayInfoRepository roadWayInfoRepository, IDt_RoadWayRepository roadWayRepository, IDt_TaskService taskService, IUnitOfWorkManage unitOfWorkManage)
        public WCSService(ILocationInfoRepository locationRepository, IDt_TaskRepository taskRepository, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository, IMESService mesService, IDt_PalletStockInfoRepository palletStockInfoRepository, IDt_CarBodyInfoRepository carBodyInfoRepository, IDt_RoadWayInfoRepository roadWayInfoRepository, IDt_RoadWayRepository roadWayRepository, IDt_TaskService taskService, IUnitOfWorkManage unitOfWorkManage,IDt_MESLockInfoRepository mesLockInfoRepository)
        {
            _locationRepository = locationRepository;
            _taskRepository = taskRepository;
@@ -45,6 +45,7 @@
            _roadWayRepository = roadWayRepository;
            _taskService = taskService;
            _unitOfWorkManage = unitOfWorkManage;
            _mesLockInfoRepository = mesLockInfoRepository;
        }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StorageTaskServices/AutoTask/AspNetCoreSchedule.cs
@@ -1,7 +1,9 @@
using Masuit.Tools;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.Const;
using WIDESEA_DTO.WMS;
using WIDESEA_IServices;
@@ -13,36 +15,27 @@
{
    public class MyBackgroundService : IHostedService, IDisposable
    {
        private readonly ILogger<MyBackgroundService> _logger;
        private readonly IDt_PalletStockInfoRepository _palletStockInfoRepository;
        private readonly IDt_AreaInfoRepository _areaInfoRepository; //区域
        private readonly IDt_TaskRepository _taskRepository;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ISys_ConfigService _configService;
        private readonly ILocationInfoRepository _locationRepository;
        private readonly IVV_StockInfoRepository _VVStockInfoRepository;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IDt_MESLockInfoRepository _MESLockInfoRepository;
        private ILogger<MyBackgroundService> _logger;
        private IDt_PalletStockInfoRepository _palletStockInfoRepository;
        private IDt_AreaInfoRepository _areaInfoRepository; //区域
        private IDt_TaskRepository _taskRepository;
        private IDt_StationManagerRepository _stationManagerRepository;
        private ISys_ConfigService _configService;
        private ILocationInfoRepository _locationRepository;
        private IVV_StockInfoRepository _VVStockInfoRepository;
        private IUnitOfWorkManage _unitOfWorkManage;
        private IDt_MESLockInfoRepository _MESLockInfoRepository;
        private Timer _timer;
        public MyBackgroundService(ILogger<MyBackgroundService> logger, ILocationInfoRepository locationRepository, IDt_AreaInfoRepository areaInfoRepository, IDt_TaskRepository taskRepository, IDt_StationManagerRepository stationManagerRepository, ISys_ConfigService configService, IDt_PalletStockInfoRepository palletStockInfoRepository, IVV_StockInfoRepository VV_StockInfoRepository, IUnitOfWorkManage unitOfWorkManage, IDt_MESLockInfoRepository MESLockInfoRepository)
        public MyBackgroundService(/*ILogger<MyBackgroundService> logger, ILocationInfoRepository locationRepository, IDt_AreaInfoRepository areaInfoRepository, IDt_TaskRepository taskRepository, IDt_StationManagerRepository stationManagerRepository, ISys_ConfigService configService, IDt_PalletStockInfoRepository palletStockInfoRepository, IVV_StockInfoRepository VV_StockInfoRepository, IUnitOfWorkManage unitOfWorkManage, IDt_MESLockInfoRepository MESLockInfoRepository*/)
        {
            _logger = logger;
            _locationRepository = locationRepository;
            _areaInfoRepository = areaInfoRepository;
            _taskRepository = taskRepository;
            _stationManagerRepository = stationManagerRepository;
            _configService = configService;
            _palletStockInfoRepository = palletStockInfoRepository;
            _VVStockInfoRepository = VV_StockInfoRepository;
            _unitOfWorkManage = unitOfWorkManage;
            _MESLockInfoRepository = MESLockInfoRepository;
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(5));
            //_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
            return Task.CompletedTask;
        }
@@ -50,6 +43,17 @@
        {
            try
            {
                IServiceScope scope = App.RootServices.CreateScope();
                _logger = scope.ServiceProvider.GetService<ILogger<MyBackgroundService>>();
                _locationRepository = scope.ServiceProvider.GetService<ILocationInfoRepository>();
                _areaInfoRepository = scope.ServiceProvider.GetService<IDt_AreaInfoRepository>();
                _taskRepository = scope.ServiceProvider.GetService<IDt_TaskRepository>();
                _stationManagerRepository = scope.ServiceProvider.GetService<IDt_StationManagerRepository>();
                _configService = scope.ServiceProvider.GetService<ISys_ConfigService>();
                _palletStockInfoRepository = scope.ServiceProvider.GetService<IDt_PalletStockInfoRepository>();
                _VVStockInfoRepository = scope.ServiceProvider.GetService<IVV_StockInfoRepository>();
                _unitOfWorkManage = scope.ServiceProvider.GetService<IUnitOfWorkManage>();
                _MESLockInfoRepository = scope.ServiceProvider.GetService<IDt_MESLockInfoRepository>();
                //var area = _areaInfoRepository.QueryFirst(x => x.AreaCode == "GWSC1");
                //if (area == null) { return; }
@@ -69,107 +73,198 @@
                if (lockInfo.Where(x => x.LockStatue == 1).Count() > 10) return;
                if (lockInfo.Count == 0) return;
                var lockCar = lockInfo.Where(x => x.LockStatue == 0).First();
                foreach (var item in lockInfo)
                var lockCar = lockInfo.Where(x => x.LockStatue == 0).FirstOrDefault();
                if (lockCar == null) return;
                var hasTask = _taskRepository.QueryFirst(x => x.PalletCode == lockCar.CarBodyInfo.PalletCode);
                if (hasTask != null)
                {
                    var hasTask = _taskRepository.QueryFirst(x => x.PalletCode == item.CarBodyInfo.PalletCode);
                    if (hasTask != null)
                    {
                        Console.WriteLine("已存在出库任务");
                        continue;
                    }
                    List<Dt_StationManager> stationLists = null;
                    if (item.CarBodyInfo.CarType == 1)
                    {
                        stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "3");
                    }
                    else if (item.CarBodyInfo.CarType == 2)
                    {
                        stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "4");
                    }
                    //else if (item.CarBodyInfo.CarType == 3)
                    //{
                    //    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 7 && x.stationStatus == "1" && x.stationArea == "3");
                    //}
                    var stock = _VVStockInfoRepository.QueryFirst(x => x.carBodyID == item.carBodyID);
                    var lockStock = _palletStockInfoRepository.QueryFirst(x => x.carBodyID == item.carBodyID);
                    var location = _locationRepository.QueryFirst(x => x.LocationCode == stock.LocationCode);
                    location.LocationStatus = (int)LocationEnum.InStockDisable;
                    item.LockStatue = 1;
                    lockStock.TaskStatus = 1;
                    if (stationLists == null || stationLists.Count == 0) throw new Exception("出库站台未配置或未启用");
                    Dt_StationManager Outstation = null;
                    //if (stationLists.Count > 1)
                    //{
                    //    var Outtask = BaseDal.QueryData(x => x.Roadway == stationLists.FirstOrDefault().Roadway && x.TaskType == (int)TaskTypeEnum.Outbound).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                    //    if (Outtask != null) Outstation = stationLists.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != Outtask.CurrentAddress).FirstOrDefault();
                    //    else Outstation = stationLists.FirstOrDefault();
                    //}
                    //else
                    //{
                    Outstation = stationLists.FirstOrDefault();
                    //}
                    //var stationInfo = stationInfos.FirstOrDefault();
                    // åˆ›å»ºå¹¶æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                    hasTask = new Dt_Task
                    {
                        Grade = 1,
                        Roadway = Outstation.Roadway,
                        TargetAddress = "RB043",
                        Dispatchertime = DateTime.Now,
                        NextAddress = Outstation.stationChildCode,
                        OrderNo = null,
                        PalletCode = stock.PalletCode,
                        PVI = stock.PVI,
                        SourceAddress = stock.LocationCode,
                        CurrentAddress = stock.LocationCode,
                        TaskState = (int)TaskOutStatusEnum.OutNew,
                        TaskType = (int)TaskOutboundTypeEnum.Outbound,
                        TaskNum = _taskRepository.GetTaskNo().Result,
                        Creater = "System",
                        CreateDate = DateTime.Now,
                        TaskId = 0,
                    };
                    // åˆ›å»ºä»»åŠ¡ä¼ è¾“ç”¨çš„DTO对象
                    var taskDTO = CreateTaskDTO(hasTask);
                    // èŽ·å–WMS IP地址用于发送任务请求
                    var wmsIpAddress = GetWCSIpReceiveTask();
                    if (wmsIpAddress == null)
                    {
                        throw new InvalidOperationException("WMS IP æœªé…ç½®");
                    }
                    var tasks = new List<WMSTaskDTO>() { taskDTO };
                    // å‘送任务请求到WMS
                    var result = HttpHelper.PostAsync(wmsIpAddress, tasks.ToJsonString()).Result;
                    WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                    if (content.Status)
                    {
                        _unitOfWorkManage.BeginTran();
                        // æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                        _taskRepository.AddData(hasTask);
                        // æ›´æ–°åº“位位置状态为不可用
                        _locationRepository.UpdateData(location);
                        _MESLockInfoRepository.UpdateData(item);
                        _palletStockInfoRepository.UpdateData(lockStock);
                        _unitOfWorkManage.CommitTran();
                    }
                    Console.WriteLine("已存在出库任务");
                    return;
                }
                List<Dt_StationManager> stationLists = null;
                if (lockCar.CarBodyInfo.CarType == 1)
                {
                    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == lockCar.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "3");
                }
                else if (lockCar.CarBodyInfo.CarType == 2)
                {
                    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == lockCar.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "4");
                }
                //else if (item.CarBodyInfo.CarType == 3)
                //{
                //    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 7 && x.stationStatus == "1" && x.stationArea == "3");
                //}
                var stock = _VVStockInfoRepository.QueryFirst(x => x.carBodyID == lockCar.carBodyID);
                var lockStock = _palletStockInfoRepository.QueryFirst(x => x.carBodyID == lockCar.carBodyID);
                var location = _locationRepository.QueryFirst(x => x.LocationCode == stock.LocationCode);
                location.LocationStatus = (int)LocationEnum.InStockDisable;
                lockCar.LockStatue = 1;
                lockStock.TaskStatus = 1;
                if (stationLists == null || stationLists.Count == 0) throw new Exception("出库站台未配置或未启用");
                Dt_StationManager Outstation = null;
                //if (stationLists.Count > 1)
                //{
                //    var Outtask = BaseDal.QueryData(x => x.Roadway == stationLists.FirstOrDefault().Roadway && x.TaskType == (int)TaskTypeEnum.Outbound).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                //    if (Outtask != null) Outstation = stationLists.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != Outtask.CurrentAddress).FirstOrDefault();
                //    else Outstation = stationLists.FirstOrDefault();
                //}
                //else
                //{
                Outstation = stationLists.FirstOrDefault();
                //}
                //var stationInfo = stationInfos.FirstOrDefault();
                // åˆ›å»ºå¹¶æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                hasTask = new Dt_Task
                {
                    Grade = 1,
                    Roadway = Outstation.Roadway,
                    TargetAddress = "RB043",
                    Dispatchertime = DateTime.Now,
                    NextAddress = Outstation.stationChildCode,
                    OrderNo = null,
                    PalletCode = stock.PalletCode,
                    PVI = stock.PVI,
                    SourceAddress = stock.LocationCode,
                    CurrentAddress = stock.LocationCode,
                    TaskState = (int)TaskOutStatusEnum.OutNew,
                    TaskType = (int)TaskOutboundTypeEnum.Outbound,
                    TaskNum = _taskRepository.GetTaskNo().Result,
                    Creater = "System",
                    CreateDate = DateTime.Now,
                    TaskId = 0,
                };
                // åˆ›å»ºä»»åŠ¡ä¼ è¾“ç”¨çš„DTO对象
                var taskDTO = CreateTaskDTO(hasTask);
                // èŽ·å–WMS IP地址用于发送任务请求
                var wmsIpAddress = GetWCSIpReceiveTask();
                if (wmsIpAddress == null)
                {
                    throw new InvalidOperationException("WMS IP æœªé…ç½®");
                }
                var tasks = new List<WMSTaskDTO>() { taskDTO };
                // å‘送任务请求到WMS
                var result = HttpHelper.PostAsync(wmsIpAddress, tasks.ToJsonString()).Result;
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                if (content.Status)
                {
                    _unitOfWorkManage.BeginTran();
                    // æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                    _taskRepository.AddData(hasTask);
                    // æ›´æ–°åº“位位置状态为不可用
                    _locationRepository.UpdateData(location);
                    _MESLockInfoRepository.UpdateData(lockCar);
                    _palletStockInfoRepository.UpdateData(lockStock);
                    _unitOfWorkManage.CommitTran();
                }
                //foreach (var item in lockInfo)
                //{
                //    var hasTask = _taskRepository.QueryFirst(x => x.PalletCode == item.CarBodyInfo.PalletCode);
                //    if (hasTask != null)
                //    {
                //        Console.WriteLine("已存在出库任务");
                //        continue;
                //    }
                //    List<Dt_StationManager> stationLists = null;
                //    if (item.CarBodyInfo.CarType == 1)
                //    {
                //        stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "3");
                //    }
                //    else if (item.CarBodyInfo.CarType == 2)
                //    {
                //        stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "4");
                //    }
                //    //else if (item.CarBodyInfo.CarType == 3)
                //    //{
                //    //    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 7 && x.stationStatus == "1" && x.stationArea == "3");
                //    //}
                //    var stock = _VVStockInfoRepository.QueryFirst(x => x.carBodyID == item.carBodyID);
                //    var lockStock = _palletStockInfoRepository.QueryFirst(x => x.carBodyID == item.carBodyID);
                //    var location = _locationRepository.QueryFirst(x => x.LocationCode == stock.LocationCode);
                //    location.LocationStatus = (int)LocationEnum.InStockDisable;
                //    item.LockStatue = 1;
                //    lockStock.TaskStatus = 1;
                //    if (stationLists == null || stationLists.Count == 0) throw new Exception("出库站台未配置或未启用");
                //    Dt_StationManager Outstation = null;
                //    //if (stationLists.Count > 1)
                //    //{
                //    //    var Outtask = BaseDal.QueryData(x => x.Roadway == stationLists.FirstOrDefault().Roadway && x.TaskType == (int)TaskTypeEnum.Outbound).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                //    //    if (Outtask != null) Outstation = stationLists.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != Outtask.CurrentAddress).FirstOrDefault();
                //    //    else Outstation = stationLists.FirstOrDefault();
                //    //}
                //    //else
                //    //{
                //    Outstation = stationLists.FirstOrDefault();
                //    //}
                //    //var stationInfo = stationInfos.FirstOrDefault();
                //    // åˆ›å»ºå¹¶æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                //    hasTask = new Dt_Task
                //    {
                //        Grade = 1,
                //        Roadway = Outstation.Roadway,
                //        TargetAddress = "RB043",
                //        Dispatchertime = DateTime.Now,
                //        NextAddress = Outstation.stationChildCode,
                //        OrderNo = null,
                //        PalletCode = stock.PalletCode,
                //        PVI = stock.PVI,
                //        SourceAddress = stock.LocationCode,
                //        CurrentAddress = stock.LocationCode,
                //        TaskState = (int)TaskOutStatusEnum.OutNew,
                //        TaskType = (int)TaskOutboundTypeEnum.Outbound,
                //        TaskNum = _taskRepository.GetTaskNo().Result,
                //        Creater = "System",
                //        CreateDate = DateTime.Now,
                //        TaskId = 0,
                //    };
                //    // åˆ›å»ºä»»åŠ¡ä¼ è¾“ç”¨çš„DTO对象
                //    var taskDTO = CreateTaskDTO(hasTask);
                //    // èŽ·å–WMS IP地址用于发送任务请求
                //    var wmsIpAddress = GetWCSIpReceiveTask();
                //    if (wmsIpAddress == null)
                //    {
                //        throw new InvalidOperationException("WMS IP æœªé…ç½®");
                //    }
                //    var tasks = new List<WMSTaskDTO>() { taskDTO };
                //    // å‘送任务请求到WMS
                //    var result = HttpHelper.PostAsync(wmsIpAddress, tasks.ToJsonString()).Result;
                //    WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                //    if (content.Status)
                //    {
                //        _unitOfWorkManage.BeginTran();
                //        // æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                //        _taskRepository.AddData(hasTask);
                //        // æ›´æ–°åº“位位置状态为不可用
                //        _locationRepository.UpdateData(location);
                //        _MESLockInfoRepository.UpdateData(item);
                //        _palletStockInfoRepository.UpdateData(lockStock);
                //        _unitOfWorkManage.CommitTran();
                //    }
                //}
            }
            catch (Exception ex)
            {
                ConsoleHelper.WriteErrorLine($",错误信息:" + ex.Message);
                ConsoleHelper.WriteErrorLine($"拉动锁车出车错误信息:" + ex.Message);
            }
            ConsoleHelper.WriteSuccessLine($":" + DateTime.Now.ToString());
            ConsoleHelper.WriteSuccessLine($"拉动锁车:" + DateTime.Now.ToString());
        }
        public Task StopAsync(CancellationToken cancellationToken)
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StorageTaskServices/AutoTask/BackgroundJob.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,327 @@
using Masuit.Tools;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.Const;
using WIDESEA_DTO.WMS;
using WIDESEA_IServices;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Model.Models;
namespace WIDESEA_StorageTaskServices
{
    [DisallowConcurrentExecution]
    public class BackgroundJob : IJob
    {
        private ILogger<BackgroundJob> _logger;
        private IDt_PalletStockInfoRepository _palletStockInfoRepository;
        private IDt_AreaInfoRepository _areaInfoRepository; //区域
        private IDt_TaskRepository _taskRepository;
        private IDt_StationManagerRepository _stationManagerRepository;
        private ISys_ConfigService _configService;
        private ILocationInfoRepository _locationRepository;
        private IVV_StockInfoRepository _VVStockInfoRepository;
        private IUnitOfWorkManage _unitOfWorkManage;
        private IDt_MESLockInfoRepository _MESLockInfoRepository;
        public BackgroundJob(ILogger<BackgroundJob> logger, IDt_PalletStockInfoRepository palletStockInfoRepository, IDt_AreaInfoRepository areaInfoRepository, IDt_TaskRepository taskRepository, IDt_StationManagerRepository stationManagerRepository, ISys_ConfigService configService, ILocationInfoRepository locationRepository, IVV_StockInfoRepository vVStockInfoRepository, IUnitOfWorkManage unitOfWorkManage, IDt_MESLockInfoRepository mESLockInfoRepository)
        {
            _logger = logger;
            _palletStockInfoRepository = palletStockInfoRepository;
            _areaInfoRepository = areaInfoRepository;
            _taskRepository = taskRepository;
            _stationManagerRepository = stationManagerRepository;
            _configService = configService;
            _locationRepository = locationRepository;
            _VVStockInfoRepository = vVStockInfoRepository;
            _unitOfWorkManage = unitOfWorkManage;
            _MESLockInfoRepository = mESLockInfoRepository;
        }
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                //var area = _areaInfoRepository.QueryFirst(x => x.AreaCode == "GWSC1");
                //if (area == null) { return; }
                //IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
                //List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
                //var stockInfo = stockInfoList.Where(x => x.AreaCode == area.AreaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) // è¿‡æ»¤æ¡ä»¶
                //     .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID) // è¿‡æ»¤æ¡ä»¶
                //     .OrderBy(x => x.OutboundTime) // æŽ’序
                //     .ToList(); // èŽ·å–ç¬¬ä¸€ä¸ªå…ƒç´ 
                var lockInfo = _palletStockInfoRepository.Db.Queryable<Dt_MESLockInfo>()
                    //.Where(x => x.LockStatue == 0)
                    .Includes(x => x.CarBodyInfo)
                    .OrderBy(x => x.sequenceNo) // æŽ’序
                    .ToList(); // èŽ·å–ç¬¬ä¸€ä¸ªå…ƒç´ 
                if (lockInfo.Where(x => x.LockStatue == 1).Count() > 10) return Task.CompletedTask;
                if (lockInfo.Count == 0) return Task.CompletedTask;
                var lockCar = lockInfo.Where(x => x.LockStatue == 0).FirstOrDefault();
                if (lockCar == null) return Task.CompletedTask;
                var hasTask = _taskRepository.QueryFirst(x => x.PalletCode == lockCar.CarBodyInfo.PalletCode);
                if (hasTask != null)
                {
                    Console.WriteLine("已存在出库任务");
                    return Task.CompletedTask;
                }
                List<Dt_StationManager> stationLists = null;
                if (lockCar.CarBodyInfo.CarType == 1)
                {
                    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == lockCar.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "3");
                }
                else if (lockCar.CarBodyInfo.CarType == 2)
                {
                    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == lockCar.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "4");
                }
                //else if (item.CarBodyInfo.CarType == 3)
                //{
                //    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 7 && x.stationStatus == "1" && x.stationArea == "3");
                //}
                var stock = _VVStockInfoRepository.QueryFirst(x => x.carBodyID == lockCar.carBodyID);
                var lockStock = _palletStockInfoRepository.QueryFirst(x => x.carBodyID == lockCar.carBodyID);
                var location = _locationRepository.QueryFirst(x => x.LocationCode == stock.LocationCode);
                location.LocationStatus = (int)LocationEnum.InStockDisable;
                lockCar.LockStatue = 1;
                lockStock.TaskStatus = 1;
                if (stationLists == null || stationLists.Count == 0) throw new Exception("出库站台未配置或未启用");
                Dt_StationManager Outstation = null;
                //if (stationLists.Count > 1)
                //{
                //    var Outtask = BaseDal.QueryData(x => x.Roadway == stationLists.FirstOrDefault().Roadway && x.TaskType == (int)TaskTypeEnum.Outbound).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                //    if (Outtask != null) Outstation = stationLists.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != Outtask.CurrentAddress).FirstOrDefault();
                //    else Outstation = stationLists.FirstOrDefault();
                //}
                //else
                //{
                Outstation = stationLists.FirstOrDefault();
                //}
                //var stationInfo = stationInfos.FirstOrDefault();
                // åˆ›å»ºå¹¶æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                hasTask = new Dt_Task
                {
                    Grade = 1,
                    Roadway = Outstation.Roadway,
                    TargetAddress = "RB043",
                    Dispatchertime = DateTime.Now,
                    NextAddress = Outstation.stationChildCode,
                    OrderNo = null,
                    PalletCode = stock.PalletCode,
                    PVI = stock.PVI,
                    SourceAddress = stock.LocationCode,
                    CurrentAddress = stock.LocationCode,
                    TaskState = (int)TaskOutStatusEnum.OutNew,
                    TaskType = (int)TaskOutboundTypeEnum.Outbound,
                    TaskNum = _taskRepository.GetTaskNo().Result,
                    Creater = "System",
                    CreateDate = DateTime.Now,
                    TaskId = 0,
                };
                // åˆ›å»ºä»»åŠ¡ä¼ è¾“ç”¨çš„DTO对象
                var taskDTO = CreateTaskDTO(hasTask);
                // èŽ·å–WMS IP地址用于发送任务请求
                var wmsIpAddress = GetWCSIpReceiveTask();
                if (wmsIpAddress == null)
                {
                    throw new InvalidOperationException("WMS IP æœªé…ç½®");
                }
                var tasks = new List<WMSTaskDTO>() { taskDTO };
                // å‘送任务请求到WMS
                var result = HttpHelper.PostAsync(wmsIpAddress, tasks.ToJsonString()).Result;
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                if (content.Status)
                {
                    _unitOfWorkManage.BeginTran();
                    // æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                    _taskRepository.AddData(hasTask);
                    // æ›´æ–°åº“位位置状态为不可用
                    _locationRepository.UpdateData(location);
                    _MESLockInfoRepository.UpdateData(lockCar);
                    _palletStockInfoRepository.UpdateData(lockStock);
                    _unitOfWorkManage.CommitTran();
                }
                //foreach (var item in lockInfo)
                //{
                //    var hasTask = _taskRepository.QueryFirst(x => x.PalletCode == item.CarBodyInfo.PalletCode);
                //    if (hasTask != null)
                //    {
                //        Console.WriteLine("已存在出库任务");
                //        continue;
                //    }
                //    List<Dt_StationManager> stationLists = null;
                //    if (item.CarBodyInfo.CarType == 1)
                //    {
                //        stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "3");
                //    }
                //    else if (item.CarBodyInfo.CarType == 2)
                //    {
                //        stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "4");
                //    }
                //    //else if (item.CarBodyInfo.CarType == 3)
                //    //{
                //    //    stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == item.TCLine && x.stationType == 7 && x.stationStatus == "1" && x.stationArea == "3");
                //    //}
                //    var stock = _VVStockInfoRepository.QueryFirst(x => x.carBodyID == item.carBodyID);
                //    var lockStock = _palletStockInfoRepository.QueryFirst(x => x.carBodyID == item.carBodyID);
                //    var location = _locationRepository.QueryFirst(x => x.LocationCode == stock.LocationCode);
                //    location.LocationStatus = (int)LocationEnum.InStockDisable;
                //    item.LockStatue = 1;
                //    lockStock.TaskStatus = 1;
                //    if (stationLists == null || stationLists.Count == 0) throw new Exception("出库站台未配置或未启用");
                //    Dt_StationManager Outstation = null;
                //    //if (stationLists.Count > 1)
                //    //{
                //    //    var Outtask = BaseDal.QueryData(x => x.Roadway == stationLists.FirstOrDefault().Roadway && x.TaskType == (int)TaskTypeEnum.Outbound).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                //    //    if (Outtask != null) Outstation = stationLists.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != Outtask.CurrentAddress).FirstOrDefault();
                //    //    else Outstation = stationLists.FirstOrDefault();
                //    //}
                //    //else
                //    //{
                //    Outstation = stationLists.FirstOrDefault();
                //    //}
                //    //var stationInfo = stationInfos.FirstOrDefault();
                //    // åˆ›å»ºå¹¶æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                //    hasTask = new Dt_Task
                //    {
                //        Grade = 1,
                //        Roadway = Outstation.Roadway,
                //        TargetAddress = "RB043",
                //        Dispatchertime = DateTime.Now,
                //        NextAddress = Outstation.stationChildCode,
                //        OrderNo = null,
                //        PalletCode = stock.PalletCode,
                //        PVI = stock.PVI,
                //        SourceAddress = stock.LocationCode,
                //        CurrentAddress = stock.LocationCode,
                //        TaskState = (int)TaskOutStatusEnum.OutNew,
                //        TaskType = (int)TaskOutboundTypeEnum.Outbound,
                //        TaskNum = _taskRepository.GetTaskNo().Result,
                //        Creater = "System",
                //        CreateDate = DateTime.Now,
                //        TaskId = 0,
                //    };
                //    // åˆ›å»ºä»»åŠ¡ä¼ è¾“ç”¨çš„DTO对象
                //    var taskDTO = CreateTaskDTO(hasTask);
                //    // èŽ·å–WMS IP地址用于发送任务请求
                //    var wmsIpAddress = GetWCSIpReceiveTask();
                //    if (wmsIpAddress == null)
                //    {
                //        throw new InvalidOperationException("WMS IP æœªé…ç½®");
                //    }
                //    var tasks = new List<WMSTaskDTO>() { taskDTO };
                //    // å‘送任务请求到WMS
                //    var result = HttpHelper.PostAsync(wmsIpAddress, tasks.ToJsonString()).Result;
                //    WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                //    if (content.Status)
                //    {
                //        _unitOfWorkManage.BeginTran();
                //        // æ·»åŠ ä»»åŠ¡åˆ°æ•°æ®åº“
                //        _taskRepository.AddData(hasTask);
                //        // æ›´æ–°åº“位位置状态为不可用
                //        _locationRepository.UpdateData(location);
                //        _MESLockInfoRepository.UpdateData(item);
                //        _palletStockInfoRepository.UpdateData(lockStock);
                //        _unitOfWorkManage.CommitTran();
                //    }
                //}
            }
            catch (Exception ex)
            {
                ConsoleHelper.WriteErrorLine($"拉动锁车出车错误信息:" + ex.Message);
            }
            finally
            {
                ConsoleHelper.WriteSuccessLine($"拉动锁车:" + DateTime.Now.ToString());
            }
            return Task.CompletedTask;
        }
        /// <summary>
        /// åˆ›å»ºä»»åŠ¡å®žä¾‹
        /// </summary>
        private Dt_Task CreateTask(DtStockInfo stockInfo, string position, int tag)
        {
            return new Dt_Task
            {
                Grade = 1,
                Roadway = stockInfo.LocationInfo.RoadwayNo,
                TargetAddress = position,
                Dispatchertime = DateTime.Now,
                NextAddress = position,
                OrderNo = null,
                PalletCode = stockInfo.PalletCode,
                SourceAddress = stockInfo.LocationCode,
                CurrentAddress = stockInfo.LocationCode,
                TaskState = (int)TaskOutStatusEnum.OutNew,
                TaskType = tag,
                TaskNum = _taskRepository.GetTaskNo().Result,
                Creater = "System", // ä¿®æ­£æ‹¼å†™é”™è¯¯
                CreateDate = DateTime.Now,
                TaskId = 0,
            };
        }
        /// <summary>
        /// åˆ›å»ºä»»åŠ¡DTO
        /// </summary>
        private WMSTaskDTO CreateTaskDTO(Dt_Task task)
        {
            return new WMSTaskDTO
            {
                TaskNum = task.TaskNum.Value,
                Grade = task.Grade.Value,
                PalletCode = task.PalletCode,
                RoadWay = task.Roadway,
                SourceAddress = task.SourceAddress,
                TargetAddress = task.TargetAddress,
                TaskState = task.TaskState.Value,
                Id = 0,
                TaskType = task.TaskType,
                pvi = task.PVI,
                NextAddress = task.NextAddress
            };
        }
        private string GetWCSIpReceiveTask()
        {
            var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveTask)?.ConfigValue;
            if (wmsBase == null || ipAddress == null)
            {
                return null;
            }
            return wmsBase + ipAddress;
        }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StorageTaskServices/AutoTask/QuartzJobMildd.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,64 @@

using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic;
using System.Text;
using WIDESEA.QuartzJob;
using WIDESEA_Core;
using WIDESEA_Core.Helper;
namespace WIDESEA_StorageTaskServices
{
    /// <summary>
    /// Quartz å¯åŠ¨æœåŠ¡
    /// </summary>
    public static class QuartzJobMiddleWare
    {
        public static void UseQuartzJobMildd(this IApplicationBuilder app)
        {
            if (app == null) throw new ArgumentNullException(nameof(app));
            var schedulerCenter = app.ApplicationServices.GetService(typeof(ISchedulerCenter)) as ISchedulerCenter;
            try
            {
                var allQzServices = new List<TasksQz>()
                {
                    new TasksQz()
                    {
                         Id = 1,
                         AssemblyName = "WIDESEA_StorageTaskServices",
                         ClassName = "BackgroundJob",
                         CreateTime = DateTime.Now,
                         IntervalSecond = 10,
                         IsDeleted = false,
                         IsStart = false,
                         JobGroup = "WIDESEA_StorageTaskServices",
                         Name = "BackgroundJob",
                         TriggerType = 0
                    }
                };
                //if(App.HostEnvironment.IsDevelopment())
                //{
                //    return;
                //}
                foreach (var item in allQzServices)
                {
                    var ResuleModel = schedulerCenter.AddScheduleJobAsync(item).Result;
                    if (ResuleModel.Status)
                    {
                        ConsoleHelper.WriteSuccessLine($"{item.ClassName}启动成功");
                    }
                    else
                    {
                        Console.Out.WriteLine($"QuartzNetJob{item.Name}启动失败!错误信息:{ResuleModel.Message}");
                    }
                }
                schedulerCenter.StartScheduleAsync();
            }
            catch (Exception e)
            {
                throw;
            }
        }
    }
}
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_StorageTaskServices/WIDESEA_StorageTaskServices.csproj
@@ -15,6 +15,10 @@
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Quartz" Version="3.16.1" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\LogLibrary\LogLibrary.csproj" />
    <ProjectReference Include="..\WIDESEA_IBusinessServices\WIDESEA_IBusinessServices.csproj" />
    <ProjectReference Include="..\WIDESEA_IStorageBasicService\WIDESEA_IStorageBasicServices.csproj" />
ÏîÄ¿´úÂë/WMS/WMSServer/WIDESEA_WMSServer/Program.cs
@@ -20,6 +20,8 @@
using Swashbuckle.AspNetCore.SwaggerGen;
using Microsoft.OpenApi.Models;
using WIDESEA_StorageTaskServices;
using Quartz.Spi;
using WIDESEA.QuartzJob;
var builder = WebApplication.CreateBuilder(args);
@@ -54,7 +56,10 @@
builder.Services.AddSwaggerSetup();
builder.Services.AddJobSetup();//任务调度 å¯åŠ¨æœåŠ¡
builder.Services.AddSingleton<IJobFactory, JobFactory>();
builder.Services.AddTransient<BackgroundJob>();//Job使用瞬时依赖注入
builder.Services.AddSingleton<ISchedulerCenter, SchedulerCenterServer>();
builder.Services.AddHttpContextSetup();
@@ -115,6 +120,7 @@
var app = builder.Build();
app.UseQuartzJobMildd();
// 3、配置中间件
app.UseMiniProfiler();//性能分析器
app.ConfigureApplication();//配置文件