Selaa lähdekoodia

添加文件比较发邮件人员清单及相关案件清单信息

luocaiyang 8 kuukautta sitten
vanhempi
commit
ad2403cc65

+ 370 - 12
wispro.sp.api/Controllers/CaseFileCompareController.cs

@@ -4,8 +4,10 @@ using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Query;
 using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Data;
 using System.Diagnostics;
@@ -256,6 +258,351 @@ namespace wispro.sp.api.Controllers
             return Context.CaseInfos.Where(p => p.CaseNo == caseNo.Trim()).Count() > 0;
         }
 
+        public static (double, double) UpdateStatistics(int n, double mean, double variance, double newValue)
+        {
+            double newMean = (n * mean + newValue) / (n + 1);
+            
+            double newVariance = Math.Sqrt((n * (mean - newMean) * (mean - newMean) + (newValue - newMean) * (newValue - newMean) + n * variance * variance) / (n + 1));
+
+            return (newMean, newVariance);
+        }
+
+        /// <summary>
+        /// 计算指定日期之前一年的指定客户的平均权利要求差异度和标准方差
+        /// </summary>
+        /// <param name="endDate">结束日期</param>
+        /// /// <param name="customerName">客户名称,默认不指定,获取所有客户的平均权利要求差异度和标准方差</param>
+        /// <returns></returns>
+        private List<CustomerCompareStatistics> getLaseYearMean_Variance(DateTime endDate,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
+            {
+                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);
+            }
+
+            List < CustomerCompareStatistics > retList = new List < CustomerCompareStatistics >();
+
+            foreach ( var item in caseList)
+            {
+                var temObj = retList.Where(p=>p.CustomerName == item.Customer.Name).FirstOrDefault<CustomerCompareStatistics>();
+                if(temObj == null) {
+                    temObj = new CustomerCompareStatistics();
+                    temObj.CustomerName = item.Customer.Name;
+                    retList.Add(temObj);
+                }
+
+                temObj.CaseCount += 1;
+
+                if (item.DRRCalim != null)
+                {
+                    if (temObj.Diff_FinalDrafted_Claims_Count > 0) {
+                        var retStatistics = UpdateStatistics(temObj.Diff_Drafted_Claims_Count, temObj.Diff_Drafted_Claims_Avg, temObj.Diff_Drafted_Claims_Std, item.DRRCalim.diffRate);
+                        temObj.Diff_Drafted_Claims_Std = retStatistics.Item2;
+                        temObj.Diff_Drafted_Claims_Avg = retStatistics.Item1;
+                        temObj.Diff_Drafted_Claims_Count += 1;
+                    }
+                    else
+                    {
+                        temObj.Diff_Drafted_Claims_Std = 0.0;
+                        temObj.Diff_Drafted_Claims_Avg = item.DRRCalim.diffRate;
+                        temObj.Diff_Drafted_Claims_Count = 1;
+                    }
+                }
+
+                if (item.RFRCalim != null)
+                {
+                    if (temObj.Diff_FinalDrafted_Claims_Count > 0)
+                    {
+                        var retStatistics = UpdateStatistics(temObj.Diff_FinalDrafted_Claims_Count, temObj.Diff_FinalDrafted_Claims_Avg, temObj.Diff_FinalDrafted_Claims_Std, item.RFRCalim.diffRate);
+                        temObj.Diff_FinalDrafted_Claims_Std = retStatistics.Item2;
+                        temObj.Diff_FinalDrafted_Claims_Avg = retStatistics.Item1;
+                        temObj.Diff_FinalDrafted_Claims_Count += 1;
+                    }
+                    else
+                    {
+                        temObj.Diff_FinalDrafted_Claims_Std = 0.0;
+                        temObj.Diff_FinalDrafted_Claims_Avg = item.RFRCalim.diffRate;
+                        temObj.Diff_FinalDrafted_Claims_Count = 1;
+                    }
+                }
+            }
+
+            return retList;
+        }
+
+        /// <summary>
+        /// 获取指定时间内客户的权要修改差异率最高的10各案件
+        /// </summary>
+        /// <param name="start">开始日期</param>
+        /// <param name="end">结束日期</param>
+        /// <param name="customerName">客户名称</param>
+        /// <param name="type">类型:
+        ///     0:外部核稿差异率,默认值,
+        ///     1:内部核稿差异率
+        /// </param>
+        /// <returns></returns>
+        private List<CaseInfo> getTop10DiffRateCases(DateTime start, DateTime end,string customerName,int type=0)
+        {
+            if (type == 0) {
+
+                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.RFRCalim?.diffRate);
+
+                return top10Case.Take(10).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);
+
+                return top10Case.Take(10).ToList();
+            }
+        }
+
+        /// <summary>
+        /// 获取指定时间内客户权要修改差异度计算出的异常案件
+        /// </summary>
+        /// <param name="start">开始日期</param>
+        /// <param name="end">结束日期</param>
+        /// <param name="customerName">客户名称</param>
+        /// <returns></returns>
+        private List<CaseInfo> GetAbnormalCases(DateTime start, DateTime end, string customerName)
+        {
+            var customerStatics = getLaseYearMean_Variance(end, customerName);
+            var cStatics = customerStatics.Where(s => s.CustomerName == customerName).FirstOrDefault();
+            return _GetAbnormalCases(start, end, customerName, cStatics);
+
+        }
+
+        private  List<CaseInfo> _GetAbnormalCases(DateTime start, DateTime end, string customerName, CustomerCompareStatistics cStatics)
+        {
+            if (cStatics != null)
+            {
+                var caseList = 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.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);
+
+                var retList = new List<CaseInfo>();
+
+                foreach (var item in caseList)
+                {
+                    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);
+
+                    if (score > 3.0)
+                    {
+                        if (score2 > 0)
+                        {
+                            if (score1 < 0)
+                            {
+                                item.AbnormalMessage = "内部核稿修改相对少,外部修改相对很多!【核稿人不给力/沟通有问题?】";
+                            }
+                            else
+                            {
+                                item.AbnormalMessage = "内部核稿相对多,外部修改也相对多!【沟通有问题?】";
+                            }
+                        }
+                        else
+                        {
+                            //if (score1 < 0)
+                            //{
+                            //    item.AbnormalMessage = "内部核稿修改相对少,外部修改相对少!【撰稿人给力】";
+                            //}
+                            //else
+                            //{
+                            //    item.AbnormalMessage = "内部核稿相对多,外部修改也相对少!【核稿人给力】";
+                            //}
+                        }
+
+
+                        retList.Add(item);
+                    }
+                }
+
+                return retList;
+            }
+            else
+            {
+                return new List<CaseInfo>();
+            }
+
+
+        }
+
+        internal class mailCaseInfo
+        {
+            public CustomerCompareStatistics CustomerCompareStatistics { get; set; }
+
+            public List<CaseInfo> Top10Cases { get; set; } = new List<CaseInfo>();
+
+            public List<CaseInfo> AbnormalCases { get; set; }= new List<CaseInfo>();
+        }
+
+        public void getMailCaseInfo(DateTime start, DateTime end)
+        {
+            List<string> defaultStaffNames = new List<string>() { "罗才洋","李庆波","钟子敏"};
+            var DefaultEmailAccounts = Context.Staffs.Where(p => defaultStaffNames.Contains(p.Name)).ToList();
+            
+            var customerStatics = getLaseYearMean_Variance(end);
+            Hashtable staffMailInfo = new Hashtable();
+            foreach (var cStatics in customerStatics)
+            {
+                if(cStatics.CaseCount < 20)
+                {
+                    continue;
+                }
+
+                //var cStatics = customerStatics.Where(s => s.CustomerName == item.Customer.Name).FirstOrDefault();
+                var Top10Cases =getTop10DiffRateCases(start, end, cStatics.CustomerName);
+                foreach (var caseInfo in Top10Cases)
+                {
+                    foreach (Staff staff in DefaultEmailAccounts)
+                    {
+                        AddtoHashTable(caseInfo, 0, staff, staffMailInfo, cStatics);
+                    }
+
+                    if (caseInfo.Reviewer != null)
+                    {
+                        AddtoHashTable(caseInfo,0, caseInfo.Reviewer,staffMailInfo,cStatics);
+                    }
+
+                    if (caseInfo.Customer.ResponseManId != null)
+                    {
+                        Staff respMan = Context.Staffs.FirstOrDefault<Staff>(p => p.Id == caseInfo.Customer.ResponseManId);
+                        if (respMan != null)
+                        {
+                            AddtoHashTable(caseInfo, 0, respMan, staffMailInfo, cStatics);
+                        }
+                    }
+                }
+
+                var AbnormalCases = _GetAbnormalCases(start,end, cStatics.CustomerName, cStatics);
+                foreach (var caseInfo in AbnormalCases)
+                {
+                    foreach(Staff staff in DefaultEmailAccounts)
+                    {
+                        AddtoHashTable(caseInfo, 1, staff, staffMailInfo, cStatics);
+                    }
+                    if (caseInfo.Reviewer != null)
+                    {
+                        AddtoHashTable(caseInfo, 1, caseInfo.Reviewer, staffMailInfo, cStatics);
+                    }
+
+                    if (caseInfo.Customer.ResponseManId != null)
+                    {
+                        Staff respMan = Context.Staffs.FirstOrDefault<Staff>(p => p.Id == caseInfo.Customer.ResponseManId);
+                        if (respMan != null)
+                        {
+                            AddtoHashTable(caseInfo, 1, respMan, staffMailInfo, cStatics);
+                        }
+                    }
+                }
+
+            }
+        }
+
+        private void AddtoHashTable(CaseInfo caseInfo, int v, Staff staff, Hashtable staffMailInfo,CustomerCompareStatistics cStatics)
+        {
+            var staffCaseMailInfo = new mailCaseInfo()
+            {
+                CustomerCompareStatistics = cStatics,
+            };
+
+            List<mailCaseInfo> staffCaseMailInfos = new List<mailCaseInfo>();
+            if (staffMailInfo.ContainsKey(staff))
+            {
+                staffCaseMailInfos = (List<mailCaseInfo>)staffMailInfo[staff];
+            }
+            else
+            {
+                staffMailInfo.Add(staff,staffCaseMailInfos);
+            }
+
+            var temObj = staffCaseMailInfos.Where(p => p.CustomerCompareStatistics.CustomerName == caseInfo.Customer.Name).FirstOrDefault();
+            if (temObj != null)
+            {
+                staffCaseMailInfo = temObj;
+            }
+            else
+            {
+                staffCaseMailInfos.Add(staffCaseMailInfo);
+            }
+
+            if (v == 0)
+            {
+                staffCaseMailInfo.Top10Cases.Add(caseInfo);
+            }
+            else
+            {
+                staffCaseMailInfo.AbnormalCases.Add(caseInfo);
+            }
+        }
+
         /// <summary>
         /// 计算案件的zScore
         /// </summary>
