PerformanceItemController.cs 128 KB

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