1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936 |
- 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 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);
- 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[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
- }
- 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
- {
- ret.Success = false;
- ret.ErrorMessage = "所给的栏位值不能转换成数字!";
- return ret;
- }
- break;
- case "ReturnCasseNo":
- item.ReturnCasseNo = temValue;
- break;
- }
- }
- if (item.AgentFeedbackMemo != "特殊点数申诉")
- {
- Utility.Utility.CalBasePoint(item, Context.BasePointRules.ToList());
- 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;
- }
- public double DegreeOfDifficulty(int year,int month, int? userId = null)
- {
- string strKey = $"DegreeOfDifficulty:{year}-{month}-{userId}";
- object cacheEntry;
- if (!MyMemoryCache.TryGetValue(strKey, out cacheEntry))
- {
- 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 = Context.PerformanceItems.Where<PerformanceItem>(p => p.CalMonth.Year == year && p.CalMonth.Month == month && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") && p.BasePoint > 0.0);
- if (userId != null)
- {
- results = Context.PerformanceItems.Where<PerformanceItem>(p =>
- p.CalMonth.Year == year && p.CalMonth.Month == month && ((p.Type == "新申请" && p.BasePoint > 0) || p.Type == "专案") &&
- (p.ItemStaffs.Where<ItemStaff>(s => s.DoPerson.Id == userId).Count() > 0 || p.ReviewerId == userId ) && 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;
- #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
- if (CaseXiShu.ContainsKey(strCaseCeoffcient))
- {
- d += CaseXiShu[strCaseCeoffcient];
- iCount += 1;
- }
- }
- #endregion
- #region 统计计算
- //var groupResult = results.GroupBy(x => x.CaseCoefficient).Select(g=> new {
- // CaseCeoffcient = g.Key,
- // count = g.Count()
- //});
- //int iCount = 0;
- //double d = 0.0;
- //foreach(var g in groupResult)
- //{
- // if (!string.IsNullOrEmpty(g.CaseCeoffcient))
- // {
- // if (CaseXiShu.ContainsKey(g.CaseCeoffcient))
- // {
- // d += g.count * CaseXiShu[g.CaseCeoffcient];
- // iCount += g.count;
- // }
- // }
- //}
- #endregion
- cacheEntry = d / (double)iCount;
- // Set cache options.
-
- // Save data in cache.
- MyMemoryCache.SetValue(strKey, cacheEntry);
- return (double)cacheEntry;
- }
- else
- {
- return (double)cacheEntry;
- }
- }
- 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)
- {
- double gspjXS = DegreeOfDifficulty(calMonth.Year, calMonth.Month);
- //未归档,从绩效记录中统计数据
- 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;
- }
- else
- {
- retList.Add(retUserValue);
- }
- }
- }
- }
- if (userid != null)
- {
- retList = retList.Where<StaffStatistics>(s => s.StaffId == userid.Value).ToList();
- }
- IDictionary<int, double> staffXiShu = new Dictionary<int, double>();
- foreach (StaffStatistics ss in retList)
- {
- if (ss.jxType.Contains("新申请") || ss.jxType.Contains("专案"))
- {
- if (!staffXiShu.ContainsKey(ss.StaffId))
- {
- staffXiShu.Add(ss.StaffId, DegreeOfDifficulty(calMonth.Year, calMonth.Month, ss.StaffId));
- }
- ss.totalActuallyPoint = ss.totalBasePoint * staffXiShu[ss.StaffId] / gspjXS;
- }
- else
- {
- ss.totalActuallyPoint = ss.totalBasePoint;
- }
- ss.CalMonth.PerformanceItems = null;
- }
- return retList;
- }
- 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);
- 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).FirstOrDefault(p => p.Id == itemId);
- if (Item != null)
- {
- new Job.UpdateJXDataFromIPEasyJob().UpdateFromIPEasy(Item, Context);
- }
- 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
- };
- }
- 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(calMonth, 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(calMonth, 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(calMonth, 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");
-
- }
- private List<StaffStatistics> _calItemJX(CalMonth calMonth, List<VerifyCoefficient> verifyCoefficients, PerformanceItem item,spDbContext spDb)
- {
- //if(item.CaseNo == "PACN2116373")
- //{
- // System.Diagnostics.Debug.WriteLine("");
- //}
- System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
- bool isPJFP = true;
- double total = item.ItemStaffs.Count();
- if (item.ItemStaffs.Where<ItemStaff>(p => p.PerformancePoint != null || p.PerformancePoint == 0).Count() > 0)
- {
- total = item.ItemStaffs.Select(i => i.PerformancePoint.Value).Sum();
- isPJFP = false;
- }
- 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();
- }
- foreach (ItemStaff itemStaff in item.ItemStaffs)
- {
- 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 != "专案" && item.ItemStaffs.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 == calMonth.Id).FirstOrDefault();
- if (temReviewerStatic != null)
- {
- temReviewerStatic.totalBasePoint += reviewerBasePoint;
- }
- else
- {
- if (item.Reviewer.IsOnJob && itemStaff.DoPerson.Status != "试用期") //判断是否在职
- {
- temReviewerStatic = new StaffStatistics()
- {
- CalMonth = calMonth,
- CalMonthId = calMonth.Id,
- StaffId = item.ReviewerId.Value,
- totalBasePoint = 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
- {
- handlerBasePoint = itemStaff.PerformancePoint.Value;
- }
- string handlerJxType = $"{item.Type}处理";
- var temStatic = itemStatistics.Where<StaffStatistics>(s => s.StaffId == itemStaff.DoPersonId && s.jxType == handlerJxType && s.CalMonth.Id == calMonth.Id).FirstOrDefault();
- if (temStatic != null)
- {
- if (item.Type != "专案")
- {
- temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
- }
- else
- {
- temStatic.totalBasePoint += handlerBasePoint;
- }
- }
- else
- {
- if (itemStaff.DoPerson.StaffGradeId != null && itemStaff.DoPerson.IsOnJob)
- {
- if (item.Type != "专案")
- {
- if (itemStaff.DoPerson.Status == "试用期" && item.Reviewer != null)
- {
- temStatic = new StaffStatistics()
- {
- CalMonth = calMonth,
- CalMonthId = calMonth.Id,
- StaffId = item.Reviewer.Id,
- totalBasePoint = handlerBasePoint * item.Reviewer.StaffGrade.Coefficient,
- jxType = handlerJxType
- };
- itemStatistics.Add(temStatic);
- }
- else
- {
- itemStaff.DoPerson.StaffGrade = spDb.StaffGrades.FirstOrDefault(s=>s.Id == itemStaff.DoPerson.StaffGradeId);
- temStatic = new StaffStatistics()
- {
- CalMonth = calMonth,
- CalMonthId = calMonth.Id,
- StaffId = itemStaff.DoPersonId,
- totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
- jxType = handlerJxType
- };
- itemStatistics.Add(temStatic);
- }
- }
- else
- {
- temStatic = new StaffStatistics()
- {
- CalMonth = calMonth,
- CalMonthId = calMonth.Id,
- StaffId = itemStaff.DoPersonId,
- totalBasePoint = handlerBasePoint,
- jxType = handlerJxType
- };
- itemStatistics.Add(temStatic);
- }
- }
- }
- #endregion
- }
- return itemStatistics;
- }
- 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)
- {
- var retList = CalMyStatistics(year, month);
- using (var t = Context.Database.BeginTransaction())
- {
- try
- {
- foreach (var obj in retList)
- {
- obj.CalMonthId = calMonth.Id;
- obj.CalMonth = null;
- Context.StaffStatistics.Add(obj);
- Context.SaveChanges();
- }
- 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
- {
- 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
- {
- retList = _CalMyStatistics(calMonth, userid);
- }
- // Set cache options.
- var cacheEntryOptions = new MemoryCacheEntryOptions()
- // Keep in cache for this time, reset time if accessed.
- .SetSlidingExpiration(TimeSpan.FromHours(1));
- // Save data in cache.
- MyMemoryCache.SetValue(strKey, retList);
- return (List<StaffStatistics>)retList;
- }
- }
- else
- {
- return (List<StaffStatistics>)retList;
- }
-
- }
-
- 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(item.CalMonth, 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.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)
- {
- 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)
- {
- retObj = IPEasyUtility.GetPerformanceRecord(CaseNo, DoItem, caseStage);
- }
- return retObj;
- }
- 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;
- }
- }
- }
|