Bladeren bron

添加其他新申请绩效分配比率模块
从维德系统中更新数据时,增加可对外处理人更新代码

luocaiyang 10 maanden geleden
bovenliggende
commit
fb9799d6fc

+ 136 - 11
wispro.sp.api/Controllers/PerformanceItemController.cs

@@ -1,4 +1,5 @@
-using DynamicExpresso;
+using DocumentFormat.OpenXml.Office2010.ExcelAc;
+using DynamicExpresso;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
@@ -241,12 +242,7 @@ namespace wispro.sp.api.Controllers
 
                     Context.SaveChanges();
 
-                    #region 添加其他新申请的绩效分配(默认是对外处理人与处理人50:50)
-                    if(item.Type == "其他新申请")
-                    {
-                        //Context.AllocationRatios.Add();
-                    }
-                    #endregion
+                    
 
                     Context.Database.CommitTransaction();
                 }
@@ -1979,9 +1975,134 @@ namespace wispro.sp.api.Controllers
 
         }
 
+        public List<AllocationRatio> CalAllocationRatios(int itemId)
+        {
+            var retList = Context.AllocationRatios
+                .Include(p=>p.Person)
+                .Where<AllocationRatio>(p => p.ItemId == itemId).ToList();
+
+            foreach(var ar in retList)
+            {
+                ar.Person.AllocationRatios = null;
+                ar.Person.Customers = null;
+                ar.Person.ExternalHandlerItems = null;
+                ar.Person.ItemStaffs = null;
+                ar.Person.ReviewerItems = null;
+                ar.Person.Positions = null;
+            }
+
+            return retList;
+            
+        }
+
+        public void SaveAllocationRatios(List<AllocationRatio> allocationRatios)
+        {
+            using (var t = Context.Database.BeginTransaction())
+            {
+                try
+                {
+                    var oldList = Context.AllocationRatios.Where<AllocationRatio>(a => a.ItemId == allocationRatios[0].ItemId).ToList();
+                    Context.AllocationRatios.RemoveRange(oldList);
+
+                    Context.AllocationRatios.AddRange(allocationRatios);
+
+                    Context.SaveChanges();
+
+                    _calNDItemJx(new PerformanceItem() { Id = allocationRatios[0].ItemId }, Context);
+
+                    t.Commit();
+                }
+                catch
+                {
+                    t.Rollback();
+                }
+            }
+        }
+
+        private void _calNDItemJx(PerformanceItem item,spDbContext spDb)
+        {
+            //宁德时代绩效计算
+            var lstARs = spDb.AllocationRatios.Where<AllocationRatio>(i => i.ItemId == item.Id).ToList();
+            double? baseMony = item.BasePoint;
+
+            if(item.isDanger() && item.OverDueMemo == null)
+            {
+                #region 完成日期-委托日期>45天为延迟,每延迟一天绩效减去0.5个百分点
+                DateTime? dt1 = item.EntrustingDate;
+                DateTime? dt2 = item.FinishedDate;
+
+                if (dt2 == null)
+                {
+                    dt2 = DateTime.Now;
+                }
 
+                baseMony = baseMony * (100-((dt2.Value - dt1.Value).TotalDays - 45) * 0.5)/100.00;
+                #endregion
+            }
+
+            
+            if(lstARs == null || lstARs.Count()==0)
+            {
+                lstARs = new List<AllocationRatio>();
+                if(item.ExternalHandlerId != null && item.ItemStaffs.Where<ItemStaff>(i=>i.DoPersonId== item.ExternalHandlerId).Count() > 0)
+                {
+                    foreach(ItemStaff iStaff in item.ItemStaffs)
+                    {
+                        lstARs.Add(new AllocationRatio() { 
+                            ItemId = item.Id,
+                            PersonId = iStaff.DoPersonId,
+                            Ratio = 100.00/item.ItemStaffs.Count(),
+                        });
+                    }
+                }
+                else
+                {
+
+                    double temTotals = 100.00;
+                    if (item.ExternalHandlerId != null)
+                    {
+                        lstARs.Add(new AllocationRatio()
+                        {
+                            ItemId = item.Id,
+                            PersonId = item.ExternalHandlerId.Value,
+                            Ratio = 50.00
+                        });
+                        temTotals = 50.00;
+                    }
+
+                    foreach (ItemStaff iStaff in item.ItemStaffs)
+                    {
+                        lstARs.Add(new AllocationRatio()
+                        {
+                            ItemId = item.Id,
+                            PersonId = iStaff.DoPersonId,
+                            Ratio = temTotals / item.ItemStaffs.Count(),
+                        });
+                    }
+                }
+
+                spDb.AllocationRatios.AddRange(lstARs);
+
+            }
+
+            var totals = lstARs.Sum<AllocationRatio>(a => a.Ratio);
+
+            foreach(var ar in lstARs)
+            {
+                ar.ActualAmount = baseMony * ar.Ratio / totals;
+            }
+
+            spDb.SaveChanges();
+        }
         private void _calItemJX(PerformanceItem Item, spDbContext spDb)
         {
+            if(Item.Type == "其他新申请")
+            {
+                _calNDItemJx(Item, spDb);
+                return;
+                
+            }
+
             List<VerifyCoefficient> verifyCoefficients = spDb.VerifyCoefficients.ToList<VerifyCoefficient>();
 
             var jxList = _calItemJX(verifyCoefficients, Item, spDb);
@@ -2847,7 +2968,7 @@ namespace wispro.sp.api.Controllers
 
             int totals = response.ToList<PerformanceItem>().Count;
 
-            if (totals > 0 && totals < (queryFilter.PageIndex - 1) * queryFilter.PageSize)
+            if (totals > 0 && totals < (queryFilter.PageIndex) * queryFilter.PageSize)
             {
                 response = response
                     .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
@@ -2855,7 +2976,9 @@ namespace wispro.sp.api.Controllers
                     .Include(pi => pi.Customer)
                     .Include(pi => pi.CalMonth)
                     .Include(pi => pi.ExternalHandler)
-                    .OrderConditions<PerformanceItem>(queryFilter.Sorts);
+                    .OrderConditions<PerformanceItem>(queryFilter.Sorts)
+                    .Skip((queryFilter.PageIndex - 1) * queryFilter.PageSize)
+                    .Take(totals- (queryFilter.PageIndex - 1) * queryFilter.PageSize);
                     //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
             }
             else
@@ -2866,14 +2989,16 @@ namespace wispro.sp.api.Controllers
                     .Include(pi => pi.Customer)
                     .Include(pi => pi.CalMonth)
                     .Include(pi => pi.ExternalHandler)
-                    .OrderConditions<PerformanceItem>(queryFilter.Sorts);
+                    .OrderConditions<PerformanceItem>(queryFilter.Sorts)
+                    .Skip((queryFilter.PageIndex - 1) * queryFilter.PageSize)
+                    .Take(queryFilter.PageSize);
                     //.Pager<PerformanceItem>(queryFilter.PageIndex, queryFilter.PageSize, out totals);
             }
             ret.TotalCount = totals;
 
 
 
