PerformanceItemController.cs 158 KB

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