PerformanceItemController.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  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. .OrderByDescending(o => o.Id)
  417. .ToList<PerformanceItem>();
  418. List<StaffStatistics> retList = new List<StaffStatistics>();
  419. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  420. var Rules = Context.BasePointRules.ToList();
  421. foreach (PerformanceItem item in ItemList)
  422. {
  423. //if (item.BasePoint == null)
  424. //{
  425. Utility.Utility.CalBasePoint(item,Rules);
  426. Context.SaveChanges();
  427. //}
  428. if (item.BasePoint != null && item.BasePoint.Value > 0)
  429. {
  430. double doPersonBasePoint = item.BasePoint.Value;
  431. List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
  432. List<StaffStatistics> temItemStatics;
  433. if (userid != null)
  434. {
  435. temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
  436. }
  437. else
  438. {
  439. temItemStatics = itemStatistics;
  440. }
  441. foreach (StaffStatistics retUserValue in temItemStatics)
  442. {
  443. var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
  444. if (temValue != null)
  445. {
  446. temValue.totalBasePoint += retUserValue.totalBasePoint;
  447. }
  448. else
  449. {
  450. retList.Add(retUserValue);
  451. }
  452. }
  453. }
  454. }
  455. if (userid != null)
  456. {
  457. retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
  458. }
  459. IDictionary<int, double> staffXiShu = new Dictionary<int, double>();
  460. foreach (StaffStatistics ss in retList)
  461. {
  462. if (ss.jxType.Contains("新申请") || ss.jxType.Contains("专案"))
  463. {
  464. if (!staffXiShu.ContainsKey(ss.StaffId))
  465. {
  466. staffXiShu.Add(ss.StaffId, DegreeOfDifficulty(calMonth.Year, calMonth.Month, ss.StaffId));
  467. }
  468. ss.totalActuallyPoint = ss.totalBasePoint * staffXiShu[ss.StaffId] / gspjXS;
  469. }
  470. else
  471. {
  472. ss.totalActuallyPoint = ss.totalBasePoint;
  473. }
  474. ss.CalMonth.PerformanceItems = null;
  475. }
  476. return retList;
  477. }
  478. private List<StaffStatistics> _calItemJX(CalMonth calMonth, List<VerifyCoefficient> verifyCoefficients, PerformanceItem item,spDbContext spDb)
  479. {
  480. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  481. bool isPJFP = true;
  482. double total = item.ItemStaffs.Count();
  483. if (item.ItemStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  484. {
  485. total = item.ItemStaffs.Select(i => i.PerformancePoint.Value).Sum();
  486. isPJFP = false;
  487. }
  488. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  489. if (item.ReviewerId != null)
  490. {
  491. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  492. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  493. }
  494. foreach (ItemStaff itemStaff in item.ItemStaffs)
  495. {
  496. if(itemStaff.DoPerson == null)
  497. {
  498. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  499. }
  500. //spDb.Entry(itemStaff).Reference(b => b.DoPerson).Load();
  501. //spDb.Entry(itemStaff.DoPerson).Reference(b => b.StaffGrade).Load();
  502. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  503. if (item.ReviewerId != null && item.Type != "专案")
  504. {
  505. #region 取审核人等级审核等级系数
  506. VerifyCoefficient vcoefficient
  507. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  508. v.CheckerId == item.Reviewer.StaffGrade.Id
  509. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  510. .FirstOrDefault<VerifyCoefficient>();
  511. #endregion
  512. if (vcoefficient != null)
  513. {
  514. double reviewerBasePoint = item.BasePoint.Value * vcoefficient.Coefficient;
  515. string temJxType = $"{item.Type}审核";
  516. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  517. if (temReviewerStatic != null)
  518. {
  519. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  520. }
  521. else
  522. {
  523. if (item.Reviewer.IsOnJob && itemStaff.DoPerson.Status != "试用期") //判断是否在职
  524. {
  525. temReviewerStatic = new StaffStatistics()
  526. {
  527. CalMonth = calMonth,
  528. CalMonthId = calMonth.Id,
  529. StaffId = item.ReviewerId.Value,
  530. totalBasePoint = reviewerBasePoint,
  531. jxType = temJxType
  532. };
  533. itemStatistics.Add(temReviewerStatic);
  534. }
  535. }
  536. }
  537. }
  538. #endregion
  539. #region 计算各处理人的绩效点数
  540. double handlerBasePoint;
  541. if (item.Type != "专案")
  542. {
  543. if (isPJFP)
  544. {
  545. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  546. }
  547. else
  548. {
  549. handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
  550. }
  551. }
  552. else
  553. {
  554. handlerBasePoint = itemStaff.PerformancePoint.Value;
  555. }
  556. string handlerJxType = $"{item.Type}处理";
  557. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  558. if (temStatic != null)
  559. {
  560. if (item.Type != "专案")
  561. {
  562. temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
  563. }
  564. else
  565. {
  566. temStatic.totalBasePoint += handlerBasePoint;
  567. }
  568. }
  569. else
  570. {
  571. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsOnJob)
  572. {
  573. if (item.Type != "专案")
  574. {
  575. if (itemStaff.DoPerson.Status == "试用期" && item.Reviewer != null)
  576. {
  577. temStatic = new StaffStatistics()
  578. {
  579. CalMonth = calMonth,
  580. CalMonthId = calMonth.Id,
  581. StaffId = item.Reviewer.Id,
  582. totalBasePoint = handlerBasePoint * item.Reviewer.StaffGrade.Coefficient,
  583. jxType = handlerJxType
  584. };
  585. itemStatistics.Add(temStatic);
  586. }
  587. else
  588. {
  589. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s=>s.Id == itemStaff.DoPerson.StaffGradeId);
  590. temStatic = new StaffStatistics()
  591. {
  592. CalMonth = calMonth,
  593. CalMonthId = calMonth.Id,
  594. StaffId = itemStaff.DoPersonId,
  595. totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
  596. jxType = handlerJxType
  597. };
  598. itemStatistics.Add(temStatic);
  599. }
  600. }
  601. else
  602. {
  603. temStatic = new StaffStatistics()
  604. {
  605. CalMonth = calMonth,
  606. CalMonthId = calMonth.Id,
  607. StaffId = itemStaff.DoPersonId,
  608. totalBasePoint = handlerBasePoint,
  609. jxType = handlerJxType
  610. };
  611. itemStatistics.Add(temStatic);
  612. }
  613. }
  614. }
  615. #endregion
  616. }
  617. return itemStatistics;
  618. }
  619. public ApiSaveResponse FinishedCalMonth(int year,int month)
  620. {
  621. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  622. if (calMonth != null || calMonth.Status !=4)
  623. {
  624. var retList = CalMyStatistics(year, month);
  625. using (var t = Context.Database.BeginTransaction())
  626. {
  627. try
  628. {
  629. foreach (var obj in retList)
  630. {
  631. obj.CalMonthId = calMonth.Id;
  632. obj.CalMonth = null;
  633. Context.StaffStatistics.Add(obj);
  634. Context.SaveChanges();
  635. }
  636. calMonth.Status = 4;
  637. Context.SaveChanges();
  638. t.Commit();
  639. return new ApiSaveResponse()
  640. {
  641. Success = true
  642. };
  643. }
  644. catch(Exception ex)
  645. {
  646. t.Rollback();
  647. return new ApiSaveResponse()
  648. {
  649. Success = false,
  650. ErrorMessage = ex.Message
  651. };
  652. }
  653. }
  654. }
  655. else
  656. {
  657. return new ApiSaveResponse()
  658. {
  659. Success = false,
  660. ErrorMessage ="指定月份没有数据或者已归档!"
  661. };
  662. }
  663. }
  664. /// <summary>
  665. /// 计算指定用户,指定年月的绩效统计信息
  666. /// </summary>
  667. /// <param name="userid"></param>
  668. /// <param name="year"></param>
  669. /// <param name="month"></param>
  670. /// <returns></returns>
  671. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  672. {
  673. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  674. if(calMonth == null)
  675. {
  676. return null;
  677. }
  678. else
  679. {
  680. if(calMonth.Status == 4)
  681. {
  682. //已归档,归档数据库中直接取出记录
  683. if (userid == null)
  684. {
  685. return Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  686. }
  687. else
  688. {
  689. return Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  690. }
  691. }
  692. else
  693. {
  694. return _CalMyStatistics(calMonth, userid);
  695. }
  696. }
  697. }
  698. private string GetExpress(IList<FieldCondition> conditions)
  699. {
  700. string str = "";
  701. foreach(var c in conditions)
  702. {
  703. if (string.IsNullOrEmpty(str))
  704. {
  705. str = c.ToExpressString("s");
  706. }
  707. else
  708. {
  709. if(c.LogicOperate == LogicEnum.And)
  710. {
  711. str = $"({str}) && {c.ToExpressString("s")}";
  712. }
  713. else
  714. {
  715. str = $"({str}) || {c.ToExpressString("s")}";
  716. }
  717. }
  718. }
  719. return str;
  720. }
  721. [HttpGet,HttpPost]
  722. public FileProcessTask ExportData(QueryFilter queryFilter)
  723. {
  724. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  725. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  726. var filePath = Path.Combine(attachfileSavePath, filename);
  727. var fileTask = new FileProcessTask()
  728. {
  729. Id = Guid.NewGuid().ToString(),
  730. FileName = filename,
  731. FilePath = filePath,
  732. Processed = 0
  733. };
  734. fileTaskService.Add(fileTask);
  735. ThreadObject threadObject = new ThreadObject()
  736. {
  737. queryFilter = queryFilter,
  738. fileTask = fileTask
  739. };
  740. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  741. t.Start(threadObject);
  742. return fileTask;
  743. }
  744. internal class ThreadObject
  745. {
  746. public QueryFilter queryFilter { get; set; }
  747. public FileProcessTask fileTask { get; set; }
  748. }
  749. private void ExportDataThread(object tObj)
  750. {
  751. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  752. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  753. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  754. var retList = response
  755. .Include(p=>p.Customer)
  756. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  757. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  758. .Include(p=>p.PreOastaff)
  759. .Include(p=>p.CalMonth)
  760. .ToList<PerformanceItem>();
  761. DataTable dt = new DataTable();
  762. #region 添加栏位
  763. dt.Columns.Add("我方文号",typeof(string));
  764. dt.Columns.Add("申请类型", typeof(string));
  765. dt.Columns.Add("业务类型", typeof(string));
  766. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  767. dt.Columns.Add("处理事项", typeof(string));
  768. dt.Columns.Add("案件阶段", typeof(string));
  769. dt.Columns.Add("案件系数", typeof(string));
  770. dt.Columns.Add("处理事项系数", typeof(string));
  771. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  772. dt.Columns.Add("前一次OA处理人", typeof(string));
  773. dt.Columns.Add("处理人等级", typeof(string));
  774. dt.Columns.Add("基本点数", typeof(string));
  775. dt.Columns.Add("核稿系数", typeof(string));
  776. dt.Columns.Add("核稿绩效", typeof(string));
  777. dt.Columns.Add("处理人", typeof(string));
  778. dt.Columns.Add("核稿人", typeof(string));
  779. dt.Columns.Add("客户名称", typeof(string));
  780. dt.Columns.Add("申请人", typeof(string));
  781. dt.Columns.Add("处理事项完成日", typeof(string));
  782. dt.Columns.Add("定稿日", typeof(string));
  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("内部期限", typeof(string));
  792. dt.Columns.Add("初稿日", typeof(string));
  793. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
  794. dt.Columns.Add("备注", typeof(string));
  795. #endregion
  796. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  797. fileTask.Size = retList.Count;
  798. foreach (var item in retList)
  799. {
  800. fileTask.Processed += 1;
  801. if (item.CaseNo.StartsWith("J"))
  802. {
  803. continue;
  804. }
  805. try
  806. {
  807. var row = dt.NewRow();
  808. row["我方文号"] = item.CaseNo;
  809. row["申请类型"] = item.ApplicationType;
  810. row["业务类型"] = item.BusinessType;
  811. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  812. row["处理事项"] = item.DoItem;
  813. row["案件阶段"] = item.CaseStage;
  814. row["案件系数"] = item.CaseCoefficient;
  815. row["处理事项系数"] = item.DoItemCoefficient;
  816. row["前一次OA处理事项系数"] = "";
  817. if (item.PreOastaffId.HasValue)
  818. {
  819. row["前一次OA处理人"] = item.PreOastaff?.Name;
  820. }
  821. string strISLevels = "";
  822. string strISNames = "";
  823. foreach (var istaff in item.ItemStaffs)
  824. {
  825. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  826. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  827. }
  828. row["处理人等级"] = strISLevels;
  829. row["基本点数"] = item.BasePoint;
  830. row["处理人"] = strISNames;
  831. row["核稿人"] = item.Reviewer?.Name;
  832. if (item.ReviewerId != null && item.BasePoint.HasValue)
  833. {
  834. var jxList = _calItemJX(item.CalMonth, verifyCoefficients, item, new spDbContext());
  835. row["核稿系数"] = "";
  836. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  837. if (temJx != null)
  838. {
  839. row["核稿绩效"] = temJx.totalBasePoint;
  840. }
  841. }
  842. row["客户名称"] = item.Customer?.Name;
  843. row["申请人"] = item.ApplicationName;
  844. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  845. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  846. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  847. row["案件类型"] = item.CaseType;
  848. row["案件状态"] = item.CaseState;
  849. row["处理事项备注"] = item.DoItemState;
  850. row["处理状态"] = item.DoItemState;
  851. row["案件名称"] = item.CaseName;
  852. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  853. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  854. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  855. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  856. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  857. row["备注"] = item.DoItemMemo;
  858. dt.Rows.Add(row);
  859. }
  860. catch(Exception ex)
  861. {
  862. throw ex;
  863. }
  864. }
  865. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  866. fileTask.Finished = true;
  867. }
  868. [HttpPost]
  869. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  870. {
  871. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  872. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  873. int totals = response.ToList<PerformanceItem>().Count;
  874. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  875. {
  876. response = response
  877. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  878. .Include(pi => pi.Reviewer)
  879. .Include(pi => pi.Customer)
  880. .Include(pi => pi.CalMonth)
  881. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  882. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  883. }
  884. else
  885. {
  886. response = response
  887. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  888. .Include(pi => pi.Reviewer)
  889. .Include(pi => pi.Customer)
  890. .Include(pi => pi.CalMonth)
  891. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  892. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  893. }
  894. ret.TotalCount = totals;
  895. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  896. #region 将某些属性设为null,避免循环取值造成返回json过大
  897. foreach (PerformanceItem item in retList)
  898. {
  899. foreach (ItemStaff itemStaff in item.ItemStaffs)
  900. {
  901. itemStaff.DoPerson.ItemStaffs = null;
  902. itemStaff.DoPerson.ReviewerItems = null;
  903. itemStaff.Item = null;
  904. }
  905. if (item.Reviewer != null)
  906. {
  907. item.Reviewer.ReviewerItems = null;
  908. item.Reviewer.Customers = null;
  909. item.Reviewer.ItemStaffs = null;
  910. }
  911. if (item.Customer != null)
  912. {
  913. item.Customer.PerformanceItems = null;
  914. }
  915. if (item.CalMonth != null)
  916. {
  917. item.CalMonth.PerformanceItems = null;
  918. }
  919. }
  920. #endregion
  921. ret.Results = retList.ToList();
  922. return ret;
  923. }
  924. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  925. {
  926. string strExpress = "";
  927. string strCalMonth = "";
  928. if (queryFilter.CalMonthId.HasValue)
  929. {
  930. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  931. }
  932. else
  933. {
  934. strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  935. }
  936. if (!string.IsNullOrEmpty(strExpress))
  937. {
  938. strExpress = $"{strExpress} && {strCalMonth}";
  939. }
  940. else
  941. {
  942. strExpress = strCalMonth;
  943. }
  944. if (queryFilter.ConditionTree != null)
  945. {
  946. string strTem = GetExpress(queryFilter.ConditionTree);
  947. if (!string.IsNullOrEmpty(strTem))
  948. {
  949. strExpress = $"{strExpress} && ({strTem})";
  950. }
  951. }
  952. var interpreter = new Interpreter();
  953. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  954. IQueryable<PerformanceItem> response;
  955. if (queryFilter.userId > 0)
  956. {
  957. 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));
  958. }
  959. else
  960. {
  961. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  962. }
  963. return response;
  964. }
  965. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  966. {
  967. ApiSaveResponse retResponse = new ApiSaveResponse();
  968. retResponse.Success = true;
  969. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  970. {
  971. using (var t = Context.Database.BeginTransaction())
  972. {
  973. try
  974. {
  975. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  976. if (calMonth == null)
  977. {
  978. retResponse.Success = false;
  979. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  980. return retResponse;
  981. }
  982. else
  983. {
  984. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  985. projectContents.ProjectContentRecord.CalMonth = null;
  986. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  987. projectContents.ProjectContentRecord.StaffId = staff.Id;
  988. projectContents.ProjectContentRecord.State = 0;
  989. }
  990. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  991. if (project != null)
  992. {
  993. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  994. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  995. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  996. if(pRecord != null)
  997. {
  998. retResponse.Success = false;
  999. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  1000. return retResponse;
  1001. }
  1002. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  1003. foreach (var doItem in projectContents.ProjectWorkContents)
  1004. {
  1005. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  1006. Context.ProjectWorkContents.Add(doItem);
  1007. }
  1008. t.Commit();
  1009. }
  1010. else
  1011. {
  1012. retResponse.Success = false;
  1013. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  1014. return retResponse;
  1015. }
  1016. }
  1017. catch (Exception ex)
  1018. {
  1019. retResponse.Success = false;
  1020. retResponse.ErrorMessage = ex.Message;
  1021. t.Rollback();
  1022. return retResponse;
  1023. }
  1024. }
  1025. }
  1026. return retResponse;
  1027. }
  1028. public PerformanceItem GetCaseInfo(string CaseNo)
  1029. {
  1030. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  1031. if(retObj == null)
  1032. {
  1033. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  1034. }
  1035. return retObj;
  1036. }
  1037. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  1038. {
  1039. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  1040. if (retObj == null)
  1041. {
  1042. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  1043. }
  1044. return retObj;
  1045. }
  1046. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage)
  1047. {
  1048. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  1049. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  1050. if (retObj == null)
  1051. {
  1052. retObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  1053. }
  1054. return retObj;
  1055. }
  1056. public bool MovePerformance2ProjectInfo()
  1057. {
  1058. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  1059. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  1060. var pList = response.ToList<PerformanceItem>();
  1061. foreach(var p in pList)
  1062. {
  1063. ProjectInfo project = new ProjectInfo();
  1064. project.CaseNo = p.CaseNo;
  1065. project.CaseName = p.CaseName;
  1066. project.CaseState = 0;
  1067. project.CaseType = p.CaseType;
  1068. project.CustomerId = p.CustomerId;
  1069. project.ReviewerId = p.ReviewerId;
  1070. Context.ProjectInfos.Add(project);
  1071. foreach(ItemStaff iStaff in p.ItemStaffs)
  1072. {
  1073. Context.ItemStaffs.Remove(iStaff);
  1074. }
  1075. Context.PerformanceItems.Remove(p);
  1076. Context.SaveChanges();
  1077. }
  1078. return true;
  1079. }
  1080. }
  1081. }