-            var retList = response.ToList<PerformanceItem>().Skip((queryFilter.PageIndex-1) *queryFilter.PageSize).Take(queryFilter.PageSize);
+            var retList = response.ToList<PerformanceItem>();
 
 
             #region 将某些属性设为null,避免循环取值造成返回json过大

+ 26 - 1
wispro.sp.api/Job/UpdateJXDataFromIPEasyJob.cs

@@ -310,7 +310,6 @@ namespace wispro.sp.api.Job
             }
 
 
-
             if (keyValuePairs.ContainsKey("WordCount"))
             {
                 if (!string.IsNullOrEmpty(retObj.WordCount))
@@ -348,6 +347,32 @@ namespace wispro.sp.api.Job
                 }
             }
 
+            if (keyValuePairs.ContainsKey("ExternalHandler") && (Item.ExternalHandler == null || Item.ExternalHandler.Name != retObj.ExternalHandler) && !string.IsNullOrEmpty(retObj.ExternalHandler))
+            {
+                string name = retObj.ExternalHandler;
+
+                if (!string.IsNullOrEmpty(name))
+                {
+                    string temName = name.Split('-')[0].Trim();
+
+                    if (!name.Contains("君龙"))
+                    {
+                        temName = name;
+                    }
+                    var temExternalHandler = spDb.Staffs.Where<Staff>(s => s.Name == temName).FirstOrDefault();
+                    if (temExternalHandler == null)
+                    {
+                        //Item.Reviewer = new Staff() { Name = retObj.Reviewer };
+                    }
+                    else
+                    {
+                        //Item.Reviewer = temReviewer;
+                        Item.ExternalHandlerId = temExternalHandler.Id;
+                    }
+                }
+            }
+
+
             if (keyValuePairs.ContainsKey("ApplicationType") && Item.ApplicationType != retObj.ApplicationType && !string.IsNullOrEmpty(retObj.ApplicationType))
             {
                 Item.ApplicationType = retObj.ApplicationType;

+ 56 - 2
wispro.sp.web/Pages/AppCase/CaseManager.razor

@@ -155,6 +155,7 @@ RenderFragment gdIcon =
                                      @bind-SelectedRows="selectedItems"
                                      ScrollY="900"
                                      Loading="_loading"
+                                     RowClassName="@(x => (x.Data.isDanger()&& string.IsNullOrEmpty(x.Data.OverDueMemo))?"danger" : "")"
                                      OnChange="HandleTableChange" RemoteDataSource>
                         <RowTemplate>
                             <AntDesign.Selection Key="@(context.Id.ToString())" Width="50" Fixed="left" />
@@ -188,8 +189,15 @@ RenderFragment gdIcon =
                             </AntDesign.Column>
                             <AntDesign.Column Title="对外处理人" TData="string" Width="100">@(context.ExternalHandler == null ? "" : context.ExternalHandler.Name)</AntDesign.Column>
                             <AntDesign.Column Title="核稿人" TData="string" Width="100">@(context.Reviewer == null ? "" : context.Reviewer.Name)</AntDesign.Column>
-                            <ActionColumn>
-                                <Button Icon="refresh" @onclick="()=>OnRefresh(context)">刷新</Button>
+
+                            <ActionColumn Fixed="right">
+                                @if (HandlingCalMonth.Status == 0)
+                                {
+                                    <Button Icon="refresh" @onclick="()=>OnRefresh(context)">同步数据</Button>
+                                    @if(context.Type =="其他新申请"){
+                                        <Button Icon="setting" @onclick="()=>ONJXAllocationRatios(context)">绩效比率设置</Button>
+                                    }
+                                }
                             </ActionColumn>
                         </RowTemplate>
                         <ExpandTemplate>
@@ -218,3 +226,49 @@ RenderFragment gdIcon =
         }
     </ChildContent>
 </PageContainer>
