فهرست منبع

添加从IPEasy中获取案件信息

luocaiyang 3 سال پیش
والد
کامیت
ea567bb7ce

+ 194 - 0
wispro.sp.api/Controllers/IPEasyController.cs

@@ -0,0 +1,194 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text.Json;
+using System.Threading.Tasks;
+using wispro.sp.entity;
+
+namespace wispro.sp.api.Controllers
+{
+    [Route("api/[controller]/[action]")]
+    [ApiController]
+    public class IPEasyController : ControllerBase
+    {
+        spDbContext Context;
+        public IPEasyController(spDbContext context)
+        {
+            Context = context;
+        }
+
+        #region 将从IPEasy中获得的信息保存到临时文件或从文件中取出已存在的信息
+        private PerformanceItem GetFromCache(string CaseNo,string DoItem = null)
+        {
+            var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
+            string fileName = $"{CaseNo}{(string.IsNullOrEmpty(DoItem) ? "" : $"-{DoItem}")}.json";
+
+            var path = Path.Combine(attachfileSavePath,
+                fileName);
+
+            if (System.IO.File.Exists(path))
+            {
+                if(new FileInfo(path).CreationTime < DateTime.Now.AddDays(-1))
+                {
+                    return null;
+                }
+
+                using (var file = System.IO.File.OpenText(path))
+                {
+                    string strJson = file.ReadToEnd();
+
+                    JsonSerializerOptions options = new System.Text.Json.JsonSerializerOptions()
+                    {
+                        IgnoreNullValues = true
+                    };
+                    return System.Text.Json.JsonSerializer.Deserialize<PerformanceItem>(strJson,options);
+                }
+                    
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        private void SaveToCache(PerformanceItem Item)
+        {
+            var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
+            string fileName = $"{Item.CaseNo}{(string.IsNullOrEmpty(Item.DoItem) ? "" : $"-{Item.DoItem}")}.json";
+
+            var path = Path.Combine(attachfileSavePath,
+                fileName);
+
+            if (System.IO.File.Exists(path))
+            {
+                System.IO.File.Delete(path);
+            }
+
+            JsonSerializerOptions options = new System.Text.Json.JsonSerializerOptions() {
+                IgnoreNullValues = true
+                
+            };
+            
+            string strJson = System.Text.Json.JsonSerializer.Serialize<PerformanceItem>(Item,options);
+
+            using (var file = System.IO.File.CreateText(path))
+            {
+                file.Write(strJson);
+            }
+              
+        }
+        #endregion
+
+        public PerformanceItem GetCaseInfo(string CaseNo)
+        {
+            var retItem = GetFromCache(CaseNo);
+            if (retItem != null)
+            {
+                return retItem;
+            }
+            else
+            {
+                dynamic retObj = wispro.sp.utility.IPEasyUtility.GetCaseInfo(CaseNo);
+                PerformanceItem Item = new PerformanceItem();
+                Item.CaseName = retObj.CaseName;
+                Item.CaseNo = retObj.CaseNo;
+                Item.Customer = new Customer();
+                Item.Customer.Name = retObj.CustomerName;
+                Item.ApplicationType = retObj.ApplicationType;
+                Item.BusinessType = retObj.BusinessType;
+                Item.CaseCoefficient = retObj.CaseCoefficient;
+                Item.CaseMemo = retObj.CaseMemo;
+                Item.CaseState = retObj.CaseState;
+                Item.CaseType = retObj.CaseType;
+
+                SaveToCache(Item);
+                return Item;
+            }
+        }
+
+        public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
+        {
+            var retItem = GetFromCache(CaseNo,DoItem);
+            if (retItem != null)
+            {
+                return retItem;
+            }
+            else
+            {
+                dynamic retObj = wispro.sp.utility.IPEasyUtility.GetPerformanctRecord(CaseNo, DoItem);
+                PerformanceItem Item = new PerformanceItem();
+                Item.CaseName = retObj.CaseName;
+                Item.CaseNo = retObj.CaseNo;
+                Item.DoItem = retObj.DoItem;
+                Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
+                Item.Customer = new Customer();
+                Item.Customer.Name = retObj.CustomerName;
+                Item.DoItemCoefficient = retObj.DoItemCoefficient;
+                Item.DoItemMemo = retObj.DoItemMemo;
+                Item.DoItemState = retObj.DoItemState;
+                Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
+                Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
+                Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
+                //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
+                Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
+
+                if (!string.IsNullOrEmpty(retObj.DoPersons))
+                {
+
+                    Item.ItemStaffs = new List<ItemStaff>();
+                    string[] names = retObj.DoPersons.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+                    foreach (var name in names)
+                    {
+
+                        ItemStaff iStaff = new ItemStaff();
+                        iStaff.DoPerson = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
+                        if (iStaff.DoPerson == null)
+                        {
+                            iStaff.DoPerson = new Staff() { Name = name };
+                        }
+                        else
+                        {
+                            iStaff.DoPersonId = iStaff.DoPerson.Id;
+                        }
+
+
+
+                        Item.ItemStaffs.Add(iStaff);
+                    }
+                }
+
+                Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
+
+                if (!string.IsNullOrEmpty(retObj.Reviewer))
+                {
+                    string name = retObj.Reviewer;
+                    var temReviewer = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
+                    if (temReviewer == null)
+                    {
+                        Item.Reviewer = new Staff() { Name = retObj.Reviewer };
+                    }
+                    else
+                    {
+                        Item.Reviewer = temReviewer;
+                        Item.ReviewerId = temReviewer.Id;
+                    }
+                }
+                Item.ApplicationType = retObj.ApplicationType;
+                Item.BusinessType = retObj.BusinessType;
+                Item.CaseCoefficient = retObj.CaseCoefficient;
+                Item.CaseMemo = retObj.CaseMemo;
+                Item.CaseStage = retObj.CaseStage;
+                Item.CaseState = retObj.CaseState;
+                Item.CaseType = retObj.CaseType;
+
+                SaveToCache(Item);
+
+                return Item;
+            }
+        }
+
+    }
+}

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

@@ -659,76 +659,6 @@ namespace wispro.sp.api.Controllers
         }
 
         
-        public PerformanceItem GetItemFormIPEasy(string CaseNo, string DoItem)
-        {
-            dynamic retObj = wispro.sp.utility.IPEasyUtility.GetPerformanctRecord(CaseNo, DoItem);
-            PerformanceItem Item = new PerformanceItem();
-            Item.CaseName = retObj.CaseName;
-            Item.CaseNo = retObj.CaseNo;
-            Item.DoItem = retObj.DoItem;
-            Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
-            Item.Customer = new Customer();
-            Item.Customer.Name = retObj.CustomerName;
-            Item.DoItemCoefficient = retObj.DoItemCoefficient;
-            Item.DoItemMemo = retObj.DoItemMemo;
-            Item.DoItemState = retObj.DoItemState;
-            Item.EntrustingDate = string.IsNullOrEmpty(retObj.EntrustingDate) ? null : DateTime.Parse(retObj.EntrustingDate);
-            Item.FinalizationDate = string.IsNullOrEmpty(retObj.FinalizationDate) ? null : DateTime.Parse(retObj.FinalizationDate);
-            Item.FinishedDate = string.IsNullOrEmpty(retObj.FinishedDate) ? null : DateTime.Parse(retObj.FinishedDate);
-            //Item.FirstDraftDate = string.IsNullOrEmpty(retObj.FirstDraftDate) ? null : DateTime.Parse(retObj.FirstDraftDate);
-            Item.InternalDate = string.IsNullOrEmpty(retObj.InternalDate) ? null : DateTime.Parse(retObj.InternalDate);
-
-            if (!string.IsNullOrEmpty(retObj.DoPersons))
-            {
-
-                Item.ItemStaffs = new List<ItemStaff>();
-                string[] names = retObj.DoPersons.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
-                foreach (var name in names)
-                {
-
-                    ItemStaff iStaff = new ItemStaff();
-                    iStaff.DoPerson = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
-                    if(iStaff.DoPerson == null)
-                    {
-                        iStaff.DoPerson = new Staff() { Name = name };
-                    }
-                    else
-                    {
-                        iStaff.DoPersonId = iStaff.DoPerson.Id;
-                    }
-
-
-
-                    Item.ItemStaffs.Add(iStaff);
-                }
-            }
-
-            Item.ReturnDate = string.IsNullOrEmpty(retObj.ReturnDate) ? null : DateTime.Parse(retObj.ReturnDate);
-
-            if (!string.IsNullOrEmpty(retObj.Reviewer))
-            {
-                string name = retObj.Reviewer;
-                var temReviewer = Context.Staffs.Where<Staff>(s => s.Name == name).FirstOrDefault();
-                if (temReviewer == null)
-                {
-                    Item.Reviewer = new Staff() { Name = retObj.Reviewer };
-                }
-                else
-                {
-                    Item.Reviewer = temReviewer;
-                    Item.ReviewerId = temReviewer.Id;
-                }
-            }
-            Item.ApplicationType = retObj.ApplicationType;
-            Item.BusinessType = retObj.BusinessType;
-            Item.CaseCoefficient = retObj.CaseCoefficient;
-            Item.CaseMemo = retObj.CaseMemo;
-            Item.CaseStage = retObj.CaseStage;
-            Item.CaseState = retObj.CaseState;
-            Item.CaseType = retObj.CaseType;
-
-            return Item;
-        }
-
+        
     }
 }

