1
z8018
2025-04-05 f94288b728f81b20c29e626526c584c11a7894a3
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -1,126 +1,128 @@
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
/*----------------------------------------------------------------
 * å‘½åç©ºé—´ï¼šWIDESEAWCS_Tasks.ConveyorLineJob
 * åˆ›å»ºè€…:胡童庆
 * åˆ›å»ºæ—¶é—´ï¼š2024/8/2 16:13:36
 * ç‰ˆæœ¬ï¼šV1.0.0
 * æè¿°ï¼š
 *
 * ----------------------------------------------------------------
 * ä¿®æ”¹äººï¼š
 * ä¿®æ”¹æ—¶é—´ï¼š
 * ç‰ˆæœ¬ï¼šV1.0.1
 * ä¿®æ”¹è¯´æ˜Žï¼š
 *
 *----------------------------------------------------------------*/
#endregion << ç‰ˆ æœ¬ æ³¨ é‡Š >>
//#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
///*----------------------------------------------------------------
// * å‘½åç©ºé—´ï¼šWIDESEAWCS_Tasks.ConveyorLineJob
// * åˆ›å»ºè€…:胡童庆
// * åˆ›å»ºæ—¶é—´ï¼š2024/8/2 16:13:36
// * ç‰ˆæœ¬ï¼šV1.0.0
// * æè¿°ï¼š
// *
// * ----------------------------------------------------------------
// * ä¿®æ”¹äººï¼š
// * ä¿®æ”¹æ—¶é—´ï¼š
// * ç‰ˆæœ¬ï¼šV1.0.1
// * ä¿®æ”¹è¯´æ˜Žï¼š
// *
// *----------------------------------------------------------------*/
//#endregion << ç‰ˆ æœ¬ æ³¨ é‡Š >>
using AutoMapper;
using Quartz;
using System.Text.RegularExpressions;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
//using AutoMapper;
//using Quartz;
//using System.Text.RegularExpressions;
//using WIDESEA_Common.Log;
//using WIDESEAWCS_Common.TaskEnum;
//using WIDESEAWCS_DTO.Enum;
//using WIDESEAWCS_ISystemServices;
//using WIDESEAWCS_ITaskInfoService;
//using WIDESEAWCS_Model.Models;
//using WIDESEAWCS_Model.Models.System;
//using WIDESEAWCS_QuartzJob;
//using WIDESEAWCS_QuartzJob.Service;
//using WIDESEAWCS_Tasks.ConveyorLineJob;
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLineJob : IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IOrderDetailsService _OrderDetailsService;
        private readonly IMapper _mapper;
//namespace WIDESEAWCS_Tasks
//{
//    [DisallowConcurrentExecution]
//    public class CommonConveyorLineJob : IJob
//    {
//        private readonly ITaskService _taskService;
//        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
//        private readonly IRouterService _routerService;
//        private readonly IOrderDetailsService _OrderDetailsService;
//        private readonly IMapper _mapper;
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _OrderDetailsService = orderDetails;
            _mapper = mapper;
        }
