PerformanceItemController.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  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).ThenInclude(p=>p.StaffGrade)
  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.StaffGradeId
  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. if(queryFilter.jxType == jxType.finished)
  955. {
  956. strCalMonth = $"s.CalMonth.Status == 4";
  957. }
  958. else
  959. {
  960. strCalMonth = $"s.CalMonth.Status != 4";
  961. }
  962. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  963. }
  964. if (!string.IsNullOrEmpty(strExpress))
  965. {
  966. strExpress = $"{strExpress} && {strCalMonth}";
  967. }
  968. else
  969. {
  970. strExpress = strCalMonth;
  971. }
  972. if (queryFilter.ConditionTree != null)
  973. {
  974. string strTem = GetExpress(queryFilter.ConditionTree);
  975. if (!string.IsNullOrEmpty(strTem))
  976. {
  977. strExpress = $"{strExpress} && ({strTem})";
  978. }
  979. }
  980. var interpreter = new Interpreter();
  981. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  982. IQueryable<PerformanceItem> response;
  983. if (queryFilter.userId > 0)
  984. {
  985. if (queryFilter.DoingOrReview == 0)
  986. {
  987. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  988. }
  989. else
  990. {
  991. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  992. }
  993. }
  994. else
  995. {
  996. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  997. }
  998. return response;
  999. }
  1000. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  1001. {
  1002. ApiSaveResponse retResponse = new ApiSaveResponse();
  1003. retResponse.Success = true;
  1004. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  1005. {
  1006. using (var t = Context.Database.BeginTransaction())
  1007. {
  1008. try
  1009. {
  1010. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  1011. if (calMonth == null)
  1012. {
  1013. retResponse.Success = false;
  1014. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  1015. return retResponse;
  1016. }
  1017. else
  1018. {
  1019. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  1020. projectContents.ProjectContentRecord.CalMonth = null;
  1021. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  1022. projectContents.ProjectContentRecord.StaffId = staff.Id;
  1023. projectContents.ProjectContentRecord.State = 0;
  1024. }
  1025. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  1026. if (project != null)
  1027. {
  1028. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  1029. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  1030. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  1031. if(pRecord != null)
  1032. {
  1033. retResponse.Success = false;
  1034. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  1035. return retResponse;
  1036. }
  1037. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  1038. foreach (var doItem in projectContents.ProjectWorkContents)
  1039. {
  1040. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  1041. Context.ProjectWorkContents.Add(doItem);
  1042. }
  1043. t.Commit();
  1044. }
  1045. else
  1046. {
  1047. retResponse.Success = false;
  1048. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  1049. return retResponse;
  1050. }
  1051. }
  1052. catch (Exception ex)
  1053. {
  1054. retResponse.Success = false;
  1055. retResponse.ErrorMessage = ex.Message;
  1056. t.Rollback();
  1057. return retResponse;
  1058. }
  1059. }
  1060. }
  1061. return retResponse;
  1062. }
  1063. public PerformanceItem GetCaseInfo(string CaseNo)
  1064. {
  1065. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  1066. if(retObj == null)
  1067. {
  1068. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  1069. }
  1070. return retObj;
  1071. }
  1072. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  1073. {
  1074. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  1075. if (retObj == null)
  1076. {
  1077. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  1078. }
  1079. return retObj;
  1080. }
  1081. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage)
  1082. {
  1083. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  1084. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  1085. if (retObj == null)
  1086. {
  1087. retObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  1088. }
  1089. return retObj;
  1090. }
  1091. public bool MovePerformance2ProjectInfo()
  1092. {
  1093. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  1094. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  1095. var pList = response.ToList<PerformanceItem>();
  1096. foreach(var p in pList)
  1097. {
  1098. ProjectInfo project = new ProjectInfo();
  1099. project.CaseNo = p.CaseNo;
  1100. project.CaseName = p.CaseName;
  1101. project.CaseState = 0;
  1102. project.CaseType = p.CaseType;
  1103. project.CustomerId = p.CustomerId;
  1104. project.ReviewerId = p.ReviewerId;
  1105. Context.ProjectInfos.Add(project);
  1106. foreach(ItemStaff iStaff in p.ItemStaffs)
  1107. {
  1108. Context.ItemStaffs.Remove(iStaff);
  1109. }
  1110. Context.PerformanceItems.Remove(p);
  1111. Context.SaveChanges();
  1112. }
  1113. return true;
  1114. }
  1115. }
  1116. }