|
@@ -2455,96 +2455,74 @@ namespace MainForm
|
|
|
string bucket =
|
|
|
$"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
|
|
|
|
|
|
- // 获取所有图片文件
|
|
|
- List<string> imageFiles = GetAllImageFiles(path);
|
|
|
+ if (guid == "")
|
|
|
+ {
|
|
|
+ guid = Guid.NewGuid().ToString();
|
|
|
+ }
|
|
|
try
|
|
|
{
|
|
|
- if (imageFiles.Count > 0)
|
|
|
- {
|
|
|
- CompressFolder("D:\\Temp\\VisionLog\\Pic\\Left", "D:\\Temp\\VisionLog\\Pic\\YaSuo.zip");
|
|
|
-
|
|
|
- foreach (string imageFile in imageFiles)
|
|
|
- {
|
|
|
-
|
|
|
- break;
|
|
|
- if (guid == "")
|
|
|
- {
|
|
|
- guid = Guid.NewGuid().ToString();
|
|
|
- }
|
|
|
-
|
|
|
- filename = Path.GetFileName(imageFile);
|
|
|
-
|
|
|
- sql = string.Format(
|
|
|
- "INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
|
|
|
- "VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
|
|
|
- , stationCode
|
|
|
- , stationName
|
|
|
- , BarcodeSet.strCarrierBarcode
|
|
|
- , BarcodeSet.strProductBarcode
|
|
|
- , bucket
|
|
|
- , filename
|
|
|
- , ""
|
|
|
- , guid
|
|
|
- , ""
|
|
|
- , 0
|
|
|
- , ""
|
|
|
- , DateTime.Now
|
|
|
- );
|
|
|
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
|
|
|
-
|
|
|
- FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
|
|
|
- fileUpload_X5.bucket = bucket;
|
|
|
- fileUpload_X5.name = filename;
|
|
|
- fileUpload_X5.uuid = guid.ToString();
|
|
|
- ///需要上传文件
|
|
|
- FileInfo file = new FileInfo(imageFile);
|
|
|
- string fileMd5Hex = GetMD5Hex(file);
|
|
|
- fileUpload_X5.md5 = fileMd5Hex;
|
|
|
- fileUpload_X5.uploadCloud = true;
|
|
|
- fileUpload_X5.informMqtt = true;
|
|
|
-
|
|
|
- FileMqttPayload fileMqttPayload = new FileMqttPayload();
|
|
|
- fileMqttPayload.factory = GlobalContext.Factory_Code;
|
|
|
- fileMqttPayload.project_name = GlobalContext.Project_Code;
|
|
|
- fileMqttPayload.product_mode = GlobalContext.product_mode;
|
|
|
- fileMqttPayload.line_no = GlobalContext.LineCode;
|
|
|
- fileMqttPayload.work_station_no = xiaomiParm.workstation;
|
|
|
- fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
|
|
|
- fileMqttPayload.station_no = xiaomiParm.stationCode;
|
|
|
- fileMqttPayload.file_id = guid;
|
|
|
- fileMqttPayload.file_name = filename;
|
|
|
- fileMqttPayload.sn = BarcodeSet.strProductBarcode;
|
|
|
- //fileMqttPayload.opt_time = "";
|
|
|
- //fileMqttPayload.file_type = "";
|
|
|
- //fileMqttPayload.file_category = "";
|
|
|
- //fileMqttPayload.tag = "";
|
|
|
- fileMqttPayload.reference_info.pass_station_id = uuid;
|
|
|
-
|
|
|
- var fileresult =
|
|
|
- XiaomiMESHttp_UpLoadFile.FileUoladToMes(imageFile, fileUpload_X5, fileMqttPayload);
|
|
|
-
|
|
|
- if (fileresult.Result.Item1 == 0)
|
|
|
- {
|
|
|
- sql = string.Format("UPDATE [dbo].[DataFiles] SET status='{0}' WHERE uuid='{1}'", 1, guid);
|
|
|
- string retnew = SQLHelper_New.ExecuteNonQuery(sql, null);
|
|
|
- }
|
|
|
-
|
|
|
- msg = msg + $"{fileresult.Result.Item2}\r\n";
|
|
|
+ if (GlobalContext.MESIsSendUpFile)
|
|
|
+ {
|
|
|
+ string toPath = GlobalContext.MqttFileBackupLogDir;
|
|
|
+ string toFileName = $"[{xiaomiParm.workstation}]_{file_type}_{sn}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}.zip";
|
|
|
+ string directoryPath = Path.GetDirectoryName(path);
|
|
|
+ string strFilePath = toPath + toFileName;
|
|
|
+ CompressFolder(directoryPath, strFilePath);
|
|
|
+
|
|
|
+ FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
|
|
|
+ fileUpload_X5.bucket = bucket;
|
|
|
+ fileUpload_X5.name = filename;
|
|
|
+ fileUpload_X5.uuid = guid.ToString();
|
|
|
+ ///需要上传文件
|
|
|
+ FileInfo file = new FileInfo(strFilePath);
|
|
|
+ string fileMd5Hex = GetMD5Hex(file);
|
|
|
+ fileUpload_X5.md5 = fileMd5Hex;
|
|
|
+ fileUpload_X5.uploadCloud = true;
|
|
|
+ fileUpload_X5.informMqtt = true;
|
|
|
+
|
|
|
+ FileMqttPayload fileMqttPayload = new FileMqttPayload();
|
|
|
+ fileMqttPayload.factory = GlobalContext.Factory_Code;
|
|
|
+ fileMqttPayload.project_name = GlobalContext.Project_Code;
|
|
|
+ fileMqttPayload.product_mode = GlobalContext.product_mode;
|
|
|
+ fileMqttPayload.line_no = GlobalContext.LineCode;
|
|
|
+ fileMqttPayload.work_station_no = xiaomiParm.workstation;
|
|
|
+ fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
|
|
|
+ fileMqttPayload.station_no = xiaomiParm.stationCode;
|
|
|
+ fileMqttPayload.file_id = guid;
|
|
|
+ fileMqttPayload.file_name = filename;
|
|
|
+ fileMqttPayload.sn = BarcodeSet.strProductBarcode;
|
|
|
+ //fileMqttPayload.opt_time = "";
|
|
|
+ //fileMqttPayload.file_type = "";
|
|
|
+ //fileMqttPayload.file_category = "";
|
|
|
+ //fileMqttPayload.tag = "";
|
|
|
+ fileMqttPayload.reference_info.pass_station_id = uuid;
|
|
|
+
|
|
|
+ var fileresult =await
|
|
|
+ XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
|
|
|
+
|
|
|
+ msg = msg + $"{fileresult.Item2}\r\n";
|
|
|
+
|
|
|
+ // 获取所有图片文件
|
|
|
+ List<string> imageFiles = GetAllImageFiles(path);
|
|
|
+ foreach (var imageFile in imageFiles) {
|
|
|
+ if (File.Exists(imageFile))
|
|
|
+ {
|
|
|
+ //删除文件
|
|
|
+ (bool, string) newResult = DeleteFile(imageFile);
|
|
|
+ if (!newResult.Item1)
|
|
|
+ {
|
|
|
+ return (0, Path.GetFileName(imageFile) + newResult.Item2);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- return (1, msg);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return (1, "文件不存在!");
|
|
|
}
|
|
|
+ return (1, msg);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
return (1,
|
|
|
- filename + $"图片获取失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
|
|
|
+ filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
|
|
|
e.Message);
|
|
|
- //AddMessage_Station(stationName, LogType.Error, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode}");
|
|
|
}
|
|
|
}
|
|
|
|