PerformanceItemController.cs 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950
  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.EntityFrameworkCore;
  7. using Microsoft.Extensions.Caching.Memory;
  8. using Microsoft.Extensions.Hosting;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Linq.Expressions;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using wispro.sp.api.Services;
  18. using wispro.sp.api.Utility;
  19. using wispro.sp.entity;
  20. using wispro.sp.share;
  21. using wispro.sp.utility;
  22. namespace wispro.sp.api.Controllers
  23. {
  24. [Route("api/[controller]/[action]")]
  25. [ApiController]
  26. [Authorize]
  27. public class PerformanceItemController : ControllerBase
  28. {
  29. spDbContext Context;
  30. IFileTaskService fileTaskService;
  31. public PerformanceItemController(spDbContext context, IFileTaskService _fileTaskService)
  32. {
  33. Context = context;
  34. fileTaskService = _fileTaskService;
  35. }
  36. public ApiSaveResponse RemoveDBNotFinishDate(int year,int month)
  37. {
  38. ApiSaveResponse ret = new ApiSaveResponse();
  39. ret.Success = true;
  40. var itemList = Context.PerformanceItems.Include(p=>p.ItemStaffs).Where(p => p.CalMonth.Year == year &&
  41. p.CalMonth.Month == month &&
  42. p.DoItem =="处理审查意见" &&
  43. p.FinishedDate ==null);
  44. using var t = Context.Database.BeginTransaction();
  45. try
  46. {
  47. foreach (var item in itemList.ToList())
  48. {
  49. if (item != null)
  50. {
  51. Context.ItemStaffs.RemoveRange(item.ItemStaffs);
  52. Context.PerformanceItems.Remove(item);
  53. }
  54. }
  55. Context.SaveChanges();
  56. t.Commit();
  57. return ret;
  58. }
  59. catch (Exception ex)
  60. {
  61. t.Rollback();
  62. ret.Success = false;
  63. ret.ErrorMessage = ex.Message;
  64. return ret;
  65. }
  66. }
  67. public bool IsExist(PerformanceItem item)
  68. {
  69. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  70. x.CaseNo == item.CaseNo &&
  71. x.DoItem == item.DoItem &&
  72. x.CaseStage == item.CaseStage &&
  73. x.CalMonth.Year == item.CalMonth.Year &&
  74. x.CalMonth.Month == item.CalMonth.Month);
  75. if(results.Count() > 0)
  76. {
  77. return true;
  78. }
  79. else
  80. {
  81. return false;
  82. }
  83. }
  84. public ApiSaveResponse New(PerformanceItem item)
  85. {
  86. ApiSaveResponse ret = new ApiSaveResponse();
  87. ret.Success = true;
  88. using (Context.Database.BeginTransaction())
  89. {
  90. try
  91. {
  92. var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
  93. x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
  94. if (item.DoItem.ToUpper() == "提交IDS")
  95. {
  96. //提交IDS 添加完成日期做完判断是否已算绩效的条件
  97. results = Context.PerformanceItems.Where<PerformanceItem>(x=>x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.FinishedDate == item.FinishedDate);
  98. }
  99. var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
  100. if (items != null)
  101. {
  102. item.AgentFeedbackMemo = "已算绩效";
  103. item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
  104. item.BasePoint = 0;
  105. }
  106. if (item.CalMonth != null)
  107. {
  108. var calMonth = Context.CalMonths.Where<CalMonth>(c => c.Year == item.CalMonth.Year && c.Month == item.CalMonth.Month).FirstOrDefault();
  109. if(calMonth == null)
  110. {
  111. Context.CalMonths.Add(item.CalMonth);
  112. if (item.BasePoint > 0)
  113. {
  114. _calItemJX(item,Context);
  115. }
  116. else
  117. {
  118. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  119. Context.StaffStatistics.RemoveRange(oldJxList);
  120. }
  121. Context.SaveChanges();
  122. }
  123. else
  124. {
  125. item.CalMonth = calMonth;
  126. }
  127. item.CalMonthId = item.CalMonth.Id;
  128. item.CalMonth = null;
  129. }
  130. if (!string.IsNullOrEmpty(item.Customer.Name))
  131. {
  132. var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
  133. if (temCustomer == null)
  134. {
  135. temCustomer = new Customer() { Name = item.Customer.Name };
  136. //item.Customer.Id = 0;
  137. Context.Customers.Add(temCustomer);
  138. Context.SaveChanges();
  139. item.Customer = temCustomer;
  140. //item.CustomerId = item.Customer.Id;
  141. }
  142. else
  143. {
  144. item.Customer = temCustomer;
  145. }
  146. item.CustomerId = item.Customer.Id;
  147. item.Customer = null;
  148. }
  149. else
  150. {
  151. item.Customer = null;
  152. }
  153. var ItemStaffs = item.ItemStaffs;
  154. item.ItemStaffs = null;
  155. Context.PerformanceItems.Add(item);
  156. Context.SaveChanges();
  157. foreach (ItemStaff itemStaff in ItemStaffs)
  158. {
  159. itemStaff.ItemId = item.Id;
  160. itemStaff.Item = null;
  161. if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
  162. {
  163. var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
  164. if (temStaff != null)
  165. {
  166. itemStaff.DoPersonId = temStaff.Id;
  167. itemStaff.DoPerson = null;
  168. }
  169. else
  170. {
  171. Context.Staffs.Add(itemStaff.DoPerson);
  172. Context.SaveChanges();
  173. itemStaff.DoPersonId = itemStaff.DoPerson.Id;
  174. itemStaff.DoPerson = null;
  175. }
  176. }
  177. }
  178. Context.ItemStaffs.AddRange(ItemStaffs);
  179. Context.SaveChanges();
  180. Context.Database.CommitTransaction();
  181. }
  182. catch (Exception ex)
  183. {
  184. ret.Success = false;
  185. ret.ErrorMessage = ex.Message;
  186. Context.Database.RollbackTransaction();
  187. }
  188. }
  189. return ret;
  190. }
  191. /// <summary>
  192. /// 更新绩效记录信息
  193. /// </summary>
  194. /// <param name="id">绩效记录编号</param>
  195. /// <param name="field">栏位,多个位以|杠隔开</param>
  196. /// <param name="value">栏位值,多个以|杠隔开</param>
  197. /// <returns></returns>
  198. public ApiSaveResponse UpdateFieldValue(int id,string field,string value)
  199. {
  200. ApiSaveResponse ret = new ApiSaveResponse();
  201. ret.Success = true;
  202. var item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.Id == id);
  203. if (item == null)
  204. {
  205. ret.Success = false;
  206. ret.ErrorMessage = $"不存在的{id}";
  207. return ret;
  208. }
  209. if(string.IsNullOrEmpty(field) )
  210. {
  211. ret.Success = false;
  212. ret.ErrorMessage = $"参数不对!";
  213. return ret;
  214. }
  215. string[] fields = field.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  216. string[] values = new string[] { null };
  217. if (!string.IsNullOrEmpty(value))
  218. {
  219. values = value.Split(new char[] { '|' });
  220. }
  221. if (fields.Length != values.Length) {
  222. ret.Success = false;
  223. ret.ErrorMessage = "栏位和值对不匹配";
  224. }
  225. else
  226. {
  227. for(int i = 0; i < fields.Length; i++)
  228. {
  229. string temField = fields[i];
  230. string temValue = values[i];
  231. switch (temField)
  232. {
  233. case "AgentFeedbackMemo":
  234. item.AgentFeedbackMemo = temValue;
  235. break;
  236. case "CaseCoefficient":
  237. item.CaseCoefficient = temValue;
  238. //此处添加保存到流程系统的代码
  239. break;
  240. case "DoItemCoefficient":
  241. item.DoItemCoefficient = temValue;
  242. //此处添加保存到流程系统的代码
  243. break;
  244. case "WordCount":
  245. int wordCount;
  246. if (int.TryParse(temValue, out wordCount))
  247. {
  248. item.WordCount = wordCount;
  249. }
  250. else
  251. {
  252. item.WordCount = null;
  253. //ret.Success = false;
  254. //ret.ErrorMessage = "所给的栏位值不能转换成数字!";
  255. //return ret;
  256. }
  257. break;
  258. case "ReturnCasseNo":
  259. item.ReturnCasseNo = temValue;
  260. break;
  261. }
  262. }
  263. if (item.AgentFeedbackMemo != "特殊点数申诉")
  264. {
  265. Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
  266. if (item.BasePoint > 0)
  267. {
  268. _calItemJX(item,Context);
  269. }
  270. else
  271. {
  272. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  273. Context.StaffStatistics.RemoveRange(oldJxList);
  274. }
  275. Context.SaveChanges();
  276. }
  277. }
  278. return ret;
  279. }
  280. public ListApiResponse<PerformanceItem> Query(int pageIndex,int pageSize)
  281. {
  282. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  283. var results = Context.PerformanceItems
  284. .Where<PerformanceItem>(s =>
  285. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == User.Identity.Name).Count() > 0 || s.Reviewer.Name == User.Identity.Name)
  286. && s.CalMonth.Status != 4);
  287. ret.TotalCount = results.Count();
  288. List<PerformanceItem> retList = results
  289. .Include(pi=>pi.ItemStaffs).ThenInclude(iStaff=>iStaff.DoPerson)
  290. .Include(pi=>pi.Reviewer)
  291. .Include(pi=>pi.Customer)
  292. .Include(pi=>pi.CalMonth)
  293. .OrderByDescending(o=>o.Id)
  294. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize).ToList<PerformanceItem>();
  295. #region 将某些属性设为null,避免循环取值造成返回json过大
  296. foreach (PerformanceItem item in retList)
  297. {
  298. foreach (ItemStaff itemStaff in item.ItemStaffs)
  299. {
  300. itemStaff.DoPerson.ItemStaffs = null;
  301. itemStaff.DoPerson.ReviewerItems = null;
  302. itemStaff.Item = null;
  303. }
  304. item.Reviewer.ReviewerItems = null;
  305. item.Reviewer.Customers = null;
  306. item.Reviewer.ItemStaffs = null;
  307. item.Customer.PerformanceItems = null;
  308. item.CalMonth.PerformanceItems = null;
  309. }
  310. #endregion
  311. ret.Results = retList;
  312. return ret;
  313. }
  314. public PerformanceItem Get(int Id)
  315. {
  316. var results = Context.PerformanceItems
  317. .Where<PerformanceItem>(s =>s.Id == Id);
  318. PerformanceItem item = results
  319. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  320. .Include(pi => pi.Reviewer)
  321. .Include(pi => pi.Customer)
  322. .Include(pi => pi.CalMonth)
  323. .OrderByDescending(o => o.Id)
  324. .FirstOrDefault();
  325. #region 将某些属性设为null,避免循环取值造成返回json过大
  326. foreach (ItemStaff itemStaff in item.ItemStaffs)
  327. {
  328. itemStaff.DoPerson.ItemStaffs = null;
  329. itemStaff.DoPerson.ReviewerItems = null;
  330. itemStaff.Item = null;
  331. }
  332. if (item.Reviewer != null)
  333. {
  334. item.Reviewer.ReviewerItems = null;
  335. item.Reviewer.Customers = null;
  336. item.Reviewer.ItemStaffs = null;
  337. }
  338. item.Customer.PerformanceItems = null;
  339. item.CalMonth.PerformanceItems = null;
  340. #endregion
  341. return item;
  342. }
  343. /// <summary>
  344. /// 获取给定用户的绩效清单
  345. /// </summary>
  346. /// <param name="userid">用户id</param>
  347. /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
  348. /// <returns></returns>
  349. public ListApiResponse<PerformanceItem> GetMyList(int userid, int type,int pageIndex=1,int pageSize = 10)
  350. {
  351. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  352. var results = Context.PerformanceItems
  353. .Where<PerformanceItem>(s =>
  354. (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid ).Count() > 0 || s.Reviewer.Id == userid )
  355. && s.CalMonth.Status == type);
  356. ret.TotalCount = results.Count();
  357. List<PerformanceItem> retList = results
  358. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  359. .Include(pi => pi.Reviewer)
  360. .Include(pi => pi.Customer)
  361. .Include(pi => pi.CalMonth)
  362. .OrderByDescending(o => o.Id)
  363. .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize)
  364. .ToList<PerformanceItem>();
  365. #region 将某些属性设为null,避免循环取值造成返回json过大
  366. foreach (PerformanceItem item in retList)
  367. {
  368. foreach(ItemStaff itemStaff in item.ItemStaffs)
  369. {
  370. itemStaff.DoPerson.ItemStaffs = null;
  371. itemStaff.DoPerson.ReviewerItems = null;
  372. itemStaff.Item = null;
  373. }
  374. item.Reviewer.ReviewerItems = null;
  375. item.Reviewer.Customers = null;
  376. item.Reviewer.ItemStaffs = null;
  377. item.Customer.PerformanceItems = null;
  378. item.CalMonth.PerformanceItems = null;
  379. }
  380. #endregion
  381. ret.Results = retList;
  382. return ret;
  383. }
  384. /// <summary>
  385. /// 获取个人难度系数
  386. /// </summary>
  387. /// <param name="calMonth">绩效月份</param>
  388. /// <param name="userId">用户Id</param>
  389. /// <param name="isReivewer">是否审核个人难度系数</param>
  390. /// <returns></returns>
  391. private NanduStatics PersonNanduStatics(CalMonth calMonth,int userId,spDbContext spDb,bool isReivewer = false)
  392. {
  393. NanduStatics retObj = new NanduStatics();
  394. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  395. var list = spDb.CaseCeoffcients;
  396. foreach (var cx in list.ToList<CaseCeoffcient>())
  397. {
  398. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  399. }
  400. string jxType = isReivewer ? "新申请审核" : "新申请处理";
  401. var results = spDb.StaffStatistics.Include(p => p.Item).Where(s => s.CalMonthId == calMonth.Id && s.jxType == jxType && s.StaffId == userId);
  402. if (!isReivewer)
  403. {
  404. results = spDb.StaffStatistics.Include(p=>p.Item).Where(s => s.CalMonthId == calMonth.Id && (s.jxType == jxType || s.jxType == "专案处理") && s.StaffId == userId);
  405. }
  406. #region 循环计算
  407. int iCount = 0;
  408. double d = 0.0;
  409. var retList = results.ToList();
  410. foreach (var item in retList)
  411. {
  412. if (item.Item != null)
  413. {
  414. string strCaseCeoffcient = item.Item.CaseCoefficient;
  415. if (string.IsNullOrEmpty(strCaseCeoffcient))
  416. {
  417. strCaseCeoffcient = "B";
  418. }
  419. #region 严重延期降系数
  420. if (item.Item.isDanger() && string.IsNullOrEmpty(item.Item.OverDueMemo))
  421. {
  422. switch (item.Item.CaseCoefficient)
  423. {
  424. case "S":
  425. strCaseCeoffcient = "A";
  426. break;
  427. case "A":
  428. strCaseCeoffcient = "B";
  429. break;
  430. case "B":
  431. strCaseCeoffcient = "C";
  432. break;
  433. case "C":
  434. strCaseCeoffcient = "D";
  435. break;
  436. }
  437. }
  438. #endregion
  439. switch (strCaseCeoffcient)
  440. {
  441. case "S":
  442. if (item.Item.Type == "专案")
  443. {
  444. retObj.S += item.totalBasePoint.Value;
  445. }
  446. else
  447. {
  448. retObj.S += 1;
  449. }
  450. break;
  451. case "A":
  452. if (item.Item.Type == "专案")
  453. {
  454. retObj.A += item.totalBasePoint.Value;
  455. }
  456. else
  457. {
  458. retObj.A += 1;
  459. }
  460. break;
  461. case "B":
  462. if (item.Item.Type == "专案")
  463. {
  464. retObj.B += item.totalBasePoint.Value;
  465. }
  466. else
  467. {
  468. retObj.B += 1;
  469. }
  470. break;
  471. case "C":
  472. if (item.Item.Type == "专案")
  473. {
  474. retObj.C += item.totalBasePoint.Value;
  475. }
  476. else
  477. {
  478. retObj.C += 1;
  479. }
  480. break;
  481. case "D":
  482. if (item.Item.Type == "专案")
  483. {
  484. retObj.D += item.totalBasePoint.Value;
  485. }
  486. else
  487. {
  488. retObj.D += 1;
  489. }
  490. break;
  491. default:
  492. if (item.Item.Type == "专案")
  493. {
  494. retObj.B += item.totalBasePoint.Value;
  495. }
  496. else
  497. {
  498. retObj.B += 1;
  499. }
  500. break;
  501. }
  502. if (CaseXiShu.ContainsKey(strCaseCeoffcient))
  503. {
  504. d += CaseXiShu[strCaseCeoffcient];
  505. iCount += 1;
  506. }
  507. }
  508. }
  509. #endregion
  510. retObj.NanduXS = d / (double)iCount;
  511. return retObj;
  512. }
  513. /// <summary>
  514. /// 获取总难度系数
  515. /// </summary>
  516. /// <param name="calMonth"></param>
  517. /// <returns></returns>
  518. private NanduStatics DegreeOfDifficulty(CalMonth calMonth,spDbContext spDb)
  519. {
  520. NanduStatics retObj = new NanduStatics();
  521. IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
  522. var list = spDb.CaseCeoffcients.ToList();
  523. foreach (var cx in list)
  524. {
  525. CaseXiShu.Add(cx.Ceoffcient, cx.Value);
  526. }
  527. var results = spDb.PerformanceItems.Where<PerformanceItem>(p => p.CalMonthId == calMonth.Id && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") && p.BasePoint > 0.0);
  528. #region 循环计算
  529. int iCount = 0;
  530. double d = 0.0;
  531. var retList = results.ToList();
  532. foreach (var item in retList)
  533. {
  534. string strCaseCeoffcient = item.CaseCoefficient;
  535. if (string.IsNullOrEmpty(strCaseCeoffcient))
  536. {
  537. strCaseCeoffcient = "B";
  538. }
  539. #region 严重延期降系数
  540. if (item.isDanger() && string.IsNullOrEmpty(item.OverDueMemo))
  541. {
  542. switch (item.CaseCoefficient)
  543. {
  544. case "S":
  545. strCaseCeoffcient = "A";
  546. break;
  547. case "A":
  548. strCaseCeoffcient = "B";
  549. break;
  550. case "B":
  551. strCaseCeoffcient = "C";
  552. break;
  553. case "C":
  554. strCaseCeoffcient = "D";
  555. break;
  556. }
  557. }
  558. #endregion
  559. switch (strCaseCeoffcient)
  560. {
  561. case "S":
  562. if(item.Type == "专案")
  563. {
  564. retObj.S += item.BasePoint.Value;
  565. }
  566. else
  567. {
  568. retObj.S += 1;
  569. }
  570. break;
  571. case "A":
  572. if (item.Type == "专案")
  573. {
  574. retObj.A += item.BasePoint.Value;
  575. }
  576. else
  577. {
  578. retObj.A += 1;
  579. }
  580. break;
  581. case "B":
  582. if (item.Type == "专案")
  583. {
  584. retObj.B += item.BasePoint.Value;
  585. }
  586. else
  587. {
  588. retObj.B += 1;
  589. }
  590. break;
  591. case "C":
  592. if (item.Type == "专案")
  593. {
  594. retObj.C += item.BasePoint.Value;
  595. }
  596. else
  597. {
  598. retObj.C += 1;
  599. }
  600. break;
  601. case "D":
  602. if (item.Type == "专案")
  603. {
  604. retObj.D += item.BasePoint.Value;
  605. }
  606. else
  607. {
  608. retObj.D += 1;
  609. }
  610. break;
  611. default:
  612. if (item.Type == "专案")
  613. {
  614. retObj.B += item.BasePoint.Value;
  615. }
  616. else
  617. {
  618. retObj.B += 1;
  619. }
  620. break;
  621. }
  622. if (CaseXiShu.ContainsKey(strCaseCeoffcient))
  623. {
  624. d += CaseXiShu[strCaseCeoffcient];
  625. iCount += 1;
  626. }
  627. }
  628. #endregion
  629. retObj.NanduXS = d / (double)iCount;
  630. return retObj;
  631. }
  632. public List<string> GetFeedbackString(int itemId)
  633. {
  634. PerformanceItem item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == itemId);
  635. if(item != null)
  636. {
  637. return Utility.Utility.GetFeedbackMemos(item, Context.BasePointRules.ToList());
  638. }
  639. return new List<string>();
  640. }
  641. private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
  642. {
  643. var retList = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
  644. if (userid != null)
  645. {
  646. retList = retList.Where(s => s.StaffId == userid);
  647. }
  648. var retData2 = retList.GroupBy(s => new { s.CalMonthId, s.StaffId, s.jxType })
  649. .Select(g => new
  650. {
  651. StaffId = g.Key.StaffId,
  652. CalMonthId = g.Key.CalMonthId,
  653. jxType = g.Key.jxType,
  654. FinianlPoint = g.Sum(s => s.FinianlPoint),
  655. totalBasePoint = g.Sum(s => s.totalBasePoint),
  656. totalActuallyPoint = g.Sum(s => s.totalActuallyPoint)
  657. });
  658. List<StaffStatistics> temList = new List<StaffStatistics>();
  659. foreach (var key in retData2)
  660. {
  661. temList.Add(new StaffStatistics()
  662. {
  663. StaffId = key.StaffId,
  664. CalMonthId = key.CalMonthId,
  665. jxType = key.jxType,
  666. totalBasePoint = key.totalBasePoint,
  667. totalActuallyPoint = key.totalActuallyPoint,
  668. FinianlPoint = key.FinianlPoint
  669. });
  670. }
  671. return temList;
  672. #region old code
  673. ////未归档,从绩效记录中统计数据
  674. //var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
  675. //if (userid != null)
  676. //{
  677. // results = Context.PerformanceItems.Where<PerformanceItem>(s =>
  678. // (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
  679. // && s.CalMonth.Id == calMonth.Id);
  680. //}
  681. //List<PerformanceItem> ItemList = results
  682. // .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  683. // .Include(pi => pi.Reviewer).ThenInclude(p=>p.StaffGrade)
  684. // .Include(pi => pi.Customer)
  685. // .OrderByDescending(o => o.Id)
  686. // .ToList<PerformanceItem>();
  687. //List<StaffStatistics> retList = new List<StaffStatistics>();
  688. //List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  689. //var Rules = Context.BasePointRules.ToList();
  690. //foreach (PerformanceItem item in ItemList)
  691. //{
  692. // //if (item.BasePoint == null)
  693. // //{
  694. // if (item.AgentFeedbackMemo != "特殊点数申诉")
  695. // {
  696. // Utility.Utility.CalBasePoint(item, Rules);
  697. // Context.SaveChanges();
  698. // }
  699. // //}
  700. // if (item.BasePoint != null && item.BasePoint.Value > 0)
  701. // {
  702. // double doPersonBasePoint = item.BasePoint.Value;
  703. // List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
  704. // List<StaffStatistics> temItemStatics;
  705. // if (userid != null)
  706. // {
  707. // temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
  708. // }
  709. // else
  710. // {
  711. // temItemStatics = itemStatistics;
  712. // }
  713. // foreach (StaffStatistics retUserValue in temItemStatics)
  714. // {
  715. // var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
  716. // if (temValue != null)
  717. // {
  718. // temValue.totalBasePoint += retUserValue.totalBasePoint;
  719. // temValue.totalActuallyPoint += retUserValue.totalActuallyPoint;
  720. // }
  721. // else
  722. // {
  723. // retList.Add(retUserValue);
  724. // }
  725. // }
  726. // }
  727. //}
  728. //if (userid != null)
  729. //{
  730. // retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
  731. //}
  732. //return retList;
  733. #endregion
  734. }
  735. private void _RefreshBasePoint()
  736. {
  737. spDbContext spDb = new spDbContext();
  738. var calMonth = spDb.CalMonths.FirstOrDefault(c => c.Status == 0);
  739. _RefreshBasePoint(calMonth,spDb);
  740. }
  741. private void _RefreshBasePoint(CalMonth calMonth,spDbContext spDb )
  742. {
  743. if (calMonth != null)
  744. {
  745. var lstItem = spDb.PerformanceItems
  746. .Include(p => p.Customer)
  747. .Include(p => p.ItemStaffs)
  748. .Include(p => p.Reviewer)
  749. .Include(p => p.CalMonth)
  750. .Where(p => p.CalMonthId == calMonth.Id).ToList();
  751. var rules = spDb.BasePointRules.ToList();
  752. foreach (var item in lstItem)
  753. {
  754. try
  755. {
  756. Utility.Utility.CalBasePoint(item, rules);
  757. if (item.BasePoint > 0)
  758. {
  759. _calItemJX(item, spDb);
  760. }
  761. else
  762. {
  763. var oldJxList = spDb.StaffStatistics.Where(p => p.ItemId == item.Id);
  764. spDb.StaffStatistics.RemoveRange(oldJxList);
  765. }
  766. spDb.SaveChanges();
  767. }
  768. catch (Exception ex)
  769. {
  770. System.Diagnostics.Debug.WriteLine(ex.Message);
  771. }
  772. }
  773. _CalJXPoint(calMonth, spDb);
  774. }
  775. }
  776. public ApiSaveResponse RefreshBasePoint()
  777. {
  778. System.Threading.Thread t = new Thread(_RefreshBasePoint);
  779. t.Start();
  780. return new ApiSaveResponse() {
  781. Success = true
  782. };
  783. }
  784. public void RefreshPoint(PerformanceItem item)
  785. {
  786. spDbContext spDb = new spDbContext();
  787. var rules = spDb.BasePointRules.ToList();
  788. if (item.AgentFeedbackMemo != "特殊点数申诉")
  789. {
  790. Utility.Utility.CalBasePoint(item, rules);
  791. if (item.BasePoint > 0)
  792. {
  793. _calItemJX(item, spDb);
  794. }
  795. else
  796. {
  797. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  798. Context.StaffStatistics.RemoveRange(oldJxList);
  799. }
  800. spDb.SaveChanges();
  801. }
  802. }
  803. public ApiSaveResponse RefreshFromIPEasyById(int itemId)
  804. {
  805. var Item = Context.PerformanceItems.Include(p=>p.Customer).Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).FirstOrDefault(p => p.Id == itemId);
  806. if (Item != null)
  807. {
  808. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
  809. }
  810. Utility.Utility.CalBasePoint(Item, Context.BasePointRules.ToList());
  811. if(Item.BasePoint > 0)
  812. {
  813. _calItemJX(Item,Context);
  814. }
  815. else
  816. {
  817. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == Item.Id);
  818. Context.StaffStatistics.RemoveRange(oldJxList);
  819. }
  820. Context.SaveChanges();
  821. return new ApiSaveResponse()
  822. {
  823. Success = true
  824. };
  825. }
  826. public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
  827. {
  828. new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
  829. return new ApiSaveResponse()
  830. {
  831. Success = true
  832. };
  833. }
  834. public ApiSaveResponse RefreshFromIPEasy(string CaseNo,string DoItem,string caseStage)
  835. {
  836. var Item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault(p=>p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
  837. if(Item != null)
  838. {
  839. new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item,Context);
  840. }
  841. return new ApiSaveResponse()
  842. {
  843. Success = true
  844. };
  845. }
  846. public ApiSaveResponse CompareExcel2DB()
  847. {
  848. System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
  849. t.Start();
  850. return new ApiSaveResponse()
  851. {
  852. Success = true
  853. };
  854. }
  855. public FileProcessTask CurrentData2Excel()
  856. {
  857. CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Status == 0);
  858. if (calMonth != null)
  859. {
  860. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
  861. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  862. var filePath = Path.Combine(attachfileSavePath, filename);
  863. var fileTask = new FileProcessTask()
  864. {
  865. Id = Guid.NewGuid().ToString(),
  866. FileName = filename,
  867. FilePath = filePath,
  868. Processed = 0
  869. };
  870. fileTaskService.Add(fileTask);
  871. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(Export2ExcelThread));
  872. t.Start(fileTask);
  873. return fileTask;
  874. }
  875. return null;
  876. }
  877. private void Export2ExcelThread(object attfile)
  878. {
  879. FileProcessTask file = (FileProcessTask)attfile;
  880. spDbContext spDb = new spDbContext();
  881. List<PerformanceItem> items = spDb.PerformanceItems
  882. .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
  883. .Include(p=>p.PreOastaff)
  884. .Include(p => p.Customer)
  885. .Include(p => p.CalMonth)
  886. .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
  887. .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
  888. DataTable dt = new DataTable();
  889. #region 栏位名称
  890. dt.Columns.Add("我方文号",typeof(string));
  891. dt.Columns.Add("申请类型", typeof(string));
  892. dt.Columns.Add("业务类型", typeof(string));
  893. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  894. dt.Columns.Add("处理事项", typeof(string));
  895. dt.Columns.Add("案件阶段", typeof(string));
  896. dt.Columns.Add("案件系数", typeof(string));
  897. dt.Columns.Add("处理事项系数", typeof(string));
  898. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  899. dt.Columns.Add("前一次OA处理人", typeof(string));
  900. dt.Columns.Add("处理人等级", typeof(string));
  901. dt.Columns.Add("基本点数", typeof(string));
  902. dt.Columns.Add("核稿系数", typeof(string));
  903. dt.Columns.Add("核稿绩效", typeof(string));
  904. dt.Columns.Add("处理人", typeof(string));
  905. dt.Columns.Add("核稿人", typeof(string));
  906. dt.Columns.Add("客户名称", typeof(string));
  907. dt.Columns.Add("申请人", typeof(string));
  908. dt.Columns.Add("处理事项完成日", typeof(string));
  909. dt.Columns.Add("定稿日", typeof(string));
  910. dt.Columns.Add("返稿日", typeof(string));
  911. dt.Columns.Add("案件类型", typeof(string));
  912. dt.Columns.Add("案件状态", typeof(string));
  913. dt.Columns.Add("处理事项备注", typeof(string));
  914. dt.Columns.Add("处理状态", typeof(string));
  915. dt.Columns.Add("案件名称", typeof(string));
  916. dt.Columns.Add("委案日期", typeof(string));
  917. dt.Columns.Add("客户期限", typeof(string));
  918. dt.Columns.Add("内部期限", typeof(string));
  919. dt.Columns.Add("初稿日", typeof(string));
  920. dt.Columns.Add("翻译字数", typeof(string));
  921. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因", typeof(string));
  922. dt.Columns.Add("绩效类型", typeof(string));
  923. dt.Columns.Add("案件备注", typeof(string));
  924. dt.Columns.Add("处理人绩效系数", typeof(string));
  925. dt.Columns.Add("系统核算绩效", typeof(string));
  926. dt.Columns.Add("实际处理人", typeof(string));
  927. #endregion
  928. var verifyCeoffients = spDb.VerifyCoefficients.ToList();
  929. var Rules = spDb.BasePointRules.ToList();
  930. file.Size = items.Count;
  931. foreach(var p in items)
  932. {
  933. List<ItemStaff> temItemStaffs = p.ItemStaffs.ToList();
  934. string strCaseMemo = "";
  935. string strHandler = "";
  936. temItemStaffs = new List<ItemStaff>();
  937. foreach (var iStaff in p.ItemStaffs)
  938. {
  939. strHandler = string.IsNullOrEmpty(strHandler)?iStaff.DoPerson.Name : $"{strHandler},{iStaff.DoPerson.Name}";
  940. if (iStaff.DoPerson.Status == "试用期")
  941. {
  942. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}在试用期" : $"{strCaseMemo},{iStaff.DoPerson.Name}在试用期";
  943. }
  944. else
  945. {
  946. if(!iStaff.DoPerson.IsCalPerformsnce )
  947. strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}不计算绩效" : $"{strCaseMemo},{iStaff.DoPerson.Name}不计算绩效";
  948. }
  949. if(iStaff.DoPersonId == p.ReviewerId)
  950. {
  951. strCaseMemo = String.IsNullOrEmpty(strCaseMemo) ? "核稿人与处理人相同" : $"{strCaseMemo},核稿人与处理人相同";
  952. }
  953. }
  954. var staffStatics = spDb.StaffStatistics.Include(s=>s.Staff).ThenInclude(s=>s.StaffGrade).Where(s=>s.ItemId == p.Id && s.jxType.Contains("处理"));
  955. var reviewStatic = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).FirstOrDefault(s => s.ItemId == p.Id && s.jxType.Contains("审核"));
  956. foreach (var iStaff in staffStatics.ToList())
  957. {
  958. DataRow row = dt.NewRow();
  959. row["我方文号"] = p.CaseNo;
  960. row["申请类型"] = p.ApplicationType;
  961. row["实际处理人"] = strHandler;
  962. if(p.ApplicationName != null && p.ApplicationName.Contains("OPPO") && p.ApplicationType == "实用新型" && p.Type =="新申请")
  963. {
  964. row["申请类型"] = "发明";
  965. row["案件备注"] = $"{row["案件备注"]}\r\n【OPPO案件实用新型修改为发明】";
  966. }
  967. row["处理事项"] = p.DoItem;
  968. row["业务类型"] = p.BusinessType;
  969. row["备注(填表注意事项)"] = p.AgentFeedbackMemo;
  970. if(p.Type == "专案")
  971. {
  972. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]}【主管给定点数】专案";
  973. row["处理事项"] = "提出报告";
  974. }
  975. if(p.ItemStaffs.Count() > 1)
  976. {
  977. row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]},{strHandler}合写";
  978. }
  979. row["案件阶段"] = p.CaseStage;
  980. row["案件系数"] = p.CaseCoefficient;
  981. if(p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo) && p.Type =="新申请")
  982. {
  983. switch (p.CaseCoefficient)
  984. {
  985. case "S":
  986. row["案件系数"] = "A";
  987. break;
  988. case "A":
  989. row["案件系数"] = "B";
  990. break;
  991. case "B":
  992. row["案件系数"] = "C";
  993. break;
  994. case "C":
  995. row["案件系数"] = "D";
  996. break;
  997. }
  998. row["案件备注"] = $"{row["案件备注"]}\r\n严重延期降系数【{p.CaseCoefficient}->{row["案件系数"]}】";
  999. }
  1000. row["处理事项系数"] = p.DoItemCoefficient;
  1001. row["前一次OA处理事项系数"] = "";
  1002. row["前一次OA处理人"] = p.PreOastaff?.Name;
  1003. row["处理人"] = iStaff.Staff.Name;
  1004. row["基本点数"] = iStaff.totalBasePoint;
  1005. row["处理人等级"] = iStaff.Staff.StaffGrade.Grade;
  1006. row["处理人绩效系数"] = iStaff.Staff.StaffGrade.Coefficient;
  1007. if (reviewStatic != null)
  1008. {
  1009. row["核稿人"] = reviewStatic.Staff.Name;
  1010. var v = verifyCeoffients.FirstOrDefault(p => p.CheckerId == reviewStatic.Staff.StaffGradeId && p.DoPersonId == iStaff.Staff.StaffGradeId);
  1011. if (v != null)
  1012. {
  1013. row["核稿绩效"] = ((decimal)iStaff.totalBasePoint * (decimal)v.Coefficient);
  1014. row["核稿系数"] = v.Coefficient;
  1015. }
  1016. }
  1017. row["客户名称"] = p.Customer?.Name;
  1018. row["申请人"] = p.ApplicationName;
  1019. row["处理事项完成日"] = p.FinishedDate?.ToString("yyyy-MM-dd");
  1020. row["定稿日"] = p.FinalizationDate?.ToString("yyyy-MM-dd");
  1021. row["返稿日"] = p.ReturnDate?.ToString("yyyy-MM-dd");
  1022. row["案件类型"] = p.CaseType;
  1023. row["案件状态"] = p.CaseState;
  1024. row["处理事项备注"] = p.DoItemMemo;
  1025. row["处理状态"] = p.DoItemState;
  1026. row["案件名称"] = p.CaseName;
  1027. row["委案日期"] = p.EntrustingDate?.ToString("yyyy-MM-dd");
  1028. row["客户期限"] = p.CustomerLimitDate?.ToString("yyyy-MM-dd");
  1029. row["内部期限"] = p.InternalDate?.ToString("yyyy-MM-dd");
  1030. row["初稿日"] = p.FirstDraftDate?.ToString("yyyy-MM-dd");
  1031. row["翻译字数"] = p.WordCount;
  1032. row["备注(发文严重超期是否属客观原因,若为否,请填写原因"] = p.OverDueMemo;
  1033. row["绩效类型"] = p.Type;
  1034. row["案件备注"] = $"{p.CaseMemo}\r\n{row["案件备注"]}";
  1035. if (!string.IsNullOrEmpty(strCaseMemo))
  1036. {
  1037. row["案件备注"] = $"{strCaseMemo}\r\n{row["案件备注"]}";
  1038. }
  1039. dt.Rows.Add(row);
  1040. }
  1041. file.Processed += 1;
  1042. }
  1043. NPOIExcel.DataTableToExcel(dt, file.FilePath);
  1044. file.Finished = true;
  1045. }
  1046. private void _CompareExcel2DB()
  1047. {
  1048. DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0,2);
  1049. DataTable retTable = new DataTable();
  1050. retTable.Columns.Add("我方文号");
  1051. retTable.Columns.Add("申请类型");
  1052. retTable.Columns.Add("业务类型");
  1053. retTable.Columns.Add("备注(填表注意事项)");
  1054. retTable.Columns.Add("备注(填表注意事项)【系统】");
  1055. retTable.Columns.Add("处理事项");
  1056. retTable.Columns.Add("处理事项【系统】");
  1057. retTable.Columns.Add("案件阶段");
  1058. retTable.Columns.Add("案件阶段【系统】");
  1059. retTable.Columns.Add("案件系数");
  1060. retTable.Columns.Add("案件系数【系统】");
  1061. retTable.Columns.Add("处理事项系数");
  1062. retTable.Columns.Add("处理事项系数【系统】");
  1063. retTable.Columns.Add("处理人等级");
  1064. retTable.Columns.Add("处理人等级【系统】");
  1065. retTable.Columns.Add("处理人系数");
  1066. retTable.Columns.Add("处理人系数【系统】");
  1067. retTable.Columns.Add("基本点数");
  1068. retTable.Columns.Add("基本点数【系统】");
  1069. retTable.Columns.Add("核稿系数");
  1070. retTable.Columns.Add("核稿系数【系统】");
  1071. retTable.Columns.Add("核稿绩效");
  1072. retTable.Columns.Add("核稿绩效【系统】");
  1073. retTable.Columns.Add("处理人");
  1074. retTable.Columns.Add("处理人【系统】");
  1075. retTable.Columns.Add("核稿人");
  1076. retTable.Columns.Add("核稿人【系统】");
  1077. retTable.Columns.Add("严重超期备注原因");
  1078. retTable.Columns.Add("严重超期备注原因【系统】");
  1079. retTable.Columns.Add("是否一致");
  1080. retTable.Columns.Add("不一致原因");
  1081. spDbContext spDb = new spDbContext();
  1082. List<PerformanceItem> items = spDb.PerformanceItems
  1083. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  1084. .Include(p=>p.Customer)
  1085. .Include(p=>p.ItemStaffs).ThenInclude(s=>s.DoPerson).ThenInclude(s=>s.StaffGrade)
  1086. .Where(p=>p.CalMonth.Status ==0 && !p.CaseNo.StartsWith("J")).OrderBy(p=>p.CaseNo).ThenBy(p=>p.DoItem).ToList();
  1087. excelDT.DefaultView.Sort = "我方文号,处理事项";
  1088. DataTable temDt = excelDT.DefaultView.ToTable();
  1089. int iTable = 0;
  1090. int iList = 0;
  1091. CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p=>p.Status ==0);
  1092. var verifyCoefficients = spDb.VerifyCoefficients.ToList();
  1093. var Rules = spDb.BasePointRules.ToList();
  1094. while (iTable < temDt.Rows.Count && iList < items.Count)
  1095. {
  1096. System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
  1097. DataRow row = temDt.Rows[iTable];
  1098. PerformanceItem item = items[iList];
  1099. if(row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString()== "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
  1100. {
  1101. var temRow = retTable.NewRow();
  1102. int iBegin = iTable;
  1103. int iEnd = iTable;
  1104. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1105. if (iEnd < temDt.Rows.Count - 1)
  1106. {
  1107. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1108. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1109. {
  1110. iEnd++;
  1111. }
  1112. }
  1113. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1114. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1115. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1116. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1117. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1118. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1119. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1120. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1121. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1122. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1123. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1124. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1125. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1126. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1127. for (int i = iBegin; i <= iEnd; i++)
  1128. {
  1129. temRow["备注(填表注意事项)"] =string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ?temDt.Rows[i]["备注(填表注意事项)"] :$"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1130. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1131. temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
  1132. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1133. {
  1134. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1135. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1136. }
  1137. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1138. }
  1139. iTable = iEnd;
  1140. #endregion
  1141. Utility.Utility.CalBasePoint(item, Rules);
  1142. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1143. try
  1144. {
  1145. retPoints = _calItemJX( verifyCoefficients, item, spDb);
  1146. }
  1147. catch { }
  1148. temRow["案件阶段【系统】"] = item.CaseStage;
  1149. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1150. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1151. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1152. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1153. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1154. temRow["严重超期备注原因"] = item.OverDueMemo;
  1155. if (retPoints != null && retPoints.Count > 0)
  1156. {
  1157. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
  1158. foreach (var itemStaff in item.ItemStaffs)
  1159. {
  1160. //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1161. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1162. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1163. if (item.ReviewerId != null)
  1164. {
  1165. #region 取审核人等级审核等级系数
  1166. VerifyCoefficient vcoefficient
  1167. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1168. v.CheckerId == item.Reviewer.StaffGradeId
  1169. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1170. .FirstOrDefault<VerifyCoefficient>();
  1171. #endregion
  1172. if (vcoefficient != null)
  1173. {
  1174. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1175. }
  1176. }
  1177. }
  1178. }
  1179. temRow["是否一致"] = "";
  1180. temRow["不一致原因"] = "";
  1181. if(temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
  1182. {
  1183. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
  1184. }
  1185. if (temRow["案件系数【系统】"].ToString().Trim() != temRow["案件系数"].ToString().Trim())
  1186. {
  1187. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件系数" : $"{temRow["不一致原因"]},案件系数";
  1188. }
  1189. if (temRow["处理事项系数【系统】"].ToString().Trim() != temRow["处理事项系数"].ToString().Trim())
  1190. {
  1191. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "处理事项系数" : $"{temRow["不一致原因"]},处理事项系数";
  1192. }
  1193. if (temRow["核稿人【系统】"].ToString().Trim() != temRow["核稿人"].ToString().Trim())
  1194. {
  1195. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "核稿人" : $"{temRow["不一致原因"]},核稿人";
  1196. }
  1197. if (temRow["基本点数【系统】"].ToString().Trim() != temRow["基本点数"].ToString().Trim())
  1198. {
  1199. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "基本点数" : $"{temRow["不一致原因"]},基本点数";
  1200. }
  1201. if (temRow["严重超期备注原因【系统】"].ToString().Trim() != temRow["严重超期备注原因"].ToString().Trim())
  1202. {
  1203. temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "严重超期备注原因" : $"{temRow["不一致原因"]},严重超期备注原因";
  1204. }
  1205. if (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
  1206. {
  1207. temRow["是否一致"] = "不一致";
  1208. }
  1209. retTable.Rows.Add(temRow);
  1210. iTable++;
  1211. iList++;
  1212. }
  1213. else
  1214. {
  1215. string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
  1216. string strList = $"{item.CaseNo}-{item.DoItem}";
  1217. if (strDT.CompareTo(strList) > 0)
  1218. {
  1219. var temRow = retTable.NewRow();
  1220. Utility.Utility.CalBasePoint(item, Rules);
  1221. List<StaffStatistics> retPoints = new List<StaffStatistics>();
  1222. try
  1223. {
  1224. retPoints = _calItemJX( verifyCoefficients, item, spDb);
  1225. }
  1226. catch { }
  1227. temRow["我方文号"] = item.CaseNo;
  1228. temRow["处理事项"] = item.DoItem;
  1229. temRow["申请类型"] = item.ApplicationType;
  1230. temRow["业务类型"] = item.BusinessType;
  1231. temRow["案件阶段【系统】"] = item.CaseStage;
  1232. temRow["案件系数【系统】"] = item.CaseCoefficient;
  1233. temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
  1234. temRow["核稿人【系统】"] = item.Reviewer?.Name;
  1235. temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
  1236. temRow["基本点数【系统】"] = item.BasePoint?.ToString();
  1237. temRow["严重超期备注原因"] = item.OverDueMemo;
  1238. if (item.ReviewerId != null)
  1239. {
  1240. temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
  1241. }
  1242. foreach (var itemStaff in item.ItemStaffs)
  1243. {
  1244. //if (itemStaff.DoPerson.Status != "试用期")
  1245. //{
  1246. // if (retPoints != null && retPoints.Count > 0)
  1247. // {
  1248. // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
  1249. // }
  1250. //}
  1251. temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
  1252. temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
  1253. temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
  1254. if (item.ReviewerId != null)
  1255. {
  1256. #region 取审核人等级审核等级系数
  1257. VerifyCoefficient vcoefficient
  1258. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1259. v.CheckerId == item.Reviewer.StaffGradeId
  1260. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1261. .FirstOrDefault<VerifyCoefficient>();
  1262. #endregion
  1263. if (vcoefficient != null)
  1264. {
  1265. temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
  1266. }
  1267. }
  1268. }
  1269. temRow["是否一致"] = "不一致";
  1270. temRow["不一致原因"] = "Excel中没有,系统中有";
  1271. retTable.Rows.Add(temRow);
  1272. iList++;
  1273. }
  1274. else
  1275. {
  1276. var temRow = retTable.NewRow();
  1277. int iBegin = iTable;
  1278. int iEnd = iTable;
  1279. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1280. if (iEnd < temDt.Rows.Count - 1)
  1281. {
  1282. while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
  1283. temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
  1284. {
  1285. iEnd++;
  1286. }
  1287. }
  1288. temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
  1289. temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
  1290. temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
  1291. temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
  1292. temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
  1293. temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
  1294. temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
  1295. temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
  1296. temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
  1297. temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
  1298. temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
  1299. temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
  1300. temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
  1301. temRow["处理人"] = temDt.Rows[iTable]["处理人"];
  1302. temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
  1303. for (int i = iBegin+1; i <= iEnd; i++)
  1304. {
  1305. temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
  1306. //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
  1307. temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
  1308. if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
  1309. {
  1310. temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
  1311. temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
  1312. }
  1313. temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
  1314. }
  1315. iTable = iEnd;
  1316. #endregion
  1317. temRow["是否一致"] = "不一致";
  1318. temRow["不一致原因"] = "系统中没有,Excel中有";
  1319. retTable.Rows.Add(temRow);
  1320. iTable++;
  1321. }
  1322. }
  1323. }
  1324. if (iList <=items.Count)
  1325. {
  1326. while(iList <items.Count){
  1327. var item = items[iList];
  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. iList++;
  1381. retTable.Rows.Add(temRow);
  1382. }
  1383. }
  1384. else
  1385. {
  1386. while (iTable < temDt.Rows.Count)
  1387. {
  1388. var temRow = retTable.NewRow();
  1389. int iBegin = iTable;
  1390. int iEnd = iTable;
  1391. #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
  1392. while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
  1393. temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
  1394. {
  1395. iEnd++;
  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. NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
  1433. }
  1434. public List<StaffStatistics> CalItemJX(int itemid)
  1435. {
  1436. var Item = Context.PerformanceItems.Include(p=>p.CalMonth)
  1437. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(s=>s.StaffGrade)
  1438. .Include(p=>p.Reviewer)
  1439. .Include(p=>p.Customer)
  1440. .FirstOrDefault(p=>p.Id == itemid);
  1441. List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
  1442. return _calItemJX(verifyCoefficients,Item,Context);
  1443. }
  1444. private void _calItemJX(PerformanceItem Item,spDbContext spDb)
  1445. {
  1446. List<VerifyCoefficient> verifyCoefficients = spDb.VerifyCoefficients.ToList<VerifyCoefficient>();
  1447. var jxList = _calItemJX( verifyCoefficients, Item, spDb);
  1448. var oldJxList = spDb.StaffStatistics.Where(p=>p.ItemId == Item.Id);
  1449. spDb.StaffStatistics.RemoveRange(oldJxList);
  1450. spDb.SaveChanges();
  1451. foreach (var jx in jxList)
  1452. {
  1453. if(jx.totalBasePoint == 0)
  1454. {
  1455. return;
  1456. }
  1457. jx.ItemId = Item.Id;
  1458. spDb.StaffStatistics.Add(jx);
  1459. spDb.SaveChanges();
  1460. }
  1461. }
  1462. /// <summary>
  1463. /// 序号 情况 处理逻辑
  1464. /// 1 处理人试用期算绩效 一人处理 正常算绩效给处理人
  1465. /// 2 处理人试用期不算绩效 一人处理 算给核稿人,如果没有核稿人,这条数据忽略
  1466. /// 3 处理人试用期算绩效 与人合写 合写人算绩效、与合写人一人一半
  1467. /// 4 处理人试用期不算绩效 与人合写 合写人算绩效、全部绩效算给合写人
  1468. /// 5 处理人试用期不算绩效 与人合写 合写人不算算绩效、这条数据忽略
  1469. /// 6 处理人试用期算绩效 与人合写 合写人不算绩效、试用期人员拿一半
  1470. /// 7 处理人不算绩效 一人处理 这条数据忽略
  1471. /// 8 处理人不算绩效 与人合写 合写人算绩效、合写人拿一半
  1472. /// 9 处理人不算绩效 与人合写 合写人不算绩效、这条数据忽略
  1473. /// </summary>
  1474. /// <param name="verifyCoefficients"></param>
  1475. /// <param name="item"></param>
  1476. /// <param name="spDb"></param>
  1477. /// <returns></returns>
  1478. private List<StaffStatistics> _calItemJX( List<VerifyCoefficient> verifyCoefficients, PerformanceItem item,spDbContext spDb)
  1479. {
  1480. System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
  1481. List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
  1482. if (item.ReviewerId != null && item.Reviewer == null)
  1483. {
  1484. item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
  1485. //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
  1486. }
  1487. List<ItemStaff> temIStaffs = new List<ItemStaff>();
  1488. #region 将试用期且不算绩效的人员从处理人清单中剔除
  1489. int syqUsers = 0;
  1490. foreach(var itemStaff in item.ItemStaffs)
  1491. {
  1492. if (itemStaff.DoPerson == null)
  1493. {
  1494. itemStaff.DoPerson = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == itemStaff.DoPersonId);
  1495. }
  1496. if(itemStaff.DoPerson.Status == "试用期" && !itemStaff.DoPerson.IsCalPerformsnce )
  1497. {
  1498. syqUsers += 1;
  1499. }
  1500. else
  1501. {
  1502. temIStaffs.Add(itemStaff);
  1503. }
  1504. }
  1505. #endregion
  1506. #region 处理人全部是试用期人员,则将核稿人当成处理人(处理人为试用期人)
  1507. if (syqUsers == item.ItemStaffs.Count)
  1508. {
  1509. if(item.Reviewer != null)
  1510. {
  1511. temIStaffs.Add(new ItemStaff() { DoPersonId = item.ReviewerId.Value, ItemId = item.Id });
  1512. }
  1513. }
  1514. #endregion
  1515. bool isPJFP = true;
  1516. double total = temIStaffs.Count();
  1517. if (total > 1)
  1518. {
  1519. System.Diagnostics.Debug.WriteLine("");
  1520. }
  1521. if (temIStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
  1522. {
  1523. total = temIStaffs.Select(i => i.PerformancePoint.Value).Sum();
  1524. isPJFP = false;
  1525. }
  1526. foreach (ItemStaff itemStaff in temIStaffs)
  1527. {
  1528. if(itemStaff.DoPerson == null)
  1529. {
  1530. itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
  1531. }
  1532. if (itemStaff.DoPerson.IsCalPerformsnce)
  1533. {
  1534. #region 计算各处理人的绩效点数
  1535. double handlerBasePoint;
  1536. if (item.Type != "专案")
  1537. {
  1538. if (isPJFP)
  1539. {
  1540. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1541. }
  1542. else
  1543. {
  1544. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1545. }
  1546. }
  1547. else
  1548. {
  1549. if (itemStaff.PerformancePoint == null)
  1550. {
  1551. if (isPJFP)
  1552. {
  1553. handlerBasePoint = item.BasePoint.Value * 1.0 / total;
  1554. }
  1555. else
  1556. {
  1557. handlerBasePoint = (double)((decimal)item.BasePoint.Value * (decimal)itemStaff.PerformancePoint.Value / (decimal)total);
  1558. }
  1559. }
  1560. else
  1561. {
  1562. if (item.ItemStaffs.Count == 1 && itemStaff.PerformancePoint == 0)
  1563. {
  1564. handlerBasePoint = item.BasePoint.Value;
  1565. }
  1566. else
  1567. {
  1568. handlerBasePoint = itemStaff.PerformancePoint.Value;
  1569. }
  1570. }
  1571. }
  1572. string handlerJxType = $"{item.Type}处理";
  1573. var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
  1574. if (temStatic != null)
  1575. {
  1576. temStatic.totalBasePoint += handlerBasePoint;
  1577. if (item.Type == "OA" || item.Type == "新申请")
  1578. {
  1579. temStatic.totalActuallyPoint += (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient);
  1580. }
  1581. else
  1582. {
  1583. temStatic.totalActuallyPoint += handlerBasePoint;
  1584. }
  1585. }
  1586. else
  1587. {
  1588. if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsCalPerformsnce)
  1589. {
  1590. if (item.Type == "OA" || item.Type == "新申请")
  1591. {
  1592. if (itemStaff.DoPerson.StaffGrade == null)
  1593. {
  1594. itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s => s.Id == itemStaff.DoPerson.StaffGradeId);
  1595. }
  1596. temStatic = new StaffStatistics()
  1597. {
  1598. //CalMonth = calMonth,
  1599. CalMonthId = item.CalMonthId,
  1600. StaffId = itemStaff.DoPersonId,
  1601. totalActuallyPoint = (double)((decimal)handlerBasePoint * (decimal)itemStaff.DoPerson.StaffGrade.Coefficient),
  1602. totalBasePoint = handlerBasePoint,
  1603. jxType = handlerJxType
  1604. };
  1605. itemStatistics.Add(temStatic);
  1606. }
  1607. else
  1608. {
  1609. temStatic = new StaffStatistics()
  1610. {
  1611. //CalMonth = calMonth,
  1612. CalMonthId = item.CalMonthId,
  1613. StaffId = itemStaff.DoPersonId,
  1614. totalBasePoint = handlerBasePoint,
  1615. totalActuallyPoint = handlerBasePoint,
  1616. jxType = handlerJxType
  1617. };
  1618. itemStatistics.Add(temStatic);
  1619. }
  1620. }
  1621. }
  1622. #endregion
  1623. #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
  1624. if (item.ReviewerId != null && item.Type != "专案" &&
  1625. temIStaffs.FirstOrDefault(s => s.DoPersonId == item.ReviewerId) == null)
  1626. {
  1627. if(item.Reviewer == null)
  1628. {
  1629. item.Reviewer = spDb.Staffs.FirstOrDefault(s=>s.Id == item.ReviewerId);
  1630. }
  1631. if (item.Reviewer.IsCalPerformsnce)
  1632. {
  1633. #region 取审核人等级审核等级系数
  1634. VerifyCoefficient vcoefficient
  1635. = verifyCoefficients.Where<VerifyCoefficient>(v =>
  1636. v.CheckerId == item.Reviewer.StaffGradeId
  1637. && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
  1638. .FirstOrDefault<VerifyCoefficient>();
  1639. #endregion
  1640. if (vcoefficient != null)
  1641. {
  1642. double reviewerBasePoint = (double)((decimal)handlerBasePoint * (decimal)vcoefficient.Coefficient);
  1643. string temJxType = $"{item.Type}审核";
  1644. var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
  1645. if (temReviewerStatic != null)
  1646. {
  1647. temReviewerStatic.totalBasePoint += reviewerBasePoint;
  1648. temReviewerStatic.totalActuallyPoint += reviewerBasePoint;
  1649. }
  1650. else
  1651. {
  1652. if (itemStaff.DoPerson.Status != "试用期" && item.Reviewer.IsCalPerformsnce) //判断是否在职
  1653. {
  1654. temReviewerStatic = new StaffStatistics()
  1655. {
  1656. CalMonthId = item.CalMonthId,
  1657. StaffId = item.ReviewerId.Value,
  1658. totalBasePoint = reviewerBasePoint,
  1659. totalActuallyPoint = reviewerBasePoint,
  1660. jxType = temJxType
  1661. };
  1662. itemStatistics.Add(temReviewerStatic);
  1663. }
  1664. }
  1665. }
  1666. }
  1667. }
  1668. #endregion
  1669. }
  1670. }
  1671. return itemStatistics;
  1672. }
  1673. private void _CalJXPoint(CalMonth calMonth,spDbContext spDb)
  1674. {
  1675. NanduStatics gspjXS = DegreeOfDifficulty(calMonth,spDb);
  1676. calMonth.NanduXS = gspjXS.NanduXS;
  1677. calMonth.S = gspjXS.S;
  1678. calMonth.A = gspjXS.A;
  1679. calMonth.B = gspjXS.B;
  1680. calMonth.C = gspjXS.C;
  1681. calMonth.D = gspjXS.D;
  1682. var retList = spDb.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id).ToList();
  1683. #region 新申请处理+专案处理 奖励点数
  1684. double jlPoint = 0;
  1685. if (calMonth.S.HasValue)
  1686. {
  1687. jlPoint = jlPoint + (calMonth.S.Value * 1.5);
  1688. }
  1689. if (calMonth.A.HasValue)
  1690. {
  1691. jlPoint = jlPoint + (calMonth.A.Value * 0.5);
  1692. }
  1693. #endregion
  1694. double? totalFPBLPoint = 0; //新申请处理+专案 分配比率总点数
  1695. #region 难度系数
  1696. IDictionary<int, NanduStatics> staffXiShu = new Dictionary<int, NanduStatics>();
  1697. IDictionary<int, NanduStatics> ReivewerXiShu = new Dictionary<int, NanduStatics>();
  1698. foreach (StaffStatistics ss in retList)
  1699. {
  1700. if (ss.jxType == "新申请处理" || ss.jxType == "专案处理")
  1701. {
  1702. #region 新申请处理+专案处理
  1703. if (!staffXiShu.ContainsKey(ss.StaffId))
  1704. {
  1705. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb);
  1706. staffXiShu.Add(ss.StaffId, nandu);
  1707. }
  1708. ss.FinianlPoint = ss.totalActuallyPoint * staffXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1709. totalFPBLPoint += ss.FinianlPoint;
  1710. ss.NanduXS = staffXiShu[ss.StaffId].NanduXS;
  1711. ss.S = staffXiShu[ss.StaffId].S;
  1712. ss.A = staffXiShu[ss.StaffId].A;
  1713. ss.B = staffXiShu[ss.StaffId].B;
  1714. ss.C = staffXiShu[ss.StaffId].C;
  1715. ss.D = staffXiShu[ss.StaffId].D;
  1716. #endregion
  1717. }
  1718. else
  1719. {
  1720. if (ss.jxType == "新申请审核")
  1721. {
  1722. if (!ReivewerXiShu.ContainsKey(ss.StaffId))
  1723. {
  1724. NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb, true);
  1725. ReivewerXiShu.Add(ss.StaffId, nandu);
  1726. }
  1727. ss.FinianlPoint = ss.totalBasePoint * ReivewerXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
  1728. ss.NanduXS = ReivewerXiShu[ss.StaffId].NanduXS;
  1729. ss.S = ReivewerXiShu[ss.StaffId].S;
  1730. ss.A = ReivewerXiShu[ss.StaffId].A;
  1731. ss.B = ReivewerXiShu[ss.StaffId].B;
  1732. ss.C = ReivewerXiShu[ss.StaffId].C;
  1733. ss.D = ReivewerXiShu[ss.StaffId].D;
  1734. spDb.SaveChanges();
  1735. }
  1736. else
  1737. {
  1738. ss.FinianlPoint = ss.totalBasePoint;
  1739. spDb.SaveChanges();
  1740. }
  1741. }
  1742. }
  1743. foreach (StaffStatistics ss in retList)
  1744. {
  1745. if (ss.jxType == "新申请处理" || ss.jxType == "专案处理")
  1746. {
  1747. ss.FinianlPoint = ss.FinianlPoint / totalFPBLPoint * (totalFPBLPoint + jlPoint);
  1748. spDb.SaveChanges();
  1749. }
  1750. }
  1751. #endregion
  1752. }
  1753. public void CalJXPoint(int year, int month)
  1754. {
  1755. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1756. if (calMonth != null)
  1757. {
  1758. using (var t = Context.Database.BeginTransaction())
  1759. {
  1760. try
  1761. {
  1762. var result = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
  1763. Context.StaffStatistics.RemoveRange(result);
  1764. var itemList = Context.PerformanceItems
  1765. .Include(s => s.ItemStaffs)
  1766. .Include(p=>p.Customer)
  1767. .Include(p=>p.Reviewer)
  1768. .Where(s => s.CalMonthId == calMonth.Id).ToList();
  1769. var rules = Context.BasePointRules.ToList();
  1770. foreach (var item in itemList)
  1771. {
  1772. Utility.Utility.CalBasePoint(item, rules);
  1773. Context.SaveChanges();
  1774. if (item.BasePoint > 0)
  1775. {
  1776. _calItemJX(item,Context);
  1777. }
  1778. else
  1779. {
  1780. var oldJxList = Context.StaffStatistics.Where(p => p.ItemId == item.Id);
  1781. Context.StaffStatistics.RemoveRange(oldJxList);
  1782. }
  1783. }
  1784. _CalJXPoint(calMonth, Context);
  1785. t.Commit();
  1786. }
  1787. catch (Exception ex)
  1788. {
  1789. t.Rollback();
  1790. }
  1791. }
  1792. }
  1793. }
  1794. /// <summary>
  1795. /// 新申请/专案:
  1796. /// 调整点数 = 分配比例点数/分配比例点数之和*总点数
  1797. /// 等级调整点数+项目组点数之和 = 基础点数 * 代理人等级系数 + 项目组案件调整点数
  1798. /// 分配比例点数 = 个人平均难度系数 / 总平均难度系数 *(等级调整点数+项目组点数之和)
  1799. /// 总点数=等级调整点数+项目组点数之和+奖励点数
  1800. /// 奖励点数= S案数量*1.5 + A案数量 * 0.5
  1801. /// 难度系数=(S案数量*2.5 + A案数量* 1.5 + B案数量*1.0 + C案数量*0.7+ D案数量*0.4) / 总案件数量
  1802. /// 总案件数量= S案数量 + A案数量 + B案数量 + C案数量+ D案数量
  1803. /// OA :
  1804. /// 调整点数= 基础点数 * 等级系数
  1805. /// 其他:
  1806. /// 直接加和基础点数 不需要乘以系数
  1807. /// </summary>
  1808. /// <param name="year"></param>
  1809. /// <param name="month"></param>
  1810. /// <returns></returns>
  1811. public ApiSaveResponse FinishedCalMonth(int year,int month)
  1812. {
  1813. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1814. if (calMonth != null || calMonth.Status !=4)
  1815. {
  1816. using (var t = Context.Database.BeginTransaction())
  1817. {
  1818. try
  1819. {
  1820. _RefreshBasePoint(calMonth,Context);
  1821. //_CalJXPoint(calMonth, Context);
  1822. calMonth.Status = 4;
  1823. Context.SaveChanges();
  1824. t.Commit();
  1825. return new ApiSaveResponse()
  1826. {
  1827. Success = true
  1828. };
  1829. }
  1830. catch (Exception ex)
  1831. {
  1832. t.Rollback();
  1833. return new ApiSaveResponse()
  1834. {
  1835. Success = false,
  1836. ErrorMessage = ex.Message
  1837. };
  1838. }
  1839. }
  1840. }
  1841. else
  1842. {
  1843. return new ApiSaveResponse()
  1844. {
  1845. Success = false,
  1846. ErrorMessage ="指定月份没有数据或者已归档!"
  1847. };
  1848. }
  1849. }
  1850. /// <summary>
  1851. /// 计算指定用户,指定年月的绩效统计信息
  1852. /// </summary>
  1853. /// <param name="userid"></param>
  1854. /// <param name="year"></param>
  1855. /// <param name="month"></param>
  1856. /// <returns></returns>
  1857. public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
  1858. {
  1859. //object retList;
  1860. //string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
  1861. //if(!MyMemoryCache.TryGetValue(strKey,out retList))
  1862. //{
  1863. CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
  1864. if (calMonth == null)
  1865. {
  1866. return null;
  1867. }
  1868. else
  1869. {
  1870. return _CalMyStatistics(calMonth, userid);
  1871. #region old code
  1872. //if (calMonth.Status == 4)
  1873. //{
  1874. // //已归档,归档数据库中直接取出记录
  1875. // if (userid == null)
  1876. // {
  1877. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
  1878. // }
  1879. // else
  1880. // {
  1881. // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
  1882. // }
  1883. //}
  1884. //else
  1885. //{
  1886. // try
  1887. // {
  1888. // retList = _CalMyStatistics(calMonth, userid);
  1889. // }
  1890. // catch(Exception ex)
  1891. // {
  1892. // StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
  1893. // sw.WriteLine($"{ex.Message}");
  1894. // sw.Flush();
  1895. // sw.Close();
  1896. // sw.Dispose();
  1897. // }
  1898. //}
  1899. //// Set cache options.
  1900. //var cacheEntryOptions = new MemoryCacheEntryOptions()
  1901. // // Keep in cache for this time, reset time if accessed.
  1902. // .SetSlidingExpiration(TimeSpan.FromHours(1));
  1903. //foreach(var temObj in (List<StaffStatistics>)retList)
  1904. //{
  1905. // temObj.CalMonth.PerformanceItems = null;
  1906. //}
  1907. //// Save data in cache.
  1908. //MyMemoryCache.SetValue(strKey, retList);
  1909. //return (List<StaffStatistics>)retList;
  1910. #endregion
  1911. }
  1912. //}
  1913. //else
  1914. //{
  1915. // var temList = (List<StaffStatistics>)retList;
  1916. // foreach (var temObj in temList)
  1917. // {
  1918. // temObj.CalMonth.PerformanceItems = null;
  1919. // }
  1920. // return temList;
  1921. //}
  1922. }
  1923. private string GetExpress(IList<FieldCondition> conditions)
  1924. {
  1925. string str = "";
  1926. foreach(var c in conditions)
  1927. {
  1928. if (string.IsNullOrEmpty(str))
  1929. {
  1930. str = c.ToExpressString("s");
  1931. }
  1932. else
  1933. {
  1934. if(c.LogicOperate == LogicEnum.And)
  1935. {
  1936. str = $"({str}) && {c.ToExpressString("s")}";
  1937. }
  1938. else
  1939. {
  1940. str = $"({str}) || {c.ToExpressString("s")}";
  1941. }
  1942. }
  1943. }
  1944. return str;
  1945. }
  1946. [HttpGet,HttpPost]
  1947. public FileProcessTask ExportData(QueryFilter queryFilter)
  1948. {
  1949. var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
  1950. var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
  1951. var filePath = Path.Combine(attachfileSavePath, filename);
  1952. var fileTask = new FileProcessTask()
  1953. {
  1954. Id = Guid.NewGuid().ToString(),
  1955. FileName = filename,
  1956. FilePath = filePath,
  1957. Processed = 0
  1958. };
  1959. fileTaskService.Add(fileTask);
  1960. ThreadObject threadObject = new ThreadObject()
  1961. {
  1962. queryFilter = queryFilter,
  1963. fileTask = fileTask
  1964. };
  1965. System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
  1966. t.Start(threadObject);
  1967. return fileTask;
  1968. }
  1969. internal class ThreadObject
  1970. {
  1971. public QueryFilter queryFilter { get; set; }
  1972. public FileProcessTask fileTask { get; set; }
  1973. }
  1974. private void ExportDataThread(object tObj)
  1975. {
  1976. QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
  1977. FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
  1978. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  1979. var retList = response
  1980. .Include(p=>p.Customer)
  1981. .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
  1982. .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
  1983. .Include(p=>p.PreOastaff)
  1984. .Include(p=>p.CalMonth)
  1985. .ToList<PerformanceItem>();
  1986. DataTable dt = new DataTable();
  1987. #region 添加栏位
  1988. dt.Columns.Add("我方文号",typeof(string));
  1989. dt.Columns.Add("申请类型", typeof(string));
  1990. dt.Columns.Add("业务类型", typeof(string));
  1991. dt.Columns.Add("备注(填表注意事项)", typeof(string));
  1992. dt.Columns.Add("处理事项", typeof(string));
  1993. dt.Columns.Add("案件阶段", typeof(string));
  1994. dt.Columns.Add("案件系数", typeof(string));
  1995. dt.Columns.Add("处理事项系数", typeof(string));
  1996. dt.Columns.Add("前一次OA处理事项系数", typeof(string));
  1997. dt.Columns.Add("前一次OA处理人", typeof(string));
  1998. dt.Columns.Add("处理人等级", typeof(string));
  1999. dt.Columns.Add("基本点数", typeof(string));
  2000. dt.Columns.Add("核稿系数", typeof(string));
  2001. dt.Columns.Add("核稿绩效", typeof(string));
  2002. dt.Columns.Add("处理人", typeof(string));
  2003. dt.Columns.Add("核稿人", typeof(string));
  2004. dt.Columns.Add("客户名称", typeof(string));
  2005. dt.Columns.Add("申请人", typeof(string));
  2006. dt.Columns.Add("处理事项完成日", typeof(string));
  2007. dt.Columns.Add("定稿日", typeof(string));
  2008. dt.Columns.Add("返稿日", typeof(string));
  2009. dt.Columns.Add("案件类型", typeof(string));
  2010. dt.Columns.Add("案件状态", typeof(string));
  2011. dt.Columns.Add("处理事项备注", typeof(string));
  2012. dt.Columns.Add("处理状态", typeof(string));
  2013. dt.Columns.Add("案件名称", typeof(string));
  2014. dt.Columns.Add("委案日期", typeof(string));
  2015. dt.Columns.Add("客户期限", typeof(string));
  2016. dt.Columns.Add("内部期限", typeof(string));
  2017. dt.Columns.Add("初稿日", typeof(string));
  2018. dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
  2019. dt.Columns.Add("备注", typeof(string));
  2020. #endregion
  2021. List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
  2022. fileTask.Size = retList.Count;
  2023. foreach (var item in retList)
  2024. {
  2025. fileTask.Processed += 1;
  2026. if (item.CaseNo.StartsWith("J"))
  2027. {
  2028. continue;
  2029. }
  2030. try
  2031. {
  2032. var row = dt.NewRow();
  2033. row["我方文号"] = item.CaseNo;
  2034. row["申请类型"] = item.ApplicationType;
  2035. row["业务类型"] = item.BusinessType;
  2036. row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
  2037. row["处理事项"] = item.DoItem;
  2038. row["案件阶段"] = item.CaseStage;
  2039. row["案件系数"] = item.CaseCoefficient;
  2040. row["处理事项系数"] = item.DoItemCoefficient;
  2041. row["前一次OA处理事项系数"] = "";
  2042. if (item.PreOastaffId.HasValue)
  2043. {
  2044. row["前一次OA处理人"] = item.PreOastaff?.Name;
  2045. }
  2046. string strISLevels = "";
  2047. string strISNames = "";
  2048. foreach (var istaff in item.ItemStaffs)
  2049. {
  2050. strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
  2051. strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
  2052. }
  2053. row["处理人等级"] = strISLevels;
  2054. row["基本点数"] = item.BasePoint;
  2055. row["处理人"] = strISNames;
  2056. row["核稿人"] = item.Reviewer?.Name;
  2057. if (item.ReviewerId != null && item.BasePoint.HasValue)
  2058. {
  2059. var jxList = _calItemJX( verifyCoefficients, item, new spDbContext());
  2060. row["核稿系数"] = "";
  2061. var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
  2062. if (temJx != null)
  2063. {
  2064. row["核稿绩效"] = temJx.totalBasePoint;
  2065. }
  2066. }
  2067. row["客户名称"] = item.Customer?.Name;
  2068. row["申请人"] = item.ApplicationName;
  2069. row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
  2070. row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
  2071. row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
  2072. row["案件类型"] = item.CaseType;
  2073. row["案件状态"] = item.CaseState;
  2074. row["处理事项备注"] = item.DoItemState;
  2075. row["处理状态"] = item.DoItemState;
  2076. row["案件名称"] = item.CaseName;
  2077. row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
  2078. row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
  2079. row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
  2080. row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
  2081. row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
  2082. row["备注"] = item.DoItemMemo;
  2083. dt.Rows.Add(row);
  2084. }
  2085. catch(Exception ex)
  2086. {
  2087. throw ex;
  2088. }
  2089. }
  2090. utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
  2091. fileTask.Finished = true;
  2092. }
  2093. [HttpPost]
  2094. public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
  2095. {
  2096. ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
  2097. IQueryable<PerformanceItem> response = NewMethod(queryFilter);
  2098. int totals = response.ToList<PerformanceItem>().Count;
  2099. if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
  2100. {
  2101. response = response
  2102. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2103. .Include(pi => pi.Reviewer)
  2104. .Include(pi => pi.Customer)
  2105. .Include(pi => pi.CalMonth)
  2106. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2107. //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
  2108. }
  2109. else
  2110. {
  2111. response = response
  2112. .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
  2113. .Include(pi => pi.Reviewer)
  2114. .Include(pi => pi.Customer)
  2115. .Include(pi => pi.CalMonth)
  2116. .OrderConditions<PerformanceItem>(queryFilter.Sorts);
  2117. //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
  2118. }
  2119. ret.TotalCount = totals;
  2120. var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
  2121. #region 将某些属性设为null,避免循环取值造成返回json过大
  2122. foreach (PerformanceItem item in retList)
  2123. {
  2124. foreach (ItemStaff itemStaff in item.ItemStaffs)
  2125. {
  2126. itemStaff.DoPerson.ItemStaffs = null;
  2127. itemStaff.DoPerson.ReviewerItems = null;
  2128. itemStaff.Item = null;
  2129. }
  2130. if (item.Reviewer != null)
  2131. {
  2132. item.Reviewer.ReviewerItems = null;
  2133. item.Reviewer.Customers = null;
  2134. item.Reviewer.ItemStaffs = null;
  2135. }
  2136. if (item.WorkflowUser != null)
  2137. {
  2138. item.WorkflowUser.ReviewerItems = null;
  2139. item.WorkflowUser.Customers = null;
  2140. item.WorkflowUser.ItemStaffs = null;
  2141. }
  2142. if (item.Customer != null)
  2143. {
  2144. item.Customer.PerformanceItems = null;
  2145. }
  2146. if (item.CalMonth != null)
  2147. {
  2148. item.CalMonth.PerformanceItems = null;
  2149. }
  2150. }
  2151. #endregion
  2152. ret.Results = retList.ToList();
  2153. return ret;
  2154. }
  2155. private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
  2156. {
  2157. string strExpress = "";
  2158. string strCalMonth = "";
  2159. if (queryFilter.CalMonthId.HasValue)
  2160. {
  2161. strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
  2162. }
  2163. else
  2164. {
  2165. if(queryFilter.jxType == jxType.finished)
  2166. {
  2167. strCalMonth = $"s.CalMonth.Status == 4";
  2168. }
  2169. else
  2170. {
  2171. strCalMonth = $"s.CalMonth.Status != 4";
  2172. }
  2173. //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
  2174. }
  2175. if (!string.IsNullOrEmpty(strExpress))
  2176. {
  2177. strExpress = $"{strExpress} && {strCalMonth}";
  2178. }
  2179. else
  2180. {
  2181. strExpress = strCalMonth;
  2182. }
  2183. if (queryFilter.ConditionTree != null)
  2184. {
  2185. string strTem = GetExpress(queryFilter.ConditionTree);
  2186. if (!string.IsNullOrEmpty(strTem))
  2187. {
  2188. strExpress = $"{strExpress} && ({strTem})";
  2189. }
  2190. }
  2191. var interpreter = new Interpreter();
  2192. Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
  2193. IQueryable<PerformanceItem> response;
  2194. if (queryFilter.userId > 0)
  2195. {
  2196. if (queryFilter.DoingOrReview == 0)
  2197. {
  2198. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
  2199. }
  2200. else
  2201. {
  2202. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
  2203. }
  2204. }
  2205. else
  2206. {
  2207. response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
  2208. }
  2209. return response;
  2210. }
  2211. public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
  2212. {
  2213. ApiSaveResponse retResponse = new ApiSaveResponse();
  2214. retResponse.Success = true;
  2215. if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
  2216. {
  2217. using (var t = Context.Database.BeginTransaction())
  2218. {
  2219. try
  2220. {
  2221. CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
  2222. if (calMonth == null)
  2223. {
  2224. retResponse.Success = false;
  2225. retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
  2226. return retResponse;
  2227. }
  2228. else
  2229. {
  2230. projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
  2231. projectContents.ProjectContentRecord.CalMonth = null;
  2232. var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
  2233. projectContents.ProjectContentRecord.StaffId = staff.Id;
  2234. projectContents.ProjectContentRecord.State = 0;
  2235. }
  2236. var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
  2237. if (project != null)
  2238. {
  2239. var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
  2240. && p.StaffId == projectContents.ProjectContentRecord.StaffId
  2241. && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
  2242. if(pRecord != null)
  2243. {
  2244. retResponse.Success = false;
  2245. retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
  2246. return retResponse;
  2247. }
  2248. Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
  2249. foreach (var doItem in projectContents.ProjectWorkContents)
  2250. {
  2251. doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
  2252. Context.ProjectWorkContents.Add(doItem);
  2253. }
  2254. t.Commit();
  2255. }
  2256. else
  2257. {
  2258. retResponse.Success = false;
  2259. retResponse.ErrorMessage = "专案不存在或专案已完成!";
  2260. return retResponse;
  2261. }
  2262. }
  2263. catch (Exception ex)
  2264. {
  2265. retResponse.Success = false;
  2266. retResponse.ErrorMessage = ex.Message;
  2267. t.Rollback();
  2268. return retResponse;
  2269. }
  2270. }
  2271. }
  2272. return retResponse;
  2273. }
  2274. public PerformanceItem GetCaseInfo(string CaseNo)
  2275. {
  2276. var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
  2277. if(retObj == null)
  2278. {
  2279. retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
  2280. }
  2281. return retObj;
  2282. }
  2283. public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
  2284. {
  2285. var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
  2286. if (retObj == null)
  2287. {
  2288. retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
  2289. }
  2290. return retObj;
  2291. }
  2292. public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage,bool UpdateFromIPEasy=true)
  2293. {
  2294. var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2295. && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
  2296. if (retObj == null && UpdateFromIPEasy)
  2297. {
  2298. var temObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
  2299. System.Dynamic.ExpandoObject temExpandoObject = (System.Dynamic.ExpandoObject)temObj;
  2300. retObj = new PerformanceItem();
  2301. retObj.CaseNo = temObj.CaseNo.ToString();
  2302. retObj.CaseName = temObj.CaseName.ToString();
  2303. try
  2304. {
  2305. if (temObj.ApplicationType != null)
  2306. retObj.ApplicationType = temObj.ApplicationType.ToString();
  2307. if (temObj.CaseMemo != null)
  2308. retObj.CaseMemo = temObj.CaseMemo.ToString();
  2309. if (temObj.BusinessType != null)
  2310. retObj.BusinessType = temObj.BusinessType.ToString();
  2311. if (temObj.DoItem != null)
  2312. retObj.DoItem = temObj.DoItem.ToString();
  2313. if (temObj.CaseStage != null)
  2314. retObj.CaseStage = temObj.CaseStage.ToString();
  2315. if (temObj.CaseType != null)
  2316. retObj.CaseType = temObj.CaseType.ToString();
  2317. if (temObj.DoItemState != null)
  2318. retObj.DoItemState = temObj.DoItemState.ToString();
  2319. if (temObj.DoItemCoefficient != null)
  2320. retObj.DoItemCoefficient = temObj.DoItemCoefficient.ToString();
  2321. if (temObj.CaseCoefficient != null)
  2322. retObj.CaseCoefficient = temObj.CaseCoefficient.ToString();
  2323. if (temObj.EntrustingDate != null)
  2324. {
  2325. if (!string.IsNullOrEmpty(temObj.EntrustingDate.ToString()))
  2326. retObj.EntrustingDate = DateTime.Parse(temObj.EntrustingDate.ToString());
  2327. }
  2328. if (temObj.InternalDate != null)
  2329. {
  2330. if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
  2331. retObj.InternalDate = DateTime.Parse(temObj.InternalDate.ToString());
  2332. }
  2333. if (temObj.CustomerLimitDate != null)
  2334. {
  2335. if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
  2336. retObj.CustomerLimitDate = DateTime.Parse(temObj.InternalDate.ToString());
  2337. }
  2338. if (temObj.ReturnDate != null)
  2339. {
  2340. if (!string.IsNullOrEmpty(temObj.ReturnDate.ToString()))
  2341. retObj.ReturnDate = DateTime.Parse(temObj.ReturnDate.ToString());
  2342. }
  2343. if (temObj.FinalizationDate != null)
  2344. {
  2345. if (!string.IsNullOrEmpty(temObj.FinalizationDate.ToString()))
  2346. retObj.FinalizationDate = DateTime.Parse(temObj.FinalizationDate.ToString());
  2347. }
  2348. if (temObj.FinishedDate != null)
  2349. {
  2350. if (!string.IsNullOrEmpty(temObj.FinishedDate.ToString()))
  2351. retObj.FinishedDate = DateTime.Parse(temObj.FinishedDate.ToString());
  2352. }
  2353. }
  2354. catch { }
  2355. int temWordCount;
  2356. if (temObj.WordCount != null)
  2357. {
  2358. if (int.TryParse(temObj.WordCount, out temWordCount))
  2359. {
  2360. retObj.WordCount = temWordCount;
  2361. }
  2362. }
  2363. try
  2364. {
  2365. if (temObj.CustomerName != null)
  2366. {
  2367. string strCustomer = temObj.CustomerName.ToString();
  2368. retObj.Customer = new Customer() { Name = strCustomer };
  2369. var temCustomer = Context.Customers.Where(c => c.Name == strCustomer.Trim()).FirstOrDefault();
  2370. if (temCustomer != null)
  2371. {
  2372. retObj.CustomerId = temCustomer.Id;
  2373. }
  2374. }
  2375. }
  2376. catch { }
  2377. try
  2378. {
  2379. if (temObj.Reviewer != null)
  2380. {
  2381. string strReViewer = temObj.Reviewer.ToString();
  2382. var temReviewer = Context.Staffs.Where(s => s.Name == strReViewer.Trim()).FirstOrDefault();
  2383. if (temReviewer != null)
  2384. {
  2385. retObj.ReviewerId = temReviewer.Id;
  2386. }
  2387. }
  2388. }
  2389. catch { }
  2390. if (temObj.DoPersons != null)
  2391. {
  2392. string DoPersons = temObj.DoPersons.ToString();
  2393. string[] Persons = DoPersons.Split(new char[] { ',' });
  2394. List<ItemStaff> itemStaffs = new List<ItemStaff>();
  2395. foreach (var doPerson in Persons)
  2396. {
  2397. itemStaffs.Add(new ItemStaff() { DoPerson = new Staff() { Name = doPerson } });
  2398. }
  2399. retObj.ItemStaffs = itemStaffs;
  2400. }
  2401. }
  2402. return retObj;
  2403. }
  2404. public PerformanceItem GetItemInfoByMonthId(string CaseNo, string DoItem, string caseStage,int calMonthId)
  2405. {
  2406. var retObj = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
  2407. && p.DoItem == DoItem.Trim() && p.CalMonthId == calMonthId);
  2408. if(retObj != null)
  2409. {
  2410. if(string.IsNullOrEmpty (retObj.CaseStage) && string.IsNullOrEmpty(caseStage))
  2411. {
  2412. return retObj;
  2413. }
  2414. else
  2415. {
  2416. if(retObj.CaseStage == caseStage)
  2417. {
  2418. return retObj;
  2419. }
  2420. else
  2421. {
  2422. return null;
  2423. }
  2424. }
  2425. }
  2426. else
  2427. {
  2428. return null;
  2429. }
  2430. }
  2431. public bool MovePerformance2ProjectInfo()
  2432. {
  2433. var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
  2434. .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
  2435. var pList = response.ToList<PerformanceItem>();
  2436. foreach(var p in pList)
  2437. {
  2438. ProjectInfo project = new ProjectInfo();
  2439. project.CaseNo = p.CaseNo;
  2440. project.CaseName = p.CaseName;
  2441. project.CaseState = 0;
  2442. project.CaseType = p.CaseType;
  2443. project.CustomerId = p.CustomerId;
  2444. project.ReviewerId = p.ReviewerId;
  2445. Context.ProjectInfos.Add(project);
  2446. foreach(ItemStaff iStaff in p.ItemStaffs)
  2447. {
  2448. Context.ItemStaffs.Remove(iStaff);
  2449. }
  2450. Context.PerformanceItems.Remove(p);
  2451. Context.SaveChanges();
  2452. }
  2453. return true;
  2454. }
  2455. }
  2456. }