+
+<Modal Title="@("绩效比率设定")"
+       Visible="@ShowSettingModal"
+       OnOk="@btnOk"
+       OnCancel="@btnCancel">
+
+    @if(CurrentItem.ExternalHandler != null && CurrentItem.ItemStaffs.Where(p=>p.DoPersonId == CurrentItem.ExternalHandlerId).Count() == 0)
+    {
+        <div>
+            <span>@($"对外处理人【{CurrentItem.ExternalHandler.Name}】"):</span>
+            <AntDesign.Input @bind-Value="@getAllocationRatio(CurrentItem.ExternalHandler).Ratio">
+                 <AddOnAfter>%</AddOnAfter>
+            </AntDesign.Input>
+        </div>
+    }
+    
+    @foreach(var it in CurrentItem.ItemStaffs)
+    {
+        <div>
+            <span> @($"处理人【{it.DoPerson.Name}】"): </span>
+            <AntDesign.Input @bind-Value="@getAllocationRatio(it.DoPerson).Ratio">
+                <AddOnAfter>%</AddOnAfter>
+            </AntDesign.Input>
+        </div>
+    }
+    
+    @if(CurrentItem.Reviewer != null 
+        && CurrentItem.ReviewerId != CurrentItem.ExternalHandlerId
+        && CurrentItem.ItemStaffs.Where(p=>p.DoPersonId == CurrentItem.ReviewerId).Count() == 0)
+    {
+        <div>
+            <span>@($"核稿人【{CurrentItem.Reviewer.Name}】"):</span>
+            <AntDesign.Input @bind-Value="@getAllocationRatio(CurrentItem.Reviewer).Ratio">
+                 <AddOnAfter>%</AddOnAfter>
+            </AntDesign.Input>
+        </div>
+    }
+  
+
+</Modal>
+
+<style>
+    .danger {
+        background-color: #fa3d2c;
+    }
+</style>

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