+ 5 - 2
wispro.sp.api/Startup.cs

@@ -53,8 +53,11 @@ namespace wispro.sp.api
                 };
             });
 
-            services.AddControllers().AddNewtonsoftJson(o=>
-            o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
+            services.AddControllers().AddJsonOptions(options =>
+            {
+                options.JsonSerializerOptions.IgnoreNullValues = true;
+            });
+
             services.AddDbContext<spDbContext>(optionsAction =>
                 optionsAction.UseSqlServer(Configuration.GetConnectionString("DefaultConnect"))
             );

+ 92 - 2
wispro.sp.utility/IPEasyUtility.cs

@@ -205,10 +205,100 @@ namespace wispro.sp.utility
         }
 
         /// <summary>
+        /// 获取案件基本信息
+        /// </summary>
+        /// <param name="caseNo">我方文号</param>
+        /// <returns></returns>
+        public static dynamic GetCaseInfo(string caseNo)
+        {
+            string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
+            bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
+            string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
+            string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
+
+            OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
+
+
+            options.AddUserProfilePreference("download.default_directory", strFileSavePath);
+            options.AddUserProfilePreference("intl.accept_languages", "nl");
+            options.AddUserProfilePreference("disable-popup-blocking", "true");
+            options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
+
+            if (isheadless)
+            {
+                options.AddArgument("headless");
+            }
+
+            dynamic retObject = new ExpandoObject();
+
+            retObject.CaseNo = caseNo;
+
+            using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
+            {
+
+                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
+                driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
+
+                //进入登录界面
+                driver.Navigate().GoToUrl("http://47.106.221.167/Login.aspx");
+
+                //输入用户名和密码
+                driver.FindElement(By.Id("txtUser")).SendKeys(Account);
+                driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
+
+                //点击登录按钮
+                driver.FindElement(By.Id("btnLogin")).Click();
+
+                //关闭提示遮罩层
+                driver.FindElement(By.Id("jpwClose")).Click();
+
+                //点击顶部菜单栏中的案件管理菜单
+                driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
+
+                //点击左侧 查询 菜单
+                driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
+
+                //切换到自定义报表Frame
+                driver.SwitchTo().Frame(1);
+
+                var inputSearch = driver.FindElement(By.Id("case_volume"));
+                inputSearch.SendKeys(caseNo);
+
+                var btnSearch = driver.FindElement(By.Id("btn_Search"));
+                btnSearch.Click();
+
+                var caseLink = driver.FindElement(By.XPath($"//a[contains(text(),'{caseNo}')]"));
+                caseLink.Click();
+                System.Threading.Thread.Sleep(500);
+
+                driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
+                
+                driver.FindElement(By.Id("libase")).Click();
+                retObject.CaseName = driver.FindElement(By.Id("p_case_info__case_name")).GetAttribute("value");  //案件名称
+                retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value");  //客户名称
+                retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value");     //业务类型
+
+                retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
+                retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
+
+
+                retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value");  //案件类型
+                retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
+                retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value");    //案件备注
+
+                driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
+                //select[@id='p_case_info__case_coefficient_id']
+                retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
+
+            }
+
+            return retObject;
+        }
+        /// <summary>
         /// 获取案件处理事项记录
         /// </summary>
