CaseFileCompareController.cs 57 KB

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