@@ -1,14 +1,17 @@
 using AntDesign;
 using AntDesign.TableModels;
 using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Web;
 using Microsoft.Extensions.Configuration;
 using ServiceStack;
+using ServiceStack.Script;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using wispro.sp.entity;
 using wispro.sp.share;
+using wispro.sp.web.Pages.Organization;
 using wispro.sp.web.Services;
 
 namespace wispro.sp.web.Pages.AppCase
@@ -218,6 +221,106 @@ namespace wispro.sp.web.Pages.AppCase
             StateHasChanged();
         }
 
+        private bool ShowSettingModal = false;
+        private List<AllocationRatio> allocationRatios = null;
+        private PerformanceItem CurrentItem = null;
+        async Task ONJXAllocationRatios(PerformanceItem item)
+        {
+            CurrentItem = item;
+            allocationRatios = await _ItemService.getARatios(item);
+
+            if(allocationRatios == null)
+            {
+                allocationRatios= new List<AllocationRatio>();
+            }
+
+            if(item.ReviewerId != null && allocationRatios.Where(p=>p.PersonId == item.ReviewerId ).Count()==0)
+            {
+                allocationRatios.Add(new AllocationRatio() { 
+                    ItemId = item.Id,
+                    PersonId = item.ReviewerId.Value,
+                    Ratio = 0,
+                    ActualAmount = 0
+                });
+            }
+
+            if (item.ExternalHandlerId != null && allocationRatios.Where(p => p.PersonId == item.ExternalHandlerId).Count() == 0)
+            {
+                allocationRatios.Add(new AllocationRatio()
+                {
+                    ItemId = item.Id,
+                    PersonId = item.ExternalHandlerId.Value,
+                    Ratio = 0,
+                    ActualAmount = 0
+                });
+            }
+
+            foreach(var iStaff in item.ItemStaffs)
+            {
+                if (allocationRatios.Where(p => p.PersonId == iStaff.DoPersonId).Count() == 0)
+                {
+                    allocationRatios.Add(new AllocationRatio()
+                    {
+                        ItemId = item.Id,
+                        PersonId = iStaff.DoPersonId,
+                        Ratio = 0,
+                        ActualAmount = 0
+                    });
+                }
+            }
+            ShowSettingModal = true;
+        }
+
+       
+        private AllocationRatio getAllocationRatio(Staff person)
+        {
+            var retObj= allocationRatios.Where(a => a.PersonId == person.Id).FirstOrDefault();
+            if (retObj == null)
+            {
+                retObj = new AllocationRatio() { 
+                    Person = person,
+                    PersonId = person.Id,
+                    Ratio = 0,
+                    ItemId = CurrentItem.Id
+                    
+                };
+            }
+            return retObj;
+        }
+
+        private async System.Threading.Tasks.Task btnOk(MouseEventArgs e)
+        {
+            foreach(var ar in allocationRatios)
+            {
+                ar.Person = null;
+                ar.Item = null;
+            }
+            Console.WriteLine("1");
+            var zeros = allocationRatios.Where(i => i.Ratio.Value == 0).ToList();
+            foreach(var a in zeros)
+            {
+                allocationRatios.Remove(a);
+            }
+            Console.WriteLine("2");
+            if (allocationRatios.Sum(i => i.Ratio.Value) == 100)
+            {
+
+                await _ItemService.SaveAllocationRatios(allocationRatios);
+                ShowSettingModal = false;
+                StateHasChanged();
+            }
+            else
+            {
+                Console.WriteLine("3");
+                await _message.Error("分配比率相加应该等于100!");
+            }
+        }
+
+        private void btnCancel(MouseEventArgs e)
+        {
+            ShowSettingModal = false;
+        }
+
         async Task<string> CalItemJX(PerformanceItem item)
         {
             return null;

+ 32 - 18
wispro.sp.web/Services/PerformanceItemServices.cs

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
 using wispro.sp.entity;
 using wispro.sp.share;
 using wispro.sp.web.Auth;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 
 namespace wispro.sp.web.Services
 {
@@ -17,7 +18,7 @@ namespace wispro.sp.web.Services
         private readonly IHttpService _httpClient;
         private readonly JwtAuthenticationStateProvider _jwt;
 
-        
+
 
         public PerformanceItemServices(IHttpService httpClient, AuthenticationStateProvider jwt)
         {
@@ -25,14 +26,14 @@ namespace wispro.sp.web.Services
             _jwt = (JwtAuthenticationStateProvider)jwt;
         }
 
-        public async Task<ListApiResponse<PerformanceItem>> GetItems(int _pageIndex,int _pageSize)
+        public async Task<ListApiResponse<PerformanceItem>> GetItems(int _pageIndex, int _pageSize)
         {
             ListApiResponse<PerformanceItem> data = await _httpClient.Get<ListApiResponse<PerformanceItem>>($"PerformanceItem/Query?pageIndex={_pageIndex}&pageSize={_pageSize}");
             return data;
 
         }
 
-        public async Task<ApiSaveResponse> SaveFieldChange(int id,string Field,string value)
+        public async Task<ApiSaveResponse> SaveFieldChange(int id, string Field, string value)
         {
             ApiSaveResponse data = await _httpClient.Get<ApiSaveResponse>($"PerformanceItem/UpdateFieldValue?id={id}&field={Field}&value={value}");
             return data;
@@ -44,13 +45,13 @@ namespace wispro.sp.web.Services
             return data;
         }
 
-        public async Task<ListApiResponse<PerformanceItem>> GetMyList(int userid,jxType type,int pageIndex=1,int pageSize=5)
+        public async Task<ListApiResponse<PerformanceItem>> GetMyList(int userid, jxType type, int pageIndex = 1, int pageSize = 5)
         {
             ListApiResponse<PerformanceItem> data = await _httpClient.Get<ListApiResponse<PerformanceItem>>($"PerformanceItem/GetMyList?userid={userid}&Type={Convert.ToInt32(type)}&pageIndex={pageIndex}&pageSize={pageSize}");
             return data;
         }
 
-        
+
         public async Task<FileProcessTask> ExportData(int calMonthId)
         {
             QueryFilter query = new QueryFilter();
@@ -64,10 +65,10 @@ namespace wispro.sp.web.Services
             var fileData = await _httpClient.Post<FileProcessTask>($"PerformanceItem/ExportData", query);
 
             return fileData;
-            
+
         }
 
-        public async Task<FileProcessTask> ExportJXReport(int Year,int month)
+        public async Task<FileProcessTask> ExportJXReport(int Year, int month)
         {
             var fileData = await _httpClient.Get<FileProcessTask>($"PerformanceItem/GetStaticsReport?Year={Year}&Month={month}");
             return fileData;
@@ -80,7 +81,7 @@ namespace wispro.sp.web.Services
             return fileData;
         }
 
-        public async Task<FileProcessTask> ExportData(int calMonthId, int userid, jxType jxType,int DoingOrReview=0)
+        public async Task<FileProcessTask> ExportData(int calMonthId, int userid, jxType jxType, int DoingOrReview = 0)
         {
             QueryFilter query = new QueryFilter();
             query.userId = userid;
@@ -93,7 +94,7 @@ namespace wispro.sp.web.Services
             query.ConditionTree = new List<FieldCondition>();
             query.Sorts = new List<OrderField>();
 
-            var fileData = await  _httpClient.Post<FileProcessTask>($"PerformanceItem/ExportData", query);
+            var fileData = await _httpClient.Post<FileProcessTask>($"PerformanceItem/ExportData", query);
 
             return fileData;
         }
@@ -105,7 +106,7 @@ namespace wispro.sp.web.Services
             return fileData;
         }
 
-        public async Task<ListApiResponse<PerformanceItem>> Query(CalMonth calMonth,int pageIndex,int pageSize,string sortFieldName)
+        public async Task<ListApiResponse<PerformanceItem>> Query(CalMonth calMonth, int pageIndex, int pageSize, string sortFieldName)
         {
             QueryFilter query = new QueryFilter();
             query.userId = 0;
@@ -122,14 +123,14 @@ namespace wispro.sp.web.Services
                 };
             }
 
