Bladeren bron

完成每月异常案件通知邮件

luocaiyang 7 maanden geleden
bovenliggende
commit
e00f69b2d7

+ 122 - 97
wispro.sp.api/Controllers/CaseFileCompareController.cs

@@ -1,5 +1,6 @@
 using AntDesign;
 using DocumentFormat.OpenXml.InkML;
+using DocumentFormat.OpenXml.Presentation;
 using DynamicExpresso;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
@@ -275,46 +276,40 @@ namespace wispro.sp.api.Controllers
         /// <param name="endDate">结束日期</param>
         /// /// <param name="customerName">客户名称,默认不指定,获取所有客户的平均权利要求差异度和标准方差</param>
         /// <returns></returns>
-        private List<CustomerCompareStatistics> getLaseYearMean_Variance(DateTime endDate,string customerName=null)
+        private List<CustomerCompareStatistics> getLaseYearMean_Variance(DateTime endDate,List<CaseInfo> caseList,string customerName=null)
         {
-
-            IIncludableQueryable<CaseInfo, CompareResult> caseList;
-
-            if (customerName != null) {
-                caseList = Context.CaseInfos.Where<CaseInfo>(
-                p => p.CreateTime >= endDate.AddYears(-1) && p.CreateTime <= endDate && p.Customer.Name == customerName)
-                .Include(p => p.Customer)
-                .Include(p => p.Reviewer)
-                .Include(p => p.DRRAbstract)
-                .Include(p => p.DRRAbstract)
-                .Include(p => p.DRRCalim)
-                .Include(p => p.DRRFulltext)
-                .Include(p => p.DRRAll)
-                .Include(p => p.RFRAbstract)
-                .Include(p => p.RFRCalim)
-                .Include(p => p.RFRFulltext)
-                .Include(p => p.RFRAll);
-            }
-            else
+            if(caseList == null)
             {
                 caseList = Context.CaseInfos.Where<CaseInfo>(
-                p => p.CreateTime >= endDate.AddYears(-1) && p.CreateTime <= endDate)
-                .Include(p => p.Customer)
-                .Include(p => p.Reviewer)
-                .Include(p => p.DRRAbstract)
-                .Include(p => p.DRRAbstract)
-                .Include(p => p.DRRCalim)
-                .Include(p => p.DRRFulltext)
-                .Include(p => p.DRRAll)
-                .Include(p => p.RFRAbstract)
-                .Include(p => p.RFRCalim)
-                .Include(p => p.RFRFulltext)
-                .Include(p => p.RFRAll);
+                        p => p.CreateTime >= endDate.AddYears(-1) &&
+                        p.CreateTime <= endDate &&
+                        p.Customer.Name == customerName
+                        )
+                    .Include(p => p.Customer)
+                    .Include(p => p.Reviewer)
+                    .Include(p => p.DRRAbstract)
+                    .Include(p => p.DRRAbstract)
+                    .Include(p => p.DRRCalim)
+                    .Include(p => p.DRRFulltext)
+                    .Include(p => p.DRRAll)
+                    .Include(p => p.RFRAbstract)
+                    .Include(p => p.RFRCalim)
+                    .Include(p => p.RFRFulltext)
+                    .Include(p => p.RFRAll)
+                    .ToList();
+            }
+
+            //IIncludableQueryable<CaseInfo, CompareResult> caseList;
+            var temcaseList = caseList;
+            if (customerName != null) {
+                temcaseList = caseList.Where(p=> p.Customer.Name == customerName)
+                .ToList();
             }
+            
 
             List < CustomerCompareStatistics > retList = new List < CustomerCompareStatistics >();
 
