PerformanceItemController.cs 181 KB

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