From e7fa8b518df97c0e8fe1d01929693e6681dacbd5 Mon Sep 17 00:00:00 2001 From: gcw_MV9p2JJN Date: Tue, 27 Jan 2026 11:52:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RIZO.Admin.WebApi/Program.cs | 39 +- .../product_trace/ProductProcessParameters.cs | 155 +++++++ ...01.cs => PlcIntoStationService_OP07_01.cs} | 104 +++-- .../Stations/PlcOutStationService_OP07_01.cs | 415 ++++++++++++++++++ 4 files changed, 647 insertions(+), 66 deletions(-) create mode 100644 RIZO.Model/MES/product_trace/ProductProcessParameters.cs rename RIZO.Service/PLCBackground/Stations/{PlcPollingService_OP07_01.cs => PlcIntoStationService_OP07_01.cs} (60%) create mode 100644 RIZO.Service/PLCBackground/Stations/PlcOutStationService_OP07_01.cs diff --git a/RIZO.Admin.WebApi/Program.cs b/RIZO.Admin.WebApi/Program.cs index 91a5de4..628f423 100644 --- a/RIZO.Admin.WebApi/Program.cs +++ b/RIZO.Admin.WebApi/Program.cs @@ -14,6 +14,7 @@ using RIZO.Common.Cache; using RIZO.Common.DynamicApiSimple.Extens; using RIZO.Infrastructure.WebExtensions; using RIZO.Mall; +using RIZO.Service.PLCBackground.Stations; using RIZO.ServiceCore.Signalr; using RIZO.ServiceCore.SqlSugar; using S7.Net; @@ -107,43 +108,9 @@ builder.Services.AddSwaggerConfig(); builder.Services.AddLogo(); // 添加本地化服务 builder.Services.AddLocalization(options => options.ResourcesPath = ""); -// 配置PLC设置 -//builder.Services.Configure>(builder.Configuration.GetSection("PlcSettings:Stations")); -//// 注册PLC数据服务 -//builder.Services.AddSingleton(); -//builder.Services.AddHostedService(provider => provider.GetService() as BackgroundService); - -//builder.Services.Configure>(builder.Configuration.GetSection("PlcSettingss:Connections")); -//builder.Services.AddSingleton(sp => -//{ -// var configs = sp.GetRequiredService>>().Value; -// var logger = sp.GetRequiredService>(); -// var service = new RIZO.Service.PLC.PlcService2(logger); - -// foreach (var config in configs) -// { -// service.AddPlc( -// config.PlcId, -// ParseCpuType(config.CpuType), -// config.Ip, -// config.Rack, -// config.Slot -// ); -// } - -// // 后台启动连接 -// _ = service.ConnectAllAsync(); -// return service; -//}); - -//// CPU类型转换辅助方法 -//static CpuType ParseCpuType(string type) -//{ -// return Enum.Parse(type.Replace("-", "")); // "S71200" -> "S71200" -//} -// 配置服务 - // 注册PLC服务(单例模式) +builder.Services.AddHostedService(); +builder.Services.AddHostedService(); // 在应用程序启动的最开始处调用 diff --git a/RIZO.Model/MES/product_trace/ProductProcessParameters.cs b/RIZO.Model/MES/product_trace/ProductProcessParameters.cs new file mode 100644 index 0000000..9e14047 --- /dev/null +++ b/RIZO.Model/MES/product_trace/ProductProcessParameters.cs @@ -0,0 +1,155 @@ +namespace RIZO.Model.MES.product_trace +{ + /// + /// 生产过程参数 + /// + [SugarTable("product_process_parameters")] + public class ProductProcessParameters + { + /// + /// 主键ID + /// + [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// 工单号 + /// + [SugarColumn(ColumnName = "workorder", Length = 50)] + public string Workorder { get; set; } + + /// + /// 产品序列号 + /// + [SugarColumn(ColumnName = "product_SN", Length = 50)] + public string ProductSN { get; set; } + + /// + /// 工艺路线代码 + /// + [SugarColumn(ColumnName = "routingCode", Length = 50)] + public string RoutingCode { get; set; } + + /// + /// 工序代码 + /// + [SugarColumn(ColumnName = "operationCode", Length = 50)] + public string OperationCode { get; set; } + + /// + /// 流程代码 + /// + [SugarColumn(ColumnName = "flowCode", Length = 50)] + public string FlowCode { get; set; } + + /// + /// 生产线体代码 + /// + [SugarColumn(ColumnName = "productlinebodyCode", Length = 50)] + public string ProductlinebodyCode { get; set; } + + /// + /// 工位代码 + /// + [SugarColumn(ColumnName = "workstationCode", Length = 50)] + public string WorkstationCode { get; set; } + + /// + /// 参数代码 + /// + [SugarColumn(ColumnName = "parameter_code", Length = 255)] + public string ParameterCode { get; set; } + + /// + /// 参数名称 + /// + [SugarColumn(ColumnName = "parameter_name", Length = 100)] + public string ParameterName { get; set; } + + /// + /// PLC点位 + /// + [SugarColumn(ColumnName = "plc_point", Length = 50)] + public string PlcPoint { get; set; } + + /// + /// 描述 + /// + [SugarColumn(ColumnName = "description", ColumnDataType = "text")] + public string Description { get; set; } + + /// + /// 数据类型 + /// + [SugarColumn(ColumnName = "data_type", Length = 50)] + public string DataType { get; set; } + + /// + /// 单位 + /// + [SugarColumn(ColumnName = "unit", Length = 20)] + public string Unit { get; set; } + + + + /// + /// 实际值 + /// + [SugarColumn(ColumnName = "actual_value", Length = 50)] + public string ActualValue { get; set; } + + /// + /// 期望值 + /// + [SugarColumn(ColumnName = "expect_value", Length = 50)] + public string ExpectValue { get; set; } + + /// + /// 标准值 + /// + [SugarColumn(ColumnName = "standard_value", ColumnDataType = "decimal(18,4)")] + public decimal? StandardValue { get; set; } + + /// + /// 最小值 + /// + [SugarColumn(ColumnName = "min_value", ColumnDataType = "decimal(18,4)")] + public decimal? MinValue { get; set; } + + /// + /// 最大值 + /// + [SugarColumn(ColumnName = "max_value", ColumnDataType = "decimal(18,4)")] + public decimal? MaxValue { get; set; } + + /// + /// 结果 + /// + [SugarColumn(ColumnName = "result")] + public int? Result { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "createdby", Length = 50)] + public string Createdby { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "updatedby", Length = 50)] + public string Updatedby { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + } +} \ No newline at end of file diff --git a/RIZO.Service/PLCBackground/Stations/PlcPollingService_OP07_01.cs b/RIZO.Service/PLCBackground/Stations/PlcIntoStationService_OP07_01.cs similarity index 60% rename from RIZO.Service/PLCBackground/Stations/PlcPollingService_OP07_01.cs rename to RIZO.Service/PLCBackground/Stations/PlcIntoStationService_OP07_01.cs index f76c538..7f45ecd 100644 --- a/RIZO.Service/PLCBackground/Stations/PlcPollingService_OP07_01.cs +++ b/RIZO.Service/PLCBackground/Stations/PlcIntoStationService_OP07_01.cs @@ -6,7 +6,6 @@ using NLog; using RIZO.Model.Mes; using RIZO.Model.MES.product_trace; using RIZO.Repository; -using RIZO.Service.MES.product_trace; using RIZO.Service.PLC; using S7.Net; using SqlSugar.IOC; @@ -16,9 +15,7 @@ using System.Threading.Tasks; namespace RIZO.Service.PLCBackground.Stations { - - - public class PlcPollingService_OP07_01 : BackgroundService + public class PlcIntoStationService_OP07_01 : BackgroundService { private static Logger _logger = LogManager.GetCurrentClassLogger(); private PlcConntectHepler _plcService; @@ -26,8 +23,11 @@ namespace RIZO.Service.PLCBackground.Stations private readonly string _ipAddress = "192.168.10.222"; private readonly CpuType _cpuType = CpuType.S71500; private string WorkstationCode; - - + private readonly SqlSugarClient Context; + public PlcIntoStationService_OP07_01() + { + Context = DbScoped.SugarScope.CopyNew(); + } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { @@ -38,8 +38,8 @@ namespace RIZO.Service.PLCBackground.Stations { // 获取当前的工序/工站 - WorkstationCode = await DbScoped.SugarScope.CopyNew().Queryable().Where(it => it.PlcIP == _ipAddress) - .Select(it => it.WorkstationCode).FirstAsync(); + WorkstationCode = await Context.Queryable().Where(it => it.PlcIP == _ipAddress) + .Select(it => it.WorkstationCode).FirstAsync(); while (!stoppingToken.IsCancellationRequested) @@ -60,16 +60,44 @@ namespace RIZO.Service.PLCBackground.Stations string productModel = await _plcService.ReadStringAsync("DB1001.DBB1000"); string productSN = await _plcService.ReadStringAsync("DB1001.DBB1054"); + // 获取工单 + + //获取工艺路线工序 + List processOperations = await Context.Queryable().LeftJoin((r, o) => r.RoutingCode == o.FkRoutingCode) + .Where((r, o) => r.FkProductMaterialCode == productModel && r.Status == 1) + .Select((r, o) => o).ToListAsync(); + //判断改产品是正常件还是返工件 + //插入入站请求ASK过站记录 + ProductPassStationRecord ASKintoStation = new ProductPassStationRecord + { + ProductSN = productSN, + WorkstationCode = WorkstationCode, + Routingcode = processOperations.First().FkRoutingCode, + OperationCode = WorkstationCode, + ProductionLifeStage = 1, // 1表示生产中 + PasstationType = 0, // 0表示入站请求 + PasstationDescription = "入站请求ASK", + EffectTime = DateTime.Now, + CreatedTime = DateTime.Now, + + }; + await Context.Insertable(ASKintoStation).ExecuteCommandAsync(); //判断该产品是否允许进站 - EntryPermissionResult result = await checkEntryPermission(productModel, productSN, WorkstationCode); + EntryPermissionResult result = await checkEntryPermission(productModel, productSN, WorkstationCode, processOperations); await _plcService.WriteAsync("DB1010.DBW2000", (int)result); + } + + + + + await Task.Delay(_pollingInterval, stoppingToken); } @@ -95,21 +123,16 @@ namespace RIZO.Service.PLCBackground.Stations /// 产品型号 /// 产品SN /// - private async Task checkEntryPermission(string productModel, string productSN, string workstationCode) + private async Task checkEntryPermission(string productModel, string productSN, string workstationCode, List processOperations) { - // 获取工单 - - //获取工艺路线工序 - List processOperations = await DbScoped.SugarScope.CopyNew().Queryable().LeftJoin((r, o) => r.RoutingCode == o.FkRoutingCode) - .Where((r, o) => r.FkProductMaterialCode == productModel && r.Status == 1) - .Select((r, o) => o).ToListAsync(); + EntryPermissionResult result = EntryPermissionResult.UnkownException; //2上工位无记录 //ProcessOperation LastOperation = processOperations.Where(operation => operation.OperationSeq < processOperations.Where(it => it.OperationCode == workstationCode).Select(it => it.OperationSeq).First()).OrderByDescending(operation => operation.OperationSeq).First(); - int LastOperationSeq=processOperations.Where(operation => operation.OperationCode == workstationCode).Select(operation => operation.LastOperationSeq??-1).First(); + int LastOperationSeq = processOperations.Where(operation => operation.OperationCode == workstationCode).Select(operation => operation.LastOperationSeq ?? -1).First(); ProcessOperation LastOperation = processOperations.Where(it => it.OperationSeq == LastOperationSeq).First(); bool isExistLastOperationRecord = await DbScoped.SugarScope.CopyNew().Queryable() .Where(it => it.ProductSN == productSN) @@ -121,7 +144,7 @@ namespace RIZO.Service.PLCBackground.Stations } // 3 上工位NG 入站或者出站结果 NG - bool isExistLastOperationNG = await DbScoped.SugarScope.CopyNew().Queryable() + bool isExistLastOperationNG = await Context.Queryable() .Where(it => it.ProductSN == productSN) .Where(it => it.OperationCode == LastOperation.OperationCode) .Where(it => it.PasstationType == 2 || it.PasstationType == 4) @@ -129,37 +152,58 @@ namespace RIZO.Service.PLCBackground.Stations .AnyAsync(); if (!isExistLastOperationNG) { - return EntryPermissionResult.PreviousStationNG; + result = EntryPermissionResult.PreviousStationNG; + goto InsertPassrecord; } // 4 扫码产品型号错误 - bool isExistproductSN = await DbScoped.SugarScope.CopyNew().Queryable() + bool isExistproductSN = await Context.Queryable() .Where(it => it.ProductSN == productSN).AnyAsync(); - bool isExistproductSNProducting = await DbScoped.SugarScope.CopyNew().Queryable() + + + bool isExistproductSNProducting = await Context.Queryable() .Where(it => it.ProductSN == productSN && (it.ProductCurrentStatus != 1 && it.ProductCurrentStatus != 3)).AnyAsync(); if (!isExistproductSN || !isExistproductSNProducting) { - return EntryPermissionResult.ProductModelError; + result = EntryPermissionResult.ProductModelError; + goto InsertPassrecord; } //6时间超出规定无法生产 - - //查询上一站标准时间 + //OK 准许进站 + result = EntryPermissionResult.AllowIntoStation; + goto InsertPassrecord; + InsertPassrecord: + //插入入站请求Resp过站记录 + ProductPassStationRecord RespintoStation = new ProductPassStationRecord + { + ProductSN = productSN, + WorkstationCode = WorkstationCode, + Routingcode = processOperations.First().FkRoutingCode, + OperationCode = WorkstationCode, + ProductionLifeStage = 1, // 1表示生产中 + PasstationType = 1, // 入站完毕 + PasstationDescription = "入站完毕Resp", + EffectTime = DateTime.Now, + InStationTime = DateTime.Now, + ResultCode = (int)result, + ResultDescription = result.ToString(), + CreatedTime = DateTime.Now, + }; + await Context.Insertable(RespintoStation).ExecuteCommandAsync(); - - - - - - return EntryPermissionResult.UnkownException; + return result; } } + /// + /// 入站校验结果 + /// enum EntryPermissionResult { //1之前工位数据正常 diff --git a/RIZO.Service/PLCBackground/Stations/PlcOutStationService_OP07_01.cs b/RIZO.Service/PLCBackground/Stations/PlcOutStationService_OP07_01.cs new file mode 100644 index 0000000..7eaf180 --- /dev/null +++ b/RIZO.Service/PLCBackground/Stations/PlcOutStationService_OP07_01.cs @@ -0,0 +1,415 @@ +using MDM.Model.Plant; +using MDM.Model.Process; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using NLog; +using NPOI.SS.Formula.Functions; +using RIZO.Model.Mes; +using RIZO.Model.MES.product_trace; +using RIZO.Repository; +using RIZO.Service.PLC; +using S7.Net; +using SqlSugar.IOC; +using System; +using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; + +namespace RIZO.Service.PLCBackground.Stations +{ + + /// + /// OP07_01 出站 + /// + public class PlcOutStationService_OP07_01 : BackgroundService + { + private static Logger _logger = LogManager.GetCurrentClassLogger(); + private PlcConntectHepler _plcService; + private readonly TimeSpan _pollingInterval = TimeSpan.FromSeconds(5); + private readonly string _ipAddress = "192.168.10.222"; + private readonly CpuType _cpuType = CpuType.S71500; + private string WorkstationCode; + private readonly SqlSugarClient Context; + public PlcOutStationService_OP07_01() + { + Context = DbScoped.SugarScope.CopyNew(); + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + _logger.Info("PLC Polling Service started"); + + // 使用工厂方法创建服务实例 + using (_plcService = new PlcConntectHepler(_ipAddress, _cpuType)) + { + + // 获取当前的工序/工站 + WorkstationCode = await Context.Queryable().Where(it => it.PlcIP == _ipAddress) + .Select(it => it.WorkstationCode).FirstAsync(); + + + while (!stoppingToken.IsCancellationRequested) + { + try + { + //心跳检测 + await _plcService.WriteAsync("DB1010.DBW0", 1); + + // 轮询出站站请求信号/工位保存查询请求 + int outStationAsk = await _plcService.ReadAsync("DB1001.DBW2002"); + if (outStationAsk == 1) + { + // 处理进站请求 + _logger.Info("Processing out station request..."); + + //获取产品SN码 + string productModel = await _plcService.ReadStringAsync("DB1001.DBB1000"); + string productSN = await _plcService.ReadStringAsync("DB1001.DBB1054"); + + // 获取工单 + + //获取工艺路线工序 + List processOperations = await Context.Queryable().LeftJoin((r, o) => r.RoutingCode == o.FkRoutingCode) + .Where((r, o) => r.FkProductMaterialCode == productModel && r.Status == 1) + .Select((r, o) => o).ToListAsync(); + //判断改产品是正常件还是返工件 + + + //插入出站请求ASK过站记录 + ProductPassStationRecord ASKoutStation = new ProductPassStationRecord + { + ProductSN = productSN, + WorkstationCode = WorkstationCode, + Routingcode = processOperations.First().FkRoutingCode, + OperationCode = WorkstationCode, + ProductionLifeStage = 1, // 1表示生产中 + PasstationType = 2, // 0表示出站请求 + PasstationDescription = "出站请求ASK", + EffectTime = DateTime.Now, + CreatedTime = DateTime.Now, + + }; + await Context.Insertable(ASKoutStation).ExecuteCommandAsync(); + + //上传工艺参数 + bool CheckOutstationResult = await UploadProcessParameters(productSN, processOperations.First().FkRoutingCode, WorkstationCode); + + //判断该产品是否允许进站 + + OutPermissionResult result = await checkOutPermission(productModel, productSN, WorkstationCode, processOperations, CheckOutstationResult); + await _plcService.WriteAsync("DB1010.DBW2000", (int)result); + + + + } + await Task.Delay(_pollingInterval, stoppingToken); + + } + catch (OperationCanceledException) + { + _logger.Info("PLC Polling Service is stopping"); + break; + } + catch (Exception ex) + { + _logger.Error(ex, "PLC polling error"); + await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken); + } + } + } + + _logger.Info("PLC Polling Service stopped"); + } + + /// + /// 保存工艺参数上传 + /// + /// + private async Task UploadProcessParameters(string productSN, string RoutingCode, string OperationCode) + { + bool result = true; + List productProcessParameters = new List(); + //实际产量 + ProductProcessParameters ActualProductParameter = new ProductProcessParameters + { + ProductSN = productSN, + RoutingCode = RoutingCode, + OperationCode = OperationCode, + ProductlinebodyCode = "line3", + WorkstationCode = OperationCode, + ParameterCode = "actual_product", + ParameterName = "实际产量", + PlcPoint = "DB1001.DBW1104", + Description = OperationCode + "工序的" + "实际产量", + DataType = "int", + Unit = "个", + ActualValue = (await _plcService.ReadAsync("DB1001.DBW1104")).ToString(), + CreatedTime = DateTime.Now, + }; + productProcessParameters.Add(ActualProductParameter); + + //合格数量 + ProductProcessParameters QualifiedProductParameter = new ProductProcessParameters + { + ProductSN = productSN, + RoutingCode = RoutingCode, + OperationCode = OperationCode, + ProductlinebodyCode = "line3", + WorkstationCode = OperationCode, + ParameterCode = "actual_product", + ParameterName = "合格数量", + PlcPoint = "DB1001.DBW1108", + Description = OperationCode + "工序的" + "合格数量", + DataType = "int", + Unit = "个", + ActualValue = (await _plcService.ReadAsync("DB1001.DBW1108")).ToString(), + CreatedTime = DateTime.Now, + }; + productProcessParameters.Add(QualifiedProductParameter); + + //失败数量 + ProductProcessParameters FailureProductParameter = new ProductProcessParameters + { + ProductSN = productSN, + RoutingCode = RoutingCode, + OperationCode = OperationCode, + ProductlinebodyCode = "line3", + WorkstationCode = OperationCode, + ParameterCode = "actual_product", + ParameterName = "失败数量", + PlcPoint = "DB1001.DBW1112", + Description = OperationCode + "工序的" + "失败数量", + DataType = "int", + Unit = "个", + ActualValue = (await _plcService.ReadAsync("DB1001.DBW1112")).ToString(), + CreatedTime = DateTime.Now, + }; + productProcessParameters.Add(FailureProductParameter); + + + //SN_1 + ProductProcessParameters SN_1Parameter = new ProductProcessParameters + { + ProductSN = productSN, + RoutingCode = RoutingCode, + OperationCode = OperationCode, + ProductlinebodyCode = "line3", + WorkstationCode = OperationCode, + ParameterCode = "SN_1", + ParameterName = "SN_1", + PlcPoint = "DB1001.DBW1112", + Description = OperationCode + "工序的" + "SN_1", + DataType = "string", + Unit = "个", + ActualValue = await _plcService.ReadStringAsync("DB1001.DBW1112"), + CreatedTime = DateTime.Now, + }; + productProcessParameters.Add(SN_1Parameter); + + //SN_2 + ProductProcessParameters SN_2Parameter = new ProductProcessParameters + { + ProductSN = productSN, + RoutingCode = RoutingCode, + OperationCode = OperationCode, + ProductlinebodyCode = "line3", + WorkstationCode = OperationCode, + ParameterCode = "SN_1", + ParameterName = "SN_1", + PlcPoint = "DB1001.DBW2134", + Description = OperationCode + "工序的" + "SN_2", + DataType = "string", + Unit = "个", + ActualValue = await _plcService.ReadStringAsync("DB1001.DBW2134"), + CreatedTime = DateTime.Now, + }; + productProcessParameters.Add(SN_2Parameter); + + //相机结果 + + int CameraResult = await _plcService.ReadAsync("DB1001.DBW2164"); + if (CameraResult == 1) + { + result = true; + } + if (CameraResult == 2) + { + result = false; + } + ProductProcessParameters CameraParameter = new ProductProcessParameters + { + ProductSN = productSN, + RoutingCode = RoutingCode, + OperationCode = OperationCode, + ProductlinebodyCode = "line3", + WorkstationCode = OperationCode, + ParameterCode = "CameraResult", + ParameterName = "CameraResult", + PlcPoint = "DB1001.DBW2164", + Description = OperationCode + "工序的" + "相机结果 1 OK 2 NG", + DataType = "int", + Unit = "个", + ActualValue = CameraResult.ToString(), + ExpectValue = "1", + Result = result ? 1 : 0, + CreatedTime = DateTime.Now, + }; + productProcessParameters.Add(CameraParameter); + + //站位结果 + int StationPosition = await _plcService.ReadAsync("DB1001.DBW2166"); + if (StationPosition == 1) + { + result = true; + } + if (StationPosition == 2) + { + result = false; + } + ProductProcessParameters StationPositionParameter = new ProductProcessParameters + { + ProductSN = productSN, + RoutingCode = RoutingCode, + OperationCode = OperationCode, + ProductlinebodyCode = "line3", + WorkstationCode = OperationCode, + ParameterCode = "StationPosition", + ParameterName = "StationPosition", + PlcPoint = "DB1001.DBW2166", + Description = OperationCode + "工序的" + "站位结果 1 OK 2 NG", + DataType = "int", + Unit = "个", + ActualValue = StationPosition.ToString(), + ExpectValue = "1", + Result = result ? 1 : 0, + CreatedTime = DateTime.Now, + }; + productProcessParameters.Add(StationPositionParameter); + + //节拍时间 real类型 + ProductProcessParameters BeatParameter = new ProductProcessParameters + { + ProductSN = productSN, + RoutingCode = RoutingCode, + OperationCode = OperationCode, + ProductlinebodyCode = "line3", + WorkstationCode = OperationCode, + ParameterCode = "beat", + ParameterName = "节拍时间", + PlcPoint = "DB1001.DBD2168", + Description = OperationCode + "工序的" + "节拍时间", + DataType = "float", + Unit = "s", + ActualValue = (await _plcService.ReadAsync("DB1001.DBD2168")).ToString(), + CreatedTime = DateTime.Now, + }; + productProcessParameters.Add(BeatParameter); + + await Context.Insertable(productProcessParameters).ExecuteCommandAsync(); + + return result; + + } + /// + /// 校验是否可以出站 + /// + /// 产品型号 + /// 产品SN + /// + private async Task checkOutPermission(string productModel, string productSN, string workstationCode, List processOperations, bool CheckOutstationResult) + { + + OutPermissionResult result = OutPermissionResult.UnkownException; + + if (!CheckOutstationResult) + { + + result = OutPermissionResult.ProcessParameterNG; + + goto InsertPassrecord; + } + + + //OK 准许进站 + result = OutPermissionResult.OK; + goto InsertPassrecord; + InsertPassrecord: + //插入出站请求Resp 过站记录 + ProductPassStationRecord RespintoStation = new ProductPassStationRecord + { + ProductSN = productSN, + WorkstationCode = WorkstationCode, + Routingcode = processOperations.First().FkRoutingCode, + OperationCode = WorkstationCode, + ProductionLifeStage = 1, // 1表示生产中 + PasstationType = 3, // 出站完毕 + PasstationDescription = "出站完毕Resp", + EffectTime = DateTime.Now, + OutStationTime = DateTime.Now, + ResultCode = (int)result, + ResultDescription = result.ToString(), + CreatedTime = DateTime.Now, + + }; + await Context.Insertable(RespintoStation).ExecuteCommandAsync(); + + return result; + } + + + + + } + /// + /// 出站校验结果 + /// + public enum OutPermissionResult + { + /// + /// 1 OK - 成功 + /// + OK = 1, + + /// + /// 2 产品时间属性增加失败 + /// + ProductTimeAttributeAddFailed = 2, + + /// + /// 3 产品条码合并失败 + /// + ProductBarcodeMergeFailed = 3, + + /// + /// 4 产品结果上传次数超出 + /// + ProductUploadCountExceeded = 4, + + /// + /// 5 时间属性移除失败 + /// + TimeAttributeRemoveFailed = 5, + + /// + /// 6 数据保存失败 + /// + DataSaveFailed = 6, + + /// + /// 10 上传条码为空 + /// + UploadBarcodeEmpty = 10, + /// + /// 11 未知异常 + /// + UnkownException = 11, + + /// + /// 工艺参数NG + /// + ProcessParameterNG = 12 + + + } +} +