-            
+
 
             var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter", query);
             return data;
 
         }
 
-        public async  Task<FileProcessTask> FinishedCalMonth(CalMonth calMonth)
+        public async Task<FileProcessTask> FinishedCalMonth(CalMonth calMonth)
         {
             var ret = await _httpClient.Get<FileProcessTask>($"PerformanceItem/FinishedCalMonth?year={calMonth.Year}&month={calMonth.Month}");
             return ret;
@@ -233,7 +234,7 @@ namespace wispro.sp.web.Services
 
         }
 
-        public async Task<ListApiResponse<PerformanceItem>> Query(int calMonthId, int userid, jxType type, QueryModel<PerformanceItem> queryModel,int DoingOrReview=0)
+        public async Task<ListApiResponse<PerformanceItem>> Query(int calMonthId, int userid, jxType type, QueryModel<PerformanceItem> queryModel, int DoingOrReview = 0)
         {
             QueryFilter query = new QueryFilter();
             query.CalMonthId = calMonthId;
@@ -326,7 +327,7 @@ namespace wispro.sp.web.Services
                 query.Sorts = new List<OrderField>();
             }
 
-            var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter",query);
+            var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter", query);
             //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(queryModel));
             return data;
         }
@@ -335,9 +336,9 @@ namespace wispro.sp.web.Services
         {
             var data = await _httpClient.Get<ApiSaveResponse>($"PerformanceItem/RefreshFromIPEasyById?itemId={Id}");
 
-            
+
             return await _httpClient.Get<PerformanceItem>($"PerformanceItem/PerformanceItem?Id={Id}");
-           
+
         }
 
         public async Task<List<StaffStatistics>> CalMyStatistics(int year, int month, int? userid = null)
