123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832 |
- using DynamicExpresso;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.StaticFiles;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Caching.Memory;
- using Microsoft.Extensions.Hosting;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Threading;
- using System.Threading.Tasks;
- using wispro.sp.api.Services;
- using wispro.sp.api.Utility;
- using wispro.sp.entity;
- using wispro.sp.share;
- using wispro.sp.utility;
- namespace wispro.sp.api.Controllers
- {
- [Route("api/[controller]/[action]")]
- [ApiController]
- [Authorize]
- public class PerformanceItemController : ControllerBase
- {
- spDbContext Context;
- IFileTaskService fileTaskService;
-
- public PerformanceItemController(spDbContext context, IFileTaskService _fileTaskService)
- {
- Context = context;
- fileTaskService = _fileTaskService;
- }
- public ApiSaveResponse RemoveDBNotFinishDate(int year,int month)
- {
- ApiSaveResponse ret = new ApiSaveResponse();
- ret.Success = true;
- var itemList = Context.PerformanceItems.Include(p=>p.ItemStaffs).Where(p => p.CalMonth.Year == year &&
- p.CalMonth.Month == month &&
- p.DoItem =="处理审查意见" &&
- p.FinishedDate ==null);
- using var t = Context.Database.BeginTransaction();
- try
- {
- foreach (var item in itemList.ToList())
- {
- if (item != null)
- {
- Context.ItemStaffs.RemoveRange(item.ItemStaffs);
- Context.PerformanceItems.Remove(item);
- }
- }
- Context.SaveChanges();
- t.Commit();
- return ret;
- }
- catch (Exception ex)
- {
- t.Rollback();
- ret.Success = false;
- ret.ErrorMessage = ex.Message;
- return ret;
- }
- }
- public bool IsExist(PerformanceItem item)
- {
- var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
- x.CaseNo == item.CaseNo &&
- x.DoItem == item.DoItem &&
- x.CaseStage == item.CaseStage &&
- x.CalMonth.Year == item.CalMonth.Year &&
- x.CalMonth.Month == item.CalMonth.Month);
- if(results.Count() > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public ApiSaveResponse New(PerformanceItem item)
- {
- ApiSaveResponse ret = new ApiSaveResponse();
- ret.Success = true;
- using (Context.Database.BeginTransaction())
- {
- try
- {
- var results = Context.PerformanceItems.Where<PerformanceItem>(x =>
- x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.DoItem != "提出报告" && x.CaseStage == item.CaseStage);
- if (item.DoItem.ToUpper() == "提交IDS")
- {
- //提交IDS 添加完成日期做完判断是否已算绩效的条件
- results = Context.PerformanceItems.Where<PerformanceItem>(x=>x.CaseNo == item.CaseNo && x.DoItem == item.DoItem && x.FinishedDate == item.FinishedDate);
- }
- var items = results.Include(pi => pi.CalMonth).FirstOrDefault<PerformanceItem>();
- if (items != null)
- {
- item.AgentFeedbackMemo = "已算绩效";
- item.DoItemMemo = $"{items.DoItemMemo}\r\n{items.CalMonth.Year}-{items.CalMonth.Month}已计算!";
- item.BasePoint = 0;
- }
- if (item.CalMonth != null)
- {
- var calMonth = Context.CalMonths.Where<CalMonth>(c => c.Year == item.CalMonth.Year && c.Month == item.CalMonth.Month).FirstOrDefault();
-
- if(calMonth == null)
- {
- Context.CalMonths.Add(item.CalMonth);
- if (item.BasePoint > 0)
- {
- _calItemJX(item);
- }
- Context.SaveChanges();
- }
- else
- {
- item.CalMonth = calMonth;
- }
- item.CalMonthId = item.CalMonth.Id;
- item.CalMonth = null;
- }
- if (!string.IsNullOrEmpty(item.Customer.Name))
- {
- var temCustomer = Context.Customers.Where<Customer>(c => c.Name == item.Customer.Name).FirstOrDefault();
- if (temCustomer == null)
- {
- temCustomer = new Customer() { Name = item.Customer.Name };
- //item.Customer.Id = 0;
-
- Context.Customers.Add(temCustomer);
- Context.SaveChanges();
- item.Customer = temCustomer;
- //item.CustomerId = item.Customer.Id;
- }
- else
- {
- item.Customer = temCustomer;
- }
- item.CustomerId = item.Customer.Id;
- item.Customer = null;
- }
- else
- {
- item.Customer = null;
- }
-
- var ItemStaffs = item.ItemStaffs;
- item.ItemStaffs = null;
- Context.PerformanceItems.Add(item);
- Context.SaveChanges();
- foreach (ItemStaff itemStaff in ItemStaffs)
- {
- itemStaff.ItemId = item.Id;
- itemStaff.Item = null;
- if (itemStaff.DoPersonId == 0 && itemStaff.DoPerson != null)
- {
- var temStaff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == itemStaff.DoPerson.Name);
- if (temStaff != null)
- {
- itemStaff.DoPersonId = temStaff.Id;
- itemStaff.DoPerson = null;
- }
- else
- {
- Context.Staffs.Add(itemStaff.DoPerson);
- Context.SaveChanges();
- itemStaff.DoPersonId = itemStaff.DoPerson.Id;
- itemStaff.DoPerson = null;
- }
- }
- }
- Context.ItemStaffs.AddRange(ItemStaffs);
- Context.SaveChanges();
- Context.Database.CommitTransaction();
- }
- catch (Exception ex)
- {
- ret.Success = false;
- ret.ErrorMessage = ex.Message;
- Context.Database.RollbackTransaction();
- }
- }
-
- return ret;
- }
- /// <summary>
- /// 更新绩效记录信息
- /// </summary>
- /// <param name="id">绩效记录编号</param>
- /// <param name="field">栏位,多个位以|杠隔开</param>
- /// <param name="value">栏位值,多个以|杠隔开</param>
- /// <returns></returns>
- public ApiSaveResponse UpdateFieldValue(int id,string field,string value)
- {
- ApiSaveResponse ret = new ApiSaveResponse();
- ret.Success = true;
- var item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.Id == id);
- if (item == null)
- {
- ret.Success = false;
- ret.ErrorMessage = $"不存在的{id}";
- return ret;
- }
- if(string.IsNullOrEmpty(field) )
- {
- ret.Success = false;
- ret.ErrorMessage = $"参数不对!";
- return ret;
- }
- string[] fields = field.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
- string[] values = new string[] { null };
- if (!string.IsNullOrEmpty(value))
- {
- values = value.Split(new char[] { '|' });
- }
- if (fields.Length != values.Length) {
- ret.Success = false;
- ret.ErrorMessage = "栏位和值对不匹配";
- }
- else
- {
- for(int i = 0; i < fields.Length; i++)
- {
- string temField = fields[i];
- string temValue = values[i];
- switch (temField)
- {
- case "AgentFeedbackMemo":
- item.AgentFeedbackMemo = temValue;
- break;
- case "CaseCoefficient":
- item.CaseCoefficient = temValue;
- //此处添加保存到流程系统的代码
- break;
- case "DoItemCoefficient":
- item.DoItemCoefficient = temValue;
- //此处添加保存到流程系统的代码
- break;
- case "WordCount":
- int wordCount;
- if (int.TryParse(temValue, out wordCount))
- {
- item.WordCount = wordCount;
- }
- else
- {
- item.WordCount = null;
- //ret.Success = false;
- //ret.ErrorMessage = "所给的栏位值不能转换成数字!";
- //return ret;
- }
- break;
- case "ReturnCasseNo":
- item.ReturnCasseNo = temValue;
- break;
- }
- }
- if (item.AgentFeedbackMemo != "特殊点数申诉")
- {
- Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
- if (item.BasePoint > 0)
- {
- _calItemJX(item);
- }
- Context.SaveChanges();
- }
- }
-
- return ret;
- }
- public ListApiResponse<PerformanceItem> Query(int pageIndex,int pageSize)
- {
- ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
- var results = Context.PerformanceItems
- .Where<PerformanceItem>(s =>
- (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == User.Identity.Name).Count() > 0 || s.Reviewer.Name == User.Identity.Name)
- && s.CalMonth.Status != 4);
- ret.TotalCount = results.Count();
- List<PerformanceItem> retList = results
- .Include(pi=>pi.ItemStaffs).ThenInclude(iStaff=>iStaff.DoPerson)
- .Include(pi=>pi.Reviewer)
- .Include(pi=>pi.Customer)
- .Include(pi=>pi.CalMonth)
- .OrderByDescending(o=>o.Id)
- .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize).ToList<PerformanceItem>();
- #region 将某些属性设为null,避免循环取值造成返回json过大
- foreach (PerformanceItem item in retList)
- {
- foreach (ItemStaff itemStaff in item.ItemStaffs)
- {
- itemStaff.DoPerson.ItemStaffs = null;
- itemStaff.DoPerson.ReviewerItems = null;
- itemStaff.Item = null;
- }
- item.Reviewer.ReviewerItems = null;
- item.Reviewer.Customers = null;
- item.Reviewer.ItemStaffs = null;
- item.Customer.PerformanceItems = null;
- item.CalMonth.PerformanceItems = null;
- }
- #endregion
- ret.Results = retList;
- return ret;
- }
- public PerformanceItem Get(int Id)
- {
- var results = Context.PerformanceItems
- .Where<PerformanceItem>(s =>s.Id == Id);
- PerformanceItem item = results
- .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
- .Include(pi => pi.Reviewer)
- .Include(pi => pi.Customer)
- .Include(pi => pi.CalMonth)
- .OrderByDescending(o => o.Id)
- .FirstOrDefault();
- #region 将某些属性设为null,避免循环取值造成返回json过大
- foreach (ItemStaff itemStaff in item.ItemStaffs)
- {
- itemStaff.DoPerson.ItemStaffs = null;
- itemStaff.DoPerson.ReviewerItems = null;
- itemStaff.Item = null;
- }
- if (item.Reviewer != null)
- {
- item.Reviewer.ReviewerItems = null;
- item.Reviewer.Customers = null;
- item.Reviewer.ItemStaffs = null;
- }
- item.Customer.PerformanceItems = null;
- item.CalMonth.PerformanceItems = null;
- #endregion
- return item;
- }
- /// <summary>
- /// 获取给定用户的绩效清单
- /// </summary>
- /// <param name="userid">用户id</param>
- /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
- /// <returns></returns>
- public ListApiResponse<PerformanceItem> GetMyList(int userid, int type,int pageIndex=1,int pageSize = 10)
- {
-
- ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
- var results = Context.PerformanceItems
- .Where<PerformanceItem>(s =>
- (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid ).Count() > 0 || s.Reviewer.Id == userid )
- && s.CalMonth.Status == type);
-
- ret.TotalCount = results.Count();
- List<PerformanceItem> retList = results
- .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
- .Include(pi => pi.Reviewer)
- .Include(pi => pi.Customer)
- .Include(pi => pi.CalMonth)
- .OrderByDescending(o => o.Id)
- .Skip<PerformanceItem>((pageIndex - 1) * pageSize).Take(pageSize)
- .ToList<PerformanceItem>();
- #region 将某些属性设为null,避免循环取值造成返回json过大
- foreach (PerformanceItem item in retList)
- {
- foreach(ItemStaff itemStaff in item.ItemStaffs)
- {
- itemStaff.DoPerson.ItemStaffs = null;
- itemStaff.DoPerson.ReviewerItems = null;
- itemStaff.Item = null;
- }
- item.Reviewer.ReviewerItems = null;
- item.Reviewer.Customers = null;
- item.Reviewer.ItemStaffs = null;
- item.Customer.PerformanceItems = null;
- item.CalMonth.PerformanceItems = null;
- }
- #endregion
- ret.Results = retList;
- return ret;
- }
- /// <summary>
- /// 获取个人难度系数
- /// </summary>
- /// <param name="calMonth">绩效月份</param>
- /// <param name="userId">用户Id</param>
- /// <param name="isReivewer">是否审核个人难度系数</param>
- /// <returns></returns>
- private NanduStatics PersonNanduStatics(CalMonth calMonth,int userId,spDbContext spDb,bool isReivewer = false)
- {
- NanduStatics retObj = new NanduStatics();
-
- IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
- var list = spDb.CaseCeoffcients;
- foreach (var cx in list.ToList<CaseCeoffcient>())
- {
- CaseXiShu.Add(cx.Ceoffcient, cx.Value);
- }
- string jxType = isReivewer ? "新申请审核" : "新申请处理";
- var results = spDb.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id && s.jxType == jxType && s.StaffId == userId);
- if (!isReivewer)
- {
- results = spDb.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id && (s.jxType == jxType || s.jxType == "专案处理") && s.StaffId == userId);
- }
-
- #region 循环计算
- int iCount = 0;
- double d = 0.0;
- var retList = results.ToList();
- foreach (var item in retList)
- {
- string strCaseCeoffcient = item.Item.CaseCoefficient;
- if (string.IsNullOrEmpty(strCaseCeoffcient))
- {
- strCaseCeoffcient = "B";
- }
- #region 严重延期降系数
- if (item.Item.isDanger() && string.IsNullOrEmpty(item.Item.OverDueMemo))
- {
- switch (item.Item.CaseCoefficient)
- {
- case "S":
- strCaseCeoffcient = "A";
- break;
- case "A":
- strCaseCeoffcient = "B";
- break;
- case "B":
- strCaseCeoffcient = "C";
- break;
- case "C":
- strCaseCeoffcient = "D";
- break;
- }
- }
- #endregion
- switch (strCaseCeoffcient)
- {
- case "S":
- if (item.Item.Type == "专案")
- {
- retObj.S += item.totalBasePoint.Value;
- }
- else
- {
- retObj.S += 1;
- }
- break;
- case "A":
- if (item.Item.Type == "专案")
- {
- retObj.A += item.totalBasePoint.Value;
- }
- else
- {
- retObj.A += 1;
- }
- break;
- case "B":
- if (item.Item.Type == "专案")
- {
- retObj.B += item.totalBasePoint.Value;
- }
- else
- {
- retObj.B += 1;
- }
- break;
- case "C":
- if (item.Item.Type == "专案")
- {
- retObj.C += item.totalBasePoint.Value;
- }
- else
- {
- retObj.C += 1;
- }
- break;
- case "D":
- if (item.Item.Type == "专案")
- {
- retObj.D += item.totalBasePoint.Value;
- }
- else
- {
- retObj.D += 1;
- }
- break;
- default:
- if (item.Item.Type == "专案")
- {
- retObj.B += item.totalBasePoint.Value;
- }
- else
- {
- retObj.B += 1;
- }
- break;
- }
- if (CaseXiShu.ContainsKey(strCaseCeoffcient))
- {
- d += CaseXiShu[strCaseCeoffcient];
- iCount += 1;
- }
- }
- #endregion
- retObj.NanduXS = d / (double)iCount;
-
- return retObj;
-
- }
-
- /// <summary>
- /// 获取总难度系数
- /// </summary>
- /// <param name="calMonth"></param>
- /// <returns></returns>
- private NanduStatics DegreeOfDifficulty(CalMonth calMonth,spDbContext spDb)
- {
- NanduStatics retObj = new NanduStatics();
-
- IDictionary<string, double> CaseXiShu = new Dictionary<string, double>();
- var list = Context.CaseCeoffcients;
- foreach (var cx in list.ToList<CaseCeoffcient>())
- {
- CaseXiShu.Add(cx.Ceoffcient, cx.Value);
- }
- var results = spDb.PerformanceItems.Where<PerformanceItem>(p => p.CalMonthId == calMonth.Id && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") && p.BasePoint > 0.0);
- #region 循环计算
- int iCount = 0;
- double d = 0.0;
- var retList = results.ToList();
- foreach (var item in retList)
- {
- string strCaseCeoffcient = item.CaseCoefficient;
- if (string.IsNullOrEmpty(strCaseCeoffcient))
- {
- strCaseCeoffcient = "B";
- }
- #region 严重延期降系数
- if (item.isDanger() && string.IsNullOrEmpty(item.OverDueMemo))
- {
- switch (item.CaseCoefficient)
- {
- case "S":
- strCaseCeoffcient = "A";
- break;
- case "A":
- strCaseCeoffcient = "B";
- break;
- case "B":
- strCaseCeoffcient = "C";
- break;
- case "C":
- strCaseCeoffcient = "D";
- break;
- }
- }
- #endregion
- switch (strCaseCeoffcient)
- {
- case "S":
- if(item.Type == "专案")
- {
- retObj.S += item.BasePoint.Value;
- }
- else
- {
- retObj.S += 1;
- }
-
- break;
- case "A":
- if (item.Type == "专案")
- {
- retObj.A += item.BasePoint.Value;
- }
- else
- {
- retObj.A += 1;
- }
- break;
- case "B":
- if (item.Type == "专案")
- {
- retObj.B += item.BasePoint.Value;
- }
- else
- {
- retObj.B += 1;
- }
- break;
- case "C":
- if (item.Type == "专案")
- {
- retObj.C += item.BasePoint.Value;
- }
- else
- {
- retObj.C += 1;
- }
- break;
- case "D":
- if (item.Type == "专案")
- {
- retObj.D += item.BasePoint.Value;
- }
- else
- {
- retObj.D += 1;
- }
- break;
- default:
- if (item.Type == "专案")
- {
- retObj.B += item.BasePoint.Value;
- }
- else
- {
- retObj.B += 1;
- }
- break;
- }
- if (CaseXiShu.ContainsKey(strCaseCeoffcient))
- {
- d += CaseXiShu[strCaseCeoffcient];
- iCount += 1;
- }
- }
- #endregion
- retObj.NanduXS = d / (double)iCount;
-
- return retObj;
-
- }
- public List<string> GetFeedbackString(int itemId)
- {
- PerformanceItem item = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.Id == itemId);
- if(item != null)
- {
- return Utility.Utility.GetFeedbackMemos(item, Context.BasePointRules.ToList());
- }
- return new List<string>();
- }
- private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
- {
- var retList = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
- if (userid != null)
- {
- retList = retList.Where(s => s.StaffId == userid);
- }
- var retData2 = retList.GroupBy(s => new { s.CalMonthId, s.StaffId, s.jxType })
- .Select(g => new
- {
- StaffId = g.Key.StaffId,
- CalMonthId = g.Key.CalMonthId,
- jxType = g.Key.jxType,
- FinianlPoint = g.Sum(s => s.FinianlPoint),
- totalBasePoint = g.Sum(s => s.totalBasePoint),
- totalActuallyPoint = g.Sum(s => s.totalActuallyPoint)
- });
- List<StaffStatistics> temList = new List<StaffStatistics>();
- foreach (var key in retData2)
- {
- temList.Add(new StaffStatistics()
- {
- StaffId = key.StaffId,
- CalMonthId = key.CalMonthId,
- jxType = key.jxType,
- totalBasePoint = key.totalBasePoint,
- totalActuallyPoint = key.totalActuallyPoint,
- FinianlPoint = key.FinianlPoint
- });
- }
- return temList;
- #region old code
- ////未归档,从绩效记录中统计数据
- //var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
- //if (userid != null)
- //{
- // results = Context.PerformanceItems.Where<PerformanceItem>(s =>
- // (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == userid).Count() > 0 || s.Reviewer.Id == userid)
- // && s.CalMonth.Id == calMonth.Id);
- //}
- //List<PerformanceItem> ItemList = results
- // .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
- // .Include(pi => pi.Reviewer).ThenInclude(p=>p.StaffGrade)
- // .Include(pi => pi.Customer)
- // .OrderByDescending(o => o.Id)
- // .ToList<PerformanceItem>();
- //List<StaffStatistics> retList = new List<StaffStatistics>();
- //List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
- //var Rules = Context.BasePointRules.ToList();
- //foreach (PerformanceItem item in ItemList)
- //{
- // //if (item.BasePoint == null)
- // //{
- // if (item.AgentFeedbackMemo != "特殊点数申诉")
- // {
- // Utility.Utility.CalBasePoint(item, Rules);
-
- // Context.SaveChanges();
- // }
- // //}
- // if (item.BasePoint != null && item.BasePoint.Value > 0)
- // {
- // double doPersonBasePoint = item.BasePoint.Value;
- // List<StaffStatistics> itemStatistics = _calItemJX(calMonth, verifyCoefficients, item,Context);
- // List<StaffStatistics> temItemStatics;
- // if (userid != null)
- // {
- // temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
- // }
- // else
- // {
- // temItemStatics = itemStatistics;
- // }
- // foreach (StaffStatistics retUserValue in temItemStatics)
- // {
- // var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
- // if (temValue != null)
- // {
- // temValue.totalBasePoint += retUserValue.totalBasePoint;
- // temValue.totalActuallyPoint += retUserValue.totalActuallyPoint;
- // }
- // else
- // {
- // retList.Add(retUserValue);
- // }
- // }
- // }
- //}
- //if (userid != null)
- //{
- // retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
- //}
- //return retList;
- #endregion
- }
- private void _RefreshBasePoint()
- {
- spDbContext spDb = new spDbContext();
- var lstItem = spDb.PerformanceItems.Include(p => p.Customer).Where(p => p.CalMonth.Status != 4).ToList();
- var rules = spDb.BasePointRules.ToList();
- foreach (var item in lstItem)
- {
- if (item.AgentFeedbackMemo != "特殊点数申诉")
- {
- Utility.Utility.CalBasePoint(item, rules);
- if(item.BasePoint > 0)
- {
- _calItemJX(item);
- }
- spDb.SaveChanges();
- }
- }
- }
- public ApiSaveResponse RefreshBasePoint()
- {
- System.Threading.Thread t = new Thread(_RefreshBasePoint);
- t.Start();
- return new ApiSaveResponse() {
- Success = true
- };
- }
- public ApiSaveResponse RefreshFromIPEasyById(int itemId)
- {
- var Item = Context.PerformanceItems.Include(p=>p.Customer).Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).FirstOrDefault(p => p.Id == itemId);
- if (Item != null)
- {
- new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
- }
- Utility.Utility.CalBasePoint(Item, Context.BasePointRules.ToList());
- if(Item.BasePoint > 0)
- {
- _calItemJX(Item);
- }
- Context.SaveChanges();
- return new ApiSaveResponse()
- {
- Success = true
- };
- }
- public ApiSaveResponse RefreshFromIPEasy_Batch(int type)
- {
- new Job.UpdateJXDataFromIPEasyJob().RefreshFromIPEasy(type);
- return new ApiSaveResponse()
- {
- Success = true
- };
- }
- public ApiSaveResponse RefreshFromIPEasy(string CaseNo,string DoItem,string caseStage)
- {
- var Item = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault(p=>p.CaseNo == CaseNo && p.DoItem == DoItem && p.CaseStage == caseStage);
- if(Item != null)
- {
- new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item,Context);
- }
- return new ApiSaveResponse()
- {
- Success = true
- };
- }
- public ApiSaveResponse CompareExcel2DB()
- {
- System.Threading.Thread t = new Thread(new ThreadStart(_CompareExcel2DB));
- t.Start();
-
- return new ApiSaveResponse()
- {
- Success = true
- };
- }
- public FileProcessTask CurrentData2Excel()
- {
-
- CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Status == 0);
- if (calMonth != null)
- {
- var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
- var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
- var filePath = Path.Combine(attachfileSavePath, filename);
- var fileTask = new FileProcessTask()
- {
- Id = Guid.NewGuid().ToString(),
- FileName = filename,
- FilePath = filePath,
- Processed = 0
- };
- fileTaskService.Add(fileTask);
- System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(Export2ExcelThread));
- t.Start(fileTask);
- return fileTask;
- }
- return null;
-
- }
-
- private void Export2ExcelThread(object attfile)
- {
- FileProcessTask file = (FileProcessTask)attfile;
- spDbContext spDb = new spDbContext();
- List<PerformanceItem> items = spDb.PerformanceItems
- .Include(p => p.Reviewer).ThenInclude(p => p.StaffGrade)
- .Include(p=>p.PreOastaff)
- .Include(p => p.Customer)
- .Include(p => p.CalMonth)
- .Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
- .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
- DataTable dt = new DataTable();
- #region 栏位名称
- dt.Columns.Add("我方文号",typeof(string));
- dt.Columns.Add("申请类型", typeof(string));
- dt.Columns.Add("业务类型", typeof(string));
- dt.Columns.Add("备注(填表注意事项)", typeof(string));
- dt.Columns.Add("处理事项", typeof(string));
- dt.Columns.Add("案件阶段", typeof(string));
- dt.Columns.Add("案件系数", typeof(string));
- dt.Columns.Add("处理事项系数", typeof(string));
- dt.Columns.Add("前一次OA处理事项系数", typeof(string));
- dt.Columns.Add("前一次OA处理人", typeof(string));
- dt.Columns.Add("处理人等级", typeof(string));
- dt.Columns.Add("基本点数", typeof(string));
- dt.Columns.Add("核稿系数", typeof(string));
- dt.Columns.Add("核稿绩效", typeof(string));
- dt.Columns.Add("处理人", typeof(string));
- dt.Columns.Add("核稿人", typeof(string));
- dt.Columns.Add("客户名称", typeof(string));
- dt.Columns.Add("申请人", typeof(string));
- dt.Columns.Add("处理事项完成日", typeof(string));
- dt.Columns.Add("定稿日", typeof(string));
- dt.Columns.Add("返稿日", typeof(string));
- dt.Columns.Add("案件类型", typeof(string));
- dt.Columns.Add("案件状态", typeof(string));
- dt.Columns.Add("处理事项备注", typeof(string));
- dt.Columns.Add("处理状态", typeof(string));
- dt.Columns.Add("案件名称", typeof(string));
- dt.Columns.Add("委案日期", typeof(string));
- dt.Columns.Add("客户期限", typeof(string));
- dt.Columns.Add("内部期限", typeof(string));
- dt.Columns.Add("初稿日", typeof(string));
- dt.Columns.Add("翻译字数", typeof(string));
- dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因", typeof(string));
- dt.Columns.Add("绩效类型", typeof(string));
- dt.Columns.Add("案件备注", typeof(string));
- dt.Columns.Add("处理人绩效系数", typeof(string));
- dt.Columns.Add("系统核算绩效", typeof(string));
- dt.Columns.Add("实际处理人", typeof(string));
- #endregion
- var verifyCeoffients = spDb.VerifyCoefficients.ToList();
- var Rules = spDb.BasePointRules.ToList();
- file.Size = items.Count;
- foreach(var p in items)
- {
-
- List<ItemStaff> temItemStaffs = p.ItemStaffs.ToList();
- string strCaseMemo = "";
- string strHandler = "";
-
- temItemStaffs = new List<ItemStaff>();
- foreach (var iStaff in p.ItemStaffs)
- {
- strHandler = string.IsNullOrEmpty(strHandler)?iStaff.DoPerson.Name : $"{strHandler},{iStaff.DoPerson.Name}";
- if (iStaff.DoPerson.Status == "试用期")
- {
- strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}在试用期" : $"{strCaseMemo},{iStaff.DoPerson.Name}在试用期";
- }
- else
- {
- if(!iStaff.DoPerson.IsCalPerformsnce )
- strCaseMemo = string.IsNullOrEmpty(strCaseMemo) ? $"{iStaff.DoPerson.Name}不计算绩效" : $"{strCaseMemo},{iStaff.DoPerson.Name}不计算绩效";
- }
- if(iStaff.DoPersonId == p.ReviewerId)
- {
- strCaseMemo = String.IsNullOrEmpty(strCaseMemo) ? "核稿人与处理人相同" : $"{strCaseMemo},核稿人与处理人相同";
- }
- }
-
- var staffStatics = spDb.StaffStatistics.Include(s=>s.Staff).ThenInclude(s=>s.StaffGrade).Where(s=>s.ItemId == p.Id && s.jxType.Contains("处理"));
- var reviewStatic = spDb.StaffStatistics.Include(s => s.Staff).ThenInclude(s => s.StaffGrade).FirstOrDefault(s => s.ItemId == p.Id && s.jxType.Contains("审核"));
- foreach (var iStaff in staffStatics.ToList())
- {
- DataRow row = dt.NewRow();
- row["我方文号"] = p.CaseNo;
- row["申请类型"] = p.ApplicationType;
- row["实际处理人"] = strHandler;
- if(p.ApplicationName != null && p.ApplicationName.Contains("OPPO") && p.ApplicationType == "实用新型")
- {
- row["申请类型"] = "发明";
- row["案件备注"] = $"{row["案件备注"]}\r\nOPPO案件实用新型修改为发明】";
- }
- row["处理事项"] = p.DoItem;
- row["业务类型"] = p.BusinessType;
- row["备注(填表注意事项)"] = p.AgentFeedbackMemo;
- if(p.Type == "专案")
- {
- row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]}【主管给定点数】专案";
- row["处理事项"] = "提出报告";
- }
- if(p.ItemStaffs.Count() > 1)
- {
- row["备注(填表注意事项)"] = $"{row["备注(填表注意事项)"]},{strHandler}合写";
- }
-
- row["案件阶段"] = p.CaseStage;
-
- row["案件系数"] = p.CaseCoefficient;
- if(p.isDanger() && string.IsNullOrEmpty(p.OverDueMemo) && p.Type =="新申请")
- {
- switch (p.CaseCoefficient)
- {
- case "S":
- row["案件系数"] = "A";
- break;
- case "A":
- row["案件系数"] = "B";
- break;
- case "B":
- row["案件系数"] = "C";
- break;
- case "C":
- row["案件系数"] = "D";
- break;
- }
- row["案件备注"] = $"{row["案件备注"]}\r\n严重延期降系数【{p.CaseCoefficient}->{row["案件系数"]}】";
- }
- row["处理事项系数"] = p.DoItemCoefficient;
- row["前一次OA处理事项系数"] = "";
- row["前一次OA处理人"] = p.PreOastaff?.Name;
- row["处理人"] = iStaff.Staff.Name;
- row["基本点数"] = iStaff.totalBasePoint;
- row["处理人绩效系数"] = iStaff.Staff.StaffGrade.Grade;
- if(reviewStatic != null)
- {
- row["核稿人"] = reviewStatic.Staff.Name;
- }
-
- row["客户名称"] = p.Customer?.Name;
- row["申请人"] = p.ApplicationName;
- row["处理事项完成日"] = p.FinishedDate?.ToString("yyyy-MM-dd");
- row["定稿日"] = p.FinalizationDate?.ToString("yyyy-MM-dd");
- row["返稿日"] = p.ReturnDate?.ToString("yyyy-MM-dd");
- row["案件类型"] = p.CaseType;
- row["案件状态"] = p.CaseState;
- row["处理事项备注"] = p.DoItemMemo;
- row["处理状态"] = p.DoItemState;
- row["案件名称"] = p.CaseName;
- row["委案日期"] = p.EntrustingDate?.ToString("yyyy-MM-dd");
- row["客户期限"] = p.CustomerLimitDate?.ToString("yyyy-MM-dd");
- row["内部期限"] = p.InternalDate?.ToString("yyyy-MM-dd");
- row["初稿日"] = p.FirstDraftDate?.ToString("yyyy-MM-dd");
- row["翻译字数"] = p.WordCount;
- row["备注(发文严重超期是否属客观原因,若为否,请填写原因"] = p.OverDueMemo;
- row["绩效类型"] = p.Type;
- row["案件备注"] = $"{p.CaseMemo}\r\n{row["案件备注"]}";
- if (!string.IsNullOrEmpty(strCaseMemo))
- {
- row["案件备注"] = $"{strCaseMemo}\r\n{row["案件备注"]}";
- }
- dt.Rows.Add(row);
- }
-
- file.Processed += 1;
-
- }
- NPOIExcel.DataTableToExcel(dt, file.FilePath);
- file.Finished = true;
- }
- private void _CompareExcel2DB()
- {
-
- DataTable excelDT = NPOIExcel.ExcelToDataTable("c:\\temp\\220112-工程师绩效总表-12月-v2F.xlsx", true, true, 0,2);
- DataTable retTable = new DataTable();
- retTable.Columns.Add("我方文号");
- retTable.Columns.Add("申请类型");
- retTable.Columns.Add("业务类型");
- retTable.Columns.Add("备注(填表注意事项)");
- retTable.Columns.Add("备注(填表注意事项)【系统】");
- retTable.Columns.Add("处理事项");
- retTable.Columns.Add("处理事项【系统】");
- retTable.Columns.Add("案件阶段");
- retTable.Columns.Add("案件阶段【系统】");
- retTable.Columns.Add("案件系数");
- retTable.Columns.Add("案件系数【系统】");
- retTable.Columns.Add("处理事项系数");
- retTable.Columns.Add("处理事项系数【系统】");
- retTable.Columns.Add("处理人等级");
- retTable.Columns.Add("处理人等级【系统】");
- retTable.Columns.Add("处理人系数");
- retTable.Columns.Add("处理人系数【系统】");
- retTable.Columns.Add("基本点数");
- retTable.Columns.Add("基本点数【系统】");
- retTable.Columns.Add("核稿系数");
- retTable.Columns.Add("核稿系数【系统】");
- retTable.Columns.Add("核稿绩效");
- retTable.Columns.Add("核稿绩效【系统】");
- retTable.Columns.Add("处理人");
- retTable.Columns.Add("处理人【系统】");
- retTable.Columns.Add("核稿人");
- retTable.Columns.Add("核稿人【系统】");
- retTable.Columns.Add("严重超期备注原因");
- retTable.Columns.Add("严重超期备注原因【系统】");
- retTable.Columns.Add("是否一致");
- retTable.Columns.Add("不一致原因");
- spDbContext spDb = new spDbContext();
- List<PerformanceItem> items = spDb.PerformanceItems
- .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
- .Include(p=>p.Customer)
- .Include(p=>p.ItemStaffs).ThenInclude(s=>s.DoPerson).ThenInclude(s=>s.StaffGrade)
- .Where(p=>p.CalMonth.Status ==0 && !p.CaseNo.StartsWith("J")).OrderBy(p=>p.CaseNo).ThenBy(p=>p.DoItem).ToList();
- excelDT.DefaultView.Sort = "我方文号,处理事项";
- DataTable temDt = excelDT.DefaultView.ToTable();
- int iTable = 0;
- int iList = 0;
- CalMonth calMonth = spDb.CalMonths.FirstOrDefault(p=>p.Status ==0);
- var verifyCoefficients = spDb.VerifyCoefficients.ToList();
- var Rules = spDb.BasePointRules.ToList();
- while (iTable < temDt.Rows.Count && iList < items.Count)
- {
- System.Diagnostics.Debug.WriteLine($"Excel:{iTable}/{temDt.Rows.Count}\t{iList}/{items.Count}");
- DataRow row = temDt.Rows[iTable];
- PerformanceItem item = items[iList];
- if(row["我方文号"].ToString() == item.CaseNo && (row["处理事项"].ToString() == item.DoItem || (row["备注(填表注意事项)"].ToString()== "发明一次OA授权" && item.DoItem == "发明一次OA授权")))
- {
- var temRow = retTable.NewRow();
- int iBegin = iTable;
- int iEnd = iTable;
- #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
- if (iEnd < temDt.Rows.Count - 1)
- {
- while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
- temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
- {
- iEnd++;
- }
- }
- temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
- temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
- temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
- temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
- temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
- temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
- temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
- temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
- temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
- temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
- temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
- temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
- temRow["处理人"] = temDt.Rows[iTable]["处理人"];
-
- temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
- for (int i = iBegin; i <= iEnd; i++)
- {
- temRow["备注(填表注意事项)"] =string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ?temDt.Rows[i]["备注(填表注意事项)"] :$"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
- //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
- temRow["核稿系数"] = string.IsNullOrEmpty(temRow["核稿系数"].ToString()) ? temDt.Rows[i]["核稿系数"] : $"{temRow["核稿系数"]},{temDt.Rows[i]["核稿系数"]}";
- if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
- {
- temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
- temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
- }
- temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
- }
- iTable = iEnd;
- #endregion
- Utility.Utility.CalBasePoint(item, Rules);
- List<StaffStatistics> retPoints = new List<StaffStatistics>();
- try
- {
- retPoints = _calItemJX( verifyCoefficients, item, spDb);
- }
- catch { }
-
-
- temRow["案件阶段【系统】"] = item.CaseStage;
- temRow["案件系数【系统】"] = item.CaseCoefficient;
- temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
- temRow["核稿人【系统】"] = item.Reviewer?.Name;
- temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
- temRow["基本点数【系统】"] = item.BasePoint?.ToString();
- temRow["严重超期备注原因"] = item.OverDueMemo;
- if (retPoints != null && retPoints.Count > 0)
- {
- temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId && p.jxType.Contains("审核"))?.totalBasePoint;
- foreach (var itemStaff in item.ItemStaffs)
- {
- //temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
- temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
- temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
- if (item.ReviewerId != null)
- {
- #region 取审核人等级审核等级系数
- VerifyCoefficient vcoefficient
- = verifyCoefficients.Where<VerifyCoefficient>(v =>
- v.CheckerId == item.Reviewer.StaffGradeId
- && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
- .FirstOrDefault<VerifyCoefficient>();
- #endregion
- if (vcoefficient != null)
- {
- temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
- }
- }
- }
- }
- temRow["是否一致"] = "";
- temRow["不一致原因"] = "";
- if(temRow["案件阶段【系统】"].ToString().Trim() != temRow["案件阶段"].ToString().Trim())
- {
- temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件阶段" : $"{temRow["不一致原因"]},案件阶段";
- }
- if (temRow["案件系数【系统】"].ToString().Trim() != temRow["案件系数"].ToString().Trim())
- {
- temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "案件系数" : $"{temRow["不一致原因"]},案件系数";
- }
- if (temRow["处理事项系数【系统】"].ToString().Trim() != temRow["处理事项系数"].ToString().Trim())
- {
- temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "处理事项系数" : $"{temRow["不一致原因"]},处理事项系数";
- }
- if (temRow["核稿人【系统】"].ToString().Trim() != temRow["核稿人"].ToString().Trim())
- {
- temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "核稿人" : $"{temRow["不一致原因"]},核稿人";
- }
- if (temRow["基本点数【系统】"].ToString().Trim() != temRow["基本点数"].ToString().Trim())
- {
- temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "基本点数" : $"{temRow["不一致原因"]},基本点数";
- }
- if (temRow["严重超期备注原因【系统】"].ToString().Trim() != temRow["严重超期备注原因"].ToString().Trim())
- {
- temRow["不一致原因"] = string.IsNullOrEmpty(temRow["不一致原因"].ToString()) ? "严重超期备注原因" : $"{temRow["不一致原因"]},严重超期备注原因";
- }
- if (!string.IsNullOrEmpty(temRow["不一致原因"].ToString()))
- {
- temRow["是否一致"] = "不一致";
- }
- retTable.Rows.Add(temRow);
- iTable++;
- iList++;
- }
- else
- {
- string strDT = $"{row["我方文号"]}-{row["处理事项"]}";
- string strList = $"{item.CaseNo}-{item.DoItem}";
- if (strDT.CompareTo(strList) > 0)
- {
- var temRow = retTable.NewRow();
- Utility.Utility.CalBasePoint(item, Rules);
- List<StaffStatistics> retPoints = new List<StaffStatistics>();
- try
- {
- retPoints = _calItemJX( verifyCoefficients, item, spDb);
- }
- catch { }
- temRow["我方文号"] = item.CaseNo;
- temRow["处理事项"] = item.DoItem;
- temRow["申请类型"] = item.ApplicationType;
- temRow["业务类型"] = item.BusinessType;
- temRow["案件阶段【系统】"] = item.CaseStage;
- temRow["案件系数【系统】"] = item.CaseCoefficient;
- temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
- temRow["核稿人【系统】"] = item.Reviewer?.Name;
- temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
- temRow["基本点数【系统】"] = item.BasePoint?.ToString();
- temRow["严重超期备注原因"] = item.OverDueMemo;
- if (item.ReviewerId != null)
- {
- temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
- }
- foreach (var itemStaff in item.ItemStaffs)
- {
- //if (itemStaff.DoPerson.Status != "试用期")
- //{
- // if (retPoints != null && retPoints.Count > 0)
- // {
- // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
- // }
- //}
- temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
- temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
- temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
- if (item.ReviewerId != null)
- {
- #region 取审核人等级审核等级系数
- VerifyCoefficient vcoefficient
- = verifyCoefficients.Where<VerifyCoefficient>(v =>
- v.CheckerId == item.Reviewer.StaffGradeId
- && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
- .FirstOrDefault<VerifyCoefficient>();
- #endregion
- if (vcoefficient != null)
- {
- temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
- }
- }
- }
- temRow["是否一致"] = "不一致";
- temRow["不一致原因"] = "Excel中没有,系统中有";
- retTable.Rows.Add(temRow);
- iList++;
- }
- else
- {
- var temRow = retTable.NewRow();
- int iBegin = iTable;
- int iEnd = iTable;
- #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
- if (iEnd < temDt.Rows.Count - 1)
- {
- while (temDt.Rows[iEnd]["我方文号"].ToString() == temDt.Rows[iEnd + 1]["我方文号"].ToString() &&
- temDt.Rows[iEnd]["处理事项"].ToString() == temDt.Rows[iEnd + 1]["处理事项"].ToString())
- {
- iEnd++;
- }
- }
- temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
- temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
- temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
- temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
- temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
- temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
- temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
- temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
- temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
- temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
- temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
- temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
- temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
- temRow["处理人"] = temDt.Rows[iTable]["处理人"];
-
- temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
- for (int i = iBegin+1; i <= iEnd; i++)
- {
- temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
- //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
- temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
- if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
- {
- temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
- temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
- }
- temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"]}";
- }
- iTable = iEnd;
- #endregion
- temRow["是否一致"] = "不一致";
- temRow["不一致原因"] = "系统中没有,Excel中有";
- retTable.Rows.Add(temRow);
- iTable++;
- }
- }
- }
- if (iList <=items.Count)
- {
- while(iList <items.Count){
- var item = items[iList];
- var temRow = retTable.NewRow();
- Utility.Utility.CalBasePoint(item, Rules);
- List<StaffStatistics> retPoints = new List<StaffStatistics>();
- try
- {
- retPoints = _calItemJX( verifyCoefficients, item, spDb);
- }
- catch { }
- temRow["我方文号"] = item.CaseNo;
- temRow["处理事项"] = item.DoItem;
- temRow["申请类型"] = item.ApplicationType;
- temRow["业务类型"] = item.BusinessType;
- temRow["案件阶段【系统】"] = item.CaseStage;
- temRow["案件系数【系统】"] = item.CaseCoefficient;
- temRow["处理事项系数【系统】"] = item.DoItemCoefficient;
- temRow["核稿人【系统】"] = item.Reviewer?.Name;
- temRow["备注(填表注意事项)【系统】"] = item.AgentFeedbackMemo;
- temRow["基本点数【系统】"] = "";// item.BasePoint?.ToString();
- temRow["严重超期备注原因"] = item.OverDueMemo;
- if (item.ReviewerId != null)
- {
- temRow["核稿绩效【系统】"] = retPoints.FirstOrDefault(p => p.StaffId == item.ReviewerId)?.totalBasePoint;
- }
- foreach (var itemStaff in item.ItemStaffs)
- {
- //if (itemStaff.DoPerson.Status != "试用期")
- //{
- // if (retPoints != null && retPoints.Count > 0)
- // {
- // temRow["基本点数【系统】"] = string.IsNullOrEmpty(temRow["基本点数【系统】"].ToString()) ? retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint.ToString() : $"{temRow["基本点数【系统】"]},{retPoints.FirstOrDefault(p => p.StaffId == itemStaff.DoPersonId)?.totalBasePoint}";
- // }
- //}
- temRow["处理人等级【系统】"] = string.IsNullOrEmpty(temRow["处理人等级【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Grade : $"{temRow["处理人等级【系统】"]},{itemStaff.DoPerson.StaffGrade?.Grade }";
- temRow["处理人系数【系统】"] = string.IsNullOrEmpty(temRow["处理人系数【系统】"].ToString()) ? itemStaff.DoPerson.StaffGrade?.Coefficient : $"{temRow["处理人系数【系统】"]},{itemStaff.DoPerson.StaffGrade?.Coefficient}";
- temRow["处理人【系统】"] = string.IsNullOrEmpty(temRow["处理人【系统】"].ToString()) ? itemStaff.DoPerson.Name : $"{temRow["处理人【系统】"]},{itemStaff.DoPerson.Name}";
- if (item.ReviewerId != null)
- {
- #region 取审核人等级审核等级系数
- VerifyCoefficient vcoefficient
- = verifyCoefficients.Where<VerifyCoefficient>(v =>
- v.CheckerId == item.Reviewer.StaffGradeId
- && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
- .FirstOrDefault<VerifyCoefficient>();
- #endregion
- if (vcoefficient != null)
- {
- temRow["核稿系数【系统】"] = string.IsNullOrEmpty(temRow["核稿系数【系统】"].ToString()) ? vcoefficient.Coefficient.ToString() : $"{temRow["核稿系数【系统】"]},{vcoefficient.Coefficient}";
- }
- }
- }
- temRow["是否一致"] = "不一致";
- temRow["不一致原因"] = "Excel中没有,系统中有";
- iList++;
- retTable.Rows.Add(temRow);
- }
- }
- else
- {
- while (iTable < temDt.Rows.Count)
- {
- var temRow = retTable.NewRow();
- int iBegin = iTable;
- int iEnd = iTable;
- #region 判断是否有重复记录,并将Excel表中的记录生成临时表中的一行记录
- while (temDt.Rows[iTable]["我方文号"].ToString() == temDt.Rows[iTable + 1]["我方文号"].ToString() &&
- temDt.Rows[iTable]["处理事项"].ToString() == temDt.Rows[iTable + 1]["处理事项"].ToString())
- {
- iEnd++;
- }
- temRow["我方文号"] = temDt.Rows[iTable]["我方文号"];
- temRow["处理事项"] = temDt.Rows[iTable]["处理事项"];
- temRow["申请类型"] = temDt.Rows[iTable]["申请类型"];
- temRow["业务类型"] = temDt.Rows[iTable]["业务类型"];
- temRow["案件阶段"] = temDt.Rows[iTable]["案件阶段"];
- temRow["案件系数"] = temDt.Rows[iTable]["案件系数"];
- temRow["处理事项系数"] = temDt.Rows[iTable]["处理事项系数"];
- temRow["核稿人"] = temDt.Rows[iTable]["核稿人"];
- temRow["备注(填表注意事项)"] = temDt.Rows[iTable]["备注(填表注意事项)"];
- temRow["处理人等级"] = temDt.Rows[iTable]["处理人等级"];
- temRow["基本点数"] = temDt.Rows[iTable]["基本点数"];
- temRow["核稿系数"] = temDt.Rows[iTable]["核稿系数"];
- temRow["核稿绩效"] = temDt.Rows[iTable]["核稿绩效"];
- temRow["处理人"] = temDt.Rows[iTable]["处理人"];
- temRow["严重超期备注原因"] = temDt.Rows[iTable]["备注(发文严重超期是否属客观原因,若为否,请填写原因)"];
- for (int i = iBegin + 1; i <= iEnd; i++)
- {
- temRow["备注(填表注意事项)"] = string.IsNullOrEmpty(temRow["备注(填表注意事项)"].ToString()) ? temDt.Rows[i]["备注(填表注意事项)"] : $"{temRow["备注(填表注意事项)"]}{temDt.Rows[i]["备注(填表注意事项)"]}";
- //temRow["基本点数"] = string.IsNullOrEmpty(temRow["基本点数"].ToString()) ? temDt.Rows[i]["基本点数"] : $"{temRow["基本点数"]},{temDt.Rows[i]["基本点数"]}";
- temRow["核稿绩效"] = string.IsNullOrEmpty(temRow["核稿绩效"].ToString()) ? temDt.Rows[i]["核稿绩效"] : $"{temRow["核稿绩效"]},{temDt.Rows[i]["核稿绩效"]}";
- if (!temRow["处理人"].ToString().Contains(temDt.Rows[i]["处理人"].ToString()))
- {
- temRow["处理人"] = string.IsNullOrEmpty(temRow["处理人"].ToString()) ? temDt.Rows[i]["处理人"] : $"{temRow["处理人"]},{temDt.Rows[i]["处理人"]}";
- temRow["处理人等级"] = string.IsNullOrEmpty(temRow["处理人等级"].ToString()) ? temDt.Rows[i]["处理人等级"] : $"{temRow["处理人等级"]},{temDt.Rows[i]["处理人等级"]}";
- }
- temRow["严重超期备注原因"] = string.IsNullOrEmpty(temRow["严重超期备注原因"].ToString()) ? temDt.Rows[i]["严重超期备注原因"] : $"{temRow["严重超期备注原因"]}{temDt.Rows[i]["严重超期备注原因"]}";
- }
- iTable = iEnd;
- #endregion
- temRow["是否一致"] = "不一致";
- temRow["不一致原因"] = "系统中没有,Excel中有";
- retTable.Rows.Add(temRow);
- iTable++;
- }
- }
- NPOIExcel.DataTableToExcel(retTable, "c:\\temp\\202112-系统线下绩效记录对比.xlsx");
-
- }
-
- public List<StaffStatistics> CalItemJX(int itemid)
- {
- var Item = Context.PerformanceItems.Include(p=>p.CalMonth).FirstOrDefault(p=>p.Id == itemid);
- List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
-
- return _calItemJX(verifyCoefficients,Item,Context);
- }
- private void _calItemJX(PerformanceItem Item)
- {
- List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
- var jxList = _calItemJX( verifyCoefficients, Item, Context);
- var oldJxList = Context.StaffStatistics.Where(p=>p.ItemId == Item.Id);
- Context.StaffStatistics.RemoveRange(oldJxList);
- foreach (var jx in jxList)
- {
- if(jx.totalBasePoint == 0)
- {
- return;
- }
- jx.ItemId = Item.Id;
- Context.StaffStatistics.Add(jx);
- Context.SaveChanges();
- }
- }
- private List<StaffStatistics> _calItemJX( List<VerifyCoefficient> verifyCoefficients, PerformanceItem item,spDbContext spDb)
- {
-
- System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
-
- List<StaffStatistics> itemStatistics = new List<StaffStatistics>();
- if (item.ReviewerId != null)
- {
- item.Reviewer = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == item.ReviewerId);
- //spDb.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
- }
- List<ItemStaff> temIStaffs = new List<ItemStaff>();
- int syqUsers = 0;
- foreach(var itemStaff in item.ItemStaffs)
- {
- if (itemStaff.DoPerson == null)
- {
- itemStaff.DoPerson = spDb.Staffs.Include(s => s.StaffGrade).FirstOrDefault(p => p.Id == itemStaff.DoPersonId);
- }
- if(itemStaff.DoPerson.Status == "试用期" || !itemStaff.DoPerson.IsCalPerformsnce )
- {
- syqUsers += 1;
- }
- else
- {
- temIStaffs.Add(itemStaff);
- }
- }
- if(syqUsers == item.ItemStaffs.Count)
- {
- if(item.Reviewer != null)
- {
- temIStaffs.Add(new ItemStaff() { DoPersonId = item.ReviewerId.Value, ItemId = item.Id });
- }
-
- }
- bool isPJFP = true;
- double total = temIStaffs.Count();
- if (temIStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
- {
- total = temIStaffs.Select(i => i.PerformancePoint.Value).Sum();
- isPJFP = false;
- }
- foreach (ItemStaff itemStaff in temIStaffs)
- {
- if(itemStaff.DoPerson == null)
- {
- itemStaff.DoPerson = spDb.Staffs.Include(s=>s.StaffGrade).FirstOrDefault(p=>p.Id==itemStaff.DoPersonId);
- }
- //spDb.Entry(itemStaff).Reference(b => b.DoPerson).Load();
- //spDb.Entry(itemStaff.DoPerson).Reference(b => b.StaffGrade).Load();
- #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
- if (item.ReviewerId != null && item.Type != "专案" &&
- temIStaffs.FirstOrDefault(s=>s.DoPersonId == item.ReviewerId) == null)
- {
- #region 取审核人等级审核等级系数
- VerifyCoefficient vcoefficient
- = verifyCoefficients.Where<VerifyCoefficient>(v =>
- v.CheckerId == item.Reviewer.StaffGradeId
- && v.DoPersonId == itemStaff.DoPerson.StaffGradeId)
- .FirstOrDefault<VerifyCoefficient>();
- #endregion
- if (vcoefficient != null)
- {
- double reviewerBasePoint = item.BasePoint.Value * vcoefficient.Coefficient;
- string temJxType = $"{item.Type}审核";
- var temReviewerStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == item.ReviewerId && s.jxType == temJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
- if (temReviewerStatic != null)
- {
- temReviewerStatic.totalBasePoint += reviewerBasePoint;
- temReviewerStatic.totalActuallyPoint += reviewerBasePoint;
- }
- else
- {
- if (itemStaff.DoPerson.Status != "试用期" && item.Reviewer.IsCalPerformsnce ) //判断是否在职
- {
- temReviewerStatic = new StaffStatistics()
- {
-
- CalMonthId = item.CalMonthId,
- StaffId = item.ReviewerId.Value,
- totalBasePoint = reviewerBasePoint,
- totalActuallyPoint = reviewerBasePoint,
- jxType = temJxType
- };
- itemStatistics.Add(temReviewerStatic);
- }
- }
- }
- }
- #endregion
- #region 计算各处理人的绩效点数
- double handlerBasePoint;
- if (item.Type != "专案")
- {
- if (isPJFP)
- {
- handlerBasePoint = item.BasePoint.Value * 1.0 / total;
- }
- else
- {
- handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
- }
- }
- else
- {
- if (itemStaff.PerformancePoint == null)
- {
- if (isPJFP)
- {
- handlerBasePoint = item.BasePoint.Value * 1.0 / total;
- }
- else
- {
- handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
- }
- }
- else
- {
- if(item.ItemStaffs.Count ==1 && itemStaff .PerformancePoint == 0)
- {
- handlerBasePoint = item.BasePoint.Value;
- }
- else
- {
- handlerBasePoint = itemStaff.PerformancePoint.Value;
- }
-
- }
- }
- string handlerJxType = $"{item.Type}处理";
- var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == item.CalMonthId).FirstOrDefault();
- if (temStatic != null)
- {
- temStatic.totalBasePoint += handlerBasePoint;
- if (item.Type == "OA" || item.Type == "新申请")
- {
- temStatic.totalActuallyPoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
- }
- else
- {
- temStatic.totalActuallyPoint += handlerBasePoint;
- }
- }
- else
- {
- if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsCalPerformsnce)
- {
- if (item.Type == "OA" || item.Type == "新申请")
- {
- if (itemStaff.DoPerson.Status == "试用期" && item.Reviewer != null)
- {
- temStatic = new StaffStatistics()
- {
- CalMonthId = item.CalMonthId,
- StaffId = item.Reviewer.Id,
- totalActuallyPoint= handlerBasePoint * item.Reviewer.StaffGrade.Coefficient,
- totalBasePoint = handlerBasePoint,
- jxType = handlerJxType
- };
- itemStatistics.Add(temStatic);
- }
- else
- {
- itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s=>s.Id == itemStaff.DoPerson.StaffGradeId);
- temStatic = new StaffStatistics()
- {
- //CalMonth = calMonth,
- CalMonthId = item.CalMonthId,
- StaffId = itemStaff.DoPersonId,
- totalActuallyPoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
- totalBasePoint = handlerBasePoint,
- jxType = handlerJxType
- };
- itemStatistics.Add(temStatic);
- }
- }
- else
- {
- temStatic = new StaffStatistics()
- {
- //CalMonth = calMonth,
- CalMonthId = item.CalMonthId,
- StaffId = itemStaff.DoPersonId,
- totalBasePoint = handlerBasePoint,
- totalActuallyPoint = handlerBasePoint,
- jxType = handlerJxType
- };
- itemStatistics.Add(temStatic);
- }
- }
- }
- #endregion
- }
- return itemStatistics;
- }
- private void _CalJXPoint(CalMonth calMonth,spDbContext spDb)
- {
- NanduStatics gspjXS = DegreeOfDifficulty(calMonth,spDb);
- calMonth.NanduXS = gspjXS.NanduXS;
- calMonth.S = gspjXS.S;
- calMonth.A = gspjXS.A;
- calMonth.B = gspjXS.B;
- calMonth.C = gspjXS.C;
- calMonth.D = gspjXS.D;
- var retList = spDb.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id).ToList();
- #region 新申请处理+专案处理 奖励点数
- double jlPoint = 0;
- if (calMonth.S.HasValue)
- {
- jlPoint = jlPoint + (calMonth.S.Value * 1.5);
- }
- if (calMonth.A.HasValue)
- {
- jlPoint = jlPoint + (calMonth.A.Value * 0.5);
- }
- #endregion
- double? totalFPBLPoint = 0; //新申请处理+专案 分配比率总点数
- #region 难度系数
- IDictionary<int, NanduStatics> staffXiShu = new Dictionary<int, NanduStatics>();
- IDictionary<int, NanduStatics> ReivewerXiShu = new Dictionary<int, NanduStatics>();
- foreach (StaffStatistics ss in retList)
- {
- if (ss.jxType == "新申请处理" || ss.jxType == "专案处理")
- {
- #region 新申请处理+专案处理
- if (!staffXiShu.ContainsKey(ss.StaffId))
- {
- NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb);
- staffXiShu.Add(ss.StaffId, nandu);
- }
- ss.FinianlPoint = ss.totalActuallyPoint * staffXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
- totalFPBLPoint += ss.FinianlPoint;
- ss.NanduXS = staffXiShu[ss.StaffId].NanduXS;
- ss.S = staffXiShu[ss.StaffId].S;
- ss.A = staffXiShu[ss.StaffId].A;
- ss.B = staffXiShu[ss.StaffId].B;
- ss.C = staffXiShu[ss.StaffId].C;
- ss.D = staffXiShu[ss.StaffId].D;
- #endregion
- }
- else
- {
- if (ss.jxType == "新申请审核")
- {
- if (!ReivewerXiShu.ContainsKey(ss.StaffId))
- {
- NanduStatics nandu = PersonNanduStatics(calMonth, ss.StaffId,spDb, true);
- ReivewerXiShu.Add(ss.StaffId, nandu);
- }
- ss.FinianlPoint = ss.totalBasePoint * ReivewerXiShu[ss.StaffId].NanduXS / gspjXS.NanduXS;
- ss.NanduXS = ReivewerXiShu[ss.StaffId].NanduXS;
- ss.S = ReivewerXiShu[ss.StaffId].S;
- ss.A = ReivewerXiShu[ss.StaffId].A;
- ss.B = ReivewerXiShu[ss.StaffId].B;
- ss.C = ReivewerXiShu[ss.StaffId].C;
- ss.D = ReivewerXiShu[ss.StaffId].D;
- spDb.SaveChanges();
- }
- else
- {
- ss.FinianlPoint = ss.totalBasePoint;
- spDb.SaveChanges();
- }
- }
- }
- foreach (StaffStatistics ss in retList)
- {
- if (ss.jxType == "新申请处理" || ss.jxType == "专案处理")
- {
- ss.FinianlPoint = ss.FinianlPoint / totalFPBLPoint * (totalFPBLPoint + jlPoint);
- Context.SaveChanges();
- }
- }
- #endregion
- }
- public void CalJXPoint(int year, int month)
- {
- CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
- if (calMonth != null)
- {
- using (var t = Context.Database.BeginTransaction())
- {
- try
- {
- var result = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
- Context.StaffStatistics.RemoveRange(result);
- var itemList = Context.PerformanceItems.Include(s => s.ItemStaffs).
- Where(s => s.CalMonthId == calMonth.Id).ToList();
- var rules = Context.BasePointRules.ToList();
- foreach (var item in itemList)
- {
- Utility.Utility.CalBasePoint(item, rules);
- Context.SaveChanges();
- if (item.BasePoint > 0)
- {
- _calItemJX(item);
- }
- //_CalItemJX(item.Id);
- }
- _CalJXPoint(calMonth, Context);
- t.Commit();
- }
- catch (Exception ex)
- {
- t.Rollback();
- }
- }
- }
- }
- /// <summary>
- /// 新申请/专案:
- /// 调整点数 = 分配比例点数/分配比例点数之和*总点数
- /// 等级调整点数+项目组点数之和 = 基础点数 * 代理人等级系数 + 项目组案件调整点数
- /// 分配比例点数 = 个人平均难度系数 / 总平均难度系数 *(等级调整点数+项目组点数之和)
- /// 总点数=等级调整点数+项目组点数之和+奖励点数
- /// 奖励点数= S案数量*1.5 + A案数量 * 0.5
- /// 难度系数=(S案数量*2.5 + A案数量* 1.5 + B案数量*1.0 + C案数量*0.7+ D案数量*0.4) / 总案件数量
- /// 总案件数量= S案数量 + A案数量 + B案数量 + C案数量+ D案数量
- /// OA :
- /// 调整点数= 基础点数 * 等级系数
- /// 其他:
- /// 直接加和基础点数 不需要乘以系数
- /// </summary>
- /// <param name="year"></param>
- /// <param name="month"></param>
- /// <returns></returns>
- public ApiSaveResponse FinishedCalMonth(int year,int month)
- {
- CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
- if (calMonth != null || calMonth.Status !=4)
- {
-
- using (var t = Context.Database.BeginTransaction())
- {
- try
- {
- _CalJXPoint(calMonth, Context);
- calMonth.Status = 4;
- Context.SaveChanges();
- t.Commit();
- return new ApiSaveResponse()
- {
- Success = true
- };
- }
- catch (Exception ex)
- {
- t.Rollback();
- return new ApiSaveResponse()
- {
- Success = false,
- ErrorMessage = ex.Message
- };
- }
- }
- }
- else
- {
- return new ApiSaveResponse()
- {
- Success = false,
- ErrorMessage ="指定月份没有数据或者已归档!"
- };
- }
- }
- /// <summary>
- /// 计算指定用户,指定年月的绩效统计信息
- /// </summary>
- /// <param name="userid"></param>
- /// <param name="year"></param>
- /// <param name="month"></param>
- /// <returns></returns>
- public List<StaffStatistics> CalMyStatistics(int year,int month, int? userid=null)
- {
- //object retList;
- //string strKey = $"CalMyStatistics:{year}-{month}-{userid}";
-
- //if(!MyMemoryCache.TryGetValue(strKey,out retList))
- //{
- CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
- if (calMonth == null)
- {
- return null;
- }
- else
- {
- return _CalMyStatistics(calMonth, userid);
- #region old code
- //if (calMonth.Status == 4)
- //{
- // //已归档,归档数据库中直接取出记录
- // if (userid == null)
- // {
- // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
- // }
- // else
- // {
- // retList = Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
- // }
- //}
- //else
- //{
- // try
- // {
- // retList = _CalMyStatistics(calMonth, userid);
- // }
- // catch(Exception ex)
- // {
- // StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
- // sw.WriteLine($"{ex.Message}");
- // sw.Flush();
- // sw.Close();
- // sw.Dispose();
- // }
- //}
- //// Set cache options.
- //var cacheEntryOptions = new MemoryCacheEntryOptions()
- // // Keep in cache for this time, reset time if accessed.
- // .SetSlidingExpiration(TimeSpan.FromHours(1));
- //foreach(var temObj in (List<StaffStatistics>)retList)
- //{
- // temObj.CalMonth.PerformanceItems = null;
- //}
- //// Save data in cache.
- //MyMemoryCache.SetValue(strKey, retList);
- //return (List<StaffStatistics>)retList;
- #endregion
- }
- //}
- //else
- //{
- // var temList = (List<StaffStatistics>)retList;
- // foreach (var temObj in temList)
- // {
- // temObj.CalMonth.PerformanceItems = null;
- // }
- // return temList;
- //}
-
- }
-
- private string GetExpress(IList<FieldCondition> conditions)
- {
- string str = "";
- foreach(var c in conditions)
- {
- if (string.IsNullOrEmpty(str))
- {
- str = c.ToExpressString("s");
- }
- else
- {
- if(c.LogicOperate == LogicEnum.And)
- {
- str = $"({str}) && {c.ToExpressString("s")}";
- }
- else
- {
- str = $"({str}) || {c.ToExpressString("s")}";
- }
- }
- }
- return str;
- }
- [HttpGet,HttpPost]
- public FileProcessTask ExportData(QueryFilter queryFilter)
- {
- var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-绩效数据下载.xlsx";
- var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
- var filePath = Path.Combine(attachfileSavePath, filename);
- var fileTask = new FileProcessTask()
- {
- Id = Guid.NewGuid().ToString(),
- FileName = filename,
- FilePath = filePath,
- Processed = 0
- };
- fileTaskService.Add(fileTask);
- ThreadObject threadObject = new ThreadObject()
- {
- queryFilter = queryFilter,
- fileTask = fileTask
- };
- System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportDataThread));
- t.Start(threadObject);
- return fileTask;
- }
- internal class ThreadObject
- {
- public QueryFilter queryFilter { get; set; }
- public FileProcessTask fileTask { get; set; }
- }
-
- private void ExportDataThread(object tObj)
- {
- QueryFilter queryFilter = ((ThreadObject)tObj).queryFilter;
- FileProcessTask fileTask = ((ThreadObject)tObj).fileTask;
- IQueryable<PerformanceItem> response = NewMethod(queryFilter);
- var retList = response
- .Include(p=>p.Customer)
- .Include(p=>p.ItemStaffs).ThenInclude(p=>p.DoPerson).ThenInclude(p=>p.StaffGrade)
- .Include(p=>p.Reviewer).ThenInclude(p=>p.StaffGrade)
- .Include(p=>p.PreOastaff)
- .Include(p=>p.CalMonth)
- .ToList<PerformanceItem>();
-
- DataTable dt = new DataTable();
- #region 添加栏位
- dt.Columns.Add("我方文号",typeof(string));
- dt.Columns.Add("申请类型", typeof(string));
- dt.Columns.Add("业务类型", typeof(string));
- dt.Columns.Add("备注(填表注意事项)", typeof(string));
- dt.Columns.Add("处理事项", typeof(string));
- dt.Columns.Add("案件阶段", typeof(string));
- dt.Columns.Add("案件系数", typeof(string));
- dt.Columns.Add("处理事项系数", typeof(string));
- dt.Columns.Add("前一次OA处理事项系数", typeof(string));
- dt.Columns.Add("前一次OA处理人", typeof(string));
- dt.Columns.Add("处理人等级", typeof(string));
- dt.Columns.Add("基本点数", typeof(string));
- dt.Columns.Add("核稿系数", typeof(string));
- dt.Columns.Add("核稿绩效", typeof(string));
- dt.Columns.Add("处理人", typeof(string));
- dt.Columns.Add("核稿人", typeof(string));
- dt.Columns.Add("客户名称", typeof(string));
- dt.Columns.Add("申请人", typeof(string));
- dt.Columns.Add("处理事项完成日", typeof(string));
- dt.Columns.Add("定稿日", typeof(string));
- dt.Columns.Add("返稿日", typeof(string));
- dt.Columns.Add("案件类型", typeof(string));
- dt.Columns.Add("案件状态", typeof(string));
- dt.Columns.Add("处理事项备注", typeof(string));
- dt.Columns.Add("处理状态", typeof(string));
- dt.Columns.Add("案件名称", typeof(string));
- dt.Columns.Add("委案日期", typeof(string));
- dt.Columns.Add("客户期限", typeof(string));
- dt.Columns.Add("内部期限", typeof(string));
- dt.Columns.Add("初稿日", typeof(string));
- dt.Columns.Add("备注(发文严重超期是否属客观原因,若为否,请填写原因)", typeof(string));
- dt.Columns.Add("备注", typeof(string));
- #endregion
- List<VerifyCoefficient> verifyCoefficients = new spDbContext().VerifyCoefficients.ToList();
- fileTask.Size = retList.Count;
- foreach (var item in retList)
- {
- fileTask.Processed += 1;
- if (item.CaseNo.StartsWith("J"))
- {
- continue;
- }
- try
- {
- var row = dt.NewRow();
- row["我方文号"] = item.CaseNo;
- row["申请类型"] = item.ApplicationType;
- row["业务类型"] = item.BusinessType;
- row["备注(填表注意事项)"] = item.AgentFeedbackMemo;
- row["处理事项"] = item.DoItem;
- row["案件阶段"] = item.CaseStage;
- row["案件系数"] = item.CaseCoefficient;
- row["处理事项系数"] = item.DoItemCoefficient;
- row["前一次OA处理事项系数"] = "";
- if (item.PreOastaffId.HasValue)
- {
- row["前一次OA处理人"] = item.PreOastaff?.Name;
- }
- string strISLevels = "";
- string strISNames = "";
- foreach (var istaff in item.ItemStaffs)
- {
- strISLevels = string.IsNullOrEmpty(strISLevels)?istaff.DoPerson.StaffGrade?.Grade : $"{strISLevels},{istaff.DoPerson.StaffGrade?.Grade}";
- strISNames = string.IsNullOrEmpty(strISNames)?istaff.DoPerson.Name : $"{strISNames},{istaff.DoPerson.Name}";
- }
- row["处理人等级"] = strISLevels;
- row["基本点数"] = item.BasePoint;
- row["处理人"] = strISNames;
- row["核稿人"] = item.Reviewer?.Name;
- if (item.ReviewerId != null && item.BasePoint.HasValue)
- {
- var jxList = _calItemJX( verifyCoefficients, item, new spDbContext());
- row["核稿系数"] = "";
- var temJx = jxList.FirstOrDefault<StaffStatistics>(s => s.jxType.Contains("审核") && s.StaffId == item.ReviewerId);
- if (temJx != null)
- {
- row["核稿绩效"] = temJx.totalBasePoint;
- }
- }
- row["客户名称"] = item.Customer?.Name;
- row["申请人"] = item.ApplicationName;
- row["处理事项完成日"] = item.FinishedDate?.ToString("yyyy-MM-dd");
- row["定稿日"] = item.FinalizationDate?.ToString("yyyy-MM-dd");
- row["返稿日"] = item.ReturnDate?.ToString("yyyy-MM-dd");
- row["案件类型"] = item.CaseType;
- row["案件状态"] = item.CaseState;
- row["处理事项备注"] = item.DoItemState;
- row["处理状态"] = item.DoItemState;
- row["案件名称"] = item.CaseName;
- row["委案日期"] = item.EntrustingDate?.ToString("yyyy-MM-dd");
- row["客户期限"] = item.CustomerLimitDate?.ToString("yyyy-MM-dd");
- row["内部期限"] = item.InternalDate?.ToString("yyyy-MM-dd"); ;
- row["初稿日"] = item.FirstDraftDate?.ToString("yyyy-MM-dd");
- row["备注(发文严重超期是否属客观原因,若为否,请填写原因)"] = item.OverDueMemo;
- row["备注"] = item.DoItemMemo;
- dt.Rows.Add(row);
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
-
- utility.NPOIExcel.DataTableToExcel(dt,fileTask.FilePath);
- fileTask.Finished = true;
- }
- [HttpPost]
- public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
- {
- ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
- IQueryable<PerformanceItem> response = NewMethod(queryFilter);
- int totals = response.ToList<PerformanceItem>().Count;
- if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
- {
- response = response
- .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
- .Include(pi => pi.Reviewer)
- .Include(pi => pi.Customer)
- .Include(pi => pi.CalMonth)
- .OrderConditions<PerformanceItem>(queryFilter.Sorts);
- //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
- }
- else
- {
- response = response
- .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
- .Include(pi => pi.Reviewer)
- .Include(pi => pi.Customer)
- .Include(pi => pi.CalMonth)
- .OrderConditions<PerformanceItem>(queryFilter.Sorts);
- //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
- }
- ret.TotalCount = totals;
- var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
- #region 将某些属性设为null,避免循环取值造成返回json过大
- foreach (PerformanceItem item in retList)
- {
- foreach (ItemStaff itemStaff in item.ItemStaffs)
- {
- itemStaff.DoPerson.ItemStaffs = null;
- itemStaff.DoPerson.ReviewerItems = null;
- itemStaff.Item = null;
- }
- if (item.Reviewer != null)
- {
- item.Reviewer.ReviewerItems = null;
- item.Reviewer.Customers = null;
- item.Reviewer.ItemStaffs = null;
- }
- if (item.WorkflowUser != null)
- {
- item.WorkflowUser.ReviewerItems = null;
- item.WorkflowUser.Customers = null;
- item.WorkflowUser.ItemStaffs = null;
- }
- if (item.Customer != null)
- {
- item.Customer.PerformanceItems = null;
- }
- if (item.CalMonth != null)
- {
- item.CalMonth.PerformanceItems = null;
- }
- }
- #endregion
- ret.Results = retList.ToList();
- return ret;
- }
- private IQueryable<PerformanceItem> NewMethod(QueryFilter queryFilter)
- {
- string strExpress = "";
- string strCalMonth = "";
- if (queryFilter.CalMonthId.HasValue)
- {
- strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
- }
- else
- {
- if(queryFilter.jxType == jxType.finished)
- {
- strCalMonth = $"s.CalMonth.Status == 4";
- }
- else
- {
- strCalMonth = $"s.CalMonth.Status != 4";
- }
-
- //strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
- }
- if (!string.IsNullOrEmpty(strExpress))
- {
- strExpress = $"{strExpress} && {strCalMonth}";
- }
- else
- {
- strExpress = strCalMonth;
- }
- if (queryFilter.ConditionTree != null)
- {
- string strTem = GetExpress(queryFilter.ConditionTree);
- if (!string.IsNullOrEmpty(strTem))
- {
- strExpress = $"{strExpress} && ({strTem})";
- }
- }
- var interpreter = new Interpreter();
- Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
- IQueryable<PerformanceItem> response;
- if (queryFilter.userId > 0)
- {
- if (queryFilter.DoingOrReview == 0)
- {
- response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0));
- }
- else
- {
- response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => s.ReviewerId == queryFilter.userId);
- }
- }
- else
- {
- response = new spDbContext().PerformanceItems.Where<PerformanceItem>(dynamicWhere);
- }
- return response;
- }
- public ApiSaveResponse AddProjectContents(ProjectContents projectContents)
- {
- ApiSaveResponse retResponse = new ApiSaveResponse();
- retResponse.Success = true;
- if (projectContents != null && projectContents.ProjectWorkContents != null && projectContents.ProjectWorkContents.Count > 0)
- {
- using (var t = Context.Database.BeginTransaction())
- {
- try
- {
- CalMonth calMonth = Context.CalMonths.FirstOrDefault<CalMonth>(c => c.Status == 0);
- if (calMonth == null)
- {
- retResponse.Success = false;
- retResponse.ErrorMessage = "不存在正在处理的绩效月度!";
- return retResponse;
- }
- else
- {
- projectContents.ProjectContentRecord.CalMonthId = calMonth.Id;
- projectContents.ProjectContentRecord.CalMonth = null;
- var staff = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
- projectContents.ProjectContentRecord.StaffId = staff.Id;
- projectContents.ProjectContentRecord.State = 0;
- }
- var project = Context.ProjectInfos.FirstOrDefault(p => p.CaseNo == projectContents.ProjectContentRecord.ProjectNo && p.CaseState ==0);
- if (project != null)
- {
- var pRecord = Context.ProjectContentRecords.FirstOrDefault(p=>p.ProjectNo == projectContents.ProjectContentRecord.ProjectNo
- && p.StaffId == projectContents.ProjectContentRecord.StaffId
- && p.CalMonthId == projectContents.ProjectContentRecord.CalMonthId);
- if(pRecord != null)
- {
- retResponse.Success = false;
- retResponse.ErrorMessage = $"您已提交专案【{projectContents.ProjectContentRecord.ProjectNo}】{pRecord.CalMonth.Year}年{pRecord.CalMonth.Month}月的工作内容!";
- return retResponse;
- }
- Context.ProjectContentRecords.Add(projectContents.ProjectContentRecord);
- foreach (var doItem in projectContents.ProjectWorkContents)
- {
- doItem.ContentRecordId = projectContents.ProjectContentRecord.Id;
- Context.ProjectWorkContents.Add(doItem);
- }
- t.Commit();
- }
- else
- {
- retResponse.Success = false;
- retResponse.ErrorMessage = "专案不存在或专案已完成!";
- return retResponse;
- }
-
- }
- catch (Exception ex)
- {
- retResponse.Success = false;
- retResponse.ErrorMessage = ex.Message;
- t.Rollback();
- return retResponse;
- }
- }
- }
- return retResponse;
- }
- public PerformanceItem GetCaseInfo(string CaseNo)
- {
- var retObj = Context.PerformanceItems.OrderByDescending(p=>p.CalMonthId).FirstOrDefault<PerformanceItem>(p=>p.CaseNo == CaseNo.Trim());
- if(retObj == null)
- {
- retObj = new IPEasyController(Context).GetCaseInfo(CaseNo);
- }
- return retObj;
-
- }
- public PerformanceItem GetItemInfo(string CaseNo, string DoItem)
- {
- var retObj = Context.PerformanceItems.FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim() && p.DoItem == DoItem.Trim());
- if (retObj == null)
- {
- retObj = new IPEasyController(Context).GetItemInfo(CaseNo,DoItem);
- }
- return retObj;
- }
- public PerformanceItem GetItemInfoByCaseStage(string CaseNo, string DoItem,string caseStage,bool UpdateFromIPEasy=true)
- {
- var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
- && p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
- if (retObj == null && UpdateFromIPEasy)
- {
- var temObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
-
- System.Dynamic.ExpandoObject temExpandoObject = (System.Dynamic.ExpandoObject)temObj;
- retObj = new PerformanceItem();
- retObj.CaseNo = temObj.CaseNo.ToString();
- retObj.CaseName = temObj.CaseName.ToString();
- try
- {
- if (temObj.ApplicationType != null)
- retObj.ApplicationType = temObj.ApplicationType.ToString();
- if (temObj.CaseMemo != null)
- retObj.CaseMemo = temObj.CaseMemo.ToString();
- if (temObj.BusinessType != null)
- retObj.BusinessType = temObj.BusinessType.ToString();
- if (temObj.DoItem != null)
- retObj.DoItem = temObj.DoItem.ToString();
- if (temObj.CaseStage != null)
- retObj.CaseStage = temObj.CaseStage.ToString();
- if (temObj.CaseType != null)
- retObj.CaseType = temObj.CaseType.ToString();
- if (temObj.DoItemState != null)
- retObj.DoItemState = temObj.DoItemState.ToString();
- if (temObj.DoItemCoefficient != null)
- retObj.DoItemCoefficient = temObj.DoItemCoefficient.ToString();
- if (temObj.CaseCoefficient != null)
- retObj.CaseCoefficient = temObj.CaseCoefficient.ToString();
- if (temObj.EntrustingDate != null)
- {
- if (!string.IsNullOrEmpty(temObj.EntrustingDate.ToString()))
- retObj.EntrustingDate = DateTime.Parse(temObj.EntrustingDate.ToString());
- }
-
- if (temObj.InternalDate != null)
- {
- if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
- retObj.InternalDate = DateTime.Parse(temObj.InternalDate.ToString());
- }
- if (temObj.CustomerLimitDate != null)
- {
- if (!string.IsNullOrEmpty(temObj.InternalDate.ToString()))
- retObj.CustomerLimitDate = DateTime.Parse(temObj.InternalDate.ToString());
- }
- if (temObj.ReturnDate != null)
- {
- if (!string.IsNullOrEmpty(temObj.ReturnDate.ToString()))
- retObj.ReturnDate = DateTime.Parse(temObj.ReturnDate.ToString());
- }
- if (temObj.FinalizationDate != null)
- {
- if (!string.IsNullOrEmpty(temObj.FinalizationDate.ToString()))
- retObj.FinalizationDate = DateTime.Parse(temObj.FinalizationDate.ToString());
- }
- if (temObj.FinishedDate != null)
- {
- if (!string.IsNullOrEmpty(temObj.FinishedDate.ToString()))
- retObj.FinishedDate = DateTime.Parse(temObj.FinishedDate.ToString());
- }
- }
- catch { }
- int temWordCount;
- if (temObj.WordCount != null)
- {
- if (int.TryParse(temObj.WordCount, out temWordCount))
- {
- retObj.WordCount = temWordCount;
- }
- }
- try
- {
- if (temObj.CustomerName != null)
- {
- string strCustomer = temObj.CustomerName.ToString();
- retObj.Customer = new Customer() { Name = strCustomer };
- var temCustomer = Context.Customers.Where(c => c.Name == strCustomer.Trim()).FirstOrDefault();
- if (temCustomer != null)
- {
- retObj.CustomerId = temCustomer.Id;
- }
- }
- }
- catch { }
- try
- {
- if (temObj.Reviewer != null)
- {
- string strReViewer = temObj.Reviewer.ToString();
- var temReviewer = Context.Staffs.Where(s => s.Name == strReViewer.Trim()).FirstOrDefault();
- if (temReviewer != null)
- {
- retObj.ReviewerId = temReviewer.Id;
- }
- }
- }
- catch { }
- if (temObj.DoPersons != null)
- {
- string DoPersons = temObj.DoPersons.ToString();
- string[] Persons = DoPersons.Split(new char[] { ',' });
- List<ItemStaff> itemStaffs = new List<ItemStaff>();
- foreach (var doPerson in Persons)
- {
- itemStaffs.Add(new ItemStaff() { DoPerson = new Staff() { Name = doPerson } });
- }
- retObj.ItemStaffs = itemStaffs;
- }
-
- }
- return retObj;
- }
-
- public PerformanceItem GetItemInfoByMonthId(string CaseNo, string DoItem, string caseStage,int calMonthId)
- {
- var retObj = Context.PerformanceItems.Include(p => p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
- && p.DoItem == DoItem.Trim() && p.CalMonthId == calMonthId);
- if(retObj != null)
- {
- if(string.IsNullOrEmpty (retObj.CaseStage) && string.IsNullOrEmpty(caseStage))
- {
- return retObj;
- }
- else
- {
- if(retObj.CaseStage == caseStage)
- {
- return retObj;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- return null;
- }
- }
- public bool MovePerformance2ProjectInfo()
- {
- var response = Context.PerformanceItems.Include(p=>p.ItemStaffs)
- .Where<PerformanceItem>(p => p.CaseNo.StartsWith("S") && p.CalMonth.Status == 0);
-
- var pList = response.ToList<PerformanceItem>();
- foreach(var p in pList)
- {
- ProjectInfo project = new ProjectInfo();
- project.CaseNo = p.CaseNo;
- project.CaseName = p.CaseName;
- project.CaseState = 0;
- project.CaseType = p.CaseType;
- project.CustomerId = p.CustomerId;
- project.ReviewerId = p.ReviewerId;
- Context.ProjectInfos.Add(project);
-
- foreach(ItemStaff iStaff in p.ItemStaffs)
- {
- Context.ItemStaffs.Remove(iStaff);
- }
- Context.PerformanceItems.Remove(p);
- Context.SaveChanges();
-
- }
- return true;
- }
- }
- }
|