@@ -264,11 +611,15 @@ namespace wispro.sp.api.Controllers
         /// <param name="type">
         /// 0:基于文本相似度计算,
         /// 1:基于文本修改差异度计算
-        /// 2:权要权重70说明书30
+        /// 2:基于权要权重70说明书30计算
+        /// 3:基于权要文本相似度计算
+        /// 4: 基于权要文字修改差异度计算
         /// </param>
         /// <returns></returns>
         public IList<Object> CalCustomer_mean(DateTime start,DateTime end,int type=0)
         {
+            
+
             var caseList = Context.CaseInfos.Where<CaseInfo>(
                 p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
                 .Include(p=>p.Customer)
@@ -362,16 +713,6 @@ namespace wispro.sp.api.Controllers
                 double? oneSim = getCalValue(item,type,0);
                 double? twoSim = getCalValue(item, type, 1); ;
 
-                //if(oneSim == null)
-                //{
-                //    oneSim = 1;
-                //}
-
-                //if (twoSim == null)
-                //{
-                //    twoSim = 1; 
-                //}
-
                 DataRow row = dt.NewRow();
                 row["我方文号"] = item.CaseNo;
                 row["案件名称"] = item.CaseName;
@@ -406,7 +747,7 @@ namespace wispro.sp.api.Controllers
                 {
                     var distince = Math.Sqrt(zScoreB.Value * zScoreB.Value + zScoreA.Value * zScoreA.Value);
 
-                    if (type == 0 || type == 2)
+                    if (type == 0 || type == 2 || type==3)
                     {
                         if (distince > 3)
                         {
@@ -608,6 +949,23 @@ namespace wispro.sp.api.Controllers
                         }
                     }
                     break;
+                case 4:
+                    if (stage == 0)
+                    {
+
+                        if (caseInfo.DRRCalim != null)
+                        {
+                            calValue = caseInfo.DRRCalim.diffRate;
+                        }
+                    }
+                    else
+                    {
+                        if (caseInfo.RFRCalim != null)
+                        {
+                            calValue = caseInfo.RFRCalim.diffRate;
+                        }
+                    }
+                    break;
             }
 
             return calValue;

+ 20 - 0
wispro.sp.winClient/APIService.cs

@@ -96,6 +96,26 @@ namespace wispro.sp.winClient
             return false;
         }
 
+        public async Task testMail()
+        {
+            userToken? Token = await Login();
+            if (Token != null)
+            {
+                HttpClient http = CreateHttp();
+                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");
+
+                }
+                catch (Exception ex)
+                {
+                    throw ex;
+                }
+
+            }
+        }
+
         public async Task<List<Object>> CalZScore()
         {
             userToken? Token = await Login();

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

@@ -940,7 +940,8 @@ namespace wispro.sp.winClient
         private void button3_Click(object sender, EventArgs e)
         {
             //new PatentDocument(@"C:\temp\PI2023CN1303-优先权分析(1).docx");
-            var ret = new APIService().CalZScore();
+            //var ret = new APIService().CalZScore();
+            new APIService().testMail();
             //ret.Wait();
 
             //emlFileReader reader = new emlFileReader(@"D:\Users\luowen\Downloads\2f7e92c1-e009-4b19-ba8d-332e8f6f2ffc.eml");

+ 4 - 0
wospro.sp.entity/CompareCase/CaseInfo.cs

@@ -107,5 +107,9 @@ namespace wispro.sp.entity.CompareCase
         /// </summary>
         public int? RFRAllId { get; set; }
         public CompareResult RFRAll { get; set; }
+
+        public DateTime CreateTime { get; set; } = DateTime.Now;
+
+        public string AbnormalMessage {  get; set; }
     }
 }

