PerformanceItemController.cs 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  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.Caching.Memory;
  8. using Microsoft.Extensions.Hosting;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Linq.Expressions;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using wispro.sp.api.Services;
  18. using wispro.sp.api.Utility;
  19. using wispro.sp.entity;
  20. using wispro.sp.share;
  21. using wispro.sp.utility;
  22. namespace wispro.sp.api.Controllers
  23. {
  24. [Route("api/[controller]/[action]")]
  25. [ApiController]
  26. [Authorize]
  27. public class PerformanceItemController : ControllerBase
  28. {
  29. spDbContext Context;
  30. IFileTaskService fileTaskService;
  31. public PerformanceItemController(spDbContext context, IFileTaskService _fileTaskService)
  32. {
  33. Context = context;
  34. fileTaskService = _fileTaskService;
  35. }
  36. public bool IsExist(PerformanceItem item)
  37. {
  38. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  39. x.CaseNo == item.CaseNo &&
  40. x.DoItem == item.DoItem &&
  41. x.CaseStage == item.CaseStage &&
  42. x.CalMonth.Year == item.CalMonth.Year &&
  43. x.CalMonth.Month == item.CalMonth.Month);
  44. if(results.Count() > 0)
  45. {
  46. return true;
  47. }
  48. else
  49. {
  50. return false;
  51. }
  52. }
  53. public ApiSaveResponse New(PerformanceItem item)
  54. {
  55. ApiSaveResponse ret = new ApiSaveResponse();
  56. ret.Success = true;
  57. using (Context.Database.BeginTransaction())
  58. {
  59. try
  60. {
  61. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  62. x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  63. if (item.DoItem.ToUpper() == "提交IDS")
  64. {
  65. //提交IDS 添加完成日期做完判断是否已算绩效的条件
  66. results = Context.PerformanceItems.Where<PerformanceItem>(x=>x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.FinishedDate == item.FinishedDate);
  67. }
  68. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  69. if (items != null)
  70. {
  71. item.AgentFeedbackMemo = "已算绩效";
  72. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  73. item.BasePoint = 0;
  74. }
  75. if (item.CalMonth != null)
  76. {
  77. var calMonth = Context.CalMonths.Where<CalMonth>(c => c.Year == item.CalMonth.Year && c.Month == item.CalMonth.Month).FirstOrDefault();
  78. if(calMonth == null)
  79. {
  80. Context.CalMonths.Add(item.CalMonth);
  81. Context.SaveChanges();
  82. }
  83. else
  84. {
  85. item.CalMonth = calMonth;
  86. }
  87. item.CalMonthId = item.CalMonth.Id;
  88. item.CalMonth = null;
  89. }
  90. if (!string.IsNullOrEmpty(item.Customer.Name))
  91. {
  92. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  93. if (temCustomer == null)
  94. {
  95. temCustomer = new Customer() { Name = item.Customer.Name };
  96. //item.Customer.Id = 0;
  97. Context.Customers.Add(temCustomer);
  98. Context.SaveChanges();
  99. item.Customer = temCustomer;
  100. //item.CustomerId = item.Customer.Id;
  101. }
  102. else
  103. {
  104. item.Customer = temCustomer;
  105. }
  106. item.CustomerId = item.Customer.Id;
  107. item.Customer = null;
  108. }
  109. else
  110. {
  111. item.Customer = null;
  112. }
  113. var ItemStaffs = item.ItemStaffs;
  114. item.ItemStaffs = null;
  115. Context.PerformanceItems.Add(item);
  116. Context.SaveChanges();
  117. foreach (ItemStaff itemStaff in ItemStaffs)
  118. {
  119. itemStaff.ItemId = item.Id;
  120. itemStaff.Item = null;
  121. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  122. {
  123. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  124. if (temStaff != null)
  125. {
  126. itemStaff.DoPersonId = temStaff.Id;
  127. itemStaff.DoPerson = null;
  128. }
  129. else
  130. {
  131. Context.Staffs.Add(itemStaff.DoPerson);
  132. Context.SaveChanges();
  133. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  134. itemStaff.DoPerson = null;
  135. }
  136. }
  137. }
  138. Context.ItemStaffs.AddRange(ItemStaffs);
  139. Context.SaveChanges();
  140. Context.Database.CommitTransaction();
  141. }
  142. catch (Exception ex)
  143. {
  144. ret.Success = false;
  145. ret.ErrorMessage = ex.Message;
  146. Context.Database.RollbackTransaction();
  147. }
  148. }
  149. return ret;
  150. }
  151. /// <summary>
  152. /// 更新绩效记录信息
  153. /// </summary>
  154. /// <param name="id">绩效记录编号</param>
  155. /// <param name="field">栏位,多个位以|杠隔开</param>
  156. /// <param name="value">栏位值,多个以|杠隔开</param>
  157. /// <returns></returns>
  158. public ApiSaveResponse UpdateFieldValue(int id,string field,string value)
  159. {
  160. ApiSaveResponse ret = new ApiSaveResponse();
  161. ret.Success = true;
  162. var item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.Id == id);
  163. if (item == null)
  164. {
  165. ret.Success = false;
  166. ret.ErrorMessage = $"不存在的{id}";
  167. return ret;
  168. }
  169. if(string.IsNullOrEmpty(field) )
  170. {
  171. ret.Success = false;
  172. ret.ErrorMessage = $"参数不对!";
  173. return ret;
  174. }
  175. string[] fields = field.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  176. string[] values = new string[] { null };
  177. if (!string.IsNullOrEmpty(value))
  178. {
  179. values = value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  180. }
  181. if (fields.Length != values.Length) {
  182. ret.Success = false;
  183. ret.ErrorMessage = "栏位和值对不匹配";
  184. }
  185. else
  186. {
  187. for(int i = 0; i < fields.Length; i++)
  188. {
  189. string temField = fields[i];
  190. string temValue = values[i];
  191. switch (temField)
  192. {
  193. case "AgentFeedbackMemo":
  194. item.AgentFeedbackMemo = temValue;
  195. break;
  196. case "CaseCoefficient":
  197. item.CaseCoefficient = temValue;
  198. //此处添加保存到流程系统的代码
  199. break;
  200. case "DoItemCoefficient":
  201. item.DoItemCoefficient = temValue;
  202. //此处添加保存到流程系统的代码
  203. break;
  204. case "WordCount":
  205. int wordCount;
  206. if (int.TryParse(temValue, out wordCount))
  207. {
  208. item.WordCount = wordCount;
  209. }
  210. else
  211. {
  212. ret.Success = false;
  213. ret.ErrorMessage = "所给的栏位值不能转换成数字!";
  214. return ret;
  215. }
  216. break;
  217. case "ReturnCasseNo":
  218. item.ReturnCasseNo = temValue;
  219. break;
  220. }
  221. }
  222. if (item.AgentFeedbackMemo != "特殊点数申诉")
  223. {
  224. Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
  225. Context.SaveChanges();
  226. }
  227. }
  228. return ret;
  229. }
  230. public ListApiResponse<PerformanceItem> Query(int pageIndex,int pageSize)
  231. {
  232. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  233. var results = Context.PerformanceItems
  234. .Where<PerformanceItem>(s =>
  235. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == User.Identity.Name).Count() > 0 || s.Reviewer.Name == User.Identity.Name)
  236. && s.CalMonth.Status != 4);
  237. ret.TotalCount = results.Count();
  238. List<PerformanceItem> retList = results
  239. .Include(pi=>pi.ItemStaffs).ThenInclude(iStaff=>iStaff.DoPerson)
  240. .Include(pi=>pi.Reviewer)
  241. .Include(pi=>pi.Customer)
  242. .Include(pi=>pi.CalMonth)
  243. .OrderByDescending(o=>o.Id)
  244. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize).ToList<PerformanceItem>();
  245. #region 将某些属性设为null,避免循环取值造成返回json过大
  246. foreach (PerformanceItem item in retList)
  247. {
  248. foreach (ItemStaff itemStaff in item.ItemStaffs)
  249. {
  250. itemStaff.DoPerson.ItemStaffs = null;
  251. itemStaff.DoPerson.ReviewerItems = null;
  252. itemStaff.Item = null;
  253. }
  254. item.Reviewer.ReviewerItems = null;
  255. item.Reviewer.Customers = null;
  256. item.Reviewer.ItemStaffs = null;
  257. item.Customer.PerformanceItems = null;
  258. item.CalMonth.PerformanceItems = null;
  259. }
  260. #endregion
  261. ret.Results = retList;
  262. return ret;
  263. }
  264. public PerformanceItem Get(int Id)
  265. {
  266. var results = Context.PerformanceItems
  267. .Where<PerformanceItem>(s =>s.Id == Id);
  268. PerformanceItem item = results
  269. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  270. .Include(pi => pi.Reviewer)
  271. .Include(pi => pi.Customer)
  272. .Include(pi => pi.CalMonth)
  273. .OrderByDescending(o => o.Id)
  274. .FirstOrDefault();
  275. #region 将某些属性设为null,避免循环取值造成返回json过大
  276. foreach (ItemStaff itemStaff in item.ItemStaffs)
  277. {
  278. itemStaff.DoPerson.ItemStaffs = null;
  279. itemStaff.DoPerson.ReviewerItems = null;
  280. itemStaff.Item = null;
  281. }
  282. if (item.Reviewer != null)
  283. {
  284. item.Reviewer.ReviewerItems = null;
  285. item.Reviewer.Customers = null;
  286. item.Reviewer.ItemStaffs = null;
  287. }
  288. item.Customer.PerformanceItems = null;
  289. item.CalMonth.PerformanceItems = null;
  290. #endregion
  291. return item;
  292. }
  293. /// <summary>
  294. /// 获取给定用户的绩效清单
  295. /// </summary>
  296. /// <param name="userid">用户id</param>
  297. /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
  298. /// <returns></returns>
  299. public ListApiResponse<PerformanceItem> GetMyList(int userid, int type,int pageIndex=1,int pageSize = 10)
  300. {
  301. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  302. var results = Context.PerformanceItems
  303. .Where<PerformanceItem>(s =>
  304. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid ).Count() > 0 || s.Reviewer.Id == userid )
  305. && s.CalMonth.Status == type);
  306. ret.TotalCount = results.Count();
  307. List<PerformanceItem> retList = results
  308. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  309. .Include(pi => pi.Reviewer)
  310. .Include(pi => pi.Customer)
  311. .Include(pi => pi.CalMonth)
  312. .OrderByDescending(o => o.Id)
  313. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize)
  314. .ToList<PerformanceItem>();
  315. #region 将某些属性设为null,避免循环取值造成返回json过大
  316. foreach (PerformanceItem item in retList)
  317. {
  318. foreach(ItemStaff itemStaff in item.ItemStaffs)
  319. {
  320. itemStaff.DoPerson.ItemStaffs = null;
  321. itemStaff.DoPerson.ReviewerItems = null;
  322. itemStaff.Item = null;
  323. }
  324. item.Reviewer.ReviewerItems = null;
  325. item.Reviewer.Customers = null;
  326. item.Reviewer.ItemStaffs = null;
  327. item.Customer.PerformanceItems = null;
  328. item.CalMonth.PerformanceItems = null;
  329. }
  330. #endregion
  331. ret.Results = retList;
  332. return ret;
  333. }
  334. public double DegreeOfDifficulty(int year,int month, int? userId = null)
  335. {
  336. string strKey = $"DegreeOfDifficulty:{year}-{month}-{userId}";
  337. object cacheEntry;
  338. if (!MyMemoryCache.TryGetValue(strKey, out cacheEntry))
  339. {
  340. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  341. var list = Context.CaseCeoffcients;
  342. foreach (var cx in list.ToList<CaseCeoffcient>())
  343. {
  344. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  345. }
  346. 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);
  347. if (userId != null)
  348. {
  349. results = Context.PerformanceItems.Where<PerformanceItem>(p =>
  350. p.CalMonth.Year == year && p.CalMonth.Month == month && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") &&
  351. (p.ItemStaffs.Where<ItemStaff>(s => s.DoPerson.Id == userId).Count() > 0 || p.ReviewerId == userId ) && p.BasePoint > 0.0);
  352. }
  353. #region 循环计算
  354. int iCount = 0;
  355. double d = 0.0;
  356. var retList = results.ToList();
  357. foreach (var item in retList)
  358. {
  359. string strCaseCeoffcient = item.CaseCoefficient;
  360. #region 严重延期降系数
  361. if (item.isDanger() && string.IsNullOrEmpty(item.OverDueMemo))
  362. {
  363. switch (item.CaseCoefficient)
  364. {
  365. case "S":
  366. strCaseCeoffcient = "A";
  367. break;
  368. case "A":
  369. strCaseCeoffcient = "B";
  370. break;
  371. case "B":
  372. strCaseCeoffcient = "C";
  373. break;
  374. case "C":
  375. strCaseCeoffcient = "D";
  376. break;
  377. }
  378. }
  379. #endregion
  380. if (CaseXiShu.ContainsKey(strCaseCeoffcient))
  381. {
  382. d += CaseXiShu[strCaseCeoffcient];
  383. iCount += 1;
  384. }
  385. }
  386. #endregion
  387. #region 统计计算
  388. //var groupResult = results.GroupBy(x => x.CaseCoefficient).Select(g=> new {
  389. // CaseCeoffcient = g.Key,
  390. // count = g.Count()
  391. //});
  392. //int iCount = 0;
  393. //double d = 0.0;
  394. //foreach(var g in groupResult)
  395. //{
  396. // if (!string.IsNullOrEmpty(g.CaseCeoffcient))
  397. // {
  398. // if (CaseXiShu.ContainsKey(g.CaseCeoffcient))
  399. // {
  400. // d += g.count * CaseXiShu[g.CaseCeoffcient];
  401. // iCount += g.count;
  402. // }
  403. // }
  404. //}
  405. #endregion
  406. cacheEntry = d / (double)iCount;
  407. // Set cache options.
  408. // Save data in cache.
  409. MyMemoryCache.SetValue(strKey, cacheEntry);
  410. return (double)cacheEntry;
  411. }
  412. else
  413. {
  414. return (double)cacheEntry;
  415. }
  416. }
  417. public List<string> GetFeedbackString(int itemId)
  418. {
  419. PerformanceItem item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == itemId);
  420. if(item != null)
  421. {
  422. return Utility.Utility.GetFeedbackMemos(item, Context.BasePointRules.ToList());
  423. }
  424. return new List<string>();
  425. }
  426. private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
  427. {
  428. double gspjXS = DegreeOfDifficulty(calMonth.Year, calMonth.Month);
  429. //未归档,从绩效记录中统计数据
  430. var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
  431. if (userid != null)
  432. {
  433. results = Context.PerformanceItems.Where<PerformanceItem>(s =>
  434. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  435. && s.CalMonth.Id == calMonth.Id);
  436. }
  437. List<PerformanceItem> ItemList = results
  438. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  439. .Include(pi => pi.Reviewer).ThenInclude(p=>p.StaffGrade)
  440. .Include(pi => pi.Customer)
  441. .OrderByDescending(o => o.Id)
  442. .ToList<PerformanceItem>();
  443. List<StaffStatistics> retList = new List<StaffStatistics>();
  444. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  445. var Rules = Context.BasePointRules.ToList();
  446. foreach (PerformanceItem item in ItemList)
  447. {
  448. //if (item.BasePoint == null)
  449. //{
  450. if (item.AgentFeedbackMemo != "特殊点数申诉")
  451. {
  452. Utility.Utility.CalBasePoint(item, Rules);
  453. Context.SaveChanges();
  454. }
  455. //}
  456. if (item.BasePoint != null && item.BasePoint.Value > 0)
  457. {
  458. double doPersonBasePoint = item.BasePoint.Value;
  459. List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
  460. List<StaffStatistics> temItemStatics;
  461. if (userid != null)
  462. {
  463. temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
  464. }
  465. else
  466. {
  467. temItemStatics = itemStatistics;
  468. }
  469. foreach (StaffStatistics retUserValue in temItemStatics)
  470. {
  471. var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
  472. if (temValue != null)
  473. {
  474. temValue.totalBasePoint += retUserValue.totalBasePoint;
  475. }
  476. else
  477. {
  478. retList.Add(retUserValue);
  479. }
  480. }
  481. }
  482. }
  483. if (userid != null)
  484. {
  485. retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
  486. }
  487. IDictionary<int, double> staffXiShu = new Dictionary<int, double>();
  488. foreach (StaffStatistics ss in retList)
  489. {
  490. if (ss.jxType.Contains("新申请") || ss.jxType.Contains("专案"))
  491. {
  492. if (!staffXiShu.ContainsKey(ss.StaffId))
  493. {
  494. staffXiShu.Add(ss.StaffId, DegreeOfDifficulty(calMonth.Year, calMonth.Month, ss.StaffId));
  495. }
  496. ss.totalActuallyPoint = ss.totalBasePoint * staffXiShu[ss.StaffId] / gspjXS;
  497. }
  498. else
  499. {
  500. ss.totalActuallyPoint = ss.totalBasePoint;
  501. }
  502. ss.CalMonth.PerformanceItems = null;
  503. }
  504. return retList;
  505. }
  506. private void _RefreshBasePoint()
  507. {
  508. spDbContext spDb = new spDbContext();
  509. var lstItem = spDb.PerformanceItems.Include(p => p.Customer).Where(p => p.CalMonth.Status != 4).ToList();
  510. var rules = spDb.BasePointRules.ToList();
  511. foreach (var item in lstItem)
  512. {
  513. if (item.AgentFeedbackMemo != "特殊点数申诉")
  514. {
  515. Utility.Utility.CalBasePoint(item, rules);
  516. spDb.SaveChanges();
  517. }
  518. }
  519. }
  520. public ApiSaveResponse RefreshBasePoint()
  521. {
  522. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  523. t.Start();
  524. return new ApiSaveResponse() {
  525. Success = true
  526. };
  527. }
  528. public ApiSaveResponse RefreshFromIPEasyById(int itemId)
  529. {
  530. var Item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault(p => p.Id == itemId);
  531. if (Item != null)
  532. {
  533. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  534. }
  535. return new ApiSaveResponse()
  536. {
  537. Success = true
  538. };
  539. }
  540. public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
  541. {
  542. new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
  543. return new ApiSaveResponse()
  544. {
  545. Success = true
  546. };
  547. }
  548. public ApiSaveResponse RefreshFromIPEasy(string CaseNo,string DoItem,string caseStage)
  549. {
  550. var Item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault(p=>p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
  551. if(Item != null)
  552. {
  553. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item,Context);
  554. }
  555. return new ApiSaveResponse()
  556. {
  557. Success = true
  558. };
  559. }
  560. public ApiSaveResponse CompareExcel2DB()
  561. {
  562. System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
  563. t.Start();
  564. return new ApiSaveResponse()
  565. {
  566. Success = true
  567. };
  568. }
  569. private void _CompareExcel2DB()
  570. {
  571. DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0,2);
  572. DataTable retTable = new DataTable();
  573. retTable.Columns.Add("我方文号");
  574. retTable.Columns.Add("申请类型");
  575. retTable.Columns.Add("业务类型");
  576. retTable.Columns.Add("备注(填表注意事项)");
  577. retTable.Columns.Add("备注(填表注意事项)【系统】");
  578. retTable.Columns.Add("处理事项");
  579. retTable.Columns.Add("处理事项【系统】");
  580. retTable.Columns.Add("案件阶段");
  581. retTable.Columns.Add("案件阶段【系统】");
  582. retTable.Columns.Add("案件系数");
  583. retTable.Columns.Add("案件系数【系统】");
  584. retTable.Columns.Add("处理事项系数");
  585. retTable.Columns.Add("处理事项系数【系统】");
  586. retTable.Columns.Add("处理人等级");
  587. retTable.Columns.Add("处理人等级【系统】");
  588. retTable.Columns.Add("处理人系数");
  589. retTable.Columns.Add("处理人系数【系统】");
  590. retTable.Columns.Add("基本点数");
  591. retTable.Columns.Add("基本点数【系统】");
  592. retTable.Columns.Add("核稿系数");
  593. retTable.Columns.Add("核稿系数【系统】");
  594. retTable.Columns.Add("核稿绩效");
  595. retTable.Columns.Add("核稿绩效【系统】");
  596. retTable.Columns.Add("处理人");
  597. retTable.Columns.Add("处理人【系统】");
  598. retTable.Columns.Add("核稿人");
  599. retTable.Columns.Add("核稿人【系统】");
  600. retTable.Columns.Add("严重超期备注原因");
  601. retTable.Columns.Add("严重超期备注原因【系统】");
  602. retTable.Columns.Add("是否一致");
  603. retTable.Columns.Add("不一致原因");
  604. spDbContext spDb = new spDbContext();
  605. List<PerformanceItem> items = spDb.PerformanceItems
  606. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  607. .Include(p=>p.Customer)
  608. .Include(p=>p.ItemStaffs).ThenInclude(s=>s.DoPerson).ThenInclude(s=>s.StaffGrade)
  609. .Where(p=>p.CalMonth.Status ==0 && !p.CaseNo.StartsWith("J")).OrderBy(p=>p.CaseNo).ThenBy(p=>p.DoItem).ToList();
  610. excelDT.DefaultView.Sort = "我方文号,处理事项";
  611. DataTable temDt = excelDT.DefaultView.ToTable();
  612. int iTable = 0;
  613. int iList = 0;
  614. CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p=>p.Status ==0);
  615. var verifyCoefficients = spDb.VerifyCoefficients.ToList();
  616. var Rules = spDb.BasePointRules.ToList();
  617. while (iTable < temDt.Rows.Count && iList < items.Count)
  618. {
  619. System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
  620. DataRow row = temDt.Rows[iTable];
  621. PerformanceItem item = items[iList];
  622. if(row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString()== "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
  623. {
  624. var temRow = retTable.NewRow();
  625. int iBegin = iTable;
  626. int iEnd = iTable;
  627. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  628. if (iEnd < temDt.Rows.Count - 1)
  629. {
  630. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  631. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  632. {
  633. iEnd++;
  634. }
  635. }
  636. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  637. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  638. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  639. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  640. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  641. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  642. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  643. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  644. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  645. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  646. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  647. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  648. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  649. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  650. for (int i = iBegin; i <= iEnd; i++)
  651. {
  652. temRow["备注(填表注意事项)"] =string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ?temDt.Rows[i]["备注(填表注意事项)"] :$"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  653. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  654. temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
  655. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  656. {
  657. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  658. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  659. }
  660. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  661. }
  662. iTable = iEnd;
  663. #endregion
  664. Utility.Utility.CalBasePoint(item, Rules);
  665. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  666. try
  667. {
  668. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  669. }
  670. catch { }
  671. temRow["案件阶段【系统】"] = item.CaseStage;
  672. temRow["案件系数【系统】"] = item.CaseCoefficient;
  673. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  674. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  675. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  676. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  677. temRow["严重超期备注原因"] = item.OverDueMemo;
  678. if (retPoints != null && retPoints.Count > 0)
  679. {
  680. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
  681. foreach (var itemStaff in item.ItemStaffs)
  682. {
  683. //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  684. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  685. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  686. if (item.ReviewerId != null)
  687. {
  688. #region 取审核人等级审核等级系数
  689. VerifyCoefficient vcoefficient
  690. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  691. v.CheckerId == item.Reviewer.StaffGradeId
  692. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  693. .FirstOrDefault<VerifyCoefficient>();
  694. #endregion
  695. if (vcoefficient != null)
  696. {
  697. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  698. }
  699. }
  700. }
  701. }
  702. temRow["是否一致"] = "";
  703. temRow["不一致原因"] = "";
  704. if(temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
  705. {
  706. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
  707. }
  708. if (temRow["案件系数【系统】"].ToString().Trim() != temRow["案件系数"].ToString().Trim())
  709. {
  710. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件系数" : $"{temRow["不一致原因"]},案件系数";
  711. }
  712. if (temRow["处理事项系数【系统】"].ToString().Trim() != temRow["处理事项系数"].ToString().Trim())
  713. {
  714. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "处理事项系数" : $"{temRow["不一致原因"]},处理事项系数";
  715. }
  716. if (temRow["核稿人【系统】"].ToString().Trim() != temRow["核稿人"].ToString().Trim())
  717. {
  718. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "核稿人" : $"{temRow["不一致原因"]},核稿人";
  719. }
  720. if (temRow["基本点数【系统】"].ToString().Trim() != temRow["基本点数"].ToString().Trim())
  721. {
  722. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "基本点数" : $"{temRow["不一致原因"]},基本点数";
  723. }
  724. if (temRow["严重超期备注原因【系统】"].ToString().Trim() != temRow["严重超期备注原因"].ToString().Trim())
  725. {
  726. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "严重超期备注原因" : $"{temRow["不一致原因"]},严重超期备注原因";
  727. }
  728. if (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
  729. {
  730. temRow["是否一致"] = "不一致";
  731. }
  732. retTable.Rows.Add(temRow);
  733. iTable++;
  734. iList++;
  735. }
  736. else
  737. {
  738. string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
  739. string strList = $"{item.CaseNo}-{item.DoItem}";
  740. if (strDT.CompareTo(strList) > 0)
  741. {
  742. var temRow = retTable.NewRow();
  743. Utility.Utility.CalBasePoint(item, Rules);
  744. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  745. try
  746. {
  747. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  748. }
  749. catch { }
  750. temRow["我方文号"] = item.CaseNo;
  751. temRow["处理事项"] = item.DoItem;
  752. temRow["申请类型"] = item.ApplicationType;
  753. temRow["业务类型"] = item.BusinessType;
  754. temRow["案件阶段【系统】"] = item.CaseStage;
  755. temRow["案件系数【系统】"] = item.CaseCoefficient;
  756. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  757. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  758. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  759. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  760. temRow["严重超期备注原因"] = item.OverDueMemo;
  761. if (item.ReviewerId != null)
  762. {
  763. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  764. }
  765. foreach (var itemStaff in item.ItemStaffs)
  766. {
  767. //if (itemStaff.DoPerson.Status != "试用期")
  768. //{
  769. // if (retPoints != null && retPoints.Count > 0)
  770. // {
  771. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  772. // }
  773. //}
  774. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  775. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  776. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  777. if (item.ReviewerId != null)
  778. {
  779. #region 取审核人等级审核等级系数
  780. VerifyCoefficient vcoefficient
  781. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  782. v.CheckerId == item.Reviewer.StaffGradeId
  783. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  784. .FirstOrDefault<VerifyCoefficient>();
  785. #endregion
  786. if (vcoefficient != null)
  787. {
  788. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  789. }
  790. }
  791. }
  792. temRow["是否一致"] = "不一致";
  793. temRow["不一致原因"] = "Excel中没有,系统中有";
  794. retTable.Rows.Add(temRow);
  795. iList++;
  796. }
  797. else
  798. {
  799. var temRow = retTable.NewRow();
  800. int iBegin = iTable;
  801. int iEnd = iTable;
  802. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  803. if (iEnd < temDt.Rows.Count - 1)
  804. {
  805. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  806. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  807. {
  808. iEnd++;
  809. }
  810. }
  811. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  812. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  813. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  814. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  815. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  816. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  817. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  818. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  819. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  820. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  821. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  822. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  823. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  824. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  825. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  826. for (int i = iBegin+1; i <= iEnd; i++)
  827. {
  828. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  829. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  830. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  831. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  832. {
  833. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  834. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  835. }
  836. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  837. }
  838. iTable = iEnd;
  839. #endregion
  840. temRow["是否一致"] = "不一致";
  841. temRow["不一致原因"] = "系统中没有,Excel中有";
  842. retTable.Rows.Add(temRow);
  843. iTable++;
  844. }
  845. }
  846. }
  847. if (iList <=items.Count)
  848. {
  849. while(iList <items.Count){
  850. var item = items[iList];
  851. var temRow = retTable.NewRow();
  852. Utility.Utility.CalBasePoint(item, Rules);
  853. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  854. try
  855. {
  856. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  857. }
  858. catch { }
  859. temRow["我方文号"] = item.CaseNo;
  860. temRow["处理事项"] = item.DoItem;
  861. temRow["申请类型"] = item.ApplicationType;
  862. temRow["业务类型"] = item.BusinessType;
  863. temRow["案件阶段【系统】"] = item.CaseStage;
  864. temRow["案件系数【系统】"] = item.CaseCoefficient;
  865. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  866. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  867. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  868. temRow["基本点数【系统】"] = "";// item.BasePoint?.ToString();
  869. temRow["严重超期备注原因"] = item.OverDueMemo;
  870. if (item.ReviewerId != null)
  871. {
  872. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  873. }
  874. foreach (var itemStaff in item.ItemStaffs)
  875. {
  876. //if (itemStaff.DoPerson.Status != "试用期")
  877. //{
  878. // if (retPoints != null && retPoints.Count > 0)
  879. // {
  880. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  881. // }
  882. //}
  883. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  884. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  885. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  886. if (item.ReviewerId != null)
  887. {
  888. #region 取审核人等级审核等级系数
  889. VerifyCoefficient vcoefficient
  890. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  891. v.CheckerId == item.Reviewer.StaffGradeId
  892. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  893. .FirstOrDefault<VerifyCoefficient>();
  894. #endregion
  895. if (vcoefficient != null)
  896. {
  897. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  898. }
  899. }
  900. }
  901. temRow["是否一致"] = "不一致";
  902. temRow["不一致原因"] = "Excel中没有,系统中有";
  903. iList++;
  904. retTable.Rows.Add(temRow);
  905. }
  906. }
  907. else
  908. {
  909. while (iTable < temDt.Rows.Count)
  910. {
  911. var temRow = retTable.NewRow();
  912. int iBegin = iTable;
  913. int iEnd = iTable;
  914. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  915. while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
  916. temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
  917. {
  918. iEnd++;
  919. }
  920. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  921. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  922. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  923. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  924. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  925. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  926. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  927. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  928. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  929. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  930. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  931. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  932. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  933. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  934. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  935. for (int i = iBegin + 1; i <= iEnd; i++)
  936. {
  937. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  938. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  939. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  940. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  941. {
  942. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  943. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  944. }
  945. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["严重超期备注原因"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["严重超期备注原因"]}";
  946. }
  947. iTable = iEnd;
  948. #endregion
  949. temRow["是否一致"] = "不一致";
  950. temRow["不一致原因"] = "系统中没有,Excel中有";
  951. retTable.Rows.Add(temRow);
  952. iTable++;
  953. }
  954. }
  955. NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
  956. }
  957. private List<StaffStatistics> _calItemJX(CalMonth calMonth, List<VerifyCoefficient> verifyCoefficients, PerformanceItem item,spDbContext spDb)
  958. {
  959. //if(item.CaseNo == "PACN2116373")
  960. //{
  961. // System.Diagnostics.Debug.WriteLine("");
  962. //}
  963. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  964. bool isPJFP = true;
  965. double total = item.ItemStaffs.Count();
  966. if (item.ItemStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  967. {
  968. total = item.ItemStaffs.Select(i => i.PerformancePoint.Value).Sum();
  969. isPJFP = false;
  970. }
  971. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  972. if (item.ReviewerId != null)
  973. {
  974. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  975. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  976. }
  977. foreach (ItemStaff itemStaff in item.ItemStaffs)
  978. {
  979. if(itemStaff.DoPerson == null)
  980. {
  981. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  982. }
  983. //spDb.Entry(itemStaff).Reference(b => b.DoPerson).Load();
  984. //spDb.Entry(itemStaff.DoPerson).Reference(b => b.StaffGrade).Load();
  985. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  986. if (item.ReviewerId != null && item.Type != "专案" && item.ItemStaffs.FirstOrDefault(s=>s.DoPersonId == item.ReviewerId) == null)
  987. {
  988. #region 取审核人等级审核等级系数
  989. VerifyCoefficient vcoefficient
  990. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  991. v.CheckerId == item.Reviewer.StaffGradeId
  992. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  993. .FirstOrDefault<VerifyCoefficient>();
  994. #endregion
  995. if (vcoefficient != null)
  996. {
  997. double reviewerBasePoint = item.BasePoint.Value * vcoefficient.Coefficient;
  998. string temJxType = $"{item.Type}审核";
  999. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  1000. if (temReviewerStatic != null)
  1001. {
  1002. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  1003. }
  1004. else
  1005. {
  1006. if (item.Reviewer.IsOnJob && itemStaff.DoPerson.Status != "试用期") //判断是否在职
  1007. {
  1008. temReviewerStatic = new StaffStatistics()
  1009. {
  1010. CalMonth = calMonth,
  1011. CalMonthId = calMonth.Id,
  1012. StaffId = item.ReviewerId.Value,
  1013. totalBasePoint = reviewerBasePoint,
  1014. jxType = temJxType
  1015. };
  1016. itemStatistics.Add(temReviewerStatic);
  1017. }
  1018. }
  1019. }
  1020. }
  1021. #endregion
  1022. #region 计算各处理人的绩效点数
  1023. double handlerBasePoint;
  1024. if (item.Type != "专案")
  1025. {
  1026. if (isPJFP)
  1027. {
  1028. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1029. }
  1030. else
  1031. {
  1032. handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
  1033. }
  1034. }
  1035. else
  1036. {
  1037. handlerBasePoint = itemStaff.PerformancePoint.Value;
  1038. }
  1039. string handlerJxType = $"{item.Type}处理";
  1040. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  1041. if (temStatic != null)
  1042. {
  1043. if (item.Type != "专案")
  1044. {
  1045. temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
  1046. }
  1047. else
  1048. {
  1049. temStatic.totalBasePoint += handlerBasePoint;
  1050. }
  1051. }
  1052. else
  1053. {
  1054. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsOnJob)
  1055. {
  1056. if (item.Type != "专案")
  1057. {
  1058. if (itemStaff.DoPerson.Status == "试用期" && item.Reviewer != null)
  1059. {
  1060. temStatic = new StaffStatistics()
  1061. {
  1062. CalMonth = calMonth,
  1063. CalMonthId = calMonth.Id,
  1064. StaffId = item.Reviewer.Id,
  1065. totalBasePoint = handlerBasePoint * item.Reviewer.StaffGrade.Coefficient,
  1066. jxType = handlerJxType
  1067. };
  1068. itemStatistics.Add(temStatic);
  1069. }
  1070. else
  1071. {
  1072. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s=>s.Id == itemStaff.DoPerson.StaffGradeId);
  1073. temStatic = new StaffStatistics()
  1074. {
  1075. CalMonth = calMonth,
  1076. CalMonthId = calMonth.Id,
  1077. StaffId = itemStaff.DoPersonId,
  1078. totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
  1079. jxType = handlerJxType
  1080. };
  1081. itemStatistics.Add(temStatic);
  1082. }
  1083. }
  1084. else
  1085. {
  1086. temStatic = new StaffStatistics()
  1087. {
  1088. CalMonth = calMonth,
  1089. CalMonthId = calMonth.Id,
  1090. StaffId = itemStaff.DoPersonId,
  1091. totalBasePoint = handlerBasePoint,
  1092. jxType = handlerJxType
  1093. };
  1094. itemStatistics.Add(temStatic);
  1095. }
  1096. }
  1097. }
  1098. #endregion
  1099. }
  1100. return itemStatistics;
  1101. }
  1102. public ApiSaveResponse FinishedCalMonth(int year,int month)
  1103. {
  1104. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1105. if (calMonth != null || calMonth.Status !=4)
  1106. {
  1107. var retList = CalMyStatistics(year, month);
  1108. using (var t = Context.Database.BeginTransaction())
  1109. {
  1110. try
  1111. {
  1112. foreach (var obj in retList)
  1113. {
  1114. obj.CalMonthId = calMonth.Id;
  1115. obj.CalMonth = null;
  1116. Context.StaffStatistics.Add(obj);
  1117. Context.SaveChanges();
  1118. }
  1119. calMonth.Status = 4;
  1120. Context.SaveChanges();
  1121. t.Commit();
  1122. return new ApiSaveResponse()
  1123. {
  1124. Success = true
  1125. };
  1126. }
  1127. catch(Exception ex)
  1128. {
  1129. t.Rollback();
  1130. return new ApiSaveResponse()
  1131. {
  1132. Success = false,
  1133. ErrorMessage = ex.Message
  1134. };
  1135. }
  1136. }
  1137. }
  1138. else
  1139. {
  1140. return new ApiSaveResponse()
  1141. {
  1142. Success = false,
  1143. ErrorMessage ="指定月份没有数据或者已归档!"
  1144. };
  1145. }
  1146. }
  1147. /// <summary>
  1148. /// 计算指定用户,指定年月的绩效统计信息
  1149. /// </summary>
  1150. /// <param name="userid"></param>
  1151. /// <param name="year"></param>
  1152. /// <param name="month"></param>
  1153. /// <returns></returns>
  1154. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  1155. {
  1156. object retList;
  1157. string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
  1158. if(!MyMemoryCache.TryGetValue(strKey,out retList))
  1159. {
  1160. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1161. if (calMonth == null)
  1162. {
  1163. return null;
  1164. }
  1165. else
  1166. {
  1167. if (calMonth.Status == 4)
  1168. {
  1169. //已归档,归档数据库中直接取出记录
  1170. if (userid == null)
  1171. {
  1172. retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  1173. }
  1174. else
  1175. {
  1176. retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  1177. }
  1178. }
  1179. else
  1180. {
  1181. retList = _CalMyStatistics(calMonth, userid);
  1182. }
  1183. // Set cache options.
  1184. var cacheEntryOptions = new MemoryCacheEntryOptions()
  1185. // Keep in cache for this time, reset time if accessed.
  1186. .SetSlidingExpiration(TimeSpan.FromHours(1));
  1187. // Save data in cache.
  1188. MyMemoryCache.SetValue(strKey, retList);
  1189. return (List<StaffStatistics>)retList;
  1190. }
  1191. }
  1192. else
  1193. {
  1194. return (List<StaffStatistics>)retList;
  1195. }
  1196. }
  1197. private string GetExpress(IList<FieldCondition> conditions)
  1198. {
  1199. string str = "";
  1200. foreach(var c in conditions)
  1201. {
  1202. if (string.IsNullOrEmpty(str))
  1203. {
  1204. str = c.ToExpressString("s");
  1205. }
  1206. else
  1207. {
  1208. if(c.LogicOperate == LogicEnum.And)
  1209. {
  1210. str = $"({str}) && {c.ToExpressString("s")}";
  1211. }
  1212. else
  1213. {
  1214. str = $"({str}) || {c.ToExpressString("s")}";
  1215. }
  1216. }
  1217. }
  1218. return str;
  1219. }
  1220. [HttpGet,HttpPost]
  1221. public FileProcessTask ExportData(QueryFilter queryFilter)
  1222. {
  1223. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  1224. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  1225. var filePath = Path.Combine(attachfileSavePath, filename);
  1226. var fileTask = new FileProcessTask()
  1227. {
  1228. Id = Guid.NewGuid().ToString(),
  1229. FileName = filename,
  1230. FilePath = filePath,
  1231. Processed = 0
  1232. };
  1233. fileTaskService.Add(fileTask);
  1234. ThreadObject threadObject = new ThreadObject()
  1235. {
  1236. queryFilter = queryFilter,
  1237. fileTask = fileTask
  1238. };
  1239. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  1240. t.Start(threadObject);
  1241. return fileTask;
  1242. }
  1243. internal class ThreadObject
  1244. {
  1245. public QueryFilter queryFilter { get; set; }
  1246. public FileProcessTask fileTask { get; set; }
  1247. }
  1248. private void ExportDataThread(object tObj)
  1249. {
  1250. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  1251. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  1252. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  1253. var retList = response
  1254. .Include(p=>p.Customer)
  1255. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  1256. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  1257. .Include(p=>p.PreOastaff)
  1258. .Include(p=>p.CalMonth)
  1259. .ToList<PerformanceItem>();
  1260. DataTable dt = new DataTable();
  1261. #region 添加栏位
  1262. dt.Columns.Add("我方文号",typeof(string));
  1263. dt.Columns.Add("申请类型", typeof(string));
  1264. dt.Columns.Add("业务类型", typeof(string));
  1265. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  1266. dt.Columns.Add("处理事项", typeof(string));
  1267. dt.Columns.Add("案件阶段", typeof(string));
  1268. dt.Columns.Add("案件系数", typeof(string));
  1269. dt.Columns.Add("处理事项系数", typeof(string));
  1270. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  1271. dt.Columns.Add("前一次OA处理人", typeof(string));
  1272. dt.Columns.Add("处理人等级", typeof(string));
  1273. dt.Columns.Add("基本点数", typeof(string));
  1274. dt.Columns.Add("核稿系数", typeof(string));
  1275. dt.Columns.Add("核稿绩效", typeof(string));
  1276. dt.Columns.Add("处理人", typeof(string));
  1277. dt.Columns.Add("核稿人", typeof(string));
  1278. dt.Columns.Add("客户名称", typeof(string));
  1279. dt.Columns.Add("申请人", typeof(string));
  1280. dt.Columns.Add("处理事项完成日", typeof(string));
  1281. dt.Columns.Add("定稿日", typeof(string));
  1282. dt.Columns.Add("返稿日", typeof(string));
  1283. dt.Columns.Add("案件类型", typeof(string));
  1284. dt.Columns.Add("案件状态", typeof(string));
  1285. dt.Columns.Add("处理事项备注", typeof(string));
  1286. dt.Columns.Add("处理状态", typeof(string));
  1287. dt.Columns.Add("案件名称", typeof(string));
  1288. dt.Columns.Add("委案日期", typeof(string));
  1289. dt.Columns.Add("客户期限", typeof(string));
  1290. dt.Columns.Add("内部期限", typeof(string));
  1291. dt.Columns.Add("初稿日", typeof(string));
  1292. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
  1293. dt.Columns.Add("备注", typeof(string));
  1294. #endregion
  1295. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  1296. fileTask.Size = retList.Count;
  1297. foreach (var item in retList)
  1298. {
  1299. fileTask.Processed += 1;
  1300. if (item.CaseNo.StartsWith("J"))
  1301. {
  1302. continue;
  1303. }
  1304. try
  1305. {
  1306. var row = dt.NewRow();
  1307. row["我方文号"] = item.CaseNo;
  1308. row["申请类型"] = item.ApplicationType;
  1309. row["业务类型"] = item.BusinessType;
  1310. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  1311. row["处理事项"] = item.DoItem;
  1312. row["案件阶段"] = item.CaseStage;
  1313. row["案件系数"] = item.CaseCoefficient;
  1314. row["处理事项系数"] = item.DoItemCoefficient;
  1315. row["前一次OA处理事项系数"] = "";
  1316. if (item.PreOastaffId.HasValue)
  1317. {
  1318. row["前一次OA处理人"] = item.PreOastaff?.Name;
  1319. }
  1320. string strISLevels = "";
  1321. string strISNames = "";
  1322. foreach (var istaff in item.ItemStaffs)
  1323. {
  1324. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  1325. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  1326. }
  1327. row["处理人等级"] = strISLevels;
  1328. row["基本点数"] = item.BasePoint;
  1329. row["处理人"] = strISNames;
  1330. row["核稿人"] = item.Reviewer?.Name;
  1331. if (item.ReviewerId != null && item.BasePoint.HasValue)
  1332. {
  1333. var jxList = _calItemJX(item.CalMonth, verifyCoefficients, item, new spDbContext());
  1334. row["核稿系数"] = "";
  1335. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  1336. if (temJx != null)
  1337. {
  1338. row["核稿绩效"] = temJx.totalBasePoint;
  1339. }
  1340. }
  1341. row["客户名称"] = item.Customer?.Name;
  1342. row["申请人"] = item.ApplicationName;
  1343. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  1344. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  1345. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  1346. row["案件类型"] = item.CaseType;
  1347. row["案件状态"] = item.CaseState;
  1348. row["处理事项备注"] = item.DoItemState;
  1349. row["处理状态"] = item.DoItemState;
  1350. row["案件名称"] = item.CaseName;
  1351. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  1352. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  1353. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  1354. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  1355. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  1356. row["备注"] = item.DoItemMemo;
  1357. dt.Rows.Add(row);
  1358. }
  1359. catch(Exception ex)
  1360. {
  1361. throw ex;
  1362. }
  1363. }
  1364. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  1365. fileTask.Finished = true;
  1366. }
  1367. [HttpPost]
  1368. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  1369. {
  1370. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  1371. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  1372. int totals = response.ToList<PerformanceItem>().Count;
  1373. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  1374. {
  1375. response = response
  1376. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  1377. .Include(pi => pi.Reviewer)
  1378. .Include(pi => pi.Customer)
  1379. .Include(pi => pi.CalMonth)
  1380. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  1381. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  1382. }
  1383. else
  1384. {
  1385. response = response
  1386. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  1387. .Include(pi => pi.Reviewer)
  1388. .Include(pi => pi.Customer)
  1389. .Include(pi => pi.CalMonth)
  1390. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  1391. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  1392. }
  1393. ret.TotalCount = totals;
  1394. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  1395. #region 将某些属性设为null,避免循环取值造成返回json过大
  1396. foreach (PerformanceItem item in retList)
  1397. {
  1398. foreach (ItemStaff itemStaff in item.ItemStaffs)
  1399. {
  1400. itemStaff.DoPerson.ItemStaffs = null;
  1401. itemStaff.DoPerson.ReviewerItems = null;
  1402. itemStaff.Item = null;
  1403. }
  1404. if (item.Reviewer != null)
  1405. {
  1406. item.Reviewer.ReviewerItems = null;
  1407. item.Reviewer.Customers = null;
  1408. item.Reviewer.ItemStaffs = null;
  1409. }
  1410. if (item.Customer != null)
  1411. {
  1412. item.Customer.PerformanceItems = null;
  1413. }
  1414. if (item.CalMonth != null)
  1415. {
  1416. item.CalMonth.PerformanceItems = null;
  1417. }
  1418. }
  1419. #endregion
  1420. ret.Results = retList.ToList();
  1421. return ret;
  1422. }
  1423. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  1424. {
  1425. string strExpress = "";
  1426. string strCalMonth = "";
  1427. if (queryFilter.CalMonthId.HasValue)
  1428. {
  1429. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  1430. }
  1431. else
  1432. {
  1433. if(queryFilter.jxType == jxType.finished)
  1434. {
  1435. strCalMonth = $"s.CalMonth.Status == 4";
  1436. }
  1437. else
  1438. {
  1439. strCalMonth = $"s.CalMonth.Status != 4";
  1440. }
  1441. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  1442. }
  1443. if (!string.IsNullOrEmpty(strExpress))
  1444. {
  1445. strExpress = $"{strExpress} && {strCalMonth}";
  1446. }
  1447. else
  1448. {
  1449. strExpress = strCalMonth;
  1450. }
  1451. if (queryFilter.ConditionTree != null)
  1452. {
  1453. string strTem = GetExpress(queryFilter.ConditionTree);
  1454. if (!string.IsNullOrEmpty(strTem))
  1455. {
  1456. strExpress = $"{strExpress} && ({strTem})";
  1457. }
  1458. }
  1459. var interpreter = new Interpreter();
  1460. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  1461. IQueryable<PerformanceItem> response;
  1462. if (queryFilter.userId > 0)
  1463. {
  1464. if (queryFilter.DoingOrReview == 0)
  1465. {
  1466. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  1467. }
  1468. else
  1469. {
  1470. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  1471. }
  1472. }
  1473. else
  1474. {
  1475. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  1476. }
  1477. return response;
  1478. }
  1479. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  1480. {
  1481. ApiSaveResponse retResponse = new ApiSaveResponse();
  1482. retResponse.Success = true;
  1483. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  1484. {
  1485. using (var t = Context.Database.BeginTransaction())
  1486. {
  1487. try
  1488. {
  1489. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  1490. if (calMonth == null)
  1491. {
  1492. retResponse.Success = false;
  1493. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  1494. return retResponse;
  1495. }
  1496. else
  1497. {
  1498. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  1499. projectContents.ProjectContentRecord.CalMonth = null;
  1500. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  1501. projectContents.ProjectContentRecord.StaffId = staff.Id;
  1502. projectContents.ProjectContentRecord.State = 0;
  1503. }
  1504. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  1505. if (project != null)
  1506. {
  1507. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  1508. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  1509. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  1510. if(pRecord != null)
  1511. {
  1512. retResponse.Success = false;
  1513. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  1514. return retResponse;
  1515. }
  1516. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  1517. foreach (var doItem in projectContents.ProjectWorkContents)
  1518. {
  1519. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  1520. Context.ProjectWorkContents.Add(doItem);
  1521. }
  1522. t.Commit();
  1523. }
  1524. else
  1525. {
  1526. retResponse.Success = false;
  1527. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  1528. return retResponse;
  1529. }
  1530. }
  1531. catch (Exception ex)
  1532. {
  1533. retResponse.Success = false;
  1534. retResponse.ErrorMessage = ex.Message;
  1535. t.Rollback();
  1536. return retResponse;
  1537. }
  1538. }
  1539. }
  1540. return retResponse;
  1541. }
  1542. public PerformanceItem GetCaseInfo(string CaseNo)
  1543. {
  1544. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  1545. if(retObj == null)
  1546. {
  1547. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  1548. }
  1549. return retObj;
  1550. }
  1551. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  1552. {
  1553. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  1554. if (retObj == null)
  1555. {
  1556. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  1557. }
  1558. return retObj;
  1559. }
  1560. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage)
  1561. {
  1562. var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  1563. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  1564. if (retObj == null)
  1565. {
  1566. retObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  1567. }
  1568. return retObj;
  1569. }
  1570. public bool MovePerformance2ProjectInfo()
  1571. {
  1572. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  1573. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  1574. var pList = response.ToList<PerformanceItem>();
  1575. foreach(var p in pList)
  1576. {
  1577. ProjectInfo project = new ProjectInfo();
  1578. project.CaseNo = p.CaseNo;
  1579. project.CaseName = p.CaseName;
  1580. project.CaseState = 0;
  1581. project.CaseType = p.CaseType;
  1582. project.CustomerId = p.CustomerId;
  1583. project.ReviewerId = p.ReviewerId;
  1584. Context.ProjectInfos.Add(project);
  1585. foreach(ItemStaff iStaff in p.ItemStaffs)
  1586. {
  1587. Context.ItemStaffs.Remove(iStaff);
  1588. }
  1589. Context.PerformanceItems.Remove(p);
  1590. Context.SaveChanges();
  1591. }
  1592. return true;
  1593. }
  1594. }
  1595. }