Browse Source

由于维德系统服务器不能安装API,修改使用Selenium从维德系统中获取数据

luocaiyang 2 years ago
parent
commit
3e99f31de9

+ 1 - 0
wispro.sp.api/Controllers/AttachFilesController.cs

@@ -106,6 +106,7 @@ namespace wispro.sp.api.Controllers
             }
         }
         [HttpPost]
+        [DisableRequestSizeLimit]
         public async Task<ActionResult<AttachFile>> PostFile(
         [FromForm] IEnumerable<IFormFile> files)
         {

+ 2 - 5
wispro.sp.api/Controllers/PerformanceItemController.cs

@@ -1016,10 +1016,6 @@ namespace wispro.sp.api.Controllers
                 {
                     try
                     {
-                        if(item.CaseNo == "S2216480-稳定性分析")
-                        {
-                            System.Diagnostics.Debug.WriteLine("");
-                        }
                         Utility.Utility.CalBasePoint(item, rules);
 
                         if (item.BasePoint > 0)
@@ -2622,8 +2618,9 @@ namespace wispro.sp.api.Controllers
 
                     if (item.ReviewerId != null && item.BasePoint.HasValue)
                     {
+                        
                         System.Diagnostics.Debug.WriteLine($"{item.ReviewerId}");
-                        var jxList = _calItemJX( verifyCoefficients, item, new spDbContext());
+                        var jxList = new spDbContext().StaffStatistics.Where<StaffStatistics>(s => s.ItemId == item.Id).ToList();//_calItemJX( verifyCoefficients, item, new spDbContext());
 
                         row["核稿系数"] = "";
                         var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);

+ 46 - 15
wispro.sp.api/Job/ImportReportJob.cs

@@ -193,6 +193,7 @@ namespace wispro.sp.api.Job
                 }
 
                 System.Diagnostics.Debug.WriteLine(strDebug);
+
             }
 
             return Task.CompletedTask;
@@ -208,7 +209,7 @@ namespace wispro.sp.api.Job
             try
             {
                 Utility.Utility.CalBasePoint(item, rules);
-                var ret= new Controllers.PerformanceItemController(spDb,new Services.FileTaskCacheService()).New(item);
+                var ret= new Controllers.PerformanceItemController(new spDbContext(),new Services.FileTaskCacheService()).New(item);
                 if (ret.Success == false)
                 {
                     System.Diagnostics.Debug.WriteLine(ret.ErrorMessage);
@@ -631,25 +632,55 @@ namespace wispro.sp.api.Job
 
         private DataTable GetDataFromIPEasy(string ReportName, bool isModifyDate)
         {
-            HttpClient http = new HttpClient();
-            var bytRespon = http.GetAsync($"{ConfigHelper.GetSectionValue("IPEasySetting:ipEeasyApi")}/api/ipEasy/GetDataFromIPEasy?ReportName={ReportName}&isModifyDate={isModifyDate}").Result;
-            
-            if (bytRespon.IsSuccessStatusCode)
+            try
             {
-                string result = bytRespon.Content.ReadAsStringAsync().Result.Replace("\"", string.Empty);
-                byte[] data = Convert.FromBase64String(result);
-                //byte[] data = bytRespon.Content.ReadAsByteArrayAsync().Result;//Here is the problem
-                XmlSerializer serializer = new XmlSerializer(typeof(System.Data.DataTable));
-                MemoryStream memory = new MemoryStream(data);
-                DataTable dt = (DataTable)serializer.Deserialize(memory);
-
-                return dt;
+                return wispro.sp.utility.IPEasyUtility.DownloadReport(ReportName, isModifyDate);
             }
-            else
-            {
+            catch {
                 return null;
             }
+            #region 利用维德系统服务器上的API获取
+        //    int iTry = 0;
 
+        //tryAgain:
+        //    try
+        //    {
+                
+        //        HttpClient http = new HttpClient();
+        //        var bytRespon = http.GetAsync($"{ConfigHelper.GetSectionValue("IPEasySetting:ipEeasyApi")}/api/ipEasy/GetDataFromIPEasy?ReportName={ReportName}&isModifyDate={isModifyDate}").Result;
+
+        //        if (bytRespon.IsSuccessStatusCode)
+        //        {
+        //            string result = bytRespon.Content.ReadAsStringAsync().Result.Replace("\"", string.Empty);
+        //            byte[] data = Convert.FromBase64String(result);
+        //            //byte[] data = bytRespon.Content.ReadAsByteArrayAsync().Result;//Here is the problem
+        //            XmlSerializer serializer = new XmlSerializer(typeof(System.Data.DataTable));
+        //            MemoryStream memory = new MemoryStream(data);
+        //            DataTable dt = (DataTable)serializer.Deserialize(memory);
+
+        //            return dt;
+        //        }
+        //        else
+        //        {
+        //            if (iTry < 3)
+        //            {
+        //                iTry++;
+        //                goto tryAgain;
+        //            }
+                    
+        //        }
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        if (iTry < 3)
+        //        {
+        //            iTry++;
+        //            goto tryAgain;
+        //        }
+        //    }
+
+        //    return null;
+            #endregion
 
 
             #region old code 从维德数据库中直接读取

File diff suppressed because it is too large
+ 7 - 7
wispro.sp.api/Job/InvalidDataMessageJob.cs


+ 41 - 38
wispro.sp.api/Job/UpdateJXDataFromIPEasyJob.cs

@@ -24,44 +24,47 @@ namespace wispro.sp.api.Job
        
         public dynamic  GetItemFromIPEasyDB(PerformanceItem Item, spDbContext spDb)
         {
-            HttpClient http = new HttpClient();
-
-            //http.GetFromJsonAsync($"{ConfigHelper.GetSectionValue("IPEasySetting:ipEeasyApi")}/api/ipEasy/GetItemFromIPEasyDB?CaseNo={Item.CaseNo}&DoItem={Item.DoItem}").Wait();
-            var response =  http.GetFromJsonAsync<Object>($"{ConfigHelper.GetSectionValue("IPEasySetting:ipEeasyApi")}/api/ipEasy/GetItemFromIPEasyDB?CaseNo={Item.CaseNo}&DoItem={Item.DoItem}").Result;
-
-            
-            dynamic retItem = new ExpandoObject();
-
-            
-            
-            JsonElement json = ((System.Text.Json.JsonElement)response);
-            
-            retItem.CaseNo = json.GetProperty("CaseNo").GetString();
-            retItem.ApplicationType = json.GetProperty("ApplicationType").GetString();
-            retItem.BusinessType = json.GetProperty("BusinessType").GetString();
-            retItem.DoItem = json.GetProperty("DoItem").GetString();
-            retItem.CaseStage = json.GetProperty("CaseStage").GetString();
-            retItem.CaseCoefficient = json.GetProperty("CaseCoefficient").GetString();
-            retItem.DoItemCoefficient = json.GetProperty("DoItemCoefficient").GetString();
-            retItem.DoPersons = json.GetProperty("DoPersons").GetString();
-            retItem.Reviewer = json.GetProperty("Reviewer").GetString();
-            retItem.CustomerName = json.GetProperty("CustomerName").GetString();
-            retItem.FinishedDate = json.GetProperty("FinishedDate").GetString();
-            retItem.WordCount = json.GetProperty("WordCount").GetString();
-            retItem.ReturnDate = json.GetProperty("ReturnDate").GetString();
-            retItem.CaseType = json.GetProperty("CaseType").GetString();
-            retItem.CaseState = json.GetProperty("CaseState").GetString();
-            retItem.DoItemMemo = json.GetProperty("DoItemMemo").GetString();
-            retItem.DoItemState = json.GetProperty("DoItemState").GetString();
-            retItem.CaseName = json.GetProperty("CaseName").GetString();
-            retItem.EntrustingDate = json.GetProperty("EntrustingDate").GetString();
-            retItem.CustomerLimitDate = json.GetProperty("CustomerLimitDate").GetString();
-            retItem.InternalDate = json.GetProperty("InternalDate").GetString();
-            retItem.FirstDraftDate = json.GetProperty("FirstDraftDate").GetString();
-            retItem.CaseMemo = json.GetProperty("CaseMemo").GetString();
-            retItem.FinalizationDate = json.GetProperty("FinalizationDate").GetString();
-
-            return retItem;
+            return wispro.sp.utility.IPEasyUtility.GetPerformanceRecord(Item.CaseNo, Item.DoItem,Item.CaseStage);
+            #region 从维德系统服务上的API获取数据
+            //HttpClient http = new HttpClient();
+
+            ////http.GetFromJsonAsync($"{ConfigHelper.GetSectionValue("IPEasySetting:ipEeasyApi")}/api/ipEasy/GetItemFromIPEasyDB?CaseNo={Item.CaseNo}&DoItem={Item.DoItem}").Wait();
+            //var response =  http.GetFromJsonAsync<Object>($"{ConfigHelper.GetSectionValue("IPEasySetting:ipEeasyApi")}/api/ipEasy/GetItemFromIPEasyDB?CaseNo={Item.CaseNo}&DoItem={Item.DoItem}").Result;
+
+
+            //dynamic retItem = new ExpandoObject();
+
+
+
+            //JsonElement json = ((System.Text.Json.JsonElement)response);
+
+            //retItem.CaseNo = json.GetProperty("CaseNo").GetString();
+            //retItem.ApplicationType = json.GetProperty("ApplicationType").GetString();
+            //retItem.BusinessType = json.GetProperty("BusinessType").GetString();
+            //retItem.DoItem = json.GetProperty("DoItem").GetString();
+            //retItem.CaseStage = json.GetProperty("CaseStage").GetString();
+            //retItem.CaseCoefficient = json.GetProperty("CaseCoefficient").GetString();
+            //retItem.DoItemCoefficient = json.GetProperty("DoItemCoefficient").GetString();
+            //retItem.DoPersons = json.GetProperty("DoPersons").GetString();
+            //retItem.Reviewer = json.GetProperty("Reviewer").GetString();
+            //retItem.CustomerName = json.GetProperty("CustomerName").GetString();
+            //retItem.FinishedDate = json.GetProperty("FinishedDate").GetString();
+            //retItem.WordCount = json.GetProperty("WordCount").GetString();
+            //retItem.ReturnDate = json.GetProperty("ReturnDate").GetString();
+            //retItem.CaseType = json.GetProperty("CaseType").GetString();
+            //retItem.CaseState = json.GetProperty("CaseState").GetString();
+            //retItem.DoItemMemo = json.GetProperty("DoItemMemo").GetString();
+            //retItem.DoItemState = json.GetProperty("DoItemState").GetString();
+            //retItem.CaseName = json.GetProperty("CaseName").GetString();
+            //retItem.EntrustingDate = json.GetProperty("EntrustingDate").GetString();
+            //retItem.CustomerLimitDate = json.GetProperty("CustomerLimitDate").GetString();
+            //retItem.InternalDate = json.GetProperty("InternalDate").GetString();
+            //retItem.FirstDraftDate = json.GetProperty("FirstDraftDate").GetString();
+            //retItem.CaseMemo = json.GetProperty("CaseMemo").GetString();
+            //retItem.FinalizationDate = json.GetProperty("FinalizationDate").GetString();
+
+            //return retItem;
+            #endregion
 
             #region old code 直接从数据库中获取数据
             //dynamic retItem = new ExpandoObject();

+ 4 - 0
wispro.sp.api/Startup.cs

@@ -87,6 +87,10 @@ namespace wispro.sp.api
 
             services.AddMemoryCache();
 
+            services.Configure<IISServerOptions>(options => { 
+                options.MaxRequestBodySize = int.MaxValue;
+            });
+
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

+ 2 - 2
wispro.sp.api/appsettings.json

@@ -33,7 +33,7 @@
     "Account": "caiyangl",
     "Password": "j)wx*lier*@3",
     "ChormeDriverPath": "D:\\source\\repos\\StaffPerformance\\packages\\ChormeDriver\\100.0.4896.60",
-    "ScheduleSetting": "20 24 10 3 * ? *",
+    "ScheduleSetting": "20 50 14 1 * ? *",
     "IPEasyWeb": "http://47.106.221.167/Login.aspx"
   },
 
@@ -41,7 +41,7 @@
     "Server": "smtp.exmail.qq.com",
     "Port": "465",
     "Account": "luocaiyang@china-wispro.com",
-    "Password": "Lqftiu807005",
+    "Password": "Qj7eGb3ffQfJ3tpt",
     "mail": "luocaiyang@china-wispro.com"
   },
 

+ 14 - 0
wispro.sp.ipeasyApi/Controllers/ipEasyController.cs

@@ -345,7 +345,11 @@ namespace wispro.sp.ipeasyApi.Controllers
                         {
                             dt.Load(reader);
                         }
+
+						cmd.Dispose();
                     }
+					conn.Close();
+					conn.Dispose();
                 }
                 catch (Exception ex)
                 {
@@ -418,7 +422,12 @@ namespace wispro.sp.ipeasyApi.Controllers
                         {
                             dt.Load(reader);
                         }
+
+						cmd.Dispose();
                     }
+
+					conn.Close();
+					conn.Dispose();
                 }
                 catch (Exception ex)
                 {
@@ -585,7 +594,12 @@ namespace wispro.sp.ipeasyApi.Controllers
 
 
                         }
+
+						cmd.Dispose();
                     }
