瀏覽代碼

修正下载文件逻辑
修正判断是否申请文档逻辑

luocaiyang 9 月之前
父節點
當前提交
9092971b4d

+ 14 - 7
wispro.sp.api/Controllers/CaseFileCompareController.cs

@@ -225,13 +225,20 @@ namespace wispro.sp.api.Controllers
             #region 将某些属性设为null,避免循环取值造成返回json过大
             foreach (CaseInfo item in retList)
             {
-                item.Customer.PerformanceItems = null;
-                item.Customer.ResponseMan = null;
-                item.Reviewer.Customers = null;
-                item.Reviewer.ExternalHandlerItems = null;
-                item.Reviewer.ItemStaffs = null;
-                item.Reviewer.AllocationRatios = null;
-                item.Reviewer.ReviewerItems = null;
+                if (item.Customer != null)
+                {
+                    item.Customer.PerformanceItems = null;
+                    item.Customer.ResponseMan = null;
+                }
+                if (item.Reviewer != null)
+                {
+                    item.Reviewer.Customers = null;
+
+                    item.Reviewer.ExternalHandlerItems = null;
+                    item.Reviewer.ItemStaffs = null;
+                    item.Reviewer.AllocationRatios = null;
+                    item.Reviewer.ReviewerItems = null;
+                }
             }
             #endregion
 

+ 11 - 7
wispro.sp.utility/CompareDocx.cs

@@ -43,7 +43,10 @@ namespace wispro.sp.utility
                 }
                 else
                 {
-                    DocumentString = GetDocxTxt(this.FilePath);
+                    if (this.FilePath.ToLower().EndsWith(".docx"))
+                    {
+                        DocumentString = GetDocxTxt(this.FilePath);
+                    }
                 }
             }
 
