Browse Source

优化bug添加思泰克spi文件上传

yhluo 5 months ago
parent
commit
84b7d46260

+ 2 - 2
UAS_MES_BG/FunctionCode/Make/Make_CollectHLH.cs

@@ -475,10 +475,10 @@ namespace UAS_MES_NEW.Make
                                     ",'" + hlh["ZONE4PV_DOWN"] + "','" + hlh["ZONE5PV_UP"] + "','" + hlh["ZONE5PV_DOWN"] + "','" + hlh["ZONE6PV_UP"] + "','" + hlh["ZONE6PV_DOWN"] + "','" + hlh["ZONE7PV_UP"] + "','" + hlh["ZONE7PV_DOWN"] + "','" + hlh["ZONE8PV_UP"] + "','" + hlh["ZONE8PV_DOWN"] + "','" + hlh["ZONE9PV_UP"] + "'" +
                                     ",'" + hlh["ZONE9PV_DOWN"] + "','" + hlh["ZONE10PV_UP"] + "','" + hlh["ZONE10PV_DOWN"] + "','" + hlh["ZONE11PV_UP"] + "','" + hlh["ZONE11PV_DOWN"] + "','" + hlh["ZONE12PV_UP"] + "','" + hlh["ZONE12PV_DOWN"] + "','" + hlh["FAN1_PV"] + "','" + hlh["FAN2_PV"] + "','" + hlh["FAN3_PV"] + "'  ) ", "insert");*/
 
