yanjinhui
2026-03-21 375bad8fd1e5650859456f4b31486d43e4c49371
添加job
已添加2个文件
已修改3个文件
374 ■■■■■ 文件已修改
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/HoistEnum.cs 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITaskInfoService/ITaskService.cs 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/TSJJob.cs 201 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/HoistEnum.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WIDESEAWCS_Common
{
    public enum HoistEnum
    {
        /// <summary>
        /// 3楼入库箱号
        /// </summary>
        Inboxnumber,
        /// <summary>
        /// 3楼入库点料箱有/无
        /// </summary>
        OutboundInplace,
        /// <summary>
        /// 3楼出库料箱到位
        /// </summary>
        SOutboundmaterialbox,
        /// <summary>
        /// 3楼出库料箱缓存数量
        /// </summary>
        Outboundmaterialbox,
        /// <summary>
        /// 4楼空箱箱号
        /// </summary>
        Emptycontainernumber,
        /// <summary>
        /// 4楼回箱料箱有/无
        /// </summary>
        ReturnbinAvailable,
        /// <summary>
        /// 4楼出库料箱到位
        /// </summary>
        FOutboundmaterialbox,
        /// <summary>
        /// è®¾å¤‡çŠ¶æ€
        /// </summary>
        EquipmentStatus,
        /// <summary>
        /// 3楼读码触发
        /// </summary>
        Codereadingtriggered,
        /// <summary>
        /// 3楼入库箱放到位
        /// </summary>
        Inboundboxon,
        /// <summary>
        /// 3楼出库箱取完成
        /// </summary>
        Outboundboxon,
        /// <summary>
        /// 4楼空箱放到位
        /// </summary>
        Emptyboxplacedinposition,
        /// <summary>
        /// 4楼出库取箱完成
        /// </summary>
        Outboundboxretrievalcompleted,
    }
}
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITaskInfoService/ITaskService.cs
@@ -36,6 +36,7 @@
using Microsoft.VisualBasic;
using System.Web;
using WIDESEAWCS_DTO.RGV.FOURBOT;
using WIDESEAWCS_DTO.AGV.HIKROBOT;
namespace WIDESEAWCS_ITaskInfoService
{
@@ -296,5 +297,14 @@
        /// </summary>
        /// <returns></returns>
        WebResponseContent multiSetNodeStatus(FOURBOTStorageStatusNotify fOURBOTStorageStatusNotify);
        /// <summary>
        /// æµ·åº·AGV任务继续执行
        /// </summary>
        /// <param name="TaskCode">任务号</param>
        /// <returns></returns>
        WebResponseContent Hikvisiontaskscontinue(string TaskCode, string Address=null);
    }
}
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/HKTaskMethods.cs
@@ -13,6 +13,7 @@
using WIDESEAWCS_DTO;
using WIDESEAWCS_DTO.AGV.HIKROBOT;
using System.Diagnostics.CodeAnalysis;
using System.Reflection.PortableExecutable;
namespace WIDESEAWCS_TaskInfoService
{
@@ -322,5 +323,65 @@
            }
            return hIKROBOTTaskSubmit;
        }
        /// <summary>
        /// æµ·åº·AGV任务继续执行
        /// </summary>
        /// <param name="TaskCode">任务号</param>
        /// <returns></returns>
        public WebResponseContent Hikvisiontaskscontinue(string TaskCode,string Address=null)
        {
            WebResponseContent content = new WebResponseContent();
            HIKROBOTReturn hIKROBOTReturn = null;
            HIKROBOTTaskContinue hIKROBOTTaskContinue =null;
            try
            {
                // 1. å‚数验证
                if (string.IsNullOrWhiteSpace(TaskCode))
                {
                    throw new Exception("任务编码不能为空");
                }
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(HIKROBOTTaskContinue)) ?? throw new Exception("未找到海康AGV继续执行接口配置信息!请检查接口配置");
                hIKROBOTTaskContinue = new HIKROBOTTaskContinue()
                {
                    triggerCode = TaskCode,
                    triggerType="TASK",//固定值
                    targetRoute=string.IsNullOrEmpty(Address)?null:
                    new TargetRouteDto()
                    {
                        code = Address,
                        type = "SITE",
                    }
                };
                var headers = new Dictionary<string, string>
                {
                    { "X-lr-request-id", DateTimeOffset.Now.ToUnixTimeSeconds().ToString() }
                };
                string response = HttpHelper.Post(apiInfo.ApiAddress, hIKROBOTTaskContinue.Serialize(),headers: headers);
                hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
                if (hIKROBOTReturn.code == "SUCCESS")
                {
                    var data = hIKROBOTReturn.data.ToString().DeserializeObject<HIKROBOTReturnData>();
                    content.OK(data: data);
                }
                else
                {
                    throw new Exception(hIKROBOTReturn.message);
                }
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(hIKROBOTTaskContinue, content, "海康AGV继续执行任务", "", hIKROBOTReturn.message);
            }
            return content;
        }
    }
}
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs
@@ -87,12 +87,32 @@
                            }
                            break;
                        case "into"://申请进入提升机
                            {
                                task.TaskState = (int)TaskStatusEnum.AGV_WaitToExecute;
                                BaseDal.UpdateData(task);
                            }
                            break;
                        case "wait"://扫码等待
                            {
                                task.TaskState = (int)TaskStatusEnum.CheckPalletCodeing;
                                BaseDal.UpdateData(task);
                            }
                            break;
                        case "end":
                            {
                                ///判断任务是否跟设备有关
                                if(task.TaskType== TaskTypeEnum.RK3F.ObjToInt()&& task.TaskState == (int)TaskStatusEnum.CheckPalletCodeFinish)
                                {
                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
                                    if (device == null) task.ExceptionMessage = "未找到提升机信息";
                                    else
                                    {
                                        if (device.IsConnected)
                                            device.SetValue(HoistEnum.Inboundboxon,1);
                                        else
                                            task.ExceptionMessage = "提升机信息设备连接失败";
                                    }
                                }
                                TaskCompleted(task, deviceTypeEnum);
                            }
                            break;
