PerformanceItemController.cs 53 KB

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