|
@@ -8,6 +8,7 @@ using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading;
|
|
using System.Xml.Linq;
|
|
using System.Xml.Linq;
|
|
|
|
+using Microsoft.Extensions.Primitives;
|
|
using NPOI.HPSF;
|
|
using NPOI.HPSF;
|
|
using NPOI.SS.Formula.Functions;
|
|
using NPOI.SS.Formula.Functions;
|
|
using OpenQA.Selenium;
|
|
using OpenQA.Selenium;
|
|
@@ -24,16 +25,114 @@ namespace wispro.sp.utility
|
|
static string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
|
|
static string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
|
|
static string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
|
|
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;
|
|
DateTime startTime = DateTime.Now;
|
|
while (DateTime.Now - startTime < timeout)
|
|
while (DateTime.Now - startTime < timeout)
|
|
{
|
|
{
|
|
string filePath = Path.Combine(downloadDir, fileName);
|
|
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 previousSize = 0;
|
|
long currentSize = new FileInfo(filePath).Length;
|
|
long currentSize = new FileInfo(filePath).Length;
|
|
while (previousSize != currentSize)
|
|
while (previousSize != currentSize)
|
|
@@ -42,10 +141,13 @@ namespace wispro.sp.utility
|
|
previousSize = currentSize;
|
|
previousSize = currentSize;
|
|
currentSize = new FileInfo(filePath).Length;
|
|
currentSize = new FileInfo(filePath).Length;
|
|
}
|
|
}
|
|
|
|
+ outfile = filePath;
|
|
return true; // 文件下载完成
|
|
return true; // 文件下载完成
|
|
}
|
|
}
|
|
Thread.Sleep(1000); // 等待文件出现
|
|
Thread.Sleep(1000); // 等待文件出现
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ outfile = null;
|
|
return false; // 超时,文件未下载完成
|
|
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>
|
|
/// 获取指定案号的专利申请案的基本信息和初稿文件、定稿文件和第一次返稿文件
|
|
/// 获取指定案号的专利申请案的基本信息和初稿文件、定稿文件和第一次返稿文件
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -190,8 +311,13 @@ namespace wispro.sp.utility
|
|
dynamic retObject = new ExpandoObject();
|
|
dynamic retObject = new ExpandoObject();
|
|
|
|
|
|
retObject.CaseNo = caseNo.Trim();
|
|
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
|
|
try
|
|
{
|
|
{
|
|
@@ -230,9 +356,10 @@ namespace wispro.sp.utility
|
|
inputSearch.SendKeys(caseNo.Trim());
|
|
inputSearch.SendKeys(caseNo.Trim());
|
|
|
|
|
|
var btnSearch = waitGetElementById(wait, "btn_Search");// driver.FindElement(By.Id("btn_Search"));
|
|
var btnSearch = waitGetElementById(wait, "btn_Search");// driver.FindElement(By.Id("btn_Search"));
|
|
|
|
+ System.Threading.Thread.Sleep(200);
|
|
driver.ExecuteJavaScript("arguments[0].click();",btnSearch);
|
|
driver.ExecuteJavaScript("arguments[0].click();",btnSearch);
|
|
//btnSearch.Click();
|
|
//btnSearch.Click();
|
|
-
|
|
|
|
|
|
+ //System.Threading.Thread.Sleep(500);
|
|
try
|
|
try
|
|
{
|
|
{
|
|
var caseLink = wait.Until((d) =>
|
|
var caseLink = wait.Until((d) =>
|
|
@@ -267,6 +394,17 @@ namespace wispro.sp.utility
|
|
//申请国家
|
|
//申请国家
|
|
retObject.Country = waitGetElementById(wait, "p_case_info__country_id").GetAttribute("value");
|
|
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 table = waitGetElementById(wait, "table_ProcList");
|
|
var rows = waitGetElementsByTagName(wait, "tr", table);// table.FindElements(By.TagName("tr"));
|
|
var rows = waitGetElementsByTagName(wait, "tr", table);// table.FindElements(By.TagName("tr"));
|
|
foreach (var row in rows)
|
|
foreach (var row in rows)
|
|
@@ -274,7 +412,6 @@ namespace wispro.sp.utility
|
|
var cells = row.FindElements(By.TagName("td"));
|
|
var cells = row.FindElements(By.TagName("td"));
|
|
if (cells[1].Text == "新申请")
|
|
if (cells[1].Text == "新申请")
|
|
{
|
|
{
|
|
-
|
|
|
|
var bthEdit = waitGetElementByClassName(wait, "tbedit", cells[12]);
|
|
var bthEdit = waitGetElementByClassName(wait, "tbedit", cells[12]);
|
|
driver.ExecuteJavaScript("arguments[0].click();", bthEdit);
|
|
driver.ExecuteJavaScript("arguments[0].click();", bthEdit);
|
|
break;
|
|
break;
|
|
@@ -324,28 +461,52 @@ namespace wispro.sp.utility
|
|
//新申请第一次返稿(第一次发客户文档)、
|
|
//新申请第一次返稿(第一次发客户文档)、
|
|
//新申请文档(定稿文档)”
|
|
//新申请文档(定稿文档)”
|
|
var table_filelist = waitGetElementById(wait, "table_filelist");
|
|
var table_filelist = waitGetElementById(wait, "table_filelist");
|
|
|
|
+ System.Threading.Thread.Sleep(500);
|
|
|
|
+
|
|
//定稿文件
|
|
//定稿文件
|
|
try
|
|
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 { }
|
|
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
|
|
try
|
|
{
|
|
{
|
|
|
|
+ retObject.draftFile = null;
|
|
waitGetElementById(wait, "draftfiletoggle").Click();
|
|
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 { }
|
|
catch { }
|
|
|
|
|
|
|
|
+ if (Directory.Exists(strDownloadPath))
|
|
|
|
+ {
|
|
|
|
+ Directory.Delete(strDownloadPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
@@ -366,7 +527,7 @@ namespace wispro.sp.utility
|
|
/// <param name="type">类型0:递交中、1:前一天完成</param>
|
|
/// <param name="type">类型0:递交中、1:前一天完成</param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
/// <exception cref="Exception"></exception>
|
|
- public static DataTable GetFinished3FilesCases(int type)
|
|
|
|
|
|
+ public static DataTable GetFinished3FilesCases(int type,int days=1)
|
|
{
|
|
{
|
|
DataTable retObject = new DataTable();
|
|
DataTable retObject = new DataTable();
|
|
|
|
|
|
@@ -443,7 +604,8 @@ namespace wispro.sp.utility
|
|
driver.ExecuteJavaScript("arguments[0].scrollIntoView();", startDate);
|
|
driver.ExecuteJavaScript("arguments[0].scrollIntoView();", startDate);
|
|
startDate.Click();
|
|
startDate.Click();
|
|
System.Threading.Thread.Sleep(500);
|
|
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输入处理事项完成日期:结束日期");
|
|
Log($"{DateTime.Now}\t输入处理事项完成日期:结束日期");
|
|
|
|
|
|
@@ -524,7 +686,7 @@ namespace wispro.sp.utility
|
|
|
|
|
|
var ReportName = $"案件清单({DateTime.Now.ToString("yyyy年MM月d日")})";
|
|
var ReportName = $"案件清单({DateTime.Now.ToString("yyyy年MM月d日")})";
|
|
string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
|
|
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删除下载记录");
|
|
Log($"{DateTime.Now}\t删除下载记录");
|
|
@@ -558,84 +720,181 @@ namespace wispro.sp.utility
|
|
return retObject;
|
|
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;
|
|
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)
|
|
private static void Login(IWebDriver driver, WebDriverWait wait)
|
|
@@ -686,7 +945,8 @@ namespace wispro.sp.utility
|
|
waitGetElementById(wait, "btnSubmit").Click();
|
|
waitGetElementById(wait, "btnSubmit").Click();
|
|
//driver.FindElement(By.Id("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)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
@@ -711,7 +971,7 @@ namespace wispro.sp.utility
|
|
sw.Dispose();
|
|
sw.Dispose();
|
|
}
|
|
}
|
|
|
|
|
|
- private static OpenQA.Selenium.Chrome.ChromeDriver CreateChromeDriver()
|
|
|
|
|
|
+ private static OpenQA.Selenium.Chrome.ChromeDriver CreateChromeDriver(string downloadPath=null)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -722,7 +982,14 @@ namespace wispro.sp.utility
|
|
options.AddUserProfilePreference("profile.default_content_settings.popups", 0);
|
|
options.AddUserProfilePreference("profile.default_content_settings.popups", 0);
|
|
options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
|
|
options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
|
|
options.AddUserProfilePreference("download.prompt_for_download", false); // 禁止下载提示
|
|
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("intl.accept_languages", "nl");
|
|
options.AddUserProfilePreference("disable-popup-blocking", "true");
|
|
options.AddUserProfilePreference("disable-popup-blocking", "true");
|
|
options.AddUserProfilePreference("safebrowsing.enabled", true);
|
|
options.AddUserProfilePreference("safebrowsing.enabled", true);
|
|
@@ -935,7 +1202,7 @@ namespace wispro.sp.utility
|
|
//btnDownload.Click();
|
|
//btnDownload.Click();
|
|
|
|
|
|
string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
|
|
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删除下载记录");
|
|
Log($"{DateTime.Now}\t删除下载记录");
|