@@ -465,5 +485,9 @@
            return content;
        }
        #endregion
    }
}
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/TSJJob.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,201 @@
using Autofac.Core;
using HslCommunication;
using HslCommunication.Core;
using Microsoft.VisualBasic.FileIO;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using Quartz;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_TaskInfoService;
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class TSJJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly IStationMangerService _stationMangerService;
        public TSJJob(ITaskService taskService, IStationMangerService stationMangerService)
        {
            _taskService = taskService;//注入
            _stationMangerService = stationMangerService;
        }
        public Task Execute(IJobExecutionContext context)
        {
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
            {
                OtherDevice device = (OtherDevice)value;
                //Example
                //device.GetValue  è¯»å–
                //device.SetValue  å†™å…¥
                // _taskService.Repository ä»“储层,进行数据库访问-
                try
                {
                    List<Dt_Task> Uptasks = new List<Dt_Task>();
                    //查询所有任务类型为3,4楼的入库任务类型且任务状态为AGV_WaitToExecute的任务
                    var taskList = _taskService.Repository.QueryData(x => x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt());
                    //任务的目标地址对于站台号;
                    foreach (var task in taskList)
                    {
                        //先检查设备状态
                        if (device.GetValue<HoistEnum, short>(HoistEnum.EquipmentStatus, "TSJ") == 2)
                        {
                            if (task.ExceptionMessage == "提升机设备故障")
                            {
                                continue;
                            }
                            task.ExceptionMessage = "提升机设备故障";
                            Uptasks.Add(task);
                            continue;
                            //throw new Exception("设备故障");
                        }
                        if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt())
                        {
                            //判断3楼入库箱号有无
                            if (device.GetValue<HoistEnum, string>(HoistEnum.OutboundInplace, "TSJ") == "1")
                            {
                                if (task.ExceptionMessage == "3楼入库箱号有货,请先处理")
                                {
                                    continue;
                                }
                                task.ExceptionMessage = "3楼入库箱号有货,请先处理";
                                Uptasks.Add(task);
                                continue;
                            }
                            //然后调用输送线接口,通知输送线有料箱需要入库,任务举行执行
                            var result = _taskService.Hikvisiontaskscontinue(task.WMSTaskNum);
                            if (result.Status == false)
                            {
                                if (task.ExceptionMessage!= result.Message)
                                {
                                    task.ExceptionMessage = result.Message;
                                    Uptasks.Add(task);
                                }
                                continue;
                            }
                            task.TaskState = (int)TaskStatusEnum.AGV_ToExecute;
                            task.ExceptionMessage = "";
                            Uptasks.Add(task);
                            //这里任务变成了CheckPalletCodeing
                        }
                        else if(task.TaskType == TaskTypeEnum.CK3F.ObjToInt()) //出库
                        {
                            ////出库料箱缓存数量
                            //if (device.GetValue<HoistEnum, short>(HoistEnum.Outboundmaterialbox, "TSJ") == 0) throw new Exception("没有出库料箱缓存数量为空");
                            //读取3楼出库料箱到位
                            if (device.GetValue<HoistEnum, short>(HoistEnum.SOutboundmaterialbox, "TSJ") != 1) throw new Exception("3楼出库料箱没有到位");
                            //然后调用输送线接口,通知输送线有料箱需要入库,任务举行执行
                            if (_taskService.Hikvisiontaskscontinue(task.WMSTaskNum).Status == false) throw new Exception($"3楼出库任务举行执行失败,错误信息{_taskService.Hikvisiontaskscontinue(task.WMSTaskNum).Message}");//给任务号
                            //去更新任务里写值
                            //写3楼出库箱取货完成
                            device.SetValue<HoistEnum, short>(HoistEnum.Outboundboxon, 1);
                        }
                        else if (task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt())//4楼入库
                        {
                            //回空箱的时候要读一个吗
                            if (device.GetValue<HoistEnum, short>(HoistEnum.Emptycontainernumber, "TSJ") == null) throw new Exception($"4楼空箱,读码器没有读到值");
                            //判断4楼空箱到位
                            if (device.GetValue<HoistEnum, short>(HoistEnum.ReturnbinAvailable, "TSJ") == 2) throw new Exception("4楼回料箱为空");
                            if (_taskService.Hikvisiontaskscontinue(task.WMSTaskNum).Status == false) throw new Exception($"3楼出库任务举行执行失败,错误信息{_taskService.Hikvisiontaskscontinue(task.WMSTaskNum).Message}");//给任务号
                            //写入空箱放到位信号
                            device.SetValue(HoistEnum.Emptyboxplacedinposition, "TSJ", "1");
                        }
                        else if (task.TaskType == TaskTypeEnum.CHUKU1.ObjToInt()) //四楼库内到提升机
                        {
                            //4楼出库料箱到位
                            if (device.GetValue<HoistEnum, short>(HoistEnum.FOutboundmaterialbox, "TSJ") == 2) throw new Exception("4楼出库料箱没有到位");
                            //写以一个出库完成信号
                            device.SetValue(HoistEnum.Outboundboxretrievalcompleted, "TSJ", "1");
                        }
                    }
                    //查找三楼入库任务状态为CheckPalletCodeing的任务托盘号确认中
                    var RK3FTasks = taskList.Where(x => x.TaskType == TaskTypeEnum.RK3F.ObjToInt()&&x.TaskState== (int)TaskStatusEnum.CheckPalletCodeing).ToList();
                    foreach (var item in RK3FTasks)
                    {
                        var Barcode = device.SetValue<HoistEnum, short>(HoistEnum.Codereadingtriggered, 1);
                        //检查3楼入库箱号是多少,然后传给wms
                        var BinNumber = device.GetValue<HoistEnum, string>(HoistEnum.Inboxnumber, "TSJ");
                        //根据读到的箱号进行料箱检验,检验通过就触发读码器读取,如果不通过就抛出异常
                        var Verification = _taskService.MaterialBoxInspection(item.WMSTaskNum, BinNumber.ToString());
                        if (!Verification.Status)
                        {
                            if (!(item.ExceptionMessage == Verification.Message))
                            {
                                item.ExceptionMessage = Verification.Message;
                                Uptasks.Add(item);
                            }
                            //料箱验证写好后,需要更改
                            item.TargetAddress = Verification.Data.ToString();
                        }
                        //如果料箱检验成功就写入读码器的值
                        var result = _taskService.Hikvisiontaskscontinue(item.WMSTaskNum, item.TargetAddress);
                        if (result.Status == false)
                        {
                            if (item.ExceptionMessage != result.Message)
                            {
                                item.ExceptionMessage = result.Message;
                                Uptasks.Add(item);
                            }
                            continue;
                        }
                        item.TaskState = (int)TaskStatusEnum.CheckPalletCodeFinish;
                        Uptasks.Add(item);
                    }
                    if (Uptasks.Count > 0)
                    {
                        _taskService.UpdateData(Uptasks);
                    }
                    WriteInfo(device.DeviceName, "infoLog");
                    WriteDebug(device.DeviceName, "debugLog");
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "错误", ex);
                }
            }
            else
            {
                WriteError(nameof(TestJob), "参数错误,未传递设备参数或设备类型错误");
            }
            return Task.CompletedTask;
        }
    }
}