PerformanceItemController.cs 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758
  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.Data.SqlClient;
  7. using Microsoft.EntityFrameworkCore;
  8. using Microsoft.Extensions.Caching.Memory;
  9. using Microsoft.Extensions.Hosting;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Linq.Expressions;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using wispro.sp.api.Services;
  19. using wispro.sp.api.Utility;
  20. using wispro.sp.entity;
  21. using wispro.sp.share;
  22. using wispro.sp.utility;
  23. namespace wispro.sp.api.Controllers
  24. {
  25. [Route("api/[controller]/[action]")]
  26. [ApiController]
  27. [Authorize]
  28. public class PerformanceItemController : ControllerBase
  29. {
  30. spDbContext Context;
  31. IFileTaskService fileTaskService;
  32. public PerformanceItemController(spDbContext context, IFileTaskService _fileTaskService)
  33. {
  34. Context = context;
  35. fileTaskService = _fileTaskService;
  36. }
  37. public ApiSaveResponse RemoveDBNotFinishDate(int year, int month)
  38. {
  39. ApiSaveResponse ret = new ApiSaveResponse();
  40. ret.Success = true;
  41. var itemList = Context.PerformanceItems.Include(p => p.ItemStaffs).Where(p => p.CalMonth.Year == year &&
  42. p.CalMonth.Month == month &&
  43. p.DoItem == "处理审查意见" &&
  44. p.FinishedDate == null);
  45. using var t = Context.Database.BeginTransaction();
  46. try
  47. {
  48. foreach (var item in itemList.ToList())
  49. {
  50. if (item != null)
  51. {
  52. Context.ItemStaffs.RemoveRange(item.ItemStaffs);
  53. Context.PerformanceItems.Remove(item);
  54. }
  55. }
  56. Context.SaveChanges();
  57. t.Commit();
  58. return ret;
  59. }
  60. catch (Exception ex)
  61. {
  62. t.Rollback();
  63. ret.Success = false;
  64. ret.ErrorMessage = ex.Message;
  65. return ret;
  66. }
  67. }
  68. public bool IsExist(PerformanceItem item)
  69. {
  70. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  71. x.CaseNo == item.CaseNo &&
  72. x.DoItem == item.DoItem &&
  73. x.CaseStage == item.CaseStage &&
  74. x.CalMonth.Year == item.CalMonth.Year &&
  75. x.CalMonth.Month == item.CalMonth.Month);
  76. if (results.Count() > 0)
  77. {
  78. return true;
  79. }
  80. else
  81. {
  82. return false;
  83. }
  84. }
  85. public ApiSaveResponse New(PerformanceItem item)
  86. {
  87. ApiSaveResponse ret = new ApiSaveResponse();
  88. ret.Success = true;
  89. using (Context.Database.BeginTransaction())
  90. {
  91. try
  92. {
  93. #region 已算绩效的案号只匹配案号前边的数字 20230310
  94. string[] strNos = item.CaseNo.Split(new char[] {'-'});
  95. string strNo = item.CaseNo;
  96. if(strNos.Length > 0 )
  97. {
  98. strNo = strNos[0];
  99. if(strNos.Length > 1)
  100. {
  101. if (strNos[1].ToUpper() == "TS")
  102. {
  103. strNo = $"{strNos[0]}-{strNos[1]}";
  104. }
  105. }
  106. }
  107. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  108. x.CaseNo.StartsWith(strNo) && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  109. if (item.DoItem.ToUpper() == "提交IDS")
  110. {
  111. //提交IDS 添加完成日期做完判断是否已算绩效的条件
  112. results = Context.PerformanceItems.Where<PerformanceItem>(x => x.CaseNo.StartsWith(strNo) && x.DoItem == item.DoItem && x.FinishedDate == item.FinishedDate);
  113. }
  114. #endregion
  115. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  116. if (items != null)
  117. {
  118. item.AgentFeedbackMemo = "已算绩效";
  119. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  120. item.BasePoint = 0;
  121. }
  122. if (item.CalMonth != null)
  123. {
  124. var calMonth = Context.CalMonths.Where<CalMonth>(c => c.Year == item.CalMonth.Year && c.Month == item.CalMonth.Month).FirstOrDefault();
  125. if (calMonth == null)
  126. {
  127. Context.CalMonths.Add(item.CalMonth);
  128. if (item.BasePoint > 0)
  129. {
  130. _calItemJX(item, Context);
  131. }
  132. else
  133. {
  134. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  135. Context.StaffStatistics.RemoveRange(oldJxList);
  136. }
  137. Context.SaveChanges();
  138. }
  139. else
  140. {
  141. item.CalMonth = calMonth;
  142. }
  143. item.CalMonthId = item.CalMonth.Id;
  144. item.CalMonth = null;
  145. }
  146. if (!string.IsNullOrEmpty(item.Customer.Name))
  147. {
  148. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  149. if (temCustomer == null)
  150. {
  151. temCustomer = new Customer() { Name = item.Customer.Name };
  152. //item.Customer.Id = 0;
  153. Context.Customers.Add(temCustomer);
  154. Context.SaveChanges();
  155. item.Customer = temCustomer;
  156. //item.CustomerId = item.Customer.Id;
  157. }
  158. else
  159. {
  160. item.Customer = temCustomer;
  161. }
  162. item.CustomerId = item.Customer.Id;
  163. item.Customer = null;
  164. }
  165. else
  166. {
  167. item.Customer = null;
  168. }
  169. var ItemStaffs = item.ItemStaffs;
  170. item.ItemStaffs = null;
  171. Context.PerformanceItems.Add(item);
  172. Context.SaveChanges();
  173. foreach (ItemStaff itemStaff in ItemStaffs)
  174. {
  175. itemStaff.ItemId = item.Id;
  176. itemStaff.Item = null;
  177. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  178. {
  179. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  180. if (temStaff != null)
  181. {
  182. itemStaff.DoPersonId = temStaff.Id;
  183. itemStaff.DoPerson = null;
  184. }
  185. else
  186. {
  187. Context.Staffs.Add(itemStaff.DoPerson);
  188. Context.SaveChanges();
  189. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  190. itemStaff.DoPerson = null;
  191. }
  192. }
  193. }
  194. Context.ItemStaffs.AddRange(ItemStaffs);
  195. Context.SaveChanges();
  196. Context.Database.CommitTransaction();
  197. }
  198. catch (Exception ex)
  199. {
  200. ret.Success = false;
  201. ret.ErrorMessage = ex.Message;
  202. Context.Database.RollbackTransaction();
  203. }
  204. }
  205. return ret;
  206. }
  207. /// <summary>
  208. /// 更新绩效记录信息
  209. /// </summary>
  210. /// <param name="id">绩效记录编号</param>
  211. /// <param name="field">栏位,多个位以|杠隔开</param>
  212. /// <param name="value">栏位值,多个以|杠隔开</param>
  213. /// <returns></returns>
  214. public ApiSaveResponse UpdateFieldValue(int id, string field, string value)
  215. {
  216. ApiSaveResponse ret = new ApiSaveResponse();
  217. ret.Success = true;
  218. var item = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.Id == id);
  219. if (item == null)
  220. {
  221. ret.Success = false;
  222. ret.ErrorMessage = $"不存在的{id}";
  223. return ret;
  224. }
  225. if (string.IsNullOrEmpty(field))
  226. {
  227. ret.Success = false;
  228. ret.ErrorMessage = $"参数不对!";
  229. return ret;
  230. }
  231. string[] fields = field.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  232. string[] values = new string[] { null };
  233. if (!string.IsNullOrEmpty(value))
  234. {
  235. values = value.Split(new char[] { '|' });
  236. }
  237. if (fields.Length != values.Length) {
  238. ret.Success = false;
  239. ret.ErrorMessage = "栏位和值对不匹配";
  240. }
  241. else
  242. {
  243. for (int i = 0; i < fields.Length; i++)
  244. {
  245. string temField = fields[i];
  246. string temValue = values[i];
  247. switch (temField)
  248. {
  249. case "AgentFeedbackMemo":
  250. item.AgentFeedbackMemo = temValue;
  251. break;
  252. case "CaseCoefficient":
  253. item.CaseCoefficient = temValue;
  254. //此处添加保存到流程系统的代码
  255. break;
  256. case "DoItemCoefficient":
  257. item.DoItemCoefficient = temValue;
  258. //此处添加保存到流程系统的代码
  259. break;
  260. case "WordCount":
  261. int wordCount;
  262. if (int.TryParse(temValue, out wordCount))
  263. {
  264. item.WordCount = wordCount;
  265. }
  266. else
  267. {
  268. item.WordCount = null;
  269. //ret.Success = false;
  270. //ret.ErrorMessage = "所给的栏位值不能转换成数字!";
  271. //return ret;
  272. }
  273. break;
  274. case "ReturnCasseNo":
  275. item.ReturnCasseNo = temValue;
  276. break;
  277. }
  278. }
  279. if (item.AgentFeedbackMemo != "特殊点数申诉")
  280. {
  281. Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
  282. if (item.BasePoint > 0)
  283. {
  284. _calItemJX(item, Context);
  285. }
  286. else
  287. {
  288. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  289. Context.StaffStatistics.RemoveRange(oldJxList);
  290. }
  291. Context.SaveChanges();
  292. }
  293. }
  294. return ret;
  295. }
  296. public ListApiResponse<PerformanceItem> Query(int pageIndex, int pageSize)
  297. {
  298. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  299. var results = Context.PerformanceItems
  300. .Where<PerformanceItem>(s =>
  301. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == User.Identity.Name).Count() > 0 || s.Reviewer.Name == User.Identity.Name)
  302. && s.CalMonth.Status != 4);
  303. ret.TotalCount = results.Count();
  304. List<PerformanceItem> retList = results
  305. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  306. .Include(pi => pi.Reviewer)
  307. .Include(pi => pi.Customer)
  308. .Include(pi => pi.CalMonth)
  309. .OrderByDescending(o => o.Id)
  310. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize).ToList<PerformanceItem>();
  311. #region 将某些属性设为null,避免循环取值造成返回json过大
  312. foreach (PerformanceItem item in retList)
  313. {
  314. foreach (ItemStaff itemStaff in item.ItemStaffs)
  315. {
  316. itemStaff.DoPerson.ItemStaffs = null;
  317. itemStaff.DoPerson.ReviewerItems = null;
  318. itemStaff.Item = null;
  319. }
  320. item.Reviewer.ReviewerItems = null;
  321. item.Reviewer.Customers = null;
  322. item.Reviewer.ItemStaffs = null;
  323. item.Customer.PerformanceItems = null;
  324. item.CalMonth.PerformanceItems = null;
  325. }
  326. #endregion
  327. ret.Results = retList;
  328. return ret;
  329. }
  330. public PerformanceItem Get(int Id)
  331. {
  332. var results = Context.PerformanceItems
  333. .Where<PerformanceItem>(s => s.Id == Id);
  334. PerformanceItem item = results
  335. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  336. .Include(pi => pi.Reviewer)
  337. .Include(pi => pi.Customer)
  338. .Include(pi => pi.CalMonth)
  339. .OrderByDescending(o => o.Id)
  340. .FirstOrDefault();
  341. #region 将某些属性设为null,避免循环取值造成返回json过大
  342. foreach (ItemStaff itemStaff in item.ItemStaffs)
  343. {
  344. itemStaff.DoPerson.ItemStaffs = null;
  345. itemStaff.DoPerson.ReviewerItems = null;
  346. itemStaff.Item = null;
  347. }
  348. if (item.Reviewer != null)
  349. {
  350. item.Reviewer.ReviewerItems = null;
  351. item.Reviewer.Customers = null;
  352. item.Reviewer.ItemStaffs = null;
  353. }
  354. item.Customer.PerformanceItems = null;
  355. item.CalMonth.PerformanceItems = null;
  356. #endregion
  357. return item;
  358. }
  359. /// <summary>
  360. /// 获取给定用户的绩效清单
  361. /// </summary>
  362. /// <param name="userid">用户id</param>
  363. /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
  364. /// <returns></returns>
  365. public ListApiResponse<PerformanceItem> GetMyList(int userid, int type, int pageIndex = 1, int pageSize = 10)
  366. {
  367. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  368. var results = Context.PerformanceItems
  369. .Where<PerformanceItem>(s =>
  370. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  371. && s.CalMonth.Status == type);
  372. ret.TotalCount = results.Count();
  373. List<PerformanceItem> retList = results
  374. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  375. .Include(pi => pi.Reviewer)
  376. .Include(pi => pi.Customer)
  377. .Include(pi => pi.CalMonth)
  378. .OrderByDescending(o => o.Id)
  379. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize)
  380. .ToList<PerformanceItem>();
  381. #region 将某些属性设为null,避免循环取值造成返回json过大
  382. foreach (PerformanceItem item in retList)
  383. {
  384. foreach (ItemStaff itemStaff in item.ItemStaffs)
  385. {
  386. itemStaff.DoPerson.ItemStaffs = null;
  387. itemStaff.DoPerson.ReviewerItems = null;
  388. itemStaff.Item = null;
  389. }
  390. item.Reviewer.ReviewerItems = null;
  391. item.Reviewer.Customers = null;
  392. item.Reviewer.ItemStaffs = null;
  393. item.Customer.PerformanceItems = null;
  394. item.CalMonth.PerformanceItems = null;
  395. }
  396. #endregion
  397. ret.Results = retList;
  398. return ret;
  399. }
  400. /// <summary>
  401. /// 获取个人难度系数
  402. /// </summary>
  403. /// <param name="calMonth">绩效月份</param>
  404. /// <param name="userId">用户Id</param>
  405. /// <param name="isReivewer">是否审核个人难度系数</param>
  406. /// <param name="HXqf">合写算0.5件</param>
  407. /// <returns></returns>
  408. private NanduStatics PersonNanduStatics(CalMonth calMonth, int userId, spDbContext spDb, bool isReivewer = false,bool HXqf=false)
  409. {
  410. NanduStatics retObj = new NanduStatics();
  411. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  412. var list = spDb.CaseCeoffcients;
  413. foreach (var cx in list.ToList<CaseCeoffcient>())
  414. {
  415. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  416. }
  417. string jxType = isReivewer ? "新申请审核" : "新申请处理";
  418. var results = spDb.StaffStatistics.Include(p => p.Item).Where(s => s.CalMonthId == calMonth.Id && s.jxType == jxType && s.StaffId == userId);
  419. if (!isReivewer)
  420. {
  421. results = spDb.StaffStatistics.Include(p => p.Item).Where(s => s.CalMonthId == calMonth.Id && (s.jxType == jxType || s.jxType == "专案处理") && s.StaffId == userId);
  422. }
  423. #region 循环计算
  424. decimal iCount = 0;
  425. decimal d = 0.0M;
  426. var retList = results.ToList();
  427. foreach (var item in retList)
  428. {
  429. if (item.Item != null)
  430. {
  431. //if(item.Item.CaseNo == "PACN2220066")
  432. //{
  433. // System.Diagnostics.Debug.WriteLine("");
  434. //}
  435. //合写人数
  436. decimal CaseNumber = 1M;
  437. if (item.Item.ItemStaffs.Count > 1 && !isReivewer )
  438. {
  439. if (item.Item .ItemStaffs == null)
  440. {
  441. item.Item .ItemStaffs = spDb.ItemStaffs.Include(p => p.DoPerson).Where(p => p.ItemId == item.ItemId).ToList();
  442. }
  443. try
  444. {
  445. CaseNumber = CaseNumber / (item.Item.ItemStaffs.Where(i => i.DoPerson.IsCalPerformsnce == true || (i.DoPerson.Status != "试用期" && i.DoPerson.IsCalPerformsnce == false)).Count());
  446. }
  447. catch { }
  448. }
  449. string strCaseCeoffcient = item.Item.CaseCoefficient;
  450. if (string.IsNullOrEmpty(strCaseCeoffcient))
  451. {
  452. strCaseCeoffcient = "B";
  453. }
  454. #region 严重延期降系数
  455. if (item.Item.isDanger() && string.IsNullOrEmpty(item.Item.OverDueMemo))
  456. {
  457. switch (item.Item.CaseCoefficient)
  458. {
  459. case "S":
  460. strCaseCeoffcient = "A";
  461. break;
  462. case "A":
  463. strCaseCeoffcient = "B";
  464. break;
  465. case "B":
  466. strCaseCeoffcient = "C";
  467. break;
  468. case "C":
  469. strCaseCeoffcient = "D";
  470. break;
  471. }
  472. }
  473. #endregion
  474. switch (strCaseCeoffcient)
  475. {
  476. case "S":
  477. if (item.Item.Type == "专案")
  478. {
  479. retObj.S += (decimal)item.totalBasePoint.Value;
  480. }
  481. else
  482. {
  483. retObj.S += CaseNumber;
  484. }
  485. break;
  486. case "A":
  487. if (item.Item.Type == "专案")
  488. {
  489. retObj.A += (decimal)item.totalBasePoint.Value;
  490. }
  491. else
  492. {
  493. retObj.A += CaseNumber;
  494. }
  495. break;
  496. case "B":
  497. if (item.Item.Type == "专案")
  498. {
  499. retObj.B += (decimal)item.totalBasePoint.Value;
  500. }
  501. else
  502. {
  503. retObj.B += CaseNumber;
  504. }
  505. break;
  506. case "C":
  507. if (item.Item.Type == "专案")
  508. {
  509. retObj.C += (decimal)item.totalBasePoint.Value;
  510. }
  511. else
  512. {
  513. retObj.C += CaseNumber;
  514. }
  515. break;
  516. case "D":
  517. if (item.Item.Type == "专案")
  518. {
  519. retObj.D += (decimal)item.totalBasePoint.Value;
  520. }
  521. else
  522. {
  523. retObj.D += CaseNumber;
  524. }
  525. break;
  526. default:
  527. if (item.Item.Type == "专案")
  528. {
  529. retObj.B += (decimal)item.totalBasePoint.Value;
  530. }
  531. else
  532. {
  533. retObj.B += CaseNumber;
  534. }
  535. break;
  536. }
  537. }
  538. }
  539. #endregion
  540. d = retObj.S * (decimal)CaseXiShu["S"] + retObj.A * (decimal)CaseXiShu["A"] + retObj.B * (decimal)CaseXiShu["B"] + retObj.C * (decimal)CaseXiShu["C"] + retObj.D * (decimal)CaseXiShu["D"];
  541. iCount = retObj.S + retObj.A + retObj.B + retObj.C + retObj.D;
  542. retObj.NanduXS =(double) (d / iCount);
  543. return retObj;
  544. }
  545. /// <summary>
  546. /// 获取总难度系数
  547. /// </summary>
  548. /// <param name="calMonth"></param>
  549. /// <returns></returns>
  550. private NanduStatics DegreeOfDifficulty(CalMonth calMonth, spDbContext spDb)
  551. {
  552. NanduStatics retObj = new NanduStatics();
  553. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  554. var list = spDb.CaseCeoffcients.ToList();
  555. foreach (var cx in list)
  556. {
  557. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  558. }
  559. //var results = spDb.PerformanceItems.Where<PerformanceItem>(p =>
  560. //p.CalMonthId == calMonth.Id &&
  561. //(p.Type == "新申请" || p.Type == "专案") && p.BasePoint > 0.0);
  562. var results = spDb.StaffStatistics
  563. .Where(p =>
  564. p.CalMonthId == calMonth.Id &&
  565. (p.Item.Type == "新申请" || p.Item.Type == "专案"))
  566. .Select(p => p.Item).Distinct();
  567. #region 循环计算
  568. var retList = results.ToList();
  569. foreach (var item in retList)
  570. {
  571. decimal CaseNumber = 1;
  572. if(item.ItemStaffs == null)
  573. {
  574. item.ItemStaffs = spDb.ItemStaffs.Include(p=>p.DoPerson).Where(p =>p.ItemId == item.Id).ToList();
  575. }
  576. if (item.ItemStaffs.Count > 1)
  577. {
  578. var i = item.ItemStaffs.Where(i => (i.DoPerson.Status != "试用期" && i.DoPerson.IsCalPerformsnce == false)).Count();
  579. if ( i> 0)
  580. {
  581. CaseNumber = CaseNumber *(item.ItemStaffs.Count-i)/item.ItemStaffs.Count;
  582. }
  583. }
  584. string strCaseCeoffcient = item.CaseCoefficient;
  585. if (string.IsNullOrEmpty(strCaseCeoffcient))
  586. {
  587. strCaseCeoffcient = "B";
  588. }
  589. #region 严重延期降系数
  590. if (item.isDanger() && string.IsNullOrEmpty(item.OverDueMemo))
  591. {
  592. switch (item.CaseCoefficient)
  593. {
  594. case "S":
  595. strCaseCeoffcient = "A";
  596. break;
  597. case "A":
  598. strCaseCeoffcient = "B";
  599. break;
  600. case "B":
  601. strCaseCeoffcient = "C";
  602. break;
  603. case "C":
  604. strCaseCeoffcient = "D";
  605. break;
  606. }
  607. }
  608. #endregion
  609. switch (strCaseCeoffcient)
  610. {
  611. case "S":
  612. if (item.Type == "专案")
  613. {
  614. retObj.S += (decimal)item.BasePoint.Value;
  615. }
  616. else
  617. {
  618. retObj.S += CaseNumber;
  619. }
  620. break;
  621. case "A":
  622. if (item.Type == "专案")
  623. {
  624. retObj.A += (decimal)item.BasePoint.Value;
  625. }
  626. else
  627. {
  628. retObj.A += CaseNumber;
  629. }
  630. break;
  631. case "B":
  632. if (item.Type == "专案")
  633. {
  634. retObj.B += (decimal)item.BasePoint.Value;
  635. }
  636. else
  637. {
  638. retObj.B += CaseNumber;
  639. }
  640. break;
  641. case "C":
  642. if (item.Type == "专案")
  643. {
  644. retObj.C += (decimal)item.BasePoint.Value;
  645. }
  646. else
  647. {
  648. retObj.C += CaseNumber;
  649. }
  650. break;
  651. case "D":
  652. if (item.Type == "专案")
  653. {
  654. retObj.D += (decimal)item.BasePoint.Value;
  655. }
  656. else
  657. {
  658. retObj.D += CaseNumber;
  659. }
  660. break;
  661. default:
  662. if (item.Type == "专案")
  663. {
  664. retObj.B += (decimal)item.BasePoint.Value;
  665. }
  666. else
  667. {
  668. retObj.B += CaseNumber;
  669. }
  670. break;
  671. }
  672. System.Diagnostics.Debug.WriteLine($"{item.CaseNo}\t{item.DoItem}\t{item.DoItemCoefficient}\t{item.WordCount}\t{strCaseCeoffcient}\t{item.CaseCoefficient}\t{item.BasePoint}");
  673. }
  674. #endregion
  675. var d = retObj.S * (decimal)CaseXiShu["S"] + retObj.A * (decimal)CaseXiShu["A"] + retObj.B * (decimal)CaseXiShu["B"] + retObj.C * (decimal)CaseXiShu["C"] + retObj.D * (decimal)CaseXiShu["D"];
  676. var iCount = retObj.S + retObj.A + retObj.B + retObj.C + retObj.D;
  677. retObj.NanduXS = (double)(d /iCount);
  678. return retObj;
  679. }
  680. public List<string> GetFeedbackString(int itemId)
  681. {
  682. PerformanceItem item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == itemId);
  683. if (item != null)
  684. {
  685. return Utility.Utility.GetFeedbackMemos(item, Context.BasePointRules.ToList());
  686. }
  687. return new List<string>();
  688. }
  689. public FileProcessTask GetStaticsReport(int Year,int Month)
  690. {
  691. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == Year && c.Month == Month);
  692. if (calMonth != null)
  693. {
  694. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}代理人全部考评维度绩效点数加和.xlsx";
  695. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  696. var filePath = Path.Combine(attachfileSavePath, filename);
  697. var fileTask = new FileProcessTask()
  698. {
  699. Id = Guid.NewGuid().ToString(),
  700. FileName = filename,
  701. FilePath = filePath,
  702. Processed = 0
  703. };
  704. fileTaskService.Add(fileTask);
  705. ExportDataResult result = new ExportDataResult()
  706. {
  707. fileTask = fileTask,
  708. calMonth = calMonth
  709. };
  710. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportStaticReport));
  711. t.Start(result);
  712. return fileTask;
  713. }
  714. return null;
  715. }
  716. private void ExportStaticReport(object exportDataResult)
  717. {
  718. ExportDataResult result = (ExportDataResult)exportDataResult;
  719. FileProcessTask file = result.fileTask;
  720. CalMonth calMonth = result.calMonth;
  721. //var StatisticsResults = _CalMyStatistics(calMonth);
  722. string strSQL = @"SELECT Staff.Name as 代理人,StaffGrade.Grade as 代理人等级,
  723. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '新申请处理' and CalMonthId = @CalMonthId ) as '新申请处理',
  724. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '新申请审核' and CalMonthId = @CalMonthId) as '新申请审核',
  725. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '专案处理' and CalMonthId = @CalMonthId) as '专案处理',
  726. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '专案审核' and CalMonthId = @CalMonthId) as '专案审核',
  727. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = 'OA处理' and CalMonthId = @CalMonthId) as OA处理,
  728. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = 'OA审核' and CalMonthId = @CalMonthId) as OA审核,
  729. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '其它处理' and CalMonthId = @CalMonthId) as 其它处理,
  730. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '其它审核' and CalMonthId = @CalMonthId) as 其它审核,
  731. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and CalMonthId = @CalMonthId) as 总计
  732. FROM[spDB].[dbo].[StaffStatistics] as A
  733. inner join Staff on Staff.Id = A.StaffId
  734. Left join StaffGrade on Staff.StaffGradeId = StaffGrade.Id
  735. where CalMonthId = @CalMonthId
  736. group by A.StaffId, Staff.Name,StaffGrade.Grade";
  737. DataTable dt = new DataTable();
  738. spDbContext spDb = new spDbContext();
  739. using (var conn = spDb.Database.GetDbConnection())
  740. {
  741. conn.Open();
  742. var cmd = conn.CreateCommand();
  743. cmd.CommandText = strSQL;
  744. cmd.CommandType = CommandType.Text;
  745. cmd.Parameters.Add(new SqlParameter("CalMonthId", calMonth.Id));
  746. using (var reader = cmd.ExecuteReader())
  747. {
  748. dt.Load(reader);
  749. }
  750. }
  751. NPOIExcel.DataTableToExcel(dt, result.fileTask.FilePath);
  752. result.fileTask.Finished = true;
  753. }
  754. private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
  755. {
  756. var retList = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
  757. if (userid != null)
  758. {
  759. retList = retList.Where(s => s.StaffId == userid);
  760. }
  761. var retData2 = retList.GroupBy(s => new { s.CalMonthId, s.StaffId, s.jxType })
  762. .Select(g => new
  763. {
  764. StaffId = g.Key.StaffId,
  765. CalMonthId = g.Key.CalMonthId,
  766. jxType = g.Key.jxType,
  767. FinianlPoint = g.Sum(s => s.FinianlPoint),
  768. totalBasePoint = g.Sum(s => s.totalBasePoint),
  769. totalActuallyPoint = g.Sum(s => s.totalActuallyPoint)
  770. });
  771. List<StaffStatistics> temList = new List<StaffStatistics>();
  772. foreach (var key in retData2)
  773. {
  774. temList.Add(new StaffStatistics()
  775. {
  776. StaffId = key.StaffId,
  777. CalMonthId = key.CalMonthId,
  778. jxType = key.jxType,
  779. totalBasePoint = key.totalBasePoint,
  780. totalActuallyPoint = key.totalActuallyPoint,
  781. FinianlPoint = key.FinianlPoint
  782. });
  783. }
  784. return temList;
  785. #region old code
  786. ////未归档,从绩效记录中统计数据
  787. //var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
  788. //if (userid != null)
  789. //{
  790. // results = Context.PerformanceItems.Where<PerformanceItem>(s =>
  791. // (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  792. // && s.CalMonth.Id == calMonth.Id);
  793. //}
  794. //List<PerformanceItem> ItemList = results
  795. // .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  796. // .Include(pi => pi.Reviewer).ThenInclude(p=>p.StaffGrade)
  797. // .Include(pi => pi.Customer)
  798. // .OrderByDescending(o => o.Id)
  799. // .ToList<PerformanceItem>();
  800. //List<StaffStatistics> retList = new List<StaffStatistics>();
  801. //List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  802. //var Rules = Context.BasePointRules.ToList();
  803. //foreach (PerformanceItem item in ItemList)
  804. //{
  805. // //if (item.BasePoint == null)
  806. // //{
  807. // if (item.AgentFeedbackMemo != "特殊点数申诉")
  808. // {
  809. // Utility.Utility.CalBasePoint(item, Rules);
  810. // Context.SaveChanges();
  811. // }
  812. // //}
  813. // if (item.BasePoint != null && item.BasePoint.Value > 0)
  814. // {
  815. // double doPersonBasePoint = item.BasePoint.Value;
  816. // List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
  817. // List<StaffStatistics> temItemStatics;
  818. // if (userid != null)
  819. // {
  820. // temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
  821. // }
  822. // else
  823. // {
  824. // temItemStatics = itemStatistics;
  825. // }
  826. // foreach (StaffStatistics retUserValue in temItemStatics)
  827. // {
  828. // var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
  829. // if (temValue != null)
  830. // {
  831. // temValue.totalBasePoint += retUserValue.totalBasePoint;
  832. // temValue.totalActuallyPoint += retUserValue.totalActuallyPoint;
  833. // }
  834. // else
  835. // {
  836. // retList.Add(retUserValue);
  837. // }
  838. // }
  839. // }
  840. //}
  841. //if (userid != null)
  842. //{
  843. // retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
  844. //}
  845. //return retList;
  846. #endregion
  847. }
  848. private void _RefreshBasePoint()
  849. {
  850. spDbContext spDb = new spDbContext();
  851. var calMonth = spDb.CalMonths.FirstOrDefault(c => c.Status == 0);
  852. _RefreshBasePoint(calMonth, spDb);
  853. StatisticsLevelCount(calMonth.Year, calMonth.Month);
  854. }
  855. private void _RefreshBasePoint(CalMonth calMonth, spDbContext spDb)
  856. {
  857. if (calMonth != null)
  858. {
  859. var lstItem = spDb.PerformanceItems
  860. .Include(p => p.Customer)
  861. .Include(p => p.ItemStaffs)
  862. .Include(p => p.Reviewer)
  863. .Include(p => p.CalMonth)
  864. .Where(p => p.CalMonthId == calMonth.Id).ToList();
  865. var rules = spDb.BasePointRules.ToList();
  866. foreach (var item in lstItem)
  867. {
  868. try
  869. {
  870. Utility.Utility.CalBasePoint(item, rules);
  871. if (item.BasePoint > 0)
  872. {
  873. _calItemJX(item, spDb);
  874. }
  875. else
  876. {
  877. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == item.Id);
  878. spDb.StaffStatistics.RemoveRange(oldJxList);
  879. }
  880. spDb.SaveChanges();
  881. }
  882. catch (Exception ex)
  883. {
  884. System.Diagnostics.Debug.WriteLine(ex.Message);
  885. }
  886. }
  887. _CalJXPoint(calMonth, spDb);
  888. }
  889. }
  890. public ApiSaveResponse RefreshBasePoint()
  891. {
  892. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  893. t.Start();
  894. return new ApiSaveResponse() {
  895. Success = true
  896. };
  897. }
  898. public void RefreshPoint(PerformanceItem item)
  899. {
  900. //spDbContext spDb = new spDbContext();
  901. var rules = Context.BasePointRules.ToList();
  902. if (item.AgentFeedbackMemo != "特殊点数申诉")
  903. {
  904. Utility.Utility.CalBasePoint(item, rules);
  905. if (item.BasePoint > 0)
  906. {
  907. _calItemJX(item, Context);
  908. }
  909. else
  910. {
  911. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  912. Context.StaffStatistics.RemoveRange(oldJxList);
  913. }
  914. Context.SaveChanges();
  915. }
  916. }
  917. public ApiSaveResponse RefreshFromIPEasyById(int itemId)
  918. {
  919. var Item = Context.PerformanceItems.Include(p => p.Customer).Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson).FirstOrDefault(p => p.Id == itemId);
  920. if (Item != null)
  921. {
  922. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  923. }
  924. Utility.Utility.CalBasePoint(Item, Context.BasePointRules.ToList());
  925. if (Item.BasePoint > 0)
  926. {
  927. _calItemJX(Item, Context);
  928. }
  929. else
  930. {
  931. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == Item.Id);
  932. Context.StaffStatistics.RemoveRange(oldJxList);
  933. }
  934. Context.SaveChanges();
  935. return new ApiSaveResponse()
  936. {
  937. Success = true
  938. };
  939. }
  940. public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
  941. {
  942. new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
  943. return new ApiSaveResponse()
  944. {
  945. Success = true
  946. };
  947. }
  948. public ApiSaveResponse RefreshFromIPEasy(string CaseNo, string DoItem, string caseStage)
  949. {
  950. var Item = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault(p => p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
  951. if (Item != null)
  952. {
  953. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  954. }
  955. return new ApiSaveResponse()
  956. {
  957. Success = true
  958. };
  959. }
  960. public ApiSaveResponse CompareExcel2DB()
  961. {
  962. System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
  963. t.Start();
  964. return new ApiSaveResponse()
  965. {
  966. Success = true
  967. };
  968. }
  969. public FileProcessTask CurrentData2Excel(int Year,int Month)
  970. {
  971. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == Year && c.Month == Month);
  972. if (calMonth != null)
  973. {
  974. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  975. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  976. var filePath = Path.Combine(attachfileSavePath, filename);
  977. var fileTask = new FileProcessTask()
  978. {
  979. Id = Guid.NewGuid().ToString(),
  980. FileName = filename,
  981. FilePath = filePath,
  982. Processed = 0
  983. };
  984. fileTaskService.Add(fileTask);
  985. ExportDataResult result = new ExportDataResult() {
  986. fileTask = fileTask,
  987. calMonth = calMonth
  988. };
  989. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(Export2ExcelThread));
  990. t.Start(result);
  991. return fileTask;
  992. }
  993. return null;
  994. }
  995. internal class ExportDataResult
  996. {
  997. public FileProcessTask fileTask { get; set; }
  998. public CalMonth calMonth { get; set; }
  999. }
  1000. private void Export2ExcelThread(object attfile)
  1001. {
  1002. ExportDataResult result = (ExportDataResult)attfile;
  1003. FileProcessTask file = result.fileTask;
  1004. spDbContext spDb = new spDbContext();
  1005. List<PerformanceItem> items = spDb.PerformanceItems
  1006. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  1007. .Include(p => p.PreOastaff)
  1008. .Include(p => p.Customer)
  1009. .Include(p => p.CalMonth)
  1010. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  1011. .Where(p => p.CalMonth.Id == result.calMonth.Id && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  1012. DataTable dt = new DataTable();
  1013. #region 栏位名称
  1014. dt.Columns.Add("我方文号", typeof(string));
  1015. dt.Columns.Add("申请类型", typeof(string));
  1016. dt.Columns.Add("业务类型", typeof(string));
  1017. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  1018. dt.Columns.Add("处理事项", typeof(string));
  1019. dt.Columns.Add("案件阶段", typeof(string));
  1020. dt.Columns.Add("案件系数", typeof(string));
  1021. dt.Columns.Add("处理事项系数", typeof(string));
  1022. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  1023. dt.Columns.Add("前一次OA处理人", typeof(string));
  1024. dt.Columns.Add("处理人等级", typeof(string));
  1025. dt.Columns.Add("基本点数", typeof(string));
  1026. dt.Columns.Add("核稿系数", typeof(string));
  1027. dt.Columns.Add("核稿绩效", typeof(string));
  1028. dt.Columns.Add("处理人", typeof(string));
  1029. dt.Columns.Add("核稿人", typeof(string));
  1030. dt.Columns.Add("客户名称", typeof(string));
  1031. dt.Columns.Add("申请人", typeof(string));
  1032. dt.Columns.Add("处理事项完成日", typeof(string));
  1033. dt.Columns.Add("定稿日", typeof(string));
  1034. dt.Columns.Add("返稿日", typeof(string));
  1035. dt.Columns.Add("案件类型", typeof(string));
  1036. dt.Columns.Add("案件状态", typeof(string));
  1037. dt.Columns.Add("处理事项备注", typeof(string));
  1038. dt.Columns.Add("处理状态", typeof(string));
  1039. dt.Columns.Add("案件名称", typeof(string));
  1040. dt.Columns.Add("委案日期", typeof(string));
  1041. dt.Columns.Add("客户期限", typeof(string));
  1042. dt.Columns.Add("内部期限", typeof(string));
  1043. dt.Columns.Add("初稿日", typeof(string));
  1044. dt.Columns.Add("翻译字数", typeof(string));
  1045. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因", typeof(string));
  1046. dt.Columns.Add("绩效类型", typeof(string));
  1047. dt.Columns.Add("案件备注", typeof(string));
  1048. dt.Columns.Add("处理人绩效系数", typeof(string));
  1049. dt.Columns.Add("系统核算绩效", typeof(string));
  1050. dt.Columns.Add("实际处理人", typeof(string));
  1051. #endregion
  1052. var verifyCeoffients = spDb.VerifyCoefficients.ToList();
  1053. var Rules = spDb.BasePointRules.ToList();
  1054. file.Size = items.Count;
  1055. foreach (var p in items)
  1056. {
  1057. List<ItemStaff> temItemStaffs = p.ItemStaffs.ToList();
  1058. string strCaseMemo = "";
  1059. string strHandler = "";
  1060. temItemStaffs = new List<ItemStaff>();
  1061. foreach (var iStaff in p.ItemStaffs)
  1062. {
  1063. strHandler = string.IsNullOrEmpty(strHandler) ? iStaff.DoPerson.Name : $"{strHandler},{iStaff.DoPerson.Name}";
  1064. if (iStaff.DoPerson.Status == "试用期")
  1065. {
  1066. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}在试用期" : $"{strCaseMemo},{iStaff.DoPerson.Name}在试用期";
  1067. }
  1068. else
  1069. {
  1070. if (!iStaff.DoPerson.IsCalPerformsnce)
  1071. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}不计算绩效" : $"{strCaseMemo},{iStaff.DoPerson.Name}不计算绩效";
  1072. }
  1073. if (iStaff.DoPersonId == p.ReviewerId)
  1074. {
  1075. strCaseMemo = String.IsNullOrEmpty(strCaseMemo) ? "核稿人与处理人相同" : $"{strCaseMemo},核稿人与处理人相同";
  1076. }
  1077. }
  1078. var staffStatics = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).Where(s => s.ItemId == p.Id && s.jxType.Contains("处理"));
  1079. var reviewStatic = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).FirstOrDefault(s => s.ItemId == p.Id && s.jxType.Contains("审核"));
  1080. foreach (var iStaff in staffStatics.ToList())
  1081. {
  1082. DataRow row = dt.NewRow();
  1083. row["我方文号"] = p.CaseNo;
  1084. row["申请类型"] = p.ApplicationType;
  1085. row["实际处理人"] = strHandler;
  1086. if (p.ApplicationName != null && p.ApplicationName.Contains("OPPO") && p.ApplicationType == "实用新型" && p.Type == "新申请")
  1087. {
  1088. row["申请类型"] = "发明";
  1089. row["案件备注"] = $"{row["案件备注"]}\r\n【OPPO案件实用新型修改为发明】";
  1090. }
  1091. row["处理事项"] = p.DoItem;
  1092. row["业务类型"] = p.BusinessType;
  1093. row["备注(填表注意事项)"] = p.AgentFeedbackMemo;
  1094. if (p.Type == "专案")
  1095. {
  1096. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]}【主管给定点数】专案";
  1097. row["处理事项"] = "提出报告";
  1098. }
  1099. if (p.ItemStaffs.Count() > 1)
  1100. {
  1101. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]},{strHandler}合写";
  1102. }
  1103. row["案件阶段"] = p.CaseStage;
  1104. row["案件系数"] = p.CaseCoefficient;
  1105. if (p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo) && p.Type == "新申请")
  1106. {
  1107. switch (p.CaseCoefficient)
  1108. {
  1109. case "S":
  1110. row["案件系数"] = "A";
  1111. break;
  1112. case "A":
  1113. row["案件系数"] = "B";
  1114. break;
  1115. case "B":
  1116. row["案件系数"] = "C";
  1117. break;
  1118. case "C":
  1119. row["案件系数"] = "D";
  1120. break;
  1121. }
  1122. row["案件备注"] = $"{row["案件备注"]}\r\n严重延期降系数【{p.CaseCoefficient}->{row["案件系数"]}】";
  1123. }
  1124. row["处理事项系数"] = p.DoItemCoefficient;
  1125. row["前一次OA处理事项系数"] = "";
  1126. row["前一次OA处理人"] = p.PreOastaff?.Name;
  1127. row["处理人"] = iStaff.Staff.Name;
  1128. row["基本点数"] = iStaff.totalBasePoint;
  1129. row["处理人等级"] = iStaff.Staff.StaffGrade.Grade;
  1130. row["处理人绩效系数"] = iStaff.Staff.StaffGrade.Coefficient;
  1131. if (reviewStatic != null)
  1132. {
  1133. row["核稿人"] = reviewStatic.Staff.Name;
  1134. var v = verifyCeoffients.FirstOrDefault(p => p.CheckerId == reviewStatic.Staff.StaffGradeId && p.DoPersonId == iStaff.Staff.StaffGradeId);
  1135. if (v != null)
  1136. {
  1137. row["核稿绩效"] = ((decimal)iStaff.totalBasePoint * (decimal)v.Coefficient);
  1138. row["核稿系数"] = v.Coefficient;
  1139. }
  1140. }
  1141. row["客户名称"] = p.Customer?.Name;
  1142. row["申请人"] = p.ApplicationName;
  1143. row["处理事项完成日"] = p.FinishedDate?.ToString("yyyy-MM-dd");
  1144. row["定稿日"] = p.FinalizationDate?.ToString("yyyy-MM-dd");
  1145. row["返稿日"] = p.ReturnDate?.ToString("yyyy-MM-dd");
  1146. row["案件类型"] = p.CaseType;
  1147. row["案件状态"] = p.CaseState;
  1148. row["处理事项备注"] = p.DoItemMemo;
  1149. row["处理状态"] = p.DoItemState;
  1150. row["案件名称"] = p.CaseName;
  1151. row["委案日期"] = p.EntrustingDate?.ToString("yyyy-MM-dd");
  1152. row["客户期限"] = p.CustomerLimitDate?.ToString("yyyy-MM-dd");
  1153. row["内部期限"] = p.InternalDate?.ToString("yyyy-MM-dd");
  1154. row["初稿日"] = p.FirstDraftDate?.ToString("yyyy-MM-dd");
  1155. row["翻译字数"] = p.WordCount;
  1156. row["备注(发文严重超期是否属客观原因,若为否,请填写原因"] = p.OverDueMemo;
  1157. row["绩效类型"] = p.Type;
  1158. row["案件备注"] = $"{p.CaseMemo}\r\n{row["案件备注"]}";
  1159. if (!string.IsNullOrEmpty(strCaseMemo))
  1160. {
  1161. row["案件备注"] = $"{strCaseMemo}\r\n{row["案件备注"]}";
  1162. }
  1163. dt.Rows.Add(row);
  1164. }
  1165. file.Processed += 1;
  1166. }
  1167. NPOIExcel.DataTableToExcel(dt, file.FilePath);
  1168. file.Finished = true;
  1169. }
  1170. private void _CompareExcel2DB()
  1171. {
  1172. DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0, 2);
  1173. DataTable retTable = new DataTable();
  1174. retTable.Columns.Add("我方文号");
  1175. retTable.Columns.Add("申请类型");
  1176. retTable.Columns.Add("业务类型");
  1177. retTable.Columns.Add("备注(填表注意事项)");
  1178. retTable.Columns.Add("备注(填表注意事项)【系统】");
  1179. retTable.Columns.Add("处理事项");
  1180. retTable.Columns.Add("处理事项【系统】");
  1181. retTable.Columns.Add("案件阶段");
  1182. retTable.Columns.Add("案件阶段【系统】");
  1183. retTable.Columns.Add("案件系数");
  1184. retTable.Columns.Add("案件系数【系统】");
  1185. retTable.Columns.Add("处理事项系数");
  1186. retTable.Columns.Add("处理事项系数【系统】");
  1187. retTable.Columns.Add("处理人等级");
  1188. retTable.Columns.Add("处理人等级【系统】");
  1189. retTable.Columns.Add("处理人系数");
  1190. retTable.Columns.Add("处理人系数【系统】");
  1191. retTable.Columns.Add("基本点数");
  1192. retTable.Columns.Add("基本点数【系统】");
  1193. retTable.Columns.Add("核稿系数");
  1194. retTable.Columns.Add("核稿系数【系统】");
  1195. retTable.Columns.Add("核稿绩效");
  1196. retTable.Columns.Add("核稿绩效【系统】");
  1197. retTable.Columns.Add("处理人");
  1198. retTable.Columns.Add("处理人【系统】");
  1199. retTable.Columns.Add("核稿人");
  1200. retTable.Columns.Add("核稿人【系统】");
  1201. retTable.Columns.Add("严重超期备注原因");
  1202. retTable.Columns.Add("严重超期备注原因【系统】");
  1203. retTable.Columns.Add("是否一致");
  1204. retTable.Columns.Add("不一致原因");
  1205. spDbContext spDb = new spDbContext();
  1206. List<PerformanceItem> items = spDb.PerformanceItems
  1207. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  1208. .Include(p => p.Customer)
  1209. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  1210. .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  1211. excelDT.DefaultView.Sort = "我方文号,处理事项";
  1212. DataTable temDt = excelDT.DefaultView.ToTable();
  1213. int iTable = 0;
  1214. int iList = 0;
  1215. CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p => p.Status == 0);
  1216. var verifyCoefficients = spDb.VerifyCoefficients.ToList();
  1217. var Rules = spDb.BasePointRules.ToList();
  1218. while (iTable < temDt.Rows.Count && iList < items.Count)
  1219. {
  1220. System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
  1221. DataRow row = temDt.Rows[iTable];
  1222. PerformanceItem item = items[iList];
  1223. if (row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString() == "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
  1224. {
  1225. var temRow = retTable.NewRow();
  1226. int iBegin = iTable;
  1227. int iEnd = iTable;
  1228. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1229. if (iEnd < temDt.Rows.Count - 1)
  1230. {
  1231. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1232. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1233. {
  1234. iEnd++;
  1235. }
  1236. }
  1237. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1238. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1239. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1240. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1241. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1242. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1243. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1244. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1245. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1246. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1247. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1248. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1249. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1250. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1251. for (int i = iBegin; i <= iEnd; i++)
  1252. {
  1253. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1254. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1255. temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
  1256. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1257. {
  1258. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1259. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1260. }
  1261. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1262. }
  1263. iTable = iEnd;
  1264. #endregion
  1265. Utility.Utility.CalBasePoint(item, Rules);
  1266. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1267. try
  1268. {
  1269. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1270. }
  1271. catch { }
  1272. temRow["案件阶段【系统】"] = item.CaseStage;
  1273. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1274. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1275. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1276. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1277. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1278. temRow["严重超期备注原因"] = item.OverDueMemo;
  1279. if (retPoints != null && retPoints.Count > 0)
  1280. {
  1281. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
  1282. foreach (var itemStaff in item.ItemStaffs)
  1283. {
  1284. //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1285. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1286. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1287. if (item.ReviewerId != null)
  1288. {
  1289. #region 取审核人等级审核等级系数
  1290. VerifyCoefficient vcoefficient
  1291. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1292. v.CheckerId == item.Reviewer.StaffGradeId
  1293. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1294. .FirstOrDefault<VerifyCoefficient>();
  1295. #endregion
  1296. if (vcoefficient != null)
  1297. {
  1298. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1299. }
  1300. }
  1301. }
  1302. }
  1303. temRow["是否一致"] = "";
  1304. temRow["不一致原因"] = "";
  1305. if (temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
  1306. {
  1307. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
  1308. }
  1309. if (temRow["案件系数【系统】"].ToString().Trim() != temRow["案件系数"].ToString().Trim())
  1310. {
  1311. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件系数" : $"{temRow["不一致原因"]},案件系数";
  1312. }
  1313. if (temRow["处理事项系数【系统】"].ToString().Trim() != temRow["处理事项系数"].ToString().Trim())
  1314. {
  1315. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "处理事项系数" : $"{temRow["不一致原因"]},处理事项系数";
  1316. }
  1317. if (temRow["核稿人【系统】"].ToString().Trim() != temRow["核稿人"].ToString().Trim())
  1318. {
  1319. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "核稿人" : $"{temRow["不一致原因"]},核稿人";
  1320. }
  1321. if (temRow["基本点数【系统】"].ToString().Trim() != temRow["基本点数"].ToString().Trim())
  1322. {
  1323. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "基本点数" : $"{temRow["不一致原因"]},基本点数";
  1324. }
  1325. if (temRow["严重超期备注原因【系统】"].ToString().Trim() != temRow["严重超期备注原因"].ToString().Trim())
  1326. {
  1327. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "严重超期备注原因" : $"{temRow["不一致原因"]},严重超期备注原因";
  1328. }
  1329. if (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
  1330. {
  1331. temRow["是否一致"] = "不一致";
  1332. }
  1333. retTable.Rows.Add(temRow);
  1334. iTable++;
  1335. iList++;
  1336. }
  1337. else
  1338. {
  1339. string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
  1340. string strList = $"{item.CaseNo}-{item.DoItem}";
  1341. if (strDT.CompareTo(strList) > 0)
  1342. {
  1343. var temRow = retTable.NewRow();
  1344. Utility.Utility.CalBasePoint(item, Rules);
  1345. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1346. try
  1347. {
  1348. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1349. }
  1350. catch { }
  1351. temRow["我方文号"] = item.CaseNo;
  1352. temRow["处理事项"] = item.DoItem;
  1353. temRow["申请类型"] = item.ApplicationType;
  1354. temRow["业务类型"] = item.BusinessType;
  1355. temRow["案件阶段【系统】"] = item.CaseStage;
  1356. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1357. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1358. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1359. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1360. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1361. temRow["严重超期备注原因"] = item.OverDueMemo;
  1362. if (item.ReviewerId != null)
  1363. {
  1364. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1365. }
  1366. foreach (var itemStaff in item.ItemStaffs)
  1367. {
  1368. //if (itemStaff.DoPerson.Status != "试用期")
  1369. //{
  1370. // if (retPoints != null && retPoints.Count > 0)
  1371. // {
  1372. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1373. // }
  1374. //}
  1375. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1376. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1377. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1378. if (item.ReviewerId != null)
  1379. {
  1380. #region 取审核人等级审核等级系数
  1381. VerifyCoefficient vcoefficient
  1382. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1383. v.CheckerId == item.Reviewer.StaffGradeId
  1384. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1385. .FirstOrDefault<VerifyCoefficient>();
  1386. #endregion
  1387. if (vcoefficient != null)
  1388. {
  1389. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1390. }
  1391. }
  1392. }
  1393. temRow["是否一致"] = "不一致";
  1394. temRow["不一致原因"] = "Excel中没有,系统中有";
  1395. retTable.Rows.Add(temRow);
  1396. iList++;
  1397. }
  1398. else
  1399. {
  1400. var temRow = retTable.NewRow();
  1401. int iBegin = iTable;
  1402. int iEnd = iTable;
  1403. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1404. if (iEnd < temDt.Rows.Count - 1)
  1405. {
  1406. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1407. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1408. {
  1409. iEnd++;
  1410. }
  1411. }
  1412. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1413. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1414. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1415. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1416. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1417. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1418. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1419. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1420. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1421. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1422. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1423. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1424. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1425. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1426. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1427. for (int i = iBegin + 1; i <= iEnd; i++)
  1428. {
  1429. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1430. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1431. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1432. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1433. {
  1434. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1435. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1436. }
  1437. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1438. }
  1439. iTable = iEnd;
  1440. #endregion
  1441. temRow["是否一致"] = "不一致";
  1442. temRow["不一致原因"] = "系统中没有,Excel中有";
  1443. retTable.Rows.Add(temRow);
  1444. iTable++;
  1445. }
  1446. }
  1447. }
  1448. if (iList <= items.Count)
  1449. {
  1450. while (iList < items.Count) {
  1451. var item = items[iList];
  1452. var temRow = retTable.NewRow();
  1453. Utility.Utility.CalBasePoint(item, Rules);
  1454. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1455. try
  1456. {
  1457. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1458. }
  1459. catch { }
  1460. temRow["我方文号"] = item.CaseNo;
  1461. temRow["处理事项"] = item.DoItem;
  1462. temRow["申请类型"] = item.ApplicationType;
  1463. temRow["业务类型"] = item.BusinessType;
  1464. temRow["案件阶段【系统】"] = item.CaseStage;
  1465. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1466. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1467. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1468. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1469. temRow["基本点数【系统】"] = "";// item.BasePoint?.ToString();
  1470. temRow["严重超期备注原因"] = item.OverDueMemo;
  1471. if (item.ReviewerId != null)
  1472. {
  1473. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1474. }
  1475. foreach (var itemStaff in item.ItemStaffs)
  1476. {
  1477. //if (itemStaff.DoPerson.Status != "试用期")
  1478. //{
  1479. // if (retPoints != null && retPoints.Count > 0)
  1480. // {
  1481. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1482. // }
  1483. //}
  1484. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1485. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1486. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1487. if (item.ReviewerId != null)
  1488. {
  1489. #region 取审核人等级审核等级系数
  1490. VerifyCoefficient vcoefficient
  1491. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1492. v.CheckerId == item.Reviewer.StaffGradeId
  1493. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1494. .FirstOrDefault<VerifyCoefficient>();
  1495. #endregion
  1496. if (vcoefficient != null)
  1497. {
  1498. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1499. }
  1500. }
  1501. }
  1502. temRow["是否一致"] = "不一致";
  1503. temRow["不一致原因"] = "Excel中没有,系统中有";
  1504. iList++;
  1505. retTable.Rows.Add(temRow);
  1506. }
  1507. }
  1508. else
  1509. {
  1510. while (iTable < temDt.Rows.Count)
  1511. {
  1512. var temRow = retTable.NewRow();
  1513. int iBegin = iTable;
  1514. int iEnd = iTable;
  1515. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1516. while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
  1517. temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
  1518. {
  1519. iEnd++;
  1520. }
  1521. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1522. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1523. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1524. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1525. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1526. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1527. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1528. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1529. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1530. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1531. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1532. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1533. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1534. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1535. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1536. for (int i = iBegin + 1; i <= iEnd; i++)
  1537. {
  1538. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1539. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1540. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1541. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1542. {
  1543. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1544. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1545. }
  1546. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["严重超期备注原因"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["严重超期备注原因"]}";
  1547. }
  1548. iTable = iEnd;
  1549. #endregion
  1550. temRow["是否一致"] = "不一致";
  1551. temRow["不一致原因"] = "系统中没有,Excel中有";
  1552. retTable.Rows.Add(temRow);
  1553. iTable++;
  1554. }
  1555. }
  1556. NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
  1557. }
  1558. public List<StaffStatistics> CalItemJX(int itemid)
  1559. {
  1560. var Item = Context.PerformanceItems.Include(p => p.CalMonth)
  1561. .Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson).ThenInclude(s => s.StaffGrade)
  1562. .Include(p => p.Reviewer)
  1563. .Include(p => p.Customer)
  1564. .FirstOrDefault(p => p.Id == itemid);
  1565. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  1566. return _calItemJX(verifyCoefficients, Item, Context);
  1567. }
  1568. private void _calItemJX(PerformanceItem Item, spDbContext spDb)
  1569. {
  1570. List<VerifyCoefficient> verifyCoefficients = spDb.VerifyCoefficients.ToList<VerifyCoefficient>();
  1571. var jxList = _calItemJX(verifyCoefficients, Item, spDb);
  1572. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == Item.Id);
  1573. spDb.StaffStatistics.RemoveRange(oldJxList);
  1574. spDb.SaveChanges();
  1575. foreach (var jx in jxList)
  1576. {
  1577. if (jx.totalBasePoint == 0)
  1578. {
  1579. continue;
  1580. }
  1581. jx.ItemId = Item.Id;
  1582. spDb.StaffStatistics.Add(jx);
  1583. spDb.SaveChanges();
  1584. }
  1585. }
  1586. /// <summary>
  1587. /// 序号 情况 处理逻辑
  1588. /// 1 处理人试用期算绩效 一人处理 正常算绩效给处理人
  1589. /// 2 处理人试用期不算绩效 一人处理 算给核稿人,如果没有核稿人,这条数据忽略
  1590. /// 3 处理人试用期算绩效 与人合写 合写人算绩效、与合写人一人一半
  1591. /// 4 处理人试用期不算绩效 与人合写 合写人算绩效、全部绩效算给合写人
  1592. /// 5 处理人试用期不算绩效 与人合写 合写人不算算绩效、这条数据忽略
  1593. /// 6 处理人试用期算绩效 与人合写 合写人不算绩效、试用期人员拿一半
  1594. /// 7 处理人不算绩效 一人处理 这条数据忽略
  1595. /// 8 处理人不算绩效 与人合写 合写人算绩效、合写人拿一半
  1596. /// 9 处理人不算绩效 与人合写 合写人不算绩效、这条数据忽略
  1597. /// </summary>
  1598. /// <param name="verifyCoefficients"></param>
  1599. /// <param name="item"></param>
  1600. /// <param name="spDb"></param>
  1601. /// <returns></returns>
  1602. private List<StaffStatistics> _calItemJX(List<VerifyCoefficient> verifyCoefficients, PerformanceItem item, spDbContext spDb)
  1603. {
  1604. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  1605. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  1606. if (item.ReviewerId != null && item.Reviewer == null)
  1607. {
  1608. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  1609. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  1610. }
  1611. List<ItemStaff> temIStaffs = new List<ItemStaff>();
  1612. #region 将试用期且不算绩效的人员从处理人清单中剔除
  1613. int syqUsers = 0;
  1614. foreach(var itemStaff in item.ItemStaffs)
  1615. {
  1616. if (itemStaff.DoPerson == null)
  1617. {
  1618. itemStaff.DoPerson = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == itemStaff.DoPersonId);
  1619. }
  1620. if(itemStaff.DoPerson.Status == "试用期" && !itemStaff.DoPerson.IsCalPerformsnce )
  1621. {
  1622. syqUsers += 1;
  1623. }
  1624. else
  1625. {
  1626. temIStaffs.Add(itemStaff);
  1627. }
  1628. }
  1629. #endregion
  1630. #region 处理人全部是试用期人员,则将核稿人当成处理人(处理人为试用期人)
  1631. if (syqUsers == item.ItemStaffs.Count)
  1632. {
  1633. if(item.Reviewer != null)
  1634. {
  1635. temIStaffs.Add(new ItemStaff() { DoPersonId = item.ReviewerId.Value, ItemId = item.Id });
  1636. }
  1637. }
  1638. #endregion
  1639. bool isPJFP = true;
  1640. double total = temIStaffs.Count();
  1641. if (total >1 && temIStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  1642. {
  1643. total = temIStaffs.Select(i => i.PerformancePoint.Value).Sum();
  1644. isPJFP = false;
  1645. }
  1646. foreach (ItemStaff itemStaff in temIStaffs)
  1647. {
  1648. if(itemStaff.DoPerson == null)
  1649. {
  1650. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  1651. }
  1652. if (itemStaff.DoPerson.IsCalPerformsnce)
  1653. {
  1654. #region 计算各处理人的绩效点数
  1655. double handlerBasePoint;
  1656. if (item.Type != "专案")
  1657. {
  1658. if (isPJFP)
  1659. {
  1660. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1661. }
  1662. else
  1663. {
  1664. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1665. }
  1666. }
  1667. else
  1668. {
  1669. if (itemStaff.PerformancePoint == null)
  1670. {
  1671. if (isPJFP)
  1672. {
  1673. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1674. }
  1675. else
  1676. {
  1677. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1678. }
  1679. }
  1680. else
  1681. {
  1682. if (item.ItemStaffs.Count == 1 && itemStaff.PerformancePoint == 0)
  1683. {
  1684. handlerBasePoint = item.BasePoint.Value;
  1685. }
  1686. else
  1687. {
  1688. handlerBasePoint = itemStaff.PerformancePoint.Value;
  1689. }
  1690. }
  1691. }
  1692. string handlerJxType = $"{item.Type}处理";
  1693. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
  1694. if (temStatic != null)
  1695. {
  1696. temStatic.totalBasePoint += handlerBasePoint;
  1697. if (item.Type == "OA" || item.Type == "新申请")
  1698. {
  1699. temStatic.totalActuallyPoint += (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient);
  1700. }
  1701. else
  1702. {
  1703. temStatic.totalActuallyPoint += handlerBasePoint;
  1704. }
  1705. }
  1706. else
  1707. {
  1708. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsCalPerformsnce)
  1709. {
  1710. if (item.Type == "OA" || item.Type == "新申请")
  1711. {
  1712. if (itemStaff.DoPerson.StaffGrade == null)
  1713. {
  1714. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s => s.Id == itemStaff.DoPerson.StaffGradeId);
  1715. }
  1716. temStatic = new StaffStatistics()
  1717. {
  1718. //CalMonth = calMonth,
  1719. CalMonthId = item.CalMonthId,
  1720. StaffId = itemStaff.DoPersonId,
  1721. totalActuallyPoint = (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient),
  1722. totalBasePoint = handlerBasePoint,
  1723. jxType = handlerJxType
  1724. };
  1725. itemStatistics.Add(temStatic);
  1726. }
  1727. else
  1728. {
  1729. temStatic = new StaffStatistics()
  1730. {
  1731. //CalMonth = calMonth,
  1732. CalMonthId = item.CalMonthId,
  1733. StaffId = itemStaff.DoPersonId,
  1734. totalBasePoint = handlerBasePoint,
  1735. totalActuallyPoint = handlerBasePoint,
  1736. jxType = handlerJxType
  1737. };
  1738. itemStatistics.Add(temStatic);
  1739. }
  1740. }
  1741. }
  1742. #endregion
  1743. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  1744. if (item.ReviewerId != null && item.Type != "专案" &&
  1745. temIStaffs.FirstOrDefault(s => s.DoPersonId == item.ReviewerId) == null)
  1746. {
  1747. if(item.Reviewer == null)
  1748. {
  1749. item.Reviewer = spDb.Staffs.FirstOrDefault(s=>s.Id == item.ReviewerId);
  1750. }
  1751. if (item.Reviewer.IsCalPerformsnce)
  1752. {
  1753. #region 取审核人等级审核等级系数
  1754. VerifyCoefficient vcoefficient
  1755. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1756. v.CheckerId == item.Reviewer.StaffGradeId
  1757. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1758. .FirstOrDefault<VerifyCoefficient>();
  1759. #endregion
  1760. if (vcoefficient != null)
  1761. {
  1762. double reviewerBasePoint = (double)((decimal)handlerBasePoint * (decimal)vcoefficient.Coefficient);
  1763. string temJxType = $"{item.Type}审核";
  1764. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonthId == item.CalMonthId).FirstOrDefault();
  1765. if (temReviewerStatic != null)
  1766. {
  1767. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  1768. temReviewerStatic.totalActuallyPoint += reviewerBasePoint;
  1769. }
  1770. else
  1771. {
  1772. if (itemStaff.DoPerson.Status != "试用期" && item.Reviewer.IsCalPerformsnce) //判断是否在职
  1773. {
  1774. temReviewerStatic = new StaffStatistics()
  1775. {
  1776. CalMonthId = item.CalMonthId,
  1777. StaffId = item.ReviewerId.Value,
  1778. totalBasePoint = reviewerBasePoint,
  1779. totalActuallyPoint = reviewerBasePoint,
  1780. jxType = temJxType
  1781. };
  1782. itemStatistics.Add(temReviewerStatic);
  1783. }
  1784. }
  1785. }
  1786. }
  1787. }
  1788. #endregion
  1789. }
  1790. }
  1791. return itemStatistics;
  1792. }
  1793. private void _CalJXPoint(CalMonth calMonth,spDbContext spDb)
  1794. {
  1795. NanduStatics gspjXS = DegreeOfDifficulty(calMonth,spDb);
  1796. calMonth.NanduXS = gspjXS.NanduXS;
  1797. calMonth.S = (double)gspjXS.S;
  1798. calMonth.A = (double)gspjXS.A;
  1799. calMonth.B = (double)gspjXS.B;
  1800. calMonth.C = (double)gspjXS.C;
  1801. calMonth.D = (double)gspjXS.D;
  1802. var retList = spDb.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id).ToList();
  1803. #region 新申请处理+专案处理 奖励点数
  1804. double jlPoint = 0;
  1805. if (calMonth.S.HasValue)
  1806. {
  1807. jlPoint = jlPoint + (calMonth.S.Value * 1.5);
  1808. }
  1809. if (calMonth.A.HasValue)
  1810. {
  1811. jlPoint = jlPoint + (calMonth.A.Value * 0.5);
  1812. }
  1813. #endregion
  1814. #region 难度系数
  1815. IDictionary<int, NanduStatics> staffXiShu = new Dictionary<int, NanduStatics>();
  1816. IDictionary<int, NanduStatics> ReivewerXiShu = new Dictionary<int, NanduStatics>();
  1817. foreach (StaffStatistics ss in retList)
  1818. {
  1819. if (ss.jxType == "新申请处理" || ss.jxType == "专案处理")
  1820. {
  1821. #region 新申请处理+专案处理
  1822. if (!staffXiShu.ContainsKey(ss.StaffId))
  1823. {
  1824. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb,false,true);
  1825. staffXiShu.Add(ss.StaffId, nandu);
  1826. }
  1827. ss.FinianlPoint = ss.totalActuallyPoint * staffXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1828. ss.NanduXS = staffXiShu[ss.StaffId].NanduXS;
  1829. ss.S = (double)staffXiShu[ss.StaffId].S;
  1830. ss.A = (double)staffXiShu[ss.StaffId].A;
  1831. ss.B = (double)staffXiShu[ss.StaffId].B;
  1832. ss.C = (double)staffXiShu[ss.StaffId].C;
  1833. ss.D = (double)staffXiShu[ss.StaffId].D;
  1834. #endregion
  1835. }
  1836. else
  1837. {
  1838. if (ss.jxType == "新申请审核")
  1839. {
  1840. if (!ReivewerXiShu.ContainsKey(ss.StaffId))
  1841. {
  1842. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb, true);
  1843. ReivewerXiShu.Add(ss.StaffId, nandu);
  1844. }
  1845. ss.FinianlPoint = ss.totalBasePoint * ReivewerXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1846. ss.NanduXS = ReivewerXiShu[ss.StaffId].NanduXS;
  1847. ss.S = (double)ReivewerXiShu[ss.StaffId].S;
  1848. ss.A = (double)ReivewerXiShu[ss.StaffId].A;
  1849. ss.B = (double)ReivewerXiShu[ss.StaffId].B;
  1850. ss.C = (double)ReivewerXiShu[ss.StaffId].C;
  1851. ss.D = (double)ReivewerXiShu[ss.StaffId].D;
  1852. spDb.SaveChanges();
  1853. }
  1854. else
  1855. {
  1856. ss.FinianlPoint = ss.totalActuallyPoint;
  1857. spDb.SaveChanges();
  1858. }
  1859. }
  1860. }
  1861. var xsqList = retList.Where(ss => ss.jxType == "新申请处理" || ss.jxType == "专案处理").ToList();
  1862. var totalFPBLPoint = xsqList.Sum(p=>p.FinianlPoint); //新申请处理+专案 分配比率总点数
  1863. var totalActionPoint = xsqList.Sum(p=>p.totalActuallyPoint); //新申请处理+专案 原始总点数
  1864. foreach (StaffStatistics ss in xsqList)
  1865. {
  1866. ss.FinianlPoint = ss.FinianlPoint / totalFPBLPoint * (totalActionPoint + jlPoint);
  1867. spDb.SaveChanges();
  1868. }
  1869. #endregion
  1870. }
  1871. public void CalJXPoint(int year, int month)
  1872. {
  1873. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1874. if (calMonth != null)
  1875. {
  1876. using (var t = Context.Database.BeginTransaction())
  1877. {
  1878. try
  1879. {
  1880. var result = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
  1881. Context.StaffStatistics.RemoveRange(result);
  1882. var itemList = Context.PerformanceItems
  1883. .Include(s => s.ItemStaffs)
  1884. .Include(p=>p.Customer)
  1885. .Include(p=>p.Reviewer)
  1886. .Where(s => s.CalMonthId == calMonth.Id).ToList();
  1887. var rules = Context.BasePointRules.ToList();
  1888. foreach (var item in itemList)
  1889. {
  1890. Utility.Utility.CalBasePoint(item, rules);
  1891. Context.SaveChanges();
  1892. if (item.BasePoint > 0)
  1893. {
  1894. _calItemJX(item,Context);
  1895. }
  1896. else
  1897. {
  1898. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  1899. Context.StaffStatistics.RemoveRange(oldJxList);
  1900. }
  1901. }
  1902. _CalJXPoint(calMonth, Context);
  1903. t.Commit();
  1904. }
  1905. catch (Exception ex)
  1906. {
  1907. t.Rollback();
  1908. }
  1909. }
  1910. }
  1911. }
  1912. public ProcessTask FinishedCalMonth(int year,int month)
  1913. {
  1914. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == year && c.Month == month);
  1915. if (calMonth != null)
  1916. {
  1917. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  1918. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  1919. var filePath = Path.Combine(attachfileSavePath, filename);
  1920. var fileTask = new FileProcessTask()
  1921. {
  1922. Id = Guid.NewGuid().ToString(),
  1923. FileName = filename,
  1924. FilePath = filePath,
  1925. Processed = 0
  1926. };
  1927. fileTaskService.Add(fileTask);
  1928. ExportDataResult result = new ExportDataResult()
  1929. {
  1930. fileTask = fileTask,
  1931. calMonth = calMonth
  1932. };
  1933. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(_FinishedCalMonth));
  1934. t.Start(result);
  1935. return fileTask;
  1936. }
  1937. return null;
  1938. }
  1939. /// <summary>
  1940. /// 新申请/专案:
  1941. /// 调整点数 = 分配比例点数/分配比例点数之和*总点数
  1942. /// 等级调整点数+项目组点数之和 = 基础点数 * 代理人等级系数 + 项目组案件调整点数
  1943. /// 分配比例点数 = 个人平均难度系数 / 总平均难度系数 *(等级调整点数+项目组点数之和)
  1944. /// 总点数=等级调整点数+项目组点数之和+奖励点数
  1945. /// 奖励点数= S案数量*1.5 + A案数量 * 0.5
  1946. /// 难度系数=(S案数量*2.5 + A案数量* 1.5 + B案数量*1.0 + C案数量*0.7+ D案数量*0.4) / 总案件数量
  1947. /// 总案件数量= S案数量 + A案数量 + B案数量 + C案数量+ D案数量
  1948. /// OA :
  1949. /// 调整点数= 基础点数 * 等级系数
  1950. /// 其他:
  1951. /// 直接加和基础点数 不需要乘以系数
  1952. /// </summary>
  1953. /// <param name="year"></param>
  1954. /// <param name="month"></param>
  1955. /// <returns></returns>
  1956. private void _FinishedCalMonth(object proecssTask)
  1957. {
  1958. ExportDataResult result = (ExportDataResult)proecssTask;
  1959. CalMonth calMonth = result.calMonth;
  1960. if (calMonth != null || calMonth.Status !=4)
  1961. {
  1962. spDbContext spDb = new spDbContext();
  1963. calMonth = spDb.CalMonths.FirstOrDefault(c=>c.Id == calMonth.Id);
  1964. using (var t = spDb.Database.BeginTransaction())
  1965. {
  1966. try
  1967. {
  1968. _RefreshBasePoint(calMonth, spDb);
  1969. //_CalJXPoint(calMonth, Context);
  1970. calMonth.Status = 4;
  1971. spDb.SaveChanges();
  1972. //等级核算案件统计
  1973. _StatisticsLevelCount(calMonth.Year, calMonth.Month, spDb);
  1974. #region 将待审核的申诉全部修改为已审核
  1975. var aList = spDb.AppealRecords.Where(a => a.State == 0).ToList();
  1976. aList.ForEach(a =>a.State = 1);
  1977. spDb.SaveChanges();
  1978. #endregion
  1979. t.Commit();
  1980. result.fileTask.Finished = true;
  1981. }
  1982. catch (Exception ex)
  1983. {
  1984. t.Rollback();
  1985. result.fileTask.ErrorMessage = ex.Message;
  1986. result.fileTask.Finished = true;
  1987. }
  1988. }
  1989. }
  1990. else
  1991. {
  1992. result.fileTask.ErrorMessage = "指定月份没有数据或者已归档!";
  1993. result.fileTask.Finished = true;
  1994. }
  1995. }
  1996. /// <summary>
  1997. /// 计算指定用户,指定年月的绩效统计信息
  1998. /// </summary>
  1999. /// <param name="userid"></param>
  2000. /// <param name="year"></param>
  2001. /// <param name="month"></param>
  2002. /// <returns></returns>
  2003. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  2004. {
  2005. //object retList;
  2006. //string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
  2007. //if(!MyMemoryCache.TryGetValue(strKey,out retList))
  2008. //{
  2009. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  2010. if (calMonth == null)
  2011. {
  2012. return null;
  2013. }
  2014. else
  2015. {
  2016. return _CalMyStatistics(calMonth, userid);
  2017. #region old code
  2018. //if (calMonth.Status == 4)
  2019. //{
  2020. // //已归档,归档数据库中直接取出记录
  2021. // if (userid == null)
  2022. // {
  2023. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  2024. // }
  2025. // else
  2026. // {
  2027. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  2028. // }
  2029. //}
  2030. //else
  2031. //{
  2032. // try
  2033. // {
  2034. // retList = _CalMyStatistics(calMonth, userid);
  2035. // }
  2036. // catch(Exception ex)
  2037. // {
  2038. // StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  2039. // sw.WriteLine($"{ex.Message}");
  2040. // sw.Flush();
  2041. // sw.Close();
  2042. // sw.Dispose();
  2043. // }
  2044. //}
  2045. //// Set cache options.
  2046. //var cacheEntryOptions = new MemoryCacheEntryOptions()
  2047. // // Keep in cache for this time, reset time if accessed.
  2048. // .SetSlidingExpiration(TimeSpan.FromHours(1));
  2049. //foreach(var temObj in (List<StaffStatistics>)retList)
  2050. //{
  2051. // temObj.CalMonth.PerformanceItems = null;
  2052. //}
  2053. //// Save data in cache.
  2054. //MyMemoryCache.SetValue(strKey, retList);
  2055. //return (List<StaffStatistics>)retList;
  2056. #endregion
  2057. }
  2058. //}
  2059. //else
  2060. //{
  2061. // var temList = (List<StaffStatistics>)retList;
  2062. // foreach (var temObj in temList)
  2063. // {
  2064. // temObj.CalMonth.PerformanceItems = null;
  2065. // }
  2066. // return temList;
  2067. //}
  2068. }
  2069. private string GetExpress(IList<FieldCondition> conditions)
  2070. {
  2071. string str = "";
  2072. foreach(var c in conditions)
  2073. {
  2074. if (string.IsNullOrEmpty(str))
  2075. {
  2076. str = c.ToExpressString("s");
  2077. }
  2078. else
  2079. {
  2080. if(c.LogicOperate == LogicEnum.And)
  2081. {
  2082. str = $"({str}) && {c.ToExpressString("s")}";
  2083. }
  2084. else
  2085. {
  2086. str = $"({str}) || {c.ToExpressString("s")}";
  2087. }
  2088. }
  2089. }
  2090. return str;
  2091. }
  2092. [HttpGet,HttpPost]
  2093. public FileProcessTask ExportData(QueryFilter queryFilter)
  2094. {
  2095. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  2096. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  2097. var filePath = Path.Combine(attachfileSavePath, filename);
  2098. var fileTask = new FileProcessTask()
  2099. {
  2100. Id = Guid.NewGuid().ToString(),
  2101. FileName = filename,
  2102. FilePath = filePath,
  2103. Processed = 0
  2104. };
  2105. fileTaskService.Add(fileTask);
  2106. ThreadObject threadObject = new ThreadObject()
  2107. {
  2108. queryFilter = queryFilter,
  2109. fileTask = fileTask
  2110. };
  2111. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  2112. t.Start(threadObject);
  2113. return fileTask;
  2114. }
  2115. internal class ThreadObject
  2116. {
  2117. public QueryFilter queryFilter { get; set; }
  2118. public FileProcessTask fileTask { get; set; }
  2119. }
  2120. private void ExportDataThread(object tObj)
  2121. {
  2122. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  2123. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  2124. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2125. var retList = response
  2126. .Include(p=>p.Customer)
  2127. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  2128. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  2129. .Include(p=>p.PreOastaff)
  2130. .Include(p=>p.CalMonth)
  2131. .ToList<PerformanceItem>();
  2132. DataTable dt = new DataTable();
  2133. #region 添加栏位
  2134. dt.Columns.Add("我方文号",typeof(string));
  2135. dt.Columns.Add("申请类型", typeof(string));
  2136. dt.Columns.Add("业务类型", typeof(string));
  2137. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  2138. dt.Columns.Add("处理事项", typeof(string));
  2139. dt.Columns.Add("案件阶段", typeof(string));
  2140. dt.Columns.Add("案件系数", typeof(string));
  2141. dt.Columns.Add("处理事项系数", typeof(string));
  2142. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  2143. dt.Columns.Add("前一次OA处理人", typeof(string));
  2144. dt.Columns.Add("处理人等级", typeof(string));
  2145. dt.Columns.Add("基本点数", typeof(string));
  2146. dt.Columns.Add("核稿系数", typeof(string));
  2147. dt.Columns.Add("核稿绩效", typeof(string));
  2148. dt.Columns.Add("处理人", typeof(string));
  2149. dt.Columns.Add("核稿人", typeof(string));
  2150. dt.Columns.Add("客户名称", typeof(string));
  2151. dt.Columns.Add("申请人", typeof(string));
  2152. dt.Columns.Add("处理事项完成日", typeof(string));
  2153. dt.Columns.Add("定稿日", typeof(string));
  2154. dt.Columns.Add("返稿日", typeof(string));
  2155. dt.Columns.Add("案件类型", typeof(string));
  2156. dt.Columns.Add("案件状态", typeof(string));
  2157. dt.Columns.Add("处理事项备注", typeof(string));
  2158. dt.Columns.Add("处理状态", typeof(string));
  2159. dt.Columns.Add("案件名称", typeof(string));
  2160. dt.Columns.Add("委案日期", typeof(string));
  2161. dt.Columns.Add("客户期限", typeof(string));
  2162. dt.Columns.Add("内部期限", typeof(string));
  2163. dt.Columns.Add("初稿日", typeof(string));
  2164. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
  2165. dt.Columns.Add("备注", typeof(string));
  2166. #endregion
  2167. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  2168. fileTask.Size = retList.Count;
  2169. foreach (var item in retList)
  2170. {
  2171. fileTask.Processed += 1;
  2172. if (item.CaseNo.StartsWith("J"))
  2173. {
  2174. continue;
  2175. }
  2176. try
  2177. {
  2178. var row = dt.NewRow();
  2179. row["我方文号"] = item.CaseNo;
  2180. row["申请类型"] = item.ApplicationType;
  2181. row["业务类型"] = item.BusinessType;
  2182. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  2183. row["处理事项"] = item.DoItem;
  2184. row["案件阶段"] = item.CaseStage;
  2185. row["案件系数"] = item.CaseCoefficient;
  2186. row["处理事项系数"] = item.DoItemCoefficient;
  2187. row["前一次OA处理事项系数"] = "";
  2188. if (item.PreOastaffId.HasValue)
  2189. {
  2190. row["前一次OA处理人"] = item.PreOastaff?.Name;
  2191. }
  2192. string strISLevels = "";
  2193. string strISNames = "";
  2194. foreach (var istaff in item.ItemStaffs)
  2195. {
  2196. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  2197. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  2198. }
  2199. row["处理人等级"] = strISLevels;
  2200. row["基本点数"] = item.BasePoint;
  2201. row["处理人"] = strISNames;
  2202. row["核稿人"] = item.Reviewer?.Name;
  2203. if (item.ReviewerId != null && item.BasePoint.HasValue)
  2204. {
  2205. System.Diagnostics.Debug.WriteLine($"{item.ReviewerId}");
  2206. var jxList = new spDbContext().StaffStatistics.Where<StaffStatistics>(s => s.ItemId == item.Id).ToList();//_calItemJX( verifyCoefficients, item, new spDbContext());
  2207. row["核稿系数"] = "";
  2208. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  2209. if (temJx != null)
  2210. {
  2211. row["核稿绩效"] = temJx.totalBasePoint;
  2212. }
  2213. }
  2214. row["客户名称"] = item.Customer?.Name;
  2215. row["申请人"] = item.ApplicationName;
  2216. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  2217. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  2218. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  2219. row["案件类型"] = item.CaseType;
  2220. row["案件状态"] = item.CaseState;
  2221. row["处理事项备注"] = item.DoItemState;
  2222. row["处理状态"] = item.DoItemState;
  2223. row["案件名称"] = item.CaseName;
  2224. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  2225. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  2226. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  2227. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  2228. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  2229. row["备注"] = item.DoItemMemo;
  2230. dt.Rows.Add(row);
  2231. }
  2232. catch(Exception ex)
  2233. {
  2234. throw ex;
  2235. }
  2236. }
  2237. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  2238. fileTask.Finished = true;
  2239. }
  2240. [HttpPost]
  2241. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  2242. {
  2243. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  2244. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2245. int totals = response.ToList<PerformanceItem>().Count;
  2246. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  2247. {
  2248. response = response
  2249. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2250. .Include(pi => pi.Reviewer)
  2251. .Include(pi => pi.Customer)
  2252. .Include(pi => pi.CalMonth)
  2253. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2254. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  2255. }
  2256. else
  2257. {
  2258. response = response
  2259. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2260. .Include(pi => pi.Reviewer)
  2261. .Include(pi => pi.Customer)
  2262. .Include(pi => pi.CalMonth)
  2263. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2264. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  2265. }
  2266. ret.TotalCount = totals;
  2267. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  2268. #region 将某些属性设为null,避免循环取值造成返回json过大
  2269. foreach (PerformanceItem item in retList)
  2270. {
  2271. foreach (ItemStaff itemStaff in item.ItemStaffs)
  2272. {
  2273. itemStaff.DoPerson.ItemStaffs = null;
  2274. itemStaff.DoPerson.ReviewerItems = null;
  2275. itemStaff.DoPerson.Customers = null;
  2276. itemStaff.Item = null;
  2277. }
  2278. if (item.Reviewer != null)
  2279. {
  2280. item.Reviewer.ReviewerItems = null;
  2281. item.Reviewer.Customers = null;
  2282. item.Reviewer.ItemStaffs = null;
  2283. }
  2284. if (item.WorkflowUser != null)
  2285. {
  2286. item.WorkflowUser.ReviewerItems = null;
  2287. item.WorkflowUser.Customers = null;
  2288. item.WorkflowUser.ItemStaffs = null;
  2289. }
  2290. if (item.Customer != null)
  2291. {
  2292. item.Customer.PerformanceItems = null;
  2293. item.Customer.ResponseMan = null;
  2294. }
  2295. if (item.CalMonth != null)
  2296. {
  2297. item.CalMonth.PerformanceItems = null;
  2298. }
  2299. }
  2300. #endregion
  2301. ret.Results = retList.ToList();
  2302. //string str= System.Text.Json.JsonSerializer.Serialize(ret);
  2303. return ret;
  2304. }
  2305. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  2306. {
  2307. string strExpress = "";
  2308. string strCalMonth = "";
  2309. if (queryFilter.CalMonthId.HasValue)
  2310. {
  2311. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  2312. }
  2313. else
  2314. {
  2315. if(queryFilter.jxType == jxType.finished)
  2316. {
  2317. strCalMonth = $"s.CalMonth.Status == 4";
  2318. }
  2319. else
  2320. {
  2321. strCalMonth = $"s.CalMonth.Status != 4";
  2322. }
  2323. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  2324. }
  2325. if (!string.IsNullOrEmpty(strExpress))
  2326. {
  2327. strExpress = $"{strExpress} && {strCalMonth}";
  2328. }
  2329. else
  2330. {
  2331. strExpress = strCalMonth;
  2332. }
  2333. if (queryFilter.ConditionTree != null)
  2334. {
  2335. string strTem = GetExpress(queryFilter.ConditionTree);
  2336. if (!string.IsNullOrEmpty(strTem))
  2337. {
  2338. strExpress = $"{strExpress} && ({strTem})";
  2339. }
  2340. }
  2341. var interpreter = new Interpreter();
  2342. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  2343. IQueryable<PerformanceItem> response;
  2344. if (queryFilter.userId > 0)
  2345. {
  2346. if (queryFilter.DoingOrReview == 0)
  2347. {
  2348. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  2349. }
  2350. else
  2351. {
  2352. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  2353. }
  2354. }
  2355. else
  2356. {
  2357. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  2358. }
  2359. return response;
  2360. }
  2361. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  2362. {
  2363. ApiSaveResponse retResponse = new ApiSaveResponse();
  2364. retResponse.Success = true;
  2365. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  2366. {
  2367. using (var t = Context.Database.BeginTransaction())
  2368. {
  2369. try
  2370. {
  2371. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  2372. if (calMonth == null)
  2373. {
  2374. retResponse.Success = false;
  2375. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  2376. return retResponse;
  2377. }
  2378. else
  2379. {
  2380. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  2381. projectContents.ProjectContentRecord.CalMonth = null;
  2382. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  2383. projectContents.ProjectContentRecord.StaffId = staff.Id;
  2384. projectContents.ProjectContentRecord.State = 0;
  2385. }
  2386. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  2387. if (project != null)
  2388. {
  2389. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  2390. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  2391. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  2392. if(pRecord != null)
  2393. {
  2394. retResponse.Success = false;
  2395. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  2396. return retResponse;
  2397. }
  2398. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  2399. foreach (var doItem in projectContents.ProjectWorkContents)
  2400. {
  2401. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  2402. Context.ProjectWorkContents.Add(doItem);
  2403. }
  2404. t.Commit();
  2405. }
  2406. else
  2407. {
  2408. retResponse.Success = false;
  2409. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  2410. return retResponse;
  2411. }
  2412. }
  2413. catch (Exception ex)
  2414. {
  2415. retResponse.Success = false;
  2416. retResponse.ErrorMessage = ex.Message;
  2417. t.Rollback();
  2418. return retResponse;
  2419. }
  2420. }
  2421. }
  2422. return retResponse;
  2423. }
  2424. public PerformanceItem GetCaseInfo(string CaseNo)
  2425. {
  2426. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  2427. if(retObj == null)
  2428. {
  2429. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  2430. }
  2431. return retObj;
  2432. }
  2433. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  2434. {
  2435. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  2436. if (retObj == null)
  2437. {
  2438. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  2439. }
  2440. return retObj;
  2441. }
  2442. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage,bool UpdateFromIPEasy=true)
  2443. {
  2444. var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2445. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  2446. if (retObj == null || UpdateFromIPEasy)
  2447. {
  2448. var temObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(
  2449. new PerformanceItem() {CaseNo =CaseNo,DoItem =DoItem,CaseStage = caseStage },
  2450. Context
  2451. );// IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  2452. System.Dynamic.ExpandoObject temExpandoObject = (System.Dynamic.ExpandoObject)temObj;
  2453. retObj = new PerformanceItem();
  2454. retObj.CaseNo = temObj.CaseNo.ToString();
  2455. retObj.CaseName = temObj.CaseName.ToString();
  2456. try
  2457. {
  2458. if (temObj.ApplicationType != null)
  2459. retObj.ApplicationType = temObj.ApplicationType.ToString();
  2460. if (temObj.CaseMemo != null)
  2461. retObj.CaseMemo = temObj.CaseMemo.ToString();
  2462. if (temObj.BusinessType != null)
  2463. retObj.BusinessType = temObj.BusinessType.ToString();
  2464. if (temObj.DoItem != null)
  2465. retObj.DoItem = temObj.DoItem.ToString();
  2466. if (temObj.CaseStage != null)
  2467. retObj.CaseStage = temObj.CaseStage.ToString();
  2468. if (temObj.CaseType != null)
  2469. retObj.CaseType = temObj.CaseType.ToString();
  2470. if (temObj.DoItemState != null)
  2471. retObj.DoItemState = temObj.DoItemState.ToString();
  2472. if (temObj.DoItemCoefficient != null)
  2473. retObj.DoItemCoefficient = temObj.DoItemCoefficient.ToString();
  2474. if (temObj.CaseCoefficient != null)
  2475. retObj.CaseCoefficient = temObj.CaseCoefficient.ToString();
  2476. if (temObj.EntrustingDate != null)
  2477. {
  2478. if (!string.IsNullOrEmpty(temObj.EntrustingDate.ToString()))
  2479. retObj.EntrustingDate = DateTime.Parse(temObj.EntrustingDate.ToString());
  2480. }
  2481. if(temObj.Country != null)
  2482. {
  2483. retObj.Country = temObj.Country.ToString();
  2484. }
  2485. if (temObj.InternalDate != null)
  2486. {
  2487. if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
  2488. retObj.InternalDate = DateTime.Parse(temObj.InternalDate.ToString());
  2489. }
  2490. if (temObj.CustomerLimitDate != null)
  2491. {
  2492. if (!string.IsNullOrEmpty(temObj.CustomerLimitDate.ToString()))
  2493. retObj.CustomerLimitDate = DateTime.Parse(temObj.CustomerLimitDate.ToString());
  2494. }
  2495. if (temObj.ReturnDate != null)
  2496. {
  2497. if (!string.IsNullOrEmpty(temObj.ReturnDate.ToString()))
  2498. retObj.ReturnDate = DateTime.Parse(temObj.ReturnDate.ToString());
  2499. }
  2500. if (temObj.FinalizationDate != null)
  2501. {
  2502. if (!string.IsNullOrEmpty(temObj.FinalizationDate.ToString()))
  2503. retObj.FinalizationDate = DateTime.Parse(temObj.FinalizationDate.ToString());
  2504. }
  2505. if (temObj.FinishedDate != null)
  2506. {
  2507. if (!string.IsNullOrEmpty(temObj.FinishedDate.ToString()))
  2508. retObj.FinishedDate = DateTime.Parse(temObj.FinishedDate.ToString());
  2509. }
  2510. }
  2511. catch { }
  2512. int temWordCount;
  2513. if (temObj.WordCount != null)
  2514. {
  2515. if (int.TryParse(temObj.WordCount, out temWordCount))
  2516. {
  2517. retObj.WordCount = temWordCount;
  2518. }
  2519. }
  2520. try
  2521. {
  2522. if (temObj.CustomerName != null)
  2523. {
  2524. string strCustomer = temObj.CustomerName.ToString();
  2525. retObj.Customer = new Customer() { Name = strCustomer };
  2526. var temCustomer = Context.Customers.Where(c => c.Name == strCustomer.Trim()).FirstOrDefault();
  2527. if (temCustomer != null)
  2528. {
  2529. retObj.CustomerId = temCustomer.Id;
  2530. }
  2531. }
  2532. }
  2533. catch { }
  2534. try
  2535. {
  2536. if (temObj.Reviewer != null)
  2537. {
  2538. string strReViewer = temObj.Reviewer.ToString().Replace("-君龙", "");
  2539. var temReviewer = Context.Staffs.Where(s => s.Name == strReViewer.Trim()).FirstOrDefault();
  2540. if (temReviewer != null)
  2541. {
  2542. retObj.ReviewerId = temReviewer.Id;
  2543. }
  2544. }
  2545. }
  2546. catch { }
  2547. try
  2548. {
  2549. if (temObj.WorkflowUser != null)
  2550. {
  2551. string strWorkflowUser = temObj.WorkflowUser.ToString().Replace("-君龙", "");
  2552. var temReviewer = Context.Staffs.Where(s => s.Name == strWorkflowUser.Trim()).FirstOrDefault();
  2553. if (temReviewer != null)
  2554. {
  2555. retObj.WorkflowUserId = temReviewer.Id;
  2556. }
  2557. }
  2558. }
  2559. catch { }
  2560. if (temObj.DoPersons != null)
  2561. {
  2562. string DoPersons = temObj.DoPersons.ToString();
  2563. string[] Persons = DoPersons.Split(new char[] { ',' });
  2564. List<ItemStaff> itemStaffs = new List<ItemStaff>();
  2565. foreach (var doPerson in Persons)
  2566. {
  2567. string strName = doPerson.Replace("-君龙","");
  2568. itemStaffs.Add(new ItemStaff() { DoPerson = new Staff() { Name = strName } });
  2569. }
  2570. retObj.ItemStaffs = itemStaffs;
  2571. }
  2572. }
  2573. return retObj;
  2574. }
  2575. public PerformanceItem GetItemInfoByMonthId(string CaseNo, string DoItem, string caseStage,int calMonthId)
  2576. {
  2577. var retObj = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2578. && p.DoItem == DoItem.Trim() && p.CalMonthId == calMonthId);
  2579. if(retObj != null)
  2580. {
  2581. if(string.IsNullOrEmpty (retObj.CaseStage) && string.IsNullOrEmpty(caseStage))
  2582. {
  2583. return retObj;
  2584. }
  2585. else
  2586. {
  2587. if(retObj.CaseStage == caseStage)
  2588. {
  2589. return retObj;
  2590. }
  2591. else
  2592. {
  2593. return null;
  2594. }
  2595. }
  2596. }
  2597. else
  2598. {
  2599. return null;
  2600. }
  2601. }
  2602. public bool MovePerformance2ProjectInfo()
  2603. {
  2604. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  2605. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  2606. var pList = response.ToList<PerformanceItem>();
  2607. foreach(var p in pList)
  2608. {
  2609. ProjectInfo project = new ProjectInfo();
  2610. project.CaseNo = p.CaseNo;
  2611. project.CaseName = p.CaseName;
  2612. project.CaseState = 0;
  2613. project.CaseType = p.CaseType;
  2614. project.CustomerId = p.CustomerId;
  2615. project.ReviewerId = p.ReviewerId;
  2616. Context.ProjectInfos.Add(project);
  2617. foreach(ItemStaff iStaff in p.ItemStaffs)
  2618. {
  2619. Context.ItemStaffs.Remove(iStaff);
  2620. }
  2621. Context.PerformanceItems.Remove(p);
  2622. Context.SaveChanges();
  2623. }
  2624. return true;
  2625. }
  2626. #region 等级考核计算
  2627. /// <summary>
  2628. /// 等级考核案件量统计
  2629. /// </summary>
  2630. /// <param name="calMonthId"></param>
  2631. /// <returns></returns>
  2632. private List<StaffStatisticsforLevel> StatisticsCount(int calMonthId,spDbContext spDb )
  2633. {
  2634. var retlist = new List<StaffStatisticsforLevel>();
  2635. #region 新申请
  2636. var newList = spDb.PerformanceItems.Include(p => p.ItemStaffs).ThenInclude(p=>p.DoPerson)
  2637. .Include(p=>p.CalMonth)
  2638. .Where(p=>p.CalMonthId == calMonthId && p.BasePoint >0
  2639. && (p.Type =="新申请" || p.Type =="专案" || (p.Type == "其它" && p.WordCount >0 && (p.DoItem =="新申请" || p.DoItem == "翻译")))
  2640. ).ToList();
  2641. foreach(var p in newList)
  2642. {
  2643. #region 严重延期降系数
  2644. string strCaseCeoffcient = p.CaseCoefficient;
  2645. if (string.IsNullOrEmpty(strCaseCeoffcient))
  2646. {
  2647. strCaseCeoffcient = "B";
  2648. }
  2649. if (p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo))
  2650. {
  2651. switch (p.CaseCoefficient)
  2652. {
  2653. case "S":
  2654. strCaseCeoffcient = "A";
  2655. break;
  2656. case "A":
  2657. strCaseCeoffcient = "B";
  2658. break;
  2659. case "B":
  2660. strCaseCeoffcient = "C";
  2661. break;
  2662. case "C":
  2663. strCaseCeoffcient = "D";
  2664. break;
  2665. }
  2666. }
  2667. #endregion
  2668. var pointList = spDb.StaffStatistics.Include(i=>i.Staff).Where(i=>i.ItemId == p.Id).ToList();
  2669. #region 新申请处理
  2670. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2671. int doPersons = doList.Count();
  2672. if (p.ItemStaffs.Count() > doList.Count())
  2673. {
  2674. doPersons = p.ItemStaffs.Count;
  2675. foreach (ItemStaff itemStaff in p.ItemStaffs)
  2676. {
  2677. Staff staff = itemStaff.DoPerson;
  2678. if (staff == null)
  2679. {
  2680. staff = spDb.Staffs.FirstOrDefault(s => s.Id == itemStaff.DoPersonId);
  2681. }
  2682. if (staff.Status == "试用期")
  2683. {
  2684. doPersons =doPersons- 1;
  2685. }
  2686. }
  2687. }
  2688. if(doPersons >0)
  2689. {
  2690. //System.Diagnostics.Debug.WriteLine("");
  2691. foreach(var h in doList)
  2692. {
  2693. var temObj = retlist.FirstOrDefault(s=>s.StaffId == h.StaffId && s.Type == "新申请" && s.isReview == false);
  2694. if(temObj == null)
  2695. {
  2696. temObj = new StaffStatisticsforLevel();
  2697. temObj.StaffId = h.StaffId;
  2698. temObj.GradeId = h.Staff.StaffGradeId.Value ;
  2699. if(temObj.GradeId == 0)
  2700. {
  2701. System.Diagnostics.Debug.WriteLine("");
  2702. }
  2703. temObj.CalMonthId = p.CalMonthId;
  2704. temObj.Type = "新申请";
  2705. retlist.Add(temObj);
  2706. }
  2707. switch (strCaseCeoffcient)
  2708. {
  2709. case "S":
  2710. if(p.Type == "专案")
  2711. {
  2712. temObj.S += h.totalBasePoint.Value;
  2713. }
  2714. else
  2715. {
  2716. temObj.S+=(double)(1.0M/ (decimal)doPersons);
  2717. }
  2718. break;
  2719. case "A":
  2720. if (p.Type == "专案")
  2721. {
  2722. temObj.A += h.totalBasePoint.Value;
  2723. }
  2724. else
  2725. {
  2726. temObj.A += (double)(1.0M / (decimal)doPersons);
  2727. }
  2728. break;
  2729. case "B":
  2730. if (p.Type == "专案")
  2731. {
  2732. temObj.B += h.totalBasePoint.Value;
  2733. }
  2734. else
  2735. {
  2736. temObj.B += (double)(1.0M / (decimal)doPersons);
  2737. }
  2738. break;
  2739. case "C":
  2740. if (p.Type == "专案")
  2741. {
  2742. temObj.C += h.totalBasePoint.Value;
  2743. }
  2744. else
  2745. {
  2746. temObj.C += (double)(1.0M / (decimal)doPersons);
  2747. }
  2748. break;
  2749. case "D":
  2750. if (p.Type == "专案")
  2751. {
  2752. temObj.D += h.totalBasePoint.Value;
  2753. }
  2754. else
  2755. {
  2756. temObj.D += (double)(1.0M / (decimal)doPersons);
  2757. }
  2758. break;
  2759. }
  2760. }
  2761. }
  2762. #endregion
  2763. #region 新申请审核
  2764. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2765. if(reviewer != null)
  2766. {
  2767. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "新申请" && s.isReview == true);
  2768. if(temObj == null)
  2769. {
  2770. temObj = new StaffStatisticsforLevel();
  2771. temObj.StaffId = reviewer.StaffId;
  2772. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2773. if (temObj.GradeId == 0)
  2774. {
  2775. System.Diagnostics.Debug.WriteLine("");
  2776. }
  2777. temObj.CalMonthId = p.CalMonthId;
  2778. temObj.Type = "新申请";
  2779. temObj.isReview = true;
  2780. retlist.Add(temObj);
  2781. }
  2782. switch (strCaseCeoffcient)
  2783. {
  2784. case "S":
  2785. temObj.S += 1;
  2786. break;
  2787. case "A":
  2788. temObj.A += 1;
  2789. break;
  2790. case "B":
  2791. temObj.B += 1;
  2792. break;
  2793. case "C":
  2794. temObj.C += 1;
  2795. break;
  2796. case "D":
  2797. temObj.D += 1;
  2798. break;
  2799. }
  2800. }
  2801. #endregion
  2802. }
  2803. #endregion
  2804. #region 国内OA
  2805. var cnOA = spDb.PerformanceItems.Include(x=>x.ItemStaffs)
  2806. .Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && x.CaseNo.Contains("CN") && x.BasePoint > 0.3
  2807. ).ToList();
  2808. //因为不是所有的OA案件都是答复审查意见,所以有些应该没有一通或首次转入信息,去掉这个条件:
  2809. //&& (x.CaseStage == "一通" || x.DoItemCoefficient.Contains("首次转入"))
  2810. foreach (var p in cnOA)
  2811. {
  2812. var pointList = spDb.StaffStatistics.Include(i => i.Staff).Where(i=> i.ItemId == p.Id).ToList();
  2813. #region 国内OA处理
  2814. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2815. foreach (var h in doList)
  2816. {
  2817. var temObj = retlist.FirstOrDefault(s => s.StaffId == h.StaffId && s.Type == "国内OA" && s.isReview == false);
  2818. if (temObj == null)
  2819. {
  2820. temObj = new StaffStatisticsforLevel();
  2821. temObj.StaffId = h.StaffId;
  2822. temObj.GradeId = h.Staff.StaffGradeId.Value ;
  2823. if (temObj.GradeId == 0)
  2824. {
  2825. System.Diagnostics.Debug.WriteLine("");
  2826. }
  2827. temObj.CalMonthId = p.CalMonthId;
  2828. temObj.Type = "国内OA";
  2829. retlist.Add(temObj);
  2830. }
  2831. switch (p.CaseCoefficient)
  2832. {
  2833. case "S":
  2834. temObj.S += (double)(1.0M / (decimal)doList.Count());
  2835. break;
  2836. case "A":
  2837. temObj.A += (double)(1.0M / (decimal)doList.Count());
  2838. break;
  2839. case "B":
  2840. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2841. break;
  2842. case "C":
  2843. temObj.C += (double)(1.0M / (decimal)doList.Count());
  2844. break;
  2845. case "D":
  2846. temObj.D += (double)(1.0M / (decimal)doList.Count());
  2847. break;
  2848. default:
  2849. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2850. break;
  2851. }
  2852. }
  2853. #endregion
  2854. #region 国内OA审核
  2855. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2856. if (reviewer != null)
  2857. {
  2858. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "国内OA" && s.isReview == true);
  2859. if (temObj == null)
  2860. {
  2861. temObj = new StaffStatisticsforLevel();
  2862. temObj.StaffId = reviewer.StaffId;
  2863. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2864. if (temObj.GradeId == 0)
  2865. {
  2866. System.Diagnostics.Debug.WriteLine("");
  2867. }
  2868. temObj.CalMonthId = p.CalMonthId;
  2869. temObj.Type = "国内OA";
  2870. temObj.isReview = true;
  2871. retlist.Add(temObj);
  2872. }
  2873. switch (p.CaseCoefficient)
  2874. {
  2875. case "S":
  2876. temObj.S += 1;
  2877. break;
  2878. case "A":
  2879. temObj.A += 1;
  2880. break;
  2881. case "B":
  2882. temObj.B += 1;
  2883. break;
  2884. case "C":
  2885. temObj.C += 1;
  2886. break;
  2887. case "D":
  2888. temObj.D += 1;
  2889. break;
  2890. }
  2891. }
  2892. #endregion
  2893. }
  2894. #endregion
  2895. #region 涉外OA
  2896. var gwOA = spDb.PerformanceItems.Include(x => x.ItemStaffs)
  2897. .Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && !x.CaseNo.Contains("CN") && x.BasePoint>0.5
  2898. && (x.DoItemCoefficient.Contains("实质"))).ToList();
  2899. foreach (var p in gwOA)
  2900. {
  2901. var pointList = spDb.StaffStatistics.Include(i => i.Staff).Where(i => i.ItemId == p.Id).ToList();
  2902. #region 涉外OA处理
  2903. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2904. foreach (var h in doList)
  2905. {
  2906. var temObj = retlist.FirstOrDefault(s => s.StaffId == h.StaffId && s.Type == "涉外OA" && s.isReview == false);
  2907. if (temObj == null)
  2908. {
  2909. temObj = new StaffStatisticsforLevel();
  2910. temObj.StaffId = h.StaffId;
  2911. temObj.GradeId = h.Staff.StaffGradeId.Value;
  2912. if (temObj.GradeId == 0)
  2913. {
  2914. System.Diagnostics.Debug.WriteLine("");
  2915. }
  2916. temObj.CalMonthId = p.CalMonthId;
  2917. temObj.Type = "涉外OA";
  2918. retlist.Add(temObj);
  2919. }
  2920. switch (p.CaseCoefficient)
  2921. {
  2922. case "S":
  2923. temObj.S += (double)(1.0M / (decimal)doList.Count());
  2924. break;
  2925. case "A":
  2926. temObj.A += (double)(1.0M / (decimal)doList.Count());
  2927. break;
  2928. case "B":
  2929. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2930. break;
  2931. case "C":
  2932. temObj.C += (double)(1.0M / (decimal)doList.Count());
  2933. break;
  2934. case "D":
  2935. temObj.D += (double)(1.0M / (decimal)doList.Count());
  2936. break;
  2937. default:
  2938. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2939. break;
  2940. }
  2941. }
  2942. #endregion
  2943. #region 涉外OA审核
  2944. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2945. if (reviewer != null)
  2946. {
  2947. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "涉外OA" && s.isReview == true);
  2948. if (temObj == null)
  2949. {
  2950. temObj = new StaffStatisticsforLevel();
  2951. temObj.StaffId = reviewer.StaffId;
  2952. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2953. if (temObj.GradeId == 0)
  2954. {
  2955. System.Diagnostics.Debug.WriteLine("");
  2956. }
  2957. temObj.CalMonthId = calMonthId;
  2958. temObj.Type = "涉外OA";
  2959. temObj.isReview = true;
  2960. retlist.Add(temObj);
  2961. }
  2962. switch (p.CaseCoefficient)
  2963. {
  2964. case "S":
  2965. temObj.S += 1;
  2966. break;
  2967. case "A":
  2968. temObj.A += 1;
  2969. break;
  2970. case "B":
  2971. temObj.B += 1;
  2972. break;
  2973. case "C":
  2974. temObj.C += 1;
  2975. break;
  2976. case "D":
  2977. temObj.D += 1;
  2978. break;
  2979. default:
  2980. temObj.C += 1;
  2981. break;
  2982. }
  2983. }
  2984. #endregion
  2985. }
  2986. #endregion
  2987. return retlist;
  2988. }
  2989. /// <summary>
  2990. /// 指定等级人员等级考核案件量统计汇总
  2991. /// </summary>
  2992. /// <param name="levelCaseCounts"></param>
  2993. /// <param name="GradeCode"></param>
  2994. /// <param name="calReviw"></param>
  2995. /// <returns></returns>
  2996. private LevelStatisticsResult CalLevelStatistics(List<StaffStatisticsforLevel> levelCaseCounts,string GradeCode,bool calReviw)
  2997. {
  2998. var retList = new List<LevelStatistics>();
  2999. var temList = levelCaseCounts.Where(x=>x.Grade.Grade.StartsWith(GradeCode)).ToList();
  3000. foreach (var s in temList)
  3001. {
  3002. var temObj = retList.FirstOrDefault(i=>i.StaffId == s.StaffId);
  3003. if(temObj == null)
  3004. {
  3005. temObj = new LevelStatistics();
  3006. temObj.StaffId = s.StaffId;
  3007. temObj.StaffName = s.Staff.Name;
  3008. temObj.Grade = s.Grade.Grade;
  3009. //var Department = Context.DepartmentPositions.FirstOrDefault(x => x.StaffId == s.StaffId);
  3010. temObj.Department = Context.DepartmentPositions.Include(x => x.department).FirstOrDefault(x => x.StaffId == s.StaffId)?.department.Name;
  3011. retList.Add(temObj);
  3012. }
  3013. if (!s.isReview)
  3014. {
  3015. if(s.Type == "国内OA")
  3016. {
  3017. temObj.dS += (double)((decimal)s.S / 2M);
  3018. temObj.dA += (double)((decimal)s.A / 2M);
  3019. temObj.dB += (double)((decimal)s.B / 2M);
  3020. temObj.dC += (double)((decimal)s.C / 2M);
  3021. temObj.dD += (double)((decimal)s.D / 2M);
  3022. }
  3023. else
  3024. {
  3025. temObj.dS += s.S;
  3026. temObj.dA += s.A;
  3027. temObj.dB += s.B;
  3028. temObj.dC += s.C;
  3029. temObj.dD += s.D;
  3030. }
  3031. }
  3032. else
  3033. {
  3034. if (calReviw)
  3035. {
  3036. if (s.Type == "国内OA")
  3037. {
  3038. temObj.vS += (double)((decimal)s.S / 2M);
  3039. temObj.vA += (double)((decimal)s.A / 2M);
  3040. temObj.vB += (double)((decimal)s.B / 2M);
  3041. temObj.vC += (double)((decimal)s.C / 2M);
  3042. temObj.vD += (double)((decimal)s.D / 2M);
  3043. }
  3044. else
  3045. {
  3046. temObj.vS += s.S;
  3047. temObj.vA += s.A;
  3048. temObj.vB += s.B;
  3049. temObj.vC += s.C;
  3050. temObj.vD += s.D;
  3051. }
  3052. }
  3053. }
  3054. }
  3055. return new LevelStatisticsResult() {Grade =GradeCode , Statistics = retList};
  3056. }
  3057. /// /// <summary>
  3058. /// 获取季度等级考核结果
  3059. /// </summary>
  3060. /// <param name="year">考核年度</param>
  3061. /// <param name="quarter">考核季度,取值为1、2、3、4</param>
  3062. /// <param name="GradeCode">等级</param>
  3063. /// <returns></returns>
  3064. public LevelStatisticsResult CalAgentLevel(int year,int quarter,string GradeCode)
  3065. {
  3066. LevelStatisticsResult result = new LevelStatisticsResult();
  3067. DateTime tempDate=DateTime.Parse($"{year}-01-01");
  3068. var Months = new List<int>() { 1,2,3};
  3069. switch (quarter)
  3070. {
  3071. case 1:
  3072. if(year == 2022)
  3073. {
  3074. Months = new List<int>() { 2, 3 };
  3075. }
  3076. else
  3077. {
  3078. Months = new List<int>() { 1, 2, 3 };
  3079. }
  3080. tempDate = DateTime.Parse($"{year}-01-01");
  3081. break;
  3082. case 2:
  3083. Months = new List<int>() { 4,5,6 };
  3084. tempDate = DateTime.Parse($"{year}-04-01");
  3085. break;
  3086. case 3:
  3087. Months = new List<int>() { 7,8,9};
  3088. tempDate = DateTime.Parse($"{year}-07-01");
  3089. break;
  3090. case 4:
  3091. Months = new List<int>() { 10,11,12 };
  3092. tempDate = DateTime.Parse($"{year}-10-01");
  3093. break;
  3094. }
  3095. //var mList = Context.CalMonths.Where(c=>c.Year == year && Months.Contains(c.Month)).ToList();
  3096. //foreach (var m in mList)
  3097. //{
  3098. // StatisticsLevelCount(m.Id);
  3099. //}
  3100. var resp = Context.StaffStatisticsforLevels
  3101. .Include(p => p.Staff)
  3102. .Include(p => p.Grade)
  3103. .Where(p => Months.Contains(p.CalMonth.Month) && p.CalMonth.Year == year && p.Staff.RegularDate.Value < tempDate && p.Staff.IsGradeAssess);
  3104. var temtList = resp.ToList();
  3105. bool isReview = (GradeCode == "A");
  3106. result = CalLevelStatistics(temtList, GradeCode, isReview);
  3107. if (!isReview)
  3108. {
  3109. string UpgradCode = "A";
  3110. switch (GradeCode)
  3111. {
  3112. case "B":
  3113. UpgradCode = "A";
  3114. break;
  3115. case "C":
  3116. UpgradCode = "B";
  3117. break;
  3118. case "D":
  3119. UpgradCode = "C";
  3120. break;
  3121. }
  3122. var temResult = CalLevelStatistics(temtList, UpgradCode, isReview);
  3123. result.UpgradeBase = temResult.doAverage();
  3124. }
  3125. if (result.Statistics.Count > 0)
  3126. {
  3127. var temAverage = result.pAverage(result.Statistics[0].StaffId);
  3128. }
  3129. return result;
  3130. }
  3131. /// <summary>
  3132. /// 重新统计指定月份的人员案件数量
  3133. /// </summary>
  3134. /// <param name="year"></param>
  3135. /// <param name="month"></param>
  3136. public bool StatisticsLevelCount(int year,int month)
  3137. {
  3138. try
  3139. {
  3140. _StatisticsLevelCount(year,month,Context);
  3141. return true;
  3142. }
  3143. catch { return false; }
  3144. }
  3145. private void _StatisticsLevelCount(int year, int month,spDbContext spDb)
  3146. {
  3147. var temObj = spDb.CalMonths.FirstOrDefault(l => l.Year == year && l.Month == month);
  3148. if (temObj != null)
  3149. {
  3150. var temList = spDb.StaffStatisticsforLevels.Where(l => l.CalMonthId == temObj.Id);
  3151. spDb.StaffStatisticsforLevels.RemoveRange(temList);
  3152. var NewList = StatisticsCount(temObj.Id, spDb);
  3153. spDb.StaffStatisticsforLevels.AddRange(NewList);
  3154. spDb.SaveChanges();
  3155. }
  3156. }
  3157. #endregion
  3158. }
  3159. }