PerformanceItemController.cs 115 KB

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