Przeglądaj źródła

修改csv上传

zly 5 miesięcy temu
rodzic
commit
f5f37f9b64
1 zmienionych plików z 39 dodań i 2 usunięć
  1. 39 2
      TeamAAS-VM/Core/Management.cs

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

@@ -2862,7 +2862,7 @@ 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")}";
+                                                                //string source_csv2 = $"{stationConfig.SaveCsvPath}\\{dt.ToString("yyyy-MM")}\\{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}";
                                                                 if (!Directory.Exists(filePath))
                                                                 {
                                                                     Directory.CreateDirectory(filePath);
@@ -2919,7 +2919,7 @@ namespace TeamAAS_VP.Core
                                                                 if (isAfter20 && isNewDay && !_hasCompressedToday)
                                                                 {
                                                                     // 执行压缩
-                                                                    CompressionImage(source_csv2, csvfilename, device.Station, device.FixtureId);
+                                                                    CompressionSingleCsv(source_csv, csvfilename, device.Station, device.FixtureId);
                                                                     _lastCompressDate = dt;
                                                                     _hasCompressedToday = true;
                                                                     LogHelper.WriteLogMes("csv上传数据成功");
@@ -3780,6 +3780,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