PerformanceItemController.cs 159 KB

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