PerformanceItemController.cs 175 KB

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