4.18 checkin不管成功失败都写sn
加上needwork的判定 datacollection 判断dcinfo为空,不传mes,事件不显示在事件列表,只记录日志 状态上传定时器重新修改上传逻辑 文件上传定时器
This commit is contained in:
1 parent
4419a4de3c
commit
76cd069435
7 files changed
+461
-239
No files matched your search
@@ -157,7 +157,8 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
var response = _httpClient.PostAsync(url, httpContent).Result;
|
||||
// 检查响应状态码
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK
|
||||
|| response.StatusCode == System.Net.HttpStatusCode.BadRequest)
|
||||
{
|
||||
// 读取响应内容
|
||||
string responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
@@ -174,14 +175,15 @@ namespace WindowsFormsApp1.server
|
||||
if (res.Result != null && !string.IsNullOrEmpty(res.Result.Value))
|
||||
{
|
||||
var result = res.Result.Value == "PASS";
|
||||
|
||||
if(!string.IsNullOrEmpty( res?.Need_Work?.Value) && res?.Need_Work?.Value == "PASS")
|
||||
result = true;
|
||||
if (eventName == "SN_Release" || eventName == "SN_CheckIN")
|
||||
PlcData.Write_stSN = res.SN.Value;
|
||||
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();
|
||||
@@ -447,7 +449,7 @@ namespace WindowsFormsApp1.server
|
||||
//判断站
|
||||
var station = Init.t_Line.lineremark2.ToLower();
|
||||
var fixsn_1 = "";
|
||||
var locationindex = 1;
|
||||
var locationindex = "";
|
||||
switch (station)
|
||||
{
|
||||
case "potting"://灌胶
|
||||
@@ -457,7 +459,7 @@ namespace WindowsFormsApp1.server
|
||||
break;
|
||||
default:
|
||||
fixsn_1 = "CompSN";
|
||||
locationindex = OtherData.locationindex;
|
||||
locationindex = OtherData.locationindex.ToString();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -468,13 +470,13 @@ namespace WindowsFormsApp1.server
|
||||
StationID = _stationID,
|
||||
MachineID = _machineID,
|
||||
OPID = OtherData.opindex,
|
||||
Token = locationindex.ToString() ?? "",//判断站,胶水不用传
|
||||
Token = locationindex ?? "",//判断站,胶水不用传
|
||||
FixSN = fixsn_1,//判断站,胶水不用传
|
||||
SN = OtherData.JS_SN ?? "",
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "Glue_CheckOut", PlcData, PLC_Status.Glue_CheckOut);
|
||||
return CallApi(url, request, "Glue_CheckOut", PlcData, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -525,7 +527,7 @@ namespace WindowsFormsApp1.server
|
||||
else if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(station))
|
||||
{
|
||||
// 扭力 读马头服务器
|
||||
var geturl = $"http://10.50.12.41/getdata/v2/tighteningresults?startTime={OtherData.material.date}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}&vin={OtherData.material.sn}&controllerName={Init.t_Line.lineremark2}@{Init.t_Line.linecode}&includeCurve=true&includeSteps=false";
|
||||
var geturl = $"http://10.50.12.41/getdata/v2/tighteningresults?startTime={OtherData.material.date.Substring(0,10)}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}&vin={OtherData.material.sn}&controllerName={Init.t_Line.lineremark2}@{Init.t_Line.linecode}&includeCurve=true&includeSteps=false";
|
||||
//var geturl = "http://10.50.12.41/getdata/v2/tighteningresults?startTime=2025-04-11&endTime=2025-04-12&vin=ok&controllerName=OP1260%4010.50.247.110&includeCurve=true&includeSteps=false";
|
||||
|
||||
var res = _httpClient.GetAsync(geturl).Result;
|
||||
@@ -582,15 +584,17 @@ namespace WindowsFormsApp1.server
|
||||
LogExecute.logNet.WriteError($"解析马头数据,发生错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ApiFormResult.Sucess(mesresult.FAIL, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
|
||||
}
|
||||
if(request.DC_INFO.Count == 0)
|
||||
{
|
||||
return ApiFormResult.Sucess(mesresult.FAIL, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
||||
return CallApi(url, request, "Data_Collection", PlcData, statusCode);
|
||||
//if(result.Success && result.Mesresult == mesresult.PASS)
|
||||
//{
|
||||
// OtherData.material.datacollectionUploaded = 2;
|
||||
// var dbhelper = new SQLiteHelper<t_materialupload>();
|
||||
// dbhelper.Update(OtherData.material);
|
||||
//}
|
||||
}
|
||||
|
||||
public ApiFormResult Status(string url, plcdata PlcData, otherdata OtherData)
|
||||
@@ -620,7 +624,7 @@ namespace WindowsFormsApp1.server
|
||||
StationID = _stationID,
|
||||
MachineID = _machineID,
|
||||
OPID = _opID,
|
||||
AlarmID = Init.ErrorCode,
|
||||
AlarmID = Init.ErrorCode ?? "",
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
|
||||
ResetTime = ""
|
||||
};
|
||||
@@ -638,21 +642,30 @@ namespace WindowsFormsApp1.server
|
||||
public ApiFormResult SN_FileUpload(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
// 准备文件 视频/图片 目的路径拼接
|
||||
var month = DateTime.Now.ToString("yyyyMM");
|
||||
var day = DateTime.Now.ToString("dd");
|
||||
var month = OtherData.material.date.Substring(0,6);
|
||||
var day = OtherData.material.date.Substring(6, 2);
|
||||
var monthDay = DateTime.Now.ToString("MMdd");
|
||||
var time = DateTime.Now.ToString("HHmmss");
|
||||
var result = PlcData.Read_Result == 1 ? "OK" : "NG";
|
||||
var result = OtherData.material.result;
|
||||
|
||||
var targetDirectory = $"{OtherData.FileUploadAddress}{_line.Substring(0, 2)}\\{month}\\{day}\\Line{_line.Substring(_line.Length - 2)}\\{_stationID}\\{_machineID}\\{result}";
|
||||
var fileName = "";
|
||||
|
||||
try
|
||||
{
|
||||
string[] sourceFolders = new string[] {
|
||||
string[] sourceFolders = new string[]
|
||||
{
|
||||
OtherData.ImageAddress,
|
||||
OtherData.VedioAddress
|
||||
};
|
||||
if (OtherData.material.imageUploaded != 1)
|
||||
{
|
||||
sourceFolders[0] = "";
|
||||
}
|
||||
if (OtherData.material.vedioUploaded != 1)
|
||||
{
|
||||
sourceFolders[1] = "";
|
||||
}
|
||||
// 使用分号分隔多个源文件夹
|
||||
string targetFolder = targetDirectory;
|
||||
List<string> fileList = new List<string>();
|
||||
@@ -666,11 +679,6 @@ namespace WindowsFormsApp1.server
|
||||
return ApiFormResult.Error(mesresult.FAIL, false, "SN号为空", PlcData, DateTime.Now);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(targetFolder))
|
||||
{
|
||||
Directory.CreateDirectory(targetFolder);
|
||||
}
|
||||
|
||||
foreach (string folder in sourceFolders)
|
||||
{
|
||||
if (string.IsNullOrEmpty(folder))
|
||||
@@ -678,32 +686,32 @@ namespace WindowsFormsApp1.server
|
||||
continue;
|
||||
}
|
||||
//判断此sn需要传哪些数据 图片 或视频 todo
|
||||
string sourceFolder = sourceFolders[0];
|
||||
if (sourceFolder == folder)
|
||||
string sourceFolder = "";
|
||||
if (OtherData.ImageAddress == folder)
|
||||
{
|
||||
// 图片
|
||||
// 组装路径 可能需要从数据库读 result和sn和日期
|
||||
sourceFolder = Path.Combine(sourceFolder, OtherData.material.date, "DCDC", result);
|
||||
sourceFolder = Path.Combine(OtherData.ImageAddress, OtherData.material.date, "DCDC", result);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 视频
|
||||
sourceFolder = Path.Combine(sourceFolder, DateTime.Now.ToString("yyyy-MM-dd"));
|
||||
sourceFolder = Path.Combine(OtherData.VedioAddress, DateTime.Now.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
if (Directory.Exists(sourceFolder.Trim()))
|
||||
{
|
||||
string[] files = Directory.GetFiles(sourceFolder.Trim());
|
||||
int num = 1;
|
||||
var extensionstr = "";
|
||||
foreach (string file in files)
|
||||
foreach (string file in files.Where(x => x.Contains(snNumber)))
|
||||
{
|
||||
string fileName1 = Path.GetFileName(file);
|
||||
string filePath = "";
|
||||
if (!fileName1.Contains(snNumber))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
extensionstr = Path.GetExtension(file);
|
||||
var datetime = Directory.GetLastWriteTime(file);
|
||||
monthDay = datetime.ToString("MMdd");
|
||||
time = datetime.ToString("HHmmss");
|
||||
|
||||
fileName = $"{month}{day}_{_stationID}_{result}_{snNumber}_{monthDay}_{time}_{_machineID}_01_Detection_{num}{extensionstr}";
|
||||
filePath = Path.Combine(sourceFolder, fileName1);
|
||||
CopyFileToDirectory(filePath, targetFolder, fileName);
|
||||
@@ -736,7 +744,7 @@ namespace WindowsFormsApp1.server
|
||||
{
|
||||
new
|
||||
{
|
||||
SN = PlcData.Write_stSN,
|
||||
SN = snNumber,
|
||||
FileInfo = fileList.Select(x => new
|
||||
{
|
||||
FileName = x,
|
||||
@@ -747,7 +755,7 @@ namespace WindowsFormsApp1.server
|
||||
SendTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
|
||||
};
|
||||
|
||||
return CallApi(url, request, "SN_FileUpload", PlcData, PLC_Status.SN_FileUpload);
|
||||
return CallApi(url, request, "SN_FileUpload", PlcData, 0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -893,7 +901,8 @@ namespace WindowsFormsApp1.server
|
||||
CarrierID = PlcData.Read_MaterialCode1,
|
||||
datacollectionUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyy-MM-dd")
|
||||
date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
@@ -1039,7 +1048,8 @@ namespace WindowsFormsApp1.server
|
||||
sn = PlcData.Write_stSN,
|
||||
imageUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyyMMdd")
|
||||
date = DateTime.Now.ToString("yyyyMMdd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
@@ -1062,7 +1072,8 @@ namespace WindowsFormsApp1.server
|
||||
sn = PlcData.Write_stSN,
|
||||
vedioUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyy-MM-dd")
|
||||
date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
@@ -1139,6 +1150,7 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
return CallApi(url, request, "OEEDataCollection", PlcData, PLC_Status.OEEDataCollection);
|
||||
}
|
||||
|
||||
#region 暂时不用
|
||||
public ApiFormResult Test(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
@@ -1257,6 +1269,7 @@ namespace WindowsFormsApp1.server
|
||||
}
|
||||
}
|
||||
|
||||
#region 辅助实体类
|
||||
/// <summary>
|
||||
/// checkout dcinfo item
|
||||
/// </summary>
|
||||
@@ -1424,7 +1437,9 @@ namespace WindowsFormsApp1.server
|
||||
public double angle { get; set; }
|
||||
}
|
||||
#endregion 马头扭力角度数据 类
|
||||
|
||||
|
||||
#endregion 辅助实体类
|
||||
|
||||
// 文件copy方法
|
||||
public bool CopyFileToDirectory(string sourceFilePath, string targetDirectory, string fileName)
|
||||
{
|
||||
@@ -1439,7 +1454,11 @@ namespace WindowsFormsApp1.server
|
||||
{
|
||||
Directory.CreateDirectory(targetDirectory);
|
||||
}
|
||||
|
||||
// 判断是否重复上传
|
||||
if (Directory.GetFiles(targetDirectory).Any(x => x.Contains(fileName)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
string targetPath = Path.Combine(targetDirectory, fileName);
|
||||
|
||||
try
|
||||
|
||||
Reference in new issue
Block a user