-                                dh.ExecuteSql($@"insert into hlh(SPEEDPV1,ZONE1PV_UP,ZONE1PV_DOWN,ZONE2PV_UP,Zone2PV_Down,Zone3PV_UP,Zone3PV_Down,
+                                dh.ExecuteSql($@"insert into hlh(hlh_id,hlh_indate,SPEEDPV1,ZONE1PV_UP,ZONE1PV_DOWN,ZONE2PV_UP,Zone2PV_Down,Zone3PV_UP,Zone3PV_Down,
                                                 Zone4PV_UP,Zone4PV_Down,Zone5PV_UP,Zone5PV_Down,Zone6PV_UP,Zone6PV_Down,Zone7PV_UP,Zone7PV_Down,
                                                 Zone8PV_UP,Zone8PV_Down,Fan1_PV,Fan2_PV,Fan3_PV) values 
-                                                ({hlh["SPEEDPV"]},{hlh["ZONE1PV_UP"]},{hlh["ZONE1PV_DOWN"]},{hlh["ZONE2PV_UP"]},{hlh["ZONE2PV_DOWN"]},{hlh["ZONE3PV_UP"]},{hlh["ZONE3PV_DOWN"]},
+                                                (hlh_seq.nextval,sysdate,{hlh["SPEEDPV"]},{hlh["ZONE1PV_UP"]},{hlh["ZONE1PV_DOWN"]},{hlh["ZONE2PV_UP"]},{hlh["ZONE2PV_DOWN"]},{hlh["ZONE3PV_UP"]},{hlh["ZONE3PV_DOWN"]},
                                                  {hlh["ZONE4PV_UP"]},{hlh["ZONE4PV_DOWN"]},{hlh["ZONE5PV_UP"]},{hlh["ZONE5PV_DOWN,"]},{hlh["ZONE6PV_UP"]},{hlh["ZONE6PV_DOWN"]},{hlh["ZONE7PV_UP"]},{hlh["ZONE7PV_DOWN"]},
                                                  {hlh["ZONE8PV_UP"]},{hlh["ZONE8PV_DOWN"]},{hlh["FAN1_PV"]},{hlh["FAN2_PV"]},{hlh["FAN3_PV"]})", "insert");
                             }

+ 75 - 25
UAS_MES_BG/FunctionCode/Make/Make_ParseLog.cs

@@ -44,14 +44,15 @@ namespace UAS_MES_NEW.Make
         DataTable dt;
 
         DataHelper dh;
-        string currFileType = "";
+        string currFileType = "",equiType = "";
 
         string SN, omakeCode, oMsid, oErrorMessage = "";
-        string equiType = "";
         List<string> fileList = new List<string>();
 
         Timer formsTimer;
         string outXmlFilePath;
+
+        BgFtpOperater ftp;
         private void Make_ParseLog_Load(object sender, EventArgs e)
         {
             dh = SystemInf.dh;
@@ -76,6 +77,7 @@ namespace UAS_MES_NEW.Make
             watcher.Deleted += OnFileChanged;
             watcher.Renamed += OnFileChanged;*/
 
+            ftp = new BgFtpOperater();
             //设置锁定工单
             LockMakeCode.GetMakeCodeCtl(ma_code);
             ma_code.SetLockCheckBox(LockMakeCode);
@@ -108,22 +110,6 @@ namespace UAS_MES_NEW.Make
         {
             if (Device.SelectedIndex == -1) return;
 
-            if (Device.SelectedIndex == 4 || Device.SelectedIndex == 2 || Device.SelectedIndex == 5)
-            {
-                txtPath.Text = fileList[Device.SelectedIndex];
-                ma_code.Text = "";
-                ma_code.Enabled = false;
-                txtPath.Focus();
-                txtPath.SelectAll();
-                return;
-            }
-            if (string.IsNullOrEmpty(ma_code.Text))
-            {
-                Device.SelectedIndex = -1;
-                txtPath.Text = "";
-                MessageBox.Show(this.ParentForm, "请选择工单", "提示");
-                return;
-            }
             switch (Device.SelectedIndex)
             {
                 case 0:
@@ -152,6 +138,23 @@ namespace UAS_MES_NEW.Make
                     break;
             }
 
+            if (Device.SelectedIndex == 4 || Device.SelectedIndex == 2 || Device.SelectedIndex == 5)
+            {
+                txtPath.Text = fileList[Device.SelectedIndex];
+                ma_code.Text = "";
+                ma_code.Enabled = false;
+                txtPath.Focus();
+                txtPath.SelectAll();
+                return;
+            }
+            if (string.IsNullOrEmpty(ma_code.Text))
+            {
+                Device.SelectedIndex = -1;
+                txtPath.Text = "";
+                MessageBox.Show(this.ParentForm, "请选择工单", "提示");
+                return;
+            }
+
             txtPath.Text = fileList[Device.SelectedIndex];
             txtPath.Focus();
             txtPath.SelectAll();
@@ -234,7 +237,7 @@ namespace UAS_MES_NEW.Make
             string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
             if (txtFiles.Length == 0)
             {
-                LogMessage($"当前{txtPath.Text},没有{currFileType.ToUpper()}格式文件");
+                LogMessage($"当前{txtPath.Text},没有{equiType}设备{currFileType.ToUpper()}文件");
                 return;
             }
             RefreshFileList();
@@ -405,10 +408,57 @@ namespace UAS_MES_NEW.Make
                         }
                         else if (Device.SelectedIndex == 1) // 思泰克SPI
                         {
-                            return; // 20250630 M 调整对接方式 
+                            if (!File.Exists(file))
+                            {
+                                LogMessage($"文件不存在: {file}");
+                                continue;
+                            }
+
+                            string fileName = Path.GetFileName(file);
+                            string[] lines = File.ReadAllLines(file, Encoding.GetEncoding("GB2312"));
 
-                            #region
-                            List<SpiData> csvData;
+                            string modelName = lines[1].Split(',')[0];
+                            string lineNumber = lines[1].Split(',')[1];
+                            string boardStatus = lines[2].Split(',')[1];
+                            if (string.IsNullOrEmpty(boardStatus))
+                            {
+                                LogMessage($"文件: {file},无SN信息");
+                                continue;
+                            }
+                            if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, boardStatus, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
+                            {
+                                if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, boardStatus, "日志解析", "OK", User.UserCode, out oErrorMessage))
+                                {
+
+                                    string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
+                                    ftp.UpLoadFile(file, boardStatus + ".xml", ftppath);
+                                    int num = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class)select STEPTESTDETAIL_seq.nextval,ms_sncode,ms_makecode,sysdate,'http://112.48.67.154:8088/ftp" + ftppath + boardStatus + ".xml" + "' from makeserial where ms_sncode='" + boardStatus + "'", "insert").ToString());
+                                    if (num > 0)
+                                    {
+                                        LogMessage($"文件: {file},上传成功"); 
+                                        string xmlContent = File.ReadAllText(file);
+                                        if (ConsoleLog(xmlContent, file))
+                                        {
+                                            File.Delete(file);
+                                        }
+                                    }
+                                    else
+                                    {
+                                        LogMessage($"文件: {file},SN: {boardStatus}前工段未扫描");
+                                    }
+                                }
+                                else
+                                {
+                                    LogMessage(">>" + oErrorMessage + "\n");
+                                }
+                            }
+                            else
+                            {
+                                LogMessage(">>" + oErrorMessage + "\n");
+                            }
+
+                            #region // 20250630 M 调整对接方式 
+                            /*List<SpiData> csvData; 
                             //csvData = ParseCsvFile(file);
                             csvData = ParseCsvFile<SpiData>(file, MapToSpiData);
 
@@ -482,7 +532,7 @@ namespace UAS_MES_NEW.Make
                             if (ConsoleLog(xmlContent, file))
                             {
                                 File.Delete(file);
-                            }
+                            }*/
                             #endregion
                         }
                         else if (Device.SelectedIndex == 2) // AOI