-        /// <param name="caseNo"></param>
-        /// <param name="doItemName"></param>
+        /// <param name="caseNo">我方文号</param>
+        /// <param name="doItemName">处理事项</param>
         /// <returns></returns>
         public static dynamic GetPerformanctRecord(string caseNo,string doItemName)
         {

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

@@ -7,6 +7,7 @@ using System.Configuration;
 using System.Data;
 using System.Diagnostics;
 using System.Drawing;
+using System.Dynamic;
 using System.Linq;
 using System.Net.Http;
 using System.Net.Http.Json;
@@ -705,11 +706,12 @@ namespace wispro.sp.winClient
             Stopwatch watch = new Stopwatch();
             watch.Start();
            
-            dynamic retObj = wispro.sp.utility.IPEasyUtility.GetPerformanctRecord("S2112392-洗碗机调查分析", "提出报告");
+            dynamic retObj = wispro.sp.utility.IPEasyUtility.GetPerformanctRecord("S2112392-洗碗机调查分析","提出报告");
             PerformanceItem Item = new PerformanceItem();
             Item.CaseName = retObj.CaseName;
             Item.CaseNo = retObj.CaseNo;
             Item.DoItem = retObj.DoItem;
+
             Item.CustomerLimitDate = string.IsNullOrEmpty(retObj.CustomerLimitDate) ? null : DateTime.Parse(retObj.CustomerLimitDate);
             Item.Customer = new Customer();
             Item.Customer.Name = retObj.CustomerName;