PerformanceItemController.cs 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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.Hosting;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Linq.Expressions;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using wispro.sp.api.Services;
  17. using wispro.sp.api.Utility;
  18. using wispro.sp.entity;
  19. using wispro.sp.share;
  20. using wispro.sp.utility;
  21. namespace wispro.sp.api.Controllers
  22. {
  23. [Route("api/[controller]/[action]")]
  24. [ApiController]
  25. [Authorize]
  26. public class PerformanceItemController : ControllerBase
  27. {
  28. spDbContext Context;
  29. IFileTaskService fileTaskService;
  30. public PerformanceItemController(spDbContext context, IFileTaskService _fileTaskService)
  31. {
  32. Context = context;
  33. fileTaskService = _fileTaskService;
  34. }
  35. public bool IsExist(PerformanceItem item)
  36. {
  37. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  38. x.CaseNo == item.CaseNo &&
  39. x.DoItem == item.DoItem &&
  40. x.CaseStage == item.CaseStage &&
  41. x.CalMonth.Year == item.CalMonth.Year &&
  42. x.CalMonth.Month == item.CalMonth.Month);
  43. if(results.Count() > 0)
  44. {
  45. return true;
  46. }
  47. else
  48. {
  49. return false;
  50. }
  51. }
  52. public ApiSaveResponse New(PerformanceItem item)
  53. {
  54. ApiSaveResponse ret = new ApiSaveResponse();
  55. ret.Success = true;
  56. using (Context.Database.BeginTransaction())
  57. {
  58. try
  59. {
  60. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  61. x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  62. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  63. if (items != null)
  64. {
  65. item.AgentFeedbackMemo = "已算绩效";
  66. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  67. item.BasePoint = 0;
  68. }
  69. if (item.CalMonth != null)
  70. {
  71. var calMonth = Context.CalMonths.Where<CalMonth>(c => c.Year == item.CalMonth.Year && c.Month == item.CalMonth.Month).FirstOrDefault();
  72. if(calMonth == null)
  73. {
  74. Context.CalMonths.Add(item.CalMonth);
  75. Context.SaveChanges();
  76. }
  77. else
  78. {
  79. item.CalMonth = calMonth;
  80. }
  81. item.CalMonthId = item.CalMonth.Id;
  82. item.CalMonth = null;
  83. }
  84. if (!string.IsNullOrEmpty(item.Customer.Name))
  85. {
  86. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  87. if (temCustomer == null)
  88. {
  89. temCustomer = new Customer() { Name = item.Customer.Name };
  90. //item.Customer.Id = 0;
  91. Context.Customers.Add(temCustomer);
  92. Context.SaveChanges();
  93. item.Customer = temCustomer;
  94. //item.CustomerId = item.Customer.Id;
  95. }
  96. else
  97. {
  98. item.Customer = temCustomer;
  99. }
  100. item.CustomerId = item.Customer.Id;
  101. item.Customer = null;
  102. }
  103. else
  104. {
  105. item.Customer = null;
  106. }
  107. var ItemStaffs = item.ItemStaffs;
  108. item.ItemStaffs = null;
  109. Context.PerformanceItems.Add(item);
  110. Context.SaveChanges();
  111. foreach (ItemStaff itemStaff in ItemStaffs)
  112. {
  113. itemStaff.ItemId = item.Id;
  114. itemStaff.Item = null;
  115. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  116. {
  117. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  118. if (temStaff != null)
  119. {
  120. itemStaff.DoPersonId = temStaff.Id;
  121. itemStaff.DoPerson = null;
  122. }
  123. else
  124. {
  125. Context.Staffs.Add(itemStaff.DoPerson);
  126. Context.SaveChanges();
  127. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  128. itemStaff.DoPerson = null;
  129. }
  130. }
  131. }
  132. Context.ItemStaffs.AddRange(ItemStaffs);
  133. Context.SaveChanges();
  134. Context.Database.CommitTransaction();
  135. }
  136. catch (Exception ex)
  137. {
  138. ret.Success = false;
  139. ret.ErrorMessage = ex.Message;
  140. Context.Database.RollbackTransaction();
  141. }
  142. }
  143. return ret;
  144. }
  145. /// <summary>
  146. /// 更新绩效记录信息
  147. /// </summary>
  148. /// <param name="id">绩效记录编号</param>
  149. /// <param name="field">栏位,多个位以|杠隔开</param>
  150. /// <param name="value">栏位值,多个以|杠隔开</param>
  151. /// <returns></returns>
  152. public ApiSaveResponse UpdateFieldValue(int id,string field,string value)
  153. {
  154. ApiSaveResponse ret = new ApiSaveResponse();
  155. ret.Success = true;
  156. var item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == id);
  157. if (item == null)
  158. {
  159. ret.Success = false;
  160. ret.ErrorMessage = $"不存在的{id}";
  161. return ret;
  162. }
  163. if(string.IsNullOrEmpty(field) )
  164. {
  165. ret.Success = false;
  166. ret.ErrorMessage = $"参数不对!";
  167. return ret;
  168. }
  169. string[] fields = field.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  170. string[] values = new string[] { null };
  171. if (!string.IsNullOrEmpty(value))
  172. {
  173. values = value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  174. }
  175. if (fields.Length != values.Length) {
  176. ret.Success = false;
  177. ret.ErrorMessage = "栏位和值对不匹配";
  178. }
  179. else
  180. {
  181. for(int i = 0; i < fields.Length; i++)
  182. {
  183. string temField = fields[i];
  184. string temValue = values[i];
  185. switch (temField)
  186. {
  187. case "AgentFeedbackMemo":
  188. item.AgentFeedbackMemo = temValue;
  189. break;
  190. case "CaseCoefficient":
  191. item.CaseCoefficient = temValue;
  192. //此处添加保存到流程系统的代码
  193. break;
  194. case "DoItemCoefficient":
  195. item.DoItemCoefficient = temValue;
  196. //此处添加保存到流程系统的代码
  197. break;
  198. case "WordCount":
  199. int wordCount;
  200. if (int.TryParse(temValue, out wordCount))
  201. {
  202. item.WordCount = wordCount;
  203. }
  204. else
  205. {
  206. ret.Success = false;
  207. ret.ErrorMessage = "所给的栏位值不能转换成数字!";
  208. return ret;
  209. }
  210. break;
  211. case "ReturnCasseNo":
  212. item.ReturnCasseNo = temValue;
  213. break;
  214. }
  215. }
  216. Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
  217. Context.SaveChanges();
  218. }
  219. return ret;
  220. }
  221. public ListApiResponse<PerformanceItem> Query(int pageIndex,int pageSize)
  222. {
  223. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  224. var results = Context.PerformanceItems
  225. .Where<PerformanceItem>(s =>
  226. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == User.Identity.Name).Count() > 0 || s.Reviewer.Name == User.Identity.Name)
  227. && s.CalMonth.Status != 4);
  228. ret.TotalCount = results.Count();
  229. List<PerformanceItem> retList = results
  230. .Include(pi=>pi.ItemStaffs).ThenInclude(iStaff=>iStaff.DoPerson)
  231. .Include(pi=>pi.Reviewer)
  232. .Include(pi=>pi.Customer)
  233. .Include(pi=>pi.CalMonth)
  234. .OrderByDescending(o=>o.Id)
  235. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize).ToList<PerformanceItem>();
  236. #region 将某些属性设为null,避免循环取值造成返回json过大
  237. foreach (PerformanceItem item in retList)
  238. {
  239. foreach (ItemStaff itemStaff in item.ItemStaffs)
  240. {
  241. itemStaff.DoPerson.ItemStaffs = null;
  242. itemStaff.DoPerson.ReviewerItems = null;
  243. itemStaff.Item = null;
  244. }
  245. item.Reviewer.ReviewerItems = null;
  246. item.Reviewer.Customers = null;
  247. item.Reviewer.ItemStaffs = null;
  248. item.Customer.PerformanceItems = null;
  249. item.CalMonth.PerformanceItems = null;
  250. }
  251. #endregion
  252. ret.Results = retList;
  253. return ret;
  254. }
  255. public PerformanceItem Get(int Id)
  256. {
  257. var results = Context.PerformanceItems
  258. .Where<PerformanceItem>(s =>s.Id == Id);
  259. PerformanceItem item = results
  260. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  261. .Include(pi => pi.Reviewer)
  262. .Include(pi => pi.Customer)
  263. .Include(pi => pi.CalMonth)
  264. .OrderByDescending(o => o.Id)
  265. .FirstOrDefault();
  266. #region 将某些属性设为null,避免循环取值造成返回json过大
  267. foreach (ItemStaff itemStaff in item.ItemStaffs)
  268. {
  269. itemStaff.DoPerson.ItemStaffs = null;
  270. itemStaff.DoPerson.ReviewerItems = null;
  271. itemStaff.Item = null;
  272. }
  273. if (item.Reviewer != null)
  274. {
  275. item.Reviewer.ReviewerItems = null;
  276. item.Reviewer.Customers = null;
  277. item.Reviewer.ItemStaffs = null;
  278. }
  279. item.Customer.PerformanceItems = null;
  280. item.CalMonth.PerformanceItems = null;
  281. #endregion
  282. return item;
  283. }
  284. /// <summary>
  285. /// 获取给定用户的绩效清单
  286. /// </summary>
  287. /// <param name="userid">用户id</param>
  288. /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
  289. /// <returns></returns>
  290. public ListApiResponse<PerformanceItem> GetMyList(int userid, int type,int pageIndex=1,int pageSize = 10)
  291. {
  292. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  293. var results = Context.PerformanceItems
  294. .Where<PerformanceItem>(s =>
  295. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid ).Count() > 0 || s.Reviewer.Id == userid )
  296. && s.CalMonth.Status == type);
  297. ret.TotalCount = results.Count();
  298. List<PerformanceItem> retList = results
  299. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  300. .Include(pi => pi.Reviewer)
  301. .Include(pi => pi.Customer)
  302. .Include(pi => pi.CalMonth)
  303. .OrderByDescending(o => o.Id)
  304. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize)
  305. .ToList<PerformanceItem>();
  306. #region 将某些属性设为null,避免循环取值造成返回json过大
  307. foreach (PerformanceItem item in retList)
  308. {
  309. foreach(ItemStaff itemStaff in item.ItemStaffs)
  310. {
  311. itemStaff.DoPerson.ItemStaffs = null;
  312. itemStaff.DoPerson.ReviewerItems = null;
  313. itemStaff.Item = null;
  314. }
  315. item.Reviewer.ReviewerItems = null;
  316. item.Reviewer.Customers = null;
  317. item.Reviewer.ItemStaffs = null;
  318. item.Customer.PerformanceItems = null;
  319. item.CalMonth.PerformanceItems = null;
  320. }
  321. #endregion
  322. ret.Results = retList;
  323. return ret;
  324. }
  325. public double DegreeOfDifficulty(int year,int month, int? userId = null)
  326. {
  327. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  328. var list = Context.CaseCeoffcients;
  329. foreach(var cx in list.ToList<CaseCeoffcient>())
  330. {
  331. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  332. }
  333. var results = Context.PerformanceItems.Where<PerformanceItem>(p => p.CalMonth.Year == year && p.CalMonth.Month == month && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") && p.BasePoint > 0.0);
  334. if(userId != null)
  335. {
  336. results = Context.PerformanceItems.Where<PerformanceItem>(p =>
  337. p.CalMonth.Year == year && p.CalMonth.Month == month && ((p.Type == "新申请" && p.BasePoint >0) || p.Type == "专案") &&
  338. (p.ItemStaffs.Where<ItemStaff>(s=>s.DoPerson.Id == userId).Count ()>0 ) && p.BasePoint >0.0);
  339. }
  340. #region 循环计算
  341. int iCount = 0;
  342. double d = 0.0;
  343. var retList = results.ToList();
  344. foreach(var item in retList)
  345. {
  346. string strCaseCeoffcient = item.CaseCoefficient;
  347. if(item.isDanger() && string.IsNullOrEmpty(item.OverDueMemo))
  348. {
  349. switch (item.CaseCoefficient)
  350. {
  351. case "S":
  352. strCaseCeoffcient = "A";
  353. break;
  354. case "A":
  355. strCaseCeoffcient = "B";
  356. break;
  357. case "B":
  358. strCaseCeoffcient = "C";
  359. break;
  360. case "C":
  361. strCaseCeoffcient = "D";
  362. break;
  363. }
  364. }
  365. if (CaseXiShu.ContainsKey(strCaseCeoffcient))
  366. {
  367. d += CaseXiShu[strCaseCeoffcient];
  368. iCount += 1;
  369. }
  370. }
  371. #endregion
  372. #region 统计计算
  373. //var groupResult = results.GroupBy(x => x.CaseCoefficient).Select(g=> new {
  374. // CaseCeoffcient = g.Key,
  375. // count = g.Count()
  376. //});
  377. //int iCount = 0;
  378. //double d = 0.0;
  379. //foreach(var g in groupResult)
  380. //{
  381. // if (!string.IsNullOrEmpty(g.CaseCeoffcient))
  382. // {
  383. // if (CaseXiShu.ContainsKey(g.CaseCeoffcient))
  384. // {
  385. // d += g.count * CaseXiShu[g.CaseCeoffcient];
  386. // iCount += g.count;
  387. // }
  388. // }
  389. //}
  390. #endregion
  391. return d /(double)iCount;
  392. }
  393. public List<string> GetFeedbackString(int itemId)
  394. {
  395. PerformanceItem item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == itemId);
  396. if(item != null)
  397. {
  398. return Utility.Utility.GetFeedbackMemos(item, Context.BasePointRules.ToList());
  399. }
  400. return new List<string>();
  401. }
  402. private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
  403. {
  404. double gspjXS = DegreeOfDifficulty(calMonth.Year, calMonth.Month);
  405. //未归档,从绩效记录中统计数据
  406. var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
  407. if (userid != null)
  408. {
  409. results = Context.PerformanceItems.Where<PerformanceItem>(s =>
  410. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  411. && s.CalMonth.Id == calMonth.Id);
  412. }
  413. List<PerformanceItem> ItemList = results
  414. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  415. .Include(pi => pi.Reviewer)
  416. .Include(pi => pi.Customer)
  417. .OrderByDescending(o => o.Id)
  418. .ToList<PerformanceItem>();
  419. List<StaffStatistics> retList = new List<StaffStatistics>();
  420. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  421. var Rules = Context.BasePointRules.ToList();
  422. foreach (PerformanceItem item in ItemList)
  423. {
  424. //if (item.BasePoint == null)
  425. //{
  426. Utility.Utility.CalBasePoint(item,Rules);
  427. Context.SaveChanges();
  428. //}
  429. if (item.BasePoint != null && item.BasePoint.Value > 0)
  430. {
  431. double doPersonBasePoint = item.BasePoint.Value;
  432. List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
  433. List<StaffStatistics> temItemStatics;
  434. if (userid != null)
  435. {
  436. temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
  437. }
  438. else
  439. {
  440. temItemStatics = itemStatistics;
  441. }
  442. foreach (StaffStatistics retUserValue in temItemStatics)
  443. {
  444. var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
  445. if (temValue != null)
  446. {
  447. temValue.totalBasePoint += retUserValue.totalBasePoint;
  448. }
  449. else
  450. {
  451. retList.Add(retUserValue);
  452. }
  453. }
  454. }
  455. }
  456. if (userid != null)
  457. {
  458. retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
  459. }
  460. IDictionary<int, double> staffXiShu = new Dictionary<int, double>();
  461. foreach (StaffStatistics ss in retList)
  462. {
  463. if (ss.jxType.Contains("新申请") || ss.jxType.Contains("专案"))
  464. {
  465. if (!staffXiShu.ContainsKey(ss.StaffId))
  466. {
  467. staffXiShu.Add(ss.StaffId, DegreeOfDifficulty(calMonth.Year, calMonth.Month, ss.StaffId));
  468. }
  469. ss.totalActuallyPoint = ss.totalBasePoint * staffXiShu[ss.StaffId] / gspjXS;
  470. }
  471. else
  472. {
  473. ss.totalActuallyPoint = ss.totalBasePoint;
  474. }
  475. ss.CalMonth.PerformanceItems = null;
  476. }
  477. return retList;
  478. }
  479. private void _RefreshBasePoint()
  480. {
  481. spDbContext spDb = new spDbContext();
  482. var lstItem = spDb.PerformanceItems.Include(p => p.Customer).Where(p => p.CalMonth.Status != 4).ToList();
  483. var rules = spDb.BasePointRules.ToList();
  484. foreach (var item in lstItem)
  485. {
  486. Utility.Utility.CalBasePoint(item, rules);
  487. spDb.SaveChanges();
  488. }
  489. }
  490. public ApiSaveResponse RefreshBasePoint()
  491. {
  492. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  493. t.Start();
  494. return new ApiSaveResponse() {
  495. Success = true
  496. };
  497. }
  498. private List<StaffStatistics> _calItemJX(CalMonth calMonth, List<VerifyCoefficient> verifyCoefficients, PerformanceItem item,spDbContext spDb)
  499. {
  500. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  501. bool isPJFP = true;
  502. double total = item.ItemStaffs.Count();
  503. if (item.ItemStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  504. {
  505. total = item.ItemStaffs.Select(i => i.PerformancePoint.Value).Sum();
  506. isPJFP = false;
  507. }
  508. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  509. if (item.ReviewerId != null)
  510. {
  511. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  512. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  513. }
  514. foreach (ItemStaff itemStaff in item.ItemStaffs)
  515. {
  516. if(itemStaff.DoPerson == null)
  517. {
  518. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  519. }
  520. //spDb.Entry(itemStaff).Reference(b => b.DoPerson).Load();
  521. //spDb.Entry(itemStaff.DoPerson).Reference(b => b.StaffGrade).Load();
  522. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  523. if (item.ReviewerId != null && item.Type != "专案")
  524. {
  525. #region 取审核人等级审核等级系数
  526. VerifyCoefficient vcoefficient
  527. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  528. v.CheckerId == item.Reviewer.StaffGrade.Id
  529. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  530. .FirstOrDefault<VerifyCoefficient>();
  531. #endregion
  532. if (vcoefficient != null)
  533. {
  534. double reviewerBasePoint = item.BasePoint.Value * vcoefficient.Coefficient;
  535. string temJxType = $"{item.Type}审核";
  536. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  537. if (temReviewerStatic != null)
  538. {
  539. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  540. }
  541. else
  542. {
  543. if (item.Reviewer.IsOnJob && itemStaff.DoPerson.Status != "试用期") //判断是否在职
  544. {
  545. temReviewerStatic = new StaffStatistics()
  546. {
  547. CalMonth = calMonth,
  548. CalMonthId = calMonth.Id,
  549. StaffId = item.ReviewerId.Value,
  550. totalBasePoint = reviewerBasePoint,
  551. jxType = temJxType
  552. };
  553. itemStatistics.Add(temReviewerStatic);
  554. }
  555. }
  556. }
  557. }
  558. #endregion
  559. #region 计算各处理人的绩效点数
  560. double handlerBasePoint;
  561. if (item.Type != "专案")
  562. {
  563. if (isPJFP)
  564. {
  565. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  566. }
  567. else
  568. {
  569. handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
  570. }
  571. }
  572. else
  573. {
  574. handlerBasePoint = itemStaff.PerformancePoint.Value;
  575. }
  576. string handlerJxType = $"{item.Type}处理";
  577. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  578. if (temStatic != null)
  579. {
  580. if (item.Type != "专案")
  581. {
  582. temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
  583. }
  584. else
  585. {
  586. temStatic.totalBasePoint += handlerBasePoint;
  587. }
  588. }
  589. else
  590. {
  591. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsOnJob)
  592. {
  593. if (item.Type != "专案")
  594. {
  595. if (itemStaff.DoPerson.Status == "试用期" && item.Reviewer != null)
  596. {
  597. temStatic = new StaffStatistics()
  598. {
  599. CalMonth = calMonth,
  600. CalMonthId = calMonth.Id,
  601. StaffId = item.Reviewer.Id,
  602. totalBasePoint = handlerBasePoint * item.Reviewer.StaffGrade.Coefficient,
  603. jxType = handlerJxType
  604. };
  605. itemStatistics.Add(temStatic);
  606. }
  607. else
  608. {
  609. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s=>s.Id == itemStaff.DoPerson.StaffGradeId);
  610. temStatic = new StaffStatistics()
  611. {
  612. CalMonth = calMonth,
  613. CalMonthId = calMonth.Id,
  614. StaffId = itemStaff.DoPersonId,
  615. totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
  616. jxType = handlerJxType
  617. };
  618. itemStatistics.Add(temStatic);
  619. }
  620. }
  621. else
  622. {
  623. temStatic = new StaffStatistics()
  624. {
  625. CalMonth = calMonth,
  626. CalMonthId = calMonth.Id,
  627. StaffId = itemStaff.DoPersonId,
  628. totalBasePoint = handlerBasePoint,
  629. jxType = handlerJxType
  630. };
  631. itemStatistics.Add(temStatic);
  632. }
  633. }
  634. }
  635. #endregion
  636. }
  637. return itemStatistics;
  638. }
  639. public ApiSaveResponse FinishedCalMonth(int year,int month)
  640. {
  641. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  642. if (calMonth != null || calMonth.Status !=4)
  643. {
  644. var retList = CalMyStatistics(year, month);
  645. using (var t = Context.Database.BeginTransaction())
  646. {
  647. try
  648. {
  649. foreach (var obj in retList)
  650. {
  651. obj.CalMonthId = calMonth.Id;
  652. obj.CalMonth = null;
  653. Context.StaffStatistics.Add(obj);
  654. Context.SaveChanges();
  655. }
  656. calMonth.Status = 4;
  657. Context.SaveChanges();
  658. t.Commit();
  659. return new ApiSaveResponse()
  660. {
  661. Success = true
  662. };
  663. }
  664. catch(Exception ex)
  665. {
  666. t.Rollback();
  667. return new ApiSaveResponse()
  668. {
  669. Success = false,
  670. ErrorMessage = ex.Message
  671. };
  672. }
  673. }
  674. }
  675. else
  676. {
  677. return new ApiSaveResponse()
  678. {
  679. Success = false,
  680. ErrorMessage ="指定月份没有数据或者已归档!"
  681. };
  682. }
  683. }
  684. /// <summary>
  685. /// 计算指定用户,指定年月的绩效统计信息
  686. /// </summary>
  687. /// <param name="userid"></param>
  688. /// <param name="year"></param>
  689. /// <param name="month"></param>
  690. /// <returns></returns>
  691. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  692. {
  693. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  694. if(calMonth == null)
  695. {
  696. return null;
  697. }
  698. else
  699. {
  700. if(calMonth.Status == 4)
  701. {
  702. //已归档,归档数据库中直接取出记录
  703. if (userid == null)
  704. {
  705. return Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  706. }
  707. else
  708. {
  709. return Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  710. }
  711. }
  712. else
  713. {
  714. return _CalMyStatistics(calMonth, userid);
  715. }
  716. }
  717. }
  718. private string GetExpress(IList<FieldCondition> conditions)
  719. {
  720. string str = "";
  721. foreach(var c in conditions)
  722. {
  723. if (string.IsNullOrEmpty(str))
  724. {
  725. str = c.ToExpressString("s");
  726. }
  727. else
  728. {
  729. if(c.LogicOperate == LogicEnum.And)
  730. {
  731. str = $"({str}) && {c.ToExpressString("s")}";
  732. }
  733. else
  734. {
  735. str = $"({str}) || {c.ToExpressString("s")}";
  736. }
  737. }
  738. }
  739. return str;
  740. }
  741. [HttpGet,HttpPost]
  742. public FileProcessTask ExportData(QueryFilter queryFilter)
  743. {
  744. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  745. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  746. var filePath = Path.Combine(attachfileSavePath, filename);
  747. var fileTask = new FileProcessTask()
  748. {
  749. Id = Guid.NewGuid().ToString(),
  750. FileName = filename,
  751. FilePath = filePath,
  752. Processed = 0
  753. };
  754. fileTaskService.Add(fileTask);
  755. ThreadObject threadObject = new ThreadObject()
  756. {
  757. queryFilter = queryFilter,
  758. fileTask = fileTask
  759. };
  760. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  761. t.Start(threadObject);
  762. return fileTask;
  763. }
  764. internal class ThreadObject
  765. {
  766. public QueryFilter queryFilter { get; set; }
  767. public FileProcessTask fileTask { get; set; }
  768. }
  769. private void ExportDataThread(object tObj)
  770. {
  771. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  772. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  773. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  774. var retList = response
  775. .Include(p=>p.Customer)
  776. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  777. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  778. .Include(p=>p.PreOastaff)
  779. .Include(p=>p.CalMonth)
  780. .ToList<PerformanceItem>();
  781. DataTable dt = new DataTable();
  782. #region 添加栏位
  783. dt.Columns.Add("我方文号",typeof(string));
  784. dt.Columns.Add("申请类型", typeof(string));
  785. dt.Columns.Add("业务类型", typeof(string));
  786. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  787. dt.Columns.Add("处理事项", typeof(string));
  788. dt.Columns.Add("案件阶段", typeof(string));
  789. dt.Columns.Add("案件系数", typeof(string));
  790. dt.Columns.Add("处理事项系数", typeof(string));
  791. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  792. dt.Columns.Add("前一次OA处理人", typeof(string));
  793. dt.Columns.Add("处理人等级", typeof(string));
  794. dt.Columns.Add("基本点数", typeof(string));
  795. dt.Columns.Add("核稿系数", typeof(string));
  796. dt.Columns.Add("核稿绩效", typeof(string));
  797. dt.Columns.Add("处理人", typeof(string));
  798. dt.Columns.Add("核稿人", typeof(string));
  799. dt.Columns.Add("客户名称", typeof(string));
  800. dt.Columns.Add("申请人", typeof(string));
  801. dt.Columns.Add("处理事项完成日", typeof(string));
  802. dt.Columns.Add("定稿日", typeof(string));
  803. dt.Columns.Add("返稿日", typeof(string));
  804. dt.Columns.Add("案件类型", typeof(string));
  805. dt.Columns.Add("案件状态", typeof(string));
  806. dt.Columns.Add("处理事项备注", typeof(string));
  807. dt.Columns.Add("处理状态", typeof(string));
  808. dt.Columns.Add("案件名称", typeof(string));
  809. dt.Columns.Add("委案日期", typeof(string));
  810. dt.Columns.Add("客户期限", typeof(string));
  811. dt.Columns.Add("内部期限", typeof(string));
  812. dt.Columns.Add("初稿日", typeof(string));
  813. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
  814. dt.Columns.Add("备注", typeof(string));
  815. #endregion
  816. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  817. fileTask.Size = retList.Count;
  818. foreach (var item in retList)
  819. {
  820. fileTask.Processed += 1;
  821. if (item.CaseNo.StartsWith("J"))
  822. {
  823. continue;
  824. }
  825. try
  826. {
  827. var row = dt.NewRow();
  828. row["我方文号"] = item.CaseNo;
  829. row["申请类型"] = item.ApplicationType;
  830. row["业务类型"] = item.BusinessType;
  831. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  832. row["处理事项"] = item.DoItem;
  833. row["案件阶段"] = item.CaseStage;
  834. row["案件系数"] = item.CaseCoefficient;
  835. row["处理事项系数"] = item.DoItemCoefficient;
  836. row["前一次OA处理事项系数"] = "";
  837. if (item.PreOastaffId.HasValue)
  838. {
  839. row["前一次OA处理人"] = item.PreOastaff?.Name;
  840. }
  841. string strISLevels = "";
  842. string strISNames = "";
  843. foreach (var istaff in item.ItemStaffs)
  844. {
  845. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  846. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  847. }
  848. row["处理人等级"] = strISLevels;
  849. row["基本点数"] = item.BasePoint;
  850. row["处理人"] = strISNames;
  851. row["核稿人"] = item.Reviewer?.Name;
  852. if (item.ReviewerId != null && item.BasePoint.HasValue)
  853. {
  854. var jxList = _calItemJX(item.CalMonth, verifyCoefficients, item, new spDbContext());
  855. row["核稿系数"] = "";
  856. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  857. if (temJx != null)
  858. {
  859. row["核稿绩效"] = temJx.totalBasePoint;
  860. }
  861. }
  862. row["客户名称"] = item.Customer?.Name;
  863. row["申请人"] = item.ApplicationName;
  864. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  865. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  866. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  867. row["案件类型"] = item.CaseType;
  868. row["案件状态"] = item.CaseState;
  869. row["处理事项备注"] = item.DoItemState;
  870. row["处理状态"] = item.DoItemState;
  871. row["案件名称"] = item.CaseName;
  872. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  873. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  874. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  875. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  876. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  877. row["备注"] = item.DoItemMemo;
  878. dt.Rows.Add(row);
  879. }
  880. catch(Exception ex)
  881. {
  882. throw ex;
  883. }
  884. }
  885. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  886. fileTask.Finished = true;
  887. }
  888. [HttpPost]
  889. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  890. {
  891. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  892. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  893. int totals = response.ToList<PerformanceItem>().Count;
  894. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  895. {
  896. response = response
  897. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  898. .Include(pi => pi.Reviewer)
  899. .Include(pi => pi.Customer)
  900. .Include(pi => pi.CalMonth)
  901. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  902. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  903. }
  904. else
  905. {
  906. response = response
  907. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  908. .Include(pi => pi.Reviewer)
  909. .Include(pi => pi.Customer)
  910. .Include(pi => pi.CalMonth)
  911. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  912. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  913. }
  914. ret.TotalCount = totals;
  915. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  916. #region 将某些属性设为null,避免循环取值造成返回json过大
  917. foreach (PerformanceItem item in retList)
  918. {
  919. foreach (ItemStaff itemStaff in item.ItemStaffs)
  920. {
  921. itemStaff.DoPerson.ItemStaffs = null;
  922. itemStaff.DoPerson.ReviewerItems = null;
  923. itemStaff.Item = null;
  924. }
  925. if (item.Reviewer != null)
  926. {
  927. item.Reviewer.ReviewerItems = null;
  928. item.Reviewer.Customers = null;
  929. item.Reviewer.ItemStaffs = null;
  930. }
  931. if (item.Customer != null)
  932. {
  933. item.Customer.PerformanceItems = null;
  934. }
  935. if (item.CalMonth != null)
  936. {
  937. item.CalMonth.PerformanceItems = null;
  938. }
  939. }
  940. #endregion
  941. ret.Results = retList.ToList();
  942. return ret;
  943. }
  944. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  945. {
  946. string strExpress = "";
  947. string strCalMonth = "";
  948. if (queryFilter.CalMonthId.HasValue)
  949. {
  950. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  951. }
  952. else
  953. {
  954. strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  955. }
  956. if (!string.IsNullOrEmpty(strExpress))
  957. {
  958. strExpress = $"{strExpress} && {strCalMonth}";
  959. }
  960. else
  961. {
  962. strExpress = strCalMonth;
  963. }
  964. if (queryFilter.ConditionTree != null)
  965. {
  966. string strTem = GetExpress(queryFilter.ConditionTree);
  967. if (!string.IsNullOrEmpty(strTem))
  968. {
  969. strExpress = $"{strExpress} && ({strTem})";
  970. }
  971. }
  972. var interpreter = new Interpreter();
  973. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  974. IQueryable<PerformanceItem> response;
  975. if (queryFilter.userId > 0)
  976. {
  977. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));// || s.ReviewerId == queryFilter.userId));
  978. }
  979. else
  980. {
  981. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  982. }
  983. return response;
  984. }
  985. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  986. {
  987. ApiSaveResponse retResponse = new ApiSaveResponse();
  988. retResponse.Success = true;
  989. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  990. {
  991. using (var t = Context.Database.BeginTransaction())
  992. {
  993. try
  994. {
  995. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  996. if (calMonth == null)
  997. {
  998. retResponse.Success = false;
  999. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  1000. return retResponse;
  1001. }
  1002. else
  1003. {
  1004. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  1005. projectContents.ProjectContentRecord.CalMonth = null;
  1006. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  1007. projectContents.ProjectContentRecord.StaffId = staff.Id;
  1008. projectContents.ProjectContentRecord.State = 0;
  1009. }
  1010. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  1011. if (project != null)
  1012. {
  1013. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  1014. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  1015. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  1016. if(pRecord != null)
  1017. {
  1018. retResponse.Success = false;
  1019. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  1020. return retResponse;
  1021. }
  1022. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  1023. foreach (var doItem in projectContents.ProjectWorkContents)
  1024. {
  1025. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  1026. Context.ProjectWorkContents.Add(doItem);
  1027. }
  1028. t.Commit();
  1029. }
  1030. else
  1031. {
  1032. retResponse.Success = false;
  1033. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  1034. return retResponse;
  1035. }
  1036. }
  1037. catch (Exception ex)
  1038. {
  1039. retResponse.Success = false;
  1040. retResponse.ErrorMessage = ex.Message;
  1041. t.Rollback();
  1042. return retResponse;
  1043. }
  1044. }
  1045. }
  1046. return retResponse;
  1047. }
  1048. public PerformanceItem GetCaseInfo(string CaseNo)
  1049. {
  1050. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  1051. if(retObj == null)
  1052. {
  1053. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  1054. }
  1055. return retObj;
  1056. }
  1057. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  1058. {
  1059. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  1060. if (retObj == null)
  1061. {
  1062. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  1063. }
  1064. return retObj;
  1065. }
  1066. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage)
  1067. {
  1068. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  1069. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  1070. if (retObj == null)
  1071. {
  1072. retObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  1073. }
  1074. return retObj;
  1075. }
  1076. public bool MovePerformance2ProjectInfo()
  1077. {
  1078. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  1079. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  1080. var pList = response.ToList<PerformanceItem>();
  1081. foreach(var p in pList)
  1082. {
  1083. ProjectInfo project = new ProjectInfo();
  1084. project.CaseNo = p.CaseNo;
  1085. project.CaseName = p.CaseName;
  1086. project.CaseState = 0;
  1087. project.CaseType = p.CaseType;
  1088. project.CustomerId = p.CustomerId;
  1089. project.ReviewerId = p.ReviewerId;
  1090. Context.ProjectInfos.Add(project);
  1091. foreach(ItemStaff iStaff in p.ItemStaffs)
  1092. {
  1093. Context.ItemStaffs.Remove(iStaff);
  1094. }
  1095. Context.PerformanceItems.Remove(p);
  1096. Context.SaveChanges();
  1097. }
  1098. return true;
  1099. }
  1100. }
  1101. }