PerformanceItemController.cs 159 KB

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