PerformanceItemController.cs 120 KB

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