zly пре 5 месеци
родитељ
комит
371fa81060
1 измењених фајлова са 42 додато и 3 уклоњено
  1. 42 3
      TeamAAS-VM/Core/Management.cs

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

@@ -2821,8 +2821,8 @@ namespace TeamAAS_VP.Core
 
                                                             //filePath = $"D:\\Image\\Recored\\{dt.ToString("yyyy-MM")}\\{dt.ToString("MM-dd")}\\{currentProduct.Name}\\{ProductMainSN}";
                                                             filePath = $"{PhotoPath}\\Recored\\{dt.ToString("yyyy-MM")}\\{dt.ToString("MM-dd")}\\{currentProduct.Name}\\{ProductMainSN}";
-                                                            string source_csv2 = $"{stationConfig.SaveCsvPath}\\{dt.ToString("yyyy-MM")}\\{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}";
-                                                            //string csvfilename = $"{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")}";
+                                                            string csvfilename = $"{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}";
                                                             //复制csv
                                                             string source_csv = $"{stationConfig.SaveCsvPath}\\{dt.ToString("yyyy-MM")}\\{i}_{stationConfig.DeviceName}_{dt.ToString("yyyy-MM-dd")}.csv";
                                                             //string source_csv1 = $"{stationConfig.SaveCsvPath}\\{dt.ToString("yyyy-MM")}";
@@ -2843,7 +2843,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上传数据成功");
@@ -3926,6 +3926,45 @@ namespace TeamAAS_VP.Core
             }
         }
 
+
+        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
     }
 }