Преглед изворни кода

更改csv,图片储存方式,路径

844184169 пре 5 месеци
родитељ
комит
870339f589
1 измењених фајлова са 55 додато и 48 уклоњено
  1. 55 48
      TeamAAS-VM/Core/Management.cs

+ 55 - 48
TeamAAS-VM/Core/Management.cs

@@ -2317,7 +2317,7 @@ namespace TeamAAS_VP.Core
                                                     {
                                                         ProductMainSN[i] = snItem.Replace("sn=", "").Trim();
                                                         _productService.CurrentProductCode = ProductMainSN[i];
-                                                        _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
+                                                        //_eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
                                                         SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
                                                     }
                                                     string woItem = item.FirstOrDefault(f => f.Contains("wo="));
@@ -2421,7 +2421,7 @@ namespace TeamAAS_VP.Core
                                                 {
                                                     ProductMainSN[i] = snItem.Replace("sn=", "").Trim();
                                                     _productService.CurrentProductCode = ProductMainSN[i];
-                                                    _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
+                                                    //_eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
                                                     SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
                                                 }
                                                 string woItem = item.FirstOrDefault(f => f.Contains("wo="));
@@ -2505,7 +2505,7 @@ namespace TeamAAS_VP.Core
                                         if (i == 0)
                                         {
                                             _productService.CurrentProductCode = ProductMainSN[i];
-                                            _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
+                                            //_eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
                                         }
 
                                         LogHelper.WriteLogMes($"【未启用mes】");
@@ -2534,7 +2534,7 @@ namespace TeamAAS_VP.Core
                                         if (i == 0)
                                         {
                                             CTtime = serverTimeResult.Now.Subtract(_LastMesCheckTime[i]).TotalSeconds;
-                                            _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(false);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
+                                            _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
                                         }
 
                                         //读取产品结果
