1
z8018
2025-04-16 1f361850d35ba47225951efbc49d592eea685cf8
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -16,12 +16,15 @@
#endregion << ç‰ˆ æœ¬ æ³¨ é‡Š >>
using AutoMapper;
using HslCommunication;
using Quartz;
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_DTO.BasicInfo;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
@@ -32,7 +35,7 @@
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLineJob : IJob
    public class CommonConveyorLineJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
@@ -49,80 +52,97 @@
            _mapper = mapper;
        }
        static string barcode = string.Empty; //条码
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
                if (flag && value != null && value is OtherDevice)
                {
                    if (conveyorLine.Communicator.Read<bool>("DB7.3030.0"))   //申请
                    OtherDevice otherDevice = (OtherDevice)value;
                    bool request = otherDevice.Communicator.Read<bool>("DB15.22.0");   //申请
                    bool response = otherDevice.Communicator.Read<bool>("DB15.22.1");   //应答
                    bool wcsResponse = otherDevice.Communicator.Read<bool>("DB15.0.0");   //应答
                    if (request && !response && !wcsResponse)
                    {
                        bool[] useables = otherDevice.Communicator.Read<bool>("DB15.22.3", 3);
                        string Barcodes = conveyorLine.Communicator.Read<string>("DB7.3032");   //读条码
                        string pattern = @"\d+";  // åŒ¹é…æ•°å­—
                        Match match = Regex.Match(Barcodes, pattern);
                        string barcodeNumber = match.Value;
                        if (barcodeNumber != "")
                        int[] useableArray = GetIndexArray(useables, false);
                        List<int> useableStations = useableArray.ToList();
                        for (int i = 0; i < useableStations.Count; i++)
                        {
                            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},未找到数据明细详情长度,写入报警信息" });
                            }
                            useableStations[i] += 1;
                        }
                        else
                        barcode = otherDevice.Communicator.Read<string>("DB15.32");   //条码
                        List<byte> bytes = otherDevice.Communicator.Read("DB15.34", 40).ToList();
                        byte[] temp = bytes.ToArray().SelectMiddle(0, bytes.IndexOf(0));
                        barcode = Encoding.Default.GetString(temp);
                        string pattern = @"\d+";  // åŒ¹é…æ•°å­—
                        Match match = Regex.Match(barcode, pattern);
                        string barcodeNumber = match.Value;
                        if (!string.IsNullOrEmpty(barcodeNumber))
                        {
                            WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = $"未读取到托盘条码,条码错误{barcodeNumber}" });
                            // 1. èŽ·å–åŽ»å‘
                            int toplc = _OrderDetailsService.GetOrderDetails(barcodeNumber, useableStations, out ProductInfoDTO productInfo);
                            if (toplc > 0)//获取到有效去向
                            {
                                otherDevice.Communicator.Write("DB15.10", productInfo.Length);
                                otherDevice.Communicator.Write("DB15.14", productInfo.Width);
                                otherDevice.Communicator.Write("DB15.18", productInfo.Height);
                                otherDevice.Communicator.Write("DB15.6", toplc);   //写入去向
                                otherDevice.Communicator.Write("DB15.0", true);
                                var datast = _OrderDetailsService.ToMesBarc(int.Parse(barcode));
                            }
                            else if (toplc == -1)//板材无条码
                            {
                                otherDevice.Communicator.Write("DB15.0.3", true);
                            }
                            else if (toplc == -2) //板材大小不在区间
                            {
                                otherDevice.Communicator.Write("DB15.0.2", true);
                            }
                        }
                    }
                    else
                    {
                        WriteLog.Write_Log("扫码枪", "扫码站台", "错误", new { ä¿¡æ¯ = "未读取到扫码枪申请" });
                        if (wcsResponse && !request)
                            otherDevice.Communicator.Write("DB15.0", false);  //清除响应
                    }
                }
            }
            catch (Exception ex)
            {
                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
                WriteError(nameof(CommonConveyorLineJob), ex.ToString(), ex);
            }
            return Task.CompletedTask;
        }
        public int[] GetIndexArray<T>(T[] values, T value)
        {
            List<int> result = new List<int>();
            for (int i = 0; i < values.Length; i++)
            {
                if (value?.Equals(values[i]) ?? false)
                {
                    result.Add(i);
                }
            }
            return result.ToArray();
        }
    }
}