@@ -563,7 +613,7 @@ namespace UAS_MES_NEW.Make
                             if (priMacData.Count == 0)
                             {
                                 LogMessage($"文件: {file},读取记录 {priMacData.Count} 条");
-                                return;
+                                continue;
                             }
 
                             sql.Clear();
@@ -618,7 +668,7 @@ namespace UAS_MES_NEW.Make
                             if (xmlList.Count == 0)
                             {
                                 LogMessage($"文件: {file},读取记录 {xmlList.Count} 条");
-                                return;
+                                continue;
                             }
 
                             List<string> param = new List<string>() { };

+ 123 - 0
UAS_MES_BG/PublicMethod/BgFtpOperater.cs

@@ -0,0 +1,123 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+
+namespace UAS_MES_NEW.PublicMethod
+{
+    internal class BgFtpOperater
+    {
+        private string ftpServerIP;
+        private string ftpUser;
+        private string ftpPwd;
+        public BgFtpOperater()
+        {
+            //百岗ftp
+            string[] FTPInf = "ftp://10.8.0.208:21//mes/TestData|vsftpd|Az789***".Split('|');
+            this.ftpServerIP = FTPInf[0];
+            this.ftpUser = FTPInf[1];
+            this.ftpPwd = FTPInf[2];
+            //string FTPInf = Properties.Settings.Default.Properties["FTPAddress"].DefaultValue.ToString();
+
+            //连接共享文件夹
+            //status = BaseUtil.connectState(FTPInf);
+        }
+
+        public string UpLoadFile(string filepath, string filename, string UploadFolder)
+        {
+            try
+            {
+                FtpWebRequest reqFTP;
+                if (FtpCheckDirectoryExist(UploadFolder) == "")
+                {
+                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + UploadFolder + filename));
+                    reqFTP.UseBinary = true;
+                    reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+                    reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
+                    FileInfo file = new FileInfo(filepath + "/" + filename);
+                    const int BufferSize = 2048;
+                    byte[] content = new byte[BufferSize - 1 + 1];
+                    int dataRead;
+                    using (FileStream fs = file.OpenRead())
+                    {
+                        //把上传的文件写入流
+                        using (Stream rs = reqFTP.GetRequestStream())
+                        {
+                            do
+                            {
+                                //每次读文件流的2KB
+                                dataRead = fs.Read(content, 0, BufferSize);
+                                rs.Write(content, 0, dataRead);
+                            } while (!(dataRead < BufferSize));
+                            rs.Close();
+                        }
+                        fs.Close();
+                        fs.Dispose();
+                    }
+                    file.Delete();
+                }
+
+                //Thread.Sleep(1000);
+            }
+            catch (Exception ex)
+            {
+                return ex.Message;
+            }
+            return "";
+            //File.Delete(filepath + "/" + filename);
+        }
+
+        public string FtpCheckDirectoryExist(string destFilePath)
+        {
+            string fullDir = FtpParseDirectory(destFilePath);
+            string[] dirs = fullDir.Split('/');
+            string curDir = "/";
+            for (int i = 0; i < dirs.Length; i++)
+            {
+                string dir = dirs[i];
+                //如果是以/开始的路径,第一个为空    
+                if (dir != null && dir.Length > 0)
+                {
+                    try
+                    {
+                        curDir += dir + "/";
+                        FtpMakeDir(curDir);
+                    }
+                    catch (Exception ex)
+                    {
+
+                    }
+                }
+            }
+            return "";
+        }
+
+        public string FtpParseDirectory(string destFilePath)
+        {
+            return destFilePath.Substring(0, destFilePath.LastIndexOf("/"));
+        }
+
+        public Boolean FtpMakeDir(string localFile)
+        {
+            //Console.WriteLine(ftpServerIP + localFile);
+            FtpWebRequest req = (FtpWebRequest)WebRequest.Create(ftpServerIP + localFile);
+            try
+            {
+                req.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+                req.Method = WebRequestMethods.Ftp.MakeDirectory;
+                FtpWebResponse response = (FtpWebResponse)req.GetResponse();
+                response.Close();
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+                req.Abort();
+                return false;
+            }
+            req.Abort();
+            return true;
+        }
+    }
+}

+ 1 - 0
UAS_MES_BG/UAS_MES_BG.csproj

@@ -1188,6 +1188,7 @@
     <Compile Include="PublicMethod\AutoSizeControl.cs" />
     <Compile Include="PublicMethod\AutoSizeFormClass.cs" />
     <Compile Include="PublicMethod\BaseUtil.cs" />
+    <Compile Include="PublicMethod\BgFtpOperater.cs" />
     <Compile Include="PublicMethod\DrawHelper.cs" />
     <Compile Include="PublicMethod\Encryption.cs" />
     <Compile Include="PublicMethod\ExceptionHandler.cs" />