+
+					conn.Close();
+					conn.Dispose();
                 }
                 catch (Exception ex)
                 {

+ 6 - 1
wispro.sp.ipeasyApi/Program.cs

@@ -20,7 +20,12 @@ namespace wispro.sp.ipeasyApi
             Host.CreateDefaultBuilder(args)
                 .ConfigureWebHostDefaults(webBuilder =>
                 {
-                    webBuilder.UseStartup<Startup>();
+                    webBuilder.UseStartup<Startup>()
+                    .ConfigureKestrel((content, options) => {
+                        options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(500);
+                        options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(500);
+                    }
+                    );
                 });
     }
 }

+ 1 - 8
wispro.sp.ipeasyApi/Properties/launchSettings.json

@@ -9,14 +9,7 @@
     }
   },
   "profiles": {
-    "IIS Express": {
-      "commandName": "IISExpress",
-      "launchBrowser": true,
-      "launchUrl": "swagger",
-      "environmentVariables": {
-        "ASPNETCORE_ENVIRONMENT": "Development"
-      }
-    },
+    
     "wispro.sp.ipeasyApi": {
       "commandName": "Project",
       "dotnetRunMessages": "true",

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

@@ -7,7 +7,7 @@
     }
   },
   "IPEasySetting": {
-    "ConnectionStrings": "Data Source=(local);Initial Catalog=IPEasy;User ID=sa;Password=Lqftiu807005",
+    "ConnectionStrings": "Data Source=(local);Initial Catalog=IPEasy;User ID=sa;Password=Lqftiu807005;TimeOut=1",
     "DownloadFileSavePath": "c:\\temp",
     "isHeadless": "true",
     "Account": "caiyangl",

+ 39 - 4
wispro.sp.utility/IPEasyUtility.cs

@@ -100,8 +100,9 @@ namespace wispro.sp.utility
         /// </summary>
         /// <param name="ReportName">报告名称</param>
         /// <param name="isModifyDate">是否手动修改日期范围</param>
-        public static void DownloadReport(string ReportName,bool isModifyDate)
+        public static DataTable DownloadReport(string ReportName,bool isModifyDate)
         {
+            DataTable retDatatable;
             string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
             bool isheadless =  (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
             string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
@@ -199,13 +200,34 @@ namespace wispro.sp.utility
                     var ihg_export = driver.FindElement(By.Name("ihg_export"));
                     driver.SwitchTo().Frame(ihg_export);
                     driver.FindElement(By.Id("btnSubmit")).Click();
+                    
+                    //切换到弹出的下载报表界面,点击下载按钮
+                    System.Threading.Thread.Sleep(3000);
+                    driver.SwitchTo().DefaultContent();
+                    var frameDownload = driver.FindElement(By.Name("DownloadList"));
+                    driver.SwitchTo().Frame(frameDownload);
+                    var firstTr = driver.FindElement(By.TagName("tr"));
+                    var tdStatus = firstTr.FindElement(By.XPath("//td")).FindElement(By.XPath("following-sibling::td[4]"));
+                    string strStatus = tdStatus.Text;
+                    while (strStatus.Trim() != "导出成功!")
+                    {
+                        System.Threading.Thread.Sleep(5000);
+                        firstTr = driver.FindElement(By.TagName("tr"));
+                        tdStatus = firstTr.FindElement(By.XPath("//td")).FindElement(By.XPath("following-sibling::td[4]"));
+                        strStatus = tdStatus.Text;
+                    }
 
-                    string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
+                    firstTr = driver.FindElement(By.TagName("tr"));
+                    firstTr.FindElement(By.XPath("//td/a[@title='下载']")).Click();
+                    //System.Threading.Thread.Sleep(5000);
+                    //btnDownload.Click();
 
+                    string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
+                    
                     int iwaiting = 0;
                     while (true)
                     {
-
+                        
                         System.IO.FileInfo file = new System.IO.FileInfo(strFilePath.Replace("~", "_"));
                         if (!file.Exists || file.Length == 0)
                         {
@@ -223,6 +245,14 @@ namespace wispro.sp.utility
                             break;
                         }
                     }
+
+                    //删除下载记录
+                    firstTr = driver.FindElement(By.TagName("tr"));
+                    firstTr.FindElement(By.XPath("//td/a[@title='删除']")).Click();
+
+                    //System.IO.FileInfo file = new System.IO.FileInfo(strFilePath.Replace("~", "_"));
+                    retDatatable = NPOIExcel.ExcelToDataTable(strFilePath.Replace("~", "_"),true);
+                    System.IO.File.Delete(strFilePath.Replace("~", "_"));
                 }
                 catch (Exception ex)
                 {
@@ -232,7 +262,10 @@ namespace wispro.sp.utility
                 {
                     killChromProcess();
                 }
-        }
+
+
+            }
+            return retDatatable;
         }
 
         /// <summary>
