123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893 |
- using DynamicExpresso;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Threading.Tasks;
- 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;
- public PerformanceItemController(spDbContext context)
- {
- Context = context;
- }
- 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);
-
- 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)
- {
- Context.Customers.Add(item.Customer);
- Context.SaveChanges();
- }
- 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.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;
- }
- }
-
- 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;
- }
- 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)
- {
- 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 == "专案"));
- 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 ));
- }
- 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;
- }
- }
- }
- return d/(double)iCount;
- }
- 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)
- .OrderByDescending(o => o.Id)
- .ToList<PerformanceItem>();
- List<StaffStatistics> retList = new List<StaffStatistics>();
- List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
- foreach (PerformanceItem item in ItemList)
- {
- if (item.BasePoint != null && item.BasePoint.Value > 0)
- {
- double doPersonBasePoint = item.BasePoint.Value;
- 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.Reviewer != null)
- {
- Context.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
- }
- foreach (ItemStaff itemStaff in item.ItemStaffs)
- {
- Context.Entry(itemStaff).Reference(b => b.DoPerson).Load();
- Context.Entry(itemStaff.DoPerson).Reference(b => b.StaffGrade).Load();
- #region 计算审核人绩效点数,核稿人绩效点数按照核稿人与个处理人的核稿系数计算后加总,没有找到核稿系数(比如同级别),核稿系数为0
- if (item.ReviewerId != null && item.Type !="专案")
- {
- #region 取审核人等级审核等级系数
- VerifyCoefficient vcoefficient = verifyCoefficients.Where<VerifyCoefficient>(v =>
- v.CheckerId == item.Reviewer.StaffGrade.Id
- && 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) //判断是否在职
- {
- 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.StaffGrade != null && itemStaff.DoPerson.IsOnJob)
- {
- if (item.Type != "专案")
- {
- 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
- }
- 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;
- }
- /// <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)
- {
- 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)
- {
- return Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id).ToList<StaffStatistics>();
- }
- else
- {
- return Context.StaffStatistics.Where<StaffStatistics>(s => s.CalMonthId == calMonth.Id && s.StaffId == userid).ToList<StaffStatistics>();
- }
- }
- else
- {
- return _CalMyStatistics(calMonth, userid);
- }
- }
- }
-
- 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;
- }
-
- [HttpPost]
- public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
- {
- ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
- string strExpress = "";
-
- if (!string.IsNullOrEmpty(strExpress))
- {
- strExpress = $"{strExpress} && s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
- }
- else
- {
- strExpress = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
- }
- 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)
- {
- response = Context.PerformanceItems.Where<PerformanceItem>(dynamicWhere).Where(s => (s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == queryFilter.userId).Count() > 0 || s.ReviewerId == queryFilter.userId));
- }
- else
- {
- response = Context.PerformanceItems.Where<PerformanceItem>(dynamicWhere);
- }
- 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>();
- #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;
- return ret;
- }
-
- public ApiSaveResponse AddProjectPerformance(ProjectPointRecord pointRecord)
- {
- ApiSaveResponse retResponse = new ApiSaveResponse();
- retResponse.Success = true;
- if (pointRecord != null && pointRecord.ProjectDoItemPoints != null && pointRecord.ProjectDoItemPoints.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;
- }
- foreach (var doItem in pointRecord.ProjectDoItemPoints)
- {
- PerformanceItem item = new PerformanceItem();
- item.CaseNo = pointRecord.CaseNo;
- item.CaseName = pointRecord.CaseName;
- item.CaseMemo = pointRecord.Reason;
- item.DoItem = doItem.DoItem;
- item.CaseCoefficient = doItem.DoItemCoefficient;
- item.Type = "专案";
- item.CalMonthId = calMonth.Id;
- Context.PerformanceItems.Add(item);
- Context.SaveChanges();
- item.ItemStaffs = new List<ItemStaff>();
- foreach (var p in doItem.PersonPoints)
- {
- ItemStaff itemStaff = new ItemStaff();
- itemStaff.PerformancePoint = p.Point;
- var staff = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == p.Person);
- if (staff != null)
- {
- itemStaff.DoPersonId = staff.Id;
- itemStaff.ItemId = item.Id;
- Context.ItemStaffs.Add(itemStaff);
- Context.SaveChanges();
- }
- else
- {
- retResponse.Success = false;
- retResponse.ErrorMessage = $"用户【{p.Person}】不存在!";
- t.Rollback();
- return retResponse;
- }
- }
- }
- t.Commit();
- }
- 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;
- }
- }
- }
|