4.11更新
1.添加是否调用mes接口按钮,并只有admin用户可以点击,2.修改螺丝引导页面 3.端子只有一个,端子扫码借用扫码页面
This commit is contained in:
1 parent
752e1f37b6
commit
69c851c09e
15 files changed
+1006
-387
No files matched your search
@@ -35,6 +35,7 @@ namespace WindowsFormsApp1.server
|
||||
private readonly string _token;
|
||||
private readonly string _fixsn;
|
||||
private readonly string _logBasePath;
|
||||
private static bool _isTestMode = true; // 默认为测试模式
|
||||
|
||||
public ApiClient()
|
||||
{
|
||||
@@ -46,6 +47,13 @@ namespace WindowsFormsApp1.server
|
||||
var apiList = helper.QueryAll().Data.Select(x => new { x.code, url = x.url + x.code }).ToList();
|
||||
apiUrlDict = apiList.ToDictionary(x => x.code, x => x.url);
|
||||
|
||||
SQLiteHelper<t_keyvalue> kvHelper = new db.SQLiteHelper<t_keyvalue>();
|
||||
var testModeSetting = kvHelper.QuerySingle(x => x.key == "TestMode");
|
||||
if (testModeSetting.Success)
|
||||
{
|
||||
_isTestMode = testModeSetting.Data.value == "1";
|
||||
}
|
||||
|
||||
// 从配置中读取通用参数
|
||||
_line = Init.t_Line.lineremark1;
|
||||
_stationID = Init.t_Line.lineremark2;
|
||||
@@ -58,7 +66,7 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
// 初始化 CsvLogger
|
||||
// 初始化日志路径
|
||||
_logBasePath = Path.Combine(@"C:\", "Logs", $"logs.csv");
|
||||
_logBasePath = Path.Combine(@"D:\", "Logs", $"logs.csv");
|
||||
|
||||
// 初始化CSV日志记录器
|
||||
CsvLogger.Initialize(_logBasePath);
|
||||
@@ -95,7 +103,7 @@ namespace WindowsFormsApp1.server
|
||||
break;
|
||||
case "sealant":
|
||||
headers.Add("胶宽");
|
||||
headers.Add("CCD结果");
|
||||
headers.Add("胶高");
|
||||
break;
|
||||
case "curing":
|
||||
headers.Add("固化温度");
|
||||
@@ -125,108 +133,110 @@ namespace WindowsFormsApp1.server
|
||||
var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||
|
||||
#region test
|
||||
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
|
||||
PlcData.Write_stSN = "testsn";
|
||||
LogExecute.logNet.WriteDebug($"{eventName} 测ui接口请求成功\n请求:{jsonPayload}\n");
|
||||
return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
|
||||
|
||||
if (_isTestMode)
|
||||
{
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
|
||||
PlcData.Write_stSN = "TEST MODE testsn";
|
||||
LogExecute.logNet.WriteDebug($"{eventName} 测试接口请求成功\n请求:{jsonPayload}\n");
|
||||
return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
|
||||
}
|
||||
#endregion test
|
||||
|
||||
#region 正式调用接口
|
||||
|
||||
/*try
|
||||
else
|
||||
{
|
||||
#region MES交互
|
||||
|
||||
var response = _httpClient.PostAsync(url, httpContent).Result;
|
||||
// 检查响应状态码
|
||||
if (response.IsSuccessStatusCode)
|
||||
try
|
||||
{
|
||||
// 读取响应内容
|
||||
string responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
#region MES交互
|
||||
|
||||
// 使用 Newtonsoft.Json 将响应内容反序列化为动态对象
|
||||
dynamic res = JsonConvert.DeserializeObject(responseContent);
|
||||
|
||||
// 访问动态对象的属性
|
||||
if (res != null)
|
||||
var response = _httpClient.PostAsync(url, httpContent).Result;
|
||||
// 检查响应状态码
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
|
||||
// 读取响应内容
|
||||
string responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
// 成功!
|
||||
if (res.Result != null && !string.IsNullOrEmpty(res.Result.Value))
|
||||
// 使用 Newtonsoft.Json 将响应内容反序列化为动态对象
|
||||
dynamic res = JsonConvert.DeserializeObject(responseContent);
|
||||
|
||||
// 访问动态对象的属性
|
||||
if (res != null)
|
||||
{
|
||||
var result = res.Result.Value == "PASS";
|
||||
LogExecute.logNet.WriteDebug($"{eventName} 接口请求成功\n请求:{jsonPayload}\n 返回: {responseContent}");
|
||||
|
||||
if (result)
|
||||
// 成功!
|
||||
if (res.Result != null && !string.IsNullOrEmpty(res.Result.Value))
|
||||
{
|
||||
var result = res.Result.Value == "PASS";
|
||||
|
||||
if (result)
|
||||
{
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
|
||||
PlcData.Write_stSN = res.SN.Value;
|
||||
if (eventName == "SN_FeedingCheck")
|
||||
{
|
||||
var station = Init.t_Line.lineremark2.ToLower();
|
||||
switch (station)
|
||||
{
|
||||
case "potting"://灌胶
|
||||
case "thermalpaste"://点胶&CCD检测
|
||||
case "uvcoating"://三防漆涂覆
|
||||
case "sealant"://点密封胶&CCD
|
||||
var power = Init.t_Keyvalues.First(x => x.key == "Power");
|
||||
power.value = res.SN.Value.ToString();
|
||||
SQLiteHelper<t_keyvalue> kvHelper = new db.SQLiteHelper<t_keyvalue>();
|
||||
kvHelper.Update(power);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 判断此站是否有胶水。返回fail,执行胶水下线
|
||||
if (eventName == "SN_FeedingCheck")
|
||||
{
|
||||
//执行胶水下线操作
|
||||
}
|
||||
}
|
||||
return result
|
||||
? ApiFormResult.Sucess(mesresult.PASS, true, res.Msg?.Value ?? "", PlcData, DateTime.Now)
|
||||
: ApiFormResult.Sucess(mesresult.FAIL, true, res.Msg?.Value ?? "", PlcData, DateTime.Now);
|
||||
}
|
||||
else if (res.IsSuccess != null) // 打印 mes不返回result
|
||||
{
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
|
||||
PlcData.Write_stSN = res.SN.Value;
|
||||
if (eventName == "SN_FeedingCheck")
|
||||
{
|
||||
var station = Init.t_Line.lineremark2.ToLower();
|
||||
switch (station)
|
||||
{
|
||||
case "potting"://灌胶
|
||||
case "thermalpaste"://点胶&CCD检测
|
||||
case "uvcoating"://三防漆涂覆
|
||||
case "sealant"://点密封胶&CCD
|
||||
var power = Init.t_Keyvalues.First(x => x.key == "Power");
|
||||
power.value = res.SN.Value.ToString();
|
||||
SQLiteHelper<t_keyvalue> kvHelper = new db.SQLiteHelper<t_keyvalue>();
|
||||
kvHelper.Update(power);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 判断此站是否有胶水。返回fail,执行胶水下线
|
||||
if (eventName == "SN_FeedingCheck")
|
||||
{
|
||||
//执行胶水下线操作
|
||||
}
|
||||
}
|
||||
return result
|
||||
return res.IsSuccess.Value == true
|
||||
? ApiFormResult.Sucess(mesresult.PASS, true, res.Msg?.Value ?? "", PlcData, DateTime.Now)
|
||||
: ApiFormResult.Sucess(mesresult.FAIL, true, res.Msg?.Value ?? "", PlcData, DateTime.Now);
|
||||
}
|
||||
else if (res.IsSuccess != null) // 打印 mes不返回result
|
||||
{
|
||||
// 回写对应PLC
|
||||
if (statusCode > 0)
|
||||
PlcData.Write_Status = (short)statusCode;
|
||||
return res.IsSuccess.Value == true
|
||||
? ApiFormResult.Sucess(mesresult.PASS, true, res.Msg?.Value ?? "", PlcData, DateTime.Now)
|
||||
: ApiFormResult.Sucess(mesresult.FAIL, true, res.Msg?.Value ?? "", PlcData, DateTime.Now);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"请求失败,状态码:{response.StatusCode}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"请求失败,状态码:{response.StatusCode}");
|
||||
LogExecute.logNet.WriteError($"{eventName} 接口请求失败: {ex.Message}");
|
||||
//return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
|
||||
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
|
||||
#endregion
|
||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogExecute.logNet.WriteError($"{eventName} 接口请求失败: {ex.Message}");
|
||||
//return ApiFormResult.Sucess(mesresult.PASS, true, "PASS", PlcData, DateTime.Now);
|
||||
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
|
||||
return ApiFormResult.Sucess(mesresult.PASS, false, "", PlcData, DateTime.Now);
|
||||
*/
|
||||
#endregion 正式调用接口
|
||||
|
||||
}
|
||||
@@ -238,7 +248,7 @@ namespace WindowsFormsApp1.server
|
||||
var stationid = Init.t_Line.lineremark2.ToLower();
|
||||
if ("loadaging,exchange2,exchange1".Contains(stationid))
|
||||
{
|
||||
sn = PlcData.Write_stSN ?? OtherData.JS_SN;
|
||||
sn = PlcData.Read_MaterialCode0 ?? OtherData.JS_SN;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -296,7 +306,7 @@ namespace WindowsFormsApp1.server
|
||||
/// <returns></returns>
|
||||
public ApiFormResult SN_FeedingCheck(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
OtherData.JS_SN = PlcData.Read_MaterialCode2;
|
||||
//OtherData.JS_SN = PlcData.Read_MaterialCode2;
|
||||
//判断是否为胶水站,是查询materialscan中上线的胶水码
|
||||
var station = Init.t_Line.lineremark2.ToLower();
|
||||
switch (station)
|
||||
@@ -324,18 +334,29 @@ namespace WindowsFormsApp1.server
|
||||
OPID = _opID,
|
||||
Token = _token,
|
||||
FixSN = _fixsn,
|
||||
SN = OtherData.JS_SN ?? PlcData.Write_stSN,//扫码
|
||||
SN = OtherData.JS_SN ?? PlcData.Read_MaterialCode2 ?? Init.DZString,//扫码
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
var result = CallApi(url, request, "SN_FeedingCheck", PlcData, PLC_Status.SN_FeedingCheck);
|
||||
if (result.Success && result.Mesresult != mesresult.PASS)
|
||||
if (result.Success && result.Mesresult != mesresult.PASS && result.Msg.Contains("过期"))
|
||||
{
|
||||
// 判断是否是胶水站,FAIL 直接下线 todo
|
||||
if ("Potting,ThermalPaste,Sel_Soldering,UVCoating,Sealant".Contains(station))
|
||||
// 判断是否是胶水站,FAIL 直接下线
|
||||
if ("potting,thermalpaste,sel_soldering,uvcoating,sealant".Contains(station))
|
||||
{
|
||||
OtherData.opindex = 2;
|
||||
return CallFunctionByName("Glue_CheckOut", PlcData, OtherData);
|
||||
var glueResult = CallFunctionByName("Glue_CheckOut", PlcData, OtherData);
|
||||
if (glueResult.Success && glueResult.Mesresult == mesresult.PASS)
|
||||
{
|
||||
//更新胶水为下线
|
||||
var _dbHelper = new SQLiteHelper<t_materialscan>();
|
||||
var material = _dbHelper.QuerySingle(x => x.scancode == OtherData.JS_SN).Data;
|
||||
if (material != null)
|
||||
{
|
||||
material.isonline = false;
|
||||
_dbHelper.Update(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -365,7 +386,7 @@ namespace WindowsFormsApp1.server
|
||||
new CompListItem()
|
||||
{
|
||||
// 安装主板 端子
|
||||
CompID = OtherData.JS_SN ?? Init.ScanString,
|
||||
CompID = OtherData.JS_SN ?? Init.DZString,
|
||||
Qty = "1"
|
||||
}
|
||||
},
|
||||
@@ -556,8 +577,8 @@ namespace WindowsFormsApp1.server
|
||||
string targetFolder = targetDirectory;
|
||||
List<string> fileList = new List<string>();
|
||||
|
||||
//从数据库读 未上传的 todo
|
||||
string snNumber = PlcData.Write_stSN;
|
||||
//从数据库读 未上传的,从定时器中传出来
|
||||
string snNumber = OtherData.SN;
|
||||
|
||||
if (string.IsNullOrEmpty(snNumber))
|
||||
{
|
||||
@@ -601,7 +622,7 @@ namespace WindowsFormsApp1.server
|
||||
continue;
|
||||
}
|
||||
extensionstr = Path.GetExtension(file);
|
||||
fileName = $"{month}{day}_{_stationID}_{result}_{PlcData.Write_stSN}_{monthDay}_{time}_{_machineID}_01_Original{num}{extensionstr}";
|
||||
fileName = $"{month}{day}_{_stationID}_{result}_{snNumber}_{monthDay}_{time}_{_machineID}_01_Detection_{num}{extensionstr}";
|
||||
filePath = Path.Combine(sourceFolder, fileName1);
|
||||
//string targetPath = Path.Combine(targetFolder, fileName);
|
||||
//File.Copy(file, targetPath, true);
|
||||
@@ -779,6 +800,12 @@ namespace WindowsFormsApp1.server
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
//抽真空 fixsn 用作穴位
|
||||
if (stationid.ToLower() == "vacuum")
|
||||
{
|
||||
request.FixSN = OtherData.plcid.ToString();
|
||||
}
|
||||
|
||||
// 根据不同的lineCode可以在这里扩展request对象
|
||||
var dcInfo = new DCInfoItem();
|
||||
var sninfo = request.SNInfo[0];
|
||||
@@ -883,7 +910,7 @@ namespace WindowsFormsApp1.server
|
||||
if ("Curing".Contains(stationid))
|
||||
{
|
||||
SQLiteHelper<t_materialcall> materialHelper = new db.SQLiteHelper<t_materialcall>();
|
||||
var material = materialHelper.QuerySingle(x => x.materialid == PlcData.Write_stSN);
|
||||
var material = materialHelper.QuerySingle(x => x.sn == PlcData.Write_stSN);
|
||||
if (material.Success)
|
||||
{
|
||||
// 计算加热时间
|
||||
@@ -910,6 +937,7 @@ namespace WindowsFormsApp1.server
|
||||
//报错,没有这个物料
|
||||
}
|
||||
}
|
||||
|
||||
//胶重
|
||||
if ("Potting,ThermalPaste".Contains(stationid))
|
||||
{
|
||||
@@ -922,24 +950,26 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
sninfo.DC_INFO.Add(dcInfo);
|
||||
}
|
||||
//胶重 胶宽 CCD
|
||||
|
||||
// 胶宽 胶高 CCD
|
||||
if ("Sealant".Contains(stationid))
|
||||
{
|
||||
dcInfo = new DCInfoItem();
|
||||
dcInfo.Item = $"{stationid}_Weight";
|
||||
dcInfo.Item = $"{stationid}_Width";
|
||||
dcInfo.Value = PlcData.Read_UploadData0.ToString();
|
||||
dcInfo.Result = result;
|
||||
|
||||
sninfo.DC_INFO.Add(dcInfo);
|
||||
|
||||
dcInfo = new DCInfoItem();
|
||||
dcInfo.Item = $"{stationid}_Width";
|
||||
dcInfo.Item = $"{stationid}_Height";
|
||||
dcInfo.Value = PlcData.Read_UploadData1.ToString();
|
||||
dcInfo.Result = result;
|
||||
CsvLogger.Log($"{PlcData.Write_stSN},{PlcData.Read_UploadData0.ToString()},{PlcData.Read_UploadData1.ToString()},{logresult}");
|
||||
|
||||
sninfo.DC_INFO.Add(dcInfo);
|
||||
}
|
||||
|
||||
//胶水 材料码
|
||||
if ("Potting,ThermalPaste,Sel_Soldering,UVCoating,Sealant".Contains(stationid))
|
||||
{
|
||||
@@ -960,6 +990,52 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
sninfo.CompList.Add(compListItem);
|
||||
}
|
||||
|
||||
//图片上传
|
||||
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".Contains(stationid))
|
||||
{
|
||||
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
|
||||
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
|
||||
if (material == null)
|
||||
{
|
||||
material = new t_materialupload
|
||||
{
|
||||
sn = PlcData.Write_stSN,
|
||||
imageUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyyMMdd")
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.imageUploaded = 1;
|
||||
materialuploadHelper.Update(material);
|
||||
}
|
||||
}
|
||||
|
||||
//视频上传
|
||||
if ("WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel".Contains(stationid))
|
||||
{
|
||||
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
|
||||
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
|
||||
if (material == null)
|
||||
{
|
||||
material = new t_materialupload
|
||||
{
|
||||
sn = PlcData.Write_stSN,
|
||||
vedioUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyyMMdd")
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.vedioUploaded = 1;
|
||||
materialuploadHelper.Update(material);
|
||||
}
|
||||
}
|
||||
return CallApi(url, request, "SN_Checkout", PlcData, PLC_Status.SN_Checkout);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user