-            foreach ( var item in caseList)
+            foreach ( var item in temcaseList)
             {
                 var temObj = retList.Where(p=>p.CustomerName == item.Customer.Name).FirstOrDefault<CustomerCompareStatistics>();
                 if(temObj == null) {
@@ -373,39 +368,42 @@ namespace wispro.sp.api.Controllers
         ///     1:内部核稿差异率
         /// </param>
         /// <returns></returns>
-        private List<CaseInfo> getTop10DiffRateCases(DateTime start, DateTime end,string customerName,int type=0)
+        private List<CaseInfo> getTop10DiffRateCases(DateTime start, DateTime end,string customerName,int type=0,List<CaseInfo> caseList=null)
         {
-            if (type == 0) {
-
-                var top10Case = Context.CaseInfos.Where<CaseInfo>(
-                    p => p.CreateTime >= start &&
+            if (caseList == null) {
+                
+                caseList = Context.CaseInfos.Where<CaseInfo>(
+                    p => p.CreateTime >= end.AddYears(-1) &&
                     p.CreateTime <= end &&
                     p.Customer.Name == customerName
                     )
                 .Include(p => p.Customer)
                 .Include(p => p.Reviewer)
+                .Include(p => p.DRRAbstract)
+                .Include(p => p.DRRAbstract)
                 .Include(p => p.DRRCalim)
+                .Include(p => p.DRRFulltext)
+                .Include(p => p.DRRAll)
+                .Include(p => p.RFRAbstract)
                 .Include(p => p.RFRCalim)
-                .AsEnumerable()
-                .OrderByDescending(p => p.RFRCalim?.diffRate);
+                .Include(p => p.RFRFulltext)
+                .Include(p => p.RFRAll)
+                .ToList();
+                
+            }
+            if (type == 0) {
+
+                var top10Case = caseList.Where<CaseInfo>(p=>p.Customer.Name == customerName)
+                .OrderByDescending(p => p.RFRCalim?.diffRate).Take(10);
 
-                return top10Case.Take(10).ToList();
+                return top10Case.Where<CaseInfo>(c=>c.CreateTime>=start).ToList();
             }
             else
             {
-                var top10Case = Context.CaseInfos.Where<CaseInfo>(
-                    p => p.CreateTime >= start &&
-                    p.CreateTime <= end &&
-                    p.Customer.Name == customerName
-                    )
-                .Include(p => p.Customer)
-                .Include(p => p.Reviewer)
-                .Include(p => p.DRRCalim)
-                .Include(p => p.RFRCalim)
-                .AsEnumerable()
-                .OrderByDescending(p => p.DRRCalim?.diffRate);
+                var top10Case = caseList.Where<CaseInfo>(p => p.Customer.Name == customerName)
+                .OrderByDescending(p => p.DRRCalim?.diffRate).Take(10);
 
-                return top10Case.Take(10).ToList();
+                return top10Case.Where<CaseInfo>(c => c.CreateTime >= start).ToList();
             }
         }
 
@@ -416,20 +414,21 @@ namespace wispro.sp.api.Controllers
         /// <param name="end">结束日期</param>
         /// <param name="customerName">客户名称</param>
         /// <returns></returns>
-        private List<CaseInfo> GetAbnormalCases(DateTime start, DateTime end, string customerName)
+        private List<CaseInfo> GetAbnormalCases(DateTime start, DateTime end, string customerName,List<CaseInfo> caseList)
         {
-            var customerStatics = getLaseYearMean_Variance(end, customerName);
+            var customerStatics = getLaseYearMean_Variance(end, caseList,customerName);
             var cStatics = customerStatics.Where(s => s.CustomerName == customerName).FirstOrDefault();
-            return _GetAbnormalCases(start, end, customerName, cStatics);
+            return _GetAbnormalCases(start, end, customerName, cStatics,caseList);
 
         }
 
-        private  List<CaseInfo> _GetAbnormalCases(DateTime start, DateTime end, string customerName, CustomerCompareStatistics cStatics)
+        private  List<CaseInfo> _GetAbnormalCases(DateTime start, DateTime end, string customerName, CustomerCompareStatistics cStatics,List<CaseInfo> caseList)
         {
             if (cStatics != null)
             {
-                var caseList = Context.CaseInfos.Where<CaseInfo>(
-                        p => p.CreateTime >= start &&
+                if (caseList == null) {
+                    caseList = Context.CaseInfos.Where<CaseInfo>(
+                        p => p.CreateTime >= end.AddYears(-1) &&
                         p.CreateTime <= end &&
                         p.Customer.Name == customerName
                         )
@@ -443,46 +442,54 @@ namespace wispro.sp.api.Controllers
                     .Include(p => p.RFRAbstract)
                     .Include(p => p.RFRCalim)
                     .Include(p => p.RFRFulltext)
-                    .Include(p => p.RFRAll);
+                    .Include(p => p.RFRAll)
+                    .ToList();
+
+                }
 
                 var retList = new List<CaseInfo>();
 
-                foreach (var item in caseList)
+                var temCaseList = caseList.Where(p=>p.Customer.Name== customerName).ToList();
+
+                foreach (var item in temCaseList)
                 {
-                    double first = item.DRRCalim == null ? 0.0 : item.DRRCalim.diffRate;
-                    double second = item.RFRCalim == null ? 0.0 : item.RFRCalim.diffRate;
+                    if (item.CreateTime >= start)
+                    {
+                        double first = item.DRRCalim == null ? 0.0 : item.DRRCalim.diffRate;
+                        double second = item.RFRCalim == null ? 0.0 : item.RFRCalim.diffRate;
 
-                    double score1 = (first - cStatics.Diff_Drafted_Claims_Avg) / cStatics.Diff_Drafted_Claims_Std;
-                    double score2 = (second - cStatics.Diff_FinalDrafted_Claims_Avg) / cStatics.Diff_FinalDrafted_Claims_Std;
-                    double score = Math.Sqrt(score1 * score1 + score2 * score2);
+                        double score1 = (first - cStatics.Diff_Drafted_Claims_Avg) / cStatics.Diff_Drafted_Claims_Std;
+                        double score2 = (second - cStatics.Diff_FinalDrafted_Claims_Avg) / cStatics.Diff_FinalDrafted_Claims_Std;
+                        double score = Math.Sqrt(score1 * score1 + score2 * score2);
 
-                    if (score > 3.0)
-                    {
-                        if (score2 > 0)
+                        if (score > 3.0)
                         {
-                            if (score1 < 0)
+                            if (score2 > 0)
                             {
-                                item.AbnormalMessage = "内部核稿修改相对少,外部修改相对很多!【核稿人不给力/沟通有问题?】";
+                                if (score1 < 0)
+                                {
+                                    item.AbnormalMessage = $"内部核稿修改相对少,外部修改相对很多!【核稿人不给力/沟通有问题?】,【分数为:{score.ToString("0.00")}】";
+                                }
+                                else
+                                {
+                                    item.AbnormalMessage = $"内部核稿相对多,外部修改也相对多!【沟通有问题?】,【分数为:{score.ToString("0.00")}】";
+                                }
                             }
                             else
                             {
-                                item.AbnormalMessage = "内部核稿相对多,外部修改也相对多!【沟通有问题?】";
+                                if (score1 < 0)
+                                {
+                                    item.AbnormalMessage = $"内部核稿修改相对少,外部修改相对少!【撰稿人给力】,【分数为:{score.ToString("0.00")}】";
+                                }
+                                else
+                                {
+                                    item.AbnormalMessage = $"内部核稿相对多,外部修改也相对少!【核稿人给力】,【分数为:{score.ToString("0.00")}】";
+                                }
                             }
-                        }
-                        else
-                        {
-                            //if (score1 < 0)
-                            //{
-                            //    item.AbnormalMessage = "内部核稿修改相对少,外部修改相对少!【撰稿人给力】";
-                            //}
-                            //else
-                            //{
-                            //    item.AbnormalMessage = "内部核稿相对多,外部修改也相对少!【核稿人给力】";
-                            //}
-                        }
 
 
-                        retList.Add(item);
+                            retList.Add(item);
+                        }
                     }
                 }
 
@@ -507,10 +514,27 @@ namespace wispro.sp.api.Controllers
 
         public void getMailCaseInfo(DateTime start, DateTime end)
         {
+            var caseList = Context.CaseInfos.Where<CaseInfo>(
+                    p => p.CreateTime >= end.AddYears(-1) &&
+                    p.CreateTime <= end
+                    )
+                .Include(p => p.Customer)
+                .Include(p => p.Reviewer)
+                .Include(p => p.DRRAbstract)
+                .Include(p => p.DRRAbstract)
+                .Include(p => p.DRRCalim)
+                .Include(p => p.DRRFulltext)
+                .Include(p => p.DRRAll)
+                .Include(p => p.RFRAbstract)
+                .Include(p => p.RFRCalim)
+                .Include(p => p.RFRFulltext)
+                .Include(p => p.RFRAll)
+                .ToList();
+
             List<string> defaultStaffNames = new List<string>() { "罗才洋","李庆波","钟子敏"};
             var DefaultEmailAccounts = Context.Staffs.Where(p => defaultStaffNames.Contains(p.Name)).ToList();
             
-            var customerStatics = getLaseYearMean_Variance(end);
+            var customerStatics = getLaseYearMean_Variance(end,caseList);
             Hashtable staffMailInfo = new Hashtable();
             foreach (var cStatics in customerStatics)
             {
@@ -520,7 +544,7 @@ namespace wispro.sp.api.Controllers
                 }
 
                 //var cStatics = customerStatics.Where(s => s.CustomerName == item.Customer.Name).FirstOrDefault();
-                var Top10Cases =getTop10DiffRateCases(start, end, cStatics.CustomerName);
+                var Top10Cases =getTop10DiffRateCases(start, end, cStatics.CustomerName,0,caseList);
                 foreach (var caseInfo in Top10Cases)
                 {
                     foreach (Staff staff in DefaultEmailAccounts)
@@ -543,7 +567,7 @@ namespace wispro.sp.api.Controllers
                     }
                 }
 
-                var AbnormalCases = _GetAbnormalCases(start,end, cStatics.CustomerName, cStatics);
+                var AbnormalCases = _GetAbnormalCases(start,end, cStatics.CustomerName, cStatics,caseList);
                 foreach (var caseInfo in AbnormalCases)
                 {
                     foreach(Staff staff in DefaultEmailAccounts)
@@ -579,30 +603,30 @@ namespace wispro.sp.api.Controllers
                     {
                         if ((m.Top10Cases != null && m.Top10Cases.Count > 0) || (m.AbnormalCases != null && m.AbnormalCases.Count > 0))
                         {
-                            strMessage += $"<div><b>{m.CustomerCompareStatistics.CustomerName}:</b>";
+                            strMessage += $"<br/><div><b>{m.CustomerCompareStatistics.CustomerName}:</b>";
                             strMessage += $"<br/>一年内案件数量:{m.CustomerCompareStatistics.CaseCount}";
                             strMessage += $"<br/>内部核稿平均修改率:{m.CustomerCompareStatistics.Diff_Drafted_Claims_Avg}&nbsp;&nbsp;内部核稿修改率标准方差:{m.CustomerCompareStatistics.Diff_Drafted_Claims_Std}";
                             strMessage += $"<br/>外部部核稿平均修改率:{m.CustomerCompareStatistics.Diff_FinalDrafted_Claims_Avg}&nbsp;&nbsp;外部核稿修改率标准方差:{m.CustomerCompareStatistics.Diff_FinalDrafted_Claims_Std}</div>";
                             if (m.Top10Cases != null && m.Top10Cases.Count > 0)
                             {
                                 strMessage += $"<div>外部核稿修改率前10名案件清单:</div>";
-                                strMessage += "<table><thead><td>案号</td><td>案件名称</td><td>处理人</td><td>核稿人</td><td>内部核稿修改率</td><td>外部核稿修改率</td></thead><body>";
+                                strMessage += "<table border='1'><thead><td>案号</td><td>案件名称</td><td>处理人</td><td>核稿人</td><td>内部核稿修改率(%)</td><td>外部核稿修改率(%)</td></thead><body>";
                                 foreach (var c in m.Top10Cases)
                                 {
-                                    strMessage += $"<tr><td><a href=\"{($"http://1.116.113.26/CompareFile/detail/{c.CaseNo}")}\">{c.CaseNo}</a></td><td>{c.CaseName}</td><td>{c.Handlers}</td><td>{(c.Reviewer == null ? "" : c.Reviewer.Name)}</td><td>{(c.DRRCalim == null ? "" : c.DRRCalim.diffRate.ToString("0.0000"))}</td><td>{(c.RFRCalim == null ? "" : c.RFRCalim.diffRate.ToString("0.0000"))}</td></tr>";
+                                    strMessage += $"<tr><td><a href=\"{($"http://1.116.113.26/CompareFile/detail/{c.CaseNo}")}\">{c.CaseNo}</a></td><td>{c.CaseName}</td><td>{c.Handlers}</td><td>{(c.Reviewer == null ? "" : c.Reviewer.Name)}</td><td>{(c.DRRCalim == null ? "" : (c.DRRCalim.diffRate*100).ToString("0.0000"))}</td><td>{(c.RFRCalim == null ? "" : (c.RFRCalim.diffRate * 100).ToString("0.0000"))}</td></tr>";
                                 }
                                 strMessage += "</body></table>";
                             }
 
                             if (m.AbnormalCases != null && m.AbnormalCases.Count > 0)
                             {
-                                strMessage += $"<div>疑似异常案件清单:</div>";
-                                strMessage += "<table><thead><td>案号</td><td>案件名称</td><td>处理人</td><td>核稿人</td><td>内部核稿修改率</td><td>外部核稿修改率</td></thead><body>";
-                                foreach (var c in m.Top10Cases)
+                                strMessage += $"<br/><div>疑似异常案件清单:</div>";
+                                strMessage += "<table border='1'><thead><td>案号</td><td>案件名称</td><td>处理人</td><td>核稿人</td><td>内部核稿修改率</td><td>外部核稿修改率</td><td>异常说明</td></thead><body>";
+                                foreach (var c in m.AbnormalCases)
                                 {
-                                    strMessage += $"<tr><td><a href=\"{($"http://1.116.113.26/CompareFile/detail/{c.CaseNo}")}\">{c.CaseNo}</a></td><td>{c.CaseName}</td><td>{c.Handlers}</td><td>{(c.Reviewer == null ? "" : c.Reviewer.Name)}</td><td>{(c.DRRCalim == null ? "" : c.DRRCalim.diffRate.ToString("0.0000"))}</td><td>{(c.RFRCalim == null ? "" : c.RFRCalim.diffRate.ToString("0.0000"))}</td></tr>";
+                                    strMessage += $"<tr><td><a href=\"{($"http://1.116.113.26/CompareFile/detail/{c.CaseNo}")}\">{c.CaseNo}</a></td><td>{c.CaseName}</td><td>{c.Handlers}</td><td>{(c.Reviewer == null ? "" : c.Reviewer.Name)}</td><td>{(c.DRRCalim == null ? "" : (c.DRRCalim.diffRate*100).ToString("0.0000"))}</td><td>{(c.RFRCalim == null ? "" : (c.RFRCalim.diffRate*100).ToString("0.0000"))}</td><td>{c.AbnormalMessage}</td></tr>";
                                 }
-                                strMessage += "</body></table>";
+                                strMessage += "</body></table><br/>";
                             }
 
                             strMessage += "</div>";
@@ -610,8 +634,9 @@ namespace wispro.sp.api.Controllers
                         
                     }
 
+                    string strTem = $"如下是{start.ToString("yyyy-MM-dd")}到{end.ToString("yyyy-MM-dd")}国内专利申请案件在客户核稿处于年内修改率前10名的案件和疑似异常案件清单,请关注!";
 
-                    string strBody = $"<div style=\"position:absolute;margin-top:20px;margin-left:20px;margin-right:20px;box-shadow:0px 0px 3px 3px #ccc \"><div style= \"margin-top: 20px; margin-left:20px;;font-size:14px; \">{staff.Name},你好!</div><div style= \"margin-top: 25px; margin-left:20px;font-size:14px; \">{strMessage}<div style= \"margin-top: 100px;margin-right:15px; padding-bottom: 20px; font-size:14px;color:#888888;float:right; \">小美集团绩效管理系统</div></div>";
+                    string strBody = $"<div><div>{staff.Name},你好!</div><br/><div>{strTem}</div>{strMessage}<br/><div >小美集团绩效管理系统</div></div>";
                     staff.Mail = "luocaiyang@china-wispro.com";
                     _ = QuartzUtil.AddMailJob($"{start.ToString("yyyyMMdd")}-{end.ToString("yyyyMMdd")}申请文件比较邮件", strBody, staff.Name, staff.Mail);
                 }

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

@@ -105,7 +105,7 @@ namespace wispro.sp.winClient
                 http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token?.Token);
                 try
                 {
-                    var data = await http.GetAsync($"{strAPIBaseUri}/api/CaseFileCompare/getMailCaseInfo?start=2024-10-01&end=2025-12-31");
+                    var data = await http.GetAsync($"{strAPIBaseUri}/api/CaseFileCompare/getMailCaseInfo?start=2025-01-01&end=2025-01-31");
 
                 }
                 catch (Exception ex)

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

@@ -387,7 +387,7 @@ namespace wispro.sp.winClient
             {
                 if (MessageBox.Show("获取前一天所有的完成案件,并比较文档?", "提示框", MessageBoxButtons.YesNo) == DialogResult.Yes)
                 {
-                    compareCaseFile(DateTime.Parse("2024-02-01"),DateTime.Parse("2024-12-31"));
+                    compareCaseFile(DateTime.Parse("2025-01-01"),DateTime.Parse("2025-01-31"));
                     return;
                 }
                 else