PerformanceItemController.cs 52 KB

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