@@ -429,6 +462,7 @@ namespace wispro.sp.utility
                                         retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text;   //处理事项完成日
                                         retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text;   //处理人
                                         retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text;   //处理事项备注
+                                        retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text;   //核稿人
 
                                         DoItemLink.Click();
                                         break;
@@ -445,6 +479,7 @@ namespace wispro.sp.utility
                                 retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text;   //处理事项完成日
                                 retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text;   //处理人
                                 retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text;   //处理事项备注
+                                retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text;   //核稿人
 
 
                                 DoItemLink.Click();

+ 12 - 2
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://47.106.221.167:8081"; //  "http://localhost:39476";// 
 
         userToken Token;
 
@@ -1357,9 +1357,19 @@ namespace wispro.sp.winClient
 
         private async Task<dynamic> GetPerformanceItemFromIPEasy()
         {
+            string CaseNo = "PADE1510724";
+            DataTable retdt = wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--上个月递交完成案件", true);
+            DataTable retdt1 = wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--中国一次OA授权表", true);
+            DataTable retdt2 = wispro.sp.utility.IPEasyUtility.DownloadReport("每月绩效统计--发客户超过一个月未完成案件", false);
+            dynamic caseInfo = wispro.sp.utility.IPEasyUtility.GetPerformanceRecord(CaseNo, "处理审查意见");// wispro.sp.utility.IPEasyUtility.GetCaseInfo(CaseNo);
+            return caseInfo;
+
+            
+            
+
             HttpClient http = new HttpClient();
 
-            var response = http.GetFromJsonAsync<Object>($"http://localhost:22468/api/ipEasy/GetItemFromIPEasyDB?CaseNo=PADE1510724&DoItem=处理审查意见").Result;
+            var response = http.GetFromJsonAsync<Object>($"http://localhost:22468/api/ipEasy/GetItemFromIPEasyDB?CaseNo={CaseNo}&DoItem=处理审查意见").Result;
             
             dynamic retItem = new ExpandoObject();
 

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

@@ -4,7 +4,7 @@
     "isHeadless": "false",
     "Account": "caiyangl",
     "Password": "j)wx*lier*@3",
-    "ChormeDriverPath": "D:\\source\\repos\\StaffPerformance\\packages\\ChormeDriver\\97.0.4692.71",
+    "ChormeDriverPath": "D:\\source\\repos\\StaffPerformance\\packages\\ChormeDriver\\110.0.5481.77",
     "ScheduleSetting": "00 55 10 3 * ? *",
     "IPEasyWeb": "http://47.106.221.167/Login.aspx"
   },