瀏覽代碼

修改为使用selenium抓取绩效数据

luocaiyang 2 年之前
父節點
當前提交
2afbf30f80

+ 7 - 1
wispro.sp.api/Controllers/PerformanceItemController.cs

@@ -2346,7 +2346,7 @@ namespace wispro.sp.api.Controllers
                         spDb.SaveChanges();
                         
                         //等级核算案件统计
-                        _StatisticsLevelCount(calMonth.Year, calMonth.Month, spDb);
+                         _StatisticsLevelCount(calMonth.Year, calMonth.Month, spDb);
 
                         #region 将待审核的申诉全部修改为已审核
                         var aList = spDb.AppealRecords.Where(a => a.State == 0).ToList();
@@ -3213,6 +3213,11 @@ namespace wispro.sp.api.Controllers
                     }
                 }
 
+                if(doPersons >0)
+                {
+                    //System.Diagnostics.Debug.WriteLine("");                
+                
+
                 foreach(var h in doList)
                 {
                     var temObj = retlist.FirstOrDefault(s=>s.StaffId == h.StaffId && s.Type == "新申请" && s.isReview == false);
@@ -3288,6 +3293,7 @@ namespace wispro.sp.api.Controllers
                     }
                     
                 }
+                }
                 #endregion
 
                 #region 新申请审核

+ 6 - 0
wispro.sp.api/Job/ImportReportJob.cs

@@ -1,6 +1,7 @@
 using DynamicExpresso;
 using Microsoft.Data.SqlClient;
 using Microsoft.Extensions.DependencyInjection;
+using NPOI.SS.Formula.Functions;
 using Quartz;
 using System;
 using System.Collections.Generic;
@@ -137,6 +138,11 @@ namespace wispro.sp.api.Job
 
         private Task InputPerformanctItem(CalMonth calMonth, bool isFirstOAFile, DataTable dt)
         {
+            if(dt == null)
+            {
+                return Task.CompletedTask;
+            }
+
             #region 删除重复行
             DataTable temdt = new DataTable();
             foreach (DataColumn col in dt.Columns)

+ 1 - 1
wispro.sp.api/Job/UpdateJXDataFromIPEasyJob.cs

@@ -500,7 +500,7 @@ namespace wispro.sp.api.Job
             StreamWriter sw = File.AppendText("c:\\temp\\log.txt");
             sw.WriteLine($"{strMessage}");
             sw.Flush();
-        sw.Close();
+            sw.Close();
             sw.Dispose();
         }
     }

+ 3 - 6
wispro.sp.api/appsettings.json

@@ -26,17 +26,14 @@
     "Issuer": "http://localhost:39476"
   },
   "IPEasySetting": {
-    "ipEeasyApi": "http://47.106.221.167:8081",
-    "ConnectionStrings": "Data Source=(local);Initial Catalog=IPEasy;User ID=sa;Password=Lqftiu807005",
     "DownloadFileSavePath": "c:\\temp",
-    "isHeadless": "true",
+    "isHeadless": "false",
     "Account": "caiyangl",
     "Password": "j)wx*lier*@3",
-    "ChormeDriverPath": "D:\\source\\repos\\StaffPerformance\\packages\\ChormeDriver\\100.0.4896.60",
-    "ScheduleSetting": "20 50 14 1 * ? *",
+    "ChormeDriverPath": "D:\\source\\repos\\StaffPerformance\\packages\\ChormeDriver\\110.0.5481.77",
+    "ScheduleSetting": "00 55 15 16 * ? *",
     "IPEasyWeb": "http://47.106.221.167/Login.aspx"
   },
-
   "MailSetting": {
     "Server": "smtp.exmail.qq.com",
     "Port": "465",

+ 42 - 5
wispro.sp.utility/IPEasyUtility.cs

@@ -2,9 +2,11 @@
 using System.Data;
 using System.Diagnostics;
 using System.Dynamic;
+using System.IO;
 using System.Linq;
 using OpenQA.Selenium;
 using OpenQA.Selenium.Chrome;
+using OpenQA.Selenium.Support.Extensions;
 
 namespace wispro.sp.utility
 {
@@ -95,6 +97,15 @@ namespace wispro.sp.utility
             }
         }
 
+        private static void Log(string strMessage)
+        {
+            StreamWriter sw = File.AppendText("c:\\temp\\log.txt");
+            sw.WriteLine($"{strMessage}");
+            sw.Flush();
+            sw.Close();
+            sw.Dispose();
+        }
+
         /// <summary>
         /// 根据报表名称导出报表
         /// </summary>
