|
@@ -351,198 +351,296 @@ namespace wispro.sp.api.Controllers
|
|
|
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);
|
|
|
+ }
|
|
|
|
|
|
- /// <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)
|
|
|
+ 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)
|
|
|
{
|
|
|
- return 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 ));
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ 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(calMonth.Status == 4)
|
|
|
+ if (!string.IsNullOrEmpty(g.CaseCeoffcient))
|
|
|
{
|
|
|
- //已归档,归档数据库中直接取出记录
|
|
|
- return null;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //未归档,从绩效记录中统计数据
|
|
|
-
|
|
|
- var results = Context.PerformanceItems.Where<PerformanceItem>(s =>s.CalMonth.Id == calMonth.Id);
|
|
|
+
|
|
|
|
|
|
- if (userid != null)
|
|
|
+ if (CaseXiShu.ContainsKey(g.CaseCeoffcient))
|
|
|
{
|
|
|
- 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);
|
|
|
+ d += g.count * CaseXiShu[g.CaseCeoffcient];
|
|
|
+ iCount += g.count;
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- List<PerformanceItem> ItemList = results
|
|
|
- .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
|
|
|
- .Include(pi => pi.Reviewer)
|
|
|
- .OrderByDescending(o => o.Id)
|
|
|
- .ToList<PerformanceItem>();
|
|
|
+ return d/(double)iCount;
|
|
|
+ }
|
|
|
|
|
|
- List<StaffStatistics> retList = new List<StaffStatistics>();
|
|
|
- List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
|
|
|
+ private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
|
|
|
+ {
|
|
|
+
|
|
|
+ double gspjXS = DegreeOfDifficulty(calMonth.Year , calMonth.Month);
|
|
|
|
|
|
- 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();
|
|
|
+ //未归档,从绩效记录中统计数据
|
|
|
+ var results = Context.PerformanceItems.Where<PerformanceItem>(s => s.CalMonth.Id == calMonth.Id);
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
+ 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<StaffStatistics> itemStatistics = new List<StaffStatistics>();
|
|
|
+ List<PerformanceItem> ItemList = results
|
|
|
+ .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
|
|
|
+ .Include(pi => pi.Reviewer)
|
|
|
+ .OrderByDescending(o => o.Id)
|
|
|
+ .ToList<PerformanceItem>();
|
|
|
|
|
|
- if (item.Reviewer != null)
|
|
|
- {
|
|
|
- Context.Entry(item.Reviewer).Reference(b => b.StaffGrade).Load();
|
|
|
- }
|
|
|
+ List<StaffStatistics> retList = new List<StaffStatistics>();
|
|
|
+ List<VerifyCoefficient> verifyCoefficients = Context.VerifyCoefficients.ToList<VerifyCoefficient>();
|
|
|
|
|
|
- foreach (ItemStaff itemStaff in item.ItemStaffs)
|
|
|
- {
|
|
|
- Context.Entry(itemStaff).Reference(b => b.DoPerson).Load();
|
|
|
- Context.Entry(itemStaff.DoPerson).Reference(b => b.StaffGrade).Load();
|
|
|
+ foreach (PerformanceItem item in ItemList)
|
|
|
+ {
|
|
|
|
|
|
- #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;
|
|
|
+ if (item.BasePoint != null && item.BasePoint.Value > 0)
|
|
|
+ {
|
|
|
+ double doPersonBasePoint = item.BasePoint.Value;
|
|
|
|
|
|
+ System.Collections.Hashtable doPersonsBL = new System.Collections.Hashtable();
|
|
|
|
|
|
- string temJxType = $"{item.Type}审核";
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
- 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
|
|
|
+ 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;
|
|
|
|
|
|
- #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)
|
|
|
+ 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)
|
|
|
{
|
|
|
- temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
|
|
|
+ temReviewerStatic.totalBasePoint += reviewerBasePoint;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (itemStaff.DoPerson.StaffGrade != null && itemStaff.DoPerson.IsOnJob)
|
|
|
+ if (item.Reviewer.IsOnJob) //判断是否在职
|
|
|
{
|
|
|
- temStatic = new StaffStatistics()
|
|
|
+ temReviewerStatic = new StaffStatistics()
|
|
|
{
|
|
|
CalMonth = calMonth,
|
|
|
CalMonthId = calMonth.Id,
|
|
|
- StaffId = itemStaff.DoPersonId,
|
|
|
- totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
|
|
|
- jxType = handlerJxType
|
|
|
+ StaffId = item.ReviewerId.Value,
|
|
|
+ totalBasePoint = reviewerBasePoint,
|
|
|
+ jxType = temJxType
|
|
|
};
|
|
|
|
|
|
-
|
|
|
- itemStatistics.Add(temStatic);
|
|
|
+ itemStatistics.Add(temReviewerStatic);
|
|
|
}
|
|
|
}
|
|
|
- #endregion
|
|
|
}
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
|
|
|
- List<StaffStatistics> temItemStatics;
|
|
|
+ #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;
|
|
|
+ }
|
|
|
|
|
|
- if(userid != null)
|
|
|
+ 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 != "专案")
|
|
|
{
|
|
|
- temItemStatics = itemStatistics.Where<StaffStatistics>(s => s.StaffId == userid).ToList();
|
|
|
+ temStatic.totalBasePoint += handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- temItemStatics = itemStatistics;
|
|
|
+ temStatic.totalBasePoint += handlerBasePoint;
|
|
|
}
|
|
|
-
|
|
|
- foreach (StaffStatistics retUserValue in temItemStatics)
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (itemStaff.DoPerson.StaffGrade != null && itemStaff.DoPerson.IsOnJob)
|
|
|
{
|
|
|
- var temValue = retList.Where<StaffStatistics>(s => s.StaffId == retUserValue.StaffId && s.jxType == retUserValue.jxType && s.CalMonthId == calMonth.Id).FirstOrDefault();
|
|
|
- if (temValue != null)
|
|
|
+ if (item.Type != "专案")
|
|
|
{
|
|
|
- temValue.totalBasePoint += retUserValue.totalBasePoint;
|
|
|
+ temStatic = new StaffStatistics()
|
|
|
+ {
|
|
|
+ CalMonth = calMonth,
|
|
|
+ CalMonthId = calMonth.Id,
|
|
|
+ StaffId = itemStaff.DoPersonId,
|
|
|
+ totalBasePoint = handlerBasePoint * itemStaff.DoPerson.StaffGrade.Coefficient,
|
|
|
+ jxType = handlerJxType
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ itemStatistics.Add(temStatic);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- retList.Add(retUserValue);
|
|
|
+ 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 ss in retList)
|
|
|
+ foreach (StaffStatistics retUserValue in temItemStatics)
|
|
|
{
|
|
|
- ss.CalMonth.PerformanceItems = null;
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
- return retList;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
|
|
|
-
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //已归档,归档数据库中直接取出记录
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return _CalMyStatistics(calMonth, userid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private string GetExpress(IList<FieldCondition> conditions)
|
|
|
{
|
|
@@ -612,18 +710,34 @@ namespace wispro.sp.api.Controllers
|
|
|
|
|
|
}
|
|
|
|
|
|
- int totals;
|
|
|
- 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);
|
|
|
+ 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)
|
|
|
{
|