1
z8018
2025-04-16 1f361850d35ba47225951efbc49d592eea685cf8
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineStationJob.cs
@@ -23,8 +23,11 @@
using System.Text;
using System.Text.RegularExpressions;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.BasicInfo;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
@@ -37,51 +40,70 @@
    [DisallowConcurrentExecution]
    public class CommonConveyorLineStationJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IOrderDetailsService _OrderDetailsService;
        private readonly IMapper _mapper;
        public CommonConveyorLineStationJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper)
        private readonly ITaskRepository _taskRepository;
        public CommonConveyorLineStationJob(IMapper mapper, ITaskRepository taskRepository)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _OrderDetailsService = orderDetails;
            _mapper = mapper;
            _taskRepository = taskRepository;
        }
        static string barcode = string.Empty; //鏉$爜
        public Task Execute(IJobExecutionContext context)
        {
            try
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null && value is OtherDevice)
            {
                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
                if (flag && value != null && value is OtherDevice)
                OtherDevice otherDevice = (OtherDevice)value;
                try
                {
                    OtherDevice otherDevice = (OtherDevice)value;
                    bool request = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationRequest);   //鐢宠
                    bool response = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationResponse);    //搴旂瓟
                    bool wcsResponse = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.WCSStationResponse);    //搴旂瓟
                    if (request && !response && !wcsResponse)
                    List<string> deviceChildCodes = otherDevice.DeviceProDTOs.GroupBy(x => x.DeviceChildCode).Select(x => x.Key).ToList();
                    for (int i = 0; i < deviceChildCodes.Count; i++)
                    {
                        bool request = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationRequest, deviceChildCodes[i]);   //鐢宠
                        bool response = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationResponse, deviceChildCodes[i]);    //搴旂瓟
                        bool wcsResponse = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.WCSStationResponse, deviceChildCodes[i]);    //搴旂瓟
                        if (request && !response && !wcsResponse)
                        {
                            int taskNum = otherDevice.GetValue<ConveyorLineStationDBName, int>(ConveyorLineStationDBName.PLCStationTaskNum, deviceChildCodes[i]);
                            if (taskNum > 0)
                            {
                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
                                if (task != null)
                                {
                                    task.TaskState = TaskStatusEnum.Gantry_New.ObjToInt();
                                    _taskRepository.UpdateData(task);
                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, 0, deviceChildCodes[i]);
                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true, deviceChildCodes[i]);
                                }
                                else
                                {
                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, 8, deviceChildCodes[i]);
                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true, deviceChildCodes[i]);
                                }
                            }
                        }
                        else
                        {
                            if (wcsResponse && !request)
                                otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, false, deviceChildCodes[i]);  //娓呴櫎鍝嶅簲
                        }
                    }
                    else
                    {
                        if (wcsResponse)
                            otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, false);  //娓呴櫎鍝嶅簲
                    }
                }
                catch (Exception ex)
                {
                    WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex);
                }
            }
            catch (Exception ex)
            else
            {
                WriteError(nameof(CommonConveyorLineJob), ex.ToString(), ex);
                WriteError(nameof(CommonConveyorLineStationJob), "鍙傛暟閿欒,鏈紶閫掕澶囧弬鏁版垨璁惧绫诲瀷閿欒");
            }
            return Task.CompletedTask;
        }