Browse Source

修改上传csv程序

zly 5 months ago
parent
commit
d56690c45a
1 changed files with 39 additions and 3 deletions
  1. 39 3
      TeamAAS-VM/Core/Management.cs

+ 39 - 3
TeamAAS-VM/Core/Management.cs

@@ -3266,7 +3266,7 @@ namespace TeamAAS_VP.Core
                                                     {
                                                         DateTime dt = DateTime.Now;
                                                         string filename = $"{ProductMainSN[i]}_{dt.ToString("yyyyMMddHHmmss")}";
-                                                        //string csvfilename = $"{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}";
+                                                        string csvfilename = $"{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}";
                                                         var device = _configService.GetDeviceInfo(i);
                                                         var systemConfig = _configService.GetSystemConfiguration();
                                                         var pressureSensorConfig = systemConfig.PressureSensorConfig.FirstOrDefault();
@@ -3276,7 +3276,6 @@ namespace TeamAAS_VP.Core
                                                             LogHelper.WriteLogMes($"上传数据成功");
                                                             SendTaskMessage($"上传数据成功", MessageLevel.Debug);
                                                             string filePath = $"D:\\image\\Recored\\{dt.ToString("yyyy-MM")}\\{dt.ToString("MM-dd")}\\{currentProduct.Name}\\{ProductMainSN[i]}";
-                                                            string source_csv2 = $"{stationConfig.SaveCsvPath}\\{dt.ToString("yyyy-MM")}\\{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}";
                                                             if (!Directory.Exists(filePath))
                                                             {
                                                                 Directory.CreateDirectory(filePath);
@@ -3322,7 +3321,7 @@ namespace TeamAAS_VP.Core
                                                             if (isAfter20 && isNewDay && !_hasCompressedToday)
                                                             {
                                                                 // 执行压缩
-                                                                CompressionImage(source_csv2, filename, device.Station, device.FixtureId);
+                                                                CompressionSingleCsv(source_csv, csvfilename, device.Station, device.FixtureId);
                                                                 _lastCompressDate = dt;
                                                                 _hasCompressedToday = true;
                                                                 LogHelper.WriteLogMes("csv上传数据成功");
@@ -3887,6 +3886,7 @@ namespace TeamAAS_VP.Core
                     }
 
                     ZipFile.CreateFromDirectory(sourcePath, zipPath);
+
                 });
             }
             catch (Exception ex)
@@ -3894,7 +3894,43 @@ namespace TeamAAS_VP.Core
                 LogHelper.WriteLogError($"压缩文件时出错", ex);
             }
         }
+        public async void CompressionSingleCsv(string csvFilePath, string zipname, string station, string fixid)
+        {
+            string zipPath = "";
+            try
+            {
+                SendTaskMessage("开始压缩CSV文件", MessageLevel.Info);
+                await Task.Run(() =>
+                {
+                    if (!File.Exists(csvFilePath))
+                    {
+                        LogHelper.WriteLogMes($"CSV文件不存在,不压缩:{csvFilePath}");
+                        return;
+                    }
 
+                    zipPath = $"Z:\\{station}\\{fixid}\\{DateTime.Now.ToString("yyyyMMdd")}\\{zipname}.zip";
+                    string path = $"Z:\\{station}\\{fixid}\\{DateTime.Now.ToString("yyyyMMdd")}";
+
+                    if (!Directory.Exists(path))
+                    {
+                        Directory.CreateDirectory(path);
+                    }
+
+                    using (FileStream fs = new FileStream(zipPath, FileMode.Create))
+                    {
+                        using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Create))
+                        {
+                            archive.CreateEntryFromFile(csvFilePath, Path.GetFileName(csvFilePath));
+                        }
+                    }
+                });
+                SendTaskMessage("CSV文件压缩完成", MessageLevel.Debug);
+            }
+            catch (Exception ex)
+            {
+                LogHelper.WriteLogError("压缩CSV文件失败", ex);
+            }
+        }
         #endregion
         #endregion
     }