PerformanceItemController.cs 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174
  1. using DynamicExpresso;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.StaticFiles;
  6. using Microsoft.EntityFrameworkCore;
  7. using Microsoft.Extensions.Caching.Memory;
  8. using Microsoft.Extensions.Hosting;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Linq.Expressions;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using wispro.sp.api.Services;
  18. using wispro.sp.api.Utility;
  19. using wispro.sp.entity;
  20. using wispro.sp.share;
  21. using wispro.sp.utility;
  22. namespace wispro.sp.api.Controllers
  23. {
  24. [Route("api/[controller]/[action]")]
  25. [ApiController]
  26. [Authorize]
  27. public class PerformanceItemController : ControllerBase
  28. {
  29. spDbContext Context;
  30. IFileTaskService fileTaskService;
  31. public PerformanceItemController(spDbContext context, IFileTaskService _fileTaskService)
  32. {
  33. Context = context;
  34. fileTaskService = _fileTaskService;
  35. }
  36. public bool IsExist(PerformanceItem item)
  37. {
  38. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  39. x.CaseNo == item.CaseNo &&
  40. x.DoItem == item.DoItem &&
  41. x.CaseStage == item.CaseStage &&
  42. x.CalMonth.Year == item.CalMonth.Year &&
  43. x.CalMonth.Month == item.CalMonth.Month);
  44. if(results.Count() > 0)
  45. {
  46. return true;
  47. }
  48. else
  49. {
  50. return false;
  51. }
  52. }
  53. public ApiSaveResponse New(PerformanceItem item)
  54. {
  55. ApiSaveResponse ret = new ApiSaveResponse();
  56. ret.Success = true;
  57. using (Context.Database.BeginTransaction())
  58. {
  59. try
  60. {
  61. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  62. x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  63. if (item.DoItem.ToUpper() == "提交IDS")
  64. {
  65. //提交IDS 添加完成日期做完判断是否已算绩效的条件
  66. results = Context.PerformanceItems.Where<PerformanceItem>(x=>x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.FinishedDate == item.FinishedDate);
  67. }
  68. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  69. if (items != null)
  70. {
  71. item.AgentFeedbackMemo = "已算绩效";
  72. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  73. item.BasePoint = 0;
  74. }
  75. if (item.CalMonth != null)
  76. {
  77. var calMonth = Context.CalMonths.Where<CalMonth>(c => c.Year == item.CalMonth.Year && c.Month == item.CalMonth.Month).FirstOrDefault();
  78. if(calMonth == null)
  79. {
  80. Context.CalMonths.Add(item.CalMonth);
  81. Context.SaveChanges();
  82. }
  83. else
  84. {
  85. item.CalMonth = calMonth;
  86. }
  87. item.CalMonthId = item.CalMonth.Id;
  88. item.CalMonth = null;
  89. }
  90. if (!string.IsNullOrEmpty(item.Customer.Name))
  91. {
  92. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  93. if (temCustomer == null)
  94. {
  95. temCustomer = new Customer() { Name = item.Customer.Name };
  96. //item.Customer.Id = 0;
  97. Context.Customers.Add(temCustomer);
  98. Context.SaveChanges();
  99. item.Customer = temCustomer;
  100. //item.CustomerId = item.Customer.Id;
  101. }
  102. else
  103. {
  104. item.Customer = temCustomer;
  105. }
  106. item.CustomerId = item.Customer.Id;
  107. item.Customer = null;
  108. }
  109. else
  110. {
  111. item.Customer = null;
  112. }
  113. var ItemStaffs = item.ItemStaffs;
  114. item.ItemStaffs = null;
  115. Context.PerformanceItems.Add(item);
  116. Context.SaveChanges();
  117. foreach (ItemStaff itemStaff in ItemStaffs)
  118. {
  119. itemStaff.ItemId = item.Id;
  120. itemStaff.Item = null;
  121. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  122. {
  123. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  124. if (temStaff != null)
  125. {
  126. itemStaff.DoPersonId = temStaff.Id;
  127. itemStaff.DoPerson = null;
  128. }
  129. else
  130. {
  131. Context.Staffs.Add(itemStaff.DoPerson);
  132. Context.SaveChanges();
  133. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  134. itemStaff.DoPerson = null;
  135. }
  136. }
  137. }
  138. Context.ItemStaffs.AddRange(ItemStaffs);
  139. Context.SaveChanges();
  140. Context.Database.CommitTransaction();
  141. }
  142. catch (Exception ex)
  143. {
  144. ret.Success = false;
  145. ret.ErrorMessage = ex.Message;
  146. Context.Database.RollbackTransaction();
  147. }
  148. }
  149. return ret;
  150. }
  151. /// <summary>
  152. /// 更新绩效记录信息
  153. /// </summary>
  154. /// <param name="id">绩效记录编号</param>
  155. /// <param name="field">栏位,多个位以|杠隔开</param>
  156. /// <param name="value">栏位值,多个以|杠隔开</param>
  157. /// <returns></returns>
  158. public ApiSaveResponse UpdateFieldValue(int id,string field,string value)
  159. {
  160. ApiSaveResponse ret = new ApiSaveResponse();
  161. ret.Success = true;
  162. var item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.Id == id);
  163. if (item == null)
  164. {
  165. ret.Success = false;
  166. ret.ErrorMessage = $"不存在的{id}";
  167. return ret;
  168. }
  169. if(string.IsNullOrEmpty(field) )
  170. {
  171. ret.Success = false;
  172. ret.ErrorMessage = $"参数不对!";
  173. return ret;
  174. }
  175. string[] fields = field.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  176. string[] values = new string[] { null };
  177. if (!string.IsNullOrEmpty(value))
  178. {
  179. values = value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  180. }
  181. if (fields.Length != values.Length) {
  182. ret.Success = false;
  183. ret.ErrorMessage = "栏位和值对不匹配";
  184. }
  185. else
  186. {
  187. for(int i = 0; i < fields.Length; i++)
  188. {
  189. string temField = fields[i];
  190. string temValue = values[i];
  191. switch (temField)
  192. {
  193. case "AgentFeedbackMemo":
  194. item.AgentFeedbackMemo = temValue;
  195. break;
  196. case "CaseCoefficient":
  197. item.CaseCoefficient = temValue;
  198. //此处添加保存到流程系统的代码
  199. break;
  200. case "DoItemCoefficient":
  201. item.DoItemCoefficient = temValue;
  202. //此处添加保存到流程系统的代码
  203. break;
  204. case "WordCount":
  205. int wordCount;
  206. if (int.TryParse(temValue, out wordCount))
  207. {
  208. item.WordCount = wordCount;
  209. }
  210. else
  211. {
  212. ret.Success = false;
  213. ret.ErrorMessage = "所给的栏位值不能转换成数字!";
  214. return ret;
  215. }
  216. break;
  217. case "ReturnCasseNo":
  218. item.ReturnCasseNo = temValue;
  219. break;
  220. }
  221. }
  222. if (item.AgentFeedbackMemo != "特殊点数申诉")
  223. {
  224. Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
  225. Context.SaveChanges();
  226. }
  227. }
  228. return ret;
  229. }
  230. public ListApiResponse<PerformanceItem> Query(int pageIndex,int pageSize)
  231. {
  232. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  233. var results = Context.PerformanceItems
  234. .Where<PerformanceItem>(s =>
  235. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == User.Identity.Name).Count() > 0 || s.Reviewer.Name == User.Identity.Name)
  236. && s.CalMonth.Status != 4);
  237. ret.TotalCount = results.Count();
  238. List<PerformanceItem> retList = results
  239. .Include(pi=>pi.ItemStaffs).ThenInclude(iStaff=>iStaff.DoPerson)
  240. .Include(pi=>pi.Reviewer)
  241. .Include(pi=>pi.Customer)
  242. .Include(pi=>pi.CalMonth)
  243. .OrderByDescending(o=>o.Id)
  244. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize).ToList<PerformanceItem>();
  245. #region 将某些属性设为null,避免循环取值造成返回json过大
  246. foreach (PerformanceItem item in retList)
  247. {
  248. foreach (ItemStaff itemStaff in item.ItemStaffs)
  249. {
  250. itemStaff.DoPerson.ItemStaffs = null;
  251. itemStaff.DoPerson.ReviewerItems = null;
  252. itemStaff.Item = null;
  253. }
  254. item.Reviewer.ReviewerItems = null;
  255. item.Reviewer.Customers = null;
  256. item.Reviewer.ItemStaffs = null;
  257. item.Customer.PerformanceItems = null;
  258. item.CalMonth.PerformanceItems = null;
  259. }
  260. #endregion
  261. ret.Results = retList;
  262. return ret;
  263. }
  264. public PerformanceItem Get(int Id)
  265. {
  266. var results = Context.PerformanceItems
  267. .Where<PerformanceItem>(s =>s.Id == Id);
  268. PerformanceItem item = results
  269. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  270. .Include(pi => pi.Reviewer)
  271. .Include(pi => pi.Customer)
  272. .Include(pi => pi.CalMonth)
  273. .OrderByDescending(o => o.Id)
  274. .FirstOrDefault();
  275. #region 将某些属性设为null,避免循环取值造成返回json过大
  276. foreach (ItemStaff itemStaff in item.ItemStaffs)
  277. {
  278. itemStaff.DoPerson.ItemStaffs = null;
  279. itemStaff.DoPerson.ReviewerItems = null;
  280. itemStaff.Item = null;
  281. }
  282. if (item.Reviewer != null)
  283. {
  284. item.Reviewer.ReviewerItems = null;
  285. item.Reviewer.Customers = null;
  286. item.Reviewer.ItemStaffs = null;
  287. }
  288. item.Customer.PerformanceItems = null;
  289. item.CalMonth.PerformanceItems = null;
  290. #endregion
  291. return item;
  292. }
  293. /// <summary>
  294. /// 获取给定用户的绩效清单
  295. /// </summary>
  296. /// <param name="userid">用户id</param>
  297. /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
  298. /// <returns></returns>
  299. public ListApiResponse<PerformanceItem> GetMyList(int userid, int type,int pageIndex=1,int pageSize = 10)
  300. {
  301. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  302. var results = Context.PerformanceItems
  303. .Where<PerformanceItem>(s =>
  304. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid ).Count() > 0 || s.Reviewer.Id == userid )
  305. && s.CalMonth.Status == type);
  306. ret.TotalCount = results.Count();
  307. List<PerformanceItem> retList = results
  308. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  309. .Include(pi => pi.Reviewer)
  310. .Include(pi => pi.Customer)
  311. .Include(pi => pi.CalMonth)
  312. .OrderByDescending(o => o.Id)
  313. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize)
  314. .ToList<PerformanceItem>();
  315. #region 将某些属性设为null,避免循环取值造成返回json过大
  316. foreach (PerformanceItem item in retList)
  317. {
  318. foreach(ItemStaff itemStaff in item.ItemStaffs)
  319. {
  320. itemStaff.DoPerson.ItemStaffs = null;
  321. itemStaff.DoPerson.ReviewerItems = null;
  322. itemStaff.Item = null;
  323. }
  324. item.Reviewer.ReviewerItems = null;
  325. item.Reviewer.Customers = null;
  326. item.Reviewer.ItemStaffs = null;
  327. item.Customer.PerformanceItems = null;
  328. item.CalMonth.PerformanceItems = null;
  329. }
  330. #endregion
  331. ret.Results = retList;
  332. return ret;
  333. }
  334. public NanduStatics DegreeOfDifficulty(CalMonth calMonth,int? userId = null)
  335. {
  336. NanduStatics retObj = new NanduStatics();
  337. string strKey = $"DegreeOfDifficulty:{calMonth.Year}-{calMonth.Month}-{userId}";
  338. object cacheEntry;
  339. if (!MyMemoryCache.TryGetValue(strKey, out cacheEntry))
  340. {
  341. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  342. var list = Context.CaseCeoffcients;
  343. foreach (var cx in list.ToList<CaseCeoffcient>())
  344. {
  345. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  346. }
  347. var results = Context.PerformanceItems.Where<PerformanceItem>(p => p.CalMonthId == calMonth.Id && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") && p.BasePoint > 0.0);
  348. if (userId != null)
  349. {
  350. results = Context.PerformanceItems.Where<PerformanceItem>(p =>
  351. p.CalMonthId == calMonth.Id && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") &&
  352. (p.ItemStaffs.Where<ItemStaff>(s => s.DoPerson.Id == userId).Count() > 0 || p.ReviewerId == userId) && p.BasePoint > 0.0);
  353. }
  354. #region 循环计算
  355. int iCount = 0;
  356. double d = 0.0;
  357. var retList = results.ToList();
  358. foreach (var item in retList)
  359. {
  360. string strCaseCeoffcient = item.CaseCoefficient;
  361. #region 严重延期降系数
  362. if (item.isDanger() && string.IsNullOrEmpty(item.OverDueMemo))
  363. {
  364. switch (item.CaseCoefficient)
  365. {
  366. case "S":
  367. strCaseCeoffcient = "A";
  368. break;
  369. case "A":
  370. strCaseCeoffcient = "B";
  371. break;
  372. case "B":
  373. strCaseCeoffcient = "C";
  374. break;
  375. case "C":
  376. strCaseCeoffcient = "D";
  377. break;
  378. }
  379. }
  380. #endregion
  381. switch (strCaseCeoffcient)
  382. {
  383. case "S":
  384. retObj.S += 1;
  385. break;
  386. case "A":
  387. retObj.A += 1;
  388. break;
  389. case "B":
  390. retObj.B += 1;
  391. break;
  392. case "C":
  393. retObj.C += 1;
  394. break;
  395. case "D":
  396. retObj.D += 1;
  397. break;
  398. }
  399. if (CaseXiShu.ContainsKey(strCaseCeoffcient))
  400. {
  401. d += CaseXiShu[strCaseCeoffcient];
  402. iCount += 1;
  403. }
  404. }
  405. #endregion
  406. retObj.NanduXS = d / (double)iCount;
  407. // Save data in cache.
  408. MyMemoryCache.SetValue(strKey, retObj);
  409. return retObj;
  410. }
  411. else
  412. {
  413. return (NanduStatics)cacheEntry;
  414. }
  415. }
  416. public List<string> GetFeedbackString(int itemId)
  417. {
  418. PerformanceItem item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == itemId);
  419. if(item != null)
  420. {
  421. return Utility.Utility.GetFeedbackMemos(item, Context.BasePointRules.ToList());
  422. }
  423. return new List<string>();
  424. }
  425. private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
  426. {
  427. NanduStatics gspjXS = DegreeOfDifficulty(calMonth);
  428. calMonth.NanduXS = gspjXS.NanduXS;
  429. calMonth.S = gspjXS.S;
  430. calMonth.A = gspjXS.A;
  431. calMonth.B = gspjXS.B;
  432. calMonth.C = gspjXS.C;
  433. calMonth.D = gspjXS.D;
  434. //未归档,从绩效记录中统计数据
  435. var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
  436. if (userid != null)
  437. {
  438. results = Context.PerformanceItems.Where<PerformanceItem>(s =>
  439. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  440. && s.CalMonth.Id == calMonth.Id);
  441. }
  442. List<PerformanceItem> ItemList = results
  443. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  444. .Include(pi => pi.Reviewer).ThenInclude(p=>p.StaffGrade)
  445. .Include(pi => pi.Customer)
  446. .OrderByDescending(o => o.Id)
  447. .ToList<PerformanceItem>();
  448. List<StaffStatistics> retList = new List<StaffStatistics>();
  449. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  450. var Rules = Context.BasePointRules.ToList();
  451. foreach (PerformanceItem item in ItemList)
  452. {
  453. //if (item.BasePoint == null)
  454. //{
  455. if (item.AgentFeedbackMemo != "特殊点数申诉")
  456. {
  457. Utility.Utility.CalBasePoint(item, Rules);
  458. Context.SaveChanges();
  459. }
  460. //}
  461. if (item.BasePoint != null && item.BasePoint.Value > 0)
  462. {
  463. double doPersonBasePoint = item.BasePoint.Value;
  464. List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
  465. List<StaffStatistics> temItemStatics;
  466. if (userid != null)
  467. {
  468. temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
  469. }
  470. else
  471. {
  472. temItemStatics = itemStatistics;
  473. }
  474. foreach (StaffStatistics retUserValue in temItemStatics)
  475. {
  476. var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
  477. if (temValue != null)
  478. {
  479. temValue.totalBasePoint += retUserValue.totalBasePoint;
  480. }
  481. else
  482. {
  483. retList.Add(retUserValue);
  484. }
  485. }
  486. }
  487. }
  488. if (userid != null)
  489. {
  490. retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
  491. }
  492. IDictionary<int, NanduStatics> staffXiShu = new Dictionary<int, NanduStatics>();
  493. foreach (StaffStatistics ss in retList)
  494. {
  495. if (ss.jxType.Contains("新申请") || ss.jxType.Contains("专案"))
  496. {
  497. if (!staffXiShu.ContainsKey(ss.StaffId))
  498. {
  499. NanduStatics nandu = DegreeOfDifficulty(calMonth, ss.StaffId);
  500. staffXiShu.Add(ss.StaffId, nandu);
  501. }
  502. ss.totalActuallyPoint = ss.totalBasePoint * staffXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  503. ss.NanduXS = staffXiShu[ss.StaffId].NanduXS;
  504. ss.S = staffXiShu[ss.StaffId].S;
  505. ss.A = staffXiShu[ss.StaffId].A;
  506. ss.B = staffXiShu[ss.StaffId].B;
  507. ss.C = staffXiShu[ss.StaffId].C;
  508. ss.D = staffXiShu[ss.StaffId].D;
  509. }
  510. else
  511. {
  512. ss.totalActuallyPoint = ss.totalBasePoint;
  513. }
  514. //ss.CalMonth.PerformanceItems = null;
  515. }
  516. return retList;
  517. }
  518. private void _RefreshBasePoint()
  519. {
  520. spDbContext spDb = new spDbContext();
  521. var lstItem = spDb.PerformanceItems.Include(p => p.Customer).Where(p => p.CalMonth.Status != 4).ToList();
  522. var rules = spDb.BasePointRules.ToList();
  523. foreach (var item in lstItem)
  524. {
  525. if (item.AgentFeedbackMemo != "特殊点数申诉")
  526. {
  527. Utility.Utility.CalBasePoint(item, rules);
  528. spDb.SaveChanges();
  529. }
  530. }
  531. }
  532. public ApiSaveResponse RefreshBasePoint()
  533. {
  534. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  535. t.Start();
  536. return new ApiSaveResponse() {
  537. Success = true
  538. };
  539. }
  540. public ApiSaveResponse RefreshFromIPEasyById(int itemId)
  541. {
  542. var Item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault(p => p.Id == itemId);
  543. if (Item != null)
  544. {
  545. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  546. }
  547. return new ApiSaveResponse()
  548. {
  549. Success = true
  550. };
  551. }
  552. public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
  553. {
  554. new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
  555. return new ApiSaveResponse()
  556. {
  557. Success = true
  558. };
  559. }
  560. public ApiSaveResponse RefreshFromIPEasy(string CaseNo,string DoItem,string caseStage)
  561. {
  562. var Item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault(p=>p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
  563. if(Item != null)
  564. {
  565. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item,Context);
  566. }
  567. return new ApiSaveResponse()
  568. {
  569. Success = true
  570. };
  571. }
  572. public ApiSaveResponse CompareExcel2DB()
  573. {
  574. System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
  575. t.Start();
  576. return new ApiSaveResponse()
  577. {
  578. Success = true
  579. };
  580. }
  581. private void Export2ExcelThread()
  582. {
  583. spDbContext spDb = new spDbContext();
  584. List<PerformanceItem> items = spDb.PerformanceItems
  585. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  586. .Include(p=>p.PreOastaff)
  587. .Include(p => p.Customer)
  588. .Include(p => p.CalMonth)
  589. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  590. .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  591. DataTable dt = new DataTable();
  592. #region 栏位名称
  593. dt.Columns.Add("我方文号",typeof(string));
  594. dt.Columns.Add("申请类型", typeof(string));
  595. dt.Columns.Add("业务类型", typeof(string));
  596. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  597. dt.Columns.Add("处理事项", typeof(string));
  598. dt.Columns.Add("案件阶段", typeof(string));
  599. dt.Columns.Add("案件系数", typeof(string));
  600. dt.Columns.Add("处理事项系数", typeof(string));
  601. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  602. dt.Columns.Add("前一次OA处理人", typeof(string));
  603. dt.Columns.Add("处理人等级", typeof(string));
  604. dt.Columns.Add("基本点数", typeof(string));
  605. dt.Columns.Add("核稿系数", typeof(string));
  606. dt.Columns.Add("核稿绩效", typeof(string));
  607. dt.Columns.Add("处理人", typeof(string));
  608. dt.Columns.Add("核稿人", typeof(string));
  609. dt.Columns.Add("客户名称", typeof(string));
  610. dt.Columns.Add("申请人", typeof(string));
  611. dt.Columns.Add("处理事项完成日", typeof(string));
  612. dt.Columns.Add("定稿日", typeof(string));
  613. dt.Columns.Add("返稿日", typeof(string));
  614. dt.Columns.Add("案件类型", typeof(string));
  615. dt.Columns.Add("案件状态", typeof(string));
  616. dt.Columns.Add("处理事项备注", typeof(string));
  617. dt.Columns.Add("处理状态", typeof(string));
  618. dt.Columns.Add("案件名称", typeof(string));
  619. dt.Columns.Add("委案日期", typeof(string));
  620. dt.Columns.Add("客户期限", typeof(string));
  621. dt.Columns.Add("内部期限", typeof(string));
  622. dt.Columns.Add("初稿日", typeof(string));
  623. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因", typeof(string));
  624. dt.Columns.Add("绩效类型", typeof(string));
  625. dt.Columns.Add("案件备注", typeof(string));
  626. dt.Columns.Add("处理人绩效系数", typeof(string));
  627. dt.Columns.Add("系统核算绩效", typeof(string));
  628. dt.Columns.Add("实际处理人", typeof(string));
  629. #endregion
  630. var verifyCeoffients = spDb.VerifyCoefficients.ToList();
  631. var Rules = spDb.BasePointRules.ToList();
  632. foreach(var p in items)
  633. {
  634. Utility.Utility.CalBasePoint(p, Rules);
  635. var jxList = _calItemJX(p.CalMonth, verifyCeoffients, p, spDb);
  636. bool isPJFP = true;
  637. bool isReviewerInDopersons = false;
  638. if (p.ReviewerId.HasValue)
  639. {
  640. isReviewerInDopersons = (p.ItemStaffs.Where(i => i.DoPersonId == p.ReviewerId).Count() > 0);
  641. }
  642. double total = p.ItemStaffs.Count();
  643. if (p.ItemStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  644. {
  645. total = p.ItemStaffs.Select(i => i.PerformancePoint.Value).Sum();
  646. isPJFP = false;
  647. }
  648. foreach (var iStaff in p.ItemStaffs)
  649. {
  650. DataRow row = dt.NewRow();
  651. row["我方文号"] = p.CaseNo;
  652. row["申请类型"] = p.ApplicationType;
  653. if(p.Customer.Name.Contains("OPPO") && p.ApplicationType == "实用新型")
  654. {
  655. row["申请类型"] = "发明";
  656. row["案件备注"] = $"{row["案件备注"]}\r\nOPPO案件实用新型修改为发明】";
  657. }
  658. row["业务类型"] = p.BusinessType;
  659. row["备注(填表注意事项)"] = p.AgentFeedbackMemo;
  660. row["处理事项"] = p.DoItem;
  661. row["案件阶段"] = p.CaseStage;
  662. row["案件系数"] = p.CaseCoefficient;
  663. if(p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo))
  664. {
  665. switch (p.CaseCoefficient)
  666. {
  667. case "S":
  668. row["案件系数"] = "A";
  669. break;
  670. case "A":
  671. row["案件系数"] = "B";
  672. break;
  673. case "B":
  674. row["案件系数"] = "C";
  675. break;
  676. case "C":
  677. row["案件系数"] = "D";
  678. break;
  679. }
  680. row["案件备注"] = $"{row["案件备注"]}\r\n严重延期降系数【{p.CaseCoefficient}->{row["案件系数"]}】";
  681. }
  682. row["处理事项系数"] = p.DoItemCoefficient;
  683. row["前一次OA处理事项系数"] = "";
  684. row["前一次OA处理人"] = p.PreOastaff.Name;
  685. if(iStaff.DoPerson.Status == "试用期")
  686. {
  687. row["实际处理人"] = iStaff.DoPerson.Name;
  688. row["案件备注"] = $"{row["案件备注"]}\r\n处理人{iStaff.DoPerson.Name}未转正";
  689. row["处理人"] = p.Reviewer.Name;
  690. row["处理人等级"] = p.Reviewer.StaffGrade.Grade;
  691. row["基本点数"] = (p.BasePoint / total).ToString();
  692. row["核稿人"] = "";
  693. row["核稿系数"] = "";
  694. row["核稿绩效"] = "";
  695. row["处理人绩效系数"] = p.Reviewer.StaffGrade.Coefficient;
  696. row["系统核算绩效"] = "";
  697. }
  698. else
  699. {
  700. row["处理人"] = iStaff.DoPerson.Name;
  701. row["处理人等级"] = iStaff.DoPerson.StaffGrade.Grade;
  702. row["基本点数"] = (p.BasePoint / total).ToString();
  703. row["处理人绩效系数"] = iStaff.DoPerson.StaffGrade.Coefficient;
  704. row["系统核算绩效"] = "";
  705. if (isReviewerInDopersons)
  706. {
  707. row["核稿人"] = "";
  708. row["核稿系数"] = "";
  709. row["核稿绩效"] = "";
  710. row["处理人绩效系数"] = "";
  711. row["系统核算绩效"] = "";
  712. row["案件备注"] = $"{row["案件备注"]}\r\n核稿人与处理人一致,置空核稿人栏位";
  713. }
  714. else
  715. {
  716. row["核稿人"] = p.Reviewer?.Name;
  717. var vCoefficient = Context.VerifyCoefficients.FirstOrDefault(c => c.CheckerId == p.ReviewerId && c.DoPersonId == iStaff.DoPersonId);
  718. if (vCoefficient != null)
  719. {
  720. row["核稿系数"] = vCoefficient.Coefficient;
  721. row["核稿绩效"] = (p.BasePoint / total) * vCoefficient.Coefficient;
  722. }
  723. }
  724. }
  725. row["客户名称"] = p.Customer.Name;
  726. row["申请人"] = p.ApplicationName;
  727. row["处理事项完成日"] = p.FinishedDate?.ToString("yyyy-MM-dd");
  728. row["定稿日"] = p.FinalizationDate?.ToString("yyyy-MM-dd");
  729. row["返稿日"] = p.ReturnDate?.ToString("yyyy-MM-dd");
  730. row["案件类型"] = p.CaseType;
  731. row["案件状态"] = p.CaseState;
  732. row["处理事项备注"] = p.DoItemMemo;
  733. row["处理状态"] = p.DoItemState;
  734. row["案件名称"] = p.CaseName;
  735. row["委案日期"] = p.EntrustingDate?.ToString("yyyy-MM-dd");
  736. row["客户期限"] = p.CustomerLimitDate?.ToString("yyyy-MM-dd");
  737. row["内部期限"] = p.InternalDate?.ToString("yyyy-MM-dd");
  738. row["初稿日"] = p.FirstDraftDate?.ToString("yyyy-MM-dd");
  739. row["备注(发文严重超期是否属客观原因,若为否,请填写原因"] = p.OverDueMemo;
  740. row["绩效类型"] = p.Type;
  741. row["案件备注"] = p.CaseMemo;
  742. dt.Rows.Add(row);
  743. }
  744. }
  745. NPOIExcel.DataTableToExcel(dt,$"c:\\temp\\{DateTime.Now.ToString("yyyyMMddhhmmss")}-线下绩效核算数据.xlsx");
  746. }
  747. private void _CompareExcel2DB()
  748. {
  749. DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0,2);
  750. DataTable retTable = new DataTable();
  751. retTable.Columns.Add("我方文号");
  752. retTable.Columns.Add("申请类型");
  753. retTable.Columns.Add("业务类型");
  754. retTable.Columns.Add("备注(填表注意事项)");
  755. retTable.Columns.Add("备注(填表注意事项)【系统】");
  756. retTable.Columns.Add("处理事项");
  757. retTable.Columns.Add("处理事项【系统】");
  758. retTable.Columns.Add("案件阶段");
  759. retTable.Columns.Add("案件阶段【系统】");
  760. retTable.Columns.Add("案件系数");
  761. retTable.Columns.Add("案件系数【系统】");
  762. retTable.Columns.Add("处理事项系数");
  763. retTable.Columns.Add("处理事项系数【系统】");
  764. retTable.Columns.Add("处理人等级");
  765. retTable.Columns.Add("处理人等级【系统】");
  766. retTable.Columns.Add("处理人系数");
  767. retTable.Columns.Add("处理人系数【系统】");
  768. retTable.Columns.Add("基本点数");
  769. retTable.Columns.Add("基本点数【系统】");
  770. retTable.Columns.Add("核稿系数");
  771. retTable.Columns.Add("核稿系数【系统】");
  772. retTable.Columns.Add("核稿绩效");
  773. retTable.Columns.Add("核稿绩效【系统】");
  774. retTable.Columns.Add("处理人");
  775. retTable.Columns.Add("处理人【系统】");
  776. retTable.Columns.Add("核稿人");
  777. retTable.Columns.Add("核稿人【系统】");
  778. retTable.Columns.Add("严重超期备注原因");
  779. retTable.Columns.Add("严重超期备注原因【系统】");
  780. retTable.Columns.Add("是否一致");
  781. retTable.Columns.Add("不一致原因");
  782. spDbContext spDb = new spDbContext();
  783. List<PerformanceItem> items = spDb.PerformanceItems
  784. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  785. .Include(p=>p.Customer)
  786. .Include(p=>p.ItemStaffs).ThenInclude(s=>s.DoPerson).ThenInclude(s=>s.StaffGrade)
  787. .Where(p=>p.CalMonth.Status ==0 && !p.CaseNo.StartsWith("J")).OrderBy(p=>p.CaseNo).ThenBy(p=>p.DoItem).ToList();
  788. excelDT.DefaultView.Sort = "我方文号,处理事项";
  789. DataTable temDt = excelDT.DefaultView.ToTable();
  790. int iTable = 0;
  791. int iList = 0;
  792. CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p=>p.Status ==0);
  793. var verifyCoefficients = spDb.VerifyCoefficients.ToList();
  794. var Rules = spDb.BasePointRules.ToList();
  795. while (iTable < temDt.Rows.Count && iList < items.Count)
  796. {
  797. System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
  798. DataRow row = temDt.Rows[iTable];
  799. PerformanceItem item = items[iList];
  800. if(row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString()== "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
  801. {
  802. var temRow = retTable.NewRow();
  803. int iBegin = iTable;
  804. int iEnd = iTable;
  805. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  806. if (iEnd < temDt.Rows.Count - 1)
  807. {
  808. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  809. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  810. {
  811. iEnd++;
  812. }
  813. }
  814. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  815. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  816. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  817. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  818. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  819. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  820. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  821. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  822. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  823. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  824. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  825. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  826. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  827. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  828. for (int i = iBegin; i <= iEnd; i++)
  829. {
  830. temRow["备注(填表注意事项)"] =string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ?temDt.Rows[i]["备注(填表注意事项)"] :$"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  831. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  832. temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
  833. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  834. {
  835. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  836. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  837. }
  838. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  839. }
  840. iTable = iEnd;
  841. #endregion
  842. Utility.Utility.CalBasePoint(item, Rules);
  843. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  844. try
  845. {
  846. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  847. }
  848. catch { }
  849. temRow["案件阶段【系统】"] = item.CaseStage;
  850. temRow["案件系数【系统】"] = item.CaseCoefficient;
  851. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  852. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  853. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  854. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  855. temRow["严重超期备注原因"] = item.OverDueMemo;
  856. if (retPoints != null && retPoints.Count > 0)
  857. {
  858. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
  859. foreach (var itemStaff in item.ItemStaffs)
  860. {
  861. //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  862. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  863. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  864. if (item.ReviewerId != null)
  865. {
  866. #region 取审核人等级审核等级系数
  867. VerifyCoefficient vcoefficient
  868. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  869. v.CheckerId == item.Reviewer.StaffGradeId
  870. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  871. .FirstOrDefault<VerifyCoefficient>();
  872. #endregion
  873. if (vcoefficient != null)
  874. {
  875. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  876. }
  877. }
  878. }
  879. }
  880. temRow["是否一致"] = "";
  881. temRow["不一致原因"] = "";
  882. if(temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
  883. {
  884. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
  885. }
  886. if (temRow["案件系数【系统】"].ToString().Trim() != temRow["案件系数"].ToString().Trim())
  887. {
  888. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件系数" : $"{temRow["不一致原因"]},案件系数";
  889. }
  890. if (temRow["处理事项系数【系统】"].ToString().Trim() != temRow["处理事项系数"].ToString().Trim())
  891. {
  892. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "处理事项系数" : $"{temRow["不一致原因"]},处理事项系数";
  893. }
  894. if (temRow["核稿人【系统】"].ToString().Trim() != temRow["核稿人"].ToString().Trim())
  895. {
  896. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "核稿人" : $"{temRow["不一致原因"]},核稿人";
  897. }
  898. if (temRow["基本点数【系统】"].ToString().Trim() != temRow["基本点数"].ToString().Trim())
  899. {
  900. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "基本点数" : $"{temRow["不一致原因"]},基本点数";
  901. }
  902. if (temRow["严重超期备注原因【系统】"].ToString().Trim() != temRow["严重超期备注原因"].ToString().Trim())
  903. {
  904. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "严重超期备注原因" : $"{temRow["不一致原因"]},严重超期备注原因";
  905. }
  906. if (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
  907. {
  908. temRow["是否一致"] = "不一致";
  909. }
  910. retTable.Rows.Add(temRow);
  911. iTable++;
  912. iList++;
  913. }
  914. else
  915. {
  916. string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
  917. string strList = $"{item.CaseNo}-{item.DoItem}";
  918. if (strDT.CompareTo(strList) > 0)
  919. {
  920. var temRow = retTable.NewRow();
  921. Utility.Utility.CalBasePoint(item, Rules);
  922. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  923. try
  924. {
  925. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  926. }
  927. catch { }
  928. temRow["我方文号"] = item.CaseNo;
  929. temRow["处理事项"] = item.DoItem;
  930. temRow["申请类型"] = item.ApplicationType;
  931. temRow["业务类型"] = item.BusinessType;
  932. temRow["案件阶段【系统】"] = item.CaseStage;
  933. temRow["案件系数【系统】"] = item.CaseCoefficient;
  934. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  935. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  936. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  937. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  938. temRow["严重超期备注原因"] = item.OverDueMemo;
  939. if (item.ReviewerId != null)
  940. {
  941. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  942. }
  943. foreach (var itemStaff in item.ItemStaffs)
  944. {
  945. //if (itemStaff.DoPerson.Status != "试用期")
  946. //{
  947. // if (retPoints != null && retPoints.Count > 0)
  948. // {
  949. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  950. // }
  951. //}
  952. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  953. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  954. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  955. if (item.ReviewerId != null)
  956. {
  957. #region 取审核人等级审核等级系数
  958. VerifyCoefficient vcoefficient
  959. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  960. v.CheckerId == item.Reviewer.StaffGradeId
  961. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  962. .FirstOrDefault<VerifyCoefficient>();
  963. #endregion
  964. if (vcoefficient != null)
  965. {
  966. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  967. }
  968. }
  969. }
  970. temRow["是否一致"] = "不一致";
  971. temRow["不一致原因"] = "Excel中没有,系统中有";
  972. retTable.Rows.Add(temRow);
  973. iList++;
  974. }
  975. else
  976. {
  977. var temRow = retTable.NewRow();
  978. int iBegin = iTable;
  979. int iEnd = iTable;
  980. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  981. if (iEnd < temDt.Rows.Count - 1)
  982. {
  983. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  984. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  985. {
  986. iEnd++;
  987. }
  988. }
  989. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  990. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  991. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  992. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  993. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  994. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  995. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  996. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  997. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  998. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  999. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1000. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1001. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1002. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1003. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1004. for (int i = iBegin+1; i <= iEnd; i++)
  1005. {
  1006. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1007. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1008. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1009. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1010. {
  1011. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1012. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1013. }
  1014. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1015. }
  1016. iTable = iEnd;
  1017. #endregion
  1018. temRow["是否一致"] = "不一致";
  1019. temRow["不一致原因"] = "系统中没有,Excel中有";
  1020. retTable.Rows.Add(temRow);
  1021. iTable++;
  1022. }
  1023. }
  1024. }
  1025. if (iList <=items.Count)
  1026. {
  1027. while(iList <items.Count){
  1028. var item = items[iList];
  1029. var temRow = retTable.NewRow();
  1030. Utility.Utility.CalBasePoint(item, Rules);
  1031. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1032. try
  1033. {
  1034. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  1035. }
  1036. catch { }
  1037. temRow["我方文号"] = item.CaseNo;
  1038. temRow["处理事项"] = item.DoItem;
  1039. temRow["申请类型"] = item.ApplicationType;
  1040. temRow["业务类型"] = item.BusinessType;
  1041. temRow["案件阶段【系统】"] = item.CaseStage;
  1042. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1043. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1044. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1045. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1046. temRow["基本点数【系统】"] = "";// item.BasePoint?.ToString();
  1047. temRow["严重超期备注原因"] = item.OverDueMemo;
  1048. if (item.ReviewerId != null)
  1049. {
  1050. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1051. }
  1052. foreach (var itemStaff in item.ItemStaffs)
  1053. {
  1054. //if (itemStaff.DoPerson.Status != "试用期")
  1055. //{
  1056. // if (retPoints != null && retPoints.Count > 0)
  1057. // {
  1058. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1059. // }
  1060. //}
  1061. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1062. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1063. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1064. if (item.ReviewerId != null)
  1065. {
  1066. #region 取审核人等级审核等级系数
  1067. VerifyCoefficient vcoefficient
  1068. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1069. v.CheckerId == item.Reviewer.StaffGradeId
  1070. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1071. .FirstOrDefault<VerifyCoefficient>();
  1072. #endregion
  1073. if (vcoefficient != null)
  1074. {
  1075. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1076. }
  1077. }
  1078. }
  1079. temRow["是否一致"] = "不一致";
  1080. temRow["不一致原因"] = "Excel中没有,系统中有";
  1081. iList++;
  1082. retTable.Rows.Add(temRow);
  1083. }
  1084. }
  1085. else
  1086. {
  1087. while (iTable < temDt.Rows.Count)
  1088. {
  1089. var temRow = retTable.NewRow();
  1090. int iBegin = iTable;
  1091. int iEnd = iTable;
  1092. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1093. while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
  1094. temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
  1095. {
  1096. iEnd++;
  1097. }
  1098. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1099. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1100. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1101. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1102. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1103. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1104. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1105. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1106. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1107. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1108. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1109. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1110. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1111. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1112. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1113. for (int i = iBegin + 1; i <= iEnd; i++)
  1114. {
  1115. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1116. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1117. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1118. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1119. {
  1120. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1121. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1122. }
  1123. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["严重超期备注原因"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["严重超期备注原因"]}";
  1124. }
  1125. iTable = iEnd;
  1126. #endregion
  1127. temRow["是否一致"] = "不一致";
  1128. temRow["不一致原因"] = "系统中没有,Excel中有";
  1129. retTable.Rows.Add(temRow);
  1130. iTable++;
  1131. }
  1132. }
  1133. NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
  1134. }
  1135. public List<StaffStatistics> CalItemJX(int itemid)
  1136. {
  1137. var Item = Context.PerformanceItems.Include(p=>p.CalMonth).FirstOrDefault(p=>p.Id == itemid);
  1138. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  1139. return _calItemJX(Item.CalMonth,verifyCoefficients,Item,Context);
  1140. }
  1141. private List<StaffStatistics> _calItemJX(CalMonth calMonth, List<VerifyCoefficient> verifyCoefficients, PerformanceItem item,spDbContext spDb)
  1142. {
  1143. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  1144. bool isPJFP = true;
  1145. double total = item.ItemStaffs.Count();
  1146. if (item.ItemStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  1147. {
  1148. total = item.ItemStaffs.Select(i => i.PerformancePoint.Value).Sum();
  1149. isPJFP = false;
  1150. }
  1151. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  1152. if (item.ReviewerId != null)
  1153. {
  1154. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  1155. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  1156. }
  1157. foreach (ItemStaff itemStaff in item.ItemStaffs)
  1158. {
  1159. if(itemStaff.DoPerson == null)
  1160. {
  1161. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  1162. }
  1163. //spDb.Entry(itemStaff).Reference(b => b.DoPerson).Load();
  1164. //spDb.Entry(itemStaff.DoPerson).Reference(b => b.StaffGrade).Load();
  1165. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  1166. if (item.ReviewerId != null && item.Type != "专案" &&
  1167. item.ItemStaffs.FirstOrDefault(s=>s.DoPersonId == item.ReviewerId) == null)
  1168. {
  1169. #region 取审核人等级审核等级系数
  1170. VerifyCoefficient vcoefficient
  1171. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1172. v.CheckerId == item.Reviewer.StaffGradeId
  1173. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1174. .FirstOrDefault<VerifyCoefficient>();
  1175. #endregion
  1176. if (vcoefficient != null)
  1177. {
  1178. double reviewerBasePoint = item.BasePoint.Value * vcoefficient.Coefficient;
  1179. string temJxType = $"{item.Type}审核";
  1180. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  1181. if (temReviewerStatic != null)
  1182. {
  1183. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  1184. }
  1185. else
  1186. {
  1187. if (item.Reviewer.IsOnJob && itemStaff.DoPerson.Status != "试用期") //判断是否在职
  1188. {
  1189. temReviewerStatic = new StaffStatistics()
  1190. {
  1191. CalMonth = calMonth,
  1192. CalMonthId = calMonth.Id,
  1193. StaffId = item.ReviewerId.Value,
  1194. totalBasePoint = reviewerBasePoint,
  1195. jxType = temJxType
  1196. };
  1197. itemStatistics.Add(temReviewerStatic);
  1198. }
  1199. }
  1200. }
  1201. }
  1202. #endregion
  1203. #region 计算各处理人的绩效点数
  1204. double handlerBasePoint;
  1205. if (item.Type != "专案")
  1206. {
  1207. if (isPJFP)
  1208. {
  1209. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1210. }
  1211. else
  1212. {
  1213. handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
  1214. }
  1215. }
  1216. else
  1217. {
  1218. if (itemStaff.PerformancePoint == null)
  1219. {
  1220. if (isPJFP)
  1221. {
  1222. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1223. }
  1224. else
  1225. {
  1226. handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
  1227. }
  1228. }
  1229. else
  1230. {
  1231. handlerBasePoint = itemStaff.PerformancePoint.Value;
  1232. }
  1233. }
  1234. string handlerJxType = $"{item.Type}处理";
  1235. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  1236. if (temStatic != null)
  1237. {
  1238. if (item.Type != "专案")
  1239. {
  1240. temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
  1241. }
  1242. else
  1243. {
  1244. temStatic.totalBasePoint += handlerBasePoint;
  1245. }
  1246. }
  1247. else
  1248. {
  1249. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsOnJob)
  1250. {
  1251. if (item.Type != "专案")
  1252. {
  1253. if (itemStaff.DoPerson.Status == "试用期" && item.Reviewer != null)
  1254. {
  1255. temStatic = new StaffStatistics()
  1256. {
  1257. CalMonth = calMonth,
  1258. CalMonthId = calMonth.Id,
  1259. StaffId = item.Reviewer.Id,
  1260. totalBasePoint = handlerBasePoint * item.Reviewer.StaffGrade.Coefficient,
  1261. jxType = handlerJxType
  1262. };
  1263. itemStatistics.Add(temStatic);
  1264. }
  1265. else
  1266. {
  1267. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s=>s.Id == itemStaff.DoPerson.StaffGradeId);
  1268. temStatic = new StaffStatistics()
  1269. {
  1270. CalMonth = calMonth,
  1271. CalMonthId = calMonth.Id,
  1272. StaffId = itemStaff.DoPersonId,
  1273. totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
  1274. jxType = handlerJxType
  1275. };
  1276. itemStatistics.Add(temStatic);
  1277. }
  1278. }
  1279. else
  1280. {
  1281. temStatic = new StaffStatistics()
  1282. {
  1283. CalMonth = calMonth,
  1284. CalMonthId = calMonth.Id,
  1285. StaffId = itemStaff.DoPersonId,
  1286. totalBasePoint = handlerBasePoint,
  1287. jxType = handlerJxType
  1288. };
  1289. itemStatistics.Add(temStatic);
  1290. }
  1291. }
  1292. }
  1293. #endregion
  1294. }
  1295. return itemStatistics;
  1296. }
  1297. public ApiSaveResponse FinishedCalMonth(int year,int month)
  1298. {
  1299. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1300. if (calMonth != null || calMonth.Status !=4)
  1301. {
  1302. var retList = _CalMyStatistics(calMonth);
  1303. using (var t = Context.Database.BeginTransaction())
  1304. {
  1305. try
  1306. {
  1307. Context.SaveChanges();
  1308. foreach (var obj in retList)
  1309. {
  1310. obj.CalMonthId = calMonth.Id;
  1311. obj.CalMonth = null;
  1312. Context.StaffStatistics.Add(obj);
  1313. Context.SaveChanges();
  1314. }
  1315. calMonth.Status = 4;
  1316. Context.SaveChanges();
  1317. t.Commit();
  1318. return new ApiSaveResponse()
  1319. {
  1320. Success = true
  1321. };
  1322. }
  1323. catch(Exception ex)
  1324. {
  1325. t.Rollback();
  1326. return new ApiSaveResponse()
  1327. {
  1328. Success = false,
  1329. ErrorMessage = ex.Message
  1330. };
  1331. }
  1332. }
  1333. }
  1334. else
  1335. {
  1336. return new ApiSaveResponse()
  1337. {
  1338. Success = false,
  1339. ErrorMessage ="指定月份没有数据或者已归档!"
  1340. };
  1341. }
  1342. }
  1343. /// <summary>
  1344. /// 计算指定用户,指定年月的绩效统计信息
  1345. /// </summary>
  1346. /// <param name="userid"></param>
  1347. /// <param name="year"></param>
  1348. /// <param name="month"></param>
  1349. /// <returns></returns>
  1350. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  1351. {
  1352. object retList;
  1353. string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
  1354. if(!MyMemoryCache.TryGetValue(strKey,out retList))
  1355. {
  1356. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1357. if (calMonth == null)
  1358. {
  1359. return null;
  1360. }
  1361. else
  1362. {
  1363. if (calMonth.Status == 4)
  1364. {
  1365. //已归档,归档数据库中直接取出记录
  1366. if (userid == null)
  1367. {
  1368. retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  1369. }
  1370. else
  1371. {
  1372. retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  1373. }
  1374. }
  1375. else
  1376. {
  1377. try
  1378. {
  1379. retList = _CalMyStatistics(calMonth, userid);
  1380. }
  1381. catch(Exception ex)
  1382. {
  1383. StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  1384. sw.WriteLine($"{ex.Message}");
  1385. sw.Flush();
  1386. sw.Close();
  1387. sw.Dispose();
  1388. }
  1389. }
  1390. // Set cache options.
  1391. var cacheEntryOptions = new MemoryCacheEntryOptions()
  1392. // Keep in cache for this time, reset time if accessed.
  1393. .SetSlidingExpiration(TimeSpan.FromHours(1));
  1394. foreach(var temObj in (List<StaffStatistics>)retList)
  1395. {
  1396. temObj.CalMonth.PerformanceItems = null;
  1397. }
  1398. // Save data in cache.
  1399. MyMemoryCache.SetValue(strKey, retList);
  1400. return (List<StaffStatistics>)retList;
  1401. }
  1402. }
  1403. else
  1404. {
  1405. var temList = (List<StaffStatistics>)retList;
  1406. foreach (var temObj in temList)
  1407. {
  1408. temObj.CalMonth.PerformanceItems = null;
  1409. }
  1410. return temList;
  1411. }
  1412. }
  1413. private string GetExpress(IList<FieldCondition> conditions)
  1414. {
  1415. string str = "";
  1416. foreach(var c in conditions)
  1417. {
  1418. if (string.IsNullOrEmpty(str))
  1419. {
  1420. str = c.ToExpressString("s");
  1421. }
  1422. else
  1423. {
  1424. if(c.LogicOperate == LogicEnum.And)
  1425. {
  1426. str = $"({str}) && {c.ToExpressString("s")}";
  1427. }
  1428. else
  1429. {
  1430. str = $"({str}) || {c.ToExpressString("s")}";
  1431. }
  1432. }
  1433. }
  1434. return str;
  1435. }
  1436. [HttpGet,HttpPost]
  1437. public FileProcessTask ExportData(QueryFilter queryFilter)
  1438. {
  1439. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  1440. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  1441. var filePath = Path.Combine(attachfileSavePath, filename);
  1442. var fileTask = new FileProcessTask()
  1443. {
  1444. Id = Guid.NewGuid().ToString(),
  1445. FileName = filename,
  1446. FilePath = filePath,
  1447. Processed = 0
  1448. };
  1449. fileTaskService.Add(fileTask);
  1450. ThreadObject threadObject = new ThreadObject()
  1451. {
  1452. queryFilter = queryFilter,
  1453. fileTask = fileTask
  1454. };
  1455. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  1456. t.Start(threadObject);
  1457. return fileTask;
  1458. }
  1459. internal class ThreadObject
  1460. {
  1461. public QueryFilter queryFilter { get; set; }
  1462. public FileProcessTask fileTask { get; set; }
  1463. }
  1464. private void ExportDataThread(object tObj)
  1465. {
  1466. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  1467. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  1468. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  1469. var retList = response
  1470. .Include(p=>p.Customer)
  1471. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  1472. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  1473. .Include(p=>p.PreOastaff)
  1474. .Include(p=>p.CalMonth)
  1475. .ToList<PerformanceItem>();
  1476. DataTable dt = new DataTable();
  1477. #region 添加栏位
  1478. dt.Columns.Add("我方文号",typeof(string));
  1479. dt.Columns.Add("申请类型", typeof(string));
  1480. dt.Columns.Add("业务类型", typeof(string));
  1481. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  1482. dt.Columns.Add("处理事项", typeof(string));
  1483. dt.Columns.Add("案件阶段", typeof(string));
  1484. dt.Columns.Add("案件系数", typeof(string));
  1485. dt.Columns.Add("处理事项系数", typeof(string));
  1486. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  1487. dt.Columns.Add("前一次OA处理人", typeof(string));
  1488. dt.Columns.Add("处理人等级", typeof(string));
  1489. dt.Columns.Add("基本点数", typeof(string));
  1490. dt.Columns.Add("核稿系数", typeof(string));
  1491. dt.Columns.Add("核稿绩效", typeof(string));
  1492. dt.Columns.Add("处理人", typeof(string));
  1493. dt.Columns.Add("核稿人", typeof(string));
  1494. dt.Columns.Add("客户名称", typeof(string));
  1495. dt.Columns.Add("申请人", typeof(string));
  1496. dt.Columns.Add("处理事项完成日", typeof(string));
  1497. dt.Columns.Add("定稿日", typeof(string));
  1498. dt.Columns.Add("返稿日", typeof(string));
  1499. dt.Columns.Add("案件类型", typeof(string));
  1500. dt.Columns.Add("案件状态", typeof(string));
  1501. dt.Columns.Add("处理事项备注", typeof(string));
  1502. dt.Columns.Add("处理状态", typeof(string));
  1503. dt.Columns.Add("案件名称", typeof(string));
  1504. dt.Columns.Add("委案日期", typeof(string));
  1505. dt.Columns.Add("客户期限", typeof(string));
  1506. dt.Columns.Add("内部期限", typeof(string));
  1507. dt.Columns.Add("初稿日", typeof(string));
  1508. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
  1509. dt.Columns.Add("备注", typeof(string));
  1510. #endregion
  1511. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  1512. fileTask.Size = retList.Count;
  1513. foreach (var item in retList)
  1514. {
  1515. fileTask.Processed += 1;
  1516. if (item.CaseNo.StartsWith("J"))
  1517. {
  1518. continue;
  1519. }
  1520. try
  1521. {
  1522. var row = dt.NewRow();
  1523. row["我方文号"] = item.CaseNo;
  1524. row["申请类型"] = item.ApplicationType;
  1525. row["业务类型"] = item.BusinessType;
  1526. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  1527. row["处理事项"] = item.DoItem;
  1528. row["案件阶段"] = item.CaseStage;
  1529. row["案件系数"] = item.CaseCoefficient;
  1530. row["处理事项系数"] = item.DoItemCoefficient;
  1531. row["前一次OA处理事项系数"] = "";
  1532. if (item.PreOastaffId.HasValue)
  1533. {
  1534. row["前一次OA处理人"] = item.PreOastaff?.Name;
  1535. }
  1536. string strISLevels = "";
  1537. string strISNames = "";
  1538. foreach (var istaff in item.ItemStaffs)
  1539. {
  1540. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  1541. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  1542. }
  1543. row["处理人等级"] = strISLevels;
  1544. row["基本点数"] = item.BasePoint;
  1545. row["处理人"] = strISNames;
  1546. row["核稿人"] = item.Reviewer?.Name;
  1547. if (item.ReviewerId != null && item.BasePoint.HasValue)
  1548. {
  1549. var jxList = _calItemJX(item.CalMonth, verifyCoefficients, item, new spDbContext());
  1550. row["核稿系数"] = "";
  1551. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  1552. if (temJx != null)
  1553. {
  1554. row["核稿绩效"] = temJx.totalBasePoint;
  1555. }
  1556. }
  1557. row["客户名称"] = item.Customer?.Name;
  1558. row["申请人"] = item.ApplicationName;
  1559. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  1560. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  1561. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  1562. row["案件类型"] = item.CaseType;
  1563. row["案件状态"] = item.CaseState;
  1564. row["处理事项备注"] = item.DoItemState;
  1565. row["处理状态"] = item.DoItemState;
  1566. row["案件名称"] = item.CaseName;
  1567. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  1568. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  1569. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  1570. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  1571. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  1572. row["备注"] = item.DoItemMemo;
  1573. dt.Rows.Add(row);
  1574. }
  1575. catch(Exception ex)
  1576. {
  1577. throw ex;
  1578. }
  1579. }
  1580. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  1581. fileTask.Finished = true;
  1582. }
  1583. [HttpPost]
  1584. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  1585. {
  1586. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  1587. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  1588. int totals = response.ToList<PerformanceItem>().Count;
  1589. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  1590. {
  1591. response = response
  1592. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  1593. .Include(pi => pi.Reviewer)
  1594. .Include(pi => pi.Customer)
  1595. .Include(pi => pi.CalMonth)
  1596. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  1597. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  1598. }
  1599. else
  1600. {
  1601. response = response
  1602. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  1603. .Include(pi => pi.Reviewer)
  1604. .Include(pi => pi.Customer)
  1605. .Include(pi => pi.CalMonth)
  1606. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  1607. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  1608. }
  1609. ret.TotalCount = totals;
  1610. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  1611. #region 将某些属性设为null,避免循环取值造成返回json过大
  1612. foreach (PerformanceItem item in retList)
  1613. {
  1614. foreach (ItemStaff itemStaff in item.ItemStaffs)
  1615. {
  1616. itemStaff.DoPerson.ItemStaffs = null;
  1617. itemStaff.DoPerson.ReviewerItems = null;
  1618. itemStaff.Item = null;
  1619. }
  1620. if (item.Reviewer != null)
  1621. {
  1622. item.Reviewer.ReviewerItems = null;
  1623. item.Reviewer.Customers = null;
  1624. item.Reviewer.ItemStaffs = null;
  1625. }
  1626. if (item.Customer != null)
  1627. {
  1628. item.Customer.PerformanceItems = null;
  1629. }
  1630. if (item.CalMonth != null)
  1631. {
  1632. item.CalMonth.PerformanceItems = null;
  1633. }
  1634. }
  1635. #endregion
  1636. ret.Results = retList.ToList();
  1637. return ret;
  1638. }
  1639. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  1640. {
  1641. string strExpress = "";
  1642. string strCalMonth = "";
  1643. if (queryFilter.CalMonthId.HasValue)
  1644. {
  1645. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  1646. }
  1647. else
  1648. {
  1649. if(queryFilter.jxType == jxType.finished)
  1650. {
  1651. strCalMonth = $"s.CalMonth.Status == 4";
  1652. }
  1653. else
  1654. {
  1655. strCalMonth = $"s.CalMonth.Status != 4";
  1656. }
  1657. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  1658. }
  1659. if (!string.IsNullOrEmpty(strExpress))
  1660. {
  1661. strExpress = $"{strExpress} && {strCalMonth}";
  1662. }
  1663. else
  1664. {
  1665. strExpress = strCalMonth;
  1666. }
  1667. if (queryFilter.ConditionTree != null)
  1668. {
  1669. string strTem = GetExpress(queryFilter.ConditionTree);
  1670. if (!string.IsNullOrEmpty(strTem))
  1671. {
  1672. strExpress = $"{strExpress} && ({strTem})";
  1673. }
  1674. }
  1675. var interpreter = new Interpreter();
  1676. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  1677. IQueryable<PerformanceItem> response;
  1678. if (queryFilter.userId > 0)
  1679. {
  1680. if (queryFilter.DoingOrReview == 0)
  1681. {
  1682. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  1683. }
  1684. else
  1685. {
  1686. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  1687. }
  1688. }
  1689. else
  1690. {
  1691. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  1692. }
  1693. return response;
  1694. }
  1695. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  1696. {
  1697. ApiSaveResponse retResponse = new ApiSaveResponse();
  1698. retResponse.Success = true;
  1699. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  1700. {
  1701. using (var t = Context.Database.BeginTransaction())
  1702. {
  1703. try
  1704. {
  1705. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  1706. if (calMonth == null)
  1707. {
  1708. retResponse.Success = false;
  1709. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  1710. return retResponse;
  1711. }
  1712. else
  1713. {
  1714. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  1715. projectContents.ProjectContentRecord.CalMonth = null;
  1716. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  1717. projectContents.ProjectContentRecord.StaffId = staff.Id;
  1718. projectContents.ProjectContentRecord.State = 0;
  1719. }
  1720. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  1721. if (project != null)
  1722. {
  1723. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  1724. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  1725. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  1726. if(pRecord != null)
  1727. {
  1728. retResponse.Success = false;
  1729. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  1730. return retResponse;
  1731. }
  1732. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  1733. foreach (var doItem in projectContents.ProjectWorkContents)
  1734. {
  1735. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  1736. Context.ProjectWorkContents.Add(doItem);
  1737. }
  1738. t.Commit();
  1739. }
  1740. else
  1741. {
  1742. retResponse.Success = false;
  1743. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  1744. return retResponse;
  1745. }
  1746. }
  1747. catch (Exception ex)
  1748. {
  1749. retResponse.Success = false;
  1750. retResponse.ErrorMessage = ex.Message;
  1751. t.Rollback();
  1752. return retResponse;
  1753. }
  1754. }
  1755. }
  1756. return retResponse;
  1757. }
  1758. public PerformanceItem GetCaseInfo(string CaseNo)
  1759. {
  1760. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  1761. if(retObj == null)
  1762. {
  1763. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  1764. }
  1765. return retObj;
  1766. }
  1767. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  1768. {
  1769. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  1770. if (retObj == null)
  1771. {
  1772. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  1773. }
  1774. return retObj;
  1775. }
  1776. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage)
  1777. {
  1778. var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  1779. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  1780. if (retObj == null)
  1781. {
  1782. retObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  1783. }
  1784. return retObj;
  1785. }
  1786. public bool MovePerformance2ProjectInfo()
  1787. {
  1788. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  1789. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  1790. var pList = response.ToList<PerformanceItem>();
  1791. foreach(var p in pList)
  1792. {
  1793. ProjectInfo project = new ProjectInfo();
  1794. project.CaseNo = p.CaseNo;
  1795. project.CaseName = p.CaseName;
  1796. project.CaseState = 0;
  1797. project.CaseType = p.CaseType;
  1798. project.CustomerId = p.CustomerId;
  1799. project.ReviewerId = p.ReviewerId;
  1800. Context.ProjectInfos.Add(project);
  1801. foreach(ItemStaff iStaff in p.ItemStaffs)
  1802. {
  1803. Context.ItemStaffs.Remove(iStaff);
  1804. }
  1805. Context.PerformanceItems.Remove(p);
  1806. Context.SaveChanges();
  1807. }
  1808. return true;
  1809. }
  1810. }
  1811. }