diff --git a/SCADA/App.config b/SCADA/App.config index 7514c2f..bc5a643 100644 --- a/SCADA/App.config +++ b/SCADA/App.config @@ -23,10 +23,15 @@ - - - - + + + + + + + + + diff --git a/SCADA/Funtion/B_DB_Opera.cs b/SCADA/Funtion/B_DB_Opera.cs index 22e6cf0..fa74d11 100644 --- a/SCADA/Funtion/B_DB_Opera.cs +++ b/SCADA/Funtion/B_DB_Opera.cs @@ -363,12 +363,22 @@ namespace MesWork /// /// 更新过站记录为完成(case 19 请求保存时调用) /// - public static bool UpdateStationComplete(string engineNo, string stationNo, decimal weight) + public static bool UpdateStationComplete(string engineNo, string stationNo, decimal weight, + string modelNo = "", string orderNo = "", string palletNo = "", string stationName = "", + decimal addOilQty = 0, decimal extractOilQty = 0, decimal density = 0, string worker = "") { var sqlParameter = new SqlParameter[] { new SqlParameter("@发动机号", engineNo), new SqlParameter("@工位号", stationNo), - new SqlParameter("@称重重量", weight) + new SqlParameter("@称重重量", weight), + new SqlParameter("@机型号", modelNo), + new SqlParameter("@工单号", orderNo), + new SqlParameter("@托盘号", palletNo), + new SqlParameter("@工位名称", stationName), + new SqlParameter("@加油量", addOilQty), + new SqlParameter("@抽油量", extractOilQty), + new SqlParameter("@油密度", density), + new SqlParameter("@操作者", worker) }; SqlOperation.ExecuteStoredProcedure("过站记录_完成", sqlParameter, out DataTable dt, out string err); return dt != null && dt.Rows.Count > 0 && dt.Rows[0]["result"].ToString() == "1"; diff --git a/SCADA/Funtion/MIS_CurveCollector.cs b/SCADA/Funtion/MIS_CurveCollector.cs index f8fc514..071774e 100644 --- a/SCADA/Funtion/MIS_CurveCollector.cs +++ b/SCADA/Funtion/MIS_CurveCollector.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Configuration; using System.Globalization; using System.Linq; using System.Threading; @@ -30,8 +31,13 @@ namespace MesWork private static readonly ConcurrentDictionary _curveCollectors = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); - private const int CurveCollectorSampleIntervalMs = 200; - private const int CurveStableWindowSize = 20; + private static readonly int CurveCollectorSampleIntervalMs = int.TryParse( + ConfigurationManager.AppSettings["CurveCollectorSampleIntervalMs"], out int _sampleIntervalMs) + ? _sampleIntervalMs : 200; + + private static readonly int CurveStableWindowSize = int.TryParse( + ConfigurationManager.AppSettings["CurveStableWindowSize"], out int _stableWindowSize) + ? _stableWindowSize : 20; /// /// 允许工作后启动曲线采集,每个工位同一时间只保留一个采集段。 diff --git a/SCADA/Funtion/MIS_Funtion.cs b/SCADA/Funtion/MIS_Funtion.cs index 6192814..cdd3496 100644 --- a/SCADA/Funtion/MIS_Funtion.cs +++ b/SCADA/Funtion/MIS_Funtion.cs @@ -134,24 +134,24 @@ namespace MesWork // ==================================================================== // 称重交互核心方法 // ==================================================================== - /// - /// 获取称重类型:地面/放油前/放油后 - /// Ground模式:统一返回"地面" - /// Hanging模式:工位1=放油前,工位2=放油后 - /// - private string GetWeighingType(string opName) - { - if (WeighingType == "Ground") - return "地面"; - - if (string.Equals(opName, Station1OpName, StringComparison.OrdinalIgnoreCase)) - return "放油前"; - - if (string.Equals(opName, Station2OpName, StringComparison.OrdinalIgnoreCase)) - return "放油后"; - - throw new InvalidOperationException($"工位号[{opName}]未匹配到App.config中的Station1OpName/Station2OpName,请检查工位配置"); - } + /// + /// 获取称重类型:地面/放油前/放油后 + /// Ground模式:统一返回"地面" + /// Hanging模式:工位1=放油前,工位2=放油后 + /// + private string GetWeighingType(string opName) + { + if (WeighingType == "Ground") + return "地面"; + + if (string.Equals(opName, Station1OpName, StringComparison.OrdinalIgnoreCase)) + return "放油前"; + + if (string.Equals(opName, Station2OpName, StringComparison.OrdinalIgnoreCase)) + return "放油后"; + + throw new InvalidOperationException($"工位号[{opName}]未匹配到App.config中的Station1OpName/Station2OpName,请检查工位配置"); + } /// @@ -169,9 +169,9 @@ namespace MesWork // 清除油量参数信息 WeighingPage?.UpdateOilInfo(stIdx, 0, 0, 0, 0, 0); - // 清除结果信息 - WeighingPage?.UpdateOilResult(stIdx, 0, 0); - + // 清除结果信息 + WeighingPage?.UpdateOilResult(stIdx, 0, 0); + } catch (Exception err) { @@ -319,9 +319,16 @@ namespace MesWork decimal plcWeight = Convert.ToDecimal(ReadPLC(100140, opName)); // PLC锁定重量,曲线无效时兜底使用 decimal weight = plcWeight; // 默认使用PLC锁定重量,曲线算法成功后覆盖 decimal waterContent = Convert.ToDecimal(ReadPLC(100180, opName)); // 水含量 - string engineNo = PLC_R.GetString_CleanGarbled(ReadPLC(10, opName)); // 产品编号 - if (TryConvertCodeBlockData(engineNo, out _, out string parsedProductNo)) + string engineNo = PLC_R.GetString_CleanGarbled(ReadPLC(10, opName)); // 原始代码串/产品编号 + string modelNo = PLC_R.GetString_CleanGarbled(ReadPLC(11, opName)); // 机型号 + string orderNo = PLC_R.GetString_CleanGarbled(ReadPLC(39, opName)); // 工单号/订货号 + string palletNo = PLC_R.GetString_CleanGarbled(ReadPLC(80, opName)); // 托盘号 + if (TryConvertCodeBlockData(engineNo, out string parsedOrderNo, out string parsedProductNo)) { + if (!string.IsNullOrWhiteSpace(parsedOrderNo)) + { + orderNo = parsedOrderNo; + } engineNo = parsedProductNo; } else if (string.IsNullOrWhiteSpace(engineNo)) @@ -350,9 +357,31 @@ namespace MesWork WeighingPage?.AppendLog($"[{opName}] PLC锁定重量标定:原始={rawWeight:F3}kg,公式={calibrationFormula},结果={weight:F3}kg"); } - long curveWeighingRecordId = 0; - B_DB_Opera.UpdateStationComplete(engineNo, opName, weight); // 过站记录保存最终采用重量 - string weighType = GetWeighingType(opName); + long curveWeighingRecordId = 0; + string weighType = GetWeighingType(opName); + decimal addOilQty = 0; + decimal extractOilQty = 0; + decimal density = 0; + decimal residualOilUpperLimit = 0; + decimal residualOilLowerLimit = 0; + if (!string.IsNullOrWhiteSpace(orderNo) && + B_DB_Opera.QueryWorkpieceByOrderNo(orderNo, out string matchedModelNo, out decimal matchedAddOilQty, + out decimal matchedExtractOilQty, out decimal matchedDensity, out decimal matchedResidualOilUpperLimit, + out decimal matchedResidualOilLowerLimit)) + { + modelNo = matchedModelNo; + addOilQty = matchedAddOilQty; + extractOilQty = matchedExtractOilQty; + density = matchedDensity; + residualOilUpperLimit = matchedResidualOilUpperLimit; + residualOilLowerLimit = matchedResidualOilLowerLimit; + } + + if (!B_DB_Opera.UpdateStationComplete(engineNo, opName, weight, modelNo, orderNo, palletNo, weighType, + addOilQty, extractOilQty, density, Curr_UserName)) // 过站记录保存最终采用重量;找不到则由SP补异常完成记录 + { + LogWeighingFallback(opName, engineNo, "请求保存-过站", "未找到请求工作过站记录,已补异常过站完成记录", AID); + } decimal oilReleaseQty = 0; decimal residualOilQty = 0; int finalQualityFlag = 1; @@ -376,8 +405,8 @@ namespace MesWork else { // 兜底机制:请求工作阶段资料异常可能没有占位记录,保存时补一条异常完成记录,避免PLC等不到保存完成。 - curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "地面", engineNo, "", "", "", - 0, weight, 0, 0, 0, 0, 0, 0, 0, 2, waterContent, + curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "地面", engineNo, modelNo, orderNo, palletNo, + 0, weight, addOilQty, extractOilQty, density, residualOilUpperLimit, residualOilLowerLimit, 0, 0, 2, waterContent, opName, Curr_UserName, isComplete: 1); finalQualityFlag = 2; qualityMsg = "未找到请求工作占位记录,已按异常地面记录保存"; @@ -400,8 +429,8 @@ namespace MesWork else { // 兜底机制:没有占位记录时补异常记录并完成握手,后续放油后仍可按异常链路继续。 - curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "空中", engineNo, "", "", "", - weight, 0, 0, 0, 0, 0, 0, 0, 0, 2, waterContent, + curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "空中", engineNo, modelNo, orderNo, palletNo, + weight, 0, addOilQty, extractOilQty, density, residualOilUpperLimit, residualOilLowerLimit, 0, 0, 2, waterContent, opName, Curr_UserName, isComplete: 1); finalQualityFlag = 2; qualityMsg = "未找到请求工作占位记录,已按异常放油前记录保存"; @@ -426,9 +455,9 @@ namespace MesWork } else { - // 找不到放油前记录(可能直接进放油后工位):创建一条放油后记录并标记完成 - curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "空中放油后", engineNo, "", "", "", - 0, weight, 0, 0, 0, 0, 0, 0, 0, 2, waterContent, + // 找不到放油前记录(可能直接进放油后工位):创建一条放油后记录并标记完成 + curveWeighingRecordId = B_DB_Opera.InsertWeighingRecord(opName, "空中放油后", engineNo, modelNo, orderNo, palletNo, + 0, weight, addOilQty, extractOilQty, density, residualOilUpperLimit, residualOilLowerLimit, 0, 0, 2, waterContent, opName, Curr_UserName, isComplete: 1); // 异常兜底记录,质量直接判不合格 finalQualityFlag = 2; qualityMsg = "未找到放油前记录"; @@ -462,7 +491,7 @@ namespace MesWork /// 扫码枪扫码完成后的业务处理 /// 将码值写入PLC地址102500,触发完成信号100016=1,1秒后复位 /// - /// 工位号,由COM口绑定决定 + /// 工位号,由COM口绑定决定 /// 扫到的条码值 public void Barcode_HandleScan(string opName, string barcode) {