Browse Source

添加绩效归档功能
修正按字数算绩效计算问题(规则中添加小时点)
将1~11月份数据导入到库中

luocaiyang 3 years ago
parent
commit
131b51e3f9

+ 73 - 3
wispro.sp.api/Controllers/PerformanceItemController.cs

@@ -35,6 +35,25 @@ namespace wispro.sp.api.Controllers
 
         }
 
+        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();
@@ -455,9 +474,9 @@ namespace wispro.sp.api.Controllers
                 //if (item.BasePoint == null)
                 //{
 
-                //Utility.Utility.CalBasePoint(item,Rules);
+                    Utility.Utility.CalBasePoint(item,Rules);
 
-                //Context.SaveChanges();
+                    Context.SaveChanges();
                 //}
 
                 if (item.BasePoint != null && item.BasePoint.Value > 0)
@@ -629,7 +648,7 @@ namespace wispro.sp.api.Controllers
                 }
                 else
                 {
-                    if (itemStaff.DoPerson.StaffGrade != null && itemStaff.DoPerson.IsOnJob)
+                    if (itemStaff.DoPerson.StaffGradeId  != null && itemStaff.DoPerson.IsOnJob)
                     {
                         if (item.Type != "专案")
                         {
@@ -649,6 +668,7 @@ namespace wispro.sp.api.Controllers
                             }
                             else
                             {
+                                itemStaff.DoPerson.StaffGrade = Context.StaffGrades.FirstOrDefault(s=>s.Id == itemStaff.DoPerson.StaffGradeId);
                                 temStatic = new StaffStatistics()
                                 {
                                     CalMonth = calMonth,
@@ -684,7 +704,57 @@ namespace wispro.sp.api.Controllers
             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>

+ 5 - 0
wispro.sp.api/Utility/Utility.cs

@@ -43,6 +43,11 @@ namespace wispro.sp.api.Utility
                             temString = $"{rule.PointExpress.Trim()}.0";
                         }
 
+                        //if (temString.Contains("p."))
+                        //{
+                        //    System.Diagnostics.Debug.WriteLine(temString);
+                        //}
+
                         var target = new Interpreter().SetVariable("p", item);
                         item.BasePoint = (double?)target.Eval(temString);
                         item.Type = rule.Type;

+ 4 - 1
wispro.sp.utility/NPOIExcle.cs

@@ -85,7 +85,10 @@ namespace wispro.sp.utility
                                 for (int i = startRow; i <= rowCount; ++i)
                                 {
                                     row = sheet.GetRow(i);
-
+                                    if(row.GetCell(1).ToString()== "PACN2110126")
+                                    {
+                                        System.Diagnostics.Debug.WriteLine("");
+                                    }
                                     if (row != null && IgnoreZeroHightRow && row.ZeroHeight)
                                     {
                                         System.Diagnostics.Debug.WriteLine (string.Format("[{0}]隐藏行:{1}", filePath, i));

+ 1 - 0
wispro.sp.web/Pages/AppCase/CaseManager.razor.cs

@@ -88,6 +88,7 @@ namespace wispro.sp.web.Pages.AppCase
         private async Task GuidangCalMonth(CalMonth calMonth)
         {
             //还未实现,此处需要添加归档代码
+            await _ItemService.FinishedCalMonth(calMonth);
 
             await Task.Delay(1);
             StateHasChanged();

+ 5 - 1
wispro.sp.web/Services/PerformanceItemServices.cs

@@ -99,7 +99,11 @@ namespace wispro.sp.web.Services
 
         }
 
-        
+        public async  Task<ApiSaveResponse> FinishedCalMonth(CalMonth calMonth)
+        {
+            var ret = await _httpClient.Get<ApiSaveResponse>($"PerformanceItem/FinishedCalMonth?year={calMonth.Year}&month={calMonth.Month}");
+            return ret;
+        }
 
         public async Task<ListApiResponse<PerformanceItem>> Query(CalMonth calMonth, QueryModel<PerformanceItem> queryModel)
         {

+ 50 - 35
wispro.sp.winClient/Form1.cs

@@ -186,33 +186,33 @@ namespace wispro.sp.winClient
             //share.Utility.UserConditionHelper.GetPropertyDescription<Staff>(typeof(PerformanceItem).AssemblyQualifiedName);
 
             #region Demo流程数据
-            HttpClient http = new HttpClient();
-            int wfId = 6;
-            var workflow = await GetWorkflow(wfId, http);
-            var Steps = await GetSteps(wfId, http);
-            var Actions = await GetActions(wfId, http);
-            var Transfers = await GetTransfers(wfId,http);
+            //HttpClient http = new HttpClient();
+            //int wfId = 6;
+            //var workflow = await GetWorkflow(wfId, http);
+            //var Steps = await GetSteps(wfId, http);
+            //var Actions = await GetActions(wfId, http);
+            //var Transfers = await GetTransfers(wfId,http);
             #endregion
-            FlowChartUtility flowChart = new FlowChartUtility();
-            flowChart.workflow = workflow;
-            flowChart.Steps = Steps;
-            flowChart.Transfers = Transfers;
+            //FlowChartUtility flowChart = new FlowChartUtility();
+            //flowChart.workflow = workflow;
+            //flowChart.Steps = Steps;
+            //flowChart.Transfers = Transfers;
 
-            string strSvg = flowChart.GetSvgString();
+            //string strSvg = flowChart.GetSvgString();
 
-            //var file = System.IO.File.CreateText("c:\\temp\\tem.svg");
-            //file.WriteLine(strSvg);
-            //file.Close();
+            ////var file = System.IO.File.CreateText("c:\\temp\\tem.svg");
+            ////file.WriteLine(strSvg);
+            ////file.Close();
 
-            System.Xml.XmlDocument xmdoc = new System.Xml.XmlDocument();
-            xmdoc.LoadXml(strSvg);
-            Svg.SvgDocument svg = Svg.SvgDocument.Open(xmdoc);
-            Bitmap bitmap = svg.Draw();
-            bitmap.Save("c:\\temp\\test.jpg",ImageFormat.Jpeg);
-            MemoryStream mStream = new MemoryStream();
-            bitmap.Save(mStream, ImageFormat.Jpeg);
-            byte[] bitMaps = new byte[mStream.Length];
-            mStream.Read(bitMaps, 0, (int)mStream.Length);
+            //System.Xml.XmlDocument xmdoc = new System.Xml.XmlDocument();
+            //xmdoc.LoadXml(strSvg);
+            //Svg.SvgDocument svg = Svg.SvgDocument.Open(xmdoc);
+            //Bitmap bitmap = svg.Draw();
+            //bitmap.Save("c:\\temp\\test.jpg",ImageFormat.Jpeg);
+            //MemoryStream mStream = new MemoryStream();
+            //bitmap.Save(mStream, ImageFormat.Jpeg);
+            //byte[] bitMaps = new byte[mStream.Length];
+            //mStream.Read(bitMaps, 0, (int)mStream.Length);
 
 
 
@@ -258,7 +258,7 @@ namespace wispro.sp.winClient
             ////return;
 
             //await ImportUsers();
-            //await InputPerformanceItem("ExcelFiles\\21.01-21.06 工程师绩效报表-总表.xlsx", true, false, 0);
+            await InputPerformanceItem("c:\\temp\\21.01-21.11 工程师绩效报表-总表.xlsx", true, false, 0);
 
             ////CalMonth cal = new CalMonth()
             ////{
@@ -494,7 +494,9 @@ namespace wispro.sp.winClient
                 }
             }
 
-
+            if (!string.IsNullOrEmpty(row["点数"].ToString().Trim())) {
+                item.BasePoint = double.Parse(row["点数"].ToString().Trim());
+            }
 
 
             item.Customer = new Customer() { Name = row["客户名称"].ToString().Trim() };
@@ -757,24 +759,37 @@ namespace wispro.sp.winClient
         private async Task SavePerformanceItem(PerformanceItem obj)
         {
             HttpClient http = new HttpClient();
-            var data = await http.PostAsJsonAsync<PerformanceItem>($"http://localhost:39476/api/PerformanceItem/New", obj);
-            if (data.IsSuccessStatusCode)
+
+            if (obj.CalMonth.Month == 10)
             {
-                ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
-                //await Task.Delay(1000);
+                System.Diagnostics.Debug.WriteLine($"{obj.CalMonth.Year}-{obj.CalMonth.Month}\t{obj.CaseNo}");
+            }
+            
 
-                if (result.Success)
+            var isExist = await http.PostAsJsonAsync<PerformanceItem>($"http://localhost:39476/api/PerformanceItem/IsExist", obj);
+
+            if (isExist.IsSuccessStatusCode && await isExist.Content.ReadFromJsonAsync<bool>()==false)
+            {
+
+                var data = await http.PostAsJsonAsync<PerformanceItem>($"http://localhost:39476/api/PerformanceItem/New", obj);
+                if (data.IsSuccessStatusCode)
                 {
+                    ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
+                    //await Task.Delay(1000);
+
+                    if (result.Success)
+                    {
+                    }
+                    else
+                    {
+                        System.Diagnostics.Debug.WriteLine($"保存错误: {obj.CaseNo}\t{obj.DoItem}\r\n{result.ErrorMessage}");
+                    }
                 }
                 else
                 {
-                    System.Diagnostics.Debug.WriteLine($"保存错误: {obj.CaseNo}\t{obj.DoItem}\r\n{result.ErrorMessage}");
+                    System.Diagnostics.Debug.WriteLine($"调用API错误: {obj.CaseNo}\t{obj.DoItem}");
                 }
             }
-            else
-            {
-                System.Diagnostics.Debug.WriteLine($"调用API错误: {obj.CaseNo}\t{obj.DoItem}");
-            }
         }
 
         private async Task<List<StaffGrade>> GetStaffGrades()