@@ -353,17 +354,30 @@ namespace wispro.sp.web.Services
         }
 
         #region 绩效等级计算
-        public async Task StatisticsLevelCount(int year ,int month)
+        public async Task StatisticsLevelCount(int year, int month)
         {
             await _httpClient.Get<bool>($"PerformanceItem/StatisticsLevelCount?year={year}&month={month}");
         }
 
         public async Task<LevelStatisticsResult> CalAgentLevel(int year, int quarter, string GradeCode)
         {
-            var data =await _httpClient.Get<LevelStatisticsResult>($"PerformanceItem/CalAgentLevel?year={year}&quarter={quarter}&GradeCode={GradeCode}");
+            var data = await _httpClient.Get<LevelStatisticsResult>($"PerformanceItem/CalAgentLevel?year={year}&quarter={quarter}&GradeCode={GradeCode}");
+            return data;
+        }
+
+        public  async Task<List<AllocationRatio>> getARatios(PerformanceItem item)
+        {
+            var data = await _httpClient.Get<List<AllocationRatio>>($"PerformanceItem/CalAllocationRatios?itemId={item.Id}");
             return data;
         }
 
+        public async Task SaveAllocationRatios(List<AllocationRatio> allocationRatios)
+        {
+            await _httpClient.Post($"PerformanceItem/SaveAllocationRatios", allocationRatios);
+            
+            //throw new NotImplementedException();
+        }
+
         #endregion