@@ -105,7 +108,7 @@ namespace wispro.sp.utility
 
             private string List2String(List<string> lines)
             {
-                string[] array = { "权            书", "说            要", "说        书" , "摘         图", "说            图" };
+                string[] array = { "权利要求书", "说明书摘要", "说明书" , "摘要附图", "说明书附图" };
 
                 StringBuilder sb = new StringBuilder();
                 string lastBlock = string.Empty;
@@ -115,20 +118,21 @@ namespace wispro.sp.utility
                     {
                         sb.Append(line.Trim() + "\r\n");
 
-                        if(Array.Exists(array, element => element == line.Trim()))
+                        
+                        if(Array.Exists(array, element => element == line.Replace("\u0001","").Replace(" ","").Trim()))
                         {
-                            lastBlock = line.Trim();
+                            lastBlock = line.Replace("\u0001", "").Replace(" ", "").Trim();
                         }
                         else
                         {
                             switch(lastBlock) {
-                                case "权            书":
+                                case "权利要求书":
                                     this.Claim = this.Claim + "\r\n" + line;
                                     break;
-                                case "说            要":
+                                case "说明书摘要":
                                     this.Abstract = this.Abstract + "\r\n" + line;
                                     break;
-                                case "说        书":
+                                case "说明书":
                                     this.FullText = this.FullText + "\r\n" + line;
                                     break;
 

+ 339 - 72
wispro.sp.utility/IPEasyUtility.cs

@@ -8,6 +8,7 @@ using System.IO;
 using System.Linq;
 using System.Threading;
 using System.Xml.Linq;
+using Microsoft.Extensions.Primitives;
 using NPOI.HPSF;
 using NPOI.SS.Formula.Functions;
 using OpenQA.Selenium;
@@ -24,16 +25,114 @@ namespace wispro.sp.utility
         static string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
         static string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
 
-        static bool WaitForFileDownload(string downloadDir, string fileName, TimeSpan timeout)
+        static string WaitForFileDownload(string downloadDir, TimeSpan timeout)
+        {
+            string fileName = null;
+            DateTime startTime = DateTime.Now;
+            while (DateTime.Now - startTime < timeout)
+            {
+                if (Directory.GetFiles(downloadDir).Length > 0)
+                {
+                    fileName = Directory.GetFiles(downloadDir).FirstOrDefault();
+                    break;
+                }
+                Thread.Sleep(100);
+            }
+
+            
+            while (File.Exists(fileName) && DateTime.Now - startTime < timeout)
+            {
+                // 检查文件是否完成写入(文件大小是否稳定)
+                long previousSize = 0;
+                long currentSize = new FileInfo(fileName).Length;
+                while (previousSize != currentSize && currentSize>0)
+                {
+                    Debug.WriteLine($"{fileName}文件大小:{previousSize},{currentSize}");
+                    previousSize = currentSize;
+                    try
+                    {
+                        //文件在下载完后,临时文件可能就不存在了,
+                        //这时会导致下边的语句会抛出错误
+                        currentSize = new FileInfo(fileName).Length;
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine($"获取文件出错大小:{ex.Message}");
+                        break;
+                    }
+
+                    Debug.WriteLine("等待一段时间!");
+                    Debug.WriteLine($"{fileName}文件大小:{previousSize},{currentSize}");
+                    Thread.Sleep(3000); // 等待一段时间
+                }
+
+                if (previousSize == currentSize)
+                {
+                    if ((fileName.Contains(".crdownload") || fileName.Contains(".tmp")) && File.Exists(fileName))
+                    {
+                        Debug.WriteLine(".crdownload文件,等待!");
+                        Thread.Sleep(1000);
+                    }
+                    else
+                    {
+                        Debug.WriteLine($"文件大小相同跳出循环");
+                        break;
+                    }
+                }
+
+                
+            }
+
+            fileName = Directory.GetFiles(downloadDir).FirstOrDefault(); 
+            while(fileName.Contains(".crdownload") || fileName.Contains(".tmp")){
+                fileName = Directory.GetFiles(downloadDir).FirstOrDefault();
+                Thread.Sleep(1000);
+            }
+
+            return Directory.GetFiles(downloadDir).FirstOrDefault();
+
+        }
+
+        static bool fileInFolder(string strFolder,string filename,out string outFilePath)
+        {
+            if (File.Exists(Path.Combine(strFolder, filename)))
+            {
+                outFilePath = Path.Combine(strFolder, filename);
+                return true;
+            }
+            else
+            {
+                outFilePath = null;
+                if (Directory.Exists(strFolder))
+                {
+                    foreach (var f in new DirectoryInfo(strFolder).GetFiles())
+                    {
+                        string temName = f.Name.Trim();
+                        if (temName == filename || temName.Replace(" ", "") == filename)
+                        {
+                            outFilePath = f.FullName;
+                            return true;
+                        }
+                    }
+                    return false;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+        }
+
+        static bool WaitForFileDownload(string downloadDir, string fileName, TimeSpan timeout,out string outfile)
         {
             DateTime startTime = DateTime.Now;
             while (DateTime.Now - startTime < timeout)
             {
                 string filePath = Path.Combine(downloadDir, fileName);
                 
-                if (File.Exists(filePath))
+                if (fileInFolder(downloadDir, fileName, out filePath))
                 {
-                    // 检查文件是否完成写入(文件大小是否稳定)C:\temp\案件清单(2024年12月4日).xlsx
+                    // 检查文件是否完成写入(文件大小是否稳定)
                     long previousSize = 0;
                     long currentSize = new FileInfo(filePath).Length;
                     while (previousSize != currentSize)
@@ -42,10 +141,13 @@ namespace wispro.sp.utility
                         previousSize = currentSize;
                         currentSize = new FileInfo(filePath).Length;
                     }
+                    outfile = filePath;
                     return true; // 文件下载完成
                 }
                 Thread.Sleep(1000); // 等待文件出现
             }
+
+            outfile = null;
             return false; // 超时,文件未下载完成
         }
 
@@ -179,6 +281,25 @@ namespace wispro.sp.utility
             });
         }
 
+        private static string CopyFile(string strfile)
+        {
+            if(strfile == null)
+            {
+                return null;
+            }
+
+            string fileName = new FileInfo(strfile).Name;
+            string desfile = Path.Combine(strFileSavePath, fileName);
+            if (File.Exists(desfile))
+            {
+                File.Delete(desfile);
+            }
+            File.Copy(strfile, desfile);
+            File.Delete(strfile);
+            
+            return desfile;
+        }
+
         /// <summary>
         /// 获取指定案号的专利申请案的基本信息和初稿文件、定稿文件和第一次返稿文件
         /// </summary>
@@ -190,8 +311,13 @@ namespace wispro.sp.utility
             dynamic retObject = new ExpandoObject();
 
             retObject.CaseNo = caseNo.Trim();
+            string strDownloadPath = Path.Combine(strFileSavePath, caseNo);
+            if (!Directory.Exists(strDownloadPath))
+            {
+                Directory.CreateDirectory(strDownloadPath);
+            }
 
-            using (IWebDriver driver = CreateChromeDriver())
+            using (IWebDriver driver = CreateChromeDriver(strDownloadPath))
             {
                 try
                 {
@@ -230,9 +356,10 @@ namespace wispro.sp.utility
                     inputSearch.SendKeys(caseNo.Trim());
 
                     var btnSearch = waitGetElementById(wait, "btn_Search");// driver.FindElement(By.Id("btn_Search"));
+                    System.Threading.Thread.Sleep(200);
                     driver.ExecuteJavaScript("arguments[0].click();",btnSearch);
                     //btnSearch.Click();
-                    
+                    //System.Threading.Thread.Sleep(500);
                     try
                     {
                         var caseLink = wait.Until((d) =>
@@ -267,6 +394,17 @@ namespace wispro.sp.utility
                     //申请国家
                     retObject.Country = waitGetElementById(wait, "p_case_info__country_id").GetAttribute("value");
 
+                    #region 下载新申请第一次返稿文档
+                    var kzTab = wait.Until(d => d.FindElement(By.XPath($"//span[contains(text(),'往来信息')]")));
+                    kzTab.Click();
+                    
+
+                    var kzTable = waitGetElementById(wait, "table_SendList");
+                    System.Threading.Thread.Sleep(500);
+                    retObject.firstReturnFile = Download(driver, wait, kzTable, new { fileNameCol =2,fileTypeCol=-1,uploadDateCol=9}, "新申请第一次返稿", strDownloadPath,new string[] { "申请文件"},new string[] { "检索报告","查新报告"});
+                    retObject.firstReturnFile = CopyFile(retObject.firstReturnFile);
+                    #endregion
+
                     var table = waitGetElementById(wait, "table_ProcList");
                     var rows = waitGetElementsByTagName(wait, "tr", table);// table.FindElements(By.TagName("tr"));
                     foreach (var row in rows)
@@ -274,7 +412,6 @@ namespace wispro.sp.utility
                         var cells = row.FindElements(By.TagName("td"));
                         if (cells[1].Text == "新申请")
                         {
-
                             var bthEdit = waitGetElementByClassName(wait, "tbedit", cells[12]);
                             driver.ExecuteJavaScript("arguments[0].click();", bthEdit);
                             break;
@@ -324,28 +461,52 @@ namespace wispro.sp.utility
                     //新申请第一次返稿(第一次发客户文档)、
                     //新申请文档(定稿文档)”
                     var table_filelist = waitGetElementById(wait, "table_filelist");
+                    System.Threading.Thread.Sleep(500);
+
                     //定稿文件
                     try
                     {
-                        Download(retObject, driver, wait, table_filelist, "新申请文档");
+                        retObject.finallyFile = null;
+                        retObject.finallyFile = Download(driver, wait, table_filelist, "新申请文档", strDownloadPath);
+                        //dynamic config = new { fileNameCol = 2, fileTypeCol = 4, uploadDateCol = 7 };
+                        //retObject.finallyFile = Download(driver, wait, table_filelist, config, "新申请文档", strDownloadPath);
+                        retObject.finallyFile = CopyFile(retObject.finallyFile);
+                        
                     }
                     catch { }
-                    //新申请第一次返稿文件
-                    try
+
+                    if (retObject.firstReturnFile == null)
                     {
-                        Download(retObject, driver, wait, table_filelist, "新申请第一次返稿");
+                        //新申请第一次返稿文件
+                        try
+                        {
+                            retObject.firstReturnFile = Download(driver, wait, table_filelist, "新申请第一次返稿", strDownloadPath);
+                            retObject.firstReturnFile = CopyFile(retObject.firstReturnFile);
+                        }
+                        catch (Exception ex)
+                        {
+
+                        }
                     }
-                    catch { }
 
                     //初稿文件
                     try
                     {
+                        retObject.draftFile = null;
                         waitGetElementById(wait, "draftfiletoggle").Click();
-                        var table_draffilelist = waitGetElementById(wait, "table_draftfilelist");// driver.FindElement(By.Id("table_draftfilelist"));
-                        Download(retObject, driver, wait, table_draffilelist, "新申请第一次内审");
+                        var table_draffilelist = waitGetElementById(wait, "table_draftfilelist");
+                        System.Threading.Thread.Sleep(500);
+                        dynamic config = new { fileNameCol =1,fileTypeCol=3,uploadDateCol=6};
+                        retObject.draftFile = Download( driver, wait, table_draffilelist, config, "新申请第一次内审",strDownloadPath, new string[] { "申请文件", "权利要求" , "申请文档" }, new string[] { "检索报告","查新报告" });
+                        retObject.draftFile = CopyFile(retObject.draftFile);
                     }
                     catch { }
 
+                    if (Directory.Exists(strDownloadPath))
+                    {
+                        Directory.Delete(strDownloadPath);
+                    }
+
                 }
                 catch (Exception ex)
                 {
@@ -366,7 +527,7 @@ namespace wispro.sp.utility
         /// <param name="type">类型0:递交中、1:前一天完成</param>
         /// <returns></returns>
         /// <exception cref="Exception"></exception>
-        public static DataTable GetFinished3FilesCases(int type)
+        public static DataTable GetFinished3FilesCases(int type,int days=1)
         {
             DataTable  retObject = new DataTable();
             
@@ -443,7 +604,8 @@ namespace wispro.sp.utility
                             driver.ExecuteJavaScript("arguments[0].scrollIntoView();", startDate);
                             startDate.Click();
                             System.Threading.Thread.Sleep(500);
-                            startDate.SendKeys(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));
+                            
+                            startDate.SendKeys(DateTime.Now.AddDays(0-days).ToString("yyyy-MM-dd"));
 
                             Log($"{DateTime.Now}\t输入处理事项完成日期:结束日期");
 
@@ -524,7 +686,7 @@ namespace wispro.sp.utility
 
                     var ReportName = $"案件清单({DateTime.Now.ToString("yyyy年MM月d日")})";
                     string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
-                    WaitForFileDownload(strFileSavePath, $"{ReportName.Trim()}.xlsx", TimeSpan.FromMinutes(5));
+                    WaitForFileDownload(strFileSavePath, $"{ReportName.Trim()}.xlsx", TimeSpan.FromMinutes(5),out strFilePath);
 
                     //删除下载记录
                     Log($"{DateTime.Now}\t删除下载记录");
@@ -558,84 +720,181 @@ namespace wispro.sp.utility
             return retObject;
         }
 
-        private static void Download(dynamic retObject, IWebDriver driver, WebDriverWait wait, IWebElement table_filelist, string fileType)
+        private static bool fileNameValid(string str, string[] filterStrings)
         {
-            var tBody = waitGetElementByTagName(wait, "tbody", table_filelist);
-
-            var finallyFile = wait.Until((d) =>
+            if (filterStrings.Length == 0)
             {
-                try { 
-                    return tBody.FindElement(By.XPath($".//td[@colname='file_desc'][normalize-space()='{fileType}']"));
-                }
-                catch 
+                return true;
+            }
+            else
+            {
+                foreach (string filterString in filterStrings)
                 {
-                    return null;
+                    if (str.Contains(filterString))
+                    {
+                        return true;
+                    }
                 }
-            });
 
+                return false;
+            }
+        }
+
+        private static string Download(IWebDriver driver, WebDriverWait wait, IWebElement table_filelist, dynamic config,string fileType, string downloadPath = null, string[] includesStrings = null, string[] unincludeStrings = null)
+        {
+            if(downloadPath == null)
+            {
+                downloadPath = strFileSavePath;
+            }
+
+            if (unincludeStrings == null)
+            {
+                unincludeStrings = new string[] { };
+            }
+
+            if (includesStrings == null)
+            {
+                includesStrings = new string[] { };
+            }
             
+            var tBody = waitGetElementByTagName(wait, "tbody", table_filelist);
+            var Rows = waitGetElementsByTagName(wait, "tr", tBody);
 
-            if(finallyFile == null)
+            ReadOnlyCollection<IWebElement> temRow =null;
+            DateTime dateTime = DateTime.Now;
+            foreach(var row in Rows)
             {
-                switch (fileType)
+                var cols = waitGetElementsByTagName(wait,"td",row);
+                System.Threading.Thread.Sleep(500);
+
+                if(cols.Count ==1 && cols[0].Text == "无数据")
                 {
-                    case "新申请文档":
-                        retObject.finallyFile = null;
-                        break;
-                    case "新申请第一次返稿":
-                        retObject.firstReturnFile = null;
-                        break;
-                    case "新申请第一次内审":
-                        retObject.draftFile = null;
-                        break;
+                    break;
                 }
 
-                return;
+                if (config.fileTypeCol>0 && cols[config.fileTypeCol].Text == fileType)
+                {
+                    temRow = cols;
+                    break;
+                }
+                else
+                {
+                    if(unincludeStrings.Length ==0 || 
+                        ((unincludeStrings.Length > 0) && !fileNameValid(cols[config.fileNameCol].Text, unincludeStrings)
+                        ))
+                    {
+                        DateTime temDate = DateTime.Parse(cols[config.uploadDateCol].Text);
+                        
+                        if (fileNameValid(cols[config.fileNameCol].Text, includesStrings))
+                        {
+                            if (temRow == null)
+                            {
+                                temRow = cols;
+                                dateTime = temDate;
+                            }
+                            else
+                            {
+                                if (temDate < dateTime)
+                                {
+                                    temRow = cols;
+                                    dateTime = temDate;
+                                }
+                            }
+                        }
+                        
+                    }
+                }
             }
-            
-            var tdfileName = wait.Until((d) =>
+
+            if (temRow != null)
             {
-                try
-                {
-                    return finallyFile.FindElement(By.XPath("preceding-sibling::*[2]"));
+                //清除下载路径的文件
+                Directory.Delete(downloadPath, true);
+                Directory.CreateDirectory(downloadPath);
+
+
+                var btnDownload = waitGetElementByClassName(wait, "tbdownload", temRow[temRow.Count - 1]);
+                driver.ExecuteJavaScript("arguments[0].click();", btnDownload);
+
+
+                #region 等待文件下载完
+                string filePath = WaitForFileDownload(downloadPath, TimeSpan.FromMinutes(5));
+                return filePath;
+                #endregion
+                
+                
+            }
+
+            return null;
+        }
+
+        private static string Download(IWebDriver driver, WebDriverWait wait, IWebElement table_filelist, string fileType,string downloadPath=null)
+        {
+            if (string.IsNullOrEmpty(downloadPath))
+            {
+                downloadPath = strFileSavePath;
+            }
+            var tBody = waitGetElementByTagName(wait, "tbody", table_filelist);
+
+            var finallyFiles = wait.Until((d) =>
+            {
+                try {
+                    return tBody.FindElements(By.XPath($".//td[@colname='file_desc'][normalize-space()='{fileType}']"));
                 }
-                catch
+                catch 
                 {
                     return null;
                 }
             });
 
-            string fileName = tdfileName.Text;
 
-            while (string.IsNullOrEmpty(fileName))
+            if(finallyFiles == null && finallyFiles.Count>0)
             {
-                System.Threading.Thread.Sleep(100);
-                fileName = tdfileName.Text; 
+                return null;
             }
 
-            string filePath = System.IO.Path.Combine(strFileSavePath, fileName);
-            if (System.IO.File.Exists(filePath))
+            foreach (var finallyFile in finallyFiles)
             {
-                System.IO.File.Delete(filePath);
-            }
+                var tdfileName = wait.Until((d) =>
+                {
+                    try
+                    {
+                        return finallyFile.FindElement(By.XPath("preceding-sibling::*[2]"));
+                    }
+                    catch
+                    {
+                        return null;
+                    }
+                });
 
-            switch (fileType)
-            {
-                case "新申请文档":
-                    retObject.finallyFile = filePath; 
-                    break;
-                case "新申请第一次返稿":
-                    retObject.firstReturnFile = filePath;
-                    break;
-                case "新申请第一次内审":
-                    retObject.draftFile = filePath;
-                    break;
+                string fileName = tdfileName.Text;
+
+                
+
+                while (string.IsNullOrEmpty(fileName))
+                {
+                    System.Threading.Thread.Sleep(100);
+                    fileName = tdfileName.Text;
+                }
+
+                if (fileName.Contains(".doc"))
+                {
+                    string filePath = System.IO.Path.Combine(downloadPath, fileName);
+                    if (System.IO.File.Exists(filePath))
+                    {
+                        System.IO.File.Delete(filePath);
+                    }
+
+                    var btnDownload = finallyFile.FindElement(By.XPath("following-sibling::*[4]"));
+                    btnDownload = waitGetElementByClassName(wait, "tbdownload", btnDownload);
+                    driver.ExecuteJavaScript("arguments[0].click();", btnDownload);
+                    WaitForFileDownload(downloadPath, fileName, TimeSpan.FromMinutes(5), out filePath);
+
+                    return filePath;
+                }
             }
-            
-            var btnDownload = finallyFile.FindElement(By.XPath("following-sibling::*[4]"));
-            btnDownload = waitGetElementByClassName(wait, "tbdownload", btnDownload);
-            driver.ExecuteJavaScript("arguments[0].click();", btnDownload);
-            WaitForFileDownload(strFileSavePath, fileName, TimeSpan.FromMinutes(5));
+
+            return null;
         }
 
         private static void Login(IWebDriver driver, WebDriverWait wait)
@@ -686,7 +945,8 @@ namespace wispro.sp.utility
                     waitGetElementById(wait, "btnSubmit").Click();
                     //driver.FindElement(By.Id("btnSubmit")).Click();
 
-                    WaitForFileDownload(strFileSavePath, filename, TimeSpan.FromMinutes(5));
+                    string strRetFile = null;
+                    WaitForFileDownload(strFileSavePath, filename, TimeSpan.FromMinutes(5),out strRetFile);
                 }
                 catch (Exception ex)
                 {
@@ -711,7 +971,7 @@ namespace wispro.sp.utility
             sw.Dispose();
         }
 
-        private static OpenQA.Selenium.Chrome.ChromeDriver CreateChromeDriver()
+        private static OpenQA.Selenium.Chrome.ChromeDriver CreateChromeDriver(string downloadPath=null)
         {
             try
             {
@@ -722,7 +982,14 @@ namespace wispro.sp.utility
                 options.AddUserProfilePreference("profile.default_content_settings.popups", 0);
                 options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
                 options.AddUserProfilePreference("download.prompt_for_download", false); // 禁止下载提示
-                options.AddUserProfilePreference("download.default_directory", strFileSavePath);
+                if (!string.IsNullOrEmpty(downloadPath))
+                {
+                    options.AddUserProfilePreference("download.default_directory", downloadPath);
+                }
+                else
+                {
+                    options.AddUserProfilePreference("download.default_directory", strFileSavePath);
+                }
                 options.AddUserProfilePreference("intl.accept_languages", "nl");
                 options.AddUserProfilePreference("disable-popup-blocking", "true");
                 options.AddUserProfilePreference("safebrowsing.enabled", true);
@@ -935,7 +1202,7 @@ namespace wispro.sp.utility
                     //btnDownload.Click();
                     
                     string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
-                    WaitForFileDownload(strFileSavePath, $"{ReportName.Trim()}.xlsx", TimeSpan.FromMinutes(5));
+                    WaitForFileDownload(strFileSavePath, $"{ReportName.Trim()}.xlsx", TimeSpan.FromMinutes(5), out strFilePath);
                     
                     //删除下载记录
                     Log($"{DateTime.Now}\t删除下载记录");

+ 1 - 1
wispro.sp.winClient/appsettings.json

@@ -1,7 +1,7 @@
 {
   "IPEasySetting": {
     "DownloadFileSavePath": "c:\\temp",
-    "isHeadless": "false",
+    "isHeadless": "true",
     "Account": "caiyangl",
     "Password": "j)wx*lier*@3",
     "ChormeDriverPath": "e:\\source\\repos\\StaffPerformance\\packages\\ChormeDriver\\131.0.6778.108",

+ 12 - 1
wispro.sp.winClient/emlFileReader.cs

@@ -1,5 +1,7 @@
-using MimeKit;
+using DocumentFormat.OpenXml.Office2010.ExcelAc;
+using MimeKit;
 using System;
+using System.Collections.Generic;
 using System.IO;
 
 
@@ -9,6 +11,8 @@ namespace wispro.sp.winClient
     {
         private string _filePath;
 
+        public List<String> AttachFiles { get; set; }
+
         public emlFileReader(string filePath) { 
             _filePath = filePath;
 
@@ -31,6 +35,13 @@ namespace wispro.sp.winClient
                             part.Content.DecodeTo(output);
                         }
 
+                        if(AttachFiles== null)
+                        {
+                            AttachFiles = new List<String>(); 
+                        }
+
+                        AttachFiles.Add(savePath);
+
                         Console.WriteLine($"附件 '{fileName}' 已保存,类型: {contentType}");
                     }
                 }

文件差異過大導致無法顯示
+ 7 - 7
wispro.sp.winClient/frmCaseFileCompare.Designer.cs


+ 181 - 38
wispro.sp.winClient/frmCaseFileCompare.cs

@@ -22,6 +22,8 @@ using System.Net.Http.Json;
 using wispro.sp.share;
 using OpenQA.Selenium.Support.UI;
 using System.Dynamic;
+using System.Diagnostics;
+using NPOI.Util;
 
 namespace wispro.sp.winClient
 {
@@ -81,6 +83,11 @@ namespace wispro.sp.winClient
                 if (keyValuePairs.ContainsKey("DoPersons"))
                 {
                     caseInfo.Handlers = retFiles.DoPersons;
+                    caseInfo.Handlers = caseInfo.Handlers.Trim();
+                    if(caseInfo.Handlers.Substring(caseInfo.Handlers.Length - 1) == ";")
+                    {
+                        caseInfo.Handlers = caseInfo.Handlers.Substring(0, caseInfo.Handlers.Length - 1);
+                    }
                 }
 
 
@@ -119,9 +126,9 @@ namespace wispro.sp.winClient
 
         }
 
-        private async Task compareCaseFile()
+        private async Task compareCaseFile(int days)
         {
-            DataTable table = wispro.sp.utility.IPEasyUtility.GetFinished3FilesCases(1);
+            DataTable table = wispro.sp.utility.IPEasyUtility.GetFinished3FilesCases(1,days);
 
             if (table != null)
             {
@@ -138,28 +145,64 @@ namespace wispro.sp.winClient
 
                     string CaseNo = row["我方文号"].ToString();
 
+                    if (!CaseNo.StartsWith("PACN"))
+                    {
+                        continue ;
+                    }
+
                     var isExistResp = await new APIService().CaseExist(CaseNo);
 
                     //isExistResp.Wait();
 
-                    if (isExistResp)
+                    if (isExistResp || !CaseNo.StartsWith("PACN"))
                     {
                         continue;
                     }
 
-                    CaseInfo caseInfo = getCaseInfo_files(CaseNo, out draftFile, out returnFile, out finalFile);
+                    try
+                    {
+                        CaseInfo caseInfo = getCaseInfo_files(CaseNo, out draftFile, out returnFile, out finalFile);
 
 
-                    int i = (string.IsNullOrEmpty(draftFile) ? 0 : 1) +
-                        (string.IsNullOrEmpty(returnFile) ? 0 : 1) +
-                        (string.IsNullOrEmpty(finalFile) ? 0 : 1);
+                        int i = (string.IsNullOrEmpty(draftFile) ? 0 : 1) +
+                            (string.IsNullOrEmpty(returnFile) ? 0 : 1) +
+                            (string.IsNullOrEmpty(finalFile) ? 0 : 1);
 
-                    if (i > 1)
-                    {
-                        CompareFiles(draftFile, returnFile, finalFile, caseInfo);
+                        using (StreamWriter writer = new StreamWriter(@"c:\temp\caseFileInfo.txt", true))
+                        {
+                            writer.WriteLine($"{caseInfo.CaseNo},{(string.IsNullOrEmpty(draftFile) ? 0 : 1)},{(string.IsNullOrEmpty(returnFile) ? 0 : 1)},{(string.IsNullOrEmpty(finalFile) ? 0 : 1)}");
+                        }
 
-                        await new APIService().SaveCompareResult(caseInfo);
+                        if (i > 1)
+                        {
+                            CompareFiles(draftFile, returnFile, finalFile, caseInfo);
 
+                            await new APIService().SaveCompareResult(caseInfo);
+
+                        }
+
+                        try
+                        {
+                            if (File.Exists(draftFile))
+                            {
+                                File.Delete(draftFile);
+                            }
+
+                            if (File.Exists(returnFile))
+                            {
+                                File.Delete(returnFile);
+                            }
+
+                            if (File.Exists(finalFile))
+                            {
+                                File.Delete(finalFile);
+                            }
+                        }
+                        catch { }
+                    }
+                    catch(Exception ex)
+                    {
+                        Debug.WriteLine($"{CaseNo}\t{ex.Message}");
                     }
 
 
@@ -193,7 +236,7 @@ namespace wispro.sp.winClient
                     caseInfo.DRRCalim = docx.ClaimResult;
                 }
 
-                if (docx.AbstractResult.oldWordCount > 0)
+                if (docx.AllStringResult.oldWordCount > 0)
                 {
                     caseInfo.DRRAll = docx.AllStringResult;
                 }
@@ -241,16 +284,33 @@ namespace wispro.sp.winClient
                 System.IO.File.Delete(finalFile);
             }
 
-            if (System.IO.Directory.Exists(Path.Combine(strExtractPath, returnFile.Substring(0, returnFile.Length - 4))))
+            if (System.IO.File.Exists(tmpdraftFile))
+            {
+                System.IO.File.Delete(tmpdraftFile);
+            }
+
+            if (System.IO.File.Exists(tmpfinalFile))
+            {
+                System.IO.File.Delete(tmpfinalFile);
+            }
+
+            if (System.IO.File.Exists(tmpreturnFile))
+            {
+                System.IO.File.Delete(tmpreturnFile);
+            }
+
+
+
+            if (!string.IsNullOrEmpty(returnFile) && System.IO.Directory.Exists(Path.Combine(strExtractPath, returnFile.Substring(0, returnFile.Length - 4))))
             {
                 System.IO.Directory.Delete(Path.Combine(strExtractPath, returnFile.Substring(0, returnFile.Length - 4)), true);
             }
 
-            if (System.IO.Directory.Exists(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4))))
+            if (!string.IsNullOrEmpty(draftFile) && System.IO.Directory.Exists(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4))))
             {
                 System.IO.Directory.Delete(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4)), true);
             }
-            if (System.IO.Directory.Exists(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4))))
+            if (!string.IsNullOrEmpty(finalFile) && System.IO.Directory.Exists(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4))))
             {
                 System.IO.Directory.Delete(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4)), true);
             }
