PerformanceItemController.cs 149 KB

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