PerformanceItemController.cs 192 KB

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