Sfoglia il codice sorgente

修改log等文件上传

wanghan 6 mesi fa
parent
commit
8597fe2550

+ 1 - 1
TeamAAS-VM/Core/FtpUploader.cs

@@ -371,7 +371,7 @@ namespace TeamAAS_VP.Core
                     await Task.Run(() =>
                     {
                         zipPath = $"{_config.ImagePath}\\{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";//生成的zip文件路径
-                        string sourcePath = $"{_config.ImagePath}\\{DateTime.Now.ToString("yyyy-MM")}\\{DateTime.Now.ToString("MM-dd")}\\{currentPro}\\{sn}";//"D:\image\Recored\2026-02\02-28\产品1\CN0D0NDYCKJ006250103X02"
+                        string sourcePath = $"{_config.ImagePath}\\{DateTime.Now.ToString("yyyy-MM")}\\{DateTime.Now.ToString("MM-dd")}\\{currentPro}\\{sn}";
                         ZipFile.CreateFromDirectory(sourcePath, zipPath);
                     });
                     return zipPath;

+ 65 - 14
TeamAAS-VM/Core/Management.cs

@@ -3,6 +3,7 @@ using Cognex.VisionPro;
 using Cognex.VisionPro.ToolBlock;
 using CSScripting;
 using CSScriptLib;
+using iTextSharp.xmp.impl.xpath;
 using MathNet.Numerics.Distributions;
 using MathNet.Numerics.LinearAlgebra;
 using MathNet.Numerics.RootFinding;
@@ -27,6 +28,7 @@ using System.Data;
 using System.Diagnostics;
 using System.Drawing;
 using System.IO;
+using System.IO.Compression;
 using System.Linq;
 using System.Net.Sockets;
 using System.Reflection.Metadata;
@@ -63,6 +65,7 @@ using TeamAAS_VP.Views.Product;
 using TouchSocket.Core;
 using TouchSocket.SerialPorts;
 using TouchSocket.Sockets;
+using XAMLMarkupExtensions.Base;
 using static MaterialDesignThemes.Wpf.Theme.ToolBar;
 using static Org.BouncyCastle.Math.EC.ECCurve;
 using static System.Windows.Forms.AxHost;
@@ -2360,7 +2363,7 @@ namespace TeamAAS_VP.Core
                                                                 break;
                                                             }
                                                         }
-                                                        if (currentProduct.ID!= productId)
+                                                        if (currentProduct.ID != productId)
                                                         {
                                                             //切换产品
                                                             _productService.LoadProduct(productId);
@@ -2556,19 +2559,39 @@ namespace TeamAAS_VP.Core
                                                 if (recordResult)
                                                 {
                                                     SendTaskMessage($"{i}:{stationConfig.DeviceName}产品记录保存成功", MessageLevel.Debug);
-
-                                                   
-                                                    //(bool isSuc, string resp) = await _mesService.SendFtpFileAsync(ProductMainSN[i], "");
-                                                    //if (isSuc)
-                                                    //{
-                                                    //    LogHelper.WriteLogMes($"上传数据成功");
-                                                    //    SendTaskMessage($"上传数据成功", MessageLevel.Debug);
-                                                    //}
-                                                    //else
-                                                    //{
-                                                    //    LogHelper.WriteLogMes($"上传数据失败");
-                                                    //    SendTaskMessage($"上传数据失败", MessageLevel.Error);
-                                                    //}
+                                                    //上传数据
+                                                    try
+                                                    {
+                                                        DateTime dt = DateTime.Now;
+                                                        string filename = ProductMainSN[i] + "_" + dt.ToString("yyyyMMddHHmmss");
+                                                        var device = _configService.GetDeviceInfo();
+                                                        (bool isSuc, string resp) = await _mesService.SendFtpFileAsync(ProductMainSN[i], filename);
+                                                        if (isSuc)
+                                                        {
+                                                            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.DataInfo.PROCESS_NAME}_{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);
+                                                            CompressionImage(filePath, filename, device.FixtureId);
+                                                        }
+                                                        else
+                                                        {
+                                                            LogHelper.WriteLogMes($"上传数据失败");
+                                                            SendTaskMessage($"上传数据失败", MessageLevel.Error);
+                                                        }
+                                                    }
+                                                    catch (Exception ex)
+                                                    {
+                                                        SendTaskMessage($"上传数据时出错:{ex.Message}", MessageLevel.Error);
+                                                        LogHelper.WriteLogError($"上传数据时出错", ex);
+                                                    }
                                                 }
                                                 else
                                                 {
@@ -3248,6 +3271,34 @@ namespace TeamAAS_VP.Core
         }
         #endregion
 