@@ -264,9 +324,10 @@ namespace wispro.sp.winClient
         {
             if (string.IsNullOrEmpty(this.txtCaseNo.Text))
             {
+                
                 if (MessageBox.Show("获取前一天所有的完成案件,并比较文档?", "提示框", MessageBoxButtons.YesNo) == DialogResult.Yes)
                 {
-                    compareCaseFile();
+                    compareCaseFile(30);
                     return;
                 }
                 else
@@ -300,11 +361,67 @@ namespace wispro.sp.winClient
 
         }
 
+        private static bool isValidFile(string strFile,int type)
+        {
+            if (string.IsNullOrEmpty(strFile)) { return false; }
+
+            string strfileName = new FileInfo(strFile).Name;
+            switch (type)
+            {
+                case 0:
+                    if (strfileName.ToUpper().IndexOf("检索报告", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("通知书", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("查新报告", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("对比文件", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("检索文档", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        (strfileName.ToUpper().IndexOf("申请文档", StringComparison.OrdinalIgnoreCase) > 0 || 
+                        strfileName.ToUpper().IndexOf("申请文件", StringComparison.OrdinalIgnoreCase) > 0 ||
+                        strfileName.ToUpper().IndexOf("权利要求", StringComparison.OrdinalIgnoreCase) > 0 || 
+                        strfileName.ToUpper().IndexOf("V1R", StringComparison.OrdinalIgnoreCase) > 0))
+                    {
+                        return true;
+                    }
+                    break;
+                case 1:
+                    if ((strfileName.ToUpper().IndexOf("申请文件", StringComparison.OrdinalIgnoreCase) > 0 ||
+                        strfileName.ToUpper().IndexOf("V1F", StringComparison.OrdinalIgnoreCase) > 0 ||
+                        strfileName.ToUpper().IndexOf("初稿", StringComparison.OrdinalIgnoreCase) > 0 ||
+                        strfileName.ToUpper().IndexOf("权利要求", StringComparison.OrdinalIgnoreCase) > 0 ||
+                        strfileName.ToUpper().IndexOf("申请文档", StringComparison.OrdinalIgnoreCase) > 0 || 
+                        strfileName.ToUpper().IndexOf("说明书", StringComparison.OrdinalIgnoreCase) > 0)  &&
+                        strfileName.ToUpper().IndexOf("检索报告", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("查新报告", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("对比文件", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("通知书", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("检索文档", StringComparison.OrdinalIgnoreCase) < 0)
+                    {
+                        return true;
+                    }
+                    break;
+                case 2:
+                    if (strfileName.ToUpper().IndexOf("检索报告", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("查新报告", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("对比文件", StringComparison.OrdinalIgnoreCase) < 0 &&
+                        strfileName.ToUpper().IndexOf("检索文档", StringComparison.OrdinalIgnoreCase) < 0)
+                    {
+                        return true;
+                    }
+                    break;
+            }
+
+            return false;
+        }
+
         private static string ExtractFile(string file, int type, string strExtractPath)
         {
+            if (string.IsNullOrEmpty(file))
+            {
+                return null;
+            }
             if (file.ToLower().EndsWith(".zip") || file.ToLower().EndsWith(".rar"))
             {
-                string extractPath = Path.Combine(strExtractPath, file.Substring(0, file.Length - 4));
+                string temFileName = new FileInfo(file).Name;
+                string extractPath = Path.Combine(strExtractPath, temFileName.Substring(0, temFileName.Length - 4));
 
                 if (file.ToLower().EndsWith(".zip"))
                 {
@@ -317,35 +434,56 @@ namespace wispro.sp.winClient
 
                 foreach (string f in Directory.GetFiles(extractPath, "*.*", SearchOption.AllDirectories))
                 {
-                    switch (type)
+                    if (isValidFile(f, type))
                     {
-                        case 0:
-                            if (f.ToUpper().IndexOf("V1R", StringComparison.OrdinalIgnoreCase) > 0)
-                            {
-                                return f;
-                            }
-                            break;
-                        case 1:
-                            if (f.ToUpper().IndexOf("V1F", StringComparison.OrdinalIgnoreCase) > 0)
-                            {
-                                return f;
-                            }
-                            break;
-                        case 2:
-                            if (f.IndexOf("定稿", StringComparison.OrdinalIgnoreCase) > 0)
-                            {
-                                return f;
-                            }
-                            break;
+                        return f;
                     }
-
                 }
 
                 return null;
             }
             else
             {
-                return file;
+                if (file.ToLower().EndsWith(".eml"))
+                {
+                    emlFileReader emlFile = new emlFileReader(file);
+                    if (emlFile.AttachFiles != null)
+                    {
+                        string retFile = null;
+                        foreach (var temfile in emlFile.AttachFiles)
+                        {
+                            string temExtractFile = ExtractFile(temfile, type, strExtractPath);
+                            if (isValidFile(temExtractFile,type))
+                            {
+                                retFile = temExtractFile;
+                                break;
+                                
+                            }
+
+                        }
+
+                        if(retFile == null && emlFile.AttachFiles.Count ==1)
+                        {
+                            retFile = ExtractFile(emlFile.AttachFiles[0], type, strExtractPath);
+                        }
+
+                        foreach (var temfile in emlFile.AttachFiles)
+                        {
+                            if (temfile != retFile)
+                            {
+                                File.Delete(temfile);
+                            }
+                        }
+
+                        return retFile;
+                    }
+
+                    return null;
+                }
+                else
+                {
+                    return file;
+                }
             }
         }
 
@@ -716,5 +854,10 @@ namespace wispro.sp.winClient
         {
             emlFileReader reader = new emlFileReader(@"D:\Users\luowen\Downloads\2f7e92c1-e009-4b19-ba8d-332e8f6f2ffc.eml");
         }
+
+        private void txtCaseNo_TextChanged(object sender, EventArgs e)
+        {
+
+        }
     }
 }