dengjunjie
2025-03-27 bb56b2b6f21acb7c69c02585e5bc534d2f67715f
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/CommonProductionLineJob.cs
@@ -4,12 +4,15 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_DTO.WMSInfo;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ProductionLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
using static System.Collections.Specialized.BitVector32;
namespace WIDESEAWCS_Tasks
{
@@ -28,15 +31,52 @@
            _taskRepository = taskRepository;
            _routerService = routerService;
        }
        //static int i = 1;
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                #region MyRegion
                OtherDevice ProductionLine = (OtherDevice)context.JobDetail.JobDataMap.Get("JobParams");
                if (ProductionLine != null)
                {
                    ProductionLineExtend(ProductionLine);
                    //ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO()
                    //{
                    //    stationCode = ProductionLine.DeviceCode,
                    //    traytype = 4,
                    //    Barcode = "25000037",
                    //    batchNo = "250325T1",
                    //};
                    //var content = ProductionLineToWMSRequest(MaterielGroupDTO);
                    #region MyRegion
                    var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request);
                    if (request == 1)
                    {
                        var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType);
                        //var content = Request(ProductionLine, traytype, ProductionLine.DeviceCode);
                        if (traytype == 4)
                        {
                            var Barcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode).Replace("\0", "");
                            var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode);
                            if (task == null)
                            {
                                var batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo).Replace("\0", "");
                                ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO()
                                {
                                    stationCode = ProductionLine.DeviceCode,
                                    traytype = traytype,
                                    Barcode = Barcode,
                                    batchNo = batchNo,
                                };
                                var content = ProductionLineToWMSRequest(MaterielGroupDTO);
                                if (content.Status)
                                    ProductionLine.SetValue(ProductionLineDBName.Wrequest, request);
                            }
                        }
                    }
                    #endregion
                }
                #endregion
            }
            catch (Exception ex)
            {
@@ -44,5 +84,21 @@
            }
            return Task.CompletedTask;
        }
        public string GetString<TEnum, TResult>(TEnum value, OtherDevice ProductionLine) where TEnum : Enum
        {
            TEnum value2 = value;
            if (!ProductionLine.IsConnected)
            {
                throw new Exception("通讯连接错误,请检查网络");
            }
            DeviceProDTO deviceProDTO = ProductionLine.DeviceProDTOs.FirstOrDefault((DeviceProDTO x) => x.DeviceProParamName == value2.ToString());
            if (deviceProDTO != null)
            {
                return Encoding.ASCII.GetString(ProductionLine.Communicator.Read(deviceProDTO.DeviceProAddress, deviceProDTO.DeviceProDataLength)).Replace("\0", "");
                //return (TResult)Communicator.ReadAsObj(deviceProDTO.DeviceProAddress, deviceProDTO.DeviceDataType);
            }
            throw new Exception("读取数据错误,未在协议信息里面找到参数" + value2.ToString());
        }
    }
}