|
@@ -279,6 +279,197 @@ namespace wispro.sp.api.Controllers
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+ /// <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)
|
|
|
+ {
|
|
|
+ //已归档,归档数据库中直接取出记录
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //未归档,从绩效记录中统计数据
|
|
|
+
|
|
|
+ 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.CaseNo == "JPACN2136576") {
|
|
|
+ System.Diagnostics.Debug.WriteLine(item.CaseNo);
|
|
|
+ }
|
|
|
+ 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 && userid == item.ReviewerId)
|
|
|
+ {
|
|
|
+ #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 (isPJFP) {
|
|
|
+ handlerBasePoint = item.BasePoint.Value * 1.0/total;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ handlerBasePoint = item.BasePoint.Value * itemStaff.PerformancePoint.Value / total;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (itemStaff.DoPerson.IsOnJob)
|
|
|
+ {
|
|
|
+ temStatic = new StaffStatistics()
|
|
|
+ {
|
|
|
+ CalMonth = calMonth,
|
|
|
+ CalMonthId = calMonth.Id,
|
|
|
+ StaffId = itemStaff.DoPersonId,
|
|
|
+ totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach(StaffStatistics ss in retList)
|
|
|
+ {
|
|
|
+ ss.CalMonth.PerformanceItems = null;
|
|
|
+ }
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
|
|
|
{
|
|
|
|