PerformanceItemController.cs 154 KB

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