PerformanceItemController.cs 176 KB

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