|
@@ -7,8 +7,10 @@ using System.Dynamic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Threading;
|
|
|
+using NPOI.HPSF;
|
|
|
using OpenQA.Selenium;
|
|
|
using OpenQA.Selenium.Chrome;
|
|
|
+using OpenQA.Selenium.Interactions;
|
|
|
using OpenQA.Selenium.Support.Extensions;
|
|
|
using OpenQA.Selenium.Support.UI;
|
|
|
|
|
@@ -20,30 +22,399 @@ 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)
|
|
|
+ {
|
|
|
+ DateTime startTime = DateTime.Now;
|
|
|
+ while (DateTime.Now - startTime < timeout)
|
|
|
+ {
|
|
|
+ string filePath = Path.Combine(downloadDir, fileName);
|
|
|
+ if (File.Exists(filePath))
|
|
|
+ {
|
|
|
+ // 检查文件是否完成写入(文件大小是否稳定)
|
|
|
+ long previousSize = 0;
|
|
|
+ long currentSize = new FileInfo(filePath).Length;
|
|
|
+ while (previousSize != currentSize)
|
|
|
+ {
|
|
|
+ Thread.Sleep(1000); // 等待一段时间
|
|
|
+ previousSize = currentSize;
|
|
|
+ currentSize = new FileInfo(filePath).Length;
|
|
|
+ }
|
|
|
+ return true; // 文件下载完成
|
|
|
+ }
|
|
|
+ Thread.Sleep(1000); // 等待文件出现
|
|
|
+ }
|
|
|
+ return false; // 超时,文件未下载完成
|
|
|
+ }
|
|
|
|
|
|
- public static void DownloadReport(string strId,string filename)
|
|
|
+ static IWebElement waitGetElementById(WebDriverWait wait,string id,IWebElement parentElement =null)
|
|
|
+ {
|
|
|
+ return wait.Until((d) =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (parentElement == null)
|
|
|
+ {
|
|
|
+ return d.FindElement(By.Id(id));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return parentElement.FindElement(By.Id(id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ static IWebElement waitGetElementByName(WebDriverWait wait, string name, IWebElement parentElement = null)
|
|
|
+ {
|
|
|
+ return wait.Until((d) =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (parentElement == null)
|
|
|
+ {
|
|
|
+ return d.FindElement(By.Name(name));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return parentElement.FindElement(By.Name(name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ static IWebElement waitGetElementByTagName(WebDriverWait wait, string name, IWebElement parentElement = null)
|
|
|
+ {
|
|
|
+ return wait.Until((d) =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (parentElement == null)
|
|
|
+ {
|
|
|
+ return d.FindElement(By.TagName(name));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return parentElement.FindElement(By.TagName(name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ static ReadOnlyCollection<IWebElement> waitGetElementsByName(WebDriverWait wait, string name, IWebElement parentElement = null)
|
|
|
+ {
|
|
|
+ return wait.Until((d) =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (parentElement == null)
|
|
|
+ {
|
|
|
+ return d.FindElements(By.Name(name));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return parentElement.FindElements(By.Name(name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ static ReadOnlyCollection<IWebElement> waitGetElementsByTagName(WebDriverWait wait, string name, IWebElement parentElement = null)
|
|
|
{
|
|
|
+ return wait.Until((d) =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (parentElement == null)
|
|
|
+ {
|
|
|
+ return d.FindElements(By.TagName(name));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return parentElement.FindElements(By.TagName(name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ static IWebElement waitGetElementByClassName(WebDriverWait wait, string name, IWebElement parentElement = null)
|
|
|
+ {
|
|
|
+ return wait.Until((d) =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (parentElement == null)
|
|
|
+ {
|
|
|
+ return d.FindElement(By.ClassName(name));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return parentElement.FindElement(By.ClassName(name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取指定案号的专利申请案的基本信息和初稿文件、定稿文件和第一次返稿文件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="caseNo"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="Exception"></exception>
|
|
|
+ public static dynamic DownloadCaseFiles(string caseNo)
|
|
|
+ {
|
|
|
+ dynamic retObject = new ExpandoObject();
|
|
|
+
|
|
|
+ retObject.CaseNo = caseNo.Trim();
|
|
|
|
|
|
using (IWebDriver driver = CreateChromeDriver())
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(50));
|
|
|
+ driver.Manage().Window.Maximize();
|
|
|
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
|
|
|
- driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
|
|
|
+ driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
|
|
|
+ Login(driver, wait);
|
|
|
|
|
|
- //进入登录界面
|
|
|
- driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
|
|
|
+ //点击顶部菜单栏中的案件管理菜单
|
|
|
+ IWebElement linkCaseManager = waitGetElementByName(wait, "71A7CC35-F597-40E1-9FEF-BE622A3A3B63");
|
|
|
|
|
|
- //输入用户名和密码
|
|
|
-
|
|
|
- driver.FindElement(By.Id("txtUser")).SendKeys(Account);
|
|
|
- driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
|
|
|
+ linkCaseManager.Click();
|
|
|
|
|
|
- //点击登录按钮
|
|
|
- driver.FindElement(By.Id("btnLogin")).Click();
|
|
|
+ IWebElement linkCaseSearch = wait.Until((d) =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return driver.FindElement(By.LinkText("案件查询"));
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- //关闭提示遮罩层
|
|
|
- driver.FindElement(By.Id("jpwClose")).Click();
|
|
|
+ });
|
|
|
+
|
|
|
+ driver.ExecuteJavaScript("arguments[0].click();", linkCaseSearch);
|
|
|
+ //linkCaseSearch.Click();
|
|
|
+
|
|
|
+ IWebElement patentSearch = waitGetElementByName(wait, "4df7eee3-426f-4ce5-9204-34ccb0fd27f7");
|
|
|
+ driver.ExecuteJavaScript("arguments[0].click();", patentSearch);
|
|
|
+ //patentSearch.Click();
|
|
|
+
|
|
|
+ driver.SwitchTo().Frame(1);
|
|
|
+
|
|
|
+ var inputSearch = waitGetElementById(wait, "case_volume");//driver.FindElement(By.Id("case_volume"));
|
|
|
+ inputSearch.SendKeys(caseNo.Trim());
|
|
|
+
|
|
|
+ var btnSearch = waitGetElementById(wait, "btn_Search");// driver.FindElement(By.Id("btn_Search"));
|
|
|
+ btnSearch.Click();
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var caseLink = driver.FindElement(By.XPath($"//a[contains(text(),'{caseNo}')]"));
|
|
|
+ caseLink.Click();
|
|
|
+ }
|
|
|
+ catch(Exception ex)
|
|
|
+ {
|
|
|
+ if(ex.Message.Contains("no such element: Unable to locate element"))
|
|
|
+ {
|
|
|
+ return retObject;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ System.Threading.Thread.Sleep(1000);
|
|
|
+
|
|
|
+ driver.SwitchTo().ParentFrame();
|
|
|
+ driver.SwitchTo().Frame(2);
|
|
|
+ //案件名称
|
|
|
+ retObject.CaseName = waitGetElementById(wait, "p_case_info__case_name").GetAttribute("value");
|
|
|
+ //我方文号
|
|
|
+ retObject.CaseNo = waitGetElementById(wait, "p_case_info__case_volume").GetAttribute("value");
|
|
|
+ //案件类型
|
|
|
+ retObject.CaseType = waitGetElementById(wait, "p_case_info__case_type_id").GetAttribute("value");
|
|
|
+ //申请类型
|
|
|
+ var selectElement = waitGetElementById(wait, "p_case_info__apply_type_id");
|
|
|
+ retObject.ApplicationType = new SelectElement(selectElement).SelectedOption.Text;
|
|
|
+ //客户
|
|
|
+ retObject.Customer = waitGetElementById(wait, "p_case_info__customer_id").GetAttribute("value").Replace("(null)", "");
|
|
|
+ //申请国家
|
|
|
+ retObject.Country = waitGetElementById(wait, "p_case_info__country_id").GetAttribute("value");
|
|
|
+
|
|
|
+ var table = waitGetElementById(wait, "table_ProcList");
|
|
|
+ var rows = waitGetElementsByTagName(wait, "tr", table);// table.FindElements(By.TagName("tr"));
|
|
|
+ foreach (var row in rows)
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ driver.SwitchTo().ParentFrame().SwitchTo().Frame(0);
|
|
|
+ //案件阶段
|
|
|
+ var caseStage = waitGetElementById(wait, "select2-p_proc_info__review_stage-container");
|
|
|
+ if (caseStage != null && caseStage.Text != "--请选择--")
|
|
|
+ {
|
|
|
+ retObject.CaseStage = caseStage.Text;
|
|
|
+ }
|
|
|
+
|
|
|
+ //内部期限
|
|
|
+ retObject.InternalDate = waitGetElementById(wait, "p_proc_info__int_due_date").GetAttribute("value");
|
|
|
+
|
|
|
+ //处理事项系数
|
|
|
+ var DICoe = waitGetElementById(wait, "p_proc_info__proc_coefficient_id");
|
|
|
+ retObject.DoItemCoefficient = new SelectElement(DICoe).SelectedOption.Text;
|
|
|
+ if (retObject.DoItemCoefficient == "请选择")
|
|
|
+ {
|
|
|
+ retObject.DoItemCoefficient = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ retObject.DoPersons = waitGetElementById(wait, "pic_list").GetAttribute("value"); //处理人
|
|
|
+ retObject.Reviewer = waitGetElementById(wait, "rev_list").GetAttribute("value"); //核稿人
|
|
|
+
|
|
|
+ //第一次初稿日
|
|
|
+ retObject.FirstDraftDate = waitGetElementById(wait, "p_proc_info__first_doc_date").GetAttribute("value");
|
|
|
+ //客户期限
|
|
|
+ retObject.CustomerLimitDate = waitGetElementById(wait, "p_proc_info__cus_due_date").GetAttribute("value");
|
|
|
+ //配案日
|
|
|
+ retObject.CaseAssigmentDate = waitGetElementById(wait, "p_proc_info__allocate_date").GetAttribute("value");
|
|
|
+ //返稿日
|
|
|
+ retObject.ReturnDate = waitGetElementById(wait, "p_proc_info__back_date").GetAttribute("value");
|
|
|
+ //定稿日
|
|
|
+ retObject.FinalizationDate = waitGetElementById(wait, "p_proc_info__finish_doc_date").GetAttribute("value");
|
|
|
+
|
|
|
+ var lifile = driver.FindElement(By.Id("lifile"));
|
|
|
+ driver.ExecuteJavaScript("arguments[0].click();", lifile);
|
|
|
+
|
|
|
+
|
|
|
+ //添加从文件清单中获取“新申请第一次内审 (初稿)、 新申请第一次返稿(第一次发客户文档)、新申请文档(定稿文档)”
|
|
|
+ var table_filelist = waitGetElementById(wait, "table_filelist");
|
|
|
+ //定稿文件
|
|
|
+ Download(retObject, driver, wait, table_filelist, "新申请文档");
|
|
|
+ //新申请第一次返稿文件
|
|
|
+ Download(retObject, driver, wait, table_filelist, "新申请第一次返稿");
|
|
|
+
|
|
|
+ //初稿文件
|
|
|
+ waitGetElementById(wait, "draftfiletoggle").Click();
|
|
|
+ var table_draffilelist = waitGetElementById(wait, "table_draftfilelist");// driver.FindElement(By.Id("table_draftfilelist"));
|
|
|
+ Download(retObject, driver, wait, table_draffilelist, "新申请第一次内审");
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ throw new Exception(ex.Message, ex);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ driver.Quit();
|
|
|
+ killChromProcess();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return retObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void Download(dynamic retObject, IWebDriver driver, WebDriverWait wait, IWebElement table_filelist, string fileType)
|
|
|
+ {
|
|
|
+ var finallyFile = table_filelist.FindElement(By.XPath($"//td[@colname='file_desc'][normalize-space()='{fileType}']"));
|
|
|
+ var tdfileName = wait.Until((d) =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return finallyFile.FindElement(By.XPath("preceding-sibling::*[2]"));
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ string fileName = tdfileName.Text;
|
|
|
+ while (string.IsNullOrEmpty(fileName))
|
|
|
+ {
|
|
|
+ System.Threading.Thread.Sleep(100);
|
|
|
+ fileName = tdfileName.Text;
|
|
|
+ }
|
|
|
+
|
|
|
+ string filePath = System.IO.Path.Combine(strFileSavePath, fileName);
|
|
|
+ if (System.IO.File.Exists(filePath))
|
|
|
+ {
|
|
|
+ System.IO.File.Delete(filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (fileType)
|
|
|
+ {
|
|
|
+ case "新申请文档":
|
|
|
+ retObject.finallyFile = filePath; break;
|
|
|
+ case "新申请第一次返稿":
|
|
|
+ retObject.firstReturnFile = filePath;
|
|
|
+ break;
|
|
|
+ case "新申请第一次内审":
|
|
|
+ retObject.draftFile = filePath;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void Login(IWebDriver driver, WebDriverWait wait)
|
|
|
+ {
|
|
|
+ //进入登录界面
|
|
|
+ driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
|
|
|
+
|
|
|
+ //输入用户名和密码
|
|
|
+ waitGetElementById(wait, "txtUser").SendKeys(Account);
|
|
|
+ waitGetElementById(wait, "txtPwd").SendKeys(Password);
|
|
|
+
|
|
|
+ //点击登录按钮
|
|
|
+ waitGetElementById(wait, "btnLogin").Click();
|
|
|
+
|
|
|
+ //关闭提示遮罩层
|
|
|
+ waitGetElementById(wait, "jpwClose").Click();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void DownloadReport(string strId,string filename)
|
|
|
+ {
|
|
|
+
|
|
|
+ using (IWebDriver driver = CreateChromeDriver())
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(50));
|
|
|
+ driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
|
|
|
+ driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
|
|
|
+
|
|
|
+ Login(driver, wait);
|
|
|
|
|
|
//点击顶部菜单栏中的报表管理菜单
|
|
|
driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9")).Click();
|
|
@@ -109,6 +480,9 @@ namespace wispro.sp.utility
|
|
|
|
|
|
var options = new OpenQA.Selenium.Chrome.ChromeOptions();
|
|
|
|
|
|
+ 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);
|
|
|
options.AddUserProfilePreference("intl.accept_languages", "nl");
|
|
|
options.AddUserProfilePreference("disable-popup-blocking", "true");
|
|
@@ -136,6 +510,7 @@ namespace wispro.sp.utility
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+
|
|
|
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
|
|
|
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
|
|
|
//driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(100);
|
|
@@ -146,23 +521,6 @@ namespace wispro.sp.utility
|
|
|
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
|
|
|
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
|
|
|
|
|
|
- //进入登录界面
|
|
|
- Log($"{DateTime.Now}\t开始进入登录界面");
|
|
|
- driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
|
|
|
-
|
|
|
- //输入用户名和密码
|
|
|
-
|
|
|
- driver.FindElement(By.Id("txtUser")).SendKeys(Account);
|
|
|
- driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
|
|
|
-
|
|
|
- //点击登录按钮
|
|
|
- Log($"{DateTime.Now}\t开始点击登录按钮");
|
|
|
- driver.FindElement(By.Id("btnLogin")).Click();
|
|
|
-
|
|
|
- //关闭提示遮罩层
|
|
|
- Log($"{DateTime.Now}\t关闭提示遮罩层");
|
|
|
- driver.FindElement(By.Id("jpwClose")).Click();
|
|
|
-
|
|
|
//点击顶部菜单栏中的报表管理菜单
|
|
|
Log($"{DateTime.Now}\t点击顶部菜单栏中的报表管理菜单");
|
|
|
var reportMenu = driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9"));
|
|
@@ -623,6 +981,7 @@ namespace wispro.sp.utility
|
|
|
retObject.FinalizationDate = p_proc_finish_doc_date.GetAttribute("value"); //定稿日
|
|
|
retObject.ReturnDate = driver.FindElement(By.Id("p_proc_info__back_date")).GetAttribute("value"); //返稿日
|
|
|
retObject.Reviewer = driver.FindElement(By.Id("p_proc_info__revise_user")).GetAttribute("value"); //核稿人
|
|
|
+
|
|
|
retObject.DoItemCoefficient = driver.FindElement(By.Id("p_proc_info__proc_coefficient")).GetAttribute("value"); //处理事项系数
|
|
|
retObject.WordCount = driver.FindElement(By.Id("p_proc_info__translate_count")).GetAttribute("value"); //翻译字数
|
|
|
|