+ 43 - 0
wospro.sp.entity/CompareCase/CustomerCompareStatistics.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace wispro.sp.entity.CompareCase
+{
+    public class CustomerCompareStatistics
+    {
+        public string CustomerName { get; set; }
+
+        public int CaseCount {  get; set; }
+
+        /// <summary>
+        /// 内部核稿权要差异度平均值
+        /// </summary>
+        public double Diff_Drafted_Claims_Avg {  get; set; }
+        /// <summary>
+        /// 内部核稿权要差异度标准方差
+        /// </summary>
+        public double Diff_Drafted_Claims_Std {  get; set; }
+
+        /// <summary>
+        /// 内部核稿权要差异度案件数量
+        /// </summary>
+        public int Diff_Drafted_Claims_Count {  get; set; }
+
+        /// <summary>
+        /// 外部核稿权要差异度平均值
+        /// </summary>
+        public double Diff_FinalDrafted_Claims_Avg { get; set; }
+        /// <summary>
+        /// 外部核稿权要差异度标准方差
+        /// </summary>
+        public double Diff_FinalDrafted_Claims_Std { get; set; }
+
+        /// <summary>
+        /// 外部核稿权要差异度案件数量
+        /// </summary>
+        public int Diff_FinalDrafted_Claims_Count { get; set; }
+    }
+}