CaseFileCompareController.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. using DocumentFormat.OpenXml.InkML;
  2. using DynamicExpresso;
  3. using Microsoft.AspNetCore.Authorization;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.EntityFrameworkCore;
  7. using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Diagnostics;
  12. using System.Dynamic;
  13. using System.Linq;
  14. using System.Linq.Expressions;
  15. using System.Text.RegularExpressions;
  16. using wispro.sp.api.AppealHandler;
  17. using wispro.sp.api.Services;
  18. using wispro.sp.entity;
  19. using wispro.sp.entity.CompareCase;
  20. using wispro.sp.share;
  21. using static OneOf.Types.TrueFalseOrNull;
  22. namespace wispro.sp.api.Controllers
  23. {
  24. [Route("api/[controller]/[action]")]
  25. [ApiController]
  26. public class CaseFileCompareController : ControllerBase
  27. {
  28. spDbContext Context;
  29. IFileTaskService fileTaskService;
  30. public CaseFileCompareController(spDbContext context, IFileTaskService _fileTaskService)
  31. {
  32. Context = context;
  33. fileTaskService = _fileTaskService;
  34. }
  35. [Authorize]
  36. public ApiSaveResponse Save(CaseInfo caseInfo)
  37. {
  38. ApiSaveResponse ret = new ApiSaveResponse();
  39. ret.Success = true;
  40. using (Context.Database.BeginTransaction())
  41. {
  42. try
  43. {
  44. #region 客户处理
  45. if (caseInfo.Customer != null && !string.IsNullOrEmpty(caseInfo.Customer.Name))
  46. {
  47. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == caseInfo.Customer.Name).FirstOrDefault();
  48. if (temCustomer == null)
  49. {
  50. temCustomer = new Customer() { Name = caseInfo.Customer.Name };
  51. //item.Customer.Id = 0;
  52. Context.Customers.Add(temCustomer);
  53. Context.SaveChanges();
  54. caseInfo.Customer = temCustomer;
  55. //item.CustomerId = item.Customer.Id;
  56. }
  57. else
  58. {
  59. caseInfo.Customer = temCustomer;
  60. }
  61. caseInfo.CustomerId = caseInfo.Customer.Id;
  62. caseInfo.Customer = null;
  63. }
  64. else
  65. {
  66. caseInfo.Customer = null;
  67. }
  68. #endregion
  69. #region 审核人
  70. if (caseInfo.Reviewer != null && !string.IsNullOrEmpty(caseInfo.Reviewer.Name))
  71. {
  72. var temReviewer = Context.Staffs.Where<Staff>(c => c.Name == caseInfo.Reviewer.Name).FirstOrDefault();
  73. if (temReviewer == null)
  74. {
  75. temReviewer = new Staff() { Name = caseInfo.Reviewer.Name };
  76. //item.Customer.Id = 0;
  77. Context.Staffs.Add(temReviewer);
  78. Context.SaveChanges();
  79. caseInfo.Reviewer = temReviewer;
  80. //item.CustomerId = item.Customer.Id;
  81. }
  82. else
  83. {
  84. caseInfo.Reviewer = temReviewer;
  85. }
  86. caseInfo.ReviewerId = caseInfo.Reviewer.Id;
  87. caseInfo.Reviewer = null;
  88. }
  89. else
  90. {
  91. caseInfo.Reviewer = null;
  92. }
  93. #endregion
  94. if (caseInfo.DRRAbstract != null) {
  95. Context.CaseCompareResults.Add(caseInfo.DRRAbstract);
  96. Context.SaveChanges();
  97. caseInfo.DRRAbstractId = caseInfo.DRRAbstract.Id;
  98. caseInfo.DRRAbstract = null;
  99. }
  100. if (caseInfo.DRRCalim != null)
  101. {
  102. Context.CaseCompareResults.Add(caseInfo.DRRCalim);
  103. Context.SaveChanges();
  104. caseInfo.DRRCalimId = caseInfo.DRRCalim.Id;
  105. caseInfo.DRRCalim = null;
  106. }
  107. if (caseInfo.DRRFulltext != null)
  108. {
  109. Context.CaseCompareResults.Add(caseInfo.DRRFulltext);
  110. Context.SaveChanges();
  111. caseInfo.DRRFulltextId = caseInfo.DRRFulltext.Id;
  112. caseInfo.DRRFulltext = null;
  113. }
  114. if (caseInfo.DRRAll != null)
  115. {
  116. Context.CaseCompareResults.Add(caseInfo.DRRAll);
  117. Context.SaveChanges();
  118. caseInfo.DRRAllId = caseInfo.DRRAll.Id;
  119. caseInfo.DRRAll = null;
  120. }
  121. if (caseInfo.RFRAbstract != null)
  122. {
  123. Context.CaseCompareResults.Add(caseInfo.RFRAbstract);
  124. Context.SaveChanges();
  125. caseInfo.RFRAbstractId = caseInfo.RFRAbstract.Id;
  126. caseInfo.RFRAbstract = null;
  127. }
  128. if (caseInfo.RFRCalim != null)
  129. {
  130. Context.CaseCompareResults.Add(caseInfo.RFRCalim);
  131. Context.SaveChanges();
  132. caseInfo.RFRCalimId = caseInfo.RFRCalim.Id;
  133. caseInfo.RFRCalim = null;
  134. }
  135. if (caseInfo.RFRFulltext != null)
  136. {
  137. Context.CaseCompareResults.Add(caseInfo.RFRFulltext);
  138. Context.SaveChanges();
  139. caseInfo.RFRFulltextId = caseInfo.RFRFulltext.Id;
  140. caseInfo.RFRFulltext = null;
  141. }
  142. if (caseInfo.RFRAll != null)
  143. {
  144. Context.CaseCompareResults.Add(caseInfo.RFRAll);
  145. Context.SaveChanges();
  146. caseInfo.RFRAllId = caseInfo.RFRAll.Id;
  147. caseInfo.RFRAll = null;
  148. }
  149. Context.CaseInfos.Add(caseInfo);
  150. Context.SaveChanges();
  151. Context.Database.CommitTransaction();
  152. }
  153. catch (Exception ex)
  154. {
  155. ret.Success = false;
  156. ret.ErrorMessage = ex.Message;
  157. Context.Database.RollbackTransaction();
  158. }
  159. }
  160. return ret;
  161. }
  162. public ListApiResponse<CaseInfo> QueryFilter(QueryFilter queryFilter)
  163. {
  164. ListApiResponse<CaseInfo> ret = new ListApiResponse<CaseInfo>();
  165. IQueryable<CaseInfo> response = NewMethod(queryFilter);
  166. int totals = response.Count();
  167. if (totals > 0 && totals < (queryFilter.PageIndex) * queryFilter.PageSize)
  168. {
  169. response = response
  170. .Include(pi => pi.DRRCalim)
  171. .Include(pi => pi.DRRAbstract)
  172. .Include(pi => pi.DRRFulltext)
  173. .Include(pi => pi.DRRAll)
  174. .Include(pi => pi.RFRCalim)
  175. .Include(pi => pi.RFRAbstract)
  176. .Include(pi => pi.RFRFulltext)
  177. .Include(pi => pi.RFRAll)
  178. .Include(pi => pi.Customer)
  179. .Include(pi => pi.Reviewer)
  180. .OrderConditions<CaseInfo>(queryFilter.Sorts)
  181. .Skip((queryFilter.PageIndex - 1) * queryFilter.PageSize)
  182. .Take(totals - (queryFilter.PageIndex - 1) * queryFilter.PageSize);
  183. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  184. }
  185. else
  186. {
  187. response = response
  188. .Include(pi => pi.DRRCalim)
  189. .Include(pi => pi.DRRAbstract)
  190. .Include(pi => pi.DRRFulltext)
  191. .Include(pi=>pi.DRRAll)
  192. .Include(pi => pi.RFRCalim)
  193. .Include(pi => pi.RFRAbstract)
  194. .Include(pi => pi.RFRFulltext)
  195. .Include(pi => pi.RFRAll)
  196. .Include(pi => pi.Customer)
  197. .Include(pi => pi.Reviewer)
  198. .OrderConditions<CaseInfo>(queryFilter.Sorts)
  199. .Skip((queryFilter.PageIndex - 1) * queryFilter.PageSize)
  200. .Take(queryFilter.PageSize);
  201. }
  202. ret.TotalCount = totals;
  203. var retList = response.ToList<CaseInfo>();
  204. #region 将某些属性设为null,避免循环取值造成返回json过大
  205. foreach (CaseInfo item in retList)
  206. {
  207. if (item.Customer != null)
  208. {
  209. item.Customer.PerformanceItems = null;
  210. item.Customer.ResponseMan = null;
  211. }
  212. if (item.Reviewer != null)
  213. {
  214. item.Reviewer.Customers = null;
  215. item.Reviewer.ExternalHandlerItems = null;
  216. item.Reviewer.ItemStaffs = null;
  217. item.Reviewer.AllocationRatios = null;
  218. item.Reviewer.ReviewerItems = null;
  219. }
  220. }
  221. #endregion
  222. ret.Results = retList.ToList();
  223. return ret;
  224. }
  225. public bool CaseExist(string caseNo)
  226. {
  227. return Context.CaseInfos.Where(p => p.CaseNo == caseNo.Trim()).Count() > 0;
  228. }
  229. /// <summary>
  230. /// 计算案件的zScore
  231. /// </summary>
  232. /// <param name="start">定稿日开始时间</param>
  233. /// <param name="end">定稿日结束时间</param>
  234. /// <param name="type">
  235. /// 0:基于文本相似度计算,
  236. /// 1:基于文本修改差异度计算
  237. /// 2:权要权重70说明书30
  238. /// </param>
  239. /// <returns></returns>
  240. public IList<Object> CalCustomer_mean(DateTime start,DateTime end,int type=0)
  241. {
  242. var caseList = Context.CaseInfos.Where<CaseInfo>(
  243. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  244. .Include(p=>p.Customer)
  245. .Include(p=>p.Reviewer)
  246. .Include(p=>p.DRRAbstract)
  247. .Include(p => p.DRRAbstract)
  248. .Include(p => p.DRRCalim)
  249. .Include(p => p.DRRFulltext)
  250. .Include(p => p.DRRAll)
  251. .Include(p => p.RFRAbstract)
  252. .Include(p => p.RFRCalim)
  253. .Include(p => p.RFRFulltext)
  254. .Include(p => p.RFRAll);
  255. int iTotals = caseList.Count();
  256. int iIndex = 0;
  257. List<Object> retList = new List<Object>();
  258. #region 计算客户相似度平均值和标准方差
  259. List<CustomerAvg_Std> avg_std1 = new List<CustomerAvg_Std>();
  260. List<CustomerAvg_Std> avg_std2 = new List<CustomerAvg_Std>();
  261. foreach (var caseInfo in caseList)
  262. {
  263. iIndex++;
  264. Debug.WriteLine($"{iIndex}/{iTotals}\t{caseInfo.CaseNo}\t{caseInfo.DRRAbstractId},{caseInfo.DRRCalimId},{caseInfo.DRRFulltextId},{caseInfo.DRRAllId},{caseInfo.RFRAbstractId},{caseInfo.RFRCalimId},{caseInfo.RFRFulltextId},{caseInfo.RFRAllId}");
  265. string tmpCustomerName = "未知";
  266. if(caseInfo.Customer!= null)
  267. {
  268. tmpCustomerName = caseInfo.Customer.Name;
  269. }
  270. var one = avg_std1.Where<CustomerAvg_Std>(p => p.Name == tmpCustomerName).FirstOrDefault();
  271. if (one == null)
  272. {
  273. one = new CustomerAvg_Std() { Name = tmpCustomerName };
  274. avg_std1.Add(one);
  275. }
  276. var two = avg_std2.Where<CustomerAvg_Std>(p => p.Name == tmpCustomerName).FirstOrDefault();
  277. if (two == null)
  278. {
  279. two = new CustomerAvg_Std() { Name = tmpCustomerName };
  280. avg_std2.Add(two);
  281. }
  282. double? oneTmp = getCalValue(caseInfo, type, 0);
  283. if(oneTmp != null)
  284. {
  285. one.Sum += oneTmp.Value;
  286. one.SquareSum += oneTmp.Value * oneTmp.Value;
  287. one.count += 1;
  288. }
  289. double? twoTmp = getCalValue(caseInfo, type, 1);
  290. if (twoTmp != null)
  291. {
  292. two.Sum += twoTmp.Value;
  293. two.SquareSum += twoTmp.Value * twoTmp.Value;
  294. two.count += 1;
  295. }
  296. }
  297. #endregion
  298. System.Data.DataTable dt = new System.Data.DataTable();
  299. dt.Columns.Add("我方文号");
  300. dt.Columns.Add("案件名称");
  301. dt.Columns.Add("客户");
  302. dt.Columns.Add("处理人");
  303. dt.Columns.Add("核稿人");
  304. dt.Columns.Add("内部核稿相似度或差异度");
  305. dt.Columns.Add("内部客户平均值");
  306. dt.Columns.Add("内部客户标准偏差");
  307. dt.Columns.Add("内部核稿分数");
  308. dt.Columns.Add("外部核稿相似度或差异度");
  309. dt.Columns.Add("外部客户平均值");
  310. dt.Columns.Add("外部客户标准偏差");
  311. dt.Columns.Add("外部核稿分数");
  312. dt.Columns.Add("备注");
  313. foreach (var item in caseList)
  314. {
  315. string tmpCustomerName = "未知";
  316. if (item.Customer != null)
  317. {
  318. tmpCustomerName = item.Customer.Name;
  319. }
  320. var one = avg_std1.Where<CustomerAvg_Std>(p => p.Name == tmpCustomerName).FirstOrDefault();
  321. var two = avg_std2.Where<CustomerAvg_Std>(p => p.Name == tmpCustomerName).FirstOrDefault();
  322. double? oneSim = getCalValue(item,type,0);
  323. double? twoSim = getCalValue(item, type, 1); ;
  324. //if(oneSim == null)
  325. //{
  326. // oneSim = 1;
  327. //}
  328. //if (twoSim == null)
  329. //{
  330. // twoSim = 1;
  331. //}
  332. DataRow row = dt.NewRow();
  333. row["我方文号"] = item.CaseNo;
  334. row["案件名称"] = item.CaseName;
  335. row["客户"] = item.Customer?.Name;
  336. row["核稿人"] = item.Reviewer?.Name;
  337. row["处理人"] = item.Handlers;
  338. double? zScoreA = null;
  339. if (oneSim != null)
  340. {
  341. zScoreA = (oneSim - one.Average) / one.Std_Deviation;
  342. }
  343. row["内部核稿分数"] = zScoreA;
  344. row["内部核稿相似度或差异度"] = oneSim;
  345. row["内部客户平均值"] = one.Average;
  346. row["内部客户标准偏差"] = one.Std_Deviation;
  347. row["外部核稿相似度或差异度"] = twoSim;
  348. row["外部客户平均值"] = two.Average;
  349. row["外部客户标准偏差"] = two.Std_Deviation;
  350. double? zScoreB = null;
  351. if (twoSim != null)
  352. {
  353. zScoreB = (twoSim - two.Average) / two.Std_Deviation;
  354. }
  355. row["外部核稿分数"] = zScoreB;
  356. if (zScoreA != null && zScoreB != null)
  357. {
  358. var distince = Math.Sqrt(zScoreB.Value * zScoreB.Value + zScoreA.Value * zScoreA.Value);
  359. if (type == 0 || type == 2)
  360. {
  361. if (distince > 3)
  362. {
  363. if (zScoreA.Value > 0 && zScoreB.Value > 0)
  364. {
  365. row["备注"] = "内部核稿、外部核稿修改都较少![撰稿人给力或客户友好]";
  366. }
  367. if (zScoreA.Value > 0 && zScoreB.Value < 0)
  368. {
  369. row["备注"] = "内部核稿较少、外部核稿修改较多![核稿人没有尽责!]";
  370. }
  371. if (zScoreA.Value < 0 && zScoreB.Value > 0)
  372. {
  373. row["备注"] = "内部核稿较多、外部核稿修改都较少![核稿人给力]";
  374. }
  375. if (zScoreA.Value < 0 && zScoreB.Value < 0)
  376. {
  377. row["备注"] = "内部核稿和外部核稿修改都较多![案件沟通问题?]";
  378. }
  379. }
  380. }
  381. else
  382. {
  383. if (distince > 3)
  384. {
  385. if (zScoreA.Value > 0 && zScoreB.Value > 0)
  386. {
  387. row["备注"] = "内部核稿和外部核稿修改都较多![案件沟通问题?]";
  388. }
  389. if (zScoreA.Value > 0 && zScoreB.Value < 0)
  390. {
  391. row["备注"] = "内部核稿较多、外部核稿修改都较少![核稿人给力]";
  392. }
  393. if (zScoreA.Value < 0 && zScoreB.Value > 0)
  394. {
  395. row["备注"] = "内部核稿较少、外部核稿修改较多![核稿人没有尽责!]";
  396. }
  397. if (zScoreA.Value < 0 && zScoreB.Value < 0)
  398. {
  399. row["备注"] = "内部核稿、外部核稿修改都较少![撰稿人给力或客户友好]";
  400. }
  401. }
  402. }
  403. }
  404. dt.Rows.Add(row);
  405. retList.Add(
  406. new
  407. {
  408. Id = item.Id,
  409. CaseNo = item.CaseNo,
  410. CaseName = item.CaseName,
  411. Customer = item.Customer,
  412. Reviewer = item.Reviewer,
  413. Handlers = item.Handlers,
  414. zScoreA = (oneSim - one.Average) / one.Std_Deviation,
  415. zScoreB = (twoSim - two.Average) / two.Std_Deviation
  416. }
  417. );
  418. }
  419. wispro.sp.utility.NPOIExcel.DataTableToExcel(dt,$"c:\\temp\\{DateTime.Now.ToString("yyyyMMdd")}-内部核稿外部核稿情况案件清单_{typeName(type)}.xlsx");
  420. return retList;
  421. }
  422. private double? getCalValue(CaseInfo caseInfo,int type,int stage)
  423. {
  424. double? calValue = null;
  425. switch (type)
  426. {
  427. case 0:
  428. if(stage == 0)
  429. {
  430. if(caseInfo.DRRFulltext != null && caseInfo.DRRAbstract != null)
  431. {
  432. calValue = caseInfo.DRRAll.TextSimilarity;
  433. }
  434. else
  435. {
  436. if(caseInfo.DRRCalim != null)
  437. {
  438. calValue = caseInfo.DRRCalim.TextSimilarity;
  439. }
  440. }
  441. }
  442. else
  443. {
  444. if (caseInfo.RFRFulltext != null && caseInfo.RFRAbstract != null)
  445. {
  446. calValue = caseInfo.RFRAll.TextSimilarity;
  447. }
  448. else
  449. {
  450. if (caseInfo.RFRCalim != null)
  451. {
  452. calValue = caseInfo.RFRCalim.TextSimilarity;
  453. }
  454. }
  455. }
  456. break;
  457. case 1:
  458. if (stage == 0)
  459. {
  460. if (caseInfo.DRRFulltext != null && caseInfo.DRRAbstract != null)
  461. {
  462. calValue = caseInfo.DRRAll.diffRate;
  463. }
  464. else
  465. {
  466. if (caseInfo.DRRCalim != null)
  467. {
  468. calValue = caseInfo.DRRCalim.diffRate;
  469. }
  470. }
  471. }
  472. else
  473. {
  474. if (caseInfo.RFRFulltext != null && caseInfo.RFRAbstract != null)
  475. {
  476. calValue = caseInfo.RFRAll.diffRate;
  477. }
  478. else
  479. {
  480. if (caseInfo.RFRCalim != null)
  481. {
  482. calValue = caseInfo.RFRCalim.diffRate;
  483. }
  484. }
  485. }
  486. break;
  487. case 2:
  488. if (stage == 0)
  489. {
  490. if(caseInfo.DRRFulltext != null && caseInfo.DRRCalim!= null)
  491. {
  492. calValue = caseInfo.DRRCalim.TextSimilarity * 0.7 + caseInfo.DRRFulltext.TextSimilarity * 0.3;
  493. }
  494. else
  495. {
  496. if( caseInfo.DRRCalim != null)
  497. {
  498. calValue = caseInfo.DRRCalim.TextSimilarity;
  499. }
  500. else
  501. {
  502. if(caseInfo.DRRAll != null)
  503. {
  504. calValue = caseInfo.DRRAll.TextSimilarity;
  505. }
  506. }
  507. }
  508. }
  509. else
  510. {
  511. if (caseInfo.RFRFulltext != null && caseInfo.RFRCalim != null)
  512. {
  513. calValue = caseInfo.RFRCalim.TextSimilarity * 0.7 + caseInfo.RFRFulltext.TextSimilarity * 0.3;
  514. }
  515. else
  516. {
  517. if (caseInfo.RFRCalim != null)
  518. {
  519. calValue = caseInfo.RFRCalim.TextSimilarity;
  520. }
  521. else
  522. {
  523. if (caseInfo.RFRAll != null)
  524. {
  525. calValue = caseInfo.RFRAll.TextSimilarity;
  526. }
  527. }
  528. }
  529. }
  530. break;
  531. case 3:
  532. if (stage == 0)
  533. {
  534. if (caseInfo.DRRCalim != null)
  535. {
  536. calValue = caseInfo.DRRCalim.TextSimilarity;
  537. }
  538. }
  539. else
  540. {
  541. if (caseInfo.RFRCalim != null)
  542. {
  543. calValue = caseInfo.RFRCalim.TextSimilarity;
  544. }
  545. }
  546. break;
  547. }
  548. return calValue;
  549. }
  550. private string typeName(int type)
  551. {
  552. switch (type)
  553. {
  554. case 0:
  555. return "文本相似度计算";
  556. case 1:
  557. return "字符修改计算";
  558. case 2:
  559. return "权要权重70说明书30";
  560. case 3:
  561. return "权要相似度计算";
  562. }
  563. return "";
  564. }
  565. public IList<Object> CalMean_Std(DateTime start,DateTime end)
  566. {
  567. double AverageA = Context.CaseInfos.Where<CaseInfo>(
  568. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end && p.DRRCalim!= null)
  569. .Average(x=>x.DRRCalim.TextSimilarity);
  570. double AverageB = Context.CaseInfos.Where<CaseInfo>(
  571. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end && p.RFRAll != null)
  572. .Average(x => x.RFRAll.TextSimilarity);
  573. double stdA = Math.Sqrt( Context.CaseInfos.Where<CaseInfo>(
  574. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  575. .Average((x => (x.DRRCalim.TextSimilarity - AverageA) * (x.DRRCalim.TextSimilarity - AverageA))));
  576. double stdB = Math.Sqrt(Context.CaseInfos.Where<CaseInfo>(
  577. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  578. .Average((x => (x.RFRAll.TextSimilarity - AverageB) * (x.RFRAll.TextSimilarity - AverageB))));
  579. var response2 = Context.CaseInfos.Where<CaseInfo>(
  580. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  581. .Include(p=>p.DRRCalim)
  582. .Include(p=>p.RFRAll);
  583. IList<Object> results = new List<Object>();
  584. foreach(var item in response2.ToList())
  585. {
  586. results.Add(
  587. new {
  588. Id = item.Id,
  589. CaseNo = item.CaseNo,
  590. CaseName = item.CaseName,
  591. Customer = item.Customer,
  592. Reviewer = item.Reviewer,
  593. Handlers = item.Handlers,
  594. zScoreA = (item.DRRCalim?.TextSimilarity -AverageA)/stdA,
  595. zScoreB = (item.RFRAll?.TextSimilarity - AverageB) /stdB
  596. }
  597. );
  598. }
  599. return results;
  600. }
  601. private string GetExpress(IList<FieldCondition> conditions)
  602. {
  603. string str = "";
  604. foreach (var c in conditions)
  605. {
  606. if (string.IsNullOrEmpty(str))
  607. {
  608. str = c.ToExpressString("s");
  609. }
  610. else
  611. {
  612. if (c.LogicOperate == LogicEnum.And)
  613. {
  614. str = $"({str}) && {c.ToExpressString("s")}";
  615. }
  616. else
  617. {
  618. str = $"({str}) || {c.ToExpressString("s")}";
  619. }
  620. }
  621. }
  622. return str;
  623. }
  624. private IQueryable<CaseInfo> NewMethod(QueryFilter queryFilter)
  625. {
  626. string strExpress = "";
  627. if (queryFilter.ConditionTree != null)
  628. {
  629. strExpress = GetExpress(queryFilter.ConditionTree);
  630. }
  631. var interpreter = new Interpreter();
  632. if (string.IsNullOrEmpty(strExpress))
  633. {
  634. return new spDbContext().CaseInfos.Where<CaseInfo>(p=>(p.Id>0));
  635. }
  636. else
  637. {
  638. Expression<Func<CaseInfo, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<CaseInfo, bool>>(strExpress, "s");
  639. IQueryable<CaseInfo> response = new spDbContext().CaseInfos.Where<CaseInfo>(dynamicWhere);
  640. return response;
  641. }
  642. }
  643. }
  644. }