PerformanceItemController.cs 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503
  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. StatisticsLevelCount(calMonth.Year, calMonth.Month);
  769. }
  770. private void _RefreshBasePoint(CalMonth calMonth, spDbContext spDb)
  771. {
  772. if (calMonth != null)
  773. {
  774. var lstItem = spDb.PerformanceItems
  775. .Include(p => p.Customer)
  776. .Include(p => p.ItemStaffs)
  777. .Include(p => p.Reviewer)
  778. .Include(p => p.CalMonth)
  779. .Where(p => p.CalMonthId == calMonth.Id).ToList();
  780. var rules = spDb.BasePointRules.ToList();
  781. foreach (var item in lstItem)
  782. {
  783. try
  784. {
  785. Utility.Utility.CalBasePoint(item, rules);
  786. if (item.BasePoint > 0)
  787. {
  788. _calItemJX(item, spDb);
  789. }
  790. else
  791. {
  792. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == item.Id);
  793. spDb.StaffStatistics.RemoveRange(oldJxList);
  794. }
  795. spDb.SaveChanges();
  796. }
  797. catch (Exception ex)
  798. {
  799. System.Diagnostics.Debug.WriteLine(ex.Message);
  800. }
  801. }
  802. _CalJXPoint(calMonth, spDb);
  803. }
  804. }
  805. public ApiSaveResponse RefreshBasePoint()
  806. {
  807. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  808. t.Start();
  809. return new ApiSaveResponse() {
  810. Success = true
  811. };
  812. }
  813. public void RefreshPoint(PerformanceItem item)
  814. {
  815. //spDbContext spDb = new spDbContext();
  816. var rules = Context.BasePointRules.ToList();
  817. if (item.AgentFeedbackMemo != "特殊点数申诉")
  818. {
  819. Utility.Utility.CalBasePoint(item, rules);
  820. if (item.BasePoint > 0)
  821. {
  822. _calItemJX(item, Context);
  823. }
  824. else
  825. {
  826. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  827. Context.StaffStatistics.RemoveRange(oldJxList);
  828. }
  829. Context.SaveChanges();
  830. }
  831. }
  832. public ApiSaveResponse RefreshFromIPEasyById(int itemId)
  833. {
  834. var Item = Context.PerformanceItems.Include(p => p.Customer).Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson).FirstOrDefault(p => p.Id == itemId);
  835. if (Item != null)
  836. {
  837. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  838. }
  839. Utility.Utility.CalBasePoint(Item, Context.BasePointRules.ToList());
  840. if (Item.BasePoint > 0)
  841. {
  842. _calItemJX(Item, Context);
  843. }
  844. else
  845. {
  846. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == Item.Id);
  847. Context.StaffStatistics.RemoveRange(oldJxList);
  848. }
  849. Context.SaveChanges();
  850. return new ApiSaveResponse()
  851. {
  852. Success = true
  853. };
  854. }
  855. public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
  856. {
  857. new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
  858. return new ApiSaveResponse()
  859. {
  860. Success = true
  861. };
  862. }
  863. public ApiSaveResponse RefreshFromIPEasy(string CaseNo, string DoItem, string caseStage)
  864. {
  865. var Item = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault(p => p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
  866. if (Item != null)
  867. {
  868. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  869. }
  870. return new ApiSaveResponse()
  871. {
  872. Success = true
  873. };
  874. }
  875. public ApiSaveResponse CompareExcel2DB()
  876. {
  877. System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
  878. t.Start();
  879. return new ApiSaveResponse()
  880. {
  881. Success = true
  882. };
  883. }
  884. public FileProcessTask CurrentData2Excel()
  885. {
  886. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Status == 0);
  887. if (calMonth != null)
  888. {
  889. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  890. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  891. var filePath = Path.Combine(attachfileSavePath, filename);
  892. var fileTask = new FileProcessTask()
  893. {
  894. Id = Guid.NewGuid().ToString(),
  895. FileName = filename,
  896. FilePath = filePath,
  897. Processed = 0
  898. };
  899. fileTaskService.Add(fileTask);
  900. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(Export2ExcelThread));
  901. t.Start(fileTask);
  902. return fileTask;
  903. }
  904. return null;
  905. }
  906. private void Export2ExcelThread(object attfile)
  907. {
  908. FileProcessTask file = (FileProcessTask)attfile;
  909. spDbContext spDb = new spDbContext();
  910. List<PerformanceItem> items = spDb.PerformanceItems
  911. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  912. .Include(p => p.PreOastaff)
  913. .Include(p => p.Customer)
  914. .Include(p => p.CalMonth)
  915. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  916. .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  917. DataTable dt = new DataTable();
  918. #region 栏位名称
  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("处理事项系数", typeof(string));
  927. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  928. dt.Columns.Add("前一次OA处理人", 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. dt.Columns.Add("实际处理人", typeof(string));
  956. #endregion
  957. var verifyCeoffients = spDb.VerifyCoefficients.ToList();
  958. var Rules = spDb.BasePointRules.ToList();
  959. file.Size = items.Count;
  960. foreach (var p in items)
  961. {
  962. List<ItemStaff> temItemStaffs = p.ItemStaffs.ToList();
  963. string strCaseMemo = "";
  964. string strHandler = "";
  965. temItemStaffs = new List<ItemStaff>();
  966. foreach (var iStaff in p.ItemStaffs)
  967. {
  968. strHandler = string.IsNullOrEmpty(strHandler) ? iStaff.DoPerson.Name : $"{strHandler},{iStaff.DoPerson.Name}";
  969. if (iStaff.DoPerson.Status == "试用期")
  970. {
  971. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}在试用期" : $"{strCaseMemo},{iStaff.DoPerson.Name}在试用期";
  972. }
  973. else
  974. {
  975. if (!iStaff.DoPerson.IsCalPerformsnce)
  976. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}不计算绩效" : $"{strCaseMemo},{iStaff.DoPerson.Name}不计算绩效";
  977. }
  978. if (iStaff.DoPersonId == p.ReviewerId)
  979. {
  980. strCaseMemo = String.IsNullOrEmpty(strCaseMemo) ? "核稿人与处理人相同" : $"{strCaseMemo},核稿人与处理人相同";
  981. }
  982. }
  983. var staffStatics = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).Where(s => s.ItemId == p.Id && s.jxType.Contains("处理"));
  984. var reviewStatic = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).FirstOrDefault(s => s.ItemId == p.Id && s.jxType.Contains("审核"));
  985. foreach (var iStaff in staffStatics.ToList())
  986. {
  987. DataRow row = dt.NewRow();
  988. row["我方文号"] = p.CaseNo;
  989. row["申请类型"] = p.ApplicationType;
  990. row["实际处理人"] = strHandler;
  991. if (p.ApplicationName != null && p.ApplicationName.Contains("OPPO") && p.ApplicationType == "实用新型" && p.Type == "新申请")
  992. {
  993. row["申请类型"] = "发明";
  994. row["案件备注"] = $"{row["案件备注"]}\r\n【OPPO案件实用新型修改为发明】";
  995. }
  996. row["处理事项"] = p.DoItem;
  997. row["业务类型"] = p.BusinessType;
  998. row["备注(填表注意事项)"] = p.AgentFeedbackMemo;
  999. if (p.Type == "专案")
  1000. {
  1001. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]}【主管给定点数】专案";
  1002. row["处理事项"] = "提出报告";
  1003. }
  1004. if (p.ItemStaffs.Count() > 1)
  1005. {
  1006. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]},{strHandler}合写";
  1007. }
  1008. row["案件阶段"] = p.CaseStage;
  1009. row["案件系数"] = p.CaseCoefficient;
  1010. if (p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo) && p.Type == "新申请")
  1011. {
  1012. switch (p.CaseCoefficient)
  1013. {
  1014. case "S":
  1015. row["案件系数"] = "A";
  1016. break;
  1017. case "A":
  1018. row["案件系数"] = "B";
  1019. break;
  1020. case "B":
  1021. row["案件系数"] = "C";
  1022. break;
  1023. case "C":
  1024. row["案件系数"] = "D";
  1025. break;
  1026. }
  1027. row["案件备注"] = $"{row["案件备注"]}\r\n严重延期降系数【{p.CaseCoefficient}->{row["案件系数"]}】";
  1028. }
  1029. row["处理事项系数"] = p.DoItemCoefficient;
  1030. row["前一次OA处理事项系数"] = "";
  1031. row["前一次OA处理人"] = p.PreOastaff?.Name;
  1032. row["处理人"] = iStaff.Staff.Name;
  1033. row["基本点数"] = iStaff.totalBasePoint;
  1034. row["处理人等级"] = iStaff.Staff.StaffGrade.Grade;
  1035. row["处理人绩效系数"] = iStaff.Staff.StaffGrade.Coefficient;
  1036. if (reviewStatic != null)
  1037. {
  1038. row["核稿人"] = reviewStatic.Staff.Name;
  1039. var v = verifyCeoffients.FirstOrDefault(p => p.CheckerId == reviewStatic.Staff.StaffGradeId && p.DoPersonId == iStaff.Staff.StaffGradeId);
  1040. if (v != null)
  1041. {
  1042. row["核稿绩效"] = ((decimal)iStaff.totalBasePoint * (decimal)v.Coefficient);
  1043. row["核稿系数"] = v.Coefficient;
  1044. }
  1045. }
  1046. row["客户名称"] = p.Customer?.Name;
  1047. row["申请人"] = p.ApplicationName;
  1048. row["处理事项完成日"] = p.FinishedDate?.ToString("yyyy-MM-dd");
  1049. row["定稿日"] = p.FinalizationDate?.ToString("yyyy-MM-dd");
  1050. row["返稿日"] = p.ReturnDate?.ToString("yyyy-MM-dd");
  1051. row["案件类型"] = p.CaseType;
  1052. row["案件状态"] = p.CaseState;
  1053. row["处理事项备注"] = p.DoItemMemo;
  1054. row["处理状态"] = p.DoItemState;
  1055. row["案件名称"] = p.CaseName;
  1056. row["委案日期"] = p.EntrustingDate?.ToString("yyyy-MM-dd");
  1057. row["客户期限"] = p.CustomerLimitDate?.ToString("yyyy-MM-dd");
  1058. row["内部期限"] = p.InternalDate?.ToString("yyyy-MM-dd");
  1059. row["初稿日"] = p.FirstDraftDate?.ToString("yyyy-MM-dd");
  1060. row["翻译字数"] = p.WordCount;
  1061. row["备注(发文严重超期是否属客观原因,若为否,请填写原因"] = p.OverDueMemo;
  1062. row["绩效类型"] = p.Type;
  1063. row["案件备注"] = $"{p.CaseMemo}\r\n{row["案件备注"]}";
  1064. if (!string.IsNullOrEmpty(strCaseMemo))
  1065. {
  1066. row["案件备注"] = $"{strCaseMemo}\r\n{row["案件备注"]}";
  1067. }
  1068. dt.Rows.Add(row);
  1069. }
  1070. file.Processed += 1;
  1071. }
  1072. NPOIExcel.DataTableToExcel(dt, file.FilePath);
  1073. file.Finished = true;
  1074. }
  1075. private void _CompareExcel2DB()
  1076. {
  1077. DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0, 2);
  1078. DataTable retTable = new DataTable();
  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. retTable.Columns.Add("不一致原因");
  1110. spDbContext spDb = new spDbContext();
  1111. List<PerformanceItem> items = spDb.PerformanceItems
  1112. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  1113. .Include(p => p.Customer)
  1114. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  1115. .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  1116. excelDT.DefaultView.Sort = "我方文号,处理事项";
  1117. DataTable temDt = excelDT.DefaultView.ToTable();
  1118. int iTable = 0;
  1119. int iList = 0;
  1120. CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p => p.Status == 0);
  1121. var verifyCoefficients = spDb.VerifyCoefficients.ToList();
  1122. var Rules = spDb.BasePointRules.ToList();
  1123. while (iTable < temDt.Rows.Count && iList < items.Count)
  1124. {
  1125. System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
  1126. DataRow row = temDt.Rows[iTable];
  1127. PerformanceItem item = items[iList];
  1128. if (row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString() == "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
  1129. {
  1130. var temRow = retTable.NewRow();
  1131. int iBegin = iTable;
  1132. int iEnd = iTable;
  1133. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1134. if (iEnd < temDt.Rows.Count - 1)
  1135. {
  1136. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1137. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1138. {
  1139. iEnd++;
  1140. }
  1141. }
  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. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1156. for (int i = iBegin; i <= iEnd; i++)
  1157. {
  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. temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
  1161. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1162. {
  1163. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1164. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1165. }
  1166. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1167. }
  1168. iTable = iEnd;
  1169. #endregion
  1170. Utility.Utility.CalBasePoint(item, Rules);
  1171. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1172. try
  1173. {
  1174. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1175. }
  1176. catch { }
  1177. temRow["案件阶段【系统】"] = item.CaseStage;
  1178. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1179. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1180. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1181. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1182. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1183. temRow["严重超期备注原因"] = item.OverDueMemo;
  1184. if (retPoints != null && retPoints.Count > 0)
  1185. {
  1186. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
  1187. foreach (var itemStaff in item.ItemStaffs)
  1188. {
  1189. //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1190. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1191. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1192. if (item.ReviewerId != null)
  1193. {
  1194. #region 取审核人等级审核等级系数
  1195. VerifyCoefficient vcoefficient
  1196. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1197. v.CheckerId == item.Reviewer.StaffGradeId
  1198. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1199. .FirstOrDefault<VerifyCoefficient>();
  1200. #endregion
  1201. if (vcoefficient != null)
  1202. {
  1203. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1204. }
  1205. }
  1206. }
  1207. }
  1208. temRow["是否一致"] = "";
  1209. temRow["不一致原因"] = "";
  1210. if (temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
  1211. {
  1212. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
  1213. }
  1214. if (temRow["案件系数【系统】"].ToString().Trim() != temRow["案件系数"].ToString().Trim())
  1215. {
  1216. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件系数" : $"{temRow["不一致原因"]},案件系数";
  1217. }
  1218. if (temRow["处理事项系数【系统】"].ToString().Trim() != temRow["处理事项系数"].ToString().Trim())
  1219. {
  1220. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "处理事项系数" : $"{temRow["不一致原因"]},处理事项系数";
  1221. }
  1222. if (temRow["核稿人【系统】"].ToString().Trim() != temRow["核稿人"].ToString().Trim())
  1223. {
  1224. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "核稿人" : $"{temRow["不一致原因"]},核稿人";
  1225. }
  1226. if (temRow["基本点数【系统】"].ToString().Trim() != temRow["基本点数"].ToString().Trim())
  1227. {
  1228. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "基本点数" : $"{temRow["不一致原因"]},基本点数";
  1229. }
  1230. if (temRow["严重超期备注原因【系统】"].ToString().Trim() != temRow["严重超期备注原因"].ToString().Trim())
  1231. {
  1232. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "严重超期备注原因" : $"{temRow["不一致原因"]},严重超期备注原因";
  1233. }
  1234. if (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
  1235. {
  1236. temRow["是否一致"] = "不一致";
  1237. }
  1238. retTable.Rows.Add(temRow);
  1239. iTable++;
  1240. iList++;
  1241. }
  1242. else
  1243. {
  1244. string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
  1245. string strList = $"{item.CaseNo}-{item.DoItem}";
  1246. if (strDT.CompareTo(strList) > 0)
  1247. {
  1248. var temRow = retTable.NewRow();
  1249. Utility.Utility.CalBasePoint(item, Rules);
  1250. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1251. try
  1252. {
  1253. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1254. }
  1255. catch { }
  1256. temRow["我方文号"] = item.CaseNo;
  1257. temRow["处理事项"] = item.DoItem;
  1258. temRow["申请类型"] = item.ApplicationType;
  1259. temRow["业务类型"] = item.BusinessType;
  1260. temRow["案件阶段【系统】"] = item.CaseStage;
  1261. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1262. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1263. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1264. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1265. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1266. temRow["严重超期备注原因"] = item.OverDueMemo;
  1267. if (item.ReviewerId != null)
  1268. {
  1269. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1270. }
  1271. foreach (var itemStaff in item.ItemStaffs)
  1272. {
  1273. //if (itemStaff.DoPerson.Status != "试用期")
  1274. //{
  1275. // if (retPoints != null && retPoints.Count > 0)
  1276. // {
  1277. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1278. // }
  1279. //}
  1280. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1281. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1282. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1283. if (item.ReviewerId != null)
  1284. {
  1285. #region 取审核人等级审核等级系数
  1286. VerifyCoefficient vcoefficient
  1287. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1288. v.CheckerId == item.Reviewer.StaffGradeId
  1289. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1290. .FirstOrDefault<VerifyCoefficient>();
  1291. #endregion
  1292. if (vcoefficient != null)
  1293. {
  1294. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1295. }
  1296. }
  1297. }
  1298. temRow["是否一致"] = "不一致";
  1299. temRow["不一致原因"] = "Excel中没有,系统中有";
  1300. retTable.Rows.Add(temRow);
  1301. iList++;
  1302. }
  1303. else
  1304. {
  1305. var temRow = retTable.NewRow();
  1306. int iBegin = iTable;
  1307. int iEnd = iTable;
  1308. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1309. if (iEnd < temDt.Rows.Count - 1)
  1310. {
  1311. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1312. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1313. {
  1314. iEnd++;
  1315. }
  1316. }
  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. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1332. for (int i = iBegin + 1; i <= iEnd; i++)
  1333. {
  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. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1337. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1338. {
  1339. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1340. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1341. }
  1342. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1343. }
  1344. iTable = iEnd;
  1345. #endregion
  1346. temRow["是否一致"] = "不一致";
  1347. temRow["不一致原因"] = "系统中没有,Excel中有";
  1348. retTable.Rows.Add(temRow);
  1349. iTable++;
  1350. }
  1351. }
  1352. }
  1353. if (iList <= items.Count)
  1354. {
  1355. while (iList < items.Count) {
  1356. var item = items[iList];
  1357. var temRow = retTable.NewRow();
  1358. Utility.Utility.CalBasePoint(item, Rules);
  1359. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1360. try
  1361. {
  1362. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1363. }
  1364. catch { }
  1365. temRow["我方文号"] = item.CaseNo;
  1366. temRow["处理事项"] = item.DoItem;
  1367. temRow["申请类型"] = item.ApplicationType;
  1368. temRow["业务类型"] = item.BusinessType;
  1369. temRow["案件阶段【系统】"] = item.CaseStage;
  1370. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1371. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1372. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1373. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1374. temRow["基本点数【系统】"] = "";// item.BasePoint?.ToString();
  1375. temRow["严重超期备注原因"] = item.OverDueMemo;
  1376. if (item.ReviewerId != null)
  1377. {
  1378. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1379. }
  1380. foreach (var itemStaff in item.ItemStaffs)
  1381. {
  1382. //if (itemStaff.DoPerson.Status != "试用期")
  1383. //{
  1384. // if (retPoints != null && retPoints.Count > 0)
  1385. // {
  1386. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1387. // }
  1388. //}
  1389. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1390. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1391. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1392. if (item.ReviewerId != null)
  1393. {
  1394. #region 取审核人等级审核等级系数
  1395. VerifyCoefficient vcoefficient
  1396. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1397. v.CheckerId == item.Reviewer.StaffGradeId
  1398. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1399. .FirstOrDefault<VerifyCoefficient>();
  1400. #endregion
  1401. if (vcoefficient != null)
  1402. {
  1403. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1404. }
  1405. }
  1406. }
  1407. temRow["是否一致"] = "不一致";
  1408. temRow["不一致原因"] = "Excel中没有,系统中有";
  1409. iList++;
  1410. retTable.Rows.Add(temRow);
  1411. }
  1412. }
  1413. else
  1414. {
  1415. while (iTable < temDt.Rows.Count)
  1416. {
  1417. var temRow = retTable.NewRow();
  1418. int iBegin = iTable;
  1419. int iEnd = iTable;
  1420. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1421. while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
  1422. temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
  1423. {
  1424. iEnd++;
  1425. }
  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. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1441. for (int i = iBegin + 1; i <= iEnd; i++)
  1442. {
  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. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1446. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1447. {
  1448. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1449. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1450. }
  1451. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["严重超期备注原因"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["严重超期备注原因"]}";
  1452. }
  1453. iTable = iEnd;
  1454. #endregion
  1455. temRow["是否一致"] = "不一致";
  1456. temRow["不一致原因"] = "系统中没有,Excel中有";
  1457. retTable.Rows.Add(temRow);
  1458. iTable++;
  1459. }
  1460. }
  1461. NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
  1462. }
  1463. public List<StaffStatistics> CalItemJX(int itemid)
  1464. {
  1465. var Item = Context.PerformanceItems.Include(p => p.CalMonth)
  1466. .Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson).ThenInclude(s => s.StaffGrade)
  1467. .Include(p => p.Reviewer)
  1468. .Include(p => p.Customer)
  1469. .FirstOrDefault(p => p.Id == itemid);
  1470. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  1471. return _calItemJX(verifyCoefficients, Item, Context);
  1472. }
  1473. private void _calItemJX(PerformanceItem Item, spDbContext spDb)
  1474. {
  1475. List<VerifyCoefficient> verifyCoefficients = spDb.VerifyCoefficients.ToList<VerifyCoefficient>();
  1476. var jxList = _calItemJX(verifyCoefficients, Item, spDb);
  1477. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == Item.Id);
  1478. spDb.StaffStatistics.RemoveRange(oldJxList);
  1479. spDb.SaveChanges();
  1480. foreach (var jx in jxList)
  1481. {
  1482. if (jx.totalBasePoint == 0)
  1483. {
  1484. return;
  1485. }
  1486. jx.ItemId = Item.Id;
  1487. spDb.StaffStatistics.Add(jx);
  1488. spDb.SaveChanges();
  1489. }
  1490. }
  1491. /// <summary>
  1492. /// 序号 情况 处理逻辑
  1493. /// 1 处理人试用期算绩效 一人处理 正常算绩效给处理人
  1494. /// 2 处理人试用期不算绩效 一人处理 算给核稿人,如果没有核稿人,这条数据忽略
  1495. /// 3 处理人试用期算绩效 与人合写 合写人算绩效、与合写人一人一半
  1496. /// 4 处理人试用期不算绩效 与人合写 合写人算绩效、全部绩效算给合写人
  1497. /// 5 处理人试用期不算绩效 与人合写 合写人不算算绩效、这条数据忽略
  1498. /// 6 处理人试用期算绩效 与人合写 合写人不算绩效、试用期人员拿一半
  1499. /// 7 处理人不算绩效 一人处理 这条数据忽略
  1500. /// 8 处理人不算绩效 与人合写 合写人算绩效、合写人拿一半
  1501. /// 9 处理人不算绩效 与人合写 合写人不算绩效、这条数据忽略
  1502. /// </summary>
  1503. /// <param name="verifyCoefficients"></param>
  1504. /// <param name="item"></param>
  1505. /// <param name="spDb"></param>
  1506. /// <returns></returns>
  1507. private List<StaffStatistics> _calItemJX(List<VerifyCoefficient> verifyCoefficients, PerformanceItem item, spDbContext spDb)
  1508. {
  1509. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  1510. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  1511. if (item.ReviewerId != null && item.Reviewer == null)
  1512. {
  1513. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  1514. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  1515. }
  1516. List<ItemStaff> temIStaffs = new List<ItemStaff>();
  1517. #region 将试用期且不算绩效的人员从处理人清单中剔除
  1518. int syqUsers = 0;
  1519. foreach(var itemStaff in item.ItemStaffs)
  1520. {
  1521. if (itemStaff.DoPerson == null)
  1522. {
  1523. itemStaff.DoPerson = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == itemStaff.DoPersonId);
  1524. }
  1525. if(itemStaff.DoPerson.Status == "试用期" && !itemStaff.DoPerson.IsCalPerformsnce )
  1526. {
  1527. syqUsers += 1;
  1528. }
  1529. else
  1530. {
  1531. temIStaffs.Add(itemStaff);
  1532. }
  1533. }
  1534. #endregion
  1535. #region 处理人全部是试用期人员,则将核稿人当成处理人(处理人为试用期人)
  1536. if (syqUsers == item.ItemStaffs.Count)
  1537. {
  1538. if(item.Reviewer != null)
  1539. {
  1540. temIStaffs.Add(new ItemStaff() { DoPersonId = item.ReviewerId.Value, ItemId = item.Id });
  1541. }
  1542. }
  1543. #endregion
  1544. bool isPJFP = true;
  1545. double total = temIStaffs.Count();
  1546. if (temIStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  1547. {
  1548. total = temIStaffs.Select(i => i.PerformancePoint.Value).Sum();
  1549. isPJFP = false;
  1550. }
  1551. foreach (ItemStaff itemStaff in temIStaffs)
  1552. {
  1553. if(itemStaff.DoPerson == null)
  1554. {
  1555. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  1556. }
  1557. if (itemStaff.DoPerson.IsCalPerformsnce)
  1558. {
  1559. #region 计算各处理人的绩效点数
  1560. double handlerBasePoint;
  1561. if (item.Type != "专案")
  1562. {
  1563. if (isPJFP)
  1564. {
  1565. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1566. }
  1567. else
  1568. {
  1569. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1570. }
  1571. }
  1572. else
  1573. {
  1574. if (itemStaff.PerformancePoint == null)
  1575. {
  1576. if (isPJFP)
  1577. {
  1578. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1579. }
  1580. else
  1581. {
  1582. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if (item.ItemStaffs.Count == 1 && itemStaff.PerformancePoint == 0)
  1588. {
  1589. handlerBasePoint = item.BasePoint.Value;
  1590. }
  1591. else
  1592. {
  1593. handlerBasePoint = itemStaff.PerformancePoint.Value;
  1594. }
  1595. }
  1596. }
  1597. string handlerJxType = $"{item.Type}处理";
  1598. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
  1599. if (temStatic != null)
  1600. {
  1601. temStatic.totalBasePoint += handlerBasePoint;
  1602. if (item.Type == "OA" || item.Type == "新申请")
  1603. {
  1604. temStatic.totalActuallyPoint += (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient);
  1605. }
  1606. else
  1607. {
  1608. temStatic.totalActuallyPoint += handlerBasePoint;
  1609. }
  1610. }
  1611. else
  1612. {
  1613. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsCalPerformsnce)
  1614. {
  1615. if (item.Type == "OA" || item.Type == "新申请")
  1616. {
  1617. if (itemStaff.DoPerson.StaffGrade == null)
  1618. {
  1619. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s => s.Id == itemStaff.DoPerson.StaffGradeId);
  1620. }
  1621. temStatic = new StaffStatistics()
  1622. {
  1623. //CalMonth = calMonth,
  1624. CalMonthId = item.CalMonthId,
  1625. StaffId = itemStaff.DoPersonId,
  1626. totalActuallyPoint = (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient),
  1627. totalBasePoint = handlerBasePoint,
  1628. jxType = handlerJxType
  1629. };
  1630. itemStatistics.Add(temStatic);
  1631. }
  1632. else
  1633. {
  1634. temStatic = new StaffStatistics()
  1635. {
  1636. //CalMonth = calMonth,
  1637. CalMonthId = item.CalMonthId,
  1638. StaffId = itemStaff.DoPersonId,
  1639. totalBasePoint = handlerBasePoint,
  1640. totalActuallyPoint = handlerBasePoint,
  1641. jxType = handlerJxType
  1642. };
  1643. itemStatistics.Add(temStatic);
  1644. }
  1645. }
  1646. }
  1647. #endregion
  1648. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  1649. if (item.ReviewerId != null && item.Type != "专案" &&
  1650. temIStaffs.FirstOrDefault(s => s.DoPersonId == item.ReviewerId) == null)
  1651. {
  1652. if(item.Reviewer == null)
  1653. {
  1654. item.Reviewer = spDb.Staffs.FirstOrDefault(s=>s.Id == item.ReviewerId);
  1655. }
  1656. if (item.Reviewer.IsCalPerformsnce)
  1657. {
  1658. #region 取审核人等级审核等级系数
  1659. VerifyCoefficient vcoefficient
  1660. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1661. v.CheckerId == item.Reviewer.StaffGradeId
  1662. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1663. .FirstOrDefault<VerifyCoefficient>();
  1664. #endregion
  1665. if (vcoefficient != null)
  1666. {
  1667. double reviewerBasePoint = (double)((decimal)handlerBasePoint * (decimal)vcoefficient.Coefficient);
  1668. string temJxType = $"{item.Type}审核";
  1669. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
  1670. if (temReviewerStatic != null)
  1671. {
  1672. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  1673. temReviewerStatic.totalActuallyPoint += reviewerBasePoint;
  1674. }
  1675. else
  1676. {
  1677. if (itemStaff.DoPerson.Status != "试用期" && item.Reviewer.IsCalPerformsnce) //判断是否在职
  1678. {
  1679. temReviewerStatic = new StaffStatistics()
  1680. {
  1681. CalMonthId = item.CalMonthId,
  1682. StaffId = item.ReviewerId.Value,
  1683. totalBasePoint = reviewerBasePoint,
  1684. totalActuallyPoint = reviewerBasePoint,
  1685. jxType = temJxType
  1686. };
  1687. itemStatistics.Add(temReviewerStatic);
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. #endregion
  1694. }
  1695. }
  1696. return itemStatistics;
  1697. }
  1698. private void _CalJXPoint(CalMonth calMonth,spDbContext spDb)
  1699. {
  1700. NanduStatics gspjXS = DegreeOfDifficulty(calMonth,spDb);
  1701. calMonth.NanduXS = gspjXS.NanduXS;
  1702. calMonth.S = (double)gspjXS.S;
  1703. calMonth.A = (double)gspjXS.A;
  1704. calMonth.B = (double)gspjXS.B;
  1705. calMonth.C = (double)gspjXS.C;
  1706. calMonth.D = (double)gspjXS.D;
  1707. var retList = spDb.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id).ToList();
  1708. #region 新申请处理+专案处理 奖励点数
  1709. double jlPoint = 0;
  1710. if (calMonth.S.HasValue)
  1711. {
  1712. jlPoint = jlPoint + (calMonth.S.Value * 1.5);
  1713. }
  1714. if (calMonth.A.HasValue)
  1715. {
  1716. jlPoint = jlPoint + (calMonth.A.Value * 0.5);
  1717. }
  1718. #endregion
  1719. #region 难度系数
  1720. IDictionary<int, NanduStatics> staffXiShu = new Dictionary<int, NanduStatics>();
  1721. IDictionary<int, NanduStatics> ReivewerXiShu = new Dictionary<int, NanduStatics>();
  1722. foreach (StaffStatistics ss in retList)
  1723. {
  1724. if (ss.jxType == "新申请处理" || ss.jxType == "专案处理")
  1725. {
  1726. #region 新申请处理+专案处理
  1727. if (!staffXiShu.ContainsKey(ss.StaffId))
  1728. {
  1729. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb,false,true);
  1730. staffXiShu.Add(ss.StaffId, nandu);
  1731. }
  1732. ss.FinianlPoint = ss.totalActuallyPoint * staffXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1733. ss.NanduXS = staffXiShu[ss.StaffId].NanduXS;
  1734. ss.S = (double)staffXiShu[ss.StaffId].S;
  1735. ss.A = (double)staffXiShu[ss.StaffId].A;
  1736. ss.B = (double)staffXiShu[ss.StaffId].B;
  1737. ss.C = (double)staffXiShu[ss.StaffId].C;
  1738. ss.D = (double)staffXiShu[ss.StaffId].D;
  1739. #endregion
  1740. }
  1741. else
  1742. {
  1743. if (ss.jxType == "新申请审核")
  1744. {
  1745. if (!ReivewerXiShu.ContainsKey(ss.StaffId))
  1746. {
  1747. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb, true);
  1748. ReivewerXiShu.Add(ss.StaffId, nandu);
  1749. }
  1750. ss.FinianlPoint = ss.totalBasePoint * ReivewerXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1751. ss.NanduXS = ReivewerXiShu[ss.StaffId].NanduXS;
  1752. ss.S = (double)ReivewerXiShu[ss.StaffId].S;
  1753. ss.A = (double)ReivewerXiShu[ss.StaffId].A;
  1754. ss.B = (double)ReivewerXiShu[ss.StaffId].B;
  1755. ss.C = (double)ReivewerXiShu[ss.StaffId].C;
  1756. ss.D = (double)ReivewerXiShu[ss.StaffId].D;
  1757. spDb.SaveChanges();
  1758. }
  1759. else
  1760. {
  1761. ss.FinianlPoint = ss.totalActuallyPoint;
  1762. spDb.SaveChanges();
  1763. }
  1764. }
  1765. }
  1766. var xsqList = retList.Where(ss => ss.jxType == "新申请处理" || ss.jxType == "专案处理").ToList();
  1767. var totalFPBLPoint = xsqList.Sum(p=>p.FinianlPoint); //新申请处理+专案 分配比率总点数
  1768. var totalActionPoint = xsqList.Sum(p=>p.totalActuallyPoint); //新申请处理+专案 原始总点数
  1769. foreach (StaffStatistics ss in xsqList)
  1770. {
  1771. ss.FinianlPoint = ss.FinianlPoint / totalFPBLPoint * (totalActionPoint + jlPoint);
  1772. spDb.SaveChanges();
  1773. }
  1774. #endregion
  1775. }
  1776. public void CalJXPoint(int year, int month)
  1777. {
  1778. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1779. if (calMonth != null)
  1780. {
  1781. using (var t = Context.Database.BeginTransaction())
  1782. {
  1783. try
  1784. {
  1785. var result = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
  1786. Context.StaffStatistics.RemoveRange(result);
  1787. var itemList = Context.PerformanceItems
  1788. .Include(s => s.ItemStaffs)
  1789. .Include(p=>p.Customer)
  1790. .Include(p=>p.Reviewer)
  1791. .Where(s => s.CalMonthId == calMonth.Id).ToList();
  1792. var rules = Context.BasePointRules.ToList();
  1793. foreach (var item in itemList)
  1794. {
  1795. Utility.Utility.CalBasePoint(item, rules);
  1796. Context.SaveChanges();
  1797. if (item.BasePoint > 0)
  1798. {
  1799. _calItemJX(item,Context);
  1800. }
  1801. else
  1802. {
  1803. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  1804. Context.StaffStatistics.RemoveRange(oldJxList);
  1805. }
  1806. }
  1807. _CalJXPoint(calMonth, Context);
  1808. t.Commit();
  1809. }
  1810. catch (Exception ex)
  1811. {
  1812. t.Rollback();
  1813. }
  1814. }
  1815. }
  1816. }
  1817. /// <summary>
  1818. /// 新申请/专案:
  1819. /// 调整点数 = 分配比例点数/分配比例点数之和*总点数
  1820. /// 等级调整点数+项目组点数之和 = 基础点数 * 代理人等级系数 + 项目组案件调整点数
  1821. /// 分配比例点数 = 个人平均难度系数 / 总平均难度系数 *(等级调整点数+项目组点数之和)
  1822. /// 总点数=等级调整点数+项目组点数之和+奖励点数
  1823. /// 奖励点数= S案数量*1.5 + A案数量 * 0.5
  1824. /// 难度系数=(S案数量*2.5 + A案数量* 1.5 + B案数量*1.0 + C案数量*0.7+ D案数量*0.4) / 总案件数量
  1825. /// 总案件数量= S案数量 + A案数量 + B案数量 + C案数量+ D案数量
  1826. /// OA :
  1827. /// 调整点数= 基础点数 * 等级系数
  1828. /// 其他:
  1829. /// 直接加和基础点数 不需要乘以系数
  1830. /// </summary>
  1831. /// <param name="year"></param>
  1832. /// <param name="month"></param>
  1833. /// <returns></returns>
  1834. public ApiSaveResponse FinishedCalMonth(int year,int month)
  1835. {
  1836. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1837. if (calMonth != null || calMonth.Status !=4)
  1838. {
  1839. using (var t = Context.Database.BeginTransaction())
  1840. {
  1841. try
  1842. {
  1843. _RefreshBasePoint(calMonth,Context);
  1844. //_CalJXPoint(calMonth, Context);
  1845. calMonth.Status = 4;
  1846. Context.SaveChanges();
  1847. StatisticsCount(calMonth.Id); //等级核算案件统计
  1848. #region 将待审核的申诉全部修改为已审核
  1849. var aList = Context.AppealRecords.Where(a => a.State == 0).ToList();
  1850. aList.ForEach(a =>a.State = 1);
  1851. Context.SaveChanges();
  1852. #endregion
  1853. t.Commit();
  1854. return new ApiSaveResponse()
  1855. {
  1856. Success = true
  1857. };
  1858. }
  1859. catch (Exception ex)
  1860. {
  1861. t.Rollback();
  1862. return new ApiSaveResponse()
  1863. {
  1864. Success = false,
  1865. ErrorMessage = ex.Message
  1866. };
  1867. }
  1868. }
  1869. }
  1870. else
  1871. {
  1872. return new ApiSaveResponse()
  1873. {
  1874. Success = false,
  1875. ErrorMessage ="指定月份没有数据或者已归档!"
  1876. };
  1877. }
  1878. }
  1879. /// <summary>
  1880. /// 计算指定用户,指定年月的绩效统计信息
  1881. /// </summary>
  1882. /// <param name="userid"></param>
  1883. /// <param name="year"></param>
  1884. /// <param name="month"></param>
  1885. /// <returns></returns>
  1886. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  1887. {
  1888. //object retList;
  1889. //string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
  1890. //if(!MyMemoryCache.TryGetValue(strKey,out retList))
  1891. //{
  1892. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1893. if (calMonth == null)
  1894. {
  1895. return null;
  1896. }
  1897. else
  1898. {
  1899. return _CalMyStatistics(calMonth, userid);
  1900. #region old code
  1901. //if (calMonth.Status == 4)
  1902. //{
  1903. // //已归档,归档数据库中直接取出记录
  1904. // if (userid == null)
  1905. // {
  1906. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  1907. // }
  1908. // else
  1909. // {
  1910. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  1911. // }
  1912. //}
  1913. //else
  1914. //{
  1915. // try
  1916. // {
  1917. // retList = _CalMyStatistics(calMonth, userid);
  1918. // }
  1919. // catch(Exception ex)
  1920. // {
  1921. // StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  1922. // sw.WriteLine($"{ex.Message}");
  1923. // sw.Flush();
  1924. // sw.Close();
  1925. // sw.Dispose();
  1926. // }
  1927. //}
  1928. //// Set cache options.
  1929. //var cacheEntryOptions = new MemoryCacheEntryOptions()
  1930. // // Keep in cache for this time, reset time if accessed.
  1931. // .SetSlidingExpiration(TimeSpan.FromHours(1));
  1932. //foreach(var temObj in (List<StaffStatistics>)retList)
  1933. //{
  1934. // temObj.CalMonth.PerformanceItems = null;
  1935. //}
  1936. //// Save data in cache.
  1937. //MyMemoryCache.SetValue(strKey, retList);
  1938. //return (List<StaffStatistics>)retList;
  1939. #endregion
  1940. }
  1941. //}
  1942. //else
  1943. //{
  1944. // var temList = (List<StaffStatistics>)retList;
  1945. // foreach (var temObj in temList)
  1946. // {
  1947. // temObj.CalMonth.PerformanceItems = null;
  1948. // }
  1949. // return temList;
  1950. //}
  1951. }
  1952. private string GetExpress(IList<FieldCondition> conditions)
  1953. {
  1954. string str = "";
  1955. foreach(var c in conditions)
  1956. {
  1957. if (string.IsNullOrEmpty(str))
  1958. {
  1959. str = c.ToExpressString("s");
  1960. }
  1961. else
  1962. {
  1963. if(c.LogicOperate == LogicEnum.And)
  1964. {
  1965. str = $"({str}) && {c.ToExpressString("s")}";
  1966. }
  1967. else
  1968. {
  1969. str = $"({str}) || {c.ToExpressString("s")}";
  1970. }
  1971. }
  1972. }
  1973. return str;
  1974. }
  1975. [HttpGet,HttpPost]
  1976. public FileProcessTask ExportData(QueryFilter queryFilter)
  1977. {
  1978. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  1979. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  1980. var filePath = Path.Combine(attachfileSavePath, filename);
  1981. var fileTask = new FileProcessTask()
  1982. {
  1983. Id = Guid.NewGuid().ToString(),
  1984. FileName = filename,
  1985. FilePath = filePath,
  1986. Processed = 0
  1987. };
  1988. fileTaskService.Add(fileTask);
  1989. ThreadObject threadObject = new ThreadObject()
  1990. {
  1991. queryFilter = queryFilter,
  1992. fileTask = fileTask
  1993. };
  1994. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  1995. t.Start(threadObject);
  1996. return fileTask;
  1997. }
  1998. internal class ThreadObject
  1999. {
  2000. public QueryFilter queryFilter { get; set; }
  2001. public FileProcessTask fileTask { get; set; }
  2002. }
  2003. private void ExportDataThread(object tObj)
  2004. {
  2005. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  2006. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  2007. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2008. var retList = response
  2009. .Include(p=>p.Customer)
  2010. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  2011. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  2012. .Include(p=>p.PreOastaff)
  2013. .Include(p=>p.CalMonth)
  2014. .ToList<PerformanceItem>();
  2015. DataTable dt = new DataTable();
  2016. #region 添加栏位
  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("处理事项系数", typeof(string));
  2025. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  2026. dt.Columns.Add("前一次OA处理人", 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. dt.Columns.Add("备注", typeof(string));
  2049. #endregion
  2050. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  2051. fileTask.Size = retList.Count;
  2052. foreach (var item in retList)
  2053. {
  2054. fileTask.Processed += 1;
  2055. if (item.CaseNo.StartsWith("J"))
  2056. {
  2057. continue;
  2058. }
  2059. try
  2060. {
  2061. var row = dt.NewRow();
  2062. row["我方文号"] = item.CaseNo;
  2063. row["申请类型"] = item.ApplicationType;
  2064. row["业务类型"] = item.BusinessType;
  2065. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  2066. row["处理事项"] = item.DoItem;
  2067. row["案件阶段"] = item.CaseStage;
  2068. row["案件系数"] = item.CaseCoefficient;
  2069. row["处理事项系数"] = item.DoItemCoefficient;
  2070. row["前一次OA处理事项系数"] = "";
  2071. if (item.PreOastaffId.HasValue)
  2072. {
  2073. row["前一次OA处理人"] = item.PreOastaff?.Name;
  2074. }
  2075. string strISLevels = "";
  2076. string strISNames = "";
  2077. foreach (var istaff in item.ItemStaffs)
  2078. {
  2079. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  2080. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  2081. }
  2082. row["处理人等级"] = strISLevels;
  2083. row["基本点数"] = item.BasePoint;
  2084. row["处理人"] = strISNames;
  2085. row["核稿人"] = item.Reviewer?.Name;
  2086. if (item.ReviewerId != null && item.BasePoint.HasValue)
  2087. {
  2088. var jxList = _calItemJX( verifyCoefficients, item, new spDbContext());
  2089. row["核稿系数"] = "";
  2090. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  2091. if (temJx != null)
  2092. {
  2093. row["核稿绩效"] = temJx.totalBasePoint;
  2094. }
  2095. }
  2096. row["客户名称"] = item.Customer?.Name;
  2097. row["申请人"] = item.ApplicationName;
  2098. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  2099. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  2100. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  2101. row["案件类型"] = item.CaseType;
  2102. row["案件状态"] = item.CaseState;
  2103. row["处理事项备注"] = item.DoItemState;
  2104. row["处理状态"] = item.DoItemState;
  2105. row["案件名称"] = item.CaseName;
  2106. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  2107. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  2108. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  2109. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  2110. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  2111. row["备注"] = item.DoItemMemo;
  2112. dt.Rows.Add(row);
  2113. }
  2114. catch(Exception ex)
  2115. {
  2116. throw ex;
  2117. }
  2118. }
  2119. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  2120. fileTask.Finished = true;
  2121. }
  2122. [HttpPost]
  2123. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  2124. {
  2125. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  2126. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2127. int totals = response.ToList<PerformanceItem>().Count;
  2128. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  2129. {
  2130. response = response
  2131. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2132. .Include(pi => pi.Reviewer)
  2133. .Include(pi => pi.Customer)
  2134. .Include(pi => pi.CalMonth)
  2135. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2136. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  2137. }
  2138. else
  2139. {
  2140. response = response
  2141. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2142. .Include(pi => pi.Reviewer)
  2143. .Include(pi => pi.Customer)
  2144. .Include(pi => pi.CalMonth)
  2145. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2146. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  2147. }
  2148. ret.TotalCount = totals;
  2149. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  2150. #region 将某些属性设为null,避免循环取值造成返回json过大
  2151. foreach (PerformanceItem item in retList)
  2152. {
  2153. foreach (ItemStaff itemStaff in item.ItemStaffs)
  2154. {
  2155. itemStaff.DoPerson.ItemStaffs = null;
  2156. itemStaff.DoPerson.ReviewerItems = null;
  2157. itemStaff.Item = null;
  2158. }
  2159. if (item.Reviewer != null)
  2160. {
  2161. item.Reviewer.ReviewerItems = null;
  2162. item.Reviewer.Customers = null;
  2163. item.Reviewer.ItemStaffs = null;
  2164. }
  2165. if (item.WorkflowUser != null)
  2166. {
  2167. item.WorkflowUser.ReviewerItems = null;
  2168. item.WorkflowUser.Customers = null;
  2169. item.WorkflowUser.ItemStaffs = null;
  2170. }
  2171. if (item.Customer != null)
  2172. {
  2173. item.Customer.PerformanceItems = null;
  2174. }
  2175. if (item.CalMonth != null)
  2176. {
  2177. item.CalMonth.PerformanceItems = null;
  2178. }
  2179. }
  2180. #endregion
  2181. ret.Results = retList.ToList();
  2182. return ret;
  2183. }
  2184. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  2185. {
  2186. string strExpress = "";
  2187. string strCalMonth = "";
  2188. if (queryFilter.CalMonthId.HasValue)
  2189. {
  2190. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  2191. }
  2192. else
  2193. {
  2194. if(queryFilter.jxType == jxType.finished)
  2195. {
  2196. strCalMonth = $"s.CalMonth.Status == 4";
  2197. }
  2198. else
  2199. {
  2200. strCalMonth = $"s.CalMonth.Status != 4";
  2201. }
  2202. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  2203. }
  2204. if (!string.IsNullOrEmpty(strExpress))
  2205. {
  2206. strExpress = $"{strExpress} && {strCalMonth}";
  2207. }
  2208. else
  2209. {
  2210. strExpress = strCalMonth;
  2211. }
  2212. if (queryFilter.ConditionTree != null)
  2213. {
  2214. string strTem = GetExpress(queryFilter.ConditionTree);
  2215. if (!string.IsNullOrEmpty(strTem))
  2216. {
  2217. strExpress = $"{strExpress} && ({strTem})";
  2218. }
  2219. }
  2220. var interpreter = new Interpreter();
  2221. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  2222. IQueryable<PerformanceItem> response;
  2223. if (queryFilter.userId > 0)
  2224. {
  2225. if (queryFilter.DoingOrReview == 0)
  2226. {
  2227. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  2228. }
  2229. else
  2230. {
  2231. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  2232. }
  2233. }
  2234. else
  2235. {
  2236. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  2237. }
  2238. return response;
  2239. }
  2240. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  2241. {
  2242. ApiSaveResponse retResponse = new ApiSaveResponse();
  2243. retResponse.Success = true;
  2244. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  2245. {
  2246. using (var t = Context.Database.BeginTransaction())
  2247. {
  2248. try
  2249. {
  2250. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  2251. if (calMonth == null)
  2252. {
  2253. retResponse.Success = false;
  2254. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  2255. return retResponse;
  2256. }
  2257. else
  2258. {
  2259. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  2260. projectContents.ProjectContentRecord.CalMonth = null;
  2261. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  2262. projectContents.ProjectContentRecord.StaffId = staff.Id;
  2263. projectContents.ProjectContentRecord.State = 0;
  2264. }
  2265. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  2266. if (project != null)
  2267. {
  2268. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  2269. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  2270. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  2271. if(pRecord != null)
  2272. {
  2273. retResponse.Success = false;
  2274. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  2275. return retResponse;
  2276. }
  2277. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  2278. foreach (var doItem in projectContents.ProjectWorkContents)
  2279. {
  2280. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  2281. Context.ProjectWorkContents.Add(doItem);
  2282. }
  2283. t.Commit();
  2284. }
  2285. else
  2286. {
  2287. retResponse.Success = false;
  2288. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  2289. return retResponse;
  2290. }
  2291. }
  2292. catch (Exception ex)
  2293. {
  2294. retResponse.Success = false;
  2295. retResponse.ErrorMessage = ex.Message;
  2296. t.Rollback();
  2297. return retResponse;
  2298. }
  2299. }
  2300. }
  2301. return retResponse;
  2302. }
  2303. public PerformanceItem GetCaseInfo(string CaseNo)
  2304. {
  2305. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  2306. if(retObj == null)
  2307. {
  2308. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  2309. }
  2310. return retObj;
  2311. }
  2312. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  2313. {
  2314. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  2315. if (retObj == null)
  2316. {
  2317. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  2318. }
  2319. return retObj;
  2320. }
  2321. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage,bool UpdateFromIPEasy=true)
  2322. {
  2323. var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2324. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  2325. if (retObj == null && UpdateFromIPEasy)
  2326. {
  2327. var temObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(
  2328. new PerformanceItem() {CaseNo =CaseNo,DoItem =DoItem,CaseStage = caseStage },
  2329. Context
  2330. );// IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  2331. System.Dynamic.ExpandoObject temExpandoObject = (System.Dynamic.ExpandoObject)temObj;
  2332. retObj = new PerformanceItem();
  2333. retObj.CaseNo = temObj.CaseNo.ToString();
  2334. retObj.CaseName = temObj.CaseName.ToString();
  2335. try
  2336. {
  2337. if (temObj.ApplicationType != null)
  2338. retObj.ApplicationType = temObj.ApplicationType.ToString();
  2339. if (temObj.CaseMemo != null)
  2340. retObj.CaseMemo = temObj.CaseMemo.ToString();
  2341. if (temObj.BusinessType != null)
  2342. retObj.BusinessType = temObj.BusinessType.ToString();
  2343. if (temObj.DoItem != null)
  2344. retObj.DoItem = temObj.DoItem.ToString();
  2345. if (temObj.CaseStage != null)
  2346. retObj.CaseStage = temObj.CaseStage.ToString();
  2347. if (temObj.CaseType != null)
  2348. retObj.CaseType = temObj.CaseType.ToString();
  2349. if (temObj.DoItemState != null)
  2350. retObj.DoItemState = temObj.DoItemState.ToString();
  2351. if (temObj.DoItemCoefficient != null)
  2352. retObj.DoItemCoefficient = temObj.DoItemCoefficient.ToString();
  2353. if (temObj.CaseCoefficient != null)
  2354. retObj.CaseCoefficient = temObj.CaseCoefficient.ToString();
  2355. if (temObj.EntrustingDate != null)
  2356. {
  2357. if (!string.IsNullOrEmpty(temObj.EntrustingDate.ToString()))
  2358. retObj.EntrustingDate = DateTime.Parse(temObj.EntrustingDate.ToString());
  2359. }
  2360. if (temObj.InternalDate != null)
  2361. {
  2362. if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
  2363. retObj.InternalDate = DateTime.Parse(temObj.InternalDate.ToString());
  2364. }
  2365. if (temObj.CustomerLimitDate != null)
  2366. {
  2367. if (!string.IsNullOrEmpty(temObj.CustomerLimitDate.ToString()))
  2368. retObj.CustomerLimitDate = DateTime.Parse(temObj.CustomerLimitDate.ToString());
  2369. }
  2370. if (temObj.ReturnDate != null)
  2371. {
  2372. if (!string.IsNullOrEmpty(temObj.ReturnDate.ToString()))
  2373. retObj.ReturnDate = DateTime.Parse(temObj.ReturnDate.ToString());
  2374. }
  2375. if (temObj.FinalizationDate != null)
  2376. {
  2377. if (!string.IsNullOrEmpty(temObj.FinalizationDate.ToString()))
  2378. retObj.FinalizationDate = DateTime.Parse(temObj.FinalizationDate.ToString());
  2379. }
  2380. if (temObj.FinishedDate != null)
  2381. {
  2382. if (!string.IsNullOrEmpty(temObj.FinishedDate.ToString()))
  2383. retObj.FinishedDate = DateTime.Parse(temObj.FinishedDate.ToString());
  2384. }
  2385. }
  2386. catch { }
  2387. int temWordCount;
  2388. if (temObj.WordCount != null)
  2389. {
  2390. if (int.TryParse(temObj.WordCount, out temWordCount))
  2391. {
  2392. retObj.WordCount = temWordCount;
  2393. }
  2394. }
  2395. try
  2396. {
  2397. if (temObj.CustomerName != null)
  2398. {
  2399. string strCustomer = temObj.CustomerName.ToString();
  2400. retObj.Customer = new Customer() { Name = strCustomer };
  2401. var temCustomer = Context.Customers.Where(c => c.Name == strCustomer.Trim()).FirstOrDefault();
  2402. if (temCustomer != null)
  2403. {
  2404. retObj.CustomerId = temCustomer.Id;
  2405. }
  2406. }
  2407. }
  2408. catch { }
  2409. try
  2410. {
  2411. if (temObj.Reviewer != null)
  2412. {
  2413. string strReViewer = temObj.Reviewer.ToString();
  2414. var temReviewer = Context.Staffs.Where(s => s.Name == strReViewer.Trim()).FirstOrDefault();
  2415. if (temReviewer != null)
  2416. {
  2417. retObj.ReviewerId = temReviewer.Id;
  2418. }
  2419. }
  2420. }
  2421. catch { }
  2422. if (temObj.DoPersons != null)
  2423. {
  2424. string DoPersons = temObj.DoPersons.ToString();
  2425. string[] Persons = DoPersons.Split(new char[] { ',' });
  2426. List<ItemStaff> itemStaffs = new List<ItemStaff>();
  2427. foreach (var doPerson in Persons)
  2428. {
  2429. itemStaffs.Add(new ItemStaff() { DoPerson = new Staff() { Name = doPerson } });
  2430. }
  2431. retObj.ItemStaffs = itemStaffs;
  2432. }
  2433. }
  2434. return retObj;
  2435. }
  2436. public PerformanceItem GetItemInfoByMonthId(string CaseNo, string DoItem, string caseStage,int calMonthId)
  2437. {
  2438. var retObj = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2439. && p.DoItem == DoItem.Trim() && p.CalMonthId == calMonthId);
  2440. if(retObj != null)
  2441. {
  2442. if(string.IsNullOrEmpty (retObj.CaseStage) && string.IsNullOrEmpty(caseStage))
  2443. {
  2444. return retObj;
  2445. }
  2446. else
  2447. {
  2448. if(retObj.CaseStage == caseStage)
  2449. {
  2450. return retObj;
  2451. }
  2452. else
  2453. {
  2454. return null;
  2455. }
  2456. }
  2457. }
  2458. else
  2459. {
  2460. return null;
  2461. }
  2462. }
  2463. public bool MovePerformance2ProjectInfo()
  2464. {
  2465. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  2466. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  2467. var pList = response.ToList<PerformanceItem>();
  2468. foreach(var p in pList)
  2469. {
  2470. ProjectInfo project = new ProjectInfo();
  2471. project.CaseNo = p.CaseNo;
  2472. project.CaseName = p.CaseName;
  2473. project.CaseState = 0;
  2474. project.CaseType = p.CaseType;
  2475. project.CustomerId = p.CustomerId;
  2476. project.ReviewerId = p.ReviewerId;
  2477. Context.ProjectInfos.Add(project);
  2478. foreach(ItemStaff iStaff in p.ItemStaffs)
  2479. {
  2480. Context.ItemStaffs.Remove(iStaff);
  2481. }
  2482. Context.PerformanceItems.Remove(p);
  2483. Context.SaveChanges();
  2484. }
  2485. return true;
  2486. }
  2487. #region 等级考核计算
  2488. /// <summary>
  2489. /// 等级考核案件量统计
  2490. /// </summary>
  2491. /// <param name="calMonthId"></param>
  2492. /// <returns></returns>
  2493. private List<StaffStatisticsforLevel> StatisticsCount(int calMonthId)
  2494. {
  2495. var retlist = new List<StaffStatisticsforLevel>();
  2496. #region 新申请
  2497. var newList = Context.PerformanceItems.Include(p => p.ItemStaffs)
  2498. .Where(p=>p.CalMonthId == calMonthId && p.BasePoint >0
  2499. && (p.Type =="新申请" || p.Type =="专案" || (p.Type == "其它" && p.WordCount >0 && (p.DoItem =="新申请" || p.DoItem == "翻译")))
  2500. ).ToList();
  2501. foreach(var p in newList)
  2502. {
  2503. var pointList = Context.StaffStatistics.Include(i=>i.Staff).Where(i=>i.ItemId == p.Id).ToList();
  2504. #region 新申请处理
  2505. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2506. foreach(var h in doList)
  2507. {
  2508. var temObj = retlist.FirstOrDefault(s=>s.StaffId == h.StaffId && s.Type == "新申请" && s.isReview == false);
  2509. if(temObj == null)
  2510. {
  2511. temObj = new StaffStatisticsforLevel();
  2512. temObj.StaffId = h.StaffId;
  2513. temObj.GradeId = h.Staff.StaffGradeId.Value ;
  2514. if(temObj.GradeId == 0)
  2515. {
  2516. System.Diagnostics.Debug.WriteLine("");
  2517. }
  2518. temObj.CalMonthId = p.CalMonthId;
  2519. temObj.Type = "新申请";
  2520. retlist.Add(temObj);
  2521. }
  2522. switch (p.CaseCoefficient)
  2523. {
  2524. case "S":
  2525. if(p.Type == "专案")
  2526. {
  2527. temObj.S += h.totalBasePoint.Value;
  2528. }
  2529. else
  2530. {
  2531. temObj.S+=(double)(1.0M/ (decimal)doList.Count());
  2532. }
  2533. break;
  2534. case "A":
  2535. if (p.Type == "专案")
  2536. {
  2537. temObj.A += h.totalBasePoint.Value;
  2538. }
  2539. else
  2540. {
  2541. temObj.A += (double)(1.0M / (decimal)doList.Count());
  2542. }
  2543. break;
  2544. case "B":
  2545. if (p.Type == "专案")
  2546. {
  2547. temObj.B += h.totalBasePoint.Value;
  2548. }
  2549. else
  2550. {
  2551. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2552. }
  2553. break;
  2554. case "C":
  2555. if (p.Type == "专案")
  2556. {
  2557. temObj.C += h.totalBasePoint.Value;
  2558. }
  2559. else
  2560. {
  2561. temObj.C += (double)(1.0M / (decimal)doList.Count());
  2562. }
  2563. break;
  2564. case "D":
  2565. if (p.Type == "专案")
  2566. {
  2567. temObj.D += h.totalBasePoint.Value;
  2568. }
  2569. else
  2570. {
  2571. temObj.D += (double)(1.0M / (decimal)doList.Count());
  2572. }
  2573. break;
  2574. }
  2575. }
  2576. #endregion
  2577. #region 新申请审核
  2578. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2579. if(reviewer != null)
  2580. {
  2581. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "新申请" && s.isReview == true);
  2582. if(temObj == null)
  2583. {
  2584. temObj = new StaffStatisticsforLevel();
  2585. temObj.StaffId = reviewer.StaffId;
  2586. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2587. if (temObj.GradeId == 0)
  2588. {
  2589. System.Diagnostics.Debug.WriteLine("");
  2590. }
  2591. temObj.CalMonthId = p.CalMonthId;
  2592. temObj.Type = "新申请";
  2593. temObj.isReview = true;
  2594. retlist.Add(temObj);
  2595. }
  2596. switch (p.CaseCoefficient)
  2597. {
  2598. case "S":
  2599. temObj.S += 1;
  2600. break;
  2601. case "A":
  2602. temObj.A += 1;
  2603. break;
  2604. case "B":
  2605. temObj.B += 1;
  2606. break;
  2607. case "C":
  2608. temObj.D += 1;
  2609. break;
  2610. case "D":
  2611. temObj.D += 1;
  2612. break;
  2613. }
  2614. }
  2615. #endregion
  2616. }
  2617. #endregion
  2618. #region 国内OA
  2619. var cnOA = Context.PerformanceItems.Include(x=>x.ItemStaffs)
  2620. .Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && x.CaseNo.Contains("CN") && x.BasePoint > 0
  2621. && (x.CaseStage == "一通" || x.DoItemCoefficient.Contains("首次转入"))).ToList();
  2622. foreach(var p in cnOA)
  2623. {
  2624. var pointList = Context.StaffStatistics.Include(i => i.Staff).Where(i=> i.ItemId == p.Id).ToList();
  2625. #region 国内OA处理
  2626. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2627. foreach (var h in doList)
  2628. {
  2629. var temObj = retlist.FirstOrDefault(s => s.StaffId == h.StaffId && s.Type == "国内OA" && s.isReview == false);
  2630. if (temObj == null)
  2631. {
  2632. temObj = new StaffStatisticsforLevel();
  2633. temObj.StaffId = h.StaffId;
  2634. temObj.GradeId = h.Staff.StaffGradeId.Value ;
  2635. if (temObj.GradeId == 0)
  2636. {
  2637. System.Diagnostics.Debug.WriteLine("");
  2638. }
  2639. temObj.CalMonthId = p.CalMonthId;
  2640. temObj.Type = "国内OA";
  2641. retlist.Add(temObj);
  2642. }
  2643. switch (p.CaseCoefficient)
  2644. {
  2645. case "S":
  2646. temObj.S += (double)(1.0M / (decimal)doList.Count());
  2647. break;
  2648. case "A":
  2649. temObj.A += (double)(1.0M / (decimal)doList.Count());
  2650. break;
  2651. case "B":
  2652. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2653. break;
  2654. case "C":
  2655. temObj.C += (double)(1.0M / (decimal)doList.Count());
  2656. break;
  2657. case "D":
  2658. temObj.D += (double)(1.0M / (decimal)doList.Count());
  2659. break;
  2660. }
  2661. }
  2662. #endregion
  2663. #region 国内OA审核
  2664. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2665. if (reviewer != null)
  2666. {
  2667. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "国内OA" && s.isReview == true);
  2668. if (temObj == null)
  2669. {
  2670. temObj = new StaffStatisticsforLevel();
  2671. temObj.StaffId = reviewer.StaffId;
  2672. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2673. if (temObj.GradeId == 0)
  2674. {
  2675. System.Diagnostics.Debug.WriteLine("");
  2676. }
  2677. temObj.CalMonthId = p.CalMonthId;
  2678. temObj.Type = "国内OA";
  2679. temObj.isReview = true;
  2680. retlist.Add(temObj);
  2681. }
  2682. switch (p.CaseCoefficient)
  2683. {
  2684. case "S":
  2685. temObj.S += 1;
  2686. break;
  2687. case "A":
  2688. temObj.A += 1;
  2689. break;
  2690. case "B":
  2691. temObj.B += 1;
  2692. break;
  2693. case "C":
  2694. temObj.D += 1;
  2695. break;
  2696. case "D":
  2697. temObj.D += 1;
  2698. break;
  2699. }
  2700. }
  2701. #endregion
  2702. }
  2703. #endregion
  2704. #region 涉外OA
  2705. var gwOA = Context.PerformanceItems.Include(x => x.ItemStaffs)
  2706. .Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && !x.CaseNo.Contains("CN") && x.BasePoint>0
  2707. && (x.DoItemCoefficient.Contains("实质"))).ToList();
  2708. foreach (var p in gwOA)
  2709. {
  2710. var pointList = Context.StaffStatistics.Include(i => i.Staff).Where(i => i.ItemId == p.Id).ToList();
  2711. #region 涉外OA处理
  2712. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2713. foreach (var h in doList)
  2714. {
  2715. var temObj = retlist.FirstOrDefault(s => s.StaffId == h.StaffId && s.Type == "涉外OA" && s.isReview == false);
  2716. if (temObj == null)
  2717. {
  2718. temObj = new StaffStatisticsforLevel();
  2719. temObj.StaffId = h.StaffId;
  2720. temObj.GradeId = h.Staff.StaffGradeId.Value;
  2721. if (temObj.GradeId == 0)
  2722. {
  2723. System.Diagnostics.Debug.WriteLine("");
  2724. }
  2725. temObj.CalMonthId = p.CalMonthId;
  2726. temObj.Type = "涉外OA";
  2727. retlist.Add(temObj);
  2728. }
  2729. switch (p.CaseCoefficient)
  2730. {
  2731. case "S":
  2732. temObj.S += (double)(1.0M / (decimal)doList.Count());
  2733. break;
  2734. case "A":
  2735. temObj.A += (double)(1.0M / (decimal)doList.Count());
  2736. break;
  2737. case "B":
  2738. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2739. break;
  2740. case "C":
  2741. temObj.C += (double)(1.0M / (decimal)doList.Count());
  2742. break;
  2743. case "D":
  2744. temObj.D += (double)(1.0M / (decimal)doList.Count());
  2745. break;
  2746. }
  2747. }
  2748. #endregion
  2749. #region 涉外OA审核
  2750. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2751. if (reviewer != null)
  2752. {
  2753. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "涉外OA" && s.isReview == true);
  2754. if (temObj == null)
  2755. {
  2756. temObj = new StaffStatisticsforLevel();
  2757. temObj.StaffId = reviewer.StaffId;
  2758. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2759. if (temObj.GradeId == 0)
  2760. {
  2761. System.Diagnostics.Debug.WriteLine("");
  2762. }
  2763. temObj.CalMonthId = calMonthId;
  2764. temObj.Type = "涉外OA";
  2765. temObj.isReview = true;
  2766. retlist.Add(temObj);
  2767. }
  2768. switch (p.CaseCoefficient)
  2769. {
  2770. case "S":
  2771. temObj.S += 1;
  2772. break;
  2773. case "A":
  2774. temObj.A += 1;
  2775. break;
  2776. case "B":
  2777. temObj.B += 1;
  2778. break;
  2779. case "C":
  2780. temObj.D += 1;
  2781. break;
  2782. case "D":
  2783. temObj.D += 1;
  2784. break;
  2785. }
  2786. }
  2787. #endregion
  2788. }
  2789. #endregion
  2790. return retlist;
  2791. }
  2792. /// <summary>
  2793. /// 指定等级人员等级考核案件量统计汇总
  2794. /// </summary>
  2795. /// <param name="levelCaseCounts"></param>
  2796. /// <param name="GradeCode"></param>
  2797. /// <param name="calReviw"></param>
  2798. /// <returns></returns>
  2799. private LevelStatisticsResult CalLevelStatistics(List<StaffStatisticsforLevel> levelCaseCounts,string GradeCode,bool calReviw)
  2800. {
  2801. var retList = new List<LevelStatistics>();
  2802. var temList = levelCaseCounts.Where(x=>x.Grade.Grade.StartsWith(GradeCode)).ToList();
  2803. foreach (var s in temList)
  2804. {
  2805. var temObj = retList.FirstOrDefault(i=>i.StaffId == s.StaffId);
  2806. if(temObj == null)
  2807. {
  2808. temObj = new LevelStatistics();
  2809. temObj.StaffId = s.StaffId;
  2810. temObj.StaffName = s.Staff.Name;
  2811. temObj.Grade = s.Grade.Grade;
  2812. //var Department = Context.DepartmentPositions.FirstOrDefault(x => x.StaffId == s.StaffId);
  2813. temObj.Department = Context.DepartmentPositions.Include(x => x.department).FirstOrDefault(x => x.StaffId == s.StaffId)?.department.Name;
  2814. retList.Add(temObj);
  2815. }
  2816. if (!s.isReview)
  2817. {
  2818. if(s.Type == "国内OA")
  2819. {
  2820. temObj.dS += (double)((decimal)s.S / 2M);
  2821. temObj.dA += (double)((decimal)s.A / 2M);
  2822. temObj.dB += (double)((decimal)s.B / 2M);
  2823. temObj.dC += (double)((decimal)s.C / 2M);
  2824. temObj.dD += (double)((decimal)s.D / 2M);
  2825. }
  2826. else
  2827. {
  2828. temObj.dS += s.S;
  2829. temObj.dA += s.A;
  2830. temObj.dB += s.B;
  2831. temObj.dC += s.C;
  2832. temObj.dD += s.D;
  2833. }
  2834. }
  2835. else
  2836. {
  2837. if (calReviw)
  2838. {
  2839. if (s.Type == "国内OA")
  2840. {
  2841. temObj.vS += (double)((decimal)s.S / 2M);
  2842. temObj.vA += (double)((decimal)s.A / 2M);
  2843. temObj.vB += (double)((decimal)s.B / 2M);
  2844. temObj.vC += (double)((decimal)s.C / 2M);
  2845. temObj.vD += (double)((decimal)s.D / 2M);
  2846. }
  2847. else
  2848. {
  2849. temObj.vS += s.S;
  2850. temObj.vA += s.A;
  2851. temObj.vB += s.B;
  2852. temObj.vC += s.C;
  2853. temObj.vD += s.D;
  2854. }
  2855. }
  2856. }
  2857. }
  2858. return new LevelStatisticsResult() {Grade =GradeCode , Statistics = retList};
  2859. }
  2860. /// /// <summary>
  2861. /// 获取季度等级考核结果
  2862. /// </summary>
  2863. /// <param name="year">考核年度</param>
  2864. /// <param name="quarter">考核季度,取值为1、2、3、4</param>
  2865. /// <param name="GradeCode">等级</param>
  2866. /// <returns></returns>
  2867. public LevelStatisticsResult CalAgentLevel(int year,int quarter,string GradeCode)
  2868. {
  2869. LevelStatisticsResult result = new LevelStatisticsResult();
  2870. var Months = new List<int>() { 1,2,3};
  2871. switch (quarter)
  2872. {
  2873. case 1:
  2874. Months = new List<int>() { 1, 2, 3 };
  2875. break;
  2876. case 2:
  2877. Months = new List<int>() { 4,5,6 };
  2878. break;
  2879. case 3:
  2880. Months = new List<int>() { 7,8,9};
  2881. break;
  2882. case 4:
  2883. Months = new List<int>() { 10,11,12 };
  2884. break;
  2885. }
  2886. //var mList = Context.CalMonths.Where(c=>c.Year == year && Months.Contains(c.Month)).ToList();
  2887. //foreach (var m in mList)
  2888. //{
  2889. // StatisticsLevelCount(m.Id);
  2890. //}
  2891. var resp = Context.StaffStatisticsforLevels
  2892. .Include(p => p.Staff)
  2893. .Include(p => p.Grade)
  2894. .Where(p => Months.Contains(p.CalMonth.Month) && p.CalMonth.Year == year);
  2895. var temtList = resp.ToList();
  2896. bool isReview = (GradeCode == "A");
  2897. result = CalLevelStatistics(temtList, GradeCode, isReview);
  2898. if (!isReview)
  2899. {
  2900. string UpgradCode = "A";
  2901. switch (GradeCode)
  2902. {
  2903. case "B":
  2904. UpgradCode = "A";
  2905. break;
  2906. case "C":
  2907. UpgradCode = "B";
  2908. break;
  2909. case "D":
  2910. UpgradCode = "C";
  2911. break;
  2912. }
  2913. var temResult = CalLevelStatistics(temtList, UpgradCode, isReview);
  2914. result.UpgradeBase = temResult.doAverage();
  2915. }
  2916. var temAverage= result.pAverage(result.Statistics[0].StaffId);
  2917. return result;
  2918. }
  2919. /// <summary>
  2920. /// 重新统计指定月份的人员案件数量
  2921. /// </summary>
  2922. /// <param name="year"></param>
  2923. /// <param name="month"></param>
  2924. public bool StatisticsLevelCount(int year,int month)
  2925. {
  2926. try
  2927. {
  2928. var temObj = Context.CalMonths.FirstOrDefault(l => l.Year == year && l.Month == month);
  2929. if (temObj != null)
  2930. {
  2931. var temList = Context.StaffStatisticsforLevels.Where(l => l.CalMonthId == temObj.Id);
  2932. Context.StaffStatisticsforLevels.RemoveRange(temList);
  2933. var NewList = StatisticsCount(temObj.Id);
  2934. Context.StaffStatisticsforLevels.AddRange(NewList);
  2935. Context.SaveChanges();
  2936. }
  2937. return true;
  2938. }
  2939. catch { return false; }
  2940. }
  2941. #endregion
  2942. }
  2943. }