PerformanceItemController.cs 182 KB

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