CaseFileCompareController.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. var zScoreA = (oneSim -one.Average)/one.Std_Deviation;
  339. row["内部核稿相似度或差异度"] = oneSim;
  340. row["内部客户平均值"] = one.Average;
  341. row["内部客户标准偏差"] = one.Std_Deviation;
  342. row["内部核稿分数"] = zScoreA;
  343. var zScoreB = (twoSim -two.Average)/two.Std_Deviation;
  344. row["外部核稿相似度或差异度"] = twoSim;
  345. row["外部客户平均值"] = two.Average;
  346. row["外部客户标准偏差"] = two.Std_Deviation;
  347. row["外部核稿分数"] = zScoreB;
  348. var distince = Math.Sqrt(zScoreB.Value * zScoreB.Value + zScoreA.Value * zScoreA.Value);
  349. if (type == 0 || type==2)
  350. {
  351. if (distince > 3)
  352. {
  353. if (zScoreA.Value > 0 && zScoreB.Value > 0)
  354. {
  355. row["备注"] = "内部核稿、外部核稿修改都较少![撰稿人给力或客户友好]";
  356. }
  357. if (zScoreA.Value > 0 && zScoreB.Value < 0)
  358. {
  359. row["备注"] = "内部核稿较少、外部核稿修改较多![核稿人没有尽责!]";
  360. }
  361. if (zScoreA.Value < 0 && zScoreB.Value > 0)
  362. {
  363. row["备注"] = "内部核稿较多、外部核稿修改都较少![核稿人给力]";
  364. }
  365. if (zScoreA.Value < 0 && zScoreB.Value < 0)
  366. {
  367. row["备注"] = "内部核稿和外部核稿修改都较多![案件沟通问题?]";
  368. }
  369. }
  370. }
  371. else
  372. {
  373. if (distince > 3)
  374. {
  375. if (zScoreA.Value > 0 && zScoreB.Value > 0)
  376. {
  377. row["备注"] = "内部核稿和外部核稿修改都较多![案件沟通问题?]";
  378. }
  379. if (zScoreA.Value > 0 && zScoreB.Value < 0)
  380. {
  381. row["备注"] = "内部核稿较多、外部核稿修改都较少![核稿人给力]";
  382. }
  383. if (zScoreA.Value < 0 && zScoreB.Value > 0)
  384. {
  385. row["备注"] = "内部核稿较少、外部核稿修改较多![核稿人没有尽责!]";
  386. }
  387. if (zScoreA.Value < 0 && zScoreB.Value < 0)
  388. {
  389. row["备注"] = "内部核稿、外部核稿修改都较少![撰稿人给力或客户友好]";
  390. }
  391. }
  392. }
  393. dt.Rows.Add(row);
  394. retList.Add(
  395. new
  396. {
  397. Id = item.Id,
  398. CaseNo = item.CaseNo,
  399. CaseName = item.CaseName,
  400. Customer = item.Customer,
  401. Reviewer = item.Reviewer,
  402. Handlers = item.Handlers,
  403. zScoreA = (oneSim - one.Average) / one.Std_Deviation,
  404. zScoreB = (twoSim - two.Average) / two.Std_Deviation
  405. }
  406. );
  407. }
  408. wispro.sp.utility.NPOIExcel.DataTableToExcel(dt,$"c:\\temp\\{DateTime.Now.ToString("yyyyMMdd")}-内部核稿外部核稿情况案件清单_{typeName(type)}.xlsx");
  409. return retList;
  410. }
  411. private double? getCalValue(CaseInfo caseInfo,int type,int stage)
  412. {
  413. double? calValue = null;
  414. switch (type)
  415. {
  416. case 0:
  417. if(stage == 0)
  418. {
  419. if(caseInfo.DRRFulltext != null && caseInfo.DRRAbstract != null)
  420. {
  421. calValue = caseInfo.DRRAll.TextSimilarity;
  422. }
  423. else
  424. {
  425. if(caseInfo.DRRCalim != null)
  426. {
  427. calValue = caseInfo.DRRCalim.TextSimilarity;
  428. }
  429. }
  430. }
  431. else
  432. {
  433. if (caseInfo.RFRFulltext != null && caseInfo.RFRAbstract != null)
  434. {
  435. calValue = caseInfo.RFRAll.TextSimilarity;
  436. }
  437. else
  438. {
  439. if (caseInfo.RFRCalim != null)
  440. {
  441. calValue = caseInfo.RFRCalim.TextSimilarity;
  442. }
  443. }
  444. }
  445. break;
  446. case 1:
  447. if (stage == 0)
  448. {
  449. if (caseInfo.DRRFulltext != null && caseInfo.DRRAbstract != null)
  450. {
  451. calValue = caseInfo.DRRAll.diffRate;
  452. }
  453. else
  454. {
  455. if (caseInfo.DRRCalim != null)
  456. {
  457. calValue = caseInfo.DRRCalim.diffRate;
  458. }
  459. }
  460. }
  461. else
  462. {
  463. if (caseInfo.RFRFulltext != null && caseInfo.RFRAbstract != null)
  464. {
  465. calValue = caseInfo.RFRAll.diffRate;
  466. }
  467. else
  468. {
  469. if (caseInfo.RFRCalim != null)
  470. {
  471. calValue = caseInfo.RFRCalim.diffRate;
  472. }
  473. }
  474. }
  475. break;
  476. case 2:
  477. if (stage == 0)
  478. {
  479. if(caseInfo.DRRFulltext != null && caseInfo.DRRCalim!= null)
  480. {
  481. calValue = caseInfo.DRRCalim.TextSimilarity * 0.7 + caseInfo.DRRFulltext.TextSimilarity * 0.3;
  482. }
  483. else
  484. {
  485. if( caseInfo.DRRCalim != null)
  486. {
  487. calValue = caseInfo.DRRCalim.TextSimilarity;
  488. }
  489. else
  490. {
  491. if(caseInfo.DRRAll != null)
  492. {
  493. calValue = caseInfo.DRRAll.TextSimilarity;
  494. }
  495. }
  496. }
  497. }
  498. else
  499. {
  500. if (caseInfo.RFRFulltext != null && caseInfo.RFRCalim != null)
  501. {
  502. calValue = caseInfo.RFRCalim.TextSimilarity * 0.7 + caseInfo.RFRFulltext.TextSimilarity * 0.3;
  503. }
  504. else
  505. {
  506. if (caseInfo.RFRCalim != null)
  507. {
  508. calValue = caseInfo.RFRCalim.TextSimilarity;
  509. }
  510. else
  511. {
  512. if (caseInfo.RFRAll != null)
  513. {
  514. calValue = caseInfo.RFRAll.TextSimilarity;
  515. }
  516. }
  517. }
  518. }
  519. break;
  520. }
  521. return calValue;
  522. }
  523. private string typeName(int type)
  524. {
  525. switch (type)
  526. {
  527. case 0:
  528. return "文本相似度计算";
  529. case 1:
  530. return "字符修改计算";
  531. case 2:
  532. return "权要权重70说明书30";
  533. }
  534. return "";
  535. }
  536. public IList<Object> CalMean_Std(DateTime start,DateTime end)
  537. {
  538. double AverageA = Context.CaseInfos.Where<CaseInfo>(
  539. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end && p.DRRCalim!= null)
  540. .Average(x=>x.DRRCalim.TextSimilarity);
  541. double AverageB = Context.CaseInfos.Where<CaseInfo>(
  542. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end && p.RFRAll != null)
  543. .Average(x => x.RFRAll.TextSimilarity);
  544. double stdA = Math.Sqrt( Context.CaseInfos.Where<CaseInfo>(
  545. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  546. .Average((x => (x.DRRCalim.TextSimilarity - AverageA) * (x.DRRCalim.TextSimilarity - AverageA))));
  547. double stdB = Math.Sqrt(Context.CaseInfos.Where<CaseInfo>(
  548. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  549. .Average((x => (x.RFRAll.TextSimilarity - AverageB) * (x.RFRAll.TextSimilarity - AverageB))));
  550. var response2 = Context.CaseInfos.Where<CaseInfo>(
  551. p => p.FinalVersionDate >= start && p.FinalVersionDate <= end)
  552. .Include(p=>p.DRRCalim)
  553. .Include(p=>p.RFRAll);
  554. IList<Object> results = new List<Object>();
  555. foreach(var item in response2.ToList())
  556. {
  557. results.Add(
  558. new {
  559. Id = item.Id,
  560. CaseNo = item.CaseNo,
  561. CaseName = item.CaseName,
  562. Customer = item.Customer,
  563. Reviewer = item.Reviewer,
  564. Handlers = item.Handlers,
  565. zScoreA = (item.DRRCalim?.TextSimilarity -AverageA)/stdA,
  566. zScoreB = (item.RFRAll?.TextSimilarity - AverageB) /stdB
  567. }
  568. );
  569. }
  570. return results;
  571. }
  572. private string GetExpress(IList<FieldCondition> conditions)
  573. {
  574. string str = "";
  575. foreach (var c in conditions)
  576. {
  577. if (string.IsNullOrEmpty(str))
  578. {
  579. str = c.ToExpressString("s");
  580. }
  581. else
  582. {
  583. if (c.LogicOperate == LogicEnum.And)
  584. {
  585. str = $"({str}) && {c.ToExpressString("s")}";
  586. }
  587. else
  588. {
  589. str = $"({str}) || {c.ToExpressString("s")}";
  590. }
  591. }
  592. }
  593. return str;
  594. }
  595. private IQueryable<CaseInfo> NewMethod(QueryFilter queryFilter)
  596. {
  597. string strExpress = "";
  598. if (queryFilter.ConditionTree != null)
  599. {
  600. strExpress = GetExpress(queryFilter.ConditionTree);
  601. }
  602. var interpreter = new Interpreter();
  603. if (string.IsNullOrEmpty(strExpress))
  604. {
  605. return new spDbContext().CaseInfos.Where<CaseInfo>(p=>(p.Id>0));
  606. }
  607. else
  608. {
  609. Expression<Func<CaseInfo, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<CaseInfo, bool>>(strExpress, "s");
  610. IQueryable<CaseInfo> response = new spDbContext().CaseInfos.Where<CaseInfo>(dynamicWhere);
  611. return response;
  612. }
  613. }
  614. }
  615. }