update:更新B位静置库
This commit is contained in:
@@ -10,14 +10,20 @@ namespace MesServerFunctions
|
||||
{
|
||||
partial class FunctionMES
|
||||
{
|
||||
// OP431 手动静置出库固定配置。
|
||||
private const string ManualStaticOutOpName = "OP431";
|
||||
private const string ManualStaticPadTopic = "OP431PAD";
|
||||
private const decimal DefaultManualStaticMinutes = 30m;
|
||||
private const string ManualStaticLocation = "777777";
|
||||
private const string ManualStaticOperator = "PAD";
|
||||
|
||||
// 记录 PAD 确认时使用的最小静置分钟数,保存质量数据时沿用同一标准。
|
||||
private static readonly object ManualStaticMinutesLocker = new object();
|
||||
private static readonly Dictionary<string, decimal> ManualStaticMinutesByEngine = new Dictionary<string, decimal>();
|
||||
|
||||
/// <summary>
|
||||
/// OP431 当前产品基础信息。
|
||||
/// </summary>
|
||||
private class ManualStaticOutProduct
|
||||
{
|
||||
public string EngineID { get; set; }
|
||||
@@ -26,6 +32,9 @@ namespace MesServerFunctions
|
||||
public int EngineTypeID { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OP431 静置质量数据计算结果。
|
||||
/// </summary>
|
||||
private class ManualStaticOutData
|
||||
{
|
||||
public string SourceOpName { get; set; }
|
||||
@@ -35,6 +44,9 @@ namespace MesServerFunctions
|
||||
public int QualityMask { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询产品订单、型号和机型代码。
|
||||
/// </summary>
|
||||
private bool TryGetManualStaticOutProduct(string engineID, out ManualStaticOutProduct product, out string message)
|
||||
{
|
||||
product = null;
|
||||
@@ -63,6 +75,9 @@ namespace MesServerFunctions
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询 OP420 记录的线下手动静置开始时间。
|
||||
/// </summary>
|
||||
private bool TryGetManualStaticStartTime(string engineID, out string sourceOpName, out DateTime startTime, out string message)
|
||||
{
|
||||
sourceOpName = "";
|
||||
@@ -71,35 +86,61 @@ namespace MesServerFunctions
|
||||
|
||||
try
|
||||
{
|
||||
// 取 OP400/OP410/OP420 最后一条有效离开记录作为常温静置开始时间。
|
||||
string procedureName = "OP431手动静置出库_前序离开时间_查询";
|
||||
// OP431 手动出库以 OP420 记录的线下静置开始时间为准。
|
||||
string procedureName = "线下手动静置_记录_查询";
|
||||
SqlParameter[] sqlParameters = new SqlParameter[1];
|
||||
sqlParameters[0] = new SqlParameter("@发动机号", engineID);
|
||||
sqlParameters[0] = new SqlParameter("@产品编号", engineID);
|
||||
|
||||
DataAccess.ExecuteStoredProcedure(procedureName, ref sqlParameters, out DataTable dt, out string errorMessage);
|
||||
if (!string.IsNullOrWhiteSpace(errorMessage))
|
||||
{
|
||||
message = "查询前序出站时间失败:" + errorMessage;
|
||||
message = "查询线下手动静置开始时间失败:" + errorMessage;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
{
|
||||
message = "未查询到 OP400/OP410/OP420 前序出站记录";
|
||||
message = "未查询到线下手动静置开始记录:" + engineID;
|
||||
return false;
|
||||
}
|
||||
|
||||
sourceOpName = Convert.ToString(dt.Rows[0]["工位号"]);
|
||||
startTime = Convert.ToDateTime(dt.Rows[0]["开始静置时间"]);
|
||||
sourceOpName = "OP420";
|
||||
startTime = Convert.ToDateTime(dt.Rows[0]["静置开始时间"]);
|
||||
return true;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
message = "查询前序出站时间失败:" + err.Message;
|
||||
message = "查询线下手动静置开始时间失败:" + err.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OP431 保存时回写线下手动静置结束时间和静置时长。
|
||||
/// </summary>
|
||||
private bool FinishManualStaticRecord(string engineID, DateTime finishTime, decimal minutes, out string message)
|
||||
{
|
||||
message = "";
|
||||
SqlParameter[] sqlParameters = new SqlParameter[]
|
||||
{
|
||||
new SqlParameter("@产品编号", engineID),
|
||||
new SqlParameter("@静置结束时间", finishTime),
|
||||
new SqlParameter("@静置时长", minutes)
|
||||
};
|
||||
|
||||
DataAccess.ExecuteStoredProcedure("线下手动静置_记录_结束", ref sqlParameters, out string errorMessage);
|
||||
if (!string.IsNullOrWhiteSpace(errorMessage))
|
||||
{
|
||||
message = "回写线下手动静置结束时间失败:" + errorMessage;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成 OP431 保存时需要的静置时间和质量标识。
|
||||
/// </summary>
|
||||
private bool TryBuildManualStaticOutData(string engineID, int qualityMask, out ManualStaticOutData staticOutData, out string message)
|
||||
{
|
||||
staticOutData = null;
|
||||
@@ -110,6 +151,7 @@ namespace MesServerFunctions
|
||||
return false;
|
||||
}
|
||||
|
||||
// PLC 允许保存到达时的服务器时间作为静置完成时间。
|
||||
DateTime finishTime = DateTime.Now;
|
||||
decimal minutes = Math.Round(Convert.ToDecimal((finishTime - startTime).TotalMinutes), 2);
|
||||
staticOutData = new ManualStaticOutData
|
||||
@@ -123,11 +165,17 @@ namespace MesServerFunctions
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标准化质量标识:1 为合格,其余均按不合格处理。
|
||||
/// </summary>
|
||||
private int NormalizeManualStaticQualityMask(int qualityMask)
|
||||
{
|
||||
return qualityMask == 1 ? 1 : 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断静置时长是否达到 PAD 配置的最小分钟数。
|
||||
/// </summary>
|
||||
private bool IsManualStaticTimeEnough(ManualStaticOutData staticOutData, decimal minStaticMinutes, out string message)
|
||||
{
|
||||
message = "";
|
||||
@@ -139,6 +187,9 @@ namespace MesServerFunctions
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接写入 OP431 四项静置质量数据。
|
||||
/// </summary>
|
||||
private bool WriteManualStaticOutQualityData(string opName, string engineID, ManualStaticOutData data, out string message)
|
||||
{
|
||||
message = "";
|
||||
@@ -149,6 +200,7 @@ namespace MesServerFunctions
|
||||
return false;
|
||||
}
|
||||
|
||||
// 先写质量索引,取返回的 Id_tagCF 作为明细关联键。
|
||||
string minStaticMinutes = rememberedMinStaticMinutes.ToString("0.##");
|
||||
|
||||
// OP431 的静置数据由 Function 直接落库,不再通过 OnlineCheckData 做 HTTP 自调用。
|
||||
@@ -175,6 +227,7 @@ namespace MesServerFunctions
|
||||
return false;
|
||||
}
|
||||
|
||||
// 四条质量明细必须与 MOM 数据收集组配置的 TagID 保持一致。
|
||||
object[,] detailRows = new object[,]
|
||||
{
|
||||
{ "OP431_M0001_001", "开始静置时间", "min", "1", "60", minStaticMinutes, data.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), data.QualityMask },
|
||||
@@ -211,6 +264,9 @@ namespace MesServerFunctions
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确认上线前校验托盘到位和 PLC 申请上线状态。
|
||||
/// </summary>
|
||||
private bool CheckManualStaticPadPrecondition(string opName, out string message)
|
||||
{
|
||||
message = "";
|
||||
@@ -232,6 +288,9 @@ namespace MesServerFunctions
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PAD 确认上线:校验静置条件,通过后写入 PLC 产品区。
|
||||
/// </summary>
|
||||
private bool ConfirmManualStaticOutProduct(string opName, string engineID, decimal minStaticMinutes, out string message)
|
||||
{
|
||||
message = "";
|
||||
@@ -273,6 +332,9 @@ namespace MesServerFunctions
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PAD 扫码查询:返回产品、静置时间和是否允许确认。
|
||||
/// </summary>
|
||||
private bool QueryManualStaticOutProduct(string opName, string engineID, decimal minStaticMinutes, out string resultMessage)
|
||||
{
|
||||
resultMessage = "";
|
||||
@@ -292,6 +354,7 @@ namespace MesServerFunctions
|
||||
bool timeEnough = IsManualStaticTimeEnough(staticOutData, minStaticMinutes, out string timeMessage);
|
||||
MIS_BASE.Read_PartLoad(opName, out bool partLoad);
|
||||
|
||||
// PAD 直接使用 canConfirm 控制按钮,不再自行组合判断条件。
|
||||
bool canConfirm = timeEnough && partLoad;
|
||||
string confirmMessage = canConfirm
|
||||
? "允许确认上线"
|
||||
@@ -316,6 +379,9 @@ namespace MesServerFunctions
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将 PAD 业务结果同时发送到 PAD 主题和工位主题。
|
||||
/// </summary>
|
||||
private void SendManualStaticOutResult(string opName, string command, bool success, string message)
|
||||
{
|
||||
string value = (success ? "1" : "0") + "^" + message;
|
||||
@@ -329,11 +395,17 @@ namespace MesServerFunctions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向 OP431 PAD 专用主题发送 MQTT 回包。
|
||||
/// </summary>
|
||||
private void SendManualStaticPadMqttMessage(string command, string opName, string value)
|
||||
{
|
||||
SendMessage.AsyncSendNotOpMessage(ManualStaticPadTopic, "MES|" + command + "|" + opName + "|" + value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录产品确认上线时使用的最小静置标准。
|
||||
/// </summary>
|
||||
private void RememberManualStaticMinutesForProduct(string engineID, decimal minStaticMinutes)
|
||||
{
|
||||
lock (ManualStaticMinutesLocker)
|
||||
@@ -342,6 +414,9 @@ namespace MesServerFunctions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取产品确认上线时记录的最小静置标准。
|
||||
/// </summary>
|
||||
private bool TryGetManualStaticMinutesForProduct(string engineID, out decimal minStaticMinutes)
|
||||
{
|
||||
lock (ManualStaticMinutesLocker)
|
||||
|
||||
Reference in New Issue
Block a user