PerformanceItemController.cs 164 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865
  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.Data.SqlClient;
  7. using Microsoft.EntityFrameworkCore;
  8. using Microsoft.Extensions.Caching.Memory;
  9. using Microsoft.Extensions.Hosting;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Linq.Expressions;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using wispro.sp.api.Services;
  19. using wispro.sp.api.Utility;
  20. using wispro.sp.entity;
  21. using wispro.sp.share;
  22. using wispro.sp.utility;
  23. namespace wispro.sp.api.Controllers
  24. {
  25. [Route("api/[controller]/[action]")]
  26. [ApiController]
  27. [Authorize]
  28. public class PerformanceItemController : ControllerBase
  29. {
  30. spDbContext Context;
  31. IFileTaskService fileTaskService;
  32. public PerformanceItemController(spDbContext context, IFileTaskService _fileTaskService)
  33. {
  34. Context = context;
  35. fileTaskService = _fileTaskService;
  36. }
  37. public ApiSaveResponse RemoveDBNotFinishDate(int year, int month)
  38. {
  39. ApiSaveResponse ret = new ApiSaveResponse();
  40. ret.Success = true;
  41. var itemList = Context.PerformanceItems.Include(p => p.ItemStaffs).Where(p => p.CalMonth.Year == year &&
  42. p.CalMonth.Month == month &&
  43. p.DoItem == "处理审查意见" &&
  44. p.FinishedDate == null);
  45. using var t = Context.Database.BeginTransaction();
  46. try
  47. {
  48. foreach (var item in itemList.ToList())
  49. {
  50. if (item != null)
  51. {
  52. Context.ItemStaffs.RemoveRange(item.ItemStaffs);
  53. Context.PerformanceItems.Remove(item);
  54. }
  55. }
  56. Context.SaveChanges();
  57. t.Commit();
  58. return ret;
  59. }
  60. catch (Exception ex)
  61. {
  62. t.Rollback();
  63. ret.Success = false;
  64. ret.ErrorMessage = ex.Message;
  65. return ret;
  66. }
  67. }
  68. public bool IsExist(PerformanceItem item)
  69. {
  70. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  71. x.CaseNo == item.CaseNo &&
  72. x.DoItem == item.DoItem &&
  73. x.CaseStage == item.CaseStage &&
  74. x.CalMonth.Year == item.CalMonth.Year &&
  75. x.CalMonth.Month == item.CalMonth.Month);
  76. if (results.Count() > 0)
  77. {
  78. return true;
  79. }
  80. else
  81. {
  82. return false;
  83. }
  84. }
  85. public ApiSaveResponse New(PerformanceItem item)
  86. {
  87. ApiSaveResponse ret = new ApiSaveResponse();
  88. ret.Success = true;
  89. using (Context.Database.BeginTransaction())
  90. {
  91. try
  92. {
  93. #region 已算绩效的案号只匹配案号前边的数字 20230310
  94. string[] strNos = item.CaseNo.Split(new char[] {'-'});
  95. string strNo = item.CaseNo;
  96. if(strNos.Length > 0 )
  97. {
  98. strNo = strNos[0];
  99. if(strNos.Length > 1)
  100. {
  101. if (strNos[1].ToUpper() == "TS")
  102. {
  103. strNo = $"{strNos[0]}-{strNos[1]}";
  104. }
  105. }
  106. }
  107. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  108. x.CaseNo.StartsWith(strNo) && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  109. if (item.DoItem.ToUpper() == "提交IDS")
  110. {
  111. //提交IDS 添加完成日期做完判断是否已算绩效的条件
  112. results = Context.PerformanceItems.Where<PerformanceItem>(x => x.CaseNo.StartsWith(strNo) && x.DoItem == item.DoItem && x.FinishedDate == item.FinishedDate);
  113. }
  114. #endregion
  115. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  116. if (items != null)
  117. {
  118. item.AgentFeedbackMemo = "已算绩效";
  119. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  120. item.BasePoint = 0;
  121. }
  122. if (item.CalMonth != null)
  123. {
  124. var calMonth = Context.CalMonths.Where<CalMonth>(c => c.Year == item.CalMonth.Year && c.Month == item.CalMonth.Month).FirstOrDefault();
  125. if (calMonth == null)
  126. {
  127. Context.CalMonths.Add(item.CalMonth);
  128. if (item.BasePoint > 0)
  129. {
  130. _calItemJX(item, Context);
  131. }
  132. else
  133. {
  134. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  135. Context.StaffStatistics.RemoveRange(oldJxList);
  136. }
  137. Context.SaveChanges();
  138. }
  139. else
  140. {
  141. item.CalMonth = calMonth;
  142. }
  143. item.CalMonthId = item.CalMonth.Id;
  144. item.CalMonth = null;
  145. }
  146. if (!string.IsNullOrEmpty(item.Customer.Name))
  147. {
  148. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  149. if (temCustomer == null)
  150. {
  151. temCustomer = new Customer() { Name = item.Customer.Name };
  152. //item.Customer.Id = 0;
  153. Context.Customers.Add(temCustomer);
  154. Context.SaveChanges();
  155. item.Customer = temCustomer;
  156. //item.CustomerId = item.Customer.Id;
  157. }
  158. else
  159. {
  160. item.Customer = temCustomer;
  161. }
  162. item.CustomerId = item.Customer.Id;
  163. item.Customer = null;
  164. }
  165. else
  166. {
  167. item.Customer = null;
  168. }
  169. var ItemStaffs = item.ItemStaffs;
  170. item.ItemStaffs = null;
  171. Context.PerformanceItems.Add(item);
  172. Context.SaveChanges();
  173. foreach (ItemStaff itemStaff in ItemStaffs)
  174. {
  175. itemStaff.ItemId = item.Id;
  176. itemStaff.Item = null;
  177. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  178. {
  179. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  180. if (temStaff != null)
  181. {
  182. itemStaff.DoPersonId = temStaff.Id;
  183. itemStaff.DoPerson = null;
  184. }
  185. else
  186. {
  187. Context.Staffs.Add(itemStaff.DoPerson);
  188. Context.SaveChanges();
  189. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  190. itemStaff.DoPerson = null;
  191. }
  192. }
  193. }
  194. Context.ItemStaffs.AddRange(ItemStaffs);
  195. Context.SaveChanges();
  196. Context.Database.CommitTransaction();
  197. }
  198. catch (Exception ex)
  199. {
  200. ret.Success = false;
  201. ret.ErrorMessage = ex.Message;
  202. Context.Database.RollbackTransaction();
  203. }
  204. }
  205. return ret;
  206. }
  207. /// <summary>
  208. /// 更新绩效记录信息
  209. /// </summary>
  210. /// <param name="id">绩效记录编号</param>
  211. /// <param name="field">栏位,多个位以|杠隔开</param>
  212. /// <param name="value">栏位值,多个以|杠隔开</param>
  213. /// <returns></returns>
  214. public ApiSaveResponse UpdateFieldValue(int id, string field, string value)
  215. {
  216. ApiSaveResponse ret = new ApiSaveResponse();
  217. ret.Success = true;
  218. var item = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.Id == id);
  219. if (item == null)
  220. {
  221. ret.Success = false;
  222. ret.ErrorMessage = $"不存在的{id}";
  223. return ret;
  224. }
  225. if (string.IsNullOrEmpty(field))
  226. {
  227. ret.Success = false;
  228. ret.ErrorMessage = $"参数不对!";
  229. return ret;
  230. }
  231. string[] fields = field.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  232. string[] values = new string[] { null };
  233. if (!string.IsNullOrEmpty(value))
  234. {
  235. values = value.Split(new char[] { '|' });
  236. }
  237. if (fields.Length != values.Length) {
  238. ret.Success = false;
  239. ret.ErrorMessage = "栏位和值对不匹配";
  240. }
  241. else
  242. {
  243. for (int i = 0; i < fields.Length; i++)
  244. {
  245. string temField = fields[i];
  246. string temValue = values[i];
  247. switch (temField)
  248. {
  249. case "AgentFeedbackMemo":
  250. item.AgentFeedbackMemo = temValue;
  251. break;
  252. case "CaseCoefficient":
  253. item.CaseCoefficient = temValue;
  254. //此处添加保存到流程系统的代码
  255. break;
  256. case "DoItemCoefficient":
  257. item.DoItemCoefficient = temValue;
  258. //此处添加保存到流程系统的代码
  259. break;
  260. case "WordCount":
  261. int wordCount;
  262. if (int.TryParse(temValue, out wordCount))
  263. {
  264. item.WordCount = wordCount;
  265. }
  266. else
  267. {
  268. item.WordCount = null;
  269. //ret.Success = false;
  270. //ret.ErrorMessage = "所给的栏位值不能转换成数字!";
  271. //return ret;
  272. }
  273. break;
  274. case "ReturnCasseNo":
  275. item.ReturnCasseNo = temValue;
  276. break;
  277. }
  278. }
  279. if (item.AgentFeedbackMemo != "特殊点数申诉")
  280. {
  281. Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
  282. if (item.BasePoint > 0)
  283. {
  284. _calItemJX(item, Context);
  285. }
  286. else
  287. {
  288. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  289. Context.StaffStatistics.RemoveRange(oldJxList);
  290. }
  291. Context.SaveChanges();
  292. }
  293. }
  294. return ret;
  295. }
  296. public ListApiResponse<PerformanceItem> Query(int pageIndex, int pageSize)
  297. {
  298. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  299. var results = Context.PerformanceItems
  300. .Where<PerformanceItem>(s =>
  301. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == User.Identity.Name).Count() > 0 || s.Reviewer.Name == User.Identity.Name)
  302. && s.CalMonth.Status != 4);
  303. ret.TotalCount = results.Count();
  304. List<PerformanceItem> retList = results
  305. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  306. .Include(pi => pi.Reviewer)
  307. .Include(pi => pi.Customer)
  308. .Include(pi => pi.CalMonth)
  309. .OrderByDescending(o => o.Id)
  310. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize).ToList<PerformanceItem>();
  311. #region 将某些属性设为null,避免循环取值造成返回json过大
  312. foreach (PerformanceItem item in retList)
  313. {
  314. foreach (ItemStaff itemStaff in item.ItemStaffs)
  315. {
  316. itemStaff.DoPerson.ItemStaffs = null;
  317. itemStaff.DoPerson.ReviewerItems = null;
  318. itemStaff.Item = null;
  319. }
  320. item.Reviewer.ReviewerItems = null;
  321. item.Reviewer.Customers = null;
  322. item.Reviewer.ItemStaffs = null;
  323. item.Customer.PerformanceItems = null;
  324. item.CalMonth.PerformanceItems = null;
  325. }
  326. #endregion
  327. ret.Results = retList;
  328. return ret;
  329. }
  330. public PerformanceItem Get(int Id)
  331. {
  332. var results = Context.PerformanceItems
  333. .Where<PerformanceItem>(s => s.Id == Id);
  334. PerformanceItem item = results
  335. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  336. .Include(pi => pi.Reviewer)
  337. .Include(pi => pi.Customer)
  338. .Include(pi => pi.CalMonth)
  339. .OrderByDescending(o => o.Id)
  340. .FirstOrDefault();
  341. #region 将某些属性设为null,避免循环取值造成返回json过大
  342. foreach (ItemStaff itemStaff in item.ItemStaffs)
  343. {
  344. itemStaff.DoPerson.ItemStaffs = null;
  345. itemStaff.DoPerson.ReviewerItems = null;
  346. itemStaff.Item = null;
  347. }
  348. if (item.Reviewer != null)
  349. {
  350. item.Reviewer.ReviewerItems = null;
  351. item.Reviewer.Customers = null;
  352. item.Reviewer.ItemStaffs = null;
  353. }
  354. item.Customer.PerformanceItems = null;
  355. item.CalMonth.PerformanceItems = null;
  356. #endregion
  357. return item;
  358. }
  359. /// <summary>
  360. /// 获取给定用户的绩效清单
  361. /// </summary>
  362. /// <param name="userid">用户id</param>
  363. /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
  364. /// <returns></returns>
  365. public ListApiResponse<PerformanceItem> GetMyList(int userid, int type, int pageIndex = 1, int pageSize = 10)
  366. {
  367. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  368. var results = Context.PerformanceItems
  369. .Where<PerformanceItem>(s =>
  370. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  371. && s.CalMonth.Status == type);
  372. ret.TotalCount = results.Count();
  373. List<PerformanceItem> retList = results
  374. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  375. .Include(pi => pi.Reviewer)
  376. .Include(pi => pi.Customer)
  377. .Include(pi => pi.CalMonth)
  378. .OrderByDescending(o => o.Id)
  379. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize)
  380. .ToList<PerformanceItem>();
  381. #region 将某些属性设为null,避免循环取值造成返回json过大
  382. foreach (PerformanceItem item in retList)
  383. {
  384. foreach (ItemStaff itemStaff in item.ItemStaffs)
  385. {
  386. itemStaff.DoPerson.ItemStaffs = null;
  387. itemStaff.DoPerson.ReviewerItems = null;
  388. itemStaff.Item = null;
  389. }
  390. item.Reviewer.ReviewerItems = null;
  391. item.Reviewer.Customers = null;
  392. item.Reviewer.ItemStaffs = null;
  393. item.Customer.PerformanceItems = null;
  394. item.CalMonth.PerformanceItems = null;
  395. }
  396. #endregion
  397. ret.Results = retList;
  398. return ret;
  399. }
  400. /// <summary>
  401. /// 获取个人难度系数
  402. /// </summary>
  403. /// <param name="calMonth">绩效月份</param>
  404. /// <param name="userId">用户Id</param>
  405. /// <param name="isReivewer">是否审核个人难度系数</param>
  406. /// <param name="HXqf">合写算0.5件</param>
  407. /// <returns></returns>
  408. private NanduStatics PersonNanduStatics(CalMonth calMonth, int userId, spDbContext spDb, bool isReivewer = false,bool HXqf=false)
  409. {
  410. NanduStatics retObj = new NanduStatics();
  411. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  412. var list = spDb.CaseCeoffcients;
  413. foreach (var cx in list.ToList<CaseCeoffcient>())
  414. {
  415. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  416. }
  417. string jxType = isReivewer ? "新申请审核" : "新申请处理";
  418. var results = spDb.StaffStatistics.Include(p => p.Item).Where(s => s.CalMonthId == calMonth.Id && s.jxType == jxType && s.StaffId == userId);
  419. if (!isReivewer)
  420. {
  421. results = spDb.StaffStatistics.Include(p => p.Item).Where(s => s.CalMonthId == calMonth.Id && (s.jxType == jxType || s.jxType == "专案处理") && s.StaffId == userId);
  422. }
  423. #region 循环计算
  424. decimal iCount = 0;
  425. decimal d = 0.0M;
  426. var retList = results.ToList();
  427. foreach (var item in retList)
  428. {
  429. if (item.Item != null)
  430. {
  431. //if(item.Item.CaseNo == "PACN2220066")
  432. //{
  433. // System.Diagnostics.Debug.WriteLine("");
  434. //}
  435. //合写人数
  436. decimal CaseNumber = 1M;
  437. if (item.Item.ItemStaffs.Count > 1 && !isReivewer )
  438. {
  439. if (item.Item .ItemStaffs == null)
  440. {
  441. item.Item .ItemStaffs = spDb.ItemStaffs.Include(p => p.DoPerson).Where(p => p.ItemId == item.ItemId).ToList();
  442. }
  443. try
  444. {
  445. CaseNumber = CaseNumber / (item.Item.ItemStaffs.Where(i => i.DoPerson.IsCalPerformsnce == true || (i.DoPerson.Status != "试用期" && i.DoPerson.IsCalPerformsnce == false)).Count());
  446. }
  447. catch { }
  448. }
  449. string strCaseCeoffcient = item.Item.CaseCoefficient;
  450. if (string.IsNullOrEmpty(strCaseCeoffcient))
  451. {
  452. strCaseCeoffcient = "B";
  453. }
  454. #region 严重延期降系数
  455. if (item.Item.isDanger() && string.IsNullOrEmpty(item.Item.OverDueMemo))
  456. {
  457. switch (item.Item.CaseCoefficient)
  458. {
  459. case "S":
  460. strCaseCeoffcient = "A";
  461. break;
  462. case "A":
  463. strCaseCeoffcient = "B";
  464. break;
  465. case "B":
  466. strCaseCeoffcient = "C";
  467. break;
  468. case "C":
  469. strCaseCeoffcient = "D";
  470. break;
  471. }
  472. }
  473. #endregion
  474. switch (strCaseCeoffcient)
  475. {
  476. case "S":
  477. if (item.Item.Type == "专案")
  478. {
  479. retObj.S += (decimal)item.totalBasePoint.Value;
  480. }
  481. else
  482. {
  483. retObj.S += CaseNumber;
  484. }
  485. break;
  486. case "A":
  487. if (item.Item.Type == "专案")
  488. {
  489. retObj.A += (decimal)item.totalBasePoint.Value;
  490. }
  491. else
  492. {
  493. retObj.A += CaseNumber;
  494. }
  495. break;
  496. case "B":
  497. if (item.Item.Type == "专案")
  498. {
  499. retObj.B += (decimal)item.totalBasePoint.Value;
  500. }
  501. else
  502. {
  503. retObj.B += CaseNumber;
  504. }
  505. break;
  506. case "C":
  507. if (item.Item.Type == "专案")
  508. {
  509. retObj.C += (decimal)item.totalBasePoint.Value;
  510. }
  511. else
  512. {
  513. retObj.C += CaseNumber;
  514. }
  515. break;
  516. case "D":
  517. if (item.Item.Type == "专案")
  518. {
  519. retObj.D += (decimal)item.totalBasePoint.Value;
  520. }
  521. else
  522. {
  523. retObj.D += CaseNumber;
  524. }
  525. break;
  526. default:
  527. if (item.Item.Type == "专案")
  528. {
  529. retObj.B += (decimal)item.totalBasePoint.Value;
  530. }
  531. else
  532. {
  533. retObj.B += CaseNumber;
  534. }
  535. break;
  536. }
  537. }
  538. }
  539. #endregion
  540. d = retObj.S * (decimal)CaseXiShu["S"] + retObj.A * (decimal)CaseXiShu["A"] + retObj.B * (decimal)CaseXiShu["B"] + retObj.C * (decimal)CaseXiShu["C"] + retObj.D * (decimal)CaseXiShu["D"];
  541. iCount = retObj.S + retObj.A + retObj.B + retObj.C + retObj.D;
  542. retObj.NanduXS =(double) (d / iCount);
  543. return retObj;
  544. }
  545. /// <summary>
  546. /// 获取总难度系数
  547. /// </summary>
  548. /// <param name="calMonth"></param>
  549. /// <returns></returns>
  550. private NanduStatics DegreeOfDifficulty(CalMonth calMonth, spDbContext spDb)
  551. {
  552. NanduStatics retObj = new NanduStatics();
  553. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  554. var list = spDb.CaseCeoffcients.ToList();
  555. foreach (var cx in list)
  556. {
  557. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  558. }
  559. //var results = spDb.PerformanceItems.Where<PerformanceItem>(p =>
  560. //p.CalMonthId == calMonth.Id &&
  561. //(p.Type == "新申请" || p.Type == "专案") && p.BasePoint > 0.0);
  562. var results = spDb.StaffStatistics
  563. .Where(p =>
  564. p.CalMonthId == calMonth.Id &&
  565. (p.Item.Type == "新申请" || p.Item.Type == "专案"))
  566. .Select(p => p.Item).Distinct();
  567. #region 循环计算
  568. var retList = results.ToList();
  569. foreach (var item in retList)
  570. {
  571. decimal CaseNumber = 1;
  572. if(item.ItemStaffs == null)
  573. {
  574. item.ItemStaffs = spDb.ItemStaffs.Include(p=>p.DoPerson).Where(p =>p.ItemId == item.Id).ToList();
  575. }
  576. if (item.ItemStaffs.Count > 1)
  577. {
  578. var i = item.ItemStaffs.Where(i => (i.DoPerson.Status != "试用期" && i.DoPerson.IsCalPerformsnce == false)).Count();
  579. if ( i> 0)
  580. {
  581. CaseNumber = CaseNumber *(item.ItemStaffs.Count-i)/item.ItemStaffs.Count;
  582. }
  583. }
  584. string strCaseCeoffcient = item.CaseCoefficient;
  585. if (string.IsNullOrEmpty(strCaseCeoffcient))
  586. {
  587. strCaseCeoffcient = "B";
  588. }
  589. #region 严重延期降系数
  590. if (item.isDanger() && string.IsNullOrEmpty(item.OverDueMemo))
  591. {
  592. switch (item.CaseCoefficient)
  593. {
  594. case "S":
  595. strCaseCeoffcient = "A";
  596. break;
  597. case "A":
  598. strCaseCeoffcient = "B";
  599. break;
  600. case "B":
  601. strCaseCeoffcient = "C";
  602. break;
  603. case "C":
  604. strCaseCeoffcient = "D";
  605. break;
  606. }
  607. }
  608. #endregion
  609. switch (strCaseCeoffcient)
  610. {
  611. case "S":
  612. if (item.Type == "专案")
  613. {
  614. retObj.S += (decimal)item.BasePoint.Value;
  615. }
  616. else
  617. {
  618. retObj.S += CaseNumber;
  619. }
  620. break;
  621. case "A":
  622. if (item.Type == "专案")
  623. {
  624. retObj.A += (decimal)item.BasePoint.Value;
  625. }
  626. else
  627. {
  628. retObj.A += CaseNumber;
  629. }
  630. break;
  631. case "B":
  632. if (item.Type == "专案")
  633. {
  634. retObj.B += (decimal)item.BasePoint.Value;
  635. }
  636. else
  637. {
  638. retObj.B += CaseNumber;
  639. }
  640. break;
  641. case "C":
  642. if (item.Type == "专案")
  643. {
  644. retObj.C += (decimal)item.BasePoint.Value;
  645. }
  646. else
  647. {
  648. retObj.C += CaseNumber;
  649. }
  650. break;
  651. case "D":
  652. if (item.Type == "专案")
  653. {
  654. retObj.D += (decimal)item.BasePoint.Value;
  655. }
  656. else
  657. {
  658. retObj.D += CaseNumber;
  659. }
  660. break;
  661. default:
  662. if (item.Type == "专案")
  663. {
  664. retObj.B += (decimal)item.BasePoint.Value;
  665. }
  666. else
  667. {
  668. retObj.B += CaseNumber;
  669. }
  670. break;
  671. }
  672. System.Diagnostics.Debug.WriteLine($"{item.CaseNo}\t{item.DoItem}\t{item.DoItemCoefficient}\t{item.WordCount}\t{strCaseCeoffcient}\t{item.CaseCoefficient}\t{item.BasePoint}");
  673. }
  674. #endregion
  675. var d = retObj.S * (decimal)CaseXiShu["S"] + retObj.A * (decimal)CaseXiShu["A"] + retObj.B * (decimal)CaseXiShu["B"] + retObj.C * (decimal)CaseXiShu["C"] + retObj.D * (decimal)CaseXiShu["D"];
  676. var iCount = retObj.S + retObj.A + retObj.B + retObj.C + retObj.D;
  677. retObj.NanduXS = (double)(d /iCount);
  678. return retObj;
  679. }
  680. public List<string> GetFeedbackString(int itemId)
  681. {
  682. PerformanceItem item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == itemId);
  683. if (item != null)
  684. {
  685. return Utility.Utility.GetFeedbackMemos(item, Context.BasePointRules.ToList());
  686. }
  687. return new List<string>();
  688. }
  689. public FileProcessTask GetStaticsReport(int Year,int Month)
  690. {
  691. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == Year && c.Month == Month);
  692. if (calMonth != null)
  693. {
  694. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}代理人全部考评维度绩效点数加和.xlsx";
  695. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  696. var filePath = Path.Combine(attachfileSavePath, filename);
  697. var fileTask = new FileProcessTask()
  698. {
  699. Id = Guid.NewGuid().ToString(),
  700. FileName = filename,
  701. FilePath = filePath,
  702. Processed = 0
  703. };
  704. fileTaskService.Add(fileTask);
  705. ExportDataResult result = new ExportDataResult()
  706. {
  707. fileTask = fileTask,
  708. calMonth = calMonth
  709. };
  710. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportStaticReport));
  711. t.Start(result);
  712. return fileTask;
  713. }
  714. return null;
  715. }
  716. private void ExportStaticReport(object exportDataResult)
  717. {
  718. ExportDataResult result = (ExportDataResult)exportDataResult;
  719. FileProcessTask file = result.fileTask;
  720. CalMonth calMonth = result.calMonth;
  721. //var StatisticsResults = _CalMyStatistics(calMonth);
  722. string strSQL = @"SELECT Staff.Name as 代理人,StaffGrade.Grade as 代理人等级,
  723. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '新申请处理' and CalMonthId = @CalMonthId ) as '新申请处理',
  724. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '新申请审核' and CalMonthId = @CalMonthId) as '新申请审核',
  725. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '专案处理' and CalMonthId = @CalMonthId) as '专案处理',
  726. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '专案审核' and CalMonthId = @CalMonthId) as '专案审核',
  727. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = 'OA处理' and CalMonthId = @CalMonthId) as OA处理,
  728. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = 'OA审核' and CalMonthId = @CalMonthId) as OA审核,
  729. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '其它处理' and CalMonthId = @CalMonthId) as 其它处理,
  730. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '其它审核' and CalMonthId = @CalMonthId) as 其它审核,
  731. (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and CalMonthId = @CalMonthId) as 总计
  732. FROM[spDB].[dbo].[StaffStatistics] as A
  733. inner join Staff on Staff.Id = A.StaffId
  734. Left join StaffGrade on Staff.StaffGradeId = StaffGrade.Id
  735. where CalMonthId = @CalMonthId
  736. group by A.StaffId, Staff.Name,StaffGrade.Grade";
  737. DataTable dt = new DataTable();
  738. spDbContext spDb = new spDbContext();
  739. using (var conn = spDb.Database.GetDbConnection())
  740. {
  741. conn.Open();
  742. var cmd = conn.CreateCommand();
  743. cmd.CommandText = strSQL;
  744. cmd.CommandType = CommandType.Text;
  745. cmd.Parameters.Add(new SqlParameter("CalMonthId", calMonth.Id));
  746. using (var reader = cmd.ExecuteReader())
  747. {
  748. dt.Load(reader);
  749. }
  750. }
  751. NPOIExcel.DataTableToExcel(dt, result.fileTask.FilePath);
  752. result.fileTask.Finished = true;
  753. }
  754. private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
  755. {
  756. var retList = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
  757. if (userid != null)
  758. {
  759. retList = retList.Where(s => s.StaffId == userid);
  760. }
  761. var retData2 = retList.GroupBy(s => new { s.CalMonthId, s.StaffId, s.jxType })
  762. .Select(g => new
  763. {
  764. StaffId = g.Key.StaffId,
  765. CalMonthId = g.Key.CalMonthId,
  766. jxType = g.Key.jxType,
  767. FinianlPoint = g.Sum(s => s.FinianlPoint),
  768. totalBasePoint = g.Sum(s => s.totalBasePoint),
  769. totalActuallyPoint = g.Sum(s => s.totalActuallyPoint)
  770. });
  771. List<StaffStatistics> temList = new List<StaffStatistics>();
  772. foreach (var key in retData2)
  773. {
  774. temList.Add(new StaffStatistics()
  775. {
  776. StaffId = key.StaffId,
  777. CalMonthId = key.CalMonthId,
  778. jxType = key.jxType,
  779. totalBasePoint = key.totalBasePoint,
  780. totalActuallyPoint = key.totalActuallyPoint,
  781. FinianlPoint = key.FinianlPoint
  782. });
  783. }
  784. return temList;
  785. #region old code
  786. ////未归档,从绩效记录中统计数据
  787. //var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
  788. //if (userid != null)
  789. //{
  790. // results = Context.PerformanceItems.Where<PerformanceItem>(s =>
  791. // (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  792. // && s.CalMonth.Id == calMonth.Id);
  793. //}
  794. //List<PerformanceItem> ItemList = results
  795. // .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  796. // .Include(pi => pi.Reviewer).ThenInclude(p=>p.StaffGrade)
  797. // .Include(pi => pi.Customer)
  798. // .OrderByDescending(o => o.Id)
  799. // .ToList<PerformanceItem>();
  800. //List<StaffStatistics> retList = new List<StaffStatistics>();
  801. //List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  802. //var Rules = Context.BasePointRules.ToList();
  803. //foreach (PerformanceItem item in ItemList)
  804. //{
  805. // //if (item.BasePoint == null)
  806. // //{
  807. // if (item.AgentFeedbackMemo != "特殊点数申诉")
  808. // {
  809. // Utility.Utility.CalBasePoint(item, Rules);
  810. // Context.SaveChanges();
  811. // }
  812. // //}
  813. // if (item.BasePoint != null && item.BasePoint.Value > 0)
  814. // {
  815. // double doPersonBasePoint = item.BasePoint.Value;
  816. // List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
  817. // List<StaffStatistics> temItemStatics;
  818. // if (userid != null)
  819. // {
  820. // temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
  821. // }
  822. // else
  823. // {
  824. // temItemStatics = itemStatistics;
  825. // }
  826. // foreach (StaffStatistics retUserValue in temItemStatics)
  827. // {
  828. // var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
  829. // if (temValue != null)
  830. // {
  831. // temValue.totalBasePoint += retUserValue.totalBasePoint;
  832. // temValue.totalActuallyPoint += retUserValue.totalActuallyPoint;
  833. // }
  834. // else
  835. // {
  836. // retList.Add(retUserValue);
  837. // }
  838. // }
  839. // }
  840. //}
  841. //if (userid != null)
  842. //{
  843. // retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
  844. //}
  845. //return retList;
  846. #endregion
  847. }
  848. private void _RefreshBasePoint()
  849. {
  850. spDbContext spDb = new spDbContext();
  851. var calMonth = spDb.CalMonths.FirstOrDefault(c => c.Status == 0);
  852. _RefreshBasePoint(calMonth, spDb);
  853. StatisticsLevelCount(calMonth.Year, calMonth.Month);
  854. }
  855. private void _RefreshBasePoint(CalMonth calMonth, spDbContext spDb)
  856. {
  857. if (calMonth != null)
  858. {
  859. var lstItem = spDb.PerformanceItems
  860. .Include(p => p.Customer)
  861. .Include(p => p.ItemStaffs)
  862. .Include(p => p.Reviewer)
  863. .Include(p => p.CalMonth)
  864. .Where(p => p.CalMonthId == calMonth.Id).ToList();
  865. var rules = spDb.BasePointRules.ToList();
  866. foreach (var item in lstItem)
  867. {
  868. try
  869. {
  870. Utility.Utility.CalBasePoint(item, rules);
  871. if (item.BasePoint > 0)
  872. {
  873. _calItemJX(item, spDb);
  874. }
  875. else
  876. {
  877. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == item.Id);
  878. spDb.StaffStatistics.RemoveRange(oldJxList);
  879. }
  880. spDb.SaveChanges();
  881. }
  882. catch (Exception ex)
  883. {
  884. System.Diagnostics.Debug.WriteLine(ex.Message);
  885. }
  886. }
  887. _CalJXPoint(calMonth, spDb);
  888. }
  889. }
  890. public ApiSaveResponse RefreshBasePoint()
  891. {
  892. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  893. t.Start();
  894. return new ApiSaveResponse() {
  895. Success = true
  896. };
  897. }
  898. public void RefreshPoint(PerformanceItem item)
  899. {
  900. //spDbContext spDb = new spDbContext();
  901. var rules = Context.BasePointRules.ToList();
  902. if (item.AgentFeedbackMemo != "特殊点数申诉")
  903. {
  904. Utility.Utility.CalBasePoint(item, rules);
  905. if (item.BasePoint > 0)
  906. {
  907. _calItemJX(item, Context);
  908. }
  909. else
  910. {
  911. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  912. Context.StaffStatistics.RemoveRange(oldJxList);
  913. }
  914. Context.SaveChanges();
  915. }
  916. }
  917. private int? GetStaff(string v)
  918. {
  919. if (!string.IsNullOrEmpty(v))
  920. {
  921. string temName = v.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  922. if (!v.Contains("君龙"))
  923. {
  924. temName = v;
  925. }
  926. var staff = Context.Staffs.Where<Staff>(s => s.Name == temName).FirstOrDefault();
  927. if (staff != null)
  928. {
  929. return staff.Id;
  930. }
  931. }
  932. return null;
  933. }
  934. public ApiSaveResponse UpdateOAStaff()
  935. {
  936. string strExcelFile = @"c:\temp\每月绩效统计--中国一次OA授权表.xlsx";
  937. DataTable dt = NPOIExcel.ExcelToDataTable(strExcelFile, true, false);
  938. foreach(DataRow row in dt.Rows)
  939. {
  940. string strCaseNo = row["我方文号"].ToString().Trim();
  941. string strDoItem ="发明一次OA授权"; //row["处理事项"].ToString().Trim();
  942. PerformanceItem item = Context.PerformanceItems
  943. .Where<PerformanceItem>(p => p.CaseNo == strCaseNo &&
  944. p.DoItem == strDoItem
  945. && p.CalMonth.Status == 0)
  946. .Include(p => p.Reviewer)
  947. .Include(p => p.CalMonth)
  948. .Include(p => p.Customer)
  949. .Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson)
  950. .FirstOrDefault();
  951. if(item != null)
  952. {
  953. string strHandler = strHandler = row["处理事项处理人"].ToString().Trim();
  954. string[] temHandlers = strHandler.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  955. item.ItemStaffs = item.ItemStaffs;
  956. if(item.ItemStaffs == null)
  957. {
  958. item.ItemStaffs = new List<ItemStaff>();
  959. }
  960. foreach (string name in temHandlers)
  961. {
  962. ItemStaff itemStaff = new ItemStaff();
  963. string temName = name.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0];
  964. if (!name.Contains("君龙"))
  965. {
  966. temName = name.Trim();
  967. }
  968. int? iTem = GetStaff(temName);
  969. if ((iTem != null))
  970. {
  971. //itemStaff.Item = item;
  972. itemStaff.DoPersonId = iTem.Value;
  973. if (item.ItemStaffs.Where(itemS => itemS.DoPersonId == iTem.Value).Count() == 0)
  974. {
  975. item.ItemStaffs.Add(itemStaff);
  976. }
  977. }
  978. else
  979. {
  980. itemStaff.DoPerson = new Staff()
  981. {
  982. Name = temName,
  983. Account = temName,
  984. Password = utility.MD5Utility.GetMD5("12345678"),
  985. IsCalPerformsnce = false,
  986. Status = "试用期",
  987. StaffGradeId = 4
  988. };
  989. item.ItemStaffs.Add(itemStaff);
  990. }
  991. }
  992. }
  993. Context.SaveChanges();
  994. }
  995. return new ApiSaveResponse()
  996. {
  997. Success = true
  998. };
  999. }
  1000. public ApiSaveResponse RefreshFromIPEasyById(int itemId)
  1001. {
  1002. var Item = Context.PerformanceItems.Include(p => p.Customer).Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson).FirstOrDefault(p => p.Id == itemId);
  1003. if (Item != null)
  1004. {
  1005. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  1006. }
  1007. Utility.Utility.CalBasePoint(Item, Context.BasePointRules.ToList());
  1008. if (Item.BasePoint > 0)
  1009. {
  1010. _calItemJX(Item, Context);
  1011. }
  1012. else
  1013. {
  1014. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == Item.Id);
  1015. Context.StaffStatistics.RemoveRange(oldJxList);
  1016. }
  1017. Context.SaveChanges();
  1018. return new ApiSaveResponse()
  1019. {
  1020. Success = true
  1021. };
  1022. }
  1023. public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
  1024. {
  1025. new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
  1026. return new ApiSaveResponse()
  1027. {
  1028. Success = true
  1029. };
  1030. }
  1031. public ApiSaveResponse RefreshFromIPEasy(string CaseNo, string DoItem, string caseStage)
  1032. {
  1033. var Item = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault(p => p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
  1034. if (Item != null)
  1035. {
  1036. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  1037. }
  1038. return new ApiSaveResponse()
  1039. {
  1040. Success = true
  1041. };
  1042. }
  1043. public ApiSaveResponse CompareExcel2DB()
  1044. {
  1045. System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
  1046. t.Start();
  1047. return new ApiSaveResponse()
  1048. {
  1049. Success = true
  1050. };
  1051. }
  1052. public FileProcessTask CurrentData2Excel(int Year,int Month)
  1053. {
  1054. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == Year && c.Month == Month);
  1055. if (calMonth != null)
  1056. {
  1057. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  1058. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  1059. var filePath = Path.Combine(attachfileSavePath, filename);
  1060. var fileTask = new FileProcessTask()
  1061. {
  1062. Id = Guid.NewGuid().ToString(),
  1063. FileName = filename,
  1064. FilePath = filePath,
  1065. Processed = 0
  1066. };
  1067. fileTaskService.Add(fileTask);
  1068. ExportDataResult result = new ExportDataResult() {
  1069. fileTask = fileTask,
  1070. calMonth = calMonth
  1071. };
  1072. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(Export2ExcelThread));
  1073. t.Start(result);
  1074. return fileTask;
  1075. }
  1076. return null;
  1077. }
  1078. internal class ExportDataResult
  1079. {
  1080. public FileProcessTask fileTask { get; set; }
  1081. public CalMonth calMonth { get; set; }
  1082. }
  1083. private void Export2ExcelThread(object attfile)
  1084. {
  1085. ExportDataResult result = (ExportDataResult)attfile;
  1086. FileProcessTask file = result.fileTask;
  1087. spDbContext spDb = new spDbContext();
  1088. List<PerformanceItem> items = spDb.PerformanceItems
  1089. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  1090. .Include(p => p.PreOastaff)
  1091. .Include(p => p.Customer)
  1092. .Include(p => p.CalMonth)
  1093. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  1094. .Where(p => p.CalMonth.Id == result.calMonth.Id && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  1095. DataTable dt = new DataTable();
  1096. #region 栏位名称
  1097. dt.Columns.Add("我方文号", typeof(string));
  1098. dt.Columns.Add("申请类型", typeof(string));
  1099. dt.Columns.Add("业务类型", typeof(string));
  1100. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  1101. dt.Columns.Add("处理事项", typeof(string));
  1102. dt.Columns.Add("案件阶段", typeof(string));
  1103. dt.Columns.Add("案件系数", typeof(string));
  1104. dt.Columns.Add("处理事项系数", typeof(string));
  1105. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  1106. dt.Columns.Add("前一次OA处理人", typeof(string));
  1107. dt.Columns.Add("处理人等级", typeof(string));
  1108. dt.Columns.Add("基本点数", typeof(string));
  1109. dt.Columns.Add("核稿系数", typeof(string));
  1110. dt.Columns.Add("核稿绩效", typeof(string));
  1111. dt.Columns.Add("处理人", typeof(string));
  1112. dt.Columns.Add("核稿人", typeof(string));
  1113. dt.Columns.Add("客户名称", typeof(string));
  1114. dt.Columns.Add("申请人", typeof(string));
  1115. dt.Columns.Add("处理事项完成日", typeof(string));
  1116. dt.Columns.Add("定稿日", typeof(string));
  1117. dt.Columns.Add("返稿日", typeof(string));
  1118. dt.Columns.Add("案件类型", typeof(string));
  1119. dt.Columns.Add("案件状态", typeof(string));
  1120. dt.Columns.Add("处理事项备注", typeof(string));
  1121. dt.Columns.Add("处理状态", typeof(string));
  1122. dt.Columns.Add("案件名称", typeof(string));
  1123. dt.Columns.Add("委案日期", typeof(string));
  1124. dt.Columns.Add("客户期限", typeof(string));
  1125. dt.Columns.Add("内部期限", typeof(string));
  1126. dt.Columns.Add("初稿日", typeof(string));
  1127. dt.Columns.Add("翻译字数", typeof(string));
  1128. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因", typeof(string));
  1129. dt.Columns.Add("绩效类型", typeof(string));
  1130. dt.Columns.Add("案件备注", typeof(string));
  1131. dt.Columns.Add("处理人绩效系数", typeof(string));
  1132. dt.Columns.Add("系统核算绩效", typeof(string));
  1133. dt.Columns.Add("实际处理人", typeof(string));
  1134. #endregion
  1135. var verifyCeoffients = spDb.VerifyCoefficients.ToList();
  1136. var Rules = spDb.BasePointRules.ToList();
  1137. file.Size = items.Count;
  1138. foreach (var p in items)
  1139. {
  1140. List<ItemStaff> temItemStaffs = p.ItemStaffs.ToList();
  1141. string strCaseMemo = "";
  1142. string strHandler = "";
  1143. temItemStaffs = new List<ItemStaff>();
  1144. foreach (var iStaff in p.ItemStaffs)
  1145. {
  1146. strHandler = string.IsNullOrEmpty(strHandler) ? iStaff.DoPerson.Name : $"{strHandler},{iStaff.DoPerson.Name}";
  1147. if (iStaff.DoPerson.Status == "试用期")
  1148. {
  1149. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}在试用期" : $"{strCaseMemo},{iStaff.DoPerson.Name}在试用期";
  1150. }
  1151. else
  1152. {
  1153. if (!iStaff.DoPerson.IsCalPerformsnce)
  1154. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}不计算绩效" : $"{strCaseMemo},{iStaff.DoPerson.Name}不计算绩效";
  1155. }
  1156. if (iStaff.DoPersonId == p.ReviewerId)
  1157. {
  1158. strCaseMemo = String.IsNullOrEmpty(strCaseMemo) ? "核稿人与处理人相同" : $"{strCaseMemo},核稿人与处理人相同";
  1159. }
  1160. }
  1161. var staffStatics = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).Where(s => s.ItemId == p.Id && s.jxType.Contains("处理"));
  1162. var reviewStatic = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).FirstOrDefault(s => s.ItemId == p.Id && s.jxType.Contains("审核"));
  1163. foreach (var iStaff in staffStatics.ToList())
  1164. {
  1165. DataRow row = dt.NewRow();
  1166. row["我方文号"] = p.CaseNo;
  1167. row["申请类型"] = p.ApplicationType;
  1168. row["实际处理人"] = strHandler;
  1169. if (p.ApplicationName != null && p.ApplicationName.Contains("OPPO") && p.ApplicationType == "实用新型" && p.Type == "新申请")
  1170. {
  1171. row["申请类型"] = "发明";
  1172. row["案件备注"] = $"{row["案件备注"]}\r\n【OPPO案件实用新型修改为发明】";
  1173. }
  1174. row["处理事项"] = p.DoItem;
  1175. row["业务类型"] = p.BusinessType;
  1176. row["备注(填表注意事项)"] = p.AgentFeedbackMemo;
  1177. if (p.Type == "专案")
  1178. {
  1179. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]}【主管给定点数】专案";
  1180. row["处理事项"] = "提出报告";
  1181. }
  1182. if (p.ItemStaffs.Count() > 1)
  1183. {
  1184. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]},{strHandler}合写";
  1185. }
  1186. row["案件阶段"] = p.CaseStage;
  1187. row["案件系数"] = p.CaseCoefficient;
  1188. if (p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo) && p.Type == "新申请")
  1189. {
  1190. switch (p.CaseCoefficient)
  1191. {
  1192. case "S":
  1193. row["案件系数"] = "A";
  1194. break;
  1195. case "A":
  1196. row["案件系数"] = "B";
  1197. break;
  1198. case "B":
  1199. row["案件系数"] = "C";
  1200. break;
  1201. case "C":
  1202. row["案件系数"] = "D";
  1203. break;
  1204. }
  1205. row["案件备注"] = $"{row["案件备注"]}\r\n严重延期降系数【{p.CaseCoefficient}->{row["案件系数"]}】";
  1206. }
  1207. row["处理事项系数"] = p.DoItemCoefficient;
  1208. row["前一次OA处理事项系数"] = "";
  1209. row["前一次OA处理人"] = p.PreOastaff?.Name;
  1210. row["处理人"] = iStaff.Staff.Name;
  1211. row["基本点数"] = iStaff.totalBasePoint;
  1212. row["处理人等级"] = iStaff.Staff.StaffGrade.Grade;
  1213. row["处理人绩效系数"] = iStaff.Staff.StaffGrade.Coefficient;
  1214. if (reviewStatic != null)
  1215. {
  1216. row["核稿人"] = reviewStatic.Staff.Name;
  1217. var v = verifyCeoffients.FirstOrDefault(p => p.CheckerId == reviewStatic.Staff.StaffGradeId && p.DoPersonId == iStaff.Staff.StaffGradeId);
  1218. if (v != null)
  1219. {
  1220. row["核稿绩效"] = ((decimal)iStaff.totalBasePoint * (decimal)v.Coefficient);
  1221. row["核稿系数"] = v.Coefficient;
  1222. }
  1223. }
  1224. row["客户名称"] = p.Customer?.Name;
  1225. row["申请人"] = p.ApplicationName;
  1226. row["处理事项完成日"] = p.FinishedDate?.ToString("yyyy-MM-dd");
  1227. row["定稿日"] = p.FinalizationDate?.ToString("yyyy-MM-dd");
  1228. row["返稿日"] = p.ReturnDate?.ToString("yyyy-MM-dd");
  1229. row["案件类型"] = p.CaseType;
  1230. row["案件状态"] = p.CaseState;
  1231. row["处理事项备注"] = p.DoItemMemo;
  1232. row["处理状态"] = p.DoItemState;
  1233. row["案件名称"] = p.CaseName;
  1234. row["委案日期"] = p.EntrustingDate?.ToString("yyyy-MM-dd");
  1235. row["客户期限"] = p.CustomerLimitDate?.ToString("yyyy-MM-dd");
  1236. row["内部期限"] = p.InternalDate?.ToString("yyyy-MM-dd");
  1237. row["初稿日"] = p.FirstDraftDate?.ToString("yyyy-MM-dd");
  1238. row["翻译字数"] = p.WordCount;
  1239. row["备注(发文严重超期是否属客观原因,若为否,请填写原因"] = p.OverDueMemo;
  1240. row["绩效类型"] = p.Type;
  1241. row["案件备注"] = $"{p.CaseMemo}\r\n{row["案件备注"]}";
  1242. if (!string.IsNullOrEmpty(strCaseMemo))
  1243. {
  1244. row["案件备注"] = $"{strCaseMemo}\r\n{row["案件备注"]}";
  1245. }
  1246. dt.Rows.Add(row);
  1247. }
  1248. file.Processed += 1;
  1249. }
  1250. NPOIExcel.DataTableToExcel(dt, file.FilePath);
  1251. file.Finished = true;
  1252. }
  1253. private void _CompareExcel2DB()
  1254. {
  1255. DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0, 2);
  1256. DataTable retTable = new DataTable();
  1257. retTable.Columns.Add("我方文号");
  1258. retTable.Columns.Add("申请类型");
  1259. retTable.Columns.Add("业务类型");
  1260. retTable.Columns.Add("备注(填表注意事项)");
  1261. retTable.Columns.Add("备注(填表注意事项)【系统】");
  1262. retTable.Columns.Add("处理事项");
  1263. retTable.Columns.Add("处理事项【系统】");
  1264. retTable.Columns.Add("案件阶段");
  1265. retTable.Columns.Add("案件阶段【系统】");
  1266. retTable.Columns.Add("案件系数");
  1267. retTable.Columns.Add("案件系数【系统】");
  1268. retTable.Columns.Add("处理事项系数");
  1269. retTable.Columns.Add("处理事项系数【系统】");
  1270. retTable.Columns.Add("处理人等级");
  1271. retTable.Columns.Add("处理人等级【系统】");
  1272. retTable.Columns.Add("处理人系数");
  1273. retTable.Columns.Add("处理人系数【系统】");
  1274. retTable.Columns.Add("基本点数");
  1275. retTable.Columns.Add("基本点数【系统】");
  1276. retTable.Columns.Add("核稿系数");
  1277. retTable.Columns.Add("核稿系数【系统】");
  1278. retTable.Columns.Add("核稿绩效");
  1279. retTable.Columns.Add("核稿绩效【系统】");
  1280. retTable.Columns.Add("处理人");
  1281. retTable.Columns.Add("处理人【系统】");
  1282. retTable.Columns.Add("核稿人");
  1283. retTable.Columns.Add("核稿人【系统】");
  1284. retTable.Columns.Add("严重超期备注原因");
  1285. retTable.Columns.Add("严重超期备注原因【系统】");
  1286. retTable.Columns.Add("是否一致");
  1287. retTable.Columns.Add("不一致原因");
  1288. spDbContext spDb = new spDbContext();
  1289. List<PerformanceItem> items = spDb.PerformanceItems
  1290. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  1291. .Include(p => p.Customer)
  1292. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  1293. .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  1294. excelDT.DefaultView.Sort = "我方文号,处理事项";
  1295. DataTable temDt = excelDT.DefaultView.ToTable();
  1296. int iTable = 0;
  1297. int iList = 0;
  1298. CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p => p.Status == 0);
  1299. var verifyCoefficients = spDb.VerifyCoefficients.ToList();
  1300. var Rules = spDb.BasePointRules.ToList();
  1301. while (iTable < temDt.Rows.Count && iList < items.Count)
  1302. {
  1303. System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
  1304. DataRow row = temDt.Rows[iTable];
  1305. PerformanceItem item = items[iList];
  1306. if (row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString() == "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
  1307. {
  1308. var temRow = retTable.NewRow();
  1309. int iBegin = iTable;
  1310. int iEnd = iTable;
  1311. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1312. if (iEnd < temDt.Rows.Count - 1)
  1313. {
  1314. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1315. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1316. {
  1317. iEnd++;
  1318. }
  1319. }
  1320. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1321. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1322. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1323. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1324. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1325. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1326. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1327. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1328. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1329. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1330. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1331. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1332. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1333. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1334. for (int i = iBegin; i <= iEnd; i++)
  1335. {
  1336. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1337. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1338. temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
  1339. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1340. {
  1341. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1342. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1343. }
  1344. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1345. }
  1346. iTable = iEnd;
  1347. #endregion
  1348. Utility.Utility.CalBasePoint(item, Rules);
  1349. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1350. try
  1351. {
  1352. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1353. }
  1354. catch { }
  1355. temRow["案件阶段【系统】"] = item.CaseStage;
  1356. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1357. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1358. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1359. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1360. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1361. temRow["严重超期备注原因"] = item.OverDueMemo;
  1362. if (retPoints != null && retPoints.Count > 0)
  1363. {
  1364. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
  1365. foreach (var itemStaff in item.ItemStaffs)
  1366. {
  1367. //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1368. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1369. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1370. if (item.ReviewerId != null)
  1371. {
  1372. #region 取审核人等级审核等级系数
  1373. VerifyCoefficient vcoefficient
  1374. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1375. v.CheckerId == item.Reviewer.StaffGradeId
  1376. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1377. .FirstOrDefault<VerifyCoefficient>();
  1378. #endregion
  1379. if (vcoefficient != null)
  1380. {
  1381. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1382. }
  1383. }
  1384. }
  1385. }
  1386. temRow["是否一致"] = "";
  1387. temRow["不一致原因"] = "";
  1388. if (temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
  1389. {
  1390. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
  1391. }
  1392. if (temRow["案件系数【系统】"].ToString().Trim() != temRow["案件系数"].ToString().Trim())
  1393. {
  1394. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件系数" : $"{temRow["不一致原因"]},案件系数";
  1395. }
  1396. if (temRow["处理事项系数【系统】"].ToString().Trim() != temRow["处理事项系数"].ToString().Trim())
  1397. {
  1398. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "处理事项系数" : $"{temRow["不一致原因"]},处理事项系数";
  1399. }
  1400. if (temRow["核稿人【系统】"].ToString().Trim() != temRow["核稿人"].ToString().Trim())
  1401. {
  1402. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "核稿人" : $"{temRow["不一致原因"]},核稿人";
  1403. }
  1404. if (temRow["基本点数【系统】"].ToString().Trim() != temRow["基本点数"].ToString().Trim())
  1405. {
  1406. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "基本点数" : $"{temRow["不一致原因"]},基本点数";
  1407. }
  1408. if (temRow["严重超期备注原因【系统】"].ToString().Trim() != temRow["严重超期备注原因"].ToString().Trim())
  1409. {
  1410. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "严重超期备注原因" : $"{temRow["不一致原因"]},严重超期备注原因";
  1411. }
  1412. if (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
  1413. {
  1414. temRow["是否一致"] = "不一致";
  1415. }
  1416. retTable.Rows.Add(temRow);
  1417. iTable++;
  1418. iList++;
  1419. }
  1420. else
  1421. {
  1422. string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
  1423. string strList = $"{item.CaseNo}-{item.DoItem}";
  1424. if (strDT.CompareTo(strList) > 0)
  1425. {
  1426. var temRow = retTable.NewRow();
  1427. Utility.Utility.CalBasePoint(item, Rules);
  1428. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1429. try
  1430. {
  1431. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1432. }
  1433. catch { }
  1434. temRow["我方文号"] = item.CaseNo;
  1435. temRow["处理事项"] = item.DoItem;
  1436. temRow["申请类型"] = item.ApplicationType;
  1437. temRow["业务类型"] = item.BusinessType;
  1438. temRow["案件阶段【系统】"] = item.CaseStage;
  1439. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1440. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1441. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1442. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1443. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1444. temRow["严重超期备注原因"] = item.OverDueMemo;
  1445. if (item.ReviewerId != null)
  1446. {
  1447. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1448. }
  1449. foreach (var itemStaff in item.ItemStaffs)
  1450. {
  1451. //if (itemStaff.DoPerson.Status != "试用期")
  1452. //{
  1453. // if (retPoints != null && retPoints.Count > 0)
  1454. // {
  1455. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1456. // }
  1457. //}
  1458. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1459. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1460. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1461. if (item.ReviewerId != null)
  1462. {
  1463. #region 取审核人等级审核等级系数
  1464. VerifyCoefficient vcoefficient
  1465. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1466. v.CheckerId == item.Reviewer.StaffGradeId
  1467. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1468. .FirstOrDefault<VerifyCoefficient>();
  1469. #endregion
  1470. if (vcoefficient != null)
  1471. {
  1472. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1473. }
  1474. }
  1475. }
  1476. temRow["是否一致"] = "不一致";
  1477. temRow["不一致原因"] = "Excel中没有,系统中有";
  1478. retTable.Rows.Add(temRow);
  1479. iList++;
  1480. }
  1481. else
  1482. {
  1483. var temRow = retTable.NewRow();
  1484. int iBegin = iTable;
  1485. int iEnd = iTable;
  1486. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1487. if (iEnd < temDt.Rows.Count - 1)
  1488. {
  1489. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1490. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1491. {
  1492. iEnd++;
  1493. }
  1494. }
  1495. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1496. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1497. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1498. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1499. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1500. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1501. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1502. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1503. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1504. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1505. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1506. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1507. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1508. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1509. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1510. for (int i = iBegin + 1; i <= iEnd; i++)
  1511. {
  1512. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1513. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1514. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1515. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1516. {
  1517. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1518. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1519. }
  1520. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1521. }
  1522. iTable = iEnd;
  1523. #endregion
  1524. temRow["是否一致"] = "不一致";
  1525. temRow["不一致原因"] = "系统中没有,Excel中有";
  1526. retTable.Rows.Add(temRow);
  1527. iTable++;
  1528. }
  1529. }
  1530. }
  1531. if (iList <= items.Count)
  1532. {
  1533. while (iList < items.Count) {
  1534. var item = items[iList];
  1535. var temRow = retTable.NewRow();
  1536. Utility.Utility.CalBasePoint(item, Rules);
  1537. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1538. try
  1539. {
  1540. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1541. }
  1542. catch { }
  1543. temRow["我方文号"] = item.CaseNo;
  1544. temRow["处理事项"] = item.DoItem;
  1545. temRow["申请类型"] = item.ApplicationType;
  1546. temRow["业务类型"] = item.BusinessType;
  1547. temRow["案件阶段【系统】"] = item.CaseStage;
  1548. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1549. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1550. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1551. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1552. temRow["基本点数【系统】"] = "";// item.BasePoint?.ToString();
  1553. temRow["严重超期备注原因"] = item.OverDueMemo;
  1554. if (item.ReviewerId != null)
  1555. {
  1556. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1557. }
  1558. foreach (var itemStaff in item.ItemStaffs)
  1559. {
  1560. //if (itemStaff.DoPerson.Status != "试用期")
  1561. //{
  1562. // if (retPoints != null && retPoints.Count > 0)
  1563. // {
  1564. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1565. // }
  1566. //}
  1567. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1568. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1569. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1570. if (item.ReviewerId != null)
  1571. {
  1572. #region 取审核人等级审核等级系数
  1573. VerifyCoefficient vcoefficient
  1574. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1575. v.CheckerId == item.Reviewer.StaffGradeId
  1576. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1577. .FirstOrDefault<VerifyCoefficient>();
  1578. #endregion
  1579. if (vcoefficient != null)
  1580. {
  1581. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1582. }
  1583. }
  1584. }
  1585. temRow["是否一致"] = "不一致";
  1586. temRow["不一致原因"] = "Excel中没有,系统中有";
  1587. iList++;
  1588. retTable.Rows.Add(temRow);
  1589. }
  1590. }
  1591. else
  1592. {
  1593. while (iTable < temDt.Rows.Count)
  1594. {
  1595. var temRow = retTable.NewRow();
  1596. int iBegin = iTable;
  1597. int iEnd = iTable;
  1598. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1599. while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
  1600. temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
  1601. {
  1602. iEnd++;
  1603. }
  1604. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1605. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1606. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1607. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1608. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1609. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1610. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1611. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1612. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1613. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1614. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1615. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1616. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1617. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1618. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1619. for (int i = iBegin + 1; i <= iEnd; i++)
  1620. {
  1621. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1622. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1623. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1624. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1625. {
  1626. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1627. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1628. }
  1629. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["严重超期备注原因"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["严重超期备注原因"]}";
  1630. }
  1631. iTable = iEnd;
  1632. #endregion
  1633. temRow["是否一致"] = "不一致";
  1634. temRow["不一致原因"] = "系统中没有,Excel中有";
  1635. retTable.Rows.Add(temRow);
  1636. iTable++;
  1637. }
  1638. }
  1639. NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
  1640. }
  1641. public List<StaffStatistics> CalItemJX(int itemid)
  1642. {
  1643. var Item = Context.PerformanceItems.Include(p => p.CalMonth)
  1644. .Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson).ThenInclude(s => s.StaffGrade)
  1645. .Include(p => p.Reviewer)
  1646. .Include(p => p.Customer)
  1647. .FirstOrDefault(p => p.Id == itemid);
  1648. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  1649. return _calItemJX(verifyCoefficients, Item, Context);
  1650. }
  1651. private void _calItemJX(PerformanceItem Item, spDbContext spDb)
  1652. {
  1653. List<VerifyCoefficient> verifyCoefficients = spDb.VerifyCoefficients.ToList<VerifyCoefficient>();
  1654. var jxList = _calItemJX(verifyCoefficients, Item, spDb);
  1655. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == Item.Id);
  1656. spDb.StaffStatistics.RemoveRange(oldJxList);
  1657. spDb.SaveChanges();
  1658. foreach (var jx in jxList)
  1659. {
  1660. if (jx.totalBasePoint == 0)
  1661. {
  1662. continue;
  1663. }
  1664. jx.ItemId = Item.Id;
  1665. spDb.StaffStatistics.Add(jx);
  1666. spDb.SaveChanges();
  1667. }
  1668. }
  1669. /// <summary>
  1670. /// 序号 情况 处理逻辑
  1671. /// 1 处理人试用期算绩效 一人处理 正常算绩效给处理人
  1672. /// 2 处理人试用期不算绩效 一人处理 算给核稿人,如果没有核稿人,这条数据忽略
  1673. /// 3 处理人试用期算绩效 与人合写 合写人算绩效、与合写人一人一半
  1674. /// 4 处理人试用期不算绩效 与人合写 合写人算绩效、全部绩效算给合写人
  1675. /// 5 处理人试用期不算绩效 与人合写 合写人不算算绩效、这条数据忽略
  1676. /// 6 处理人试用期算绩效 与人合写 合写人不算绩效、试用期人员拿一半
  1677. /// 7 处理人不算绩效 一人处理 这条数据忽略
  1678. /// 8 处理人不算绩效 与人合写 合写人算绩效、合写人拿一半
  1679. /// 9 处理人不算绩效 与人合写 合写人不算绩效、这条数据忽略
  1680. /// </summary>
  1681. /// <param name="verifyCoefficients"></param>
  1682. /// <param name="item"></param>
  1683. /// <param name="spDb"></param>
  1684. /// <returns></returns>
  1685. private List<StaffStatistics> _calItemJX(List<VerifyCoefficient> verifyCoefficients, PerformanceItem item, spDbContext spDb)
  1686. {
  1687. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  1688. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  1689. if (item.ReviewerId != null && item.Reviewer == null)
  1690. {
  1691. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  1692. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  1693. }
  1694. List<ItemStaff> temIStaffs = new List<ItemStaff>();
  1695. #region 将试用期且不算绩效的人员从处理人清单中剔除
  1696. int syqUsers = 0;
  1697. foreach(var itemStaff in item.ItemStaffs)
  1698. {
  1699. if (itemStaff.DoPerson == null)
  1700. {
  1701. itemStaff.DoPerson = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == itemStaff.DoPersonId);
  1702. }
  1703. if(itemStaff.DoPerson.Status == "试用期" && !itemStaff.DoPerson.IsCalPerformsnce )
  1704. {
  1705. syqUsers += 1;
  1706. }
  1707. else
  1708. {
  1709. temIStaffs.Add(itemStaff);
  1710. }
  1711. }
  1712. #endregion
  1713. #region 处理人全部是试用期人员,则将核稿人当成处理人(处理人为试用期人)
  1714. if (syqUsers == item.ItemStaffs.Count)
  1715. {
  1716. if(item.Reviewer != null)
  1717. {
  1718. temIStaffs.Add(new ItemStaff() { DoPersonId = item.ReviewerId.Value, ItemId = item.Id });
  1719. }
  1720. }
  1721. #endregion
  1722. bool isPJFP = true;
  1723. double total = temIStaffs.Count();
  1724. if (total >1 && temIStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  1725. {
  1726. total = temIStaffs.Select(i => i.PerformancePoint.Value).Sum();
  1727. isPJFP = false;
  1728. }
  1729. foreach (ItemStaff itemStaff in temIStaffs)
  1730. {
  1731. if(itemStaff.DoPerson == null)
  1732. {
  1733. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  1734. }
  1735. if (itemStaff.DoPerson.IsCalPerformsnce)
  1736. {
  1737. #region 计算各处理人的绩效点数
  1738. double handlerBasePoint;
  1739. if (item.Type != "专案")
  1740. {
  1741. if (isPJFP)
  1742. {
  1743. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1744. }
  1745. else
  1746. {
  1747. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1748. }
  1749. }
  1750. else
  1751. {
  1752. if (itemStaff.PerformancePoint == null)
  1753. {
  1754. if (isPJFP)
  1755. {
  1756. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1757. }
  1758. else
  1759. {
  1760. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1761. }
  1762. }
  1763. else
  1764. {
  1765. if (item.ItemStaffs.Count == 1 )
  1766. {
  1767. handlerBasePoint = item.BasePoint.Value;
  1768. }
  1769. else
  1770. {
  1771. handlerBasePoint = itemStaff.PerformancePoint.Value;
  1772. }
  1773. }
  1774. }
  1775. string handlerJxType = $"{item.Type}处理";
  1776. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
  1777. if (temStatic != null)
  1778. {
  1779. temStatic.totalBasePoint += handlerBasePoint;
  1780. if (item.Type == "OA" || item.Type == "新申请")
  1781. {
  1782. temStatic.totalActuallyPoint += (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient);
  1783. }
  1784. else
  1785. {
  1786. temStatic.totalActuallyPoint += handlerBasePoint;
  1787. }
  1788. }
  1789. else
  1790. {
  1791. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsCalPerformsnce)
  1792. {
  1793. if (item.Type == "OA" || item.Type == "新申请")
  1794. {
  1795. if (itemStaff.DoPerson.StaffGrade == null)
  1796. {
  1797. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s => s.Id == itemStaff.DoPerson.StaffGradeId);
  1798. }
  1799. temStatic = new StaffStatistics()
  1800. {
  1801. //CalMonth = calMonth,
  1802. CalMonthId = item.CalMonthId,
  1803. StaffId = itemStaff.DoPersonId,
  1804. totalActuallyPoint = (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient),
  1805. totalBasePoint = handlerBasePoint,
  1806. jxType = handlerJxType
  1807. };
  1808. itemStatistics.Add(temStatic);
  1809. }
  1810. else
  1811. {
  1812. temStatic = new StaffStatistics()
  1813. {
  1814. //CalMonth = calMonth,
  1815. CalMonthId = item.CalMonthId,
  1816. StaffId = itemStaff.DoPersonId,
  1817. totalBasePoint = handlerBasePoint,
  1818. totalActuallyPoint = handlerBasePoint,
  1819. jxType = handlerJxType
  1820. };
  1821. itemStatistics.Add(temStatic);
  1822. }
  1823. }
  1824. }
  1825. #endregion
  1826. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  1827. if (item.ReviewerId != null && item.Type != "专案" &&
  1828. temIStaffs.FirstOrDefault(s => s.DoPersonId == item.ReviewerId) == null)
  1829. {
  1830. if(item.Reviewer == null)
  1831. {
  1832. item.Reviewer = spDb.Staffs.FirstOrDefault(s=>s.Id == item.ReviewerId);
  1833. }
  1834. if (item.Reviewer.IsCalPerformsnce)
  1835. {
  1836. #region 取审核人等级审核等级系数
  1837. VerifyCoefficient vcoefficient
  1838. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1839. v.CheckerId == item.Reviewer.StaffGradeId
  1840. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1841. .FirstOrDefault<VerifyCoefficient>();
  1842. #endregion
  1843. if (vcoefficient != null)
  1844. {
  1845. double reviewerBasePoint = (double)((decimal)handlerBasePoint * (decimal)vcoefficient.Coefficient);
  1846. string temJxType = $"{item.Type}审核";
  1847. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonthId == item.CalMonthId).FirstOrDefault();
  1848. if (temReviewerStatic != null)
  1849. {
  1850. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  1851. temReviewerStatic.totalActuallyPoint += reviewerBasePoint;
  1852. }
  1853. else
  1854. {
  1855. if (itemStaff.DoPerson.IsCalPerformsnce && item.Reviewer.IsCalPerformsnce) //判断是否在职
  1856. {
  1857. temReviewerStatic = new StaffStatistics()
  1858. {
  1859. CalMonthId = item.CalMonthId,
  1860. StaffId = item.ReviewerId.Value,
  1861. totalBasePoint = reviewerBasePoint,
  1862. totalActuallyPoint = reviewerBasePoint,
  1863. jxType = temJxType
  1864. };
  1865. itemStatistics.Add(temReviewerStatic);
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. #endregion
  1872. }
  1873. }
  1874. return itemStatistics;
  1875. }
  1876. private void _CalJXPoint(CalMonth calMonth,spDbContext spDb)
  1877. {
  1878. NanduStatics gspjXS = DegreeOfDifficulty(calMonth,spDb);
  1879. calMonth.NanduXS = gspjXS.NanduXS;
  1880. calMonth.S = (double)gspjXS.S;
  1881. calMonth.A = (double)gspjXS.A;
  1882. calMonth.B = (double)gspjXS.B;
  1883. calMonth.C = (double)gspjXS.C;
  1884. calMonth.D = (double)gspjXS.D;
  1885. var retList = spDb.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id).ToList();
  1886. #region 新申请处理+专案处理 奖励点数
  1887. double jlPoint = 0;
  1888. if (calMonth.S.HasValue)
  1889. {
  1890. jlPoint = jlPoint + (calMonth.S.Value * 1.5);
  1891. }
  1892. if (calMonth.A.HasValue)
  1893. {
  1894. jlPoint = jlPoint + (calMonth.A.Value * 0.5);
  1895. }
  1896. #endregion
  1897. #region 难度系数
  1898. IDictionary<int, NanduStatics> staffXiShu = new Dictionary<int, NanduStatics>();
  1899. IDictionary<int, NanduStatics> ReivewerXiShu = new Dictionary<int, NanduStatics>();
  1900. foreach (StaffStatistics ss in retList)
  1901. {
  1902. if (ss.jxType == "新申请处理" || ss.jxType == "专案处理")
  1903. {
  1904. #region 新申请处理+专案处理
  1905. if (!staffXiShu.ContainsKey(ss.StaffId))
  1906. {
  1907. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb,false,true);
  1908. staffXiShu.Add(ss.StaffId, nandu);
  1909. }
  1910. ss.FinianlPoint = ss.totalActuallyPoint * staffXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1911. ss.NanduXS = staffXiShu[ss.StaffId].NanduXS;
  1912. ss.S = (double)staffXiShu[ss.StaffId].S;
  1913. ss.A = (double)staffXiShu[ss.StaffId].A;
  1914. ss.B = (double)staffXiShu[ss.StaffId].B;
  1915. ss.C = (double)staffXiShu[ss.StaffId].C;
  1916. ss.D = (double)staffXiShu[ss.StaffId].D;
  1917. #endregion
  1918. }
  1919. else
  1920. {
  1921. if (ss.jxType == "新申请审核")
  1922. {
  1923. if (!ReivewerXiShu.ContainsKey(ss.StaffId))
  1924. {
  1925. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb, true);
  1926. ReivewerXiShu.Add(ss.StaffId, nandu);
  1927. }
  1928. ss.FinianlPoint = ss.totalBasePoint * ReivewerXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1929. ss.NanduXS = ReivewerXiShu[ss.StaffId].NanduXS;
  1930. ss.S = (double)ReivewerXiShu[ss.StaffId].S;
  1931. ss.A = (double)ReivewerXiShu[ss.StaffId].A;
  1932. ss.B = (double)ReivewerXiShu[ss.StaffId].B;
  1933. ss.C = (double)ReivewerXiShu[ss.StaffId].C;
  1934. ss.D = (double)ReivewerXiShu[ss.StaffId].D;
  1935. spDb.SaveChanges();
  1936. }
  1937. else
  1938. {
  1939. ss.FinianlPoint = ss.totalActuallyPoint;
  1940. spDb.SaveChanges();
  1941. }
  1942. }
  1943. }
  1944. var xsqList = retList.Where(ss => ss.jxType == "新申请处理" || ss.jxType == "专案处理").ToList();
  1945. var totalFPBLPoint = xsqList.Sum(p=>p.FinianlPoint); //新申请处理+专案 分配比率总点数
  1946. var totalActionPoint = xsqList.Sum(p=>p.totalActuallyPoint); //新申请处理+专案 原始总点数
  1947. foreach (StaffStatistics ss in xsqList)
  1948. {
  1949. if(totalFPBLPoint * (totalActionPoint + jlPoint) == 0)
  1950. {
  1951. Console.WriteLine("");
  1952. }
  1953. ss.FinianlPoint = ss.FinianlPoint / totalFPBLPoint * (totalActionPoint + jlPoint);
  1954. spDb.SaveChanges();
  1955. }
  1956. #endregion
  1957. }
  1958. public void CalJXPoint(int year, int month)
  1959. {
  1960. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1961. if (calMonth != null)
  1962. {
  1963. using (var t = Context.Database.BeginTransaction())
  1964. {
  1965. try
  1966. {
  1967. var result = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
  1968. Context.StaffStatistics.RemoveRange(result);
  1969. var itemList = Context.PerformanceItems
  1970. .Include(s => s.ItemStaffs)
  1971. .Include(p=>p.Customer)
  1972. .Include(p=>p.Reviewer)
  1973. .Where(s => s.CalMonthId == calMonth.Id).ToList();
  1974. var rules = Context.BasePointRules.ToList();
  1975. foreach (var item in itemList)
  1976. {
  1977. Utility.Utility.CalBasePoint(item, rules);
  1978. Context.SaveChanges();
  1979. if (item.BasePoint > 0)
  1980. {
  1981. _calItemJX(item,Context);
  1982. }
  1983. else
  1984. {
  1985. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  1986. Context.StaffStatistics.RemoveRange(oldJxList);
  1987. }
  1988. }
  1989. _CalJXPoint(calMonth, Context);
  1990. t.Commit();
  1991. }
  1992. catch (Exception ex)
  1993. {
  1994. t.Rollback();
  1995. }
  1996. }
  1997. }
  1998. }
  1999. public ProcessTask FinishedCalMonth(int year,int month)
  2000. {
  2001. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == year && c.Month == month);
  2002. if (calMonth != null)
  2003. {
  2004. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  2005. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  2006. var filePath = Path.Combine(attachfileSavePath, filename);
  2007. var fileTask = new FileProcessTask()
  2008. {
  2009. Id = Guid.NewGuid().ToString(),
  2010. FileName = filename,
  2011. FilePath = filePath,
  2012. Processed = 0
  2013. };
  2014. fileTaskService.Add(fileTask);
  2015. ExportDataResult result = new ExportDataResult()
  2016. {
  2017. fileTask = fileTask,
  2018. calMonth = calMonth
  2019. };
  2020. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(_FinishedCalMonth));
  2021. t.Start(result);
  2022. return fileTask;
  2023. }
  2024. return null;
  2025. }
  2026. /// <summary>
  2027. /// 新申请/专案:
  2028. /// 调整点数 = 分配比例点数/分配比例点数之和*总点数
  2029. /// 等级调整点数+项目组点数之和 = 基础点数 * 代理人等级系数 + 项目组案件调整点数
  2030. /// 分配比例点数 = 个人平均难度系数 / 总平均难度系数 *(等级调整点数+项目组点数之和)
  2031. /// 总点数=等级调整点数+项目组点数之和+奖励点数
  2032. /// 奖励点数= S案数量*1.5 + A案数量 * 0.5
  2033. /// 难度系数=(S案数量*2.5 + A案数量* 1.5 + B案数量*1.0 + C案数量*0.7+ D案数量*0.4) / 总案件数量
  2034. /// 总案件数量= S案数量 + A案数量 + B案数量 + C案数量+ D案数量
  2035. /// OA :
  2036. /// 调整点数= 基础点数 * 等级系数
  2037. /// 其他:
  2038. /// 直接加和基础点数 不需要乘以系数
  2039. /// </summary>
  2040. /// <param name="year"></param>
  2041. /// <param name="month"></param>
  2042. /// <returns></returns>
  2043. private void _FinishedCalMonth(object proecssTask)
  2044. {
  2045. ExportDataResult result = (ExportDataResult)proecssTask;
  2046. CalMonth calMonth = result.calMonth;
  2047. if (calMonth != null || calMonth.Status !=4)
  2048. {
  2049. spDbContext spDb = new spDbContext();
  2050. calMonth = spDb.CalMonths.FirstOrDefault(c=>c.Id == calMonth.Id);
  2051. using (var t = spDb.Database.BeginTransaction())
  2052. {
  2053. try
  2054. {
  2055. _RefreshBasePoint(calMonth, spDb);
  2056. //_CalJXPoint(calMonth, Context);
  2057. calMonth.Status = 4;
  2058. spDb.SaveChanges();
  2059. //等级核算案件统计
  2060. _StatisticsLevelCount(calMonth.Year, calMonth.Month, spDb);
  2061. #region 将待审核的申诉全部修改为已审核
  2062. var aList = spDb.AppealRecords.Where(a => a.State == 0).ToList();
  2063. aList.ForEach(a =>a.State = 1);
  2064. spDb.SaveChanges();
  2065. #endregion
  2066. t.Commit();
  2067. result.fileTask.Finished = true;
  2068. }
  2069. catch (Exception ex)
  2070. {
  2071. t.Rollback();
  2072. result.fileTask.ErrorMessage = ex.Message;
  2073. result.fileTask.Finished = true;
  2074. }
  2075. }
  2076. }
  2077. else
  2078. {
  2079. result.fileTask.ErrorMessage = "指定月份没有数据或者已归档!";
  2080. result.fileTask.Finished = true;
  2081. }
  2082. }
  2083. /// <summary>
  2084. /// 计算指定用户,指定年月的绩效统计信息
  2085. /// </summary>
  2086. /// <param name="userid"></param>
  2087. /// <param name="year"></param>
  2088. /// <param name="month"></param>
  2089. /// <returns></returns>
  2090. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  2091. {
  2092. //object retList;
  2093. //string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
  2094. //if(!MyMemoryCache.TryGetValue(strKey,out retList))
  2095. //{
  2096. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  2097. if (calMonth == null)
  2098. {
  2099. return null;
  2100. }
  2101. else
  2102. {
  2103. return _CalMyStatistics(calMonth, userid);
  2104. #region old code
  2105. //if (calMonth.Status == 4)
  2106. //{
  2107. // //已归档,归档数据库中直接取出记录
  2108. // if (userid == null)
  2109. // {
  2110. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  2111. // }
  2112. // else
  2113. // {
  2114. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  2115. // }
  2116. //}
  2117. //else
  2118. //{
  2119. // try
  2120. // {
  2121. // retList = _CalMyStatistics(calMonth, userid);
  2122. // }
  2123. // catch(Exception ex)
  2124. // {
  2125. // StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  2126. // sw.WriteLine($"{ex.Message}");
  2127. // sw.Flush();
  2128. // sw.Close();
  2129. // sw.Dispose();
  2130. // }
  2131. //}
  2132. //// Set cache options.
  2133. //var cacheEntryOptions = new MemoryCacheEntryOptions()
  2134. // // Keep in cache for this time, reset time if accessed.
  2135. // .SetSlidingExpiration(TimeSpan.FromHours(1));
  2136. //foreach(var temObj in (List<StaffStatistics>)retList)
  2137. //{
  2138. // temObj.CalMonth.PerformanceItems = null;
  2139. //}
  2140. //// Save data in cache.
  2141. //MyMemoryCache.SetValue(strKey, retList);
  2142. //return (List<StaffStatistics>)retList;
  2143. #endregion
  2144. }
  2145. //}
  2146. //else
  2147. //{
  2148. // var temList = (List<StaffStatistics>)retList;
  2149. // foreach (var temObj in temList)
  2150. // {
  2151. // temObj.CalMonth.PerformanceItems = null;
  2152. // }
  2153. // return temList;
  2154. //}
  2155. }
  2156. private string GetExpress(IList<FieldCondition> conditions)
  2157. {
  2158. string str = "";
  2159. foreach(var c in conditions)
  2160. {
  2161. if (string.IsNullOrEmpty(str))
  2162. {
  2163. str = c.ToExpressString("s");
  2164. }
  2165. else
  2166. {
  2167. if(c.LogicOperate == LogicEnum.And)
  2168. {
  2169. str = $"({str}) && {c.ToExpressString("s")}";
  2170. }
  2171. else
  2172. {
  2173. str = $"({str}) || {c.ToExpressString("s")}";
  2174. }
  2175. }
  2176. }
  2177. return str;
  2178. }
  2179. [HttpGet,HttpPost]
  2180. public FileProcessTask ExportData(QueryFilter queryFilter)
  2181. {
  2182. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  2183. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  2184. var filePath = Path.Combine(attachfileSavePath, filename);
  2185. var fileTask = new FileProcessTask()
  2186. {
  2187. Id = Guid.NewGuid().ToString(),
  2188. FileName = filename,
  2189. FilePath = filePath,
  2190. Processed = 0
  2191. };
  2192. fileTaskService.Add(fileTask);
  2193. ThreadObject threadObject = new ThreadObject()
  2194. {
  2195. queryFilter = queryFilter,
  2196. fileTask = fileTask
  2197. };
  2198. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  2199. t.Start(threadObject);
  2200. return fileTask;
  2201. }
  2202. internal class ThreadObject
  2203. {
  2204. public QueryFilter queryFilter { get; set; }
  2205. public FileProcessTask fileTask { get; set; }
  2206. }
  2207. private void ExportDataThread(object tObj)
  2208. {
  2209. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  2210. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  2211. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2212. var retList = response
  2213. .Include(p=>p.Customer)
  2214. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  2215. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  2216. .Include(p=>p.PreOastaff)
  2217. .Include(p=>p.CalMonth)
  2218. .ToList<PerformanceItem>();
  2219. DataTable dt = new DataTable();
  2220. #region 添加栏位
  2221. dt.Columns.Add("我方文号",typeof(string));
  2222. dt.Columns.Add("申请类型", typeof(string));
  2223. dt.Columns.Add("业务类型", typeof(string));
  2224. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  2225. dt.Columns.Add("处理事项", typeof(string));
  2226. dt.Columns.Add("案件阶段", typeof(string));
  2227. dt.Columns.Add("案件系数", typeof(string));
  2228. dt.Columns.Add("处理事项系数", typeof(string));
  2229. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  2230. dt.Columns.Add("前一次OA处理人", typeof(string));
  2231. dt.Columns.Add("处理人等级", typeof(string));
  2232. dt.Columns.Add("基本点数", typeof(string));
  2233. dt.Columns.Add("核稿系数", typeof(string));
  2234. dt.Columns.Add("核稿绩效", typeof(string));
  2235. dt.Columns.Add("处理人", typeof(string));
  2236. dt.Columns.Add("核稿人", typeof(string));
  2237. dt.Columns.Add("客户名称", typeof(string));
  2238. dt.Columns.Add("申请人", typeof(string));
  2239. dt.Columns.Add("处理事项完成日", typeof(string));
  2240. dt.Columns.Add("定稿日", typeof(string));
  2241. dt.Columns.Add("返稿日", typeof(string));
  2242. dt.Columns.Add("案件类型", typeof(string));
  2243. dt.Columns.Add("案件状态", typeof(string));
  2244. dt.Columns.Add("处理事项备注", typeof(string));
  2245. dt.Columns.Add("处理状态", typeof(string));
  2246. dt.Columns.Add("案件名称", typeof(string));
  2247. dt.Columns.Add("委案日期", typeof(string));
  2248. dt.Columns.Add("客户期限", typeof(string));
  2249. dt.Columns.Add("内部期限", typeof(string));
  2250. dt.Columns.Add("初稿日", typeof(string));
  2251. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
  2252. dt.Columns.Add("备注", typeof(string));
  2253. #endregion
  2254. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  2255. fileTask.Size = retList.Count;
  2256. foreach (var item in retList)
  2257. {
  2258. fileTask.Processed += 1;
  2259. if (item.CaseNo.StartsWith("J"))
  2260. {
  2261. continue;
  2262. }
  2263. try
  2264. {
  2265. var row = dt.NewRow();
  2266. row["我方文号"] = item.CaseNo;
  2267. row["申请类型"] = item.ApplicationType;
  2268. row["业务类型"] = item.BusinessType;
  2269. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  2270. row["处理事项"] = item.DoItem;
  2271. row["案件阶段"] = item.CaseStage;
  2272. row["案件系数"] = item.CaseCoefficient;
  2273. row["处理事项系数"] = item.DoItemCoefficient;
  2274. row["前一次OA处理事项系数"] = "";
  2275. if (item.PreOastaffId.HasValue)
  2276. {
  2277. row["前一次OA处理人"] = item.PreOastaff?.Name;
  2278. }
  2279. string strISLevels = "";
  2280. string strISNames = "";
  2281. foreach (var istaff in item.ItemStaffs)
  2282. {
  2283. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  2284. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  2285. }
  2286. row["处理人等级"] = strISLevels;
  2287. row["基本点数"] = item.BasePoint;
  2288. row["处理人"] = strISNames;
  2289. row["核稿人"] = item.Reviewer?.Name;
  2290. if (item.ReviewerId != null && item.BasePoint.HasValue)
  2291. {
  2292. System.Diagnostics.Debug.WriteLine($"{item.ReviewerId}");
  2293. var jxList = new spDbContext().StaffStatistics.Where<StaffStatistics>(s => s.ItemId == item.Id).ToList();//_calItemJX( verifyCoefficients, item, new spDbContext());
  2294. row["核稿系数"] = "";
  2295. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  2296. if (temJx != null)
  2297. {
  2298. row["核稿绩效"] = temJx.totalBasePoint;
  2299. }
  2300. }
  2301. row["客户名称"] = item.Customer?.Name;
  2302. row["申请人"] = item.ApplicationName;
  2303. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  2304. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  2305. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  2306. row["案件类型"] = item.CaseType;
  2307. row["案件状态"] = item.CaseState;
  2308. row["处理事项备注"] = item.DoItemState;
  2309. row["处理状态"] = item.DoItemState;
  2310. row["案件名称"] = item.CaseName;
  2311. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  2312. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  2313. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  2314. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  2315. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  2316. row["备注"] = item.DoItemMemo;
  2317. dt.Rows.Add(row);
  2318. }
  2319. catch(Exception ex)
  2320. {
  2321. throw ex;
  2322. }
  2323. }
  2324. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  2325. fileTask.Finished = true;
  2326. }
  2327. [HttpPost]
  2328. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  2329. {
  2330. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  2331. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2332. int totals = response.ToList<PerformanceItem>().Count;
  2333. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  2334. {
  2335. response = response
  2336. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2337. .Include(pi => pi.Reviewer)
  2338. .Include(pi => pi.Customer)
  2339. .Include(pi => pi.CalMonth)
  2340. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2341. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  2342. }
  2343. else
  2344. {
  2345. response = response
  2346. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2347. .Include(pi => pi.Reviewer)
  2348. .Include(pi => pi.Customer)
  2349. .Include(pi => pi.CalMonth)
  2350. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2351. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  2352. }
  2353. ret.TotalCount = totals;
  2354. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  2355. #region 将某些属性设为null,避免循环取值造成返回json过大
  2356. foreach (PerformanceItem item in retList)
  2357. {
  2358. foreach (ItemStaff itemStaff in item.ItemStaffs)
  2359. {
  2360. itemStaff.DoPerson.ItemStaffs = null;
  2361. itemStaff.DoPerson.ReviewerItems = null;
  2362. itemStaff.DoPerson.Customers = null;
  2363. itemStaff.Item = null;
  2364. }
  2365. if (item.Reviewer != null)
  2366. {
  2367. item.Reviewer.ReviewerItems = null;
  2368. item.Reviewer.Customers = null;
  2369. item.Reviewer.ItemStaffs = null;
  2370. }
  2371. if (item.WorkflowUser != null)
  2372. {
  2373. item.WorkflowUser.ReviewerItems = null;
  2374. item.WorkflowUser.Customers = null;
  2375. item.WorkflowUser.ItemStaffs = null;
  2376. }
  2377. if (item.Customer != null)
  2378. {
  2379. item.Customer.PerformanceItems = null;
  2380. item.Customer.ResponseMan = null;
  2381. }
  2382. if (item.CalMonth != null)
  2383. {
  2384. item.CalMonth.PerformanceItems = null;
  2385. }
  2386. }
  2387. #endregion
  2388. ret.Results = retList.ToList();
  2389. //string str= System.Text.Json.JsonSerializer.Serialize(ret);
  2390. return ret;
  2391. }
  2392. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  2393. {
  2394. string strExpress = "";
  2395. string strCalMonth = "";
  2396. if (queryFilter.CalMonthId.HasValue)
  2397. {
  2398. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  2399. }
  2400. else
  2401. {
  2402. if(queryFilter.jxType == jxType.finished)
  2403. {
  2404. strCalMonth = $"s.CalMonth.Status == 4";
  2405. }
  2406. else
  2407. {
  2408. strCalMonth = $"s.CalMonth.Status != 4";
  2409. }
  2410. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  2411. }
  2412. if (!string.IsNullOrEmpty(strExpress))
  2413. {
  2414. strExpress = $"{strExpress} && {strCalMonth}";
  2415. }
  2416. else
  2417. {
  2418. strExpress = strCalMonth;
  2419. }
  2420. if (queryFilter.ConditionTree != null)
  2421. {
  2422. string strTem = GetExpress(queryFilter.ConditionTree);
  2423. if (!string.IsNullOrEmpty(strTem))
  2424. {
  2425. strExpress = $"{strExpress} && ({strTem})";
  2426. }
  2427. }
  2428. var interpreter = new Interpreter();
  2429. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  2430. IQueryable<PerformanceItem> response;
  2431. if (queryFilter.userId > 0)
  2432. {
  2433. if (queryFilter.DoingOrReview == 0)
  2434. {
  2435. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  2436. }
  2437. else
  2438. {
  2439. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  2440. }
  2441. }
  2442. else
  2443. {
  2444. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  2445. }
  2446. return response;
  2447. }
  2448. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  2449. {
  2450. ApiSaveResponse retResponse = new ApiSaveResponse();
  2451. retResponse.Success = true;
  2452. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  2453. {
  2454. using (var t = Context.Database.BeginTransaction())
  2455. {
  2456. try
  2457. {
  2458. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  2459. if (calMonth == null)
  2460. {
  2461. retResponse.Success = false;
  2462. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  2463. return retResponse;
  2464. }
  2465. else
  2466. {
  2467. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  2468. projectContents.ProjectContentRecord.CalMonth = null;
  2469. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  2470. projectContents.ProjectContentRecord.StaffId = staff.Id;
  2471. projectContents.ProjectContentRecord.State = 0;
  2472. }
  2473. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  2474. if (project != null)
  2475. {
  2476. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  2477. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  2478. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  2479. if(pRecord != null)
  2480. {
  2481. retResponse.Success = false;
  2482. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  2483. return retResponse;
  2484. }
  2485. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  2486. foreach (var doItem in projectContents.ProjectWorkContents)
  2487. {
  2488. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  2489. Context.ProjectWorkContents.Add(doItem);
  2490. }
  2491. t.Commit();
  2492. }
  2493. else
  2494. {
  2495. retResponse.Success = false;
  2496. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  2497. return retResponse;
  2498. }
  2499. }
  2500. catch (Exception ex)
  2501. {
  2502. retResponse.Success = false;
  2503. retResponse.ErrorMessage = ex.Message;
  2504. t.Rollback();
  2505. return retResponse;
  2506. }
  2507. }
  2508. }
  2509. return retResponse;
  2510. }
  2511. public PerformanceItem GetCaseInfo(string CaseNo)
  2512. {
  2513. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  2514. if(retObj == null)
  2515. {
  2516. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  2517. }
  2518. return retObj;
  2519. }
  2520. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  2521. {
  2522. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  2523. if (retObj == null)
  2524. {
  2525. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  2526. }
  2527. return retObj;
  2528. }
  2529. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage,bool UpdateFromIPEasy=true)
  2530. {
  2531. var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2532. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  2533. if (retObj == null || UpdateFromIPEasy)
  2534. {
  2535. var temObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(
  2536. new PerformanceItem() {CaseNo =CaseNo,DoItem =DoItem,CaseStage = caseStage },
  2537. Context
  2538. );// IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  2539. System.Dynamic.ExpandoObject temExpandoObject = (System.Dynamic.ExpandoObject)temObj;
  2540. retObj = new PerformanceItem();
  2541. retObj.CaseNo = temObj.CaseNo.ToString();
  2542. retObj.CaseName = temObj.CaseName.ToString();
  2543. try
  2544. {
  2545. if (((IDictionary<String, Object>)temObj).Keys.Contains("ApplicationType") && temObj.ApplicationType != null)
  2546. retObj.ApplicationType = temObj.ApplicationType.ToString();
  2547. if (((IDictionary<String, Object>)temObj).Keys.Contains("CaseMemo") && temObj.CaseMemo != null)
  2548. retObj.CaseMemo = temObj.CaseMemo.ToString();
  2549. if (((IDictionary<String, Object>)temObj).Keys.Contains("BusinessType") && temObj.BusinessType != null)
  2550. retObj.BusinessType = temObj.BusinessType.ToString();
  2551. if (temObj.DoItem != null)
  2552. retObj.DoItem = temObj.DoItem.ToString();
  2553. if (((IDictionary<String, Object>)temObj).Keys.Contains("CaseStage") && temObj.CaseStage != null)
  2554. retObj.CaseStage = temObj.CaseStage.ToString();
  2555. if (((IDictionary<String, Object>)temObj).Keys.Contains("CaseType") && temObj.CaseType != null)
  2556. retObj.CaseType = temObj.CaseType.ToString();
  2557. if (((IDictionary<String, Object>)temObj).Keys.Contains("DoItemState") && temObj.DoItemState != null)
  2558. retObj.DoItemState = temObj.DoItemState.ToString();
  2559. if (((IDictionary<String, Object>)temObj).Keys.Contains("DoItemCoefficient") && temObj.DoItemCoefficient != null)
  2560. retObj.DoItemCoefficient = temObj.DoItemCoefficient.ToString();
  2561. if (((IDictionary<String, Object>)temObj).Keys.Contains("CaseCoefficient") && temObj.CaseCoefficient != null)
  2562. retObj.CaseCoefficient = temObj.CaseCoefficient.ToString();
  2563. if (((IDictionary<String, Object>)temObj).Keys.Contains("EntrustingDate") && temObj.EntrustingDate != null)
  2564. {
  2565. if (!string.IsNullOrEmpty(temObj.EntrustingDate.ToString()))
  2566. retObj.EntrustingDate = DateTime.Parse(temObj.EntrustingDate.ToString());
  2567. }
  2568. if(((IDictionary<String, Object>)temObj).Keys.Contains("Country") && temObj.Country != null)
  2569. {
  2570. retObj.Country = temObj.Country.ToString();
  2571. }
  2572. if (((IDictionary<String, Object>)temObj).Keys.Contains("InternalDate") && temObj.InternalDate != null)
  2573. {
  2574. if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
  2575. retObj.InternalDate = DateTime.Parse(temObj.InternalDate.ToString());
  2576. }
  2577. if (((IDictionary<String, Object>)temObj).Keys.Contains("CustomerLimitDate") && temObj.CustomerLimitDate != null)
  2578. {
  2579. if (!string.IsNullOrEmpty(temObj.CustomerLimitDate.ToString()))
  2580. retObj.CustomerLimitDate = DateTime.Parse(temObj.CustomerLimitDate.ToString());
  2581. }
  2582. if (((IDictionary<String, Object>)temObj).Keys.Contains("ReturnDate") && temObj.ReturnDate != null)
  2583. {
  2584. if (!string.IsNullOrEmpty(temObj.ReturnDate.ToString()))
  2585. retObj.ReturnDate = DateTime.Parse(temObj.ReturnDate.ToString());
  2586. }
  2587. if (((IDictionary<String, Object>)temObj).Keys.Contains("FinalizationDate") && temObj.FinalizationDate != null)
  2588. {
  2589. if (!string.IsNullOrEmpty(temObj.FinalizationDate.ToString()))
  2590. retObj.FinalizationDate = DateTime.Parse(temObj.FinalizationDate.ToString());
  2591. }
  2592. if (((IDictionary<String, Object>)temObj).Keys.Contains("FinishedDate") && temObj.FinishedDate != null)
  2593. {
  2594. if (!string.IsNullOrEmpty(temObj.FinishedDate.ToString()))
  2595. retObj.FinishedDate = DateTime.Parse(temObj.FinishedDate.ToString());
  2596. }
  2597. }
  2598. catch { }
  2599. int temWordCount;
  2600. if (temObj.WordCount != null)
  2601. {
  2602. if (int.TryParse(temObj.WordCount, out temWordCount))
  2603. {
  2604. retObj.WordCount = temWordCount;
  2605. }
  2606. }
  2607. try
  2608. {
  2609. if (temObj.CustomerName != null)
  2610. {
  2611. string strCustomer = temObj.CustomerName.ToString();
  2612. retObj.Customer = new Customer() { Name = strCustomer };
  2613. var temCustomer = Context.Customers.Where(c => c.Name == strCustomer.Trim()).FirstOrDefault();
  2614. if (temCustomer != null)
  2615. {
  2616. retObj.CustomerId = temCustomer.Id;
  2617. }
  2618. }
  2619. }
  2620. catch { }
  2621. try
  2622. {
  2623. if (temObj.Reviewer != null)
  2624. {
  2625. string strReViewer = temObj.Reviewer.ToString().Replace("-君龙", "");
  2626. var temReviewer = Context.Staffs.Where(s => s.Name == strReViewer.Trim()).FirstOrDefault();
  2627. if (temReviewer != null)
  2628. {
  2629. retObj.ReviewerId = temReviewer.Id;
  2630. }
  2631. }
  2632. }
  2633. catch { }
  2634. try
  2635. {
  2636. if (temObj.WorkflowUser != null)
  2637. {
  2638. string strWorkflowUser = temObj.WorkflowUser.ToString().Replace("-君龙", "");
  2639. var temReviewer = Context.Staffs.Where(s => s.Name == strWorkflowUser.Trim()).FirstOrDefault();
  2640. if (temReviewer != null)
  2641. {
  2642. retObj.WorkflowUserId = temReviewer.Id;
  2643. }
  2644. }
  2645. }
  2646. catch { }
  2647. if (temObj.DoPersons != null)
  2648. {
  2649. string DoPersons = temObj.DoPersons.ToString();
  2650. string[] Persons = DoPersons.Split(new char[] { ',' });
  2651. List<ItemStaff> itemStaffs = new List<ItemStaff>();
  2652. foreach (var doPerson in Persons)
  2653. {
  2654. string strName = doPerson.Replace("-君龙","");
  2655. itemStaffs.Add(new ItemStaff() { DoPerson = new Staff() { Name = strName } });
  2656. }
  2657. retObj.ItemStaffs = itemStaffs;
  2658. }
  2659. }
  2660. return retObj;
  2661. }
  2662. public PerformanceItem GetItemInfoByMonthId(string CaseNo, string DoItem, string caseStage,int calMonthId)
  2663. {
  2664. var retObj = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2665. && p.DoItem == DoItem.Trim() && p.CalMonthId == calMonthId);
  2666. if(retObj != null)
  2667. {
  2668. if(string.IsNullOrEmpty (retObj.CaseStage) && string.IsNullOrEmpty(caseStage))
  2669. {
  2670. return retObj;
  2671. }
  2672. else
  2673. {
  2674. if(retObj.CaseStage == caseStage)
  2675. {
  2676. return retObj;
  2677. }
  2678. else
  2679. {
  2680. return null;
  2681. }
  2682. }
  2683. }
  2684. else
  2685. {
  2686. return null;
  2687. }
  2688. }
  2689. public bool MovePerformance2ProjectInfo()
  2690. {
  2691. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  2692. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  2693. var pList = response.ToList<PerformanceItem>();
  2694. foreach(var p in pList)
  2695. {
  2696. ProjectInfo project = new ProjectInfo();
  2697. project.CaseNo = p.CaseNo;
  2698. project.CaseName = p.CaseName;
  2699. project.CaseState = 0;
  2700. project.CaseType = p.CaseType;
  2701. project.CustomerId = p.CustomerId;
  2702. project.ReviewerId = p.ReviewerId;
  2703. Context.ProjectInfos.Add(project);
  2704. foreach(ItemStaff iStaff in p.ItemStaffs)
  2705. {
  2706. Context.ItemStaffs.Remove(iStaff);
  2707. }
  2708. Context.PerformanceItems.Remove(p);
  2709. Context.SaveChanges();
  2710. }
  2711. return true;
  2712. }
  2713. #region 等级考核计算
  2714. /// <summary>
  2715. /// 等级考核案件量统计
  2716. /// </summary>
  2717. /// <param name="calMonthId"></param>
  2718. /// <returns></returns>
  2719. private List<StaffStatisticsforLevel> StatisticsCount(int calMonthId,spDbContext spDb )
  2720. {
  2721. var retlist = new List<StaffStatisticsforLevel>();
  2722. #region 新申请
  2723. var newList = spDb.PerformanceItems.Include(p => p.ItemStaffs).ThenInclude(p=>p.DoPerson)
  2724. .Include(p=>p.CalMonth)
  2725. .Where(p=>p.CalMonthId == calMonthId && p.BasePoint >0
  2726. && (p.Type =="新申请" || p.Type =="专案" || (p.Type == "其它" && p.WordCount >0 && (p.DoItem =="新申请" || p.DoItem == "翻译")))
  2727. ).ToList();
  2728. foreach(var p in newList)
  2729. {
  2730. #region 严重延期降系数
  2731. string strCaseCeoffcient = p.CaseCoefficient;
  2732. if (string.IsNullOrEmpty(strCaseCeoffcient))
  2733. {
  2734. strCaseCeoffcient = "B";
  2735. }
  2736. if (p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo))
  2737. {
  2738. switch (p.CaseCoefficient)
  2739. {
  2740. case "S":
  2741. strCaseCeoffcient = "A";
  2742. break;
  2743. case "A":
  2744. strCaseCeoffcient = "B";
  2745. break;
  2746. case "B":
  2747. strCaseCeoffcient = "C";
  2748. break;
  2749. case "C":
  2750. strCaseCeoffcient = "D";
  2751. break;
  2752. }
  2753. }
  2754. #endregion
  2755. var pointList = spDb.StaffStatistics.Include(i=>i.Staff).Where(i=>i.ItemId == p.Id).ToList();
  2756. #region 新申请处理
  2757. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2758. int doPersons = doList.Count();
  2759. if (p.ItemStaffs.Count() > doList.Count())
  2760. {
  2761. doPersons = p.ItemStaffs.Count;
  2762. foreach (ItemStaff itemStaff in p.ItemStaffs)
  2763. {
  2764. Staff staff = itemStaff.DoPerson;
  2765. if (staff == null)
  2766. {
  2767. staff = spDb.Staffs.FirstOrDefault(s => s.Id == itemStaff.DoPersonId);
  2768. }
  2769. if (staff.Status == "试用期")
  2770. {
  2771. doPersons =doPersons- 1;
  2772. }
  2773. }
  2774. }
  2775. if(doPersons >0)
  2776. {
  2777. //System.Diagnostics.Debug.WriteLine("");
  2778. foreach(var h in doList)
  2779. {
  2780. var temObj = retlist.FirstOrDefault(s=>s.StaffId == h.StaffId && s.Type == "新申请" && s.isReview == false);
  2781. if(temObj == null)
  2782. {
  2783. temObj = new StaffStatisticsforLevel();
  2784. temObj.StaffId = h.StaffId;
  2785. temObj.GradeId = h.Staff.StaffGradeId.Value ;
  2786. if(temObj.GradeId == 0)
  2787. {
  2788. System.Diagnostics.Debug.WriteLine("");
  2789. }
  2790. temObj.CalMonthId = p.CalMonthId;
  2791. temObj.Type = "新申请";
  2792. retlist.Add(temObj);
  2793. }
  2794. switch (strCaseCeoffcient)
  2795. {
  2796. case "S":
  2797. if(p.Type == "专案")
  2798. {
  2799. temObj.S += h.totalBasePoint.Value;
  2800. }
  2801. else
  2802. {
  2803. temObj.S+=(double)(1.0M/ (decimal)doPersons);
  2804. }
  2805. break;
  2806. case "A":
  2807. if (p.Type == "专案")
  2808. {
  2809. temObj.A += h.totalBasePoint.Value;
  2810. }
  2811. else
  2812. {
  2813. temObj.A += (double)(1.0M / (decimal)doPersons);
  2814. }
  2815. break;
  2816. case "B":
  2817. if (p.Type == "专案")
  2818. {
  2819. temObj.B += h.totalBasePoint.Value;
  2820. }
  2821. else
  2822. {
  2823. temObj.B += (double)(1.0M / (decimal)doPersons);
  2824. }
  2825. break;
  2826. case "C":
  2827. if (p.Type == "专案")
  2828. {
  2829. temObj.C += h.totalBasePoint.Value;
  2830. }
  2831. else
  2832. {
  2833. temObj.C += (double)(1.0M / (decimal)doPersons);
  2834. }
  2835. break;
  2836. case "D":
  2837. if (p.Type == "专案")
  2838. {
  2839. temObj.D += h.totalBasePoint.Value;
  2840. }
  2841. else
  2842. {
  2843. temObj.D += (double)(1.0M / (decimal)doPersons);
  2844. }
  2845. break;
  2846. }
  2847. }
  2848. }
  2849. #endregion
  2850. #region 新申请审核
  2851. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2852. if(reviewer != null)
  2853. {
  2854. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "新申请" && s.isReview == true);
  2855. if(temObj == null)
  2856. {
  2857. temObj = new StaffStatisticsforLevel();
  2858. temObj.StaffId = reviewer.StaffId;
  2859. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2860. if (temObj.GradeId == 0)
  2861. {
  2862. System.Diagnostics.Debug.WriteLine("");
  2863. }
  2864. temObj.CalMonthId = p.CalMonthId;
  2865. temObj.Type = "新申请";
  2866. temObj.isReview = true;
  2867. retlist.Add(temObj);
  2868. }
  2869. switch (strCaseCeoffcient)
  2870. {
  2871. case "S":
  2872. temObj.S += 1;
  2873. break;
  2874. case "A":
  2875. temObj.A += 1;
  2876. break;
  2877. case "B":
  2878. temObj.B += 1;
  2879. break;
  2880. case "C":
  2881. temObj.C += 1;
  2882. break;
  2883. case "D":
  2884. temObj.D += 1;
  2885. break;
  2886. }
  2887. }
  2888. #endregion
  2889. }
  2890. #endregion
  2891. #region 国内OA
  2892. var cnOA = spDb.PerformanceItems.Include(x=>x.ItemStaffs)
  2893. .Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && x.CaseNo.Contains("CN") && x.BasePoint > 0.3
  2894. ).ToList();
  2895. //因为不是所有的OA案件都是答复审查意见,所以有些应该没有一通或首次转入信息,去掉这个条件:
  2896. //&& (x.CaseStage == "一通" || x.DoItemCoefficient.Contains("首次转入"))
  2897. foreach (var p in cnOA)
  2898. {
  2899. var pointList = spDb.StaffStatistics.Include(i => i.Staff).Where(i=> i.ItemId == p.Id).ToList();
  2900. #region 国内OA处理
  2901. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2902. foreach (var h in doList)
  2903. {
  2904. var temObj = retlist.FirstOrDefault(s => s.StaffId == h.StaffId && s.Type == "国内OA" && s.isReview == false);
  2905. if (temObj == null)
  2906. {
  2907. temObj = new StaffStatisticsforLevel();
  2908. temObj.StaffId = h.StaffId;
  2909. temObj.GradeId = h.Staff.StaffGradeId.Value ;
  2910. if (temObj.GradeId == 0)
  2911. {
  2912. System.Diagnostics.Debug.WriteLine("");
  2913. }
  2914. temObj.CalMonthId = p.CalMonthId;
  2915. temObj.Type = "国内OA";
  2916. retlist.Add(temObj);
  2917. }
  2918. switch (p.CaseCoefficient)
  2919. {
  2920. case "S":
  2921. temObj.S += (double)(1.0M / (decimal)doList.Count());
  2922. break;
  2923. case "A":
  2924. temObj.A += (double)(1.0M / (decimal)doList.Count());
  2925. break;
  2926. case "B":
  2927. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2928. break;
  2929. case "C":
  2930. temObj.C += (double)(1.0M / (decimal)doList.Count());
  2931. break;
  2932. case "D":
  2933. temObj.D += (double)(1.0M / (decimal)doList.Count());
  2934. break;
  2935. default:
  2936. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2937. break;
  2938. }
  2939. }
  2940. #endregion
  2941. #region 国内OA审核
  2942. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2943. if (reviewer != null)
  2944. {
  2945. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "国内OA" && s.isReview == true);
  2946. if (temObj == null)
  2947. {
  2948. temObj = new StaffStatisticsforLevel();
  2949. temObj.StaffId = reviewer.StaffId;
  2950. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2951. if (temObj.GradeId == 0)
  2952. {
  2953. System.Diagnostics.Debug.WriteLine("");
  2954. }
  2955. temObj.CalMonthId = p.CalMonthId;
  2956. temObj.Type = "国内OA";
  2957. temObj.isReview = true;
  2958. retlist.Add(temObj);
  2959. }
  2960. switch (p.CaseCoefficient)
  2961. {
  2962. case "S":
  2963. temObj.S += 1;
  2964. break;
  2965. case "A":
  2966. temObj.A += 1;
  2967. break;
  2968. case "B":
  2969. temObj.B += 1;
  2970. break;
  2971. case "C":
  2972. temObj.C += 1;
  2973. break;
  2974. case "D":
  2975. temObj.D += 1;
  2976. break;
  2977. }
  2978. }
  2979. #endregion
  2980. }
  2981. #endregion
  2982. #region 涉外OA
  2983. var gwOA = spDb.PerformanceItems.Include(x => x.ItemStaffs)
  2984. .Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && !x.CaseNo.Contains("CN") && x.BasePoint>0.5
  2985. && (x.DoItemCoefficient.Contains("实质"))).ToList();
  2986. foreach (var p in gwOA)
  2987. {
  2988. var pointList = spDb.StaffStatistics.Include(i => i.Staff).Where(i => i.ItemId == p.Id).ToList();
  2989. #region 涉外OA处理
  2990. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2991. foreach (var h in doList)
  2992. {
  2993. var temObj = retlist.FirstOrDefault(s => s.StaffId == h.StaffId && s.Type == "涉外OA" && s.isReview == false);
  2994. if (temObj == null)
  2995. {
  2996. temObj = new StaffStatisticsforLevel();
  2997. temObj.StaffId = h.StaffId;
  2998. temObj.GradeId = h.Staff.StaffGradeId.Value;
  2999. if (temObj.GradeId == 0)
  3000. {
  3001. System.Diagnostics.Debug.WriteLine("");
  3002. }
  3003. temObj.CalMonthId = p.CalMonthId;
  3004. temObj.Type = "涉外OA";
  3005. retlist.Add(temObj);
  3006. }
  3007. switch (p.CaseCoefficient)
  3008. {
  3009. case "S":
  3010. temObj.S += (double)(1.0M / (decimal)doList.Count());
  3011. break;
  3012. case "A":
  3013. temObj.A += (double)(1.0M / (decimal)doList.Count());
  3014. break;
  3015. case "B":
  3016. temObj.B += (double)(1.0M / (decimal)doList.Count());
  3017. break;
  3018. case "C":
  3019. temObj.C += (double)(1.0M / (decimal)doList.Count());
  3020. break;
  3021. case "D":
  3022. temObj.D += (double)(1.0M / (decimal)doList.Count());
  3023. break;
  3024. default:
  3025. temObj.B += (double)(1.0M / (decimal)doList.Count());
  3026. break;
  3027. }
  3028. }
  3029. #endregion
  3030. #region 涉外OA审核
  3031. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  3032. if (reviewer != null)
  3033. {
  3034. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "涉外OA" && s.isReview == true);
  3035. if (temObj == null)
  3036. {
  3037. temObj = new StaffStatisticsforLevel();
  3038. temObj.StaffId = reviewer.StaffId;
  3039. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  3040. if (temObj.GradeId == 0)
  3041. {
  3042. System.Diagnostics.Debug.WriteLine("");
  3043. }
  3044. temObj.CalMonthId = calMonthId;
  3045. temObj.Type = "涉外OA";
  3046. temObj.isReview = true;
  3047. retlist.Add(temObj);
  3048. }
  3049. switch (p.CaseCoefficient)
  3050. {
  3051. case "S":
  3052. temObj.S += 1;
  3053. break;
  3054. case "A":
  3055. temObj.A += 1;
  3056. break;
  3057. case "B":
  3058. temObj.B += 1;
  3059. break;
  3060. case "C":
  3061. temObj.C += 1;
  3062. break;
  3063. case "D":
  3064. temObj.D += 1;
  3065. break;
  3066. default:
  3067. temObj.C += 1;
  3068. break;
  3069. }
  3070. }
  3071. #endregion
  3072. }
  3073. #endregion
  3074. return retlist;
  3075. }
  3076. /// <summary>
  3077. /// 指定等级人员等级考核案件量统计汇总
  3078. /// </summary>
  3079. /// <param name="levelCaseCounts"></param>
  3080. /// <param name="GradeCode"></param>
  3081. /// <param name="calReviw"></param>
  3082. /// <returns></returns>
  3083. private LevelStatisticsResult CalLevelStatistics(List<StaffStatisticsforLevel> levelCaseCounts,string GradeCode,bool calReviw)
  3084. {
  3085. var retList = new List<LevelStatistics>();
  3086. var temList = levelCaseCounts.Where(x=>x.Grade.Grade.StartsWith(GradeCode)).ToList();
  3087. foreach (var s in temList)
  3088. {
  3089. var temObj = retList.FirstOrDefault(i=>i.StaffId == s.StaffId);
  3090. if(temObj == null)
  3091. {
  3092. temObj = new LevelStatistics();
  3093. temObj.StaffId = s.StaffId;
  3094. temObj.StaffName = s.Staff.Name;
  3095. temObj.Grade = s.Grade.Grade;
  3096. //var Department = Context.DepartmentPositions.FirstOrDefault(x => x.StaffId == s.StaffId);
  3097. temObj.Department = Context.DepartmentPositions.Include(x => x.department).FirstOrDefault(x => x.StaffId == s.StaffId)?.department.Name;
  3098. retList.Add(temObj);
  3099. }
  3100. if (!s.isReview)
  3101. {
  3102. if(s.Type == "国内OA")
  3103. {
  3104. temObj.dS += (double)((decimal)s.S / 2M);
  3105. temObj.dA += (double)((decimal)s.A / 2M);
  3106. temObj.dB += (double)((decimal)s.B / 2M);
  3107. temObj.dC += (double)((decimal)s.C / 2M);
  3108. temObj.dD += (double)((decimal)s.D / 2M);
  3109. }
  3110. else
  3111. {
  3112. temObj.dS += s.S;
  3113. temObj.dA += s.A;
  3114. temObj.dB += s.B;
  3115. temObj.dC += s.C;
  3116. temObj.dD += s.D;
  3117. }
  3118. }
  3119. else
  3120. {
  3121. if (calReviw)
  3122. {
  3123. if (s.Type == "国内OA")
  3124. {
  3125. temObj.vS += (double)((decimal)s.S / 2M);
  3126. temObj.vA += (double)((decimal)s.A / 2M);
  3127. temObj.vB += (double)((decimal)s.B / 2M);
  3128. temObj.vC += (double)((decimal)s.C / 2M);
  3129. temObj.vD += (double)((decimal)s.D / 2M);
  3130. }
  3131. else
  3132. {
  3133. temObj.vS += s.S;
  3134. temObj.vA += s.A;
  3135. temObj.vB += s.B;
  3136. temObj.vC += s.C;
  3137. temObj.vD += s.D;
  3138. }
  3139. }
  3140. }
  3141. }
  3142. return new LevelStatisticsResult() {Grade =GradeCode , Statistics = retList};
  3143. }
  3144. /// /// <summary>
  3145. /// 获取季度等级考核结果
  3146. /// </summary>
  3147. /// <param name="year">考核年度</param>
  3148. /// <param name="quarter">考核季度,取值为1、2、3、4</param>
  3149. /// <param name="GradeCode">等级</param>
  3150. /// <returns></returns>
  3151. public LevelStatisticsResult CalAgentLevel(int year,int quarter,string GradeCode)
  3152. {
  3153. LevelStatisticsResult result = new LevelStatisticsResult();
  3154. DateTime tempDate=DateTime.Parse($"{year}-01-01");
  3155. var Months = new List<int>() { 1,2,3};
  3156. switch (quarter)
  3157. {
  3158. case 1:
  3159. if(year == 2022)
  3160. {
  3161. Months = new List<int>() { 2, 3 };
  3162. }
  3163. else
  3164. {
  3165. Months = new List<int>() { 1, 2, 3 };
  3166. }
  3167. tempDate = DateTime.Parse($"{year}-01-01");
  3168. break;
  3169. case 2:
  3170. Months = new List<int>() { 4,5,6 };
  3171. tempDate = DateTime.Parse($"{year}-04-01");
  3172. break;
  3173. case 3:
  3174. Months = new List<int>() { 7,8,9};
  3175. tempDate = DateTime.Parse($"{year}-07-01");
  3176. break;
  3177. case 4:
  3178. Months = new List<int>() { 10,11,12 };
  3179. tempDate = DateTime.Parse($"{year}-10-01");
  3180. break;
  3181. }
  3182. //var mList = Context.CalMonths.Where(c=>c.Year == year && Months.Contains(c.Month)).ToList();
  3183. //foreach (var m in mList)
  3184. //{
  3185. // StatisticsLevelCount(m.Id);
  3186. //}
  3187. var resp = Context.StaffStatisticsforLevels
  3188. .Include(p => p.Staff)
  3189. .Include(p => p.Grade)
  3190. .Where(p => Months.Contains(p.CalMonth.Month) && p.CalMonth.Year == year && p.Staff.RegularDate.Value < tempDate && p.Staff.IsGradeAssess);
  3191. var temtList = resp.ToList();
  3192. bool isReview = (GradeCode == "A");
  3193. result = CalLevelStatistics(temtList, GradeCode, isReview);
  3194. if (!isReview)
  3195. {
  3196. string UpgradCode = "A";
  3197. switch (GradeCode)
  3198. {
  3199. case "B":
  3200. UpgradCode = "A";
  3201. break;
  3202. case "C":
  3203. UpgradCode = "B";
  3204. break;
  3205. case "D":
  3206. UpgradCode = "C";
  3207. break;
  3208. }
  3209. var temResult = CalLevelStatistics(temtList, UpgradCode, isReview);
  3210. result.UpgradeBase = temResult.doAverage();
  3211. }
  3212. if (result.Statistics.Count > 0)
  3213. {
  3214. var temAverage = result.pAverage(result.Statistics[0].StaffId);
  3215. }
  3216. return result;
  3217. }
  3218. /// <summary>
  3219. /// 重新统计指定月份的人员案件数量
  3220. /// </summary>
  3221. /// <param name="year"></param>
  3222. /// <param name="month"></param>
  3223. public bool StatisticsLevelCount(int year,int month)
  3224. {
  3225. try
  3226. {
  3227. _StatisticsLevelCount(year,month,Context);
  3228. return true;
  3229. }
  3230. catch { return false; }
  3231. }
  3232. private void _StatisticsLevelCount(int year, int month,spDbContext spDb)
  3233. {
  3234. var temObj = spDb.CalMonths.FirstOrDefault(l => l.Year == year && l.Month == month);
  3235. if (temObj != null)
  3236. {
  3237. var temList = spDb.StaffStatisticsforLevels.Where(l => l.CalMonthId == temObj.Id);
  3238. spDb.StaffStatisticsforLevels.RemoveRange(temList);
  3239. var NewList = StatisticsCount(temObj.Id, spDb);
  3240. spDb.StaffStatisticsforLevels.AddRange(NewList);
  3241. spDb.SaveChanges();
  3242. }
  3243. }
  3244. #endregion
  3245. }
  3246. }