PerformanceItemController.cs 159 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733
  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. Utility.Utility.CalBasePoint(item, rules);
  856. if (item.BasePoint > 0)
  857. {
  858. _calItemJX(item, spDb);
  859. }
  860. else
  861. {
  862. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == item.Id);
  863. spDb.StaffStatistics.RemoveRange(oldJxList);
  864. }
  865. spDb.SaveChanges();
  866. }
  867. catch (Exception ex)
  868. {
  869. System.Diagnostics.Debug.WriteLine(ex.Message);
  870. }
  871. }
  872. _CalJXPoint(calMonth, spDb);
  873. }
  874. }
  875. public ApiSaveResponse RefreshBasePoint()
  876. {
  877. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  878. t.Start();
  879. return new ApiSaveResponse() {
  880. Success = true
  881. };
  882. }
  883. public void RefreshPoint(PerformanceItem item)
  884. {
  885. //spDbContext spDb = new spDbContext();
  886. var rules = Context.BasePointRules.ToList();
  887. if (item.AgentFeedbackMemo != "特殊点数申诉")
  888. {
  889. Utility.Utility.CalBasePoint(item, rules);
  890. if (item.BasePoint > 0)
  891. {
  892. _calItemJX(item, Context);
  893. }
  894. else
  895. {
  896. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  897. Context.StaffStatistics.RemoveRange(oldJxList);
  898. }
  899. Context.SaveChanges();
  900. }
  901. }
  902. public ApiSaveResponse RefreshFromIPEasyById(int itemId)
  903. {
  904. var Item = Context.PerformanceItems.Include(p => p.Customer).Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson).FirstOrDefault(p => p.Id == itemId);
  905. if (Item != null)
  906. {
  907. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  908. }
  909. Utility.Utility.CalBasePoint(Item, Context.BasePointRules.ToList());
  910. if (Item.BasePoint > 0)
  911. {
  912. _calItemJX(Item, Context);
  913. }
  914. else
  915. {
  916. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == Item.Id);
  917. Context.StaffStatistics.RemoveRange(oldJxList);
  918. }
  919. Context.SaveChanges();
  920. return new ApiSaveResponse()
  921. {
  922. Success = true
  923. };
  924. }
  925. public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
  926. {
  927. new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
  928. return new ApiSaveResponse()
  929. {
  930. Success = true
  931. };
  932. }
  933. public ApiSaveResponse RefreshFromIPEasy(string CaseNo, string DoItem, string caseStage)
  934. {
  935. var Item = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault(p => p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
  936. if (Item != null)
  937. {
  938. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  939. }
  940. return new ApiSaveResponse()
  941. {
  942. Success = true
  943. };
  944. }
  945. public ApiSaveResponse CompareExcel2DB()
  946. {
  947. System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
  948. t.Start();
  949. return new ApiSaveResponse()
  950. {
  951. Success = true
  952. };
  953. }
  954. public FileProcessTask CurrentData2Excel(int Year,int Month)
  955. {
  956. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == Year && c.Month == Month);
  957. if (calMonth != null)
  958. {
  959. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  960. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  961. var filePath = Path.Combine(attachfileSavePath, filename);
  962. var fileTask = new FileProcessTask()
  963. {
  964. Id = Guid.NewGuid().ToString(),
  965. FileName = filename,
  966. FilePath = filePath,
  967. Processed = 0
  968. };
  969. fileTaskService.Add(fileTask);
  970. ExportDataResult result = new ExportDataResult() {
  971. fileTask = fileTask,
  972. calMonth = calMonth
  973. };
  974. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(Export2ExcelThread));
  975. t.Start(result);
  976. return fileTask;
  977. }
  978. return null;
  979. }
  980. internal class ExportDataResult
  981. {
  982. public FileProcessTask fileTask { get; set; }
  983. public CalMonth calMonth { get; set; }
  984. }
  985. private void Export2ExcelThread(object attfile)
  986. {
  987. ExportDataResult result = (ExportDataResult)attfile;
  988. FileProcessTask file = result.fileTask;
  989. spDbContext spDb = new spDbContext();
  990. List<PerformanceItem> items = spDb.PerformanceItems
  991. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  992. .Include(p => p.PreOastaff)
  993. .Include(p => p.Customer)
  994. .Include(p => p.CalMonth)
  995. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  996. .Where(p => p.CalMonth.Id == result.calMonth.Id && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  997. DataTable dt = new DataTable();
  998. #region 栏位名称
  999. dt.Columns.Add("我方文号", typeof(string));
  1000. dt.Columns.Add("申请类型", typeof(string));
  1001. dt.Columns.Add("业务类型", typeof(string));
  1002. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  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("前一次OA处理事项系数", typeof(string));
  1008. dt.Columns.Add("前一次OA处理人", typeof(string));
  1009. dt.Columns.Add("处理人等级", typeof(string));
  1010. dt.Columns.Add("基本点数", typeof(string));
  1011. dt.Columns.Add("核稿系数", typeof(string));
  1012. dt.Columns.Add("核稿绩效", 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. #endregion
  1037. var verifyCeoffients = spDb.VerifyCoefficients.ToList();
  1038. var Rules = spDb.BasePointRules.ToList();
  1039. file.Size = items.Count;
  1040. foreach (var p in items)
  1041. {
  1042. List<ItemStaff> temItemStaffs = p.ItemStaffs.ToList();
  1043. string strCaseMemo = "";
  1044. string strHandler = "";
  1045. temItemStaffs = new List<ItemStaff>();
  1046. foreach (var iStaff in p.ItemStaffs)
  1047. {
  1048. strHandler = string.IsNullOrEmpty(strHandler) ? iStaff.DoPerson.Name : $"{strHandler},{iStaff.DoPerson.Name}";
  1049. if (iStaff.DoPerson.Status == "试用期")
  1050. {
  1051. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}在试用期" : $"{strCaseMemo},{iStaff.DoPerson.Name}在试用期";
  1052. }
  1053. else
  1054. {
  1055. if (!iStaff.DoPerson.IsCalPerformsnce)
  1056. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}不计算绩效" : $"{strCaseMemo},{iStaff.DoPerson.Name}不计算绩效";
  1057. }
  1058. if (iStaff.DoPersonId == p.ReviewerId)
  1059. {
  1060. strCaseMemo = String.IsNullOrEmpty(strCaseMemo) ? "核稿人与处理人相同" : $"{strCaseMemo},核稿人与处理人相同";
  1061. }
  1062. }
  1063. var staffStatics = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).Where(s => s.ItemId == p.Id && s.jxType.Contains("处理"));
  1064. var reviewStatic = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).FirstOrDefault(s => s.ItemId == p.Id && s.jxType.Contains("审核"));
  1065. foreach (var iStaff in staffStatics.ToList())
  1066. {
  1067. DataRow row = dt.NewRow();
  1068. row["我方文号"] = p.CaseNo;
  1069. row["申请类型"] = p.ApplicationType;
  1070. row["实际处理人"] = strHandler;
  1071. if (p.ApplicationName != null && p.ApplicationName.Contains("OPPO") && p.ApplicationType == "实用新型" && p.Type == "新申请")
  1072. {
  1073. row["申请类型"] = "发明";
  1074. row["案件备注"] = $"{row["案件备注"]}\r\n【OPPO案件实用新型修改为发明】";
  1075. }
  1076. row["处理事项"] = p.DoItem;
  1077. row["业务类型"] = p.BusinessType;
  1078. row["备注(填表注意事项)"] = p.AgentFeedbackMemo;
  1079. if (p.Type == "专案")
  1080. {
  1081. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]}【主管给定点数】专案";
  1082. row["处理事项"] = "提出报告";
  1083. }
  1084. if (p.ItemStaffs.Count() > 1)
  1085. {
  1086. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]},{strHandler}合写";
  1087. }
  1088. row["案件阶段"] = p.CaseStage;
  1089. row["案件系数"] = p.CaseCoefficient;
  1090. if (p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo) && p.Type == "新申请")
  1091. {
  1092. switch (p.CaseCoefficient)
  1093. {
  1094. case "S":
  1095. row["案件系数"] = "A";
  1096. break;
  1097. case "A":
  1098. row["案件系数"] = "B";
  1099. break;
  1100. case "B":
  1101. row["案件系数"] = "C";
  1102. break;
  1103. case "C":
  1104. row["案件系数"] = "D";
  1105. break;
  1106. }
  1107. row["案件备注"] = $"{row["案件备注"]}\r\n严重延期降系数【{p.CaseCoefficient}->{row["案件系数"]}】";
  1108. }
  1109. row["处理事项系数"] = p.DoItemCoefficient;
  1110. row["前一次OA处理事项系数"] = "";
  1111. row["前一次OA处理人"] = p.PreOastaff?.Name;
  1112. row["处理人"] = iStaff.Staff.Name;
  1113. row["基本点数"] = iStaff.totalBasePoint;
  1114. row["处理人等级"] = iStaff.Staff.StaffGrade.Grade;
  1115. row["处理人绩效系数"] = iStaff.Staff.StaffGrade.Coefficient;
  1116. if (reviewStatic != null)
  1117. {
  1118. row["核稿人"] = reviewStatic.Staff.Name;
  1119. var v = verifyCeoffients.FirstOrDefault(p => p.CheckerId == reviewStatic.Staff.StaffGradeId && p.DoPersonId == iStaff.Staff.StaffGradeId);
  1120. if (v != null)
  1121. {
  1122. row["核稿绩效"] = ((decimal)iStaff.totalBasePoint * (decimal)v.Coefficient);
  1123. row["核稿系数"] = v.Coefficient;
  1124. }
  1125. }
  1126. row["客户名称"] = p.Customer?.Name;
  1127. row["申请人"] = p.ApplicationName;
  1128. row["处理事项完成日"] = p.FinishedDate?.ToString("yyyy-MM-dd");
  1129. row["定稿日"] = p.FinalizationDate?.ToString("yyyy-MM-dd");
  1130. row["返稿日"] = p.ReturnDate?.ToString("yyyy-MM-dd");
  1131. row["案件类型"] = p.CaseType;
  1132. row["案件状态"] = p.CaseState;
  1133. row["处理事项备注"] = p.DoItemMemo;
  1134. row["处理状态"] = p.DoItemState;
  1135. row["案件名称"] = p.CaseName;
  1136. row["委案日期"] = p.EntrustingDate?.ToString("yyyy-MM-dd");
  1137. row["客户期限"] = p.CustomerLimitDate?.ToString("yyyy-MM-dd");
  1138. row["内部期限"] = p.InternalDate?.ToString("yyyy-MM-dd");
  1139. row["初稿日"] = p.FirstDraftDate?.ToString("yyyy-MM-dd");
  1140. row["翻译字数"] = p.WordCount;
  1141. row["备注(发文严重超期是否属客观原因,若为否,请填写原因"] = p.OverDueMemo;
  1142. row["绩效类型"] = p.Type;
  1143. row["案件备注"] = $"{p.CaseMemo}\r\n{row["案件备注"]}";
  1144. if (!string.IsNullOrEmpty(strCaseMemo))
  1145. {
  1146. row["案件备注"] = $"{strCaseMemo}\r\n{row["案件备注"]}";
  1147. }
  1148. dt.Rows.Add(row);
  1149. }
  1150. file.Processed += 1;
  1151. }
  1152. NPOIExcel.DataTableToExcel(dt, file.FilePath);
  1153. file.Finished = true;
  1154. }
  1155. private void _CompareExcel2DB()
  1156. {
  1157. DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0, 2);
  1158. DataTable retTable = new DataTable();
  1159. retTable.Columns.Add("我方文号");
  1160. retTable.Columns.Add("申请类型");
  1161. retTable.Columns.Add("业务类型");
  1162. retTable.Columns.Add("备注(填表注意事项)");
  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. spDbContext spDb = new spDbContext();
  1191. List<PerformanceItem> items = spDb.PerformanceItems
  1192. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  1193. .Include(p => p.Customer)
  1194. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  1195. .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  1196. excelDT.DefaultView.Sort = "我方文号,处理事项";
  1197. DataTable temDt = excelDT.DefaultView.ToTable();
  1198. int iTable = 0;
  1199. int iList = 0;
  1200. CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p => p.Status == 0);
  1201. var verifyCoefficients = spDb.VerifyCoefficients.ToList();
  1202. var Rules = spDb.BasePointRules.ToList();
  1203. while (iTable < temDt.Rows.Count && iList < items.Count)
  1204. {
  1205. System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
  1206. DataRow row = temDt.Rows[iTable];
  1207. PerformanceItem item = items[iList];
  1208. if (row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString() == "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
  1209. {
  1210. var temRow = retTable.NewRow();
  1211. int iBegin = iTable;
  1212. int iEnd = iTable;
  1213. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1214. if (iEnd < temDt.Rows.Count - 1)
  1215. {
  1216. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1217. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1218. {
  1219. iEnd++;
  1220. }
  1221. }
  1222. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1223. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1224. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1225. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  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. for (int i = iBegin; i <= iEnd; i++)
  1237. {
  1238. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1239. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1240. temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
  1241. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1242. {
  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. }
  1246. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1247. }
  1248. iTable = iEnd;
  1249. #endregion
  1250. Utility.Utility.CalBasePoint(item, Rules);
  1251. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1252. try
  1253. {
  1254. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1255. }
  1256. catch { }
  1257. temRow["案件阶段【系统】"] = item.CaseStage;
  1258. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1259. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1260. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1261. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1262. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1263. temRow["严重超期备注原因"] = item.OverDueMemo;
  1264. if (retPoints != null && retPoints.Count > 0)
  1265. {
  1266. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
  1267. foreach (var itemStaff in item.ItemStaffs)
  1268. {
  1269. //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1270. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1271. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1272. if (item.ReviewerId != null)
  1273. {
  1274. #region 取审核人等级审核等级系数
  1275. VerifyCoefficient vcoefficient
  1276. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1277. v.CheckerId == item.Reviewer.StaffGradeId
  1278. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1279. .FirstOrDefault<VerifyCoefficient>();
  1280. #endregion
  1281. if (vcoefficient != null)
  1282. {
  1283. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1284. }
  1285. }
  1286. }
  1287. }
  1288. temRow["是否一致"] = "";
  1289. temRow["不一致原因"] = "";
  1290. if (temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
  1291. {
  1292. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
  1293. }
  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 (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
  1315. {
  1316. temRow["是否一致"] = "不一致";
  1317. }
  1318. retTable.Rows.Add(temRow);
  1319. iTable++;
  1320. iList++;
  1321. }
  1322. else
  1323. {
  1324. string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
  1325. string strList = $"{item.CaseNo}-{item.DoItem}";
  1326. if (strDT.CompareTo(strList) > 0)
  1327. {
  1328. var temRow = retTable.NewRow();
  1329. Utility.Utility.CalBasePoint(item, Rules);
  1330. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1331. try
  1332. {
  1333. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1334. }
  1335. catch { }
  1336. temRow["我方文号"] = item.CaseNo;
  1337. temRow["处理事项"] = item.DoItem;
  1338. temRow["申请类型"] = item.ApplicationType;
  1339. temRow["业务类型"] = item.BusinessType;
  1340. temRow["案件阶段【系统】"] = item.CaseStage;
  1341. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1342. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1343. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1344. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1345. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1346. temRow["严重超期备注原因"] = item.OverDueMemo;
  1347. if (item.ReviewerId != null)
  1348. {
  1349. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1350. }
  1351. foreach (var itemStaff in item.ItemStaffs)
  1352. {
  1353. //if (itemStaff.DoPerson.Status != "试用期")
  1354. //{
  1355. // if (retPoints != null && retPoints.Count > 0)
  1356. // {
  1357. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1358. // }
  1359. //}
  1360. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1361. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1362. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1363. if (item.ReviewerId != null)
  1364. {
  1365. #region 取审核人等级审核等级系数
  1366. VerifyCoefficient vcoefficient
  1367. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1368. v.CheckerId == item.Reviewer.StaffGradeId
  1369. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1370. .FirstOrDefault<VerifyCoefficient>();
  1371. #endregion
  1372. if (vcoefficient != null)
  1373. {
  1374. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1375. }
  1376. }
  1377. }
  1378. temRow["是否一致"] = "不一致";
  1379. temRow["不一致原因"] = "Excel中没有,系统中有";
  1380. retTable.Rows.Add(temRow);
  1381. iList++;
  1382. }
  1383. else
  1384. {
  1385. var temRow = retTable.NewRow();
  1386. int iBegin = iTable;
  1387. int iEnd = iTable;
  1388. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1389. if (iEnd < temDt.Rows.Count - 1)
  1390. {
  1391. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1392. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1393. {
  1394. iEnd++;
  1395. }
  1396. }
  1397. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1398. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1399. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1400. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  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. for (int i = iBegin + 1; i <= iEnd; i++)
  1413. {
  1414. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1415. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1416. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1417. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1418. {
  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. }
  1422. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1423. }
  1424. iTable = iEnd;
  1425. #endregion
  1426. temRow["是否一致"] = "不一致";
  1427. temRow["不一致原因"] = "系统中没有,Excel中有";
  1428. retTable.Rows.Add(temRow);
  1429. iTable++;
  1430. }
  1431. }
  1432. }
  1433. if (iList <= items.Count)
  1434. {
  1435. while (iList < items.Count) {
  1436. var item = items[iList];
  1437. var temRow = retTable.NewRow();
  1438. Utility.Utility.CalBasePoint(item, Rules);
  1439. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1440. try
  1441. {
  1442. retPoints = _calItemJX(verifyCoefficients, item, spDb);
  1443. }
  1444. catch { }
  1445. temRow["我方文号"] = item.CaseNo;
  1446. temRow["处理事项"] = item.DoItem;
  1447. temRow["申请类型"] = item.ApplicationType;
  1448. temRow["业务类型"] = item.BusinessType;
  1449. temRow["案件阶段【系统】"] = item.CaseStage;
  1450. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1451. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1452. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1453. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1454. temRow["基本点数【系统】"] = "";// item.BasePoint?.ToString();
  1455. temRow["严重超期备注原因"] = item.OverDueMemo;
  1456. if (item.ReviewerId != null)
  1457. {
  1458. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1459. }
  1460. foreach (var itemStaff in item.ItemStaffs)
  1461. {
  1462. //if (itemStaff.DoPerson.Status != "试用期")
  1463. //{
  1464. // if (retPoints != null && retPoints.Count > 0)
  1465. // {
  1466. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1467. // }
  1468. //}
  1469. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1470. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1471. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1472. if (item.ReviewerId != null)
  1473. {
  1474. #region 取审核人等级审核等级系数
  1475. VerifyCoefficient vcoefficient
  1476. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1477. v.CheckerId == item.Reviewer.StaffGradeId
  1478. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1479. .FirstOrDefault<VerifyCoefficient>();
  1480. #endregion
  1481. if (vcoefficient != null)
  1482. {
  1483. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1484. }
  1485. }
  1486. }
  1487. temRow["是否一致"] = "不一致";
  1488. temRow["不一致原因"] = "Excel中没有,系统中有";
  1489. iList++;
  1490. retTable.Rows.Add(temRow);
  1491. }
  1492. }
  1493. else
  1494. {
  1495. while (iTable < temDt.Rows.Count)
  1496. {
  1497. var temRow = retTable.NewRow();
  1498. int iBegin = iTable;
  1499. int iEnd = iTable;
  1500. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1501. while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
  1502. temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
  1503. {
  1504. iEnd++;
  1505. }
  1506. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1507. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1508. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1509. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1510. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1511. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1512. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1513. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1514. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1515. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1516. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1517. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1518. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1519. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1520. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1521. for (int i = iBegin + 1; i <= iEnd; i++)
  1522. {
  1523. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1524. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1525. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1526. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1527. {
  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. }
  1531. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["严重超期备注原因"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["严重超期备注原因"]}";
  1532. }
  1533. iTable = iEnd;
  1534. #endregion
  1535. temRow["是否一致"] = "不一致";
  1536. temRow["不一致原因"] = "系统中没有,Excel中有";
  1537. retTable.Rows.Add(temRow);
  1538. iTable++;
  1539. }
  1540. }
  1541. NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
  1542. }
  1543. public List<StaffStatistics> CalItemJX(int itemid)
  1544. {
  1545. var Item = Context.PerformanceItems.Include(p => p.CalMonth)
  1546. .Include(p => p.ItemStaffs).ThenInclude(p => p.DoPerson).ThenInclude(s => s.StaffGrade)
  1547. .Include(p => p.Reviewer)
  1548. .Include(p => p.Customer)
  1549. .FirstOrDefault(p => p.Id == itemid);
  1550. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  1551. return _calItemJX(verifyCoefficients, Item, Context);
  1552. }
  1553. private void _calItemJX(PerformanceItem Item, spDbContext spDb)
  1554. {
  1555. List<VerifyCoefficient> verifyCoefficients = spDb.VerifyCoefficients.ToList<VerifyCoefficient>();
  1556. var jxList = _calItemJX(verifyCoefficients, Item, spDb);
  1557. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == Item.Id);
  1558. spDb.StaffStatistics.RemoveRange(oldJxList);
  1559. spDb.SaveChanges();
  1560. foreach (var jx in jxList)
  1561. {
  1562. if (jx.totalBasePoint == 0)
  1563. {
  1564. continue;
  1565. }
  1566. jx.ItemId = Item.Id;
  1567. spDb.StaffStatistics.Add(jx);
  1568. spDb.SaveChanges();
  1569. }
  1570. }
  1571. /// <summary>
  1572. /// 序号 情况 处理逻辑
  1573. /// 1 处理人试用期算绩效 一人处理 正常算绩效给处理人
  1574. /// 2 处理人试用期不算绩效 一人处理 算给核稿人,如果没有核稿人,这条数据忽略
  1575. /// 3 处理人试用期算绩效 与人合写 合写人算绩效、与合写人一人一半
  1576. /// 4 处理人试用期不算绩效 与人合写 合写人算绩效、全部绩效算给合写人
  1577. /// 5 处理人试用期不算绩效 与人合写 合写人不算算绩效、这条数据忽略
  1578. /// 6 处理人试用期算绩效 与人合写 合写人不算绩效、试用期人员拿一半
  1579. /// 7 处理人不算绩效 一人处理 这条数据忽略
  1580. /// 8 处理人不算绩效 与人合写 合写人算绩效、合写人拿一半
  1581. /// 9 处理人不算绩效 与人合写 合写人不算绩效、这条数据忽略
  1582. /// </summary>
  1583. /// <param name="verifyCoefficients"></param>
  1584. /// <param name="item"></param>
  1585. /// <param name="spDb"></param>
  1586. /// <returns></returns>
  1587. private List<StaffStatistics> _calItemJX(List<VerifyCoefficient> verifyCoefficients, PerformanceItem item, spDbContext spDb)
  1588. {
  1589. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  1590. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  1591. if (item.ReviewerId != null && item.Reviewer == null)
  1592. {
  1593. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  1594. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  1595. }
  1596. List<ItemStaff> temIStaffs = new List<ItemStaff>();
  1597. #region 将试用期且不算绩效的人员从处理人清单中剔除
  1598. int syqUsers = 0;
  1599. foreach(var itemStaff in item.ItemStaffs)
  1600. {
  1601. if (itemStaff.DoPerson == null)
  1602. {
  1603. itemStaff.DoPerson = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == itemStaff.DoPersonId);
  1604. }
  1605. if(itemStaff.DoPerson.Status == "试用期" && !itemStaff.DoPerson.IsCalPerformsnce )
  1606. {
  1607. syqUsers += 1;
  1608. }
  1609. else
  1610. {
  1611. temIStaffs.Add(itemStaff);
  1612. }
  1613. }
  1614. #endregion
  1615. #region 处理人全部是试用期人员,则将核稿人当成处理人(处理人为试用期人)
  1616. if (syqUsers == item.ItemStaffs.Count)
  1617. {
  1618. if(item.Reviewer != null)
  1619. {
  1620. temIStaffs.Add(new ItemStaff() { DoPersonId = item.ReviewerId.Value, ItemId = item.Id });
  1621. }
  1622. }
  1623. #endregion
  1624. bool isPJFP = true;
  1625. double total = temIStaffs.Count();
  1626. if (total >1 && temIStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  1627. {
  1628. total = temIStaffs.Select(i => i.PerformancePoint.Value).Sum();
  1629. isPJFP = false;
  1630. }
  1631. foreach (ItemStaff itemStaff in temIStaffs)
  1632. {
  1633. if(itemStaff.DoPerson == null)
  1634. {
  1635. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  1636. }
  1637. if (itemStaff.DoPerson.IsCalPerformsnce)
  1638. {
  1639. #region 计算各处理人的绩效点数
  1640. double handlerBasePoint;
  1641. if (item.Type != "专案")
  1642. {
  1643. if (isPJFP)
  1644. {
  1645. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1646. }
  1647. else
  1648. {
  1649. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1650. }
  1651. }
  1652. else
  1653. {
  1654. if (itemStaff.PerformancePoint == null)
  1655. {
  1656. if (isPJFP)
  1657. {
  1658. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1659. }
  1660. else
  1661. {
  1662. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1663. }
  1664. }
  1665. else
  1666. {
  1667. if (item.ItemStaffs.Count == 1 && itemStaff.PerformancePoint == 0)
  1668. {
  1669. handlerBasePoint = item.BasePoint.Value;
  1670. }
  1671. else
  1672. {
  1673. handlerBasePoint = itemStaff.PerformancePoint.Value;
  1674. }
  1675. }
  1676. }
  1677. string handlerJxType = $"{item.Type}处理";
  1678. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
  1679. if (temStatic != null)
  1680. {
  1681. temStatic.totalBasePoint += handlerBasePoint;
  1682. if (item.Type == "OA" || item.Type == "新申请")
  1683. {
  1684. temStatic.totalActuallyPoint += (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient);
  1685. }
  1686. else
  1687. {
  1688. temStatic.totalActuallyPoint += handlerBasePoint;
  1689. }
  1690. }
  1691. else
  1692. {
  1693. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsCalPerformsnce)
  1694. {
  1695. if (item.Type == "OA" || item.Type == "新申请")
  1696. {
  1697. if (itemStaff.DoPerson.StaffGrade == null)
  1698. {
  1699. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s => s.Id == itemStaff.DoPerson.StaffGradeId);
  1700. }
  1701. temStatic = new StaffStatistics()
  1702. {
  1703. //CalMonth = calMonth,
  1704. CalMonthId = item.CalMonthId,
  1705. StaffId = itemStaff.DoPersonId,
  1706. totalActuallyPoint = (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient),
  1707. totalBasePoint = handlerBasePoint,
  1708. jxType = handlerJxType
  1709. };
  1710. itemStatistics.Add(temStatic);
  1711. }
  1712. else
  1713. {
  1714. temStatic = new StaffStatistics()
  1715. {
  1716. //CalMonth = calMonth,
  1717. CalMonthId = item.CalMonthId,
  1718. StaffId = itemStaff.DoPersonId,
  1719. totalBasePoint = handlerBasePoint,
  1720. totalActuallyPoint = handlerBasePoint,
  1721. jxType = handlerJxType
  1722. };
  1723. itemStatistics.Add(temStatic);
  1724. }
  1725. }
  1726. }
  1727. #endregion
  1728. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  1729. if (item.ReviewerId != null && item.Type != "专案" &&
  1730. temIStaffs.FirstOrDefault(s => s.DoPersonId == item.ReviewerId) == null)
  1731. {
  1732. if(item.Reviewer == null)
  1733. {
  1734. item.Reviewer = spDb.Staffs.FirstOrDefault(s=>s.Id == item.ReviewerId);
  1735. }
  1736. if (item.Reviewer.IsCalPerformsnce)
  1737. {
  1738. #region 取审核人等级审核等级系数
  1739. VerifyCoefficient vcoefficient
  1740. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1741. v.CheckerId == item.Reviewer.StaffGradeId
  1742. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1743. .FirstOrDefault<VerifyCoefficient>();
  1744. #endregion
  1745. if (vcoefficient != null)
  1746. {
  1747. double reviewerBasePoint = (double)((decimal)handlerBasePoint * (decimal)vcoefficient.Coefficient);
  1748. string temJxType = $"{item.Type}审核";
  1749. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonthId == item.CalMonthId).FirstOrDefault();
  1750. if (temReviewerStatic != null)
  1751. {
  1752. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  1753. temReviewerStatic.totalActuallyPoint += reviewerBasePoint;
  1754. }
  1755. else
  1756. {
  1757. if (itemStaff.DoPerson.Status != "试用期" && item.Reviewer.IsCalPerformsnce) //判断是否在职
  1758. {
  1759. temReviewerStatic = new StaffStatistics()
  1760. {
  1761. CalMonthId = item.CalMonthId,
  1762. StaffId = item.ReviewerId.Value,
  1763. totalBasePoint = reviewerBasePoint,
  1764. totalActuallyPoint = reviewerBasePoint,
  1765. jxType = temJxType
  1766. };
  1767. itemStatistics.Add(temReviewerStatic);
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. #endregion
  1774. }
  1775. }
  1776. return itemStatistics;
  1777. }
  1778. private void _CalJXPoint(CalMonth calMonth,spDbContext spDb)
  1779. {
  1780. NanduStatics gspjXS = DegreeOfDifficulty(calMonth,spDb);
  1781. calMonth.NanduXS = gspjXS.NanduXS;
  1782. calMonth.S = (double)gspjXS.S;
  1783. calMonth.A = (double)gspjXS.A;
  1784. calMonth.B = (double)gspjXS.B;
  1785. calMonth.C = (double)gspjXS.C;
  1786. calMonth.D = (double)gspjXS.D;
  1787. var retList = spDb.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id).ToList();
  1788. #region 新申请处理+专案处理 奖励点数
  1789. double jlPoint = 0;
  1790. if (calMonth.S.HasValue)
  1791. {
  1792. jlPoint = jlPoint + (calMonth.S.Value * 1.5);
  1793. }
  1794. if (calMonth.A.HasValue)
  1795. {
  1796. jlPoint = jlPoint + (calMonth.A.Value * 0.5);
  1797. }
  1798. #endregion
  1799. #region 难度系数
  1800. IDictionary<int, NanduStatics> staffXiShu = new Dictionary<int, NanduStatics>();
  1801. IDictionary<int, NanduStatics> ReivewerXiShu = new Dictionary<int, NanduStatics>();
  1802. foreach (StaffStatistics ss in retList)
  1803. {
  1804. if (ss.jxType == "新申请处理" || ss.jxType == "专案处理")
  1805. {
  1806. #region 新申请处理+专案处理
  1807. if (!staffXiShu.ContainsKey(ss.StaffId))
  1808. {
  1809. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb,false,true);
  1810. staffXiShu.Add(ss.StaffId, nandu);
  1811. }
  1812. ss.FinianlPoint = ss.totalActuallyPoint * staffXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1813. ss.NanduXS = staffXiShu[ss.StaffId].NanduXS;
  1814. ss.S = (double)staffXiShu[ss.StaffId].S;
  1815. ss.A = (double)staffXiShu[ss.StaffId].A;
  1816. ss.B = (double)staffXiShu[ss.StaffId].B;
  1817. ss.C = (double)staffXiShu[ss.StaffId].C;
  1818. ss.D = (double)staffXiShu[ss.StaffId].D;
  1819. #endregion
  1820. }
  1821. else
  1822. {
  1823. if (ss.jxType == "新申请审核")
  1824. {
  1825. if (!ReivewerXiShu.ContainsKey(ss.StaffId))
  1826. {
  1827. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb, true);
  1828. ReivewerXiShu.Add(ss.StaffId, nandu);
  1829. }
  1830. ss.FinianlPoint = ss.totalBasePoint * ReivewerXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1831. ss.NanduXS = ReivewerXiShu[ss.StaffId].NanduXS;
  1832. ss.S = (double)ReivewerXiShu[ss.StaffId].S;
  1833. ss.A = (double)ReivewerXiShu[ss.StaffId].A;
  1834. ss.B = (double)ReivewerXiShu[ss.StaffId].B;
  1835. ss.C = (double)ReivewerXiShu[ss.StaffId].C;
  1836. ss.D = (double)ReivewerXiShu[ss.StaffId].D;
  1837. spDb.SaveChanges();
  1838. }
  1839. else
  1840. {
  1841. ss.FinianlPoint = ss.totalActuallyPoint;
  1842. spDb.SaveChanges();
  1843. }
  1844. }
  1845. }
  1846. var xsqList = retList.Where(ss => ss.jxType == "新申请处理" || ss.jxType == "专案处理").ToList();
  1847. var totalFPBLPoint = xsqList.Sum(p=>p.FinianlPoint); //新申请处理+专案 分配比率总点数
  1848. var totalActionPoint = xsqList.Sum(p=>p.totalActuallyPoint); //新申请处理+专案 原始总点数
  1849. foreach (StaffStatistics ss in xsqList)
  1850. {
  1851. ss.FinianlPoint = ss.FinianlPoint / totalFPBLPoint * (totalActionPoint + jlPoint);
  1852. spDb.SaveChanges();
  1853. }
  1854. #endregion
  1855. }
  1856. public void CalJXPoint(int year, int month)
  1857. {
  1858. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1859. if (calMonth != null)
  1860. {
  1861. using (var t = Context.Database.BeginTransaction())
  1862. {
  1863. try
  1864. {
  1865. var result = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
  1866. Context.StaffStatistics.RemoveRange(result);
  1867. var itemList = Context.PerformanceItems
  1868. .Include(s => s.ItemStaffs)
  1869. .Include(p=>p.Customer)
  1870. .Include(p=>p.Reviewer)
  1871. .Where(s => s.CalMonthId == calMonth.Id).ToList();
  1872. var rules = Context.BasePointRules.ToList();
  1873. foreach (var item in itemList)
  1874. {
  1875. Utility.Utility.CalBasePoint(item, rules);
  1876. Context.SaveChanges();
  1877. if (item.BasePoint > 0)
  1878. {
  1879. _calItemJX(item,Context);
  1880. }
  1881. else
  1882. {
  1883. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  1884. Context.StaffStatistics.RemoveRange(oldJxList);
  1885. }
  1886. }
  1887. _CalJXPoint(calMonth, Context);
  1888. t.Commit();
  1889. }
  1890. catch (Exception ex)
  1891. {
  1892. t.Rollback();
  1893. }
  1894. }
  1895. }
  1896. }
  1897. public ProcessTask FinishedCalMonth(int year,int month)
  1898. {
  1899. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == year && c.Month == month);
  1900. if (calMonth != null)
  1901. {
  1902. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  1903. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  1904. var filePath = Path.Combine(attachfileSavePath, filename);
  1905. var fileTask = new FileProcessTask()
  1906. {
  1907. Id = Guid.NewGuid().ToString(),
  1908. FileName = filename,
  1909. FilePath = filePath,
  1910. Processed = 0
  1911. };
  1912. fileTaskService.Add(fileTask);
  1913. ExportDataResult result = new ExportDataResult()
  1914. {
  1915. fileTask = fileTask,
  1916. calMonth = calMonth
  1917. };
  1918. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(_FinishedCalMonth));
  1919. t.Start(result);
  1920. return fileTask;
  1921. }
  1922. return null;
  1923. }
  1924. /// <summary>
  1925. /// 新申请/专案:
  1926. /// 调整点数 = 分配比例点数/分配比例点数之和*总点数
  1927. /// 等级调整点数+项目组点数之和 = 基础点数 * 代理人等级系数 + 项目组案件调整点数
  1928. /// 分配比例点数 = 个人平均难度系数 / 总平均难度系数 *(等级调整点数+项目组点数之和)
  1929. /// 总点数=等级调整点数+项目组点数之和+奖励点数
  1930. /// 奖励点数= S案数量*1.5 + A案数量 * 0.5
  1931. /// 难度系数=(S案数量*2.5 + A案数量* 1.5 + B案数量*1.0 + C案数量*0.7+ D案数量*0.4) / 总案件数量
  1932. /// 总案件数量= S案数量 + A案数量 + B案数量 + C案数量+ D案数量
  1933. /// OA :
  1934. /// 调整点数= 基础点数 * 等级系数
  1935. /// 其他:
  1936. /// 直接加和基础点数 不需要乘以系数
  1937. /// </summary>
  1938. /// <param name="year"></param>
  1939. /// <param name="month"></param>
  1940. /// <returns></returns>
  1941. private void _FinishedCalMonth(object proecssTask)
  1942. {
  1943. ExportDataResult result = (ExportDataResult)proecssTask;
  1944. CalMonth calMonth = result.calMonth;
  1945. if (calMonth != null || calMonth.Status !=4)
  1946. {
  1947. spDbContext spDb = new spDbContext();
  1948. calMonth = spDb.CalMonths.FirstOrDefault(c=>c.Id == calMonth.Id);
  1949. using (var t = spDb.Database.BeginTransaction())
  1950. {
  1951. try
  1952. {
  1953. _RefreshBasePoint(calMonth, spDb);
  1954. //_CalJXPoint(calMonth, Context);
  1955. calMonth.Status = 4;
  1956. spDb.SaveChanges();
  1957. //等级核算案件统计
  1958. _StatisticsLevelCount(calMonth.Year, calMonth.Month, spDb);
  1959. #region 将待审核的申诉全部修改为已审核
  1960. var aList = spDb.AppealRecords.Where(a => a.State == 0).ToList();
  1961. aList.ForEach(a =>a.State = 1);
  1962. spDb.SaveChanges();
  1963. #endregion
  1964. t.Commit();
  1965. result.fileTask.Finished = true;
  1966. }
  1967. catch (Exception ex)
  1968. {
  1969. t.Rollback();
  1970. result.fileTask.ErrorMessage = ex.Message;
  1971. result.fileTask.Finished = true;
  1972. }
  1973. }
  1974. }
  1975. else
  1976. {
  1977. result.fileTask.ErrorMessage = "指定月份没有数据或者已归档!";
  1978. result.fileTask.Finished = true;
  1979. }
  1980. }
  1981. /// <summary>
  1982. /// 计算指定用户,指定年月的绩效统计信息
  1983. /// </summary>
  1984. /// <param name="userid"></param>
  1985. /// <param name="year"></param>
  1986. /// <param name="month"></param>
  1987. /// <returns></returns>
  1988. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  1989. {
  1990. //object retList;
  1991. //string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
  1992. //if(!MyMemoryCache.TryGetValue(strKey,out retList))
  1993. //{
  1994. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1995. if (calMonth == null)
  1996. {
  1997. return null;
  1998. }
  1999. else
  2000. {
  2001. return _CalMyStatistics(calMonth, userid);
  2002. #region old code
  2003. //if (calMonth.Status == 4)
  2004. //{
  2005. // //已归档,归档数据库中直接取出记录
  2006. // if (userid == null)
  2007. // {
  2008. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  2009. // }
  2010. // else
  2011. // {
  2012. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  2013. // }
  2014. //}
  2015. //else
  2016. //{
  2017. // try
  2018. // {
  2019. // retList = _CalMyStatistics(calMonth, userid);
  2020. // }
  2021. // catch(Exception ex)
  2022. // {
  2023. // StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  2024. // sw.WriteLine($"{ex.Message}");
  2025. // sw.Flush();
  2026. // sw.Close();
  2027. // sw.Dispose();
  2028. // }
  2029. //}
  2030. //// Set cache options.
  2031. //var cacheEntryOptions = new MemoryCacheEntryOptions()
  2032. // // Keep in cache for this time, reset time if accessed.
  2033. // .SetSlidingExpiration(TimeSpan.FromHours(1));
  2034. //foreach(var temObj in (List<StaffStatistics>)retList)
  2035. //{
  2036. // temObj.CalMonth.PerformanceItems = null;
  2037. //}
  2038. //// Save data in cache.
  2039. //MyMemoryCache.SetValue(strKey, retList);
  2040. //return (List<StaffStatistics>)retList;
  2041. #endregion
  2042. }
  2043. //}
  2044. //else
  2045. //{
  2046. // var temList = (List<StaffStatistics>)retList;
  2047. // foreach (var temObj in temList)
  2048. // {
  2049. // temObj.CalMonth.PerformanceItems = null;
  2050. // }
  2051. // return temList;
  2052. //}
  2053. }
  2054. private string GetExpress(IList<FieldCondition> conditions)
  2055. {
  2056. string str = "";
  2057. foreach(var c in conditions)
  2058. {
  2059. if (string.IsNullOrEmpty(str))
  2060. {
  2061. str = c.ToExpressString("s");
  2062. }
  2063. else
  2064. {
  2065. if(c.LogicOperate == LogicEnum.And)
  2066. {
  2067. str = $"({str}) && {c.ToExpressString("s")}";
  2068. }
  2069. else
  2070. {
  2071. str = $"({str}) || {c.ToExpressString("s")}";
  2072. }
  2073. }
  2074. }
  2075. return str;
  2076. }
  2077. [HttpGet,HttpPost]
  2078. public FileProcessTask ExportData(QueryFilter queryFilter)
  2079. {
  2080. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  2081. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  2082. var filePath = Path.Combine(attachfileSavePath, filename);
  2083. var fileTask = new FileProcessTask()
  2084. {
  2085. Id = Guid.NewGuid().ToString(),
  2086. FileName = filename,
  2087. FilePath = filePath,
  2088. Processed = 0
  2089. };
  2090. fileTaskService.Add(fileTask);
  2091. ThreadObject threadObject = new ThreadObject()
  2092. {
  2093. queryFilter = queryFilter,
  2094. fileTask = fileTask
  2095. };
  2096. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  2097. t.Start(threadObject);
  2098. return fileTask;
  2099. }
  2100. internal class ThreadObject
  2101. {
  2102. public QueryFilter queryFilter { get; set; }
  2103. public FileProcessTask fileTask { get; set; }
  2104. }
  2105. private void ExportDataThread(object tObj)
  2106. {
  2107. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  2108. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  2109. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2110. var retList = response
  2111. .Include(p=>p.Customer)
  2112. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  2113. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  2114. .Include(p=>p.PreOastaff)
  2115. .Include(p=>p.CalMonth)
  2116. .ToList<PerformanceItem>();
  2117. DataTable dt = new DataTable();
  2118. #region 添加栏位
  2119. dt.Columns.Add("我方文号",typeof(string));
  2120. dt.Columns.Add("申请类型", typeof(string));
  2121. dt.Columns.Add("业务类型", typeof(string));
  2122. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  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("前一次OA处理事项系数", typeof(string));
  2128. dt.Columns.Add("前一次OA处理人", typeof(string));
  2129. dt.Columns.Add("处理人等级", typeof(string));
  2130. dt.Columns.Add("基本点数", typeof(string));
  2131. dt.Columns.Add("核稿系数", typeof(string));
  2132. dt.Columns.Add("核稿绩效", 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. #endregion
  2152. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  2153. fileTask.Size = retList.Count;
  2154. foreach (var item in retList)
  2155. {
  2156. fileTask.Processed += 1;
  2157. if (item.CaseNo.StartsWith("J"))
  2158. {
  2159. continue;
  2160. }
  2161. try
  2162. {
  2163. var row = dt.NewRow();
  2164. row["我方文号"] = item.CaseNo;
  2165. row["申请类型"] = item.ApplicationType;
  2166. row["业务类型"] = item.BusinessType;
  2167. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  2168. row["处理事项"] = item.DoItem;
  2169. row["案件阶段"] = item.CaseStage;
  2170. row["案件系数"] = item.CaseCoefficient;
  2171. row["处理事项系数"] = item.DoItemCoefficient;
  2172. row["前一次OA处理事项系数"] = "";
  2173. if (item.PreOastaffId.HasValue)
  2174. {
  2175. row["前一次OA处理人"] = item.PreOastaff?.Name;
  2176. }
  2177. string strISLevels = "";
  2178. string strISNames = "";
  2179. foreach (var istaff in item.ItemStaffs)
  2180. {
  2181. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  2182. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  2183. }
  2184. row["处理人等级"] = strISLevels;
  2185. row["基本点数"] = item.BasePoint;
  2186. row["处理人"] = strISNames;
  2187. row["核稿人"] = item.Reviewer?.Name;
  2188. if (item.ReviewerId != null && item.BasePoint.HasValue)
  2189. {
  2190. System.Diagnostics.Debug.WriteLine($"{item.ReviewerId}");
  2191. var jxList = new spDbContext().StaffStatistics.Where<StaffStatistics>(s => s.ItemId == item.Id).ToList();//_calItemJX( verifyCoefficients, item, new spDbContext());
  2192. row["核稿系数"] = "";
  2193. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  2194. if (temJx != null)
  2195. {
  2196. row["核稿绩效"] = temJx.totalBasePoint;
  2197. }
  2198. }
  2199. row["客户名称"] = item.Customer?.Name;
  2200. row["申请人"] = item.ApplicationName;
  2201. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  2202. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  2203. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  2204. row["案件类型"] = item.CaseType;
  2205. row["案件状态"] = item.CaseState;
  2206. row["处理事项备注"] = item.DoItemState;
  2207. row["处理状态"] = item.DoItemState;
  2208. row["案件名称"] = item.CaseName;
  2209. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  2210. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  2211. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  2212. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  2213. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  2214. row["备注"] = item.DoItemMemo;
  2215. dt.Rows.Add(row);
  2216. }
  2217. catch(Exception ex)
  2218. {
  2219. throw ex;
  2220. }
  2221. }
  2222. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  2223. fileTask.Finished = true;
  2224. }
  2225. [HttpPost]
  2226. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  2227. {
  2228. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  2229. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2230. int totals = response.ToList<PerformanceItem>().Count;
  2231. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  2232. {
  2233. response = response
  2234. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2235. .Include(pi => pi.Reviewer)
  2236. .Include(pi => pi.Customer)
  2237. .Include(pi => pi.CalMonth)
  2238. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2239. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  2240. }
  2241. else
  2242. {
  2243. response = response
  2244. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2245. .Include(pi => pi.Reviewer)
  2246. .Include(pi => pi.Customer)
  2247. .Include(pi => pi.CalMonth)
  2248. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2249. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  2250. }
  2251. ret.TotalCount = totals;
  2252. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  2253. #region 将某些属性设为null,避免循环取值造成返回json过大
  2254. foreach (PerformanceItem item in retList)
  2255. {
  2256. foreach (ItemStaff itemStaff in item.ItemStaffs)
  2257. {
  2258. itemStaff.DoPerson.ItemStaffs = null;
  2259. itemStaff.DoPerson.ReviewerItems = null;
  2260. itemStaff.DoPerson.Customers = null;
  2261. itemStaff.Item = null;
  2262. }
  2263. if (item.Reviewer != null)
  2264. {
  2265. item.Reviewer.ReviewerItems = null;
  2266. item.Reviewer.Customers = null;
  2267. item.Reviewer.ItemStaffs = null;
  2268. }
  2269. if (item.WorkflowUser != null)
  2270. {
  2271. item.WorkflowUser.ReviewerItems = null;
  2272. item.WorkflowUser.Customers = null;
  2273. item.WorkflowUser.ItemStaffs = null;
  2274. }
  2275. if (item.Customer != null)
  2276. {
  2277. item.Customer.PerformanceItems = null;
  2278. item.Customer.ResponseMan = null;
  2279. }
  2280. if (item.CalMonth != null)
  2281. {
  2282. item.CalMonth.PerformanceItems = null;
  2283. }
  2284. }
  2285. #endregion
  2286. ret.Results = retList.ToList();
  2287. //string str= System.Text.Json.JsonSerializer.Serialize(ret);
  2288. return ret;
  2289. }
  2290. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  2291. {
  2292. string strExpress = "";
  2293. string strCalMonth = "";
  2294. if (queryFilter.CalMonthId.HasValue)
  2295. {
  2296. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  2297. }
  2298. else
  2299. {
  2300. if(queryFilter.jxType == jxType.finished)
  2301. {
  2302. strCalMonth = $"s.CalMonth.Status == 4";
  2303. }
  2304. else
  2305. {
  2306. strCalMonth = $"s.CalMonth.Status != 4";
  2307. }
  2308. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  2309. }
  2310. if (!string.IsNullOrEmpty(strExpress))
  2311. {
  2312. strExpress = $"{strExpress} && {strCalMonth}";
  2313. }
  2314. else
  2315. {
  2316. strExpress = strCalMonth;
  2317. }
  2318. if (queryFilter.ConditionTree != null)
  2319. {
  2320. string strTem = GetExpress(queryFilter.ConditionTree);
  2321. if (!string.IsNullOrEmpty(strTem))
  2322. {
  2323. strExpress = $"{strExpress} && ({strTem})";
  2324. }
  2325. }
  2326. var interpreter = new Interpreter();
  2327. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  2328. IQueryable<PerformanceItem> response;
  2329. if (queryFilter.userId > 0)
  2330. {
  2331. if (queryFilter.DoingOrReview == 0)
  2332. {
  2333. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  2334. }
  2335. else
  2336. {
  2337. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  2338. }
  2339. }
  2340. else
  2341. {
  2342. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  2343. }
  2344. return response;
  2345. }
  2346. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  2347. {
  2348. ApiSaveResponse retResponse = new ApiSaveResponse();
  2349. retResponse.Success = true;
  2350. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  2351. {
  2352. using (var t = Context.Database.BeginTransaction())
  2353. {
  2354. try
  2355. {
  2356. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  2357. if (calMonth == null)
  2358. {
  2359. retResponse.Success = false;
  2360. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  2361. return retResponse;
  2362. }
  2363. else
  2364. {
  2365. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  2366. projectContents.ProjectContentRecord.CalMonth = null;
  2367. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  2368. projectContents.ProjectContentRecord.StaffId = staff.Id;
  2369. projectContents.ProjectContentRecord.State = 0;
  2370. }
  2371. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  2372. if (project != null)
  2373. {
  2374. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  2375. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  2376. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  2377. if(pRecord != null)
  2378. {
  2379. retResponse.Success = false;
  2380. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  2381. return retResponse;
  2382. }
  2383. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  2384. foreach (var doItem in projectContents.ProjectWorkContents)
  2385. {
  2386. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  2387. Context.ProjectWorkContents.Add(doItem);
  2388. }
  2389. t.Commit();
  2390. }
  2391. else
  2392. {
  2393. retResponse.Success = false;
  2394. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  2395. return retResponse;
  2396. }
  2397. }
  2398. catch (Exception ex)
  2399. {
  2400. retResponse.Success = false;
  2401. retResponse.ErrorMessage = ex.Message;
  2402. t.Rollback();
  2403. return retResponse;
  2404. }
  2405. }
  2406. }
  2407. return retResponse;
  2408. }
  2409. public PerformanceItem GetCaseInfo(string CaseNo)
  2410. {
  2411. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  2412. if(retObj == null)
  2413. {
  2414. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  2415. }
  2416. return retObj;
  2417. }
  2418. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  2419. {
  2420. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  2421. if (retObj == null)
  2422. {
  2423. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  2424. }
  2425. return retObj;
  2426. }
  2427. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage,bool UpdateFromIPEasy=true)
  2428. {
  2429. var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2430. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  2431. if (retObj == null || UpdateFromIPEasy)
  2432. {
  2433. var temObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(
  2434. new PerformanceItem() {CaseNo =CaseNo,DoItem =DoItem,CaseStage = caseStage },
  2435. Context
  2436. );// IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  2437. System.Dynamic.ExpandoObject temExpandoObject = (System.Dynamic.ExpandoObject)temObj;
  2438. retObj = new PerformanceItem();
  2439. retObj.CaseNo = temObj.CaseNo.ToString();
  2440. retObj.CaseName = temObj.CaseName.ToString();
  2441. try
  2442. {
  2443. if (temObj.ApplicationType != null)
  2444. retObj.ApplicationType = temObj.ApplicationType.ToString();
  2445. if (temObj.CaseMemo != null)
  2446. retObj.CaseMemo = temObj.CaseMemo.ToString();
  2447. if (temObj.BusinessType != null)
  2448. retObj.BusinessType = temObj.BusinessType.ToString();
  2449. if (temObj.DoItem != null)
  2450. retObj.DoItem = temObj.DoItem.ToString();
  2451. if (temObj.CaseStage != null)
  2452. retObj.CaseStage = temObj.CaseStage.ToString();
  2453. if (temObj.CaseType != null)
  2454. retObj.CaseType = temObj.CaseType.ToString();
  2455. if (temObj.DoItemState != null)
  2456. retObj.DoItemState = temObj.DoItemState.ToString();
  2457. if (temObj.DoItemCoefficient != null)
  2458. retObj.DoItemCoefficient = temObj.DoItemCoefficient.ToString();
  2459. if (temObj.CaseCoefficient != null)
  2460. retObj.CaseCoefficient = temObj.CaseCoefficient.ToString();
  2461. if (temObj.EntrustingDate != null)
  2462. {
  2463. if (!string.IsNullOrEmpty(temObj.EntrustingDate.ToString()))
  2464. retObj.EntrustingDate = DateTime.Parse(temObj.EntrustingDate.ToString());
  2465. }
  2466. if(temObj.Country != null)
  2467. {
  2468. retObj.Country = temObj.Country.ToString();
  2469. }
  2470. if (temObj.InternalDate != null)
  2471. {
  2472. if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
  2473. retObj.InternalDate = DateTime.Parse(temObj.InternalDate.ToString());
  2474. }
  2475. if (temObj.CustomerLimitDate != null)
  2476. {
  2477. if (!string.IsNullOrEmpty(temObj.CustomerLimitDate.ToString()))
  2478. retObj.CustomerLimitDate = DateTime.Parse(temObj.CustomerLimitDate.ToString());
  2479. }
  2480. if (temObj.ReturnDate != null)
  2481. {
  2482. if (!string.IsNullOrEmpty(temObj.ReturnDate.ToString()))
  2483. retObj.ReturnDate = DateTime.Parse(temObj.ReturnDate.ToString());
  2484. }
  2485. if (temObj.FinalizationDate != null)
  2486. {
  2487. if (!string.IsNullOrEmpty(temObj.FinalizationDate.ToString()))
  2488. retObj.FinalizationDate = DateTime.Parse(temObj.FinalizationDate.ToString());
  2489. }
  2490. if (temObj.FinishedDate != null)
  2491. {
  2492. if (!string.IsNullOrEmpty(temObj.FinishedDate.ToString()))
  2493. retObj.FinishedDate = DateTime.Parse(temObj.FinishedDate.ToString());
  2494. }
  2495. }
  2496. catch { }
  2497. int temWordCount;
  2498. if (temObj.WordCount != null)
  2499. {
  2500. if (int.TryParse(temObj.WordCount, out temWordCount))
  2501. {
  2502. retObj.WordCount = temWordCount;
  2503. }
  2504. }
  2505. try
  2506. {
  2507. if (temObj.CustomerName != null)
  2508. {
  2509. string strCustomer = temObj.CustomerName.ToString();
  2510. retObj.Customer = new Customer() { Name = strCustomer };
  2511. var temCustomer = Context.Customers.Where(c => c.Name == strCustomer.Trim()).FirstOrDefault();
  2512. if (temCustomer != null)
  2513. {
  2514. retObj.CustomerId = temCustomer.Id;
  2515. }
  2516. }
  2517. }
  2518. catch { }
  2519. try
  2520. {
  2521. if (temObj.Reviewer != null)
  2522. {
  2523. string strReViewer = temObj.Reviewer.ToString().Replace("-君龙", "");
  2524. var temReviewer = Context.Staffs.Where(s => s.Name == strReViewer.Trim()).FirstOrDefault();
  2525. if (temReviewer != null)
  2526. {
  2527. retObj.ReviewerId = temReviewer.Id;
  2528. }
  2529. }
  2530. }
  2531. catch { }
  2532. try
  2533. {
  2534. if (temObj.WorkflowUser != null)
  2535. {
  2536. string strWorkflowUser = temObj.WorkflowUser.ToString().Replace("-君龙", "");
  2537. var temReviewer = Context.Staffs.Where(s => s.Name == strWorkflowUser.Trim()).FirstOrDefault();
  2538. if (temReviewer != null)
  2539. {
  2540. retObj.WorkflowUserId = temReviewer.Id;
  2541. }
  2542. }
  2543. }
  2544. catch { }
  2545. if (temObj.DoPersons != null)
  2546. {
  2547. string DoPersons = temObj.DoPersons.ToString();
  2548. string[] Persons = DoPersons.Split(new char[] { ',' });
  2549. List<ItemStaff> itemStaffs = new List<ItemStaff>();
  2550. foreach (var doPerson in Persons)
  2551. {
  2552. string strName = doPerson.Replace("-君龙","");
  2553. itemStaffs.Add(new ItemStaff() { DoPerson = new Staff() { Name = strName } });
  2554. }
  2555. retObj.ItemStaffs = itemStaffs;
  2556. }
  2557. }
  2558. return retObj;
  2559. }
  2560. public PerformanceItem GetItemInfoByMonthId(string CaseNo, string DoItem, string caseStage,int calMonthId)
  2561. {
  2562. var retObj = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2563. && p.DoItem == DoItem.Trim() && p.CalMonthId == calMonthId);
  2564. if(retObj != null)
  2565. {
  2566. if(string.IsNullOrEmpty (retObj.CaseStage) && string.IsNullOrEmpty(caseStage))
  2567. {
  2568. return retObj;
  2569. }
  2570. else
  2571. {
  2572. if(retObj.CaseStage == caseStage)
  2573. {
  2574. return retObj;
  2575. }
  2576. else
  2577. {
  2578. return null;
  2579. }
  2580. }
  2581. }
  2582. else
  2583. {
  2584. return null;
  2585. }
  2586. }
  2587. public bool MovePerformance2ProjectInfo()
  2588. {
  2589. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  2590. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  2591. var pList = response.ToList<PerformanceItem>();
  2592. foreach(var p in pList)
  2593. {
  2594. ProjectInfo project = new ProjectInfo();
  2595. project.CaseNo = p.CaseNo;
  2596. project.CaseName = p.CaseName;
  2597. project.CaseState = 0;
  2598. project.CaseType = p.CaseType;
  2599. project.CustomerId = p.CustomerId;
  2600. project.ReviewerId = p.ReviewerId;
  2601. Context.ProjectInfos.Add(project);
  2602. foreach(ItemStaff iStaff in p.ItemStaffs)
  2603. {
  2604. Context.ItemStaffs.Remove(iStaff);
  2605. }
  2606. Context.PerformanceItems.Remove(p);
  2607. Context.SaveChanges();
  2608. }
  2609. return true;
  2610. }
  2611. #region 等级考核计算
  2612. /// <summary>
  2613. /// 等级考核案件量统计
  2614. /// </summary>
  2615. /// <param name="calMonthId"></param>
  2616. /// <returns></returns>
  2617. private List<StaffStatisticsforLevel> StatisticsCount(int calMonthId,spDbContext spDb )
  2618. {
  2619. var retlist = new List<StaffStatisticsforLevel>();
  2620. #region 新申请
  2621. var newList = spDb.PerformanceItems.Include(p => p.ItemStaffs).ThenInclude(p=>p.DoPerson)
  2622. .Include(p=>p.CalMonth)
  2623. .Where(p=>p.CalMonthId == calMonthId && p.BasePoint >0
  2624. && (p.Type =="新申请" || p.Type =="专案" || (p.Type == "其它" && p.WordCount >0 && (p.DoItem =="新申请" || p.DoItem == "翻译")))
  2625. ).ToList();
  2626. foreach(var p in newList)
  2627. {
  2628. #region 严重延期降系数
  2629. string strCaseCeoffcient = p.CaseCoefficient;
  2630. if (string.IsNullOrEmpty(strCaseCeoffcient))
  2631. {
  2632. strCaseCeoffcient = "B";
  2633. }
  2634. if (p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo))
  2635. {
  2636. switch (p.CaseCoefficient)
  2637. {
  2638. case "S":
  2639. strCaseCeoffcient = "A";
  2640. break;
  2641. case "A":
  2642. strCaseCeoffcient = "B";
  2643. break;
  2644. case "B":
  2645. strCaseCeoffcient = "C";
  2646. break;
  2647. case "C":
  2648. strCaseCeoffcient = "D";
  2649. break;
  2650. }
  2651. }
  2652. #endregion
  2653. var pointList = spDb.StaffStatistics.Include(i=>i.Staff).Where(i=>i.ItemId == p.Id).ToList();
  2654. #region 新申请处理
  2655. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2656. int doPersons = doList.Count();
  2657. if (p.ItemStaffs.Count() > doList.Count())
  2658. {
  2659. doPersons = p.ItemStaffs.Count;
  2660. foreach (ItemStaff itemStaff in p.ItemStaffs)
  2661. {
  2662. Staff staff = itemStaff.DoPerson;
  2663. if (staff == null)
  2664. {
  2665. staff = spDb.Staffs.FirstOrDefault(s => s.Id == itemStaff.DoPersonId);
  2666. }
  2667. if (staff.Status == "试用期")
  2668. {
  2669. doPersons =doPersons- 1;
  2670. }
  2671. }
  2672. }
  2673. foreach(var h in doList)
  2674. {
  2675. var temObj = retlist.FirstOrDefault(s=>s.StaffId == h.StaffId && s.Type == "新申请" && s.isReview == false);
  2676. if(temObj == null)
  2677. {
  2678. temObj = new StaffStatisticsforLevel();
  2679. temObj.StaffId = h.StaffId;
  2680. temObj.GradeId = h.Staff.StaffGradeId.Value ;
  2681. if(temObj.GradeId == 0)
  2682. {
  2683. System.Diagnostics.Debug.WriteLine("");
  2684. }
  2685. temObj.CalMonthId = p.CalMonthId;
  2686. temObj.Type = "新申请";
  2687. retlist.Add(temObj);
  2688. }
  2689. switch (strCaseCeoffcient)
  2690. {
  2691. case "S":
  2692. if(p.Type == "专案")
  2693. {
  2694. temObj.S += h.totalBasePoint.Value;
  2695. }
  2696. else
  2697. {
  2698. temObj.S+=(double)(1.0M/ (decimal)doPersons);
  2699. }
  2700. break;
  2701. case "A":
  2702. if (p.Type == "专案")
  2703. {
  2704. temObj.A += h.totalBasePoint.Value;
  2705. }
  2706. else
  2707. {
  2708. temObj.A += (double)(1.0M / (decimal)doPersons);
  2709. }
  2710. break;
  2711. case "B":
  2712. if (p.Type == "专案")
  2713. {
  2714. temObj.B += h.totalBasePoint.Value;
  2715. }
  2716. else
  2717. {
  2718. temObj.B += (double)(1.0M / (decimal)doPersons);
  2719. }
  2720. break;
  2721. case "C":
  2722. if (p.Type == "专案")
  2723. {
  2724. temObj.C += h.totalBasePoint.Value;
  2725. }
  2726. else
  2727. {
  2728. temObj.C += (double)(1.0M / (decimal)doPersons);
  2729. }
  2730. break;
  2731. case "D":
  2732. if (p.Type == "专案")
  2733. {
  2734. temObj.D += h.totalBasePoint.Value;
  2735. }
  2736. else
  2737. {
  2738. temObj.D += (double)(1.0M / (decimal)doPersons);
  2739. }
  2740. break;
  2741. }
  2742. }
  2743. #endregion
  2744. #region 新申请审核
  2745. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2746. if(reviewer != null)
  2747. {
  2748. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "新申请" && s.isReview == true);
  2749. if(temObj == null)
  2750. {
  2751. temObj = new StaffStatisticsforLevel();
  2752. temObj.StaffId = reviewer.StaffId;
  2753. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2754. if (temObj.GradeId == 0)
  2755. {
  2756. System.Diagnostics.Debug.WriteLine("");
  2757. }
  2758. temObj.CalMonthId = p.CalMonthId;
  2759. temObj.Type = "新申请";
  2760. temObj.isReview = true;
  2761. retlist.Add(temObj);
  2762. }
  2763. switch (strCaseCeoffcient)
  2764. {
  2765. case "S":
  2766. temObj.S += 1;
  2767. break;
  2768. case "A":
  2769. temObj.A += 1;
  2770. break;
  2771. case "B":
  2772. temObj.B += 1;
  2773. break;
  2774. case "C":
  2775. temObj.C += 1;
  2776. break;
  2777. case "D":
  2778. temObj.D += 1;
  2779. break;
  2780. }
  2781. }
  2782. #endregion
  2783. }
  2784. #endregion
  2785. #region 国内OA
  2786. var cnOA = spDb.PerformanceItems.Include(x=>x.ItemStaffs)
  2787. .Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && x.CaseNo.Contains("CN") && x.BasePoint > 0.3
  2788. ).ToList();
  2789. //因为不是所有的OA案件都是答复审查意见,所以有些应该没有一通或首次转入信息,去掉这个条件:
  2790. //&& (x.CaseStage == "一通" || x.DoItemCoefficient.Contains("首次转入"))
  2791. foreach (var p in cnOA)
  2792. {
  2793. var pointList = spDb.StaffStatistics.Include(i => i.Staff).Where(i=> i.ItemId == p.Id).ToList();
  2794. #region 国内OA处理
  2795. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2796. foreach (var h in doList)
  2797. {
  2798. var temObj = retlist.FirstOrDefault(s => s.StaffId == h.StaffId && s.Type == "国内OA" && s.isReview == false);
  2799. if (temObj == null)
  2800. {
  2801. temObj = new StaffStatisticsforLevel();
  2802. temObj.StaffId = h.StaffId;
  2803. temObj.GradeId = h.Staff.StaffGradeId.Value ;
  2804. if (temObj.GradeId == 0)
  2805. {
  2806. System.Diagnostics.Debug.WriteLine("");
  2807. }
  2808. temObj.CalMonthId = p.CalMonthId;
  2809. temObj.Type = "国内OA";
  2810. retlist.Add(temObj);
  2811. }
  2812. switch (p.CaseCoefficient)
  2813. {
  2814. case "S":
  2815. temObj.S += (double)(1.0M / (decimal)doList.Count());
  2816. break;
  2817. case "A":
  2818. temObj.A += (double)(1.0M / (decimal)doList.Count());
  2819. break;
  2820. case "B":
  2821. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2822. break;
  2823. case "C":
  2824. temObj.C += (double)(1.0M / (decimal)doList.Count());
  2825. break;
  2826. case "D":
  2827. temObj.D += (double)(1.0M / (decimal)doList.Count());
  2828. break;
  2829. default:
  2830. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2831. break;
  2832. }
  2833. }
  2834. #endregion
  2835. #region 国内OA审核
  2836. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2837. if (reviewer != null)
  2838. {
  2839. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "国内OA" && s.isReview == true);
  2840. if (temObj == null)
  2841. {
  2842. temObj = new StaffStatisticsforLevel();
  2843. temObj.StaffId = reviewer.StaffId;
  2844. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2845. if (temObj.GradeId == 0)
  2846. {
  2847. System.Diagnostics.Debug.WriteLine("");
  2848. }
  2849. temObj.CalMonthId = p.CalMonthId;
  2850. temObj.Type = "国内OA";
  2851. temObj.isReview = true;
  2852. retlist.Add(temObj);
  2853. }
  2854. switch (p.CaseCoefficient)
  2855. {
  2856. case "S":
  2857. temObj.S += 1;
  2858. break;
  2859. case "A":
  2860. temObj.A += 1;
  2861. break;
  2862. case "B":
  2863. temObj.B += 1;
  2864. break;
  2865. case "C":
  2866. temObj.C += 1;
  2867. break;
  2868. case "D":
  2869. temObj.D += 1;
  2870. break;
  2871. }
  2872. }
  2873. #endregion
  2874. }
  2875. #endregion
  2876. #region 涉外OA
  2877. var gwOA = spDb.PerformanceItems.Include(x => x.ItemStaffs)
  2878. .Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && !x.CaseNo.Contains("CN") && x.BasePoint>0.5
  2879. && (x.DoItemCoefficient.Contains("实质"))).ToList();
  2880. foreach (var p in gwOA)
  2881. {
  2882. var pointList = spDb.StaffStatistics.Include(i => i.Staff).Where(i => i.ItemId == p.Id).ToList();
  2883. #region 涉外OA处理
  2884. var doList = pointList.Where(i => i.jxType.Contains("处理"));
  2885. foreach (var h in doList)
  2886. {
  2887. var temObj = retlist.FirstOrDefault(s => s.StaffId == h.StaffId && s.Type == "涉外OA" && s.isReview == false);
  2888. if (temObj == null)
  2889. {
  2890. temObj = new StaffStatisticsforLevel();
  2891. temObj.StaffId = h.StaffId;
  2892. temObj.GradeId = h.Staff.StaffGradeId.Value;
  2893. if (temObj.GradeId == 0)
  2894. {
  2895. System.Diagnostics.Debug.WriteLine("");
  2896. }
  2897. temObj.CalMonthId = p.CalMonthId;
  2898. temObj.Type = "涉外OA";
  2899. retlist.Add(temObj);
  2900. }
  2901. switch (p.CaseCoefficient)
  2902. {
  2903. case "S":
  2904. temObj.S += (double)(1.0M / (decimal)doList.Count());
  2905. break;
  2906. case "A":
  2907. temObj.A += (double)(1.0M / (decimal)doList.Count());
  2908. break;
  2909. case "B":
  2910. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2911. break;
  2912. case "C":
  2913. temObj.C += (double)(1.0M / (decimal)doList.Count());
  2914. break;
  2915. case "D":
  2916. temObj.D += (double)(1.0M / (decimal)doList.Count());
  2917. break;
  2918. default:
  2919. temObj.B += (double)(1.0M / (decimal)doList.Count());
  2920. break;
  2921. }
  2922. }
  2923. #endregion
  2924. #region 涉外OA审核
  2925. var reviewer = pointList.FirstOrDefault(i => i.jxType.Contains("审核"));
  2926. if (reviewer != null)
  2927. {
  2928. var temObj = retlist.FirstOrDefault(s => s.StaffId == reviewer.StaffId && s.Type == "涉外OA" && s.isReview == true);
  2929. if (temObj == null)
  2930. {
  2931. temObj = new StaffStatisticsforLevel();
  2932. temObj.StaffId = reviewer.StaffId;
  2933. temObj.GradeId = reviewer.Staff.StaffGradeId.Value;
  2934. if (temObj.GradeId == 0)
  2935. {
  2936. System.Diagnostics.Debug.WriteLine("");
  2937. }
  2938. temObj.CalMonthId = calMonthId;
  2939. temObj.Type = "涉外OA";
  2940. temObj.isReview = true;
  2941. retlist.Add(temObj);
  2942. }
  2943. switch (p.CaseCoefficient)
  2944. {
  2945. case "S":
  2946. temObj.S += 1;
  2947. break;
  2948. case "A":
  2949. temObj.A += 1;
  2950. break;
  2951. case "B":
  2952. temObj.B += 1;
  2953. break;
  2954. case "C":
  2955. temObj.C += 1;
  2956. break;
  2957. case "D":
  2958. temObj.D += 1;
  2959. break;
  2960. default:
  2961. temObj.C += 1;
  2962. break;
  2963. }
  2964. }
  2965. #endregion
  2966. }
  2967. #endregion
  2968. return retlist;
  2969. }
  2970. /// <summary>
  2971. /// 指定等级人员等级考核案件量统计汇总
  2972. /// </summary>
  2973. /// <param name="levelCaseCounts"></param>
  2974. /// <param name="GradeCode"></param>
  2975. /// <param name="calReviw"></param>
  2976. /// <returns></returns>
  2977. private LevelStatisticsResult CalLevelStatistics(List<StaffStatisticsforLevel> levelCaseCounts,string GradeCode,bool calReviw)
  2978. {
  2979. var retList = new List<LevelStatistics>();
  2980. var temList = levelCaseCounts.Where(x=>x.Grade.Grade.StartsWith(GradeCode)).ToList();
  2981. foreach (var s in temList)
  2982. {
  2983. var temObj = retList.FirstOrDefault(i=>i.StaffId == s.StaffId);
  2984. if(temObj == null)
  2985. {
  2986. temObj = new LevelStatistics();
  2987. temObj.StaffId = s.StaffId;
  2988. temObj.StaffName = s.Staff.Name;
  2989. temObj.Grade = s.Grade.Grade;
  2990. //var Department = Context.DepartmentPositions.FirstOrDefault(x => x.StaffId == s.StaffId);
  2991. temObj.Department = Context.DepartmentPositions.Include(x => x.department).FirstOrDefault(x => x.StaffId == s.StaffId)?.department.Name;
  2992. retList.Add(temObj);
  2993. }
  2994. if (!s.isReview)
  2995. {
  2996. if(s.Type == "国内OA")
  2997. {
  2998. temObj.dS += (double)((decimal)s.S / 2M);
  2999. temObj.dA += (double)((decimal)s.A / 2M);
  3000. temObj.dB += (double)((decimal)s.B / 2M);
  3001. temObj.dC += (double)((decimal)s.C / 2M);
  3002. temObj.dD += (double)((decimal)s.D / 2M);
  3003. }
  3004. else
  3005. {
  3006. temObj.dS += s.S;
  3007. temObj.dA += s.A;
  3008. temObj.dB += s.B;
  3009. temObj.dC += s.C;
  3010. temObj.dD += s.D;
  3011. }
  3012. }
  3013. else
  3014. {
  3015. if (calReviw)
  3016. {
  3017. if (s.Type == "国内OA")
  3018. {
  3019. temObj.vS += (double)((decimal)s.S / 2M);
  3020. temObj.vA += (double)((decimal)s.A / 2M);
  3021. temObj.vB += (double)((decimal)s.B / 2M);
  3022. temObj.vC += (double)((decimal)s.C / 2M);
  3023. temObj.vD += (double)((decimal)s.D / 2M);
  3024. }
  3025. else
  3026. {
  3027. temObj.vS += s.S;
  3028. temObj.vA += s.A;
  3029. temObj.vB += s.B;
  3030. temObj.vC += s.C;
  3031. temObj.vD += s.D;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. return new LevelStatisticsResult() {Grade =GradeCode , Statistics = retList};
  3037. }
  3038. /// /// <summary>
  3039. /// 获取季度等级考核结果
  3040. /// </summary>
  3041. /// <param name="year">考核年度</param>
  3042. /// <param name="quarter">考核季度,取值为1、2、3、4</param>
  3043. /// <param name="GradeCode">等级</param>
  3044. /// <returns></returns>
  3045. public LevelStatisticsResult CalAgentLevel(int year,int quarter,string GradeCode)
  3046. {
  3047. LevelStatisticsResult result = new LevelStatisticsResult();
  3048. DateTime tempDate=DateTime.Parse($"{year}-01-01");
  3049. var Months = new List<int>() { 1,2,3};
  3050. switch (quarter)
  3051. {
  3052. case 1:
  3053. if(year == 2022)
  3054. {
  3055. Months = new List<int>() { 2, 3 };
  3056. }
  3057. else
  3058. {
  3059. Months = new List<int>() { 1, 2, 3 };
  3060. }
  3061. tempDate = DateTime.Parse($"{year}-01-01");
  3062. break;
  3063. case 2:
  3064. Months = new List<int>() { 4,5,6 };
  3065. tempDate = DateTime.Parse($"{year}-04-01");
  3066. break;
  3067. case 3:
  3068. Months = new List<int>() { 7,8,9};
  3069. tempDate = DateTime.Parse($"{year}-07-01");
  3070. break;
  3071. case 4:
  3072. Months = new List<int>() { 10,11,12 };
  3073. tempDate = DateTime.Parse($"{year}-10-01");
  3074. break;
  3075. }
  3076. //var mList = Context.CalMonths.Where(c=>c.Year == year && Months.Contains(c.Month)).ToList();
  3077. //foreach (var m in mList)
  3078. //{
  3079. // StatisticsLevelCount(m.Id);
  3080. //}
  3081. var resp = Context.StaffStatisticsforLevels
  3082. .Include(p => p.Staff)
  3083. .Include(p => p.Grade)
  3084. .Where(p => Months.Contains(p.CalMonth.Month) && p.CalMonth.Year == year && p.Staff.RegularDate.Value < tempDate && p.Staff.IsGradeAssess);
  3085. var temtList = resp.ToList();
  3086. bool isReview = (GradeCode == "A");
  3087. result = CalLevelStatistics(temtList, GradeCode, isReview);
  3088. if (!isReview)
  3089. {
  3090. string UpgradCode = "A";
  3091. switch (GradeCode)
  3092. {
  3093. case "B":
  3094. UpgradCode = "A";
  3095. break;
  3096. case "C":
  3097. UpgradCode = "B";
  3098. break;
  3099. case "D":
  3100. UpgradCode = "C";
  3101. break;
  3102. }
  3103. var temResult = CalLevelStatistics(temtList, UpgradCode, isReview);
  3104. result.UpgradeBase = temResult.doAverage();
  3105. }
  3106. if (result.Statistics.Count > 0)
  3107. {
  3108. var temAverage = result.pAverage(result.Statistics[0].StaffId);
  3109. }
  3110. return result;
  3111. }
  3112. /// <summary>
  3113. /// 重新统计指定月份的人员案件数量
  3114. /// </summary>
  3115. /// <param name="year"></param>
  3116. /// <param name="month"></param>
  3117. public bool StatisticsLevelCount(int year,int month)
  3118. {
  3119. try
  3120. {
  3121. _StatisticsLevelCount(year,month,Context);
  3122. return true;
  3123. }
  3124. catch { return false; }
  3125. }
  3126. private void _StatisticsLevelCount(int year, int month,spDbContext spDb)
  3127. {
  3128. var temObj = spDb.CalMonths.FirstOrDefault(l => l.Year == year && l.Month == month);
  3129. if (temObj != null)
  3130. {
  3131. var temList = spDb.StaffStatisticsforLevels.Where(l => l.CalMonthId == temObj.Id);
  3132. spDb.StaffStatisticsforLevels.RemoveRange(temList);
  3133. var NewList = StatisticsCount(temObj.Id, spDb);
  3134. spDb.StaffStatisticsforLevels.AddRange(NewList);
  3135. spDb.SaveChanges();
  3136. }
  3137. }
  3138. #endregion
  3139. }
  3140. }