PerformanceItemController.cs 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492
  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[] { '|' });
  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. item.WordCount = null;
  213. //ret.Success = false;
  214. //ret.ErrorMessage = "所给的栏位值不能转换成数字!";
  215. //return ret;
  216. }
  217. break;
  218. case "ReturnCasseNo":
  219. item.ReturnCasseNo = temValue;
  220. break;
  221. }
  222. }
  223. if (item.AgentFeedbackMemo != "特殊点数申诉")
  224. {
  225. Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
  226. Context.SaveChanges();
  227. }
  228. }
  229. return ret;
  230. }
  231. public ListApiResponse<PerformanceItem> Query(int pageIndex,int pageSize)
  232. {
  233. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  234. var results = Context.PerformanceItems
  235. .Where<PerformanceItem>(s =>
  236. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == User.Identity.Name).Count() > 0 || s.Reviewer.Name == User.Identity.Name)
  237. && s.CalMonth.Status != 4);
  238. ret.TotalCount = results.Count();
  239. List<PerformanceItem> retList = results
  240. .Include(pi=>pi.ItemStaffs).ThenInclude(iStaff=>iStaff.DoPerson)
  241. .Include(pi=>pi.Reviewer)
  242. .Include(pi=>pi.Customer)
  243. .Include(pi=>pi.CalMonth)
  244. .OrderByDescending(o=>o.Id)
  245. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize).ToList<PerformanceItem>();
  246. #region 将某些属性设为null,避免循环取值造成返回json过大
  247. foreach (PerformanceItem item in retList)
  248. {
  249. foreach (ItemStaff itemStaff in item.ItemStaffs)
  250. {
  251. itemStaff.DoPerson.ItemStaffs = null;
  252. itemStaff.DoPerson.ReviewerItems = null;
  253. itemStaff.Item = null;
  254. }
  255. item.Reviewer.ReviewerItems = null;
  256. item.Reviewer.Customers = null;
  257. item.Reviewer.ItemStaffs = null;
  258. item.Customer.PerformanceItems = null;
  259. item.CalMonth.PerformanceItems = null;
  260. }
  261. #endregion
  262. ret.Results = retList;
  263. return ret;
  264. }
  265. public PerformanceItem Get(int Id)
  266. {
  267. var results = Context.PerformanceItems
  268. .Where<PerformanceItem>(s =>s.Id == Id);
  269. PerformanceItem item = results
  270. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  271. .Include(pi => pi.Reviewer)
  272. .Include(pi => pi.Customer)
  273. .Include(pi => pi.CalMonth)
  274. .OrderByDescending(o => o.Id)
  275. .FirstOrDefault();
  276. #region 将某些属性设为null,避免循环取值造成返回json过大
  277. foreach (ItemStaff itemStaff in item.ItemStaffs)
  278. {
  279. itemStaff.DoPerson.ItemStaffs = null;
  280. itemStaff.DoPerson.ReviewerItems = null;
  281. itemStaff.Item = null;
  282. }
  283. if (item.Reviewer != null)
  284. {
  285. item.Reviewer.ReviewerItems = null;
  286. item.Reviewer.Customers = null;
  287. item.Reviewer.ItemStaffs = null;
  288. }
  289. item.Customer.PerformanceItems = null;
  290. item.CalMonth.PerformanceItems = null;
  291. #endregion
  292. return item;
  293. }
  294. /// <summary>
  295. /// 获取给定用户的绩效清单
  296. /// </summary>
  297. /// <param name="userid">用户id</param>
  298. /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
  299. /// <returns></returns>
  300. public ListApiResponse<PerformanceItem> GetMyList(int userid, int type,int pageIndex=1,int pageSize = 10)
  301. {
  302. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  303. var results = Context.PerformanceItems
  304. .Where<PerformanceItem>(s =>
  305. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid ).Count() > 0 || s.Reviewer.Id == userid )
  306. && s.CalMonth.Status == type);
  307. ret.TotalCount = results.Count();
  308. List<PerformanceItem> retList = results
  309. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  310. .Include(pi => pi.Reviewer)
  311. .Include(pi => pi.Customer)
  312. .Include(pi => pi.CalMonth)
  313. .OrderByDescending(o => o.Id)
  314. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize)
  315. .ToList<PerformanceItem>();
  316. #region 将某些属性设为null,避免循环取值造成返回json过大
  317. foreach (PerformanceItem item in retList)
  318. {
  319. foreach(ItemStaff itemStaff in item.ItemStaffs)
  320. {
  321. itemStaff.DoPerson.ItemStaffs = null;
  322. itemStaff.DoPerson.ReviewerItems = null;
  323. itemStaff.Item = null;
  324. }
  325. item.Reviewer.ReviewerItems = null;
  326. item.Reviewer.Customers = null;
  327. item.Reviewer.ItemStaffs = null;
  328. item.Customer.PerformanceItems = null;
  329. item.CalMonth.PerformanceItems = null;
  330. }
  331. #endregion
  332. ret.Results = retList;
  333. return ret;
  334. }
  335. public NanduStatics DegreeOfDifficulty(CalMonth calMonth,int? userId = null)
  336. {
  337. NanduStatics retObj = new NanduStatics();
  338. string strKey = $"DegreeOfDifficulty:{calMonth.Year}-{calMonth.Month}-{userId}";
  339. object cacheEntry;
  340. if (!MyMemoryCache.TryGetValue(strKey, out cacheEntry))
  341. {
  342. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  343. var list = Context.CaseCeoffcients;
  344. foreach (var cx in list.ToList<CaseCeoffcient>())
  345. {
  346. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  347. }
  348. var results = Context.PerformanceItems.Where<PerformanceItem>(p => p.CalMonthId == calMonth.Id && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") && p.BasePoint > 0.0);
  349. if (userId != null)
  350. {
  351. results = Context.PerformanceItems.Where<PerformanceItem>(p =>
  352. p.CalMonthId == calMonth.Id && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") &&
  353. (p.ItemStaffs.Where<ItemStaff>(s => s.DoPerson.Id == userId).Count() > 0 || p.ReviewerId == userId) && p.BasePoint > 0.0);
  354. }
  355. #region 循环计算
  356. int iCount = 0;
  357. double d = 0.0;
  358. var retList = results.ToList();
  359. foreach (var item in retList)
  360. {
  361. string strCaseCeoffcient = item.CaseCoefficient;
  362. if (string.IsNullOrEmpty(strCaseCeoffcient))
  363. {
  364. strCaseCeoffcient = "B";
  365. }
  366. #region 严重延期降系数
  367. if (item.isDanger() && string.IsNullOrEmpty(item.OverDueMemo))
  368. {
  369. switch (item.CaseCoefficient)
  370. {
  371. case "S":
  372. strCaseCeoffcient = "A";
  373. break;
  374. case "A":
  375. strCaseCeoffcient = "B";
  376. break;
  377. case "B":
  378. strCaseCeoffcient = "C";
  379. break;
  380. case "C":
  381. strCaseCeoffcient = "D";
  382. break;
  383. }
  384. }
  385. #endregion
  386. switch (strCaseCeoffcient)
  387. {
  388. case "S":
  389. retObj.S += 1;
  390. break;
  391. case "A":
  392. retObj.A += 1;
  393. break;
  394. case "B":
  395. retObj.B += 1;
  396. break;
  397. case "C":
  398. retObj.C += 1;
  399. break;
  400. case "D":
  401. retObj.D += 1;
  402. break;
  403. default:
  404. retObj.B += 1;
  405. break;
  406. }
  407. if (CaseXiShu.ContainsKey(strCaseCeoffcient))
  408. {
  409. d += CaseXiShu[strCaseCeoffcient];
  410. iCount += 1;
  411. }
  412. }
  413. #endregion
  414. retObj.NanduXS = d / (double)iCount;
  415. // Save data in cache.
  416. MyMemoryCache.SetValue(strKey, retObj);
  417. return retObj;
  418. }
  419. else
  420. {
  421. return (NanduStatics)cacheEntry;
  422. }
  423. }
  424. public List<string> GetFeedbackString(int itemId)
  425. {
  426. PerformanceItem item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == itemId);
  427. if(item != null)
  428. {
  429. return Utility.Utility.GetFeedbackMemos(item, Context.BasePointRules.ToList());
  430. }
  431. return new List<string>();
  432. }
  433. private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
  434. {
  435. NanduStatics gspjXS = DegreeOfDifficulty(calMonth);
  436. calMonth.NanduXS = gspjXS.NanduXS;
  437. calMonth.S = gspjXS.S;
  438. calMonth.A = gspjXS.A;
  439. calMonth.B = gspjXS.B;
  440. calMonth.C = gspjXS.C;
  441. calMonth.D = gspjXS.D;
  442. //未归档,从绩效记录中统计数据
  443. var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
  444. if (userid != null)
  445. {
  446. results = Context.PerformanceItems.Where<PerformanceItem>(s =>
  447. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  448. && s.CalMonth.Id == calMonth.Id);
  449. }
  450. List<PerformanceItem> ItemList = results
  451. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  452. .Include(pi => pi.Reviewer).ThenInclude(p=>p.StaffGrade)
  453. .Include(pi => pi.Customer)
  454. .OrderByDescending(o => o.Id)
  455. .ToList<PerformanceItem>();
  456. List<StaffStatistics> retList = new List<StaffStatistics>();
  457. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  458. var Rules = Context.BasePointRules.ToList();
  459. foreach (PerformanceItem item in ItemList)
  460. {
  461. //if (item.BasePoint == null)
  462. //{
  463. if (item.AgentFeedbackMemo != "特殊点数申诉")
  464. {
  465. Utility.Utility.CalBasePoint(item, Rules);
  466. Context.SaveChanges();
  467. }
  468. //}
  469. if (item.BasePoint != null && item.BasePoint.Value > 0)
  470. {
  471. double doPersonBasePoint = item.BasePoint.Value;
  472. List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
  473. List<StaffStatistics> temItemStatics;
  474. if (userid != null)
  475. {
  476. temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
  477. }
  478. else
  479. {
  480. temItemStatics = itemStatistics;
  481. }
  482. foreach (StaffStatistics retUserValue in temItemStatics)
  483. {
  484. var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
  485. if (temValue != null)
  486. {
  487. temValue.totalBasePoint += retUserValue.totalBasePoint;
  488. }
  489. else
  490. {
  491. retList.Add(retUserValue);
  492. }
  493. }
  494. }
  495. }
  496. if (userid != null)
  497. {
  498. retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
  499. }
  500. IDictionary<int, NanduStatics> staffXiShu = new Dictionary<int, NanduStatics>();
  501. foreach (StaffStatistics ss in retList)
  502. {
  503. if (ss.jxType.Contains("新申请") || ss.jxType.Contains("专案"))
  504. {
  505. if (!staffXiShu.ContainsKey(ss.StaffId))
  506. {
  507. NanduStatics nandu = DegreeOfDifficulty(calMonth, ss.StaffId);
  508. staffXiShu.Add(ss.StaffId, nandu);
  509. }
  510. ss.totalActuallyPoint = ss.totalBasePoint * staffXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  511. ss.NanduXS = staffXiShu[ss.StaffId].NanduXS;
  512. ss.S = staffXiShu[ss.StaffId].S;
  513. ss.A = staffXiShu[ss.StaffId].A;
  514. ss.B = staffXiShu[ss.StaffId].B;
  515. ss.C = staffXiShu[ss.StaffId].C;
  516. ss.D = staffXiShu[ss.StaffId].D;
  517. }
  518. else
  519. {
  520. ss.totalActuallyPoint = ss.totalBasePoint;
  521. }
  522. //ss.CalMonth.PerformanceItems = null;
  523. }
  524. return retList;
  525. }
  526. private void _RefreshBasePoint()
  527. {
  528. spDbContext spDb = new spDbContext();
  529. var lstItem = spDb.PerformanceItems.Include(p => p.Customer).Where(p => p.CalMonth.Status != 4).ToList();
  530. var rules = spDb.BasePointRules.ToList();
  531. foreach (var item in lstItem)
  532. {
  533. if (item.AgentFeedbackMemo != "特殊点数申诉")
  534. {
  535. Utility.Utility.CalBasePoint(item, rules);
  536. spDb.SaveChanges();
  537. }
  538. }
  539. }
  540. public ApiSaveResponse RefreshBasePoint()
  541. {
  542. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  543. t.Start();
  544. return new ApiSaveResponse() {
  545. Success = true
  546. };
  547. }
  548. public ApiSaveResponse RefreshFromIPEasyById(int itemId)
  549. {
  550. var Item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault(p => p.Id == itemId);
  551. if (Item != null)
  552. {
  553. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  554. }
  555. Utility.Utility.CalBasePoint(Item, Context.BasePointRules.ToList());
  556. Context.SaveChanges();
  557. return new ApiSaveResponse()
  558. {
  559. Success = true
  560. };
  561. }
  562. public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
  563. {
  564. new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
  565. return new ApiSaveResponse()
  566. {
  567. Success = true
  568. };
  569. }
  570. public ApiSaveResponse RefreshFromIPEasy(string CaseNo,string DoItem,string caseStage)
  571. {
  572. var Item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault(p=>p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
  573. if(Item != null)
  574. {
  575. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item,Context);
  576. }
  577. return new ApiSaveResponse()
  578. {
  579. Success = true
  580. };
  581. }
  582. public ApiSaveResponse CompareExcel2DB()
  583. {
  584. System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
  585. t.Start();
  586. return new ApiSaveResponse()
  587. {
  588. Success = true
  589. };
  590. }
  591. public FileProcessTask CurrentData2Excel()
  592. {
  593. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Status == 0);
  594. if (calMonth != null)
  595. {
  596. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  597. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  598. var filePath = Path.Combine(attachfileSavePath, filename);
  599. var fileTask = new FileProcessTask()
  600. {
  601. Id = Guid.NewGuid().ToString(),
  602. FileName = filename,
  603. FilePath = filePath,
  604. Processed = 0
  605. };
  606. fileTaskService.Add(fileTask);
  607. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(Export2ExcelThread));
  608. t.Start(fileTask);
  609. return fileTask;
  610. }
  611. return null;
  612. }
  613. private void Export2ExcelThread(object attfile)
  614. {
  615. FileProcessTask file = (FileProcessTask)attfile;
  616. spDbContext spDb = new spDbContext();
  617. List<PerformanceItem> items = spDb.PerformanceItems
  618. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  619. .Include(p=>p.PreOastaff)
  620. .Include(p => p.Customer)
  621. .Include(p => p.CalMonth)
  622. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  623. .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  624. DataTable dt = new DataTable();
  625. #region 栏位名称
  626. dt.Columns.Add("我方文号",typeof(string));
  627. dt.Columns.Add("申请类型", typeof(string));
  628. dt.Columns.Add("业务类型", typeof(string));
  629. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  630. dt.Columns.Add("处理事项", typeof(string));
  631. dt.Columns.Add("案件阶段", typeof(string));
  632. dt.Columns.Add("案件系数", typeof(string));
  633. dt.Columns.Add("处理事项系数", typeof(string));
  634. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  635. dt.Columns.Add("前一次OA处理人", typeof(string));
  636. dt.Columns.Add("处理人等级", typeof(string));
  637. dt.Columns.Add("基本点数", typeof(string));
  638. dt.Columns.Add("核稿系数", typeof(string));
  639. dt.Columns.Add("核稿绩效", typeof(string));
  640. dt.Columns.Add("处理人", typeof(string));
  641. dt.Columns.Add("核稿人", typeof(string));
  642. dt.Columns.Add("客户名称", typeof(string));
  643. dt.Columns.Add("申请人", typeof(string));
  644. dt.Columns.Add("处理事项完成日", typeof(string));
  645. dt.Columns.Add("定稿日", typeof(string));
  646. dt.Columns.Add("返稿日", typeof(string));
  647. dt.Columns.Add("案件类型", typeof(string));
  648. dt.Columns.Add("案件状态", typeof(string));
  649. dt.Columns.Add("处理事项备注", typeof(string));
  650. dt.Columns.Add("处理状态", typeof(string));
  651. dt.Columns.Add("案件名称", typeof(string));
  652. dt.Columns.Add("委案日期", typeof(string));
  653. dt.Columns.Add("客户期限", typeof(string));
  654. dt.Columns.Add("内部期限", typeof(string));
  655. dt.Columns.Add("初稿日", typeof(string));
  656. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因", typeof(string));
  657. dt.Columns.Add("绩效类型", typeof(string));
  658. dt.Columns.Add("案件备注", typeof(string));
  659. dt.Columns.Add("处理人绩效系数", typeof(string));
  660. dt.Columns.Add("系统核算绩效", typeof(string));
  661. dt.Columns.Add("实际处理人", typeof(string));
  662. #endregion
  663. var verifyCeoffients = spDb.VerifyCoefficients.ToList();
  664. var Rules = spDb.BasePointRules.ToList();
  665. file.Size = items.Count;
  666. foreach(var p in items)
  667. {
  668. System.Diagnostics.Debug.WriteLine(p.CaseNo);
  669. List<ItemStaff> temItemStaffs = p.ItemStaffs.ToList();
  670. string strCaseMemo = "";
  671. if (p.ItemStaffs.Count > 1)
  672. {
  673. temItemStaffs = new List<ItemStaff>();
  674. foreach (var iStaff in p.ItemStaffs)
  675. {
  676. if (iStaff.DoPerson.Status != "试用期")
  677. {
  678. temItemStaffs.Add(iStaff);
  679. }
  680. else
  681. {
  682. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}" : $"{strCaseMemo},{iStaff.DoPerson.Name}";
  683. }
  684. }
  685. }
  686. if (!string.IsNullOrEmpty(strCaseMemo))
  687. {
  688. strCaseMemo = $"{strCaseMemo}在试用期";
  689. }
  690. string temDoPerson = "";
  691. foreach(var iStaff in temItemStaffs)
  692. {
  693. temDoPerson =string.IsNullOrEmpty(temDoPerson)?iStaff.DoPerson.Name:$"{temDoPerson},{iStaff.DoPerson.Name}";
  694. }
  695. Utility.Utility.CalBasePoint(p, Rules);
  696. var jxList = _calItemJX(p.CalMonth, verifyCeoffients, p, spDb);
  697. bool isPJFP = true;
  698. bool isReviewerInDopersons = false;
  699. if (p.ReviewerId.HasValue)
  700. {
  701. isReviewerInDopersons = (p.ItemStaffs.Where(i => i.DoPersonId == p.ReviewerId).Count() > 0);
  702. }
  703. double total = temItemStaffs.Count();
  704. if (temItemStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  705. {
  706. total = temItemStaffs.Select(i => i.PerformancePoint.Value).Sum();
  707. isPJFP = false;
  708. }
  709. foreach (var iStaff in temItemStaffs)
  710. {
  711. DataRow row = dt.NewRow();
  712. row["我方文号"] = p.CaseNo;
  713. row["申请类型"] = p.ApplicationType;
  714. if(p.ApplicationName != null && p.ApplicationName.Contains("OPPO") && p.ApplicationType == "实用新型")
  715. {
  716. row["申请类型"] = "发明";
  717. row["案件备注"] = $"{row["案件备注"]}\r\nOPPO案件实用新型修改为发明】";
  718. }
  719. row["处理事项"] = p.DoItem;
  720. row["业务类型"] = p.BusinessType;
  721. row["备注(填表注意事项)"] = p.AgentFeedbackMemo;
  722. if(p.Type == "专案")
  723. {
  724. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]}【主管给定点数】专案";
  725. row["处理事项"] = "提出报告";
  726. }
  727. if(temItemStaffs.Count > 1)
  728. {
  729. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]},{temDoPerson}合写";
  730. }
  731. row["案件阶段"] = p.CaseStage;
  732. row["案件系数"] = p.CaseCoefficient;
  733. if(p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo) && p.Type =="新申请")
  734. {
  735. switch (p.CaseCoefficient)
  736. {
  737. case "S":
  738. row["案件系数"] = "A";
  739. break;
  740. case "A":
  741. row["案件系数"] = "B";
  742. break;
  743. case "B":
  744. row["案件系数"] = "C";
  745. break;
  746. case "C":
  747. row["案件系数"] = "D";
  748. break;
  749. }
  750. row["案件备注"] = $"{row["案件备注"]}\r\n严重延期降系数【{p.CaseCoefficient}->{row["案件系数"]}】";
  751. }
  752. row["处理事项系数"] = p.DoItemCoefficient;
  753. row["前一次OA处理事项系数"] = "";
  754. row["前一次OA处理人"] = p.PreOastaff?.Name;
  755. if(iStaff.DoPerson.Status == "试用期")
  756. {
  757. row["实际处理人"] = iStaff.DoPerson.Name;
  758. row["案件备注"] = $"{row["案件备注"]}\r\n处理人{iStaff.DoPerson.Name}未转正";
  759. row["处理人"] = p.Reviewer?.Name;
  760. row["处理人等级"] = p.Reviewer?.StaffGrade?.Grade;
  761. row["基本点数"] = (p.BasePoint / total).ToString();
  762. row["处理人绩效系数"] = p.Reviewer?.StaffGrade?.Coefficient;
  763. var clrJX = jxList.Where(j => j.StaffId == p.ReviewerId && j.jxType.Contains("处理")).FirstOrDefault();
  764. if (clrJX != null)
  765. {
  766. row["系统核算绩效"] = clrJX.totalBasePoint;
  767. }
  768. row["核稿人"] = "";
  769. row["核稿系数"] = "";
  770. row["核稿绩效"] = "";
  771. }
  772. else
  773. {
  774. row["处理人"] = iStaff.DoPerson.Name;
  775. row["处理人等级"] = iStaff.DoPerson.StaffGrade?.Grade;
  776. row["基本点数"] = (p.BasePoint / total).ToString();
  777. row["处理人绩效系数"] = iStaff.DoPerson.StaffGrade?.Coefficient;
  778. if (isReviewerInDopersons)
  779. {
  780. row["核稿人"] = "";
  781. row["核稿系数"] = "";
  782. row["核稿绩效"] = "";
  783. row["案件备注"] = $"{row["案件备注"]}\r\n核稿人与处理人一致,置空核稿人栏位";
  784. var clrJX = jxList.Where(j => j.StaffId == p.ReviewerId && j.jxType.Contains("处理")).FirstOrDefault();
  785. if (clrJX != null)
  786. {
  787. row["系统核算绩效"] = clrJX.totalBasePoint;
  788. }
  789. }
  790. else
  791. {
  792. var clrJX = jxList.Where(j => j.StaffId == iStaff.DoPersonId && j.jxType.Contains("处理")).FirstOrDefault();
  793. if (clrJX != null)
  794. {
  795. row["系统核算绩效"] = clrJX.totalBasePoint;
  796. }
  797. if (p.Reviewer != null)
  798. {
  799. row["核稿人"] = p.Reviewer?.Name;
  800. var temJX = jxList.FirstOrDefault(j => j.StaffId == p.ReviewerId && j.jxType.Contains("审核"));
  801. if(temJX != null)
  802. {
  803. row["核稿绩效"] = temJX.totalBasePoint;
  804. }
  805. var vCoefficient = spDb.VerifyCoefficients.FirstOrDefault(c => c.CheckerId == p.Reviewer.StaffGradeId && c.DoPersonId == iStaff.DoPerson.StaffGradeId);
  806. if (vCoefficient != null)
  807. {
  808. row["核稿系数"] = vCoefficient.Coefficient;
  809. //row["核稿绩效"] = (p.BasePoint / total) * vCoefficient.Coefficient;
  810. }
  811. }
  812. else
  813. {
  814. row["核稿人"] = "";
  815. row["核稿系数"] = "";
  816. row["核稿绩效"] = "";
  817. }
  818. }
  819. }
  820. row["客户名称"] = p.Customer?.Name;
  821. row["申请人"] = p.ApplicationName;
  822. row["处理事项完成日"] = p.FinishedDate?.ToString("yyyy-MM-dd");
  823. row["定稿日"] = p.FinalizationDate?.ToString("yyyy-MM-dd");
  824. row["返稿日"] = p.ReturnDate?.ToString("yyyy-MM-dd");
  825. row["案件类型"] = p.CaseType;
  826. row["案件状态"] = p.CaseState;
  827. row["处理事项备注"] = p.DoItemMemo;
  828. row["处理状态"] = p.DoItemState;
  829. row["案件名称"] = p.CaseName;
  830. row["委案日期"] = p.EntrustingDate?.ToString("yyyy-MM-dd");
  831. row["客户期限"] = p.CustomerLimitDate?.ToString("yyyy-MM-dd");
  832. row["内部期限"] = p.InternalDate?.ToString("yyyy-MM-dd");
  833. row["初稿日"] = p.FirstDraftDate?.ToString("yyyy-MM-dd");
  834. row["备注(发文严重超期是否属客观原因,若为否,请填写原因"] = p.OverDueMemo;
  835. row["绩效类型"] = p.Type;
  836. row["案件备注"] = $"{p.CaseMemo}\r\n{row["案件备注"]}";
  837. if(!string.IsNullOrEmpty(strCaseMemo))
  838. {
  839. row["案件备注"] = $"{strCaseMemo}\r\n{row["案件备注"]}";
  840. }
  841. dt.Rows.Add(row);
  842. }
  843. file.Processed += 1;
  844. }
  845. NPOIExcel.DataTableToExcel(dt, file.FilePath);
  846. file.Finished = true;
  847. }
  848. private void _CompareExcel2DB()
  849. {
  850. DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0,2);
  851. DataTable retTable = new DataTable();
  852. retTable.Columns.Add("我方文号");
  853. retTable.Columns.Add("申请类型");
  854. retTable.Columns.Add("业务类型");
  855. retTable.Columns.Add("备注(填表注意事项)");
  856. retTable.Columns.Add("备注(填表注意事项)【系统】");
  857. retTable.Columns.Add("处理事项");
  858. retTable.Columns.Add("处理事项【系统】");
  859. retTable.Columns.Add("案件阶段");
  860. retTable.Columns.Add("案件阶段【系统】");
  861. retTable.Columns.Add("案件系数");
  862. retTable.Columns.Add("案件系数【系统】");
  863. retTable.Columns.Add("处理事项系数");
  864. retTable.Columns.Add("处理事项系数【系统】");
  865. retTable.Columns.Add("处理人等级");
  866. retTable.Columns.Add("处理人等级【系统】");
  867. retTable.Columns.Add("处理人系数");
  868. retTable.Columns.Add("处理人系数【系统】");
  869. retTable.Columns.Add("基本点数");
  870. retTable.Columns.Add("基本点数【系统】");
  871. retTable.Columns.Add("核稿系数");
  872. retTable.Columns.Add("核稿系数【系统】");
  873. retTable.Columns.Add("核稿绩效");
  874. retTable.Columns.Add("核稿绩效【系统】");
  875. retTable.Columns.Add("处理人");
  876. retTable.Columns.Add("处理人【系统】");
  877. retTable.Columns.Add("核稿人");
  878. retTable.Columns.Add("核稿人【系统】");
  879. retTable.Columns.Add("严重超期备注原因");
  880. retTable.Columns.Add("严重超期备注原因【系统】");
  881. retTable.Columns.Add("是否一致");
  882. retTable.Columns.Add("不一致原因");
  883. spDbContext spDb = new spDbContext();
  884. List<PerformanceItem> items = spDb.PerformanceItems
  885. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  886. .Include(p=>p.Customer)
  887. .Include(p=>p.ItemStaffs).ThenInclude(s=>s.DoPerson).ThenInclude(s=>s.StaffGrade)
  888. .Where(p=>p.CalMonth.Status ==0 && !p.CaseNo.StartsWith("J")).OrderBy(p=>p.CaseNo).ThenBy(p=>p.DoItem).ToList();
  889. excelDT.DefaultView.Sort = "我方文号,处理事项";
  890. DataTable temDt = excelDT.DefaultView.ToTable();
  891. int iTable = 0;
  892. int iList = 0;
  893. CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p=>p.Status ==0);
  894. var verifyCoefficients = spDb.VerifyCoefficients.ToList();
  895. var Rules = spDb.BasePointRules.ToList();
  896. while (iTable < temDt.Rows.Count && iList < items.Count)
  897. {
  898. System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
  899. DataRow row = temDt.Rows[iTable];
  900. PerformanceItem item = items[iList];
  901. if(row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString()== "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
  902. {
  903. var temRow = retTable.NewRow();
  904. int iBegin = iTable;
  905. int iEnd = iTable;
  906. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  907. if (iEnd < temDt.Rows.Count - 1)
  908. {
  909. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  910. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  911. {
  912. iEnd++;
  913. }
  914. }
  915. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  916. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  917. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  918. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  919. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  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. for (int i = iBegin; i <= iEnd; i++)
  930. {
  931. temRow["备注(填表注意事项)"] =string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ?temDt.Rows[i]["备注(填表注意事项)"] :$"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  932. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  933. temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
  934. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  935. {
  936. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  937. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  938. }
  939. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  940. }
  941. iTable = iEnd;
  942. #endregion
  943. Utility.Utility.CalBasePoint(item, Rules);
  944. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  945. try
  946. {
  947. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  948. }
  949. catch { }
  950. temRow["案件阶段【系统】"] = item.CaseStage;
  951. temRow["案件系数【系统】"] = item.CaseCoefficient;
  952. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  953. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  954. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  955. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  956. temRow["严重超期备注原因"] = item.OverDueMemo;
  957. if (retPoints != null && retPoints.Count > 0)
  958. {
  959. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
  960. foreach (var itemStaff in item.ItemStaffs)
  961. {
  962. //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  963. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  964. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  965. if (item.ReviewerId != null)
  966. {
  967. #region 取审核人等级审核等级系数
  968. VerifyCoefficient vcoefficient
  969. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  970. v.CheckerId == item.Reviewer.StaffGradeId
  971. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  972. .FirstOrDefault<VerifyCoefficient>();
  973. #endregion
  974. if (vcoefficient != null)
  975. {
  976. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  977. }
  978. }
  979. }
  980. }
  981. temRow["是否一致"] = "";
  982. temRow["不一致原因"] = "";
  983. if(temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
  984. {
  985. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
  986. }
  987. if (temRow["案件系数【系统】"].ToString().Trim() != temRow["案件系数"].ToString().Trim())
  988. {
  989. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件系数" : $"{temRow["不一致原因"]},案件系数";
  990. }
  991. if (temRow["处理事项系数【系统】"].ToString().Trim() != temRow["处理事项系数"].ToString().Trim())
  992. {
  993. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "处理事项系数" : $"{temRow["不一致原因"]},处理事项系数";
  994. }
  995. if (temRow["核稿人【系统】"].ToString().Trim() != temRow["核稿人"].ToString().Trim())
  996. {
  997. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "核稿人" : $"{temRow["不一致原因"]},核稿人";
  998. }
  999. if (temRow["基本点数【系统】"].ToString().Trim() != temRow["基本点数"].ToString().Trim())
  1000. {
  1001. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "基本点数" : $"{temRow["不一致原因"]},基本点数";
  1002. }
  1003. if (temRow["严重超期备注原因【系统】"].ToString().Trim() != temRow["严重超期备注原因"].ToString().Trim())
  1004. {
  1005. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "严重超期备注原因" : $"{temRow["不一致原因"]},严重超期备注原因";
  1006. }
  1007. if (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
  1008. {
  1009. temRow["是否一致"] = "不一致";
  1010. }
  1011. retTable.Rows.Add(temRow);
  1012. iTable++;
  1013. iList++;
  1014. }
  1015. else
  1016. {
  1017. string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
  1018. string strList = $"{item.CaseNo}-{item.DoItem}";
  1019. if (strDT.CompareTo(strList) > 0)
  1020. {
  1021. var temRow = retTable.NewRow();
  1022. Utility.Utility.CalBasePoint(item, Rules);
  1023. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1024. try
  1025. {
  1026. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  1027. }
  1028. catch { }
  1029. temRow["我方文号"] = item.CaseNo;
  1030. temRow["处理事项"] = item.DoItem;
  1031. temRow["申请类型"] = item.ApplicationType;
  1032. temRow["业务类型"] = item.BusinessType;
  1033. temRow["案件阶段【系统】"] = item.CaseStage;
  1034. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1035. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1036. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1037. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1038. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1039. temRow["严重超期备注原因"] = item.OverDueMemo;
  1040. if (item.ReviewerId != null)
  1041. {
  1042. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1043. }
  1044. foreach (var itemStaff in item.ItemStaffs)
  1045. {
  1046. //if (itemStaff.DoPerson.Status != "试用期")
  1047. //{
  1048. // if (retPoints != null && retPoints.Count > 0)
  1049. // {
  1050. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1051. // }
  1052. //}
  1053. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1054. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1055. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1056. if (item.ReviewerId != null)
  1057. {
  1058. #region 取审核人等级审核等级系数
  1059. VerifyCoefficient vcoefficient
  1060. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1061. v.CheckerId == item.Reviewer.StaffGradeId
  1062. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1063. .FirstOrDefault<VerifyCoefficient>();
  1064. #endregion
  1065. if (vcoefficient != null)
  1066. {
  1067. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1068. }
  1069. }
  1070. }
  1071. temRow["是否一致"] = "不一致";
  1072. temRow["不一致原因"] = "Excel中没有,系统中有";
  1073. retTable.Rows.Add(temRow);
  1074. iList++;
  1075. }
  1076. else
  1077. {
  1078. var temRow = retTable.NewRow();
  1079. int iBegin = iTable;
  1080. int iEnd = iTable;
  1081. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1082. if (iEnd < temDt.Rows.Count - 1)
  1083. {
  1084. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1085. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1086. {
  1087. iEnd++;
  1088. }
  1089. }
  1090. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1091. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1092. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1093. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1094. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1095. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1096. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1097. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1098. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1099. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1100. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1101. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1102. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1103. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1104. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1105. for (int i = iBegin+1; i <= iEnd; i++)
  1106. {
  1107. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1108. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1109. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1110. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1111. {
  1112. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1113. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1114. }
  1115. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1116. }
  1117. iTable = iEnd;
  1118. #endregion
  1119. temRow["是否一致"] = "不一致";
  1120. temRow["不一致原因"] = "系统中没有,Excel中有";
  1121. retTable.Rows.Add(temRow);
  1122. iTable++;
  1123. }
  1124. }
  1125. }
  1126. if (iList <=items.Count)
  1127. {
  1128. while(iList <items.Count){
  1129. var item = items[iList];
  1130. var temRow = retTable.NewRow();
  1131. Utility.Utility.CalBasePoint(item, Rules);
  1132. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1133. try
  1134. {
  1135. retPoints = _calItemJX(calMonth, verifyCoefficients, item, spDb);
  1136. }
  1137. catch { }
  1138. temRow["我方文号"] = item.CaseNo;
  1139. temRow["处理事项"] = item.DoItem;
  1140. temRow["申请类型"] = item.ApplicationType;
  1141. temRow["业务类型"] = item.BusinessType;
  1142. temRow["案件阶段【系统】"] = item.CaseStage;
  1143. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1144. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1145. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1146. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1147. temRow["基本点数【系统】"] = "";// item.BasePoint?.ToString();
  1148. temRow["严重超期备注原因"] = item.OverDueMemo;
  1149. if (item.ReviewerId != null)
  1150. {
  1151. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1152. }
  1153. foreach (var itemStaff in item.ItemStaffs)
  1154. {
  1155. //if (itemStaff.DoPerson.Status != "试用期")
  1156. //{
  1157. // if (retPoints != null && retPoints.Count > 0)
  1158. // {
  1159. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1160. // }
  1161. //}
  1162. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1163. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1164. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1165. if (item.ReviewerId != null)
  1166. {
  1167. #region 取审核人等级审核等级系数
  1168. VerifyCoefficient vcoefficient
  1169. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1170. v.CheckerId == item.Reviewer.StaffGradeId
  1171. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1172. .FirstOrDefault<VerifyCoefficient>();
  1173. #endregion
  1174. if (vcoefficient != null)
  1175. {
  1176. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1177. }
  1178. }
  1179. }
  1180. temRow["是否一致"] = "不一致";
  1181. temRow["不一致原因"] = "Excel中没有,系统中有";
  1182. iList++;
  1183. retTable.Rows.Add(temRow);
  1184. }
  1185. }
  1186. else
  1187. {
  1188. while (iTable < temDt.Rows.Count)
  1189. {
  1190. var temRow = retTable.NewRow();
  1191. int iBegin = iTable;
  1192. int iEnd = iTable;
  1193. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1194. while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
  1195. temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
  1196. {
  1197. iEnd++;
  1198. }
  1199. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1200. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1201. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1202. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1203. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1204. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1205. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1206. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1207. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1208. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1209. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1210. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1211. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1212. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1213. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1214. for (int i = iBegin + 1; i <= iEnd; i++)
  1215. {
  1216. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1217. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1218. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1219. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1220. {
  1221. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1222. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1223. }
  1224. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["严重超期备注原因"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["严重超期备注原因"]}";
  1225. }
  1226. iTable = iEnd;
  1227. #endregion
  1228. temRow["是否一致"] = "不一致";
  1229. temRow["不一致原因"] = "系统中没有,Excel中有";
  1230. retTable.Rows.Add(temRow);
  1231. iTable++;
  1232. }
  1233. }
  1234. NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
  1235. }
  1236. public List<StaffStatistics> CalItemJX(int itemid)
  1237. {
  1238. var Item = Context.PerformanceItems.Include(p=>p.CalMonth).FirstOrDefault(p=>p.Id == itemid);
  1239. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  1240. return _calItemJX(Item.CalMonth,verifyCoefficients,Item,Context);
  1241. }
  1242. private List<StaffStatistics> _calItemJX(CalMonth calMonth, List<VerifyCoefficient> verifyCoefficients, PerformanceItem item,spDbContext spDb)
  1243. {
  1244. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  1245. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  1246. if (item.ReviewerId != null)
  1247. {
  1248. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  1249. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  1250. }
  1251. List<ItemStaff> temIStaffs = new List<ItemStaff>();
  1252. foreach(var itemStaff in item.ItemStaffs)
  1253. {
  1254. if (itemStaff.DoPerson == null)
  1255. {
  1256. itemStaff.DoPerson = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == itemStaff.DoPersonId);
  1257. }
  1258. if(itemStaff.DoPerson.Status != "试用期")
  1259. {
  1260. temIStaffs.Add(itemStaff);
  1261. }
  1262. }
  1263. bool isPJFP = true;
  1264. double total = temIStaffs.Count();
  1265. if (temIStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  1266. {
  1267. total = temIStaffs.Select(i => i.PerformancePoint.Value).Sum();
  1268. isPJFP = false;
  1269. }
  1270. foreach (ItemStaff itemStaff in temIStaffs)
  1271. {
  1272. if(itemStaff.DoPerson == null)
  1273. {
  1274. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  1275. }
  1276. //spDb.Entry(itemStaff).Reference(b => b.DoPerson).Load();
  1277. //spDb.Entry(itemStaff.DoPerson).Reference(b => b.StaffGrade).Load();
  1278. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  1279. if (item.ReviewerId != null && item.Type != "专案" &&
  1280. item.ItemStaffs.FirstOrDefault(s=>s.DoPersonId == item.ReviewerId) == null)
  1281. {
  1282. #region 取审核人等级审核等级系数
  1283. VerifyCoefficient vcoefficient
  1284. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1285. v.CheckerId == item.Reviewer.StaffGradeId
  1286. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1287. .FirstOrDefault<VerifyCoefficient>();
  1288. #endregion
  1289. if (vcoefficient != null)
  1290. {
  1291. double reviewerBasePoint = item.BasePoint.Value * vcoefficient.Coefficient;
  1292. string temJxType = $"{item.Type}审核";
  1293. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  1294. if (temReviewerStatic != null)
  1295. {
  1296. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  1297. }
  1298. else
  1299. {
  1300. if (item.Reviewer.IsOnJob && itemStaff.DoPerson.Status != "试用期") //判断是否在职
  1301. {
  1302. temReviewerStatic = new StaffStatistics()
  1303. {
  1304. CalMonth = calMonth,
  1305. CalMonthId = calMonth.Id,
  1306. StaffId = item.ReviewerId.Value,
  1307. totalBasePoint = reviewerBasePoint,
  1308. jxType = temJxType
  1309. };
  1310. itemStatistics.Add(temReviewerStatic);
  1311. }
  1312. }
  1313. }
  1314. }
  1315. #endregion
  1316. #region 计算各处理人的绩效点数
  1317. double handlerBasePoint;
  1318. if (item.Type != "专案")
  1319. {
  1320. if (isPJFP)
  1321. {
  1322. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1323. }
  1324. else
  1325. {
  1326. handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
  1327. }
  1328. }
  1329. else
  1330. {
  1331. if (itemStaff.PerformancePoint == null)
  1332. {
  1333. if (isPJFP)
  1334. {
  1335. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1336. }
  1337. else
  1338. {
  1339. handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
  1340. }
  1341. }
  1342. else
  1343. {
  1344. if(item.ItemStaffs.Count ==1 && itemStaff .PerformancePoint == 0)
  1345. {
  1346. handlerBasePoint = item.BasePoint.Value;
  1347. }
  1348. else
  1349. {
  1350. handlerBasePoint = itemStaff.PerformancePoint.Value;
  1351. }
  1352. }
  1353. }
  1354. string handlerJxType = $"{item.Type}处理";
  1355. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
  1356. if (temStatic != null)
  1357. {
  1358. if (item.Type == "OA" || item.Type =="新申请")
  1359. {
  1360. temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
  1361. }
  1362. else
  1363. {
  1364. temStatic.totalBasePoint += handlerBasePoint;
  1365. }
  1366. }
  1367. else
  1368. {
  1369. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsOnJob)
  1370. {
  1371. if (item.Type == "OA" || item.Type == "新申请")
  1372. {
  1373. if (itemStaff.DoPerson.Status == "试用期" && item.Reviewer != null)
  1374. {
  1375. temStatic = new StaffStatistics()
  1376. {
  1377. CalMonth = calMonth,
  1378. CalMonthId = calMonth.Id,
  1379. StaffId = item.Reviewer.Id,
  1380. totalBasePoint = handlerBasePoint * item.Reviewer.StaffGrade.Coefficient,
  1381. jxType = handlerJxType
  1382. };
  1383. itemStatistics.Add(temStatic);
  1384. }
  1385. else
  1386. {
  1387. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s=>s.Id == itemStaff.DoPerson.StaffGradeId);
  1388. temStatic = new StaffStatistics()
  1389. {
  1390. CalMonth = calMonth,
  1391. CalMonthId = calMonth.Id,
  1392. StaffId = itemStaff.DoPersonId,
  1393. totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
  1394. jxType = handlerJxType
  1395. };
  1396. itemStatistics.Add(temStatic);
  1397. }
  1398. }
  1399. else
  1400. {
  1401. temStatic = new StaffStatistics()
  1402. {
  1403. CalMonth = calMonth,
  1404. CalMonthId = calMonth.Id,
  1405. StaffId = itemStaff.DoPersonId,
  1406. totalBasePoint = handlerBasePoint,
  1407. jxType = handlerJxType
  1408. };
  1409. itemStatistics.Add(temStatic);
  1410. }
  1411. }
  1412. }
  1413. #endregion
  1414. }
  1415. return itemStatistics;
  1416. }
  1417. public ApiSaveResponse FinishedCalMonth(int year,int month)
  1418. {
  1419. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1420. if (calMonth != null || calMonth.Status !=4)
  1421. {
  1422. var retList = _CalMyStatistics(calMonth);
  1423. using (var t = Context.Database.BeginTransaction())
  1424. {
  1425. try
  1426. {
  1427. Context.SaveChanges();
  1428. foreach (var obj in retList)
  1429. {
  1430. obj.CalMonthId = calMonth.Id;
  1431. obj.CalMonth = null;
  1432. Context.StaffStatistics.Add(obj);
  1433. Context.SaveChanges();
  1434. }
  1435. calMonth.Status = 4;
  1436. Context.SaveChanges();
  1437. t.Commit();
  1438. return new ApiSaveResponse()
  1439. {
  1440. Success = true
  1441. };
  1442. }
  1443. catch(Exception ex)
  1444. {
  1445. t.Rollback();
  1446. return new ApiSaveResponse()
  1447. {
  1448. Success = false,
  1449. ErrorMessage = ex.Message
  1450. };
  1451. }
  1452. }
  1453. }
  1454. else
  1455. {
  1456. return new ApiSaveResponse()
  1457. {
  1458. Success = false,
  1459. ErrorMessage ="指定月份没有数据或者已归档!"
  1460. };
  1461. }
  1462. }
  1463. /// <summary>
  1464. /// 计算指定用户,指定年月的绩效统计信息
  1465. /// </summary>
  1466. /// <param name="userid"></param>
  1467. /// <param name="year"></param>
  1468. /// <param name="month"></param>
  1469. /// <returns></returns>
  1470. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  1471. {
  1472. object retList;
  1473. string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
  1474. if(!MyMemoryCache.TryGetValue(strKey,out retList))
  1475. {
  1476. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1477. if (calMonth == null)
  1478. {
  1479. return null;
  1480. }
  1481. else
  1482. {
  1483. if (calMonth.Status == 4)
  1484. {
  1485. //已归档,归档数据库中直接取出记录
  1486. if (userid == null)
  1487. {
  1488. retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  1489. }
  1490. else
  1491. {
  1492. retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  1493. }
  1494. }
  1495. else
  1496. {
  1497. try
  1498. {
  1499. retList = _CalMyStatistics(calMonth, userid);
  1500. }
  1501. catch(Exception ex)
  1502. {
  1503. StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  1504. sw.WriteLine($"{ex.Message}");
  1505. sw.Flush();
  1506. sw.Close();
  1507. sw.Dispose();
  1508. }
  1509. }
  1510. // Set cache options.
  1511. var cacheEntryOptions = new MemoryCacheEntryOptions()
  1512. // Keep in cache for this time, reset time if accessed.
  1513. .SetSlidingExpiration(TimeSpan.FromHours(1));
  1514. foreach(var temObj in (List<StaffStatistics>)retList)
  1515. {
  1516. temObj.CalMonth.PerformanceItems = null;
  1517. }
  1518. // Save data in cache.
  1519. MyMemoryCache.SetValue(strKey, retList);
  1520. return (List<StaffStatistics>)retList;
  1521. }
  1522. }
  1523. else
  1524. {
  1525. var temList = (List<StaffStatistics>)retList;
  1526. foreach (var temObj in temList)
  1527. {
  1528. temObj.CalMonth.PerformanceItems = null;
  1529. }
  1530. return temList;
  1531. }
  1532. }
  1533. private string GetExpress(IList<FieldCondition> conditions)
  1534. {
  1535. string str = "";
  1536. foreach(var c in conditions)
  1537. {
  1538. if (string.IsNullOrEmpty(str))
  1539. {
  1540. str = c.ToExpressString("s");
  1541. }
  1542. else
  1543. {
  1544. if(c.LogicOperate == LogicEnum.And)
  1545. {
  1546. str = $"({str}) && {c.ToExpressString("s")}";
  1547. }
  1548. else
  1549. {
  1550. str = $"({str}) || {c.ToExpressString("s")}";
  1551. }
  1552. }
  1553. }
  1554. return str;
  1555. }
  1556. [HttpGet,HttpPost]
  1557. public FileProcessTask ExportData(QueryFilter queryFilter)
  1558. {
  1559. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  1560. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  1561. var filePath = Path.Combine(attachfileSavePath, filename);
  1562. var fileTask = new FileProcessTask()
  1563. {
  1564. Id = Guid.NewGuid().ToString(),
  1565. FileName = filename,
  1566. FilePath = filePath,
  1567. Processed = 0
  1568. };
  1569. fileTaskService.Add(fileTask);
  1570. ThreadObject threadObject = new ThreadObject()
  1571. {
  1572. queryFilter = queryFilter,
  1573. fileTask = fileTask
  1574. };
  1575. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  1576. t.Start(threadObject);
  1577. return fileTask;
  1578. }
  1579. internal class ThreadObject
  1580. {
  1581. public QueryFilter queryFilter { get; set; }
  1582. public FileProcessTask fileTask { get; set; }
  1583. }
  1584. private void ExportDataThread(object tObj)
  1585. {
  1586. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  1587. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  1588. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  1589. var retList = response
  1590. .Include(p=>p.Customer)
  1591. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  1592. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  1593. .Include(p=>p.PreOastaff)
  1594. .Include(p=>p.CalMonth)
  1595. .ToList<PerformanceItem>();
  1596. DataTable dt = new DataTable();
  1597. #region 添加栏位
  1598. dt.Columns.Add("我方文号",typeof(string));
  1599. dt.Columns.Add("申请类型", typeof(string));
  1600. dt.Columns.Add("业务类型", typeof(string));
  1601. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  1602. dt.Columns.Add("处理事项", typeof(string));
  1603. dt.Columns.Add("案件阶段", typeof(string));
  1604. dt.Columns.Add("案件系数", typeof(string));
  1605. dt.Columns.Add("处理事项系数", typeof(string));
  1606. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  1607. dt.Columns.Add("前一次OA处理人", typeof(string));
  1608. dt.Columns.Add("处理人等级", typeof(string));
  1609. dt.Columns.Add("基本点数", typeof(string));
  1610. dt.Columns.Add("核稿系数", typeof(string));
  1611. dt.Columns.Add("核稿绩效", typeof(string));
  1612. dt.Columns.Add("处理人", typeof(string));
  1613. dt.Columns.Add("核稿人", typeof(string));
  1614. dt.Columns.Add("客户名称", typeof(string));
  1615. dt.Columns.Add("申请人", typeof(string));
  1616. dt.Columns.Add("处理事项完成日", typeof(string));
  1617. dt.Columns.Add("定稿日", typeof(string));
  1618. dt.Columns.Add("返稿日", typeof(string));
  1619. dt.Columns.Add("案件类型", typeof(string));
  1620. dt.Columns.Add("案件状态", typeof(string));
  1621. dt.Columns.Add("处理事项备注", typeof(string));
  1622. dt.Columns.Add("处理状态", typeof(string));
  1623. dt.Columns.Add("案件名称", typeof(string));
  1624. dt.Columns.Add("委案日期", typeof(string));
  1625. dt.Columns.Add("客户期限", typeof(string));
  1626. dt.Columns.Add("内部期限", typeof(string));
  1627. dt.Columns.Add("初稿日", typeof(string));
  1628. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
  1629. dt.Columns.Add("备注", typeof(string));
  1630. #endregion
  1631. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  1632. fileTask.Size = retList.Count;
  1633. foreach (var item in retList)
  1634. {
  1635. fileTask.Processed += 1;
  1636. if (item.CaseNo.StartsWith("J"))
  1637. {
  1638. continue;
  1639. }
  1640. try
  1641. {
  1642. var row = dt.NewRow();
  1643. row["我方文号"] = item.CaseNo;
  1644. row["申请类型"] = item.ApplicationType;
  1645. row["业务类型"] = item.BusinessType;
  1646. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  1647. row["处理事项"] = item.DoItem;
  1648. row["案件阶段"] = item.CaseStage;
  1649. row["案件系数"] = item.CaseCoefficient;
  1650. row["处理事项系数"] = item.DoItemCoefficient;
  1651. row["前一次OA处理事项系数"] = "";
  1652. if (item.PreOastaffId.HasValue)
  1653. {
  1654. row["前一次OA处理人"] = item.PreOastaff?.Name;
  1655. }
  1656. string strISLevels = "";
  1657. string strISNames = "";
  1658. foreach (var istaff in item.ItemStaffs)
  1659. {
  1660. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  1661. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  1662. }
  1663. row["处理人等级"] = strISLevels;
  1664. row["基本点数"] = item.BasePoint;
  1665. row["处理人"] = strISNames;
  1666. row["核稿人"] = item.Reviewer?.Name;
  1667. if (item.ReviewerId != null && item.BasePoint.HasValue)
  1668. {
  1669. var jxList = _calItemJX(item.CalMonth, verifyCoefficients, item, new spDbContext());
  1670. row["核稿系数"] = "";
  1671. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  1672. if (temJx != null)
  1673. {
  1674. row["核稿绩效"] = temJx.totalBasePoint;
  1675. }
  1676. }
  1677. row["客户名称"] = item.Customer?.Name;
  1678. row["申请人"] = item.ApplicationName;
  1679. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  1680. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  1681. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  1682. row["案件类型"] = item.CaseType;
  1683. row["案件状态"] = item.CaseState;
  1684. row["处理事项备注"] = item.DoItemState;
  1685. row["处理状态"] = item.DoItemState;
  1686. row["案件名称"] = item.CaseName;
  1687. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  1688. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  1689. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  1690. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  1691. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  1692. row["备注"] = item.DoItemMemo;
  1693. dt.Rows.Add(row);
  1694. }
  1695. catch(Exception ex)
  1696. {
  1697. throw ex;
  1698. }
  1699. }
  1700. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  1701. fileTask.Finished = true;
  1702. }
  1703. [HttpPost]
  1704. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  1705. {
  1706. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  1707. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  1708. int totals = response.ToList<PerformanceItem>().Count;
  1709. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  1710. {
  1711. response = response
  1712. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  1713. .Include(pi => pi.Reviewer)
  1714. .Include(pi => pi.Customer)
  1715. .Include(pi => pi.CalMonth)
  1716. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  1717. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  1718. }
  1719. else
  1720. {
  1721. response = response
  1722. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  1723. .Include(pi => pi.Reviewer)
  1724. .Include(pi => pi.Customer)
  1725. .Include(pi => pi.CalMonth)
  1726. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  1727. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  1728. }
  1729. ret.TotalCount = totals;
  1730. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  1731. #region 将某些属性设为null,避免循环取值造成返回json过大
  1732. foreach (PerformanceItem item in retList)
  1733. {
  1734. foreach (ItemStaff itemStaff in item.ItemStaffs)
  1735. {
  1736. itemStaff.DoPerson.ItemStaffs = null;
  1737. itemStaff.DoPerson.ReviewerItems = null;
  1738. itemStaff.Item = null;
  1739. }
  1740. if (item.Reviewer != null)
  1741. {
  1742. item.Reviewer.ReviewerItems = null;
  1743. item.Reviewer.Customers = null;
  1744. item.Reviewer.ItemStaffs = null;
  1745. }
  1746. if (item.Customer != null)
  1747. {
  1748. item.Customer.PerformanceItems = null;
  1749. }
  1750. if (item.CalMonth != null)
  1751. {
  1752. item.CalMonth.PerformanceItems = null;
  1753. }
  1754. }
  1755. #endregion
  1756. ret.Results = retList.ToList();
  1757. return ret;
  1758. }
  1759. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  1760. {
  1761. string strExpress = "";
  1762. string strCalMonth = "";
  1763. if (queryFilter.CalMonthId.HasValue)
  1764. {
  1765. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  1766. }
  1767. else
  1768. {
  1769. if(queryFilter.jxType == jxType.finished)
  1770. {
  1771. strCalMonth = $"s.CalMonth.Status == 4";
  1772. }
  1773. else
  1774. {
  1775. strCalMonth = $"s.CalMonth.Status != 4";
  1776. }
  1777. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  1778. }
  1779. if (!string.IsNullOrEmpty(strExpress))
  1780. {
  1781. strExpress = $"{strExpress} && {strCalMonth}";
  1782. }
  1783. else
  1784. {
  1785. strExpress = strCalMonth;
  1786. }
  1787. if (queryFilter.ConditionTree != null)
  1788. {
  1789. string strTem = GetExpress(queryFilter.ConditionTree);
  1790. if (!string.IsNullOrEmpty(strTem))
  1791. {
  1792. strExpress = $"{strExpress} && ({strTem})";
  1793. }
  1794. }
  1795. var interpreter = new Interpreter();
  1796. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  1797. IQueryable<PerformanceItem> response;
  1798. if (queryFilter.userId > 0)
  1799. {
  1800. if (queryFilter.DoingOrReview == 0)
  1801. {
  1802. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  1803. }
  1804. else
  1805. {
  1806. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  1807. }
  1808. }
  1809. else
  1810. {
  1811. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  1812. }
  1813. return response;
  1814. }
  1815. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  1816. {
  1817. ApiSaveResponse retResponse = new ApiSaveResponse();
  1818. retResponse.Success = true;
  1819. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  1820. {
  1821. using (var t = Context.Database.BeginTransaction())
  1822. {
  1823. try
  1824. {
  1825. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  1826. if (calMonth == null)
  1827. {
  1828. retResponse.Success = false;
  1829. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  1830. return retResponse;
  1831. }
  1832. else
  1833. {
  1834. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  1835. projectContents.ProjectContentRecord.CalMonth = null;
  1836. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  1837. projectContents.ProjectContentRecord.StaffId = staff.Id;
  1838. projectContents.ProjectContentRecord.State = 0;
  1839. }
  1840. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  1841. if (project != null)
  1842. {
  1843. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  1844. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  1845. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  1846. if(pRecord != null)
  1847. {
  1848. retResponse.Success = false;
  1849. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  1850. return retResponse;
  1851. }
  1852. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  1853. foreach (var doItem in projectContents.ProjectWorkContents)
  1854. {
  1855. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  1856. Context.ProjectWorkContents.Add(doItem);
  1857. }
  1858. t.Commit();
  1859. }
  1860. else
  1861. {
  1862. retResponse.Success = false;
  1863. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  1864. return retResponse;
  1865. }
  1866. }
  1867. catch (Exception ex)
  1868. {
  1869. retResponse.Success = false;
  1870. retResponse.ErrorMessage = ex.Message;
  1871. t.Rollback();
  1872. return retResponse;
  1873. }
  1874. }
  1875. }
  1876. return retResponse;
  1877. }
  1878. public PerformanceItem GetCaseInfo(string CaseNo)
  1879. {
  1880. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  1881. if(retObj == null)
  1882. {
  1883. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  1884. }
  1885. return retObj;
  1886. }
  1887. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  1888. {
  1889. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  1890. if (retObj == null)
  1891. {
  1892. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  1893. }
  1894. return retObj;
  1895. }
  1896. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage,bool UpdateFromIPEasy=true)
  1897. {
  1898. var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  1899. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  1900. if (retObj == null && UpdateFromIPEasy)
  1901. {
  1902. var temObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  1903. System.Dynamic.ExpandoObject temExpandoObject = (System.Dynamic.ExpandoObject)temObj;
  1904. retObj = new PerformanceItem();
  1905. retObj.CaseNo = temObj.CaseNo.ToString();
  1906. retObj.CaseName = temObj.CaseName.ToString();
  1907. try
  1908. {
  1909. if (temObj.ApplicationType != null)
  1910. retObj.ApplicationType = temObj.ApplicationType.ToString();
  1911. if (temObj.CaseMemo != null)
  1912. retObj.CaseMemo = temObj.CaseMemo.ToString();
  1913. if (temObj.BusinessType != null)
  1914. retObj.BusinessType = temObj.BusinessType.ToString();
  1915. if (temObj.DoItem != null)
  1916. retObj.DoItem = temObj.DoItem.ToString();
  1917. if (temObj.CaseStage != null)
  1918. retObj.CaseStage = temObj.CaseStage.ToString();
  1919. if (temObj.CaseType != null)
  1920. retObj.CaseType = temObj.CaseType.ToString();
  1921. if (temObj.DoItemState != null)
  1922. retObj.DoItemState = temObj.DoItemState.ToString();
  1923. if (temObj.DoItemCoefficient != null)
  1924. retObj.DoItemCoefficient = temObj.DoItemCoefficient.ToString();
  1925. if (temObj.CaseCoefficient != null)
  1926. retObj.CaseCoefficient = temObj.CaseCoefficient.ToString();
  1927. if (temObj.EntrustingDate != null)
  1928. {
  1929. if (!string.IsNullOrEmpty(temObj.EntrustingDate.ToString()))
  1930. retObj.EntrustingDate = DateTime.Parse(temObj.EntrustingDate.ToString());
  1931. }
  1932. if (temObj.InternalDate != null)
  1933. {
  1934. if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
  1935. retObj.InternalDate = DateTime.Parse(temObj.InternalDate.ToString());
  1936. }
  1937. if (temObj.CustomerLimitDate != null)
  1938. {
  1939. if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
  1940. retObj.CustomerLimitDate = DateTime.Parse(temObj.InternalDate.ToString());
  1941. }
  1942. if (temObj.ReturnDate != null)
  1943. {
  1944. if (!string.IsNullOrEmpty(temObj.ReturnDate.ToString()))
  1945. retObj.ReturnDate = DateTime.Parse(temObj.ReturnDate.ToString());
  1946. }
  1947. if (temObj.FinalizationDate != null)
  1948. {
  1949. if (!string.IsNullOrEmpty(temObj.FinalizationDate.ToString()))
  1950. retObj.FinalizationDate = DateTime.Parse(temObj.FinalizationDate.ToString());
  1951. }
  1952. if (temObj.FinishedDate != null)
  1953. {
  1954. if (!string.IsNullOrEmpty(temObj.FinishedDate.ToString()))
  1955. retObj.FinishedDate = DateTime.Parse(temObj.FinishedDate.ToString());
  1956. }
  1957. }
  1958. catch { }
  1959. int temWordCount;
  1960. if (temObj.WordCount != null)
  1961. {
  1962. if (int.TryParse(temObj.WordCount, out temWordCount))
  1963. {
  1964. retObj.WordCount = temWordCount;
  1965. }
  1966. }
  1967. try
  1968. {
  1969. if (temObj.CustomerName != null)
  1970. {
  1971. string strCustomer = temObj.CustomerName.ToString();
  1972. retObj.Customer = new Customer() { Name = strCustomer };
  1973. var temCustomer = Context.Customers.Where(c => c.Name == strCustomer.Trim()).FirstOrDefault();
  1974. if (temCustomer != null)
  1975. {
  1976. retObj.CustomerId = temCustomer.Id;
  1977. }
  1978. }
  1979. }
  1980. catch { }
  1981. try
  1982. {
  1983. if (temObj.Reviewer != null)
  1984. {
  1985. string strReViewer = temObj.Reviewer.ToString();
  1986. var temReviewer = Context.Staffs.Where(s => s.Name == strReViewer.Trim()).FirstOrDefault();
  1987. if (temReviewer != null)
  1988. {
  1989. retObj.ReviewerId = temReviewer.Id;
  1990. }
  1991. }
  1992. }
  1993. catch { }
  1994. if (temObj.DoPersons != null)
  1995. {
  1996. string DoPersons = temObj.DoPersons.ToString();
  1997. string[] Persons = DoPersons.Split(new char[] { ',' });
  1998. List<ItemStaff> itemStaffs = new List<ItemStaff>();
  1999. foreach (var doPerson in Persons)
  2000. {
  2001. itemStaffs.Add(new ItemStaff() { DoPerson = new Staff() { Name = doPerson } });
  2002. }
  2003. retObj.ItemStaffs = itemStaffs;
  2004. }
  2005. }
  2006. return retObj;
  2007. }
  2008. public PerformanceItem GetItemInfoByMonthId(string CaseNo, string DoItem, string caseStage,int calMonthId)
  2009. {
  2010. var retObj = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2011. && p.DoItem == DoItem.Trim() && p.CalMonthId == calMonthId);
  2012. if(retObj != null)
  2013. {
  2014. if(string.IsNullOrEmpty (retObj.CaseStage) && string.IsNullOrEmpty(caseStage))
  2015. {
  2016. return retObj;
  2017. }
  2018. else
  2019. {
  2020. if(retObj.CaseStage == caseStage)
  2021. {
  2022. return retObj;
  2023. }
  2024. else
  2025. {
  2026. return null;
  2027. }
  2028. }
  2029. }
  2030. else
  2031. {
  2032. return null;
  2033. }
  2034. }
  2035. public bool MovePerformance2ProjectInfo()
  2036. {
  2037. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  2038. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  2039. var pList = response.ToList<PerformanceItem>();
  2040. foreach(var p in pList)
  2041. {
  2042. ProjectInfo project = new ProjectInfo();
  2043. project.CaseNo = p.CaseNo;
  2044. project.CaseName = p.CaseName;
  2045. project.CaseState = 0;
  2046. project.CaseType = p.CaseType;
  2047. project.CustomerId = p.CustomerId;
  2048. project.ReviewerId = p.ReviewerId;
  2049. Context.ProjectInfos.Add(project);
  2050. foreach(ItemStaff iStaff in p.ItemStaffs)
  2051. {
  2052. Context.ItemStaffs.Remove(iStaff);
  2053. }
  2054. Context.PerformanceItems.Remove(p);
  2055. Context.SaveChanges();
  2056. }
  2057. return true;
  2058. }
  2059. }
  2060. }