@@ -2694,49 +2694,57 @@ namespace TeamAAS_VP.Core
                                                     //上传数据
                                                     try
                                                     {
-                                                        DateTime dt = DateTime.Now;
-                                                        string filename = $"{ProductMainSN[i]}_{dt.ToString("yyyyMMddHHmmss")}";
-                                                        var device = _configService.GetDeviceInfo();
-                                                        var config = _configService.GetSystemConfiguration();
-
-                                                        (bool isSuc, string resp) = await _mesService.SendFtpFileAsync(ProductMainSN[i], filename);
-                                                        if (isSuc)
+                                                        if (stationConfig.EnableMES)
                                                         {
-                                                            LogHelper.WriteLogMes($"上传数据成功");
-                                                            SendTaskMessage($"上传数据成功", MessageLevel.Debug);
-                                                            string filePath = $"D:\\image\\Recored\\{dt.ToString("yyyy-MM")}\\{dt.ToString("MM-dd")}\\{currentProduct.Name}\\{ProductMainSN[i]}";
-                                                            //复制csv
-                                                            string source_csv = $"{stationConfig.SaveCsvPath}\\{dt.ToString("yyyy-MM")}\\{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}.csv";
-                                                            string target_csv = Path.Combine(filePath, Path.GetFileName(source_csv));
-                                                            File.Copy(source_csv, target_csv, true);
-                                                            //复制log
-                                                            string source_log = $"..\\Log\\LogInfo\\{dt.ToString("yyyy-MM")}\\{dt.ToString("yyyy-MM-dd")}.txt";
-                                                            string target_log = Path.Combine(filePath, Path.GetFileName(source_log));
-                                                            File.Copy(source_log, target_log, true);
-
-                                                            string target_Directory = filePath + "\\扭力曲线\\";
-                                                            string source_Torque_Image = config.ScrewCurvePath + $"\\{dt.ToString("yyyy-MM")}\\{dt.ToString("yyyy-MM-dd")}\\{currentProduct.Name}\\{ProductMainSN[i]}";
-                                                            var col = Directory.GetFiles(source_Torque_Image);
-                                                            try
+                                                            DateTime dt = DateTime.Now;
+                                                            string filename = $"{ProductMainSN[i]}_{dt.ToString("yyyyMMddHHmmss")}";
+                                                            var device = _configService.GetDeviceInfo();
+                                                            var config = _configService.GetSystemConfiguration();
+
+                                                            (bool isSuc, string resp) = await _mesService.SendFtpFileAsync(ProductMainSN[i], filename);
+                                                            if (isSuc)
                                                             {
-                                                                Directory.CreateDirectory(target_Directory);
-                                                                foreach (var item in col)
+                                                                LogHelper.WriteLogMes($"上传数据成功");
+                                                                SendTaskMessage($"上传数据成功", MessageLevel.Debug);
+                                                                string filePath = $"D:\\image\\Recored\\{dt.ToString("yyyy-MM")}\\{dt.ToString("MM-dd")}\\{currentProduct.Name}\\{ProductMainSN[i]}";
+                                                                //复制csv
+                                                                string source_csv = $"{stationConfig.SaveCsvPath}\\{dt.ToString("yyyy-MM")}\\{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}.csv";
+                                                                string target_csv = Path.Combine(filePath, Path.GetFileName(source_csv));
+                                                                File.Copy(source_csv, target_csv, true);
+                                                                //复制log
+                                                                string source_log = $"..\\Log\\LogInfo\\{dt.ToString("yyyy-MM")}\\{dt.ToString("yyyy-MM-dd")}.txt";
+                                                                string target_log = Path.Combine(filePath, Path.GetFileName(source_log));
+                                                                File.Copy(source_log, target_log, true);
+
+                                                                string target_Directory = filePath + "\\扭力曲线\\";
+                                                                string source_Torque_Image = config.ScrewCurvePath + $"\\{dt.ToString("yyyy-MM")}\\{dt.ToString("yyyy-MM-dd")}\\{currentProduct.Name}\\{ProductMainSN[i]}";
+                                                                var col = Directory.GetFiles(source_Torque_Image);
+                                                                try
+                                                                {
+                                                                    Directory.CreateDirectory(target_Directory);
+                                                                    foreach (var item in col)
+                                                                    {
+                                                                        string target_Torque = target_Directory + item.Replace(source_Torque_Image, "");
+                                                                        File.Copy(item, target_Torque, true);
+                                                                    }
+                                                                }
+                                                                catch (Exception)
                                                                 {
-                                                                    string target_Torque = target_Directory + item.Replace(source_Torque_Image, "");
-                                                                    File.Copy(item, target_Torque, true);
+                                                                    SendTaskMessage($"扭力曲线图读取失败", MessageLevel.Error);
                                                                 }
+
+                                                                CompressionImage(filePath, filename, device.Station, device.FixtureId);
                                                             }
-                                                            catch (Exception)
+                                                            else
                                                             {
-                                                                SendTaskMessage($"扭力曲线图读取失败", MessageLevel.Error);
-                                                            }                                                    
-
-                                                            CompressionImage(filePath, filename, device.Station, device.FixtureId);
+                                                                LogHelper.WriteLogMes($"上传数据失败");
+                                                                SendTaskMessage($"上传数据失败", MessageLevel.Error);
+                                                            }
                                                         }
                                                         else
                                                         {
-                                                            LogHelper.WriteLogMes($"上传数据失败");
-                                                            SendTaskMessage($"上传数据失败", MessageLevel.Error);
+                                                            LogHelper.WriteLogMes($"未启用mes");
+                                                            SendTaskMessage($"未启用mes", MessageLevel.Error);
                                                         }
                                                     }
                                                     catch (Exception ex)
@@ -3355,7 +3363,7 @@ namespace TeamAAS_VP.Core
                 if (string.IsNullOrEmpty(savePath)) return false;
                 string fullPath = savePath;
                 //如果保存路径是一个文件路径,则直接保存,否则按照工位和日期进行保存
-                if (File.Exists(savePath) || Path.HasExtension(savePath))
+                if (!File.Exists(savePath) || !Path.HasExtension(savePath))
                 {
                     fullPath = savePath;
                     //如果路径不存在,则创建
@@ -3366,15 +3374,14 @@ namespace TeamAAS_VP.Core
                         Directory.CreateDirectory(directory);
                     }
                 }
-                else
-                {
-                    //结果保存至CSV文件,文件名格式:savePath\yyyy-MM\工位编号_工位名称_yyyy-MM-dd.csv
-                    string datePath = timestamp.ToString("yyyy-MM") + "\\";
-                    string dirPath = Path.Combine(savePath, datePath);
-                    if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);
-                    string fileName = $"{stationIndex}_{stationConfig.DeviceName}_{timestamp.ToString("yyyy-MM-dd")}.csv";
-                    fullPath = Path.Combine(dirPath, fileName);
-                }
+
+                //结果保存至CSV文件,文件名格式:savePath\yyyy-MM\工位编号_工位名称_yyyy-MM-dd.csv
+                string datePath = timestamp.ToString("yyyy-MM") + "\\";
+                string dirPath = Path.Combine(savePath, datePath);
+                if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);
+                string fileName = $"{stationIndex}_{stationConfig.DeviceName}_{timestamp.ToString("yyyy-MM-dd")}.csv";
+                fullPath = Path.Combine(dirPath, fileName);
+
                 StringBuilder sb = new StringBuilder();
                 if (!File.Exists(fullPath))
                 {