PerformanceItemController.cs 124 KB

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