PerformanceItemController.cs 176 KB

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