PerformanceItemController.cs 113 KB

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