CaseFileCompareController.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. using AntDesign;
  2. using DocumentFormat.OpenXml.InkML;
  3. using DocumentFormat.OpenXml.Presentation;
  4. using DynamicExpresso;
  5. using Microsoft.AspNetCore.Authorization;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.EntityFrameworkCore;
  9. using Microsoft.EntityFrameworkCore.Query;
  10. using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
  11. using NPOI.OpenXmlFormats.Vml.Spreadsheet;
  12. using NPOI.OpenXmlFormats.Wordprocessing;
  13. using System;
  14. using System.Collections;
  15. using System.Collections.Generic;
  16. using System.Data;
  17. using System.Diagnostics;
  18. using System.Dynamic;
  19. using System.Linq;
  20. using System.Linq.Expressions;
  21. using System.Text.RegularExpressions;
  22. using wispro.sp.api.AppealHandler;
  23. using wispro.sp.api.Job;
  24. using wispro.sp.api.Services;
  25. using wispro.sp.entity;
  26. using wispro.sp.entity.CompareCase;
  27. using wispro.sp.share;
  28. using static OneOf.Types.TrueFalseOrNull;
  29. namespace wispro.sp.api.Controllers
  30. {
  31. [Route("api/[controller]/[action]")]
  32. [ApiController]
  33. public class CaseFileCompareController : ControllerBase
  34. {
  35. spDbContext Context;
  36. IFileTaskService fileTaskService;
  37. public CaseFileCompareController(spDbContext context, IFileTaskService _fileTaskService)
  38. {
  39. Context = context;
  40. fileTaskService = _fileTaskService;
  41. }
  42. [Authorize]
  43. public ApiSaveResponse Save(CaseInfo caseInfo)
  44. {
  45. ApiSaveResponse ret = new ApiSaveResponse();
  46. ret.Success = true;
  47. using (Context.Database.BeginTransaction())
  48. {
  49. try
  50. {
  51. #region 客户处理
  52. if (caseInfo.Customer != null && !string.IsNullOrEmpty(caseInfo.Customer.Name))
  53. {
  54. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == caseInfo.Customer.Name).FirstOrDefault();
  55. if (temCustomer == null)
  56. {
  57. temCustomer = new Customer() { Name = caseInfo.Customer.Name };
  58. //item.Customer.Id = 0;
  59. Context.Customers.Add(temCustomer);
  60. Context.SaveChanges();
  61. caseInfo.Customer = temCustomer;
  62. //item.CustomerId = item.Customer.Id;
  63. }
  64. else
  65. {
  66. caseInfo.Customer = temCustomer;
  67. }
  68. caseInfo.CustomerId = caseInfo.Customer.Id;
  69. caseInfo.Customer = null;
  70. }
  71. else
  72. {
  73. caseInfo.Customer = null;
  74. }
  75. #endregion
  76. #region 审核人
  77. if (caseInfo.Reviewer != null && !string.IsNullOrEmpty(caseInfo.Reviewer.Name))
  78. {
  79. var temReviewer = Context.Staffs.Where<Staff>(c => c.Name == caseInfo.Reviewer.Name).FirstOrDefault();
  80. if (temReviewer == null)
  81. {
  82. temReviewer = new Staff() { Name = caseInfo.Reviewer.Name };
  83. //item.Customer.Id = 0;
  84. Context.Staffs.Add(temReviewer);
  85. Context.SaveChanges();
  86. caseInfo.Reviewer = temReviewer;
  87. //item.CustomerId = item.Customer.Id;
  88. }
  89. else
  90. {
  91. caseInfo.Reviewer = temReviewer;
  92. }
  93. caseInfo.ReviewerId = caseInfo.Reviewer.Id;
  94. caseInfo.Reviewer = null;
  95. }
  96. else
  97. {
  98. caseInfo.Reviewer = null;
  99. }
  100. #endregion
  101. if (caseInfo.DRRAbstract != null) {
  102. Context.CaseCompareResults.Add(caseInfo.DRRAbstract);
  103. Context.SaveChanges();
  104. caseInfo.DRRAbstractId = caseInfo.DRRAbstract.Id;
  105. caseInfo.DRRAbstract = null;
  106. }
  107. if (caseInfo.DRRCalim != null)
  108. {
  109. Context.CaseCompareResults.Add(caseInfo.DRRCalim);
  110. Context.SaveChanges();
  111. caseInfo.DRRCalimId = caseInfo.DRRCalim.Id;
  112. caseInfo.DRRCalim = null;
  113. }
  114. if (caseInfo.DRRFulltext != null)
  115. {
  116. Context.CaseCompareResults.Add(caseInfo.DRRFulltext);
  117. Context.SaveChanges();
  118. caseInfo.DRRFulltextId = caseInfo.DRRFulltext.Id;
  119. caseInfo.DRRFulltext = null;
  120. }
  121. if (caseInfo.DRRAll != null)
  122. {
  123. Context.CaseCompareResults.Add(caseInfo.DRRAll);
  124. Context.SaveChanges();
  125. caseInfo.DRRAllId = caseInfo.DRRAll.Id;
  126. caseInfo.DRRAll = null;
  127. }
  128. if (caseInfo.RFRAbstract != null)
  129. {
  130. Context.CaseCompareResults.Add(caseInfo.RFRAbstract);
  131. Context.SaveChanges();
  132. caseInfo.RFRAbstractId = caseInfo.RFRAbstract.Id;
  133. caseInfo.RFRAbstract = null;
  134. }
  135. if (caseInfo.RFRCalim != null)
  136. {
  137. Context.CaseCompareResults.Add(caseInfo.RFRCalim);
  138. Context.SaveChanges();
  139. caseInfo.RFRCalimId = caseInfo.RFRCalim.Id;
  140. caseInfo.RFRCalim = null;
  141. }
  142. if (caseInfo.RFRFulltext != null)
  143. {
  144. Context.CaseCompareResults.Add(caseInfo.RFRFulltext);
  145. Context.SaveChanges();
  146. caseInfo.RFRFulltextId = caseInfo.RFRFulltext.Id;
  147. caseInfo.RFRFulltext = null;
  148. }
  149. if (caseInfo.RFRAll != null)
  150. {
  151. Context.CaseCompareResults.Add(caseInfo.RFRAll);
  152. Context.SaveChanges();
  153. caseInfo.RFRAllId = caseInfo.RFRAll.Id;
  154. caseInfo.RFRAll = null;
  155. }
  156. Context.CaseInfos.Add(caseInfo);
  157. Context.SaveChanges();
  158. Context.Database.CommitTransaction();
  159. }
  160. catch (Exception ex)
  161. {
  162. ret.Success = false;
  163. ret.ErrorMessage = ex.Message;
  164. Context.Database.RollbackTransaction();
  165. }
  166. }
  167. return ret;
  168. }
  169. public ListApiResponse<CaseInfo> QueryFilter(QueryFilter queryFilter)
  170. {
  171. ListApiResponse<CaseInfo> ret = new ListApiResponse<CaseInfo>();
  172. IQueryable<CaseInfo> response = NewMethod(queryFilter);
  173. int totals = response.Count();
  174. if (totals > 0 && totals < (queryFilter.PageIndex) * queryFilter.PageSize)
  175. {
  176. response = response
  177. .Include(pi => pi.DRRCalim)
  178. .Include(pi => pi.DRRAbstract)
  179. .Include(pi => pi.DRRFulltext)
  180. .Include(pi => pi.DRRAll)
  181. .Include(pi => pi.RFRCalim)
  182. .Include(pi => pi.RFRAbstract)
  183. .Include(pi => pi.RFRFulltext)
  184. .Include(pi => pi.RFRAll)
  185. .Include(pi => pi.Customer)
  186. .Include(pi => pi.Reviewer)
  187. .OrderConditions<CaseInfo>(queryFilter.Sorts)
  188. .Skip((queryFilter.PageIndex - 1) * queryFilter.PageSize)
  189. .Take(totals - (queryFilter.PageIndex - 1) * queryFilter.PageSize);
  190. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  191. }
  192. else
  193. {
  194. response = response
  195. .Include(pi => pi.DRRCalim)
  196. .Include(pi => pi.DRRAbstract)
  197. .Include(pi => pi.DRRFulltext)
  198. .Include(pi=>pi.DRRAll)
  199. .Include(pi => pi.RFRCalim)
  200. .Include(pi => pi.RFRAbstract)
  201. .Include(pi => pi.RFRFulltext)
  202. .Include(pi => pi.RFRAll)
  203. .Include(pi => pi.Customer)
  204. .Include(pi => pi.Reviewer)
  205. .OrderConditions<CaseInfo>(queryFilter.Sorts)
  206. .Skip((queryFilter.PageIndex - 1) * queryFilter.PageSize)
  207. .Take(queryFilter.PageSize);
  208. }
  209. ret.TotalCount = totals;
  210. var retList = response.ToList<CaseInfo>();
  211. #region 将某些属性设为null,避免循环取值造成返回json过大
  212. foreach (CaseInfo item in retList)
  213. {
  214. if (item.Customer != null)
  215. {
  216. item.Customer.PerformanceItems = null;
  217. item.Customer.ResponseMan = null;
  218. }
  219. if (item.Reviewer != null)
  220. {
  221. item.Reviewer.Customers = null;
  222. item.Reviewer.ExternalHandlerItems = null;
  223. item.Reviewer.ItemStaffs = null;
  224. item.Reviewer.AllocationRatios = null;
  225. item.Reviewer.ReviewerItems = null;
  226. }
  227. }
  228. #endregion
  229. ret.Results = retList.ToList();
  230. return ret;
  231. }
  232. public bool CaseExist(string caseNo)
  233. {
  234. return Context.CaseInfos.Where(p => p.CaseNo == caseNo.Trim()).Count() > 0;
  235. }
  236. public static (double, double) UpdateStatistics(int n, double mean, double variance, double newValue)
  237. {
  238. double newMean = (n * mean + newValue) / (n + 1);
  239. double newVariance = Math.Sqrt((n * (mean - newMean) * (mean - newMean) + (newValue - newMean) * (newValue - newMean) + n * variance * variance) / (n + 1));
  240. return (newMean, newVariance);
  241. }
  242. /// <summary>
  243. /// 计算指定日期之前一年的指定客户的平均权利要求差异度和标准方差
  244. /// </summary>
  245. /// <param name="endDate">结束日期</param>
  246. /// /// <param name="customerName">客户名称,默认不指定,获取所有客户的平均权利要求差异度和标准方差</param>
  247. /// <returns></returns>
  248. private List<CustomerCompareStatistics> getLaseYearMean_Variance(DateTime endDate,List<CaseInfo> caseList,string customerName=null)
  249. {
  250. if(caseList == null)
  251. {
  252. caseList = Context.CaseInfos.Where<CaseInfo>(
  253. p => p.CreateTime >= endDate.AddYears(-1) &&
  254. p.CreateTime <= endDate &&
  255. p.Customer.Name == customerName
  256. )
  257. .Include(p => p.Customer)
  258. .Include(p => p.Reviewer)
  259. .Include(p => p.DRRAbstract)
  260. .Include(p => p.DRRAbstract)
  261. .Include(p => p.DRRCalim)
  262. .Include(p => p.DRRFulltext)
  263. .Include(p => p.DRRAll)
  264. .Include(p => p.RFRAbstract)
  265. .Include(p => p.RFRCalim)
  266. .Include(p => p.RFRFulltext)
  267. .Include(p => p.RFRAll)
  268. .ToList();
  269. }
  270. //IIncludableQueryable<CaseInfo, CompareResult> caseList;
  271. var temcaseList = caseList;
  272. if (customerName != null) {
  273. temcaseList = caseList.Where(p=> p.Customer.Name == customerName)
  274. .ToList();
  275. }
  276. List < CustomerCompareStatistics > retList = new List < CustomerCompareStatistics >();
  277. foreach ( var item in temcaseList)
  278. {
  279. var temObj = retList.Where(p=>p.CustomerName == item.Customer.Name).FirstOrDefault<CustomerCompareStatistics>();
  280. if(temObj == null) {
  281. temObj = new CustomerCompareStatistics();
  282. temObj.CustomerName = item.Customer.Name;
  283. retList.Add(temObj);
  284. }
  285. temObj.CaseCount += 1;
  286. if (item.DRRCalim != null)
  287. {
  288. if (temObj.Diff_FinalDrafted_Claims_Count > 0) {
  289. var retStatistics = UpdateStatistics(temObj.Diff_Drafted_Claims_Count, temObj.Diff_Drafted_Claims_Avg, temObj.Diff_Drafted_Claims_Std, item.DRRCalim.diffRate);
  290. temObj.Diff_Drafted_Claims_Std = retStatistics.Item2;
  291. temObj.Diff_Drafted_Claims_Avg = retStatistics.Item1;
  292. temObj.Diff_Drafted_Claims_Count += 1;
  293. }
  294. else
  295. {
  296. temObj.Diff_Drafted_Claims_Std = 0.0;
  297. temObj.Diff_Drafted_Claims_Avg = item.DRRCalim.diffRate;
  298. temObj.Diff_Drafted_Claims_Count = 1;
  299. }
  300. }
  301. if (item.RFRCalim != null)
  302. {
  303. if (temObj.Diff_FinalDrafted_Claims_Count > 0)
  304. {
  305. var retStatistics = UpdateStatistics(temObj.Diff_FinalDrafted_Claims_Count, temObj.Diff_FinalDrafted_Claims_Avg, temObj.Diff_FinalDrafted_Claims_Std, item.RFRCalim.diffRate);
  306. temObj.Diff_FinalDrafted_Claims_Std = retStatistics.Item2;
  307. temObj.Diff_FinalDrafted_Claims_Avg = retStatistics.Item1;
  308. temObj.Diff_FinalDrafted_Claims_Count += 1;
  309. }
  310. else
  311. {
  312. temObj.Diff_FinalDrafted_Claims_Std = 0.0;
  313. temObj.Diff_FinalDrafted_Claims_Avg = item.RFRCalim.diffRate;
  314. temObj.Diff_FinalDrafted_Claims_Count = 1;
  315. }
  316. }
  317. }
  318. return retList;
  319. }
  320. /// <summary>
  321. /// 获取指定时间内客户的权要修改差异率最高的10各案件
  322. /// </summary>
  323. /// <param name="start">开始日期</param>
  324. /// <param name="end">结束日期</param>
  325. /// <param name="customerName">客户名称</param>
  326. /// <param name="type">类型:
  327. /// 0:外部核稿差异率,默认值,
  328. /// 1:内部核稿差异率
  329. /// </param>
  330. /// <returns></returns>
  331. private List<CaseInfo> getTop10DiffRateCases(DateTime start, DateTime end,string customerName,int type=0,List<CaseInfo> caseList=null)
  332. {
  333. if (caseList == null) {
  334. caseList = Context.CaseInfos.Where<CaseInfo>(
  335. p => p.CreateTime >= end.AddYears(-1) &&
  336. p.CreateTime <= end &&
  337. p.Customer.Name == customerName
  338. )
  339. .Include(p => p.Customer)
  340. .Include(p => p.Reviewer)
  341. .Include(p => p.DRRAbstract)
  342. .Include(p => p.DRRAbstract)
  343. .Include(p => p.DRRCalim)
  344. .Include(p => p.DRRFulltext)
  345. .Include(p => p.DRRAll)
  346. .Include(p => p.RFRAbstract)
  347. .Include(p => p.RFRCalim)
  348. .Include(p => p.RFRFulltext)
  349. .Include(p => p.RFRAll)
  350. .ToList();
  351. }
  352. if (type == 0) {
  353. var top10Case = caseList.Where<CaseInfo>(p=>p.Customer.Name == customerName)
  354. .OrderByDescending(p => p.RFRCalim?.diffRate).Take(10);
  355. return top10Case.Where<CaseInfo>(c=>c.CreateTime>=start).ToList();
  356. }
  357. else
  358. {
  359. var top10Case = caseList.Where<CaseInfo>(p => p.Customer.Name == customerName)
  360. .OrderByDescending(p => p.DRRCalim?.diffRate).Take(10);
  361. return top10Case.Where<CaseInfo>(c => c.CreateTime >= start).ToList();
  362. }
  363. }
  364. /// <summary>
  365. /// 获取指定时间内客户权要修改差异度计算出的异常案件
  366. /// </summary>
  367. /// <param name="start">开始日期</param>
  368. /// <param name="end">结束日期</param>
  369. /// <param name="customerName">客户名称</param>
  370. /// <returns></returns>
  371. private List<CaseInfo> GetAbnormalCases(DateTime start, DateTime end, string customerName,List<CaseInfo> caseList)
  372. {
  373. var customerStatics = getLaseYearMean_Variance(end, caseList,customerName);
  374. var cStatics = customerStatics.Where(s => s.CustomerName == customerName).FirstOrDefault();
  375. return _GetAbnormalCases(start, end, customerName, cStatics,caseList);
  376. }
  377. private List<CaseInfo> _GetAbnormalCases(DateTime start, DateTime end, string customerName, CustomerCompareStatistics cStatics,List<CaseInfo> caseList)
  378. {
  379. if (cStatics != null)
  380. {
  381. if (caseList == null) {
  382. caseList = Context.CaseInfos.Where<CaseInfo>(
  383. p => p.CreateTime >= end.AddYears(-1) &&
  384. p.CreateTime <= end &&
  385. p.Customer.Name == customerName
  386. )
  387. .Include(p => p.Customer)
  388. .Include(p => p.Reviewer)
  389. .Include(p => p.DRRAbstract)
  390. .Include(p => p.DRRAbstract)
  391. .Include(p => p.DRRCalim)
  392. .Include(p => p.DRRFulltext)
  393. .Include(p => p.DRRAll)
  394. .Include(p => p.RFRAbstract)
  395. .Include(p => p.RFRCalim)
  396. .Include(p => p.RFRFulltext)
  397. .Include(p => p.RFRAll)
  398. .ToList();
  399. }
  400. var retList = new List<CaseInfo>();
  401. var temCaseList = caseList.Where(p=>p.Customer.Name== customerName).ToList();
  402. foreach (var item in temCaseList)
  403. {
  404. if (item.CreateTime >= start)
  405. {
  406. double first = item.DRRCalim == null ? 0.0 : item.DRRCalim.diffRate;
  407. double second = item.RFRCalim == null ? 0.0 : item.RFRCalim.diffRate;
  408. double score1 = (first - cStatics.Diff_Drafted_Claims_Avg) / cStatics.Diff_Drafted_Claims_Std;
  409. double score2 = (second - cStatics.Diff_FinalDrafted_Claims_Avg) / cStatics.Diff_FinalDrafted_Claims_Std;
  410. double score = Math.Sqrt(score1 * score1 + score2 * score2);
  411. if (score > 3.0)
  412. {
  413. if (score2 > 0)
  414. {
  415. if (score1 < 0)
  416. {
  417. item.AbnormalMessage = $"内部核稿修改相对少,外部修改相对很多!【核稿人不给力/沟通有问题?】,【分数为:{score.ToString("0.00")}】";
  418. }
  419. else
  420. {
  421. item.AbnormalMessage = $"内部核稿相对多,外部修改也相对多!【沟通有问题?】,【分数为:{score.ToString("0.00")}】";
  422. }
  423. }
  424. else
  425. {
  426. if (score1 < 0)
  427. {
  428. item.AbnormalMessage = $"内部核稿修改相对少,外部修改相对少!【撰稿人给力】,【分数为:{score.ToString("0.00")}】";
  429. }
  430. else
  431. {
  432. item.AbnormalMessage = $"内部核稿相对多,外部修改也相对少!【核稿人给力】,【分数为:{score.ToString("0.00")}】";
  433. }
  434. }
  435. retList.Add(item);
  436. }
  437. }
  438. }
  439. return retList;
  440. }
  441. else
  442. {
  443. return new List<CaseInfo>();
  444. }
  445. }
  446. internal class mailCaseInfo
  447. {
  448. public CustomerCompareStatistics CustomerCompareStatistics { get; set; }
  449. public List<CaseInfo> Top10Cases { get; set; } = new List<CaseInfo>();
  450. public List<CaseInfo> AbnormalCases { get; set; }= new List<CaseInfo>();
  451. }
  452. public void getMailCaseInfo(DateTime start, DateTime end)
  453. {
  454. var caseList = Context.CaseInfos.Where<CaseInfo>(
  455. p => p.CreateTime >= end.AddYears(-1) &&
  456. p.CreateTime <= end
  457. )
  458. .Include(p => p.Customer)
  459. .Include(p => p.Reviewer)
  460. .Include(p => p.DRRAbstract)
  461. .Include(p => p.DRRAbstract)
  462. .Include(p => p.DRRCalim)
  463. .Include(p => p.DRRFulltext)
  464. .Include(p => p.DRRAll)
  465. .Include(p => p.RFRAbstract)
  466. .Include(p => p.RFRCalim)
  467. .Include(p => p.RFRFulltext)
  468. .Include(p => p.RFRAll)
  469. .ToList();
  470. List<string> defaultStaffNames = new List<string>() { "罗才洋","李庆波","钟子敏"};
  471. var DefaultEmailAccounts = Context.Staffs.Where(p => defaultStaffNames.Contains(p.Name)).ToList();
  472. var customerStatics = getLaseYearMean_Variance(end,caseList);
  473. Hashtable staffMailInfo = new Hashtable();
  474. foreach (var cStatics in customerStatics)
  475. {
  476. if(cStatics.CaseCount < 20)
  477. {
  478. continue;
  479. }
  480. //var cStatics = customerStatics.Where(s => s.CustomerName == item.Customer.Name).FirstOrDefault();
  481. var Top10Cases =getTop10DiffRateCases(start, end, cStatics.CustomerName,0,caseList);
  482. foreach (var caseInfo in Top10Cases)
  483. {
  484. foreach (Staff staff in DefaultEmailAccounts)
  485. {
  486. AddtoHashTable(caseInfo, 0, staff, staffMailInfo, cStatics);
  487. }
  488. if (caseInfo.Reviewer != null)
  489. {
  490. AddtoHashTable(caseInfo,0, caseInfo.Reviewer,staffMailInfo,cStatics);
  491. }
  492. if (caseInfo.Customer.ResponseManId != null)
  493. {
  494. Staff respMan = Context.Staffs.FirstOrDefault<Staff>(p => p.Id == caseInfo.Customer.ResponseManId);
  495. if (respMan != null)
  496. {
  497. AddtoHashTable(caseInfo, 0, respMan, staffMailInfo, cStatics);
  498. }
  499. }
  500. }
  501. var AbnormalCases = _GetAbnormalCases(start,end, cStatics.CustomerName, cStatics,caseList);
  502. foreach (var caseInfo in AbnormalCases)
  503. {
  504. foreach(Staff staff in DefaultEmailAccounts)
  505. {
  506. AddtoHashTable(caseInfo, 1, staff, staffMailInfo, cStatics);
  507. }
  508. if (caseInfo.Reviewer != null)
  509. {
  510. AddtoHashTable(caseInfo, 1, caseInfo.Reviewer, staffMailInfo, cStatics);
  511. }
  512. if (caseInfo.Customer.ResponseManId != null)
  513. {
  514. Staff respMan = Context.Staffs.FirstOrDefault<Staff>(p => p.Id == caseInfo.Customer.ResponseManId);
  515. if (respMan != null)
  516. {
  517. AddtoHashTable(caseInfo, 1, respMan, staffMailInfo, cStatics);
  518. }
  519. }
  520. }
  521. }
  522. if (staffMailInfo.Count > 0) {
  523. foreach (var key in staffMailInfo.Keys)
  524. {
  525. Staff staff = key as Staff;
  526. List<mailCaseInfo> mailCases = (List<mailCaseInfo>)staffMailInfo[key];
  527. string strMessage = string.Empty ;
  528. foreach(var m in mailCases)
  529. {
  530. if ((m.Top10Cases != null && m.Top10Cases.Count > 0) || (m.AbnormalCases != null && m.AbnormalCases.Count > 0))
  531. {
  532. strMessage += $"<br/><div><b>{m.CustomerCompareStatistics.CustomerName}:</b>";
  533. strMessage += $"<br/>一年内案件数量:{m.CustomerCompareStatistics.CaseCount}";
  534. strMessage += $"<br/>内部核稿平均修改率:{m.CustomerCompareStatistics.Diff_Drafted_Claims_Avg}&nbsp;&nbsp;内部核稿修改率标准方差:{m.CustomerCompareStatistics.Diff_Drafted_Claims_Std}";
  535. strMessage += $"<br/>外部部核稿平均修改率:{m.CustomerCompareStatistics.Diff_FinalDrafted_Claims_Avg}&nbsp;&nbsp;外部核稿修改率标准方差:{m.CustomerCompareStatistics.Diff_FinalDrafted_Claims_Std}</div>";
  536. if (m.Top10Cases != null && m.Top10Cases.Count > 0)
  537. {
  538. strMessage += $"<div>外部核稿修改率前10名案件清单:</div>";
  539. strMessage += "<table border='1'><thead><td>案号</td><td>案件名称</td><td>处理人</td><td>核稿人</td><td>内部核稿修改率(%)</td><td>外部核稿修改率(%)</td></thead><body>";
  540. foreach (var c in m.Top10Cases)
  541. {
  542. 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>";
  543. }
  544. strMessage += "</body></table>";
  545. }
  546. if (m.AbnormalCases != null && m.AbnormalCases.Count > 0)
  547. {
  548. strMessage += $"<br/><div>疑似异常案件清单:</div>";
  549. strMessage += "<table border='1'><thead><td>案号</td><td>案件名称</td><td>处理人</td><td>核稿人</td><td>内部核稿修改率</td><td>外部核稿修改率</td><td>异常说明</td></thead><body>";
  550. foreach (var c in m.AbnormalCases)
  551. {
  552. 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>";
  553. }
  554. strMessage += "</body></table><br/>";
  555. }
  556. strMessage += "</div>";
  557. }
  558. }
  559. string strTem = $"如下是{start.ToString("yyyy-MM-dd")}到{end.ToString("yyyy-MM-dd")}国内专利申请案件在客户核稿处于年内修改率前10名的案件和疑似异常案件清单,请关注!";
  560. string strBody = $"<div><div>{staff.Name},你好!</div><br/><div>{strTem}</div>{strMessage}<br/><div >小美集团绩效管理系统</div></div>";
  561. staff.Mail = "luocaiyang@china-wispro.com";
  562. _ = QuartzUtil.AddMailJob($"{start.ToString("yyyyMMdd")}-{end.ToString("yyyyMMdd")}申请文件比较邮件", strBody, staff.Name, staff.Mail);
  563. }
  564. }
  565. }
  566. private void AddtoHashTable(CaseInfo caseInfo, int v, Staff staff, Hashtable staffMailInfo,CustomerCompareStatistics cStatics)
  567. {
  568. var staffCaseMailInfo = new mailCaseInfo()
  569. {
  570. CustomerCompareStatistics = cStatics,
  571. };
  572. List<mailCaseInfo> staffCaseMailInfos = new List<mailCaseInfo>();
  573. if (staffMailInfo.ContainsKey(staff))
  574. {
  575. staffCaseMailInfos = (List<mailCaseInfo>)staffMailInfo[staff];
  576. }
  577. else
  578. {
  579. staffMailInfo.Add(staff,staffCaseMailInfos);
  580. }
  581. var temObj = staffCaseMailInfos.Where(p => p.CustomerCompareStatistics.CustomerName == caseInfo.Customer.Name).FirstOrDefault();
  582. if (temObj != null)
  583. {
  584. staffCaseMailInfo = temObj;
  585. }
  586. else
  587. {
  588. staffCaseMailInfos.Add(staffCaseMailInfo);
  589. }
  590. if (v == 0)
  591. {
  592. staffCaseMailInfo.Top10Cases.Add(caseInfo);
  593. }
  594. else
  595. {
  596. staffCaseMailInfo.AbnormalCases.Add(caseInfo);
  597. }
  598. }
  599. private class retObject
  600. {
  601. public string CaseNo { get; set; }
  602. public string CaseName { get; set; }
  603. public string Customer { get; set; }
  604. public string Handers { get; set; }
  605. public string Reviewer { get; set; }
  606. public double? InternalSim { get; set; }
  607. public double? InternalAvg { get; set; }
  608. public double? InternalStd { get; set; }
  609. public double? InternalScore { get; set; }
  610. public double? CustomerSim { get; set; }
  611. public double? CustomerAvg { get; set; }
  612. public double? CustomerStd { get; set; }
  613. public double? CustomerScore { get; set; }
  614. public string Memo { get; set; }
  615. public DateTime? FinishedDate { get; set; }
  616. }
  617. private DataTable CoverttoDatable(List<retObject> ObjList)
  618. {
  619. System.Data.DataTable dt = new System.Data.DataTable();
  620. dt.Columns.Add("我方文号");
  621. dt.Columns.Add("案件名称");
  622. dt.Columns.Add("客户");
  623. dt.Columns.Add("处理人");
  624. dt.Columns.Add("核稿人");
  625. dt.Columns.Add("内部核稿权要差异度");
  626. dt.Columns.Add("内部客户平均值");
  627. dt.Columns.Add("内部客户标准偏差");
  628. dt.Columns.Add("内部核稿分数");
  629. dt.Columns.Add("外部核稿权要差异度");
  630. dt.Columns.Add("外部客户平均值");
  631. dt.Columns.Add("外部客户标准偏差");
  632. dt.Columns.Add("外部核稿分数");
  633. dt.Columns.Add("备注");
  634. foreach (var temObj in ObjList)
  635. {
  636. DataRow row = dt.NewRow();
  637. row["我方文号"] = temObj.CaseNo;
  638. row["案件名称"] = temObj.CaseName;
  639. row["客户"] = temObj.Customer;
  640. row["核稿人"] = temObj.Reviewer;
  641. row["处理人"] = temObj.Handers;
  642. row["内部核稿分数"] = temObj.InternalScore;
  643. row["内部核稿权要差异度"] = temObj.InternalSim;
  644. row["内部客户平均值"] = temObj.InternalAvg;
  645. row["内部客户标准偏差"] = temObj.InternalStd;
  646. row["内部核稿分数"] = temObj.InternalScore;
  647. row["外部核稿权要差异度"] = temObj.CustomerSim;
  648. row["外部客户平均值"] = temObj.CustomerAvg;
  649. row["外部客户标准偏差"] = temObj.CustomerStd;
  650. row["外部核稿分数"] = temObj.CustomerScore;
  651. row["备注"] = temObj.Memo;
  652. dt.Rows.Add(row);
  653. }
  654. return dt;
  655. }
  656. /// <summary>
  657. /// 计算案件的zScore
  658. /// </summary>
  659. /// <param name="start">定稿日开始时间</param>
  660. /// <param name="end">定稿日结束时间</param>
  661. /// <param name="type">
  662. /// 0:基于文本相似度计算,
  663. /// 1:基于文本修改差异度计算
  664. /// 2:基于权要权重70说明书30计算
  665. /// 3:基于权要文本相似度计算
  666. /// 4: 基于权要文字修改差异度计算
  667. /// </param>
  668. /// <returns></returns>
  669. private IList<retObject> CalCustomer_mean(DateTime start,DateTime end,int type=0)
  670. {
  671. var caseList = Context.CaseInfos.Where<CaseInfo>(
  672. p => p.CreateTime >= start && p.CreateTime < end)
  673. .Include(p=>p.Customer)
  674. .Include(p=>p.Reviewer)
  675. .Include(p=>p.DRRAbstract)
  676. .Include(p => p.DRRAbstract)
  677. .Include(p => p.DRRCalim)
  678. .Include(p => p.DRRFulltext)
  679. .Include(p => p.DRRAll)
  680. .Include(p => p.RFRAbstract)
  681. .Include(p => p.RFRCalim)
  682. .Include(p => p.RFRFulltext)
  683. .Include(p => p.RFRAll);
  684. int iTotals = caseList.Count();
  685. int iIndex = 0;
  686. List<retObject> retList = new List<retObject>();
  687. #region 计算客户相似度平均值和标准方差
  688. List<CustomerAvg_Std> avg_std1 = new List<CustomerAvg_Std>();
  689. List<CustomerAvg_Std> avg_std2 = new List<CustomerAvg_Std>();
  690. foreach (var caseInfo in caseList)
  691. {
  692. iIndex++;
  693. Debug.WriteLine($"{iIndex}/{iTotals}\t{caseInfo.CaseNo}\t{caseInfo.DRRAbstractId},{caseInfo.DRRCalimId},{caseInfo.DRRFulltextId},{caseInfo.DRRAllId},{caseInfo.RFRAbstractId},{caseInfo.RFRCalimId},{caseInfo.RFRFulltextId},{caseInfo.RFRAllId}");
  694. string tmpCustomerName = "未知";
  695. if(caseInfo.Customer!= null)
  696. {
  697. tmpCustomerName = caseInfo.Customer.Name;
  698. }
  699. var one = avg_std1.Where<CustomerAvg_Std>(p => p.Name == tmpCustomerName).FirstOrDefault();
  700. if (one == null)
  701. {
  702. one = new CustomerAvg_Std() { Name = tmpCustomerName };
  703. avg_std1.Add(one);
  704. }
  705. var two = avg_std2.Where<CustomerAvg_Std>(p => p.Name == tmpCustomerName).FirstOrDefault();
  706. if (two == null)
  707. {
  708. two = new CustomerAvg_Std() { Name = tmpCustomerName };
  709. avg_std2.Add(two);
  710. }
  711. double? oneTmp = getCalValue(caseInfo, type, 0);
  712. if(oneTmp != null)
  713. {
  714. one.Sum += oneTmp.Value;
  715. one.SquareSum += oneTmp.Value * oneTmp.Value;
  716. one.count += 1;
  717. }
  718. double? twoTmp = getCalValue(caseInfo, type, 1);
  719. if (twoTmp != null)
  720. {
  721. two.Sum += twoTmp.Value;
  722. two.SquareSum += twoTmp.Value * twoTmp.Value;
  723. two.count += 1;
  724. }
  725. }
  726. #endregion
  727. foreach (var item in caseList)
  728. {
  729. retObject temObj = new retObject();
  730. string tmpCustomerName = "未知";
  731. if (item.Customer != null)
  732. {
  733. tmpCustomerName = item.Customer.Name;
  734. }
  735. var one = avg_std1.Where<CustomerAvg_Std>(p => p.Name == tmpCustomerName).FirstOrDefault();
  736. var two = avg_std2.Where<CustomerAvg_Std>(p => p.Name == tmpCustomerName).FirstOrDefault();
  737. double? oneSim = getCalValue(item,type,0);
  738. double? twoSim = getCalValue(item, type, 1);
  739. temObj.FinishedDate = item.CreateTime;
  740. temObj.CaseNo = item.CaseNo;
  741. temObj.CaseName = item.CaseName;
  742. temObj.Customer = item.Customer?.Name;
  743. temObj.Reviewer = item.Reviewer?.Name;
  744. temObj.Handers = item.Handlers;
  745. double? zScoreA = null;
  746. if (oneSim != null)
  747. {
  748. zScoreA = (oneSim - one.Average) / one.Std_Deviation;
  749. }
  750. temObj.InternalScore = zScoreA;
  751. temObj.InternalSim = oneSim;
  752. temObj.InternalAvg = one.Average;
  753. temObj.InternalStd = one.Std_Deviation;
  754. double? zScoreB = null;
  755. if (twoSim != null)
  756. {
  757. zScoreB = (twoSim - two.Average) / two.Std_Deviation;
  758. }
  759. temObj.CustomerSim = twoSim;
  760. temObj.CustomerAvg = two.Average;
  761. temObj.CustomerStd = two.Std_Deviation;
  762. temObj.CustomerScore = zScoreB;
  763. string strMemo = "";
  764. zScoreA = (zScoreA == null) ? 0 : zScoreA;
  765. zScoreB = (zScoreB == null) ? 0 : zScoreB;
  766. if (zScoreA != null && zScoreB != null)
  767. {
  768. var distince = Math.Sqrt(zScoreB.Value * zScoreB.Value + zScoreA.Value * zScoreA.Value);
  769. if (type == 0 || type == 2 || type==3)
  770. {
  771. if (distince > 3)
  772. {
  773. if (zScoreA.Value > 0 && zScoreB.Value > 0)
  774. {
  775. strMemo = "内部核稿、外部核稿修改都较少![撰稿人给力或客户友好]";
  776. }
  777. if (zScoreA.Value > 0 && zScoreB.Value < 0)
  778. {
  779. strMemo = "内部核稿较少、外部核稿修改较多![核稿人没有尽责!]";
  780. }
  781. if (zScoreA.Value < 0 && zScoreB.Value > 0)
  782. {
  783. strMemo = "内部核稿较多、外部核稿修改都较少![核稿人给力]";
  784. }
  785. if (zScoreA.Value < 0 && zScoreB.Value < 0)
  786. {
  787. strMemo = "内部核稿和外部核稿修改都较多![案件沟通问题?]";
  788. }
  789. }
  790. }
  791. else
  792. {
  793. if (distince > 3)
  794. {
  795. if (zScoreA.Value > 0 && zScoreB.Value > 0)
  796. {
  797. strMemo = "内部核稿和外部核稿修改都较多![案件沟通问题?]";
  798. }
  799. if (zScoreA.Value > 0 && zScoreB.Value < 0)
  800. {
  801. strMemo = "内部核稿较多、外部核稿修改都较少![核稿人给力]";
  802. }
  803. if (zScoreA.Value < 0 && zScoreB.Value > 0)
  804. {
  805. strMemo = "内部核稿较少、外部核稿修改较多![核稿人没有尽责!]";
  806. }
  807. if (zScoreA.Value < 0 && zScoreB.Value < 0)
  808. {
  809. strMemo = "内部核稿、外部核稿修改都较少![撰稿人给力或客户友好]";
  810. }
  811. }
  812. }
  813. }
  814. temObj.Memo = strMemo;
  815. retList.Add(temObj);
  816. }
  817. //wispro.sp.utility.NPOIExcel.DataTableToExcel(dt,$"c:\\temp\\{DateTime.Now.ToString("yyyyMMdd")}-内部核稿外部核稿情况案件清单_{typeName(type)}.xlsx");
  818. return retList;
  819. }
  820. public void MonthlyReport(int year,int month)
  821. {
  822. #region 获取一年的案件清单,并计算个案件的清单
  823. DateTime endDate = new DateTime(year, month + 1, 1);
  824. DateTime yStartDate = endDate.AddYears(-1);
  825. var retList = CalCustomer_mean(yStartDate, endDate, 4);
  826. #endregion
  827. DateTime mStartDate = new DateTime(year, month, 1);
  828. #region 获取前客户修改前10名的案件清单
  829. var monthItemList = retList.Where<retObject>(
  830. r => r.FinishedDate >= mStartDate && r.FinishedDate < endDate);
  831. var top10List = monthItemList.OrderByDescending(r => r.CustomerSim)
  832. .Take(10).ToList();
  833. Hashtable reviewerHash = new Hashtable(); //核稿人
  834. Hashtable crHash = new Hashtable(); //客户对接人
  835. Hashtable dphash = new Hashtable(); //部长
  836. foreach (var item in top10List)
  837. {
  838. #region 核稿人
  839. if (!string.IsNullOrEmpty(item.Reviewer)) {
  840. Staff reviewer = Context.Staffs.Where(s => s.Name == item.Reviewer).FirstOrDefault();
  841. List<retObject> rets = new List<retObject>();
  842. foreach (Staff k in reviewerHash.Keys)
  843. {
  844. if (k.Id == reviewer.Id)
  845. {
  846. rets = (List<retObject>)reviewerHash[k];
  847. break;
  848. }
  849. }
  850. if (rets.Count == 0)
  851. {
  852. reviewerHash.Add(reviewer, rets);
  853. }
  854. rets.Add(item);
  855. }
  856. #endregion
  857. #region 客户对接人
  858. if (!string.IsNullOrEmpty(item.Customer)) {
  859. Customer c = Context.Customers.Where(s => s.Name == item.Customer)
  860. .Include(s=>s.ResponseMan).FirstOrDefault();
  861. if (c != null && c.ResponseMan != null)
  862. {
  863. List<retObject> rets = new List<retObject>();
  864. foreach (Staff k in crHash.Keys)
  865. {
  866. if (k.Id == c.ResponseManId)
  867. {
  868. rets = (List<retObject>)crHash[k];
  869. break;
  870. }
  871. }
  872. if (rets.Count == 0)
  873. {
  874. crHash.Add(c.ResponseMan, rets);
  875. }
  876. rets.Add(item);
  877. }
  878. }
  879. #endregion
  880. #region 部长
  881. string[] Handlers = item.Handers.Split(",");
  882. foreach(string n in Handlers)
  883. {
  884. var dpList = Context.DepartmentPositions.Where(d => d.Staff.Name == n).Include(d => d.department).ToList();
  885. foreach(var dp in dpList)
  886. {
  887. var dpObj = Context.DepartmentPositions.Where(d => d.departmentId == dp.departmentId && d.Position.Name == "部长").Include(d => d.Staff).FirstOrDefault();
  888. if(dpObj!= null)
  889. {
  890. List<retObject> rets = new List<retObject>();
  891. foreach(Staff k in dphash.Keys)
  892. {
  893. if(k.Id == dpObj.StaffId)
  894. {
  895. rets = (List<retObject>)dphash[k];
  896. break;
  897. }
  898. }
  899. if (rets.Count ==0)
  900. {
  901. dphash.Add(dpObj.Staff, rets);
  902. }
  903. if(!rets.Contains(item))
  904. rets.Add(item);
  905. }
  906. }
  907. }
  908. #endregion
  909. }
  910. foreach(Staff sf in reviewerHash.Keys)
  911. {
  912. List<retObject> temList = (List<retObject>)reviewerHash[sf];
  913. DataTable temdt = CoverttoDatable(temList);
  914. string strPath = $"{year}年{month}月客户修改权要排名前10的案件清单(审核人).xlsx";
  915. utility.NPOIExcel.DataTableToExcel(temdt, strPath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
  916. string strBody = $"{sf.Name},你好!<br>附件中的案件是{year}年{month}月您核稿的案件,客户权要修改率在前10的案件,请注意核稿质量!";
  917. _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", strBody, sf.Name, sf.Mail, $"{strPath}");
  918. }
  919. foreach (Staff sf in crHash.Keys)
  920. {
  921. List<retObject> temList = (List<retObject>)crHash[sf];
  922. DataTable temdt = CoverttoDatable(temList);
  923. string strPath = $"{year}年{month}月客户修改权要排名前10的案件清单(客户对接人).xlsx";
  924. utility.NPOIExcel.DataTableToExcel(temdt, strPath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
  925. string strBody = $"{sf.Name},你好!<br>附件中的案件是{year}年{month}月你对接的客户的案件,客户权要修改率在前10的案件,请注意!";
  926. _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", strBody, sf.Name, sf.Mail, $"{strPath}");
  927. }
  928. foreach (Staff sf in dphash.Keys)
  929. {
  930. List<retObject> temList = (List<retObject>)dphash[sf];
  931. DataTable temdt = CoverttoDatable(temList);
  932. string strPath = $"{year}年{month}月客户修改权要排名前10的案件清单(部长).xlsx";
  933. utility.NPOIExcel.DataTableToExcel(temdt, strPath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
  934. string strBody = $"{sf.Name},你好!<br>附件中的案件是{year}年{month}月贵部人员处理的,客户权要修改率在前10的案件,请注意!";
  935. _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", strBody, sf.Name, sf.Mail, $"{strPath}");
  936. }
  937. DataTable dt = CoverttoDatable(top10List);
  938. string top10_filePath = $"{year}年{month}月客户修改权要排名前10的案件清单.xlsx";
  939. utility.NPOIExcel.DataTableToExcel(dt, top10_filePath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
  940. #endregion
  941. #region 获取疑似问题清单
  942. var excItemList = monthItemList.Where<retObject>(r => string.IsNullOrEmpty(r.Memo) == false)
  943. .OrderBy(r => r.Customer).ThenByDescending(r => r.CustomerSim)
  944. .ToList();
  945. DataTable excdt = CoverttoDatable(excItemList);
  946. string except_filePath = $"{year}年{month}月疑似有问题的案件清单.xlsx";
  947. utility.NPOIExcel.DataTableToExcel(excdt, except_filePath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
  948. #endregion
  949. #region 所有案件清单
  950. var allItemList = monthItemList
  951. .OrderBy(r => r.Customer).ThenByDescending(r=>r.CustomerSim)
  952. .ToList();
  953. DataTable alldt = CoverttoDatable(allItemList);
  954. string all_filePath = $"{year}年{month}月案件清单.xlsx";
  955. utility.NPOIExcel.DataTableToExcel(alldt, all_filePath, true, true, 0, "http://1.116.113.26/CompareFile/detail/{0}");
  956. #endregion
  957. #region 发邮件
  958. _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "罗才洋", "luocaiyang@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
  959. _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "李庆波", "liqingbo@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
  960. _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "钟子敏", "zhongzimin@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
  961. _ = QuartzUtil.AddMailJob($"{year}年{month}月申请文件比较邮件", "FYI!", "王姝然", "zhongzimin@china-wispro.com", $"{all_filePath};{except_filePath};{top10_filePath}");
  962. #endregion
  963. }
  964. private double? getCalValue(CaseInfo caseInfo,int type,int stage)
  965. {
  966. double? calValue = null;
  967. switch (type)
  968. {
  969. case 0:
  970. if(stage == 0)
  971. {
  972. if(caseInfo.DRRFulltext != null && caseInfo.DRRAbstract != null)
  973. {
  974. calValue = caseInfo.DRRAll.TextSimilarity;
  975. }
  976. else
  977. {
  978. if(caseInfo.DRRCalim != null)
  979. {
  980. calValue = caseInfo.DRRCalim.TextSimilarity;
  981. }
  982. }
  983. }
  984. else
  985. {
  986. if (caseInfo.RFRFulltext != null && caseInfo.RFRAbstract != null)
  987. {
  988. calValue = caseInfo.RFRAll.TextSimilarity;
  989. }
  990. else
  991. {
  992. if (caseInfo.RFRCalim != null)
  993. {
  994. calValue = caseInfo.RFRCalim.TextSimilarity;
  995. }
  996. }
  997. }
  998. break;
  999. case 1:
  1000. if (stage == 0)
  1001. {
  1002. if (caseInfo.DRRFulltext != null && caseInfo.DRRAbstract != null)
  1003. {
  1004. calValue = caseInfo.DRRAll.diffRate;
  1005. }
  1006. else
  1007. {
  1008. if (caseInfo.DRRCalim != null)
  1009. {
  1010. calValue = caseInfo.DRRCalim.diffRate;
  1011. }
  1012. }
  1013. }
  1014. else
  1015. {
  1016. if (caseInfo.RFRFulltext != null && caseInfo.RFRAbstract != null)
  1017. {
  1018. calValue = caseInfo.RFRAll.diffRate;
  1019. }
  1020. else
  1021. {
  1022. if (caseInfo.RFRCalim != null)
  1023. {
  1024. calValue = caseInfo.RFRCalim.diffRate;
  1025. }
  1026. }
  1027. }
  1028. break;
  1029. case 2:
  1030. if (stage == 0)
  1031. {
  1032. if(caseInfo.DRRFulltext != null && caseInfo.DRRCalim!= null)
  1033. {
  1034. calValue = caseInfo.DRRCalim.TextSimilarity * 0.7 + caseInfo.DRRFulltext.TextSimilarity * 0.3;
  1035. }
  1036. else
  1037. {
  1038. if( caseInfo.DRRCalim != null)
  1039. {
  1040. calValue = caseInfo.DRRCalim.TextSimilarity;
  1041. }
  1042. else
  1043. {
  1044. if(caseInfo.DRRAll != null)
  1045. {
  1046. calValue = caseInfo.DRRAll.TextSimilarity;
  1047. }
  1048. }
  1049. }
  1050. }
  1051. else
  1052. {
  1053. if (caseInfo.RFRFulltext != null && caseInfo.RFRCalim != null)
  1054. {
  1055. calValue = caseInfo.RFRCalim.TextSimilarity * 0.7 + caseInfo.RFRFulltext.TextSimilarity * 0.3;
  1056. }
  1057. else
  1058. {
  1059. if (caseInfo.RFRCalim != null)
  1060. {
  1061. calValue = caseInfo.RFRCalim.TextSimilarity;
  1062. }
  1063. else
  1064. {
  1065. if (caseInfo.RFRAll != null)
  1066. {
  1067. calValue = caseInfo.RFRAll.TextSimilarity;
  1068. }
  1069. }
  1070. }
  1071. }
  1072. break;
  1073. case 3:
  1074. if (stage == 0)
  1075. {
  1076. if (caseInfo.DRRCalim != null)
  1077. {
  1078. calValue = caseInfo.DRRCalim.TextSimilarity;
  1079. }
  1080. }
  1081. else
  1082. {
  1083. if (caseInfo.RFRCalim != null)
  1084. {
  1085. calValue = caseInfo.RFRCalim.TextSimilarity;
  1086. }
  1087. }
  1088. break;
  1089. case 4:
  1090. if (stage == 0)
  1091. {
  1092. if (caseInfo.DRRCalim != null)
  1093. {
  1094. calValue = caseInfo.DRRCalim.diffRate;
  1095. }
  1096. }
  1097. else
  1098. {
  1099. if (caseInfo.RFRCalim != null)
  1100. {
  1101. calValue = caseInfo.RFRCalim.diffRate;
  1102. }
  1103. }
  1104. break;
  1105. }
  1106. return calValue;
  1107. }
  1108. private string typeName(int type)
  1109. {
  1110. switch (type)
  1111. {
  1112. case 0:
  1113. return "文本相似度计算";
  1114. case 1:
  1115. return "字符修改计算";
  1116. case 2:
  1117. return "权要权重70说明书30";
  1118. case 3:
  1119. return "权要相似度计算";
  1120. }
  1121. return "";
  1122. }
  1123. public IList<Object> CalMean_Std(DateTime start,DateTime end)
  1124. {
  1125. double AverageA = Context.CaseInfos.Where<CaseInfo>(
  1126. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end && p.DRRCalim!= null)
  1127. .Average(x=>x.DRRCalim.TextSimilarity);
  1128. double AverageB = Context.CaseInfos.Where<CaseInfo>(
  1129. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end && p.RFRAll != null)
  1130. .Average(x => x.RFRAll.TextSimilarity);
  1131. double stdA = Math.Sqrt( Context.CaseInfos.Where<CaseInfo>(
  1132. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  1133. .Average((x => (x.DRRCalim.TextSimilarity - AverageA) * (x.DRRCalim.TextSimilarity - AverageA))));
  1134. double stdB = Math.Sqrt(Context.CaseInfos.Where<CaseInfo>(
  1135. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  1136. .Average((x => (x.RFRAll.TextSimilarity - AverageB) * (x.RFRAll.TextSimilarity - AverageB))));
  1137. var response2 = Context.CaseInfos.Where<CaseInfo>(
  1138. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  1139. .Include(p=>p.DRRCalim)
  1140. .Include(p=>p.RFRAll);
  1141. IList<Object> results = new List<Object>();
  1142. foreach(var item in response2.ToList())
  1143. {
  1144. results.Add(
  1145. new {
  1146. Id = item.Id,
  1147. CaseNo = item.CaseNo,
  1148. CaseName = item.CaseName,
  1149. Customer = item.Customer,
  1150. Reviewer = item.Reviewer,
  1151. Handlers = item.Handlers,
  1152. zScoreA = (item.DRRCalim?.TextSimilarity -AverageA)/stdA,
  1153. zScoreB = (item.RFRAll?.TextSimilarity - AverageB) /stdB
  1154. }
  1155. );
  1156. }
  1157. return results;
  1158. }
  1159. private string GetExpress(IList<FieldCondition> conditions)
  1160. {
  1161. string str = "";
  1162. foreach (var c in conditions)
  1163. {
  1164. if (string.IsNullOrEmpty(str))
  1165. {
  1166. str = c.ToExpressString("s");
  1167. }
  1168. else
  1169. {
  1170. if (c.LogicOperate == LogicEnum.And)
  1171. {
  1172. str = $"({str}) && {c.ToExpressString("s")}";
  1173. }
  1174. else
  1175. {
  1176. str = $"({str}) || {c.ToExpressString("s")}";
  1177. }
  1178. }
  1179. }
  1180. return str;
  1181. }
  1182. private IQueryable<CaseInfo> NewMethod(QueryFilter queryFilter)
  1183. {
  1184. string strExpress = "";
  1185. if (queryFilter.ConditionTree != null)
  1186. {
  1187. strExpress = GetExpress(queryFilter.ConditionTree);
  1188. }
  1189. var interpreter = new Interpreter();
  1190. if (string.IsNullOrEmpty(strExpress))
  1191. {
  1192. return new spDbContext().CaseInfos.Where<CaseInfo>(p=>(p.Id>0));
  1193. }
  1194. else
  1195. {
  1196. Expression<Func<CaseInfo, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<CaseInfo, bool>>(strExpress, "s");
  1197. IQueryable<CaseInfo> response = new spDbContext().CaseInfos.Where<CaseInfo>(dynamicWhere);
  1198. return response;
  1199. }
  1200. }
  1201. }
  1202. }