@@ -102,6 +113,7 @@ namespace wispro.sp.utility
         /// <param name="isModifyDate">是否手动修改日期范围</param>
         public static DataTable DownloadReport(string ReportName,bool isModifyDate)
         {
+            Log($"{DateTime.Now}\t开始下载:{ReportName}");
             DataTable retDatatable;
             string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
             bool isheadless =  (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
@@ -118,15 +130,18 @@ namespace wispro.sp.utility
             {
                 options.AddArgument("headless");
             }
-
+            Log($"{DateTime.Now}\t开始启动Chrome");
             using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
             {
                 try
                 {
+                    Log($"{DateTime.Now}\tIWebDriver配置");
+                    driver.Manage().Window.Maximize();
                     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"));
 
                     //输入用户名和密码
@@ -134,26 +149,38 @@ namespace wispro.sp.utility
                     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();
 
                     //点击顶部菜单栏中的报表管理菜单
-                    driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9")).Click();
+                    Log($"{DateTime.Now}\t点击顶部菜单栏中的报表管理菜单");
+                    var reportMenu = driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9"));
+                    driver.ExecuteJavaScript("arguments[0].click();", reportMenu);
 
                     //点击左侧 自定义报表 菜单
-                    driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b")).Click();
-
+                    Log($"{DateTime.Now}\t点击左侧 自定义报表 菜单");
+                    var customerReportMenu = driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b"));
+                    driver.ExecuteJavaScript("arguments[0].click();", customerReportMenu);
+                    
                     //切换到自定义报表Frame
+                    Log($"{DateTime.Now}\t切换到自定义报表Frame");
                     driver.SwitchTo().Frame(1);
 
+                    Log($"{DateTime.Now}\t开始搜索报告");
                     var inputSearch = driver.FindElement(By.Id("customizedList_TxtSheetSearchKey"));
 
+                    Log($"{DateTime.Now}\t在搜索框中输入报告名称");
                     inputSearch.SendKeys(ReportName);
+
+                    Log($"{DateTime.Now}\t点击搜索按钮");
                     var btnSearch = driver.FindElement(By.ClassName("btn-search"));
                     btnSearch.Click();
 
+                    Log($"{DateTime.Now}\t选中报告");
                     var reportRecord = driver.FindElement(By.XPath($"//td[contains(text(),'{ReportName}')]"));
                     reportRecord.Click();
 
@@ -161,6 +188,7 @@ namespace wispro.sp.utility
 
                     if (isModifyDate)
                     {
+                        Log($"{DateTime.Now}\t输入报告时间");
                         var btnEdit = driver.FindElement(By.ClassName("edit"));
                         btnEdit.Click();
                         System.Threading.Thread.Sleep(500);
@@ -191,17 +219,20 @@ namespace wispro.sp.utility
 
                     }
 
+                    Log($"{DateTime.Now}\t点击导出Excel链接");
                     var linkExport = driver.FindElement(By.XPath("//a[contains(@onclick,'-') and @class='tbexcel']"));
                     linkExport.Click();
 
 
                     //切换到弹出的导出报表窗口,点击导出按钮
+                    Log($"{DateTime.Now}\t切换到弹出的导出报表窗口,点击导出按钮");
                     driver.SwitchTo().DefaultContent();
                     var ihg_export = driver.FindElement(By.Name("ihg_export"));
                     driver.SwitchTo().Frame(ihg_export);
                     driver.FindElement(By.Id("btnSubmit")).Click();
-                    
+
                     //切换到弹出的下载报表界面,点击下载按钮
+                    Log($"{DateTime.Now}\t切换到弹出的下载报表界面,点击下载按钮");
                     System.Threading.Thread.Sleep(3000);
                     driver.SwitchTo().DefaultContent();
                     var frameDownload = driver.FindElement(By.Name("DownloadList"));
@@ -217,6 +248,7 @@ namespace wispro.sp.utility
                         strStatus = tdStatus.Text;
                     }
 
+                    Log($"{DateTime.Now}\t点击下载按钮下载文档");
                     firstTr = driver.FindElement(By.TagName("tr"));
                     firstTr.FindElement(By.XPath("//td/a[@title='下载']")).Click();
                     //System.Threading.Thread.Sleep(5000);
@@ -247,6 +279,7 @@ namespace wispro.sp.utility
                     }
 
                     //删除下载记录
+                    Log($"{DateTime.Now}\t删除下载记录");
                     firstTr = driver.FindElement(By.TagName("tr"));
                     firstTr.FindElement(By.XPath("//td/a[@title='删除']")).Click();
 
@@ -256,15 +289,19 @@ namespace wispro.sp.utility
                 }
                 catch (Exception ex)
                 {
+                    Log(ex.ToString());
                     throw new Exception(ex.Message, ex);
                 }
                 finally
                 {
+                    Log("关闭Chrome");
                     killChromProcess();
                 }
 
 
             }
+
+            Log($"{DateTime.Now}\t返回数据");
             return retDatatable;
         }
 

+ 1 - 1
wispro.sp.winClient/Form1.cs

@@ -958,7 +958,7 @@ namespace wispro.sp.winClient
             return retStr;
         }
 
-        string strAPIBaseUri =   "http://1.116.113.26:81";// "http://47.106.221.167:8081"; //  "http://localhost:39476";// 
+        string strAPIBaseUri = "http://1.116.113.26:81";//"http://localhost:8080"; // "http://localhost:39476";//   "http://47.106.221.167:8081"; //  
 
         userToken Token;