Переглянути джерело

添加计算个人绩效点数API[修正一些bug]

luocaiyang 3 роки тому
батько
коміт
4c7b5cc360

+ 191 - 0
wispro.sp.api/Controllers/PerformanceItemController.cs

@@ -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)
         {
 

+ 0 - 38
wispro.sp.web/Pages/AppCase/MyCaselist.razor.cs

@@ -267,7 +267,6 @@ namespace wispro.sp.web.Pages.AppCase
                 _loading = true;
                 _Datas = null;
                 var data = await _ItemService.GetMyList(_userService.CurrentUser.Userid.Value, jxType.doing, _pageIndex, _pageSize);
-                //var  data = response.GetAwaiter().GetResult();
 
                 _Datas = data.Results;
                 _total = data.TotalCount;
@@ -275,52 +274,16 @@ namespace wispro.sp.web.Pages.AppCase
             }
         }
 
-        private string EditField;
-        
-        private bool isInputChanged = false;
-        void startEdit(string id)
-        {
-            EditField = id;
-            isInputChanged = false;
-        }
-
-        void stopEdit()
-        {
-            if (isInputChanged)
-            {
-                var respone = _ItemService.SaveFieldChange(EditingItem.Id, EditField, EditField.GetType().GetProperty(EditField).GetValue(EditField, null).ToString());
-
-                //while (!respone.GetAwaiter().IsCompleted)
-                //{
-                //    Task.Delay(50);
-                //}
-
-                //if (!respone.Result.Success)
-                //{
-                //    _message.Warn(respone.Result.ErrorMessage);
-                //}
-
-            }
-            EditField = null;
-        }
-
         void SelectChanged(Reason  value)
         {
             if (!_loading && EditingItem != null)
             {
 
-                Console.WriteLine($"SelectChanged:{EditingItem.CaseNo}\t{value.Value }\t{EditingItem.AgentFeedbackMemo}");
                 var respone = _ItemService.SaveFieldChange(EditingItem.Id, strAgentFeedbackMemo, EditingItem.AgentFeedbackMemo);
                 EditingItem = null;
-                isInputChanged = true;
             }
         }
 
-        private void InputChanged(ChangeEventArgs args)
-        {
-            isInputChanged = true;
-        }
-
         Dictionary<string, object> OnRow(RowData<PerformanceItem> row)
         {
             Dictionary<string, object> ret = new Dictionary<string, object>();
@@ -337,7 +300,6 @@ namespace wispro.sp.web.Pages.AppCase
 
         void OnFocus(PerformanceItem item)
         {
-            Console.WriteLine("OnFocus");
             EditingItem = item;
         }
     }

+ 1 - 1
wospro.sp.entity/ItemStaff.cs

@@ -18,7 +18,7 @@ namespace wispro.sp.entity
         /// <summary>
         /// 绩效点数
         /// </summary>
-        public double PerformancePoint { get; set; }
+        public double? PerformancePoint { get; set; }
 
         /// <summary>
         /// 处理人

+ 51 - 0
wospro.sp.entity/StaffStatistics.cs

@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace wispro.sp.entity
+{
+    public class StaffStatistics
+    {
+        /// <summary>
+        /// 编号
+        /// </summary>
+        public int Id { get; set; }
+
+        /// <summary>
+        /// 绩效月份
+        /// </summary>
+        public virtual CalMonth CalMonth { get; set; }
+
+        /// <summary>
+        /// 绩效月份Id
+        /// </summary>
+        public int CalMonthId { get; set; }
+
+        /// <summary>
+        /// 员工
+        /// </summary>
+        public virtual Staff Staff { get; set; }
+
+        /// <summary>
+        /// 员工Id
+        /// </summary>
+        public int StaffId { get; set; }
+
+        /// <summary>
+        /// 绩效类型
+        /// </summary>
+        public string jxType { get; set; }
+
+        /// <summary>
+        /// 原始点数统计
+        /// </summary>
+        public double? totalBasePoint { get; set; }
+
+        /// <summary>
+        /// 难度系数调整后点数统计
+        /// </summary>
+        public double? totalActuallyPoint { get; set; }
+    }
+}