PerformanceItemController.cs 189 KB

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