+        #region 压缩图片文件夹
+        public async void CompressionImage(string sourcePath, string zipname,string fixid)
+        {
+            string zipPath = "";
+            try
+            {
+                SendTaskMessage($"开始压缩文件", MessageLevel.Info);
+                await Task.Run(() =>
+                {
+                    zipPath = $"Z:\\{fixid}\\{DateTime.Now.ToString("yyyyMMdd")}\\{zipname}.zip";//生成的zip文件路径
+                    ZipFile.CreateFromDirectory(sourcePath, zipPath);
+                });
+            }
+            catch (Exception ex)
+            {
+                LogHelper.WriteLogError($"压缩文件时出错", ex);
+            }
+            finally
+            {
+                // 清理临时文件
+                if (File.Exists(zipPath))
+                {
+                    File.Delete(zipPath);
+                }
+            }
+        }
+
+        #endregion
         #endregion
     }
 }

+ 2 - 0
TeamAAS-VM/Models/Product/ProductModel.cs

@@ -407,6 +407,8 @@ namespace TeamAAS_VP.Models
                 PickPoints = this.PickPoints,
                 SecPosCameraPoints = this.SecPosCameraPoints,
                 ScrewCameraPoints = this.ScrewCameraPoints,
+                ScrewCameraLocalPos1=this.ScrewCameraLocalPos1,
+                ScrewCameraLocalPos2 = this.ScrewCameraLocalPos2,
                 ScrewPoints = this.ScrewPoints,
                 CheckCameraPoints = this.CheckCameraPoints,
                 QrCodePoints=this.QrCodePoints,

+ 4 - 4
TeamAAS-VM/Services/MesService.cs

@@ -731,8 +731,8 @@ namespace TeamAAS_VP.Services
 
             string url = $"{device.LogUrl}?db=mysql&ApiKey={device.ApiKey}&jsondata={{\"SN\":\"{sn}\",\"LINE\":\"{device.Line}\",\"STATION\":\"{device.Station}\",\"TESTRESULT\":\"PASS\",\"FIXTUREID\":\"{device.FixtureId}\",\"TESTDATETIME\":\"{DateTime.Now.ToString()}\",\"LOGFILENAME\":\"{name}.zip\"}}";
            
-            LogHelper.WriteLogMes($"【上传FTP的URL】{url}");
-            SendTaskMessage($"【上传FTP的URL】{url}", MessageLevel.Info);
+            LogHelper.WriteLogMes($"【上传LogData的URL】{url}");
+            SendTaskMessage($"【上传LogData的URL】{url}", MessageLevel.Info);
             (bool IsSuccess, string Response) result = (false, string.Empty);
 
             for (int i = 0; i < 3; i++)
@@ -742,8 +742,8 @@ namespace TeamAAS_VP.Services
                     using (var rsp = await _httpClient.GetAsync(url, cancellationToken))
                     {
                         var text = await rsp.Content.ReadAsStringAsync();
-                        LogHelper.WriteLogMes($"【HTTP接收】{text}");
-                        SendTaskMessage($"【HTTP接收】{text}", MessageLevel.Info);
+                        LogHelper.WriteLogMes($"【上传LogData的HTTP接收】{text}");
+                        SendTaskMessage($"【上传LogData的HTTP接收】{text}", MessageLevel.Info);
                         // "SFC_OK" 代表和 MES 连接成功
                         if (text.Contains("SFC_OK"))
                         {

+ 2 - 9
TeamAAS-VM/ViewModels/SettingViewModel.cs

@@ -16,6 +16,7 @@ using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Drawing.Drawing2D;
 using System.Globalization;
+using System.IO;
 using System.Linq;
 using System.Reflection.Metadata;
 using System.Text;
@@ -1970,17 +1971,9 @@ namespace TeamAAS_VP.ViewModels
         private DelegateCommand _testCommand;
         public DelegateCommand testCommand =>
             _testCommand ?? (_testCommand = new DelegateCommand(Execute_testCommand));
-        public FtpUploaderTest ftpService { get; set; } = new FtpUploaderTest();
-
+       
         private async void Execute_testCommand()
         {
-            //var currentproduct = _productService.GetCurrentProduct();
-
-            //string sn = $"CN0D0NDYCKJ006260336X02";
-            //string zippath = await ftpService.CompressionImage(sn, currentproduct.Name);
-            //ftpService.UploadToFtp(zippath);
-
-            //ftpService.UploadFolderAsZipTest();
         }
     }
 }

+ 2 - 2
TeamAAS-VM/Views/SettingView.xaml

@@ -454,7 +454,7 @@
                                          Text="{Binding SelectDeviceInfo.comp, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <!--<TextBlock Grid.Row="9"
+                                <TextBlock Grid.Row="9"
            Grid.Column="0"
            Text="LogUrl:"
            HorizontalAlignment="Right"
@@ -472,7 +472,7 @@
                                 <TextBox Grid.Row="10"
          Grid.Column="1"
          Text="{Binding SelectDeviceInfo.ApiKey, Mode=TwoWay}"
-         Margin="6,2" />-->
+         Margin="6,2" />
 
                                 <CheckBox Grid.Row="11"
                                           Grid.Column="1"