//        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper)
//        {
//            _taskService = taskService;
//            _taskExecuteDetailService = taskExecuteDetailService;
//            _routerService = routerService;
//            _OrderDetailsService = orderDetails;
//            _mapper = mapper;
//        }
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
//        public Task Execute(IJobExecutionContext context)
//        {
//            try
//            {
               
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
//                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                
                if (conveyorLine != null)
                {
                    if (conveyorLine.Communicator.Read<bool>("DB7.3030.0"))   //申请
                    {
//                if (conveyorLine != null)
//                {
//                    if (conveyorLine.Communicator.Read<bool>("DB7.3030.0"))   //申请
//                    {
                        string Barcodes = conveyorLine.Communicator.Read<string>("DB7.3032");   //读条码
                        string pattern = @"\d+";  // åŒ¹é…æ•°å­—
                        Match match = Regex.Match(Barcodes, pattern);
                        string barcodeNumber = match.Value;
                        if (barcodeNumber != "")
                        {
                            int toplc = _OrderDetailsService.GetOrderDetails(barcodeNumber);
                            if (toplc != -1)
                            {
                                conveyorLine.Communicator.Write("DB7.3022", (int)toplc);   //写入去向
                                conveyorLine.Communicator.Write("DB7.3028.0", (bool)true);    //写入反馈
                                WriteLog.Write_Log("扫码枪", "扫码站台", "成功", new { ä¿¡æ¯ = $"条码:{barcodeNumber},写入去向{toplc}" });
                                if (conveyorLine.Communicator.Read<bool>("DB7.2986"))
                                {
                                    conveyorLine.Communicator.Write("DB7.3022", (int)0);   //清除写入去向
                                    conveyorLine.Communicator.Write("DB7.3028.0", (bool)false);   //清除写入反馈
                                    WriteLog.Write_Log("扫码枪", "扫码站台", "成功", new { ä¿¡æ¯ = $"条码:{barcodeNumber},清除输送线反馈成功" });
                                    //调取反馈MES托盘条码
                                    if (_OrderDetailsService.ToMesBarc(int.Parse(barcodeNumber)))
                                    {
                                        WriteLog.Write_Log("ToMes", "条码反馈Mes", "成功", new { ä¿¡æ¯ = $"条码:{barcodeNumber},反馈成功" });
                                    }
                                    else
                                    {
                                        WriteLog.Write_Log("ToMes", "条码反馈Mes", "失败", new { ä¿¡æ¯ = $"条码:{barcodeNumber},反馈失败" });
                                    }
//                        string Barcodes = conveyorLine.Communicator.Read<string>("DB7.3032");   //读条码
//                        string pattern = @"\d+";  // åŒ¹é…æ•°å­—
//                        Match match = Regex.Match(Barcodes, pattern);
//                        string barcodeNumber = match.Value;
//                        if (barcodeNumber != "")
//                        {
//                            int toplc = _OrderDetailsService.GetOrderDetails(barcodeNumber);
//                            if (toplc != -1)
//                            {
//                                conveyorLine.Communicator.Write("DB7.3022", (int)toplc);   //写入去向
//                                conveyorLine.Communicator.Write("DB7.3028.0", (bool)true);    //写入反馈
//                                WriteLog.Write_Log("扫码枪", "扫码站台", "成功", new { ä¿¡æ¯ = $"条码:{barcodeNumber},写入去向{toplc}" });
//                                if (conveyorLine.Communicator.Read<bool>("DB7.3116"))
//                                {
//                                    conveyorLine.Communicator.Write("DB7.3022", (int)0);   //清除写入去向
//                                    conveyorLine.Communicator.Write("DB7.3028.0", (bool)false);   //清除写入反馈
//                                    WriteLog.Write_Log("扫码枪", "扫码站台", "成功", new { ä¿¡æ¯ = $"条码:{barcodeNumber},清除输送线反馈成功" });
//                                    //调取反馈MES托盘条码
//                                   var datast= _OrderDetailsService.ToMesBarc(int.Parse(barcodeNumber));
//                                    if (datast.code==1)
//                                    {
//                                        WriteLog.Write_Log("ToMes", "条码反馈Mes", "成功", new { ä¿¡æ¯ = $"条码:{barcodeNumber},反馈成功" });
//                                    }
//                                    else
//                                    {
//                                        WriteLog.Write_Log("ToMes", "条码反馈Mes", "失败", new { ä¿¡æ¯ = $"条码:{barcodeNumber},反馈失败" });
//                                    }
                                    
                                }
                                else
                                {
                                    WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = $"条码:{barcodeNumber},清除输送线反馈失败" });
                                }
                            }
                            else
                            {
                                conveyorLine.Communicator.Write("DB7.3028.1", (bool)true);
                                WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = $"条码:{barcodeNumber},未找到数据明细详情长度,写入报警信息" });
                            }
                        }
                        else
                        {
                            WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = $"未读取到托盘条码,条码错误{barcodeNumber}" });
                        }
                    }
                    else
                    {
//                                }
//                                else
//                                {
//                                    WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = $"条码:{barcodeNumber},清除输送线反馈失败" });
//                                }
//                            }
//                            else
//                            {
//                                conveyorLine.Communicator.Write("DB7.3028.1", (bool)true);
//                                WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = $"条码:{barcodeNumber},未找到数据明细详情长度,写入报警信息" });
//                            }
//                        }
//                        else
//                        {
//                            WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = $"未读取到托盘条码,条码错误{barcodeNumber}" });
//                        }
//                    }
//                    else
//                    {
                        WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = "未读取到扫码枪申请" });
                    }
                }
//                        WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = "未读取到扫码枪申请" });
//                    }
//                }
            }
            catch (Exception ex)
            {
                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
            }
            return Task.CompletedTask;
        }
//            }
//            catch (Exception ex)
//            {
//                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
//            }
//            return Task.CompletedTask;
//        }
        
    }
}
//    }
//}