PerformanceItemController.cs 174 KB

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