using AntDesign.TableModels; using Microsoft.AspNetCore.Components.Authorization; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Json; 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 { public class PerformanceItemServices { private readonly IHttpService _httpClient; private readonly JwtAuthenticationStateProvider _jwt; public PerformanceItemServices(IHttpService httpClient, AuthenticationStateProvider jwt) { _httpClient = httpClient; _jwt = (JwtAuthenticationStateProvider)jwt; } public async Task> GetItems(int _pageIndex, int _pageSize) { ListApiResponse data = await _httpClient.Get>($"PerformanceItem/Query?pageIndex={_pageIndex}&pageSize={_pageSize}"); return data; } public async Task SaveFieldChange(int id, string Field, string value) { ApiSaveResponse data = await _httpClient.Get($"PerformanceItem/UpdateFieldValue?id={id}&field={Field}&value={value}"); return data; } public async Task GetPerformancItem(int Id) { PerformanceItem data = await _httpClient.Get($"PerformanceItem/Get?Id={Id}"); return data; } public async Task> GetMyList(int userid, jxType type, int pageIndex = 1, int pageSize = 5) { ListApiResponse data = await _httpClient.Get>($"PerformanceItem/GetMyList?userid={userid}&Type={Convert.ToInt32(type)}&pageIndex={pageIndex}&pageSize={pageSize}"); return data; } public async Task ExportData(int calMonthId) { QueryFilter query = new QueryFilter(); query.CalMonthId = calMonthId; query.PageIndex = 1; query.PageSize = 1; query.ConditionTree = new List(); query.Sorts = new List(); var fileData = await _httpClient.Post($"PerformanceItem/ExportData", query); return fileData; } public async Task ExportJXReport(int Year, int month) { var fileData = await _httpClient.Get($"PerformanceItem/GetStaticsReport?Year={Year}&Month={month}"); return fileData; } public async Task ExportJXPointReport(int Year, int month) { var fileData = await _httpClient.Get($"PerformanceItem/GetStaticsPointReport?Year={Year}&Month={month}"); return fileData; } public async Task ExportJXMoneyAsync(int Year, int month) { var fileData = await _httpClient.Get($"PerformanceItem/GetOtherNewCaseAllocationReport?Year={Year}&Month={month}"); return fileData; } public async Task ExportJXTotalMoneyAsync(int Year, int month) { var fileData = await _httpClient.Get($"PerformanceItem/OtherNewCaseAllocationReport?Year={Year}&Month={month}"); return fileData; } public async Task CurrentData2Excel(CalMonth calMonth) { var fileData = await _httpClient.Get($"PerformanceItem/CurrentData2Excel?Year={calMonth.Year}&Month={calMonth.Month}"); return fileData; } public async Task ExportData(int calMonthId, int userid, jxType jxType, int DoingOrReview = 0) { QueryFilter query = new QueryFilter(); query.userId = userid; query.jxType = jxType; query.CalMonthId = calMonthId; query.DoingOrReview = DoingOrReview; query.PageIndex = 1; query.PageSize = 1; query.ConditionTree = new List(); query.Sorts = new List(); var fileData = await _httpClient.Post($"PerformanceItem/ExportData", query); return fileData; } public async Task getExportDataProcessing(string id) { var fileData = await _httpClient.Get($"FileProcesTask/Get?Id={id}"); return fileData; } public async Task> Query(CalMonth calMonth, int pageIndex, int pageSize, string sortFieldName) { QueryFilter query = new QueryFilter(); query.userId = 0; query.jxType = jxType.all; query.CalMonthId = calMonth.Id; query.PageIndex = pageIndex; query.PageSize = pageSize; if (!string.IsNullOrEmpty(sortFieldName)) { query.Sorts = new List() { new OrderField(){FieldName = sortFieldName} }; } var data = await _httpClient.Post>($"PerformanceItem/QueryFilter", query); return data; } public async Task FinishedCalMonth(CalMonth calMonth) { var ret = await _httpClient.Get($"PerformanceItem/FinishedCalMonth?year={calMonth.Year}&month={calMonth.Month}"); return ret; } public async Task> Query(CalMonth calMonth, QueryModel queryModel) { QueryFilter query = new QueryFilter(); query.userId = 0; query.jxType = jxType.all; query.CalMonthId = calMonth.Id; if (queryModel != null) { query.PageIndex = queryModel.PageIndex; query.PageSize = queryModel.PageSize; query.ConditionTree = new List(); foreach (var filter in queryModel.FilterModel) { foreach (var f in filter.Filters) { FieldCondition condition = new FieldCondition() { FieldName = filter.FieldName }; condition.Value = f.Value.ToString(); condition.ValueType = typeof(PerformanceItem).GetProperty(filter.FieldName).PropertyType.ToString(); switch (f.FilterCompareOperator) { case AntDesign.TableFilterCompareOperator.Contains: condition.Operator = OperatorEnum.Contains; break; case AntDesign.TableFilterCompareOperator.EndsWith: condition.Operator = OperatorEnum.EndWith; break; case AntDesign.TableFilterCompareOperator.Equals: condition.Operator = OperatorEnum.EndWith; break; case AntDesign.TableFilterCompareOperator.GreaterThan: condition.Operator = OperatorEnum.Greater; break; case AntDesign.TableFilterCompareOperator.GreaterThanOrEquals: condition.Operator = OperatorEnum.GreaterEqual; break; case AntDesign.TableFilterCompareOperator.LessThan: condition.Operator = OperatorEnum.Less; break; case AntDesign.TableFilterCompareOperator.LessThanOrEquals: condition.Operator = OperatorEnum.LessEqual; break; case AntDesign.TableFilterCompareOperator.NotContains: condition.Operator = OperatorEnum.NotContains; break; case AntDesign.TableFilterCompareOperator.NotEquals: condition.Operator = OperatorEnum.NotEqual; break; case AntDesign.TableFilterCompareOperator.StartsWith: condition.Operator = OperatorEnum.StartsWith; break; } switch (f.FilterCondition) { case AntDesign.TableFilterCondition.And: condition.LogicOperate = LogicEnum.And; break; case AntDesign.TableFilterCondition.Or: condition.LogicOperate = LogicEnum.Or; break; default: condition.LogicOperate = LogicEnum.And; break; } query.ConditionTree.Add(condition); } } query.Sorts = new List(); foreach (var sort in queryModel.SortModel) { if (!string.IsNullOrEmpty(sort.Sort)) { query.Sorts.Add(new OrderField() { FieldName = sort.FieldName, Sort = (sort.Sort == "descend" ? 1 : 0) }); } } } else { query.PageIndex = 1; query.PageSize = 1; query.ConditionTree = new List(); query.Sorts = new List(); } var data = await _httpClient.Post>($"PerformanceItem/QueryFilter", query); //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(queryModel)); return data; } public async Task> Query(int calMonthId, int userid, jxType type, QueryModel queryModel, int DoingOrReview = 0) { QueryFilter query = new QueryFilter(); query.CalMonthId = calMonthId; query.userId = userid; query.jxType = type; query.DoingOrReview = DoingOrReview; if (queryModel != null) { query.PageIndex = queryModel.PageIndex; query.PageSize = queryModel.PageSize; query.ConditionTree = new List(); foreach (var filter in queryModel.FilterModel) { foreach (var f in filter.Filters) { FieldCondition condition = new FieldCondition() { FieldName = filter.FieldName }; condition.Value = f.Value.ToString(); condition.ValueType = typeof(PerformanceItem).GetProperty(filter.FieldName).PropertyType.ToString(); switch (f.FilterCompareOperator) { case AntDesign.TableFilterCompareOperator.Contains: condition.Operator = OperatorEnum.Contains; break; case AntDesign.TableFilterCompareOperator.EndsWith: condition.Operator = OperatorEnum.EndWith; break; case AntDesign.TableFilterCompareOperator.Equals: condition.Operator = OperatorEnum.EndWith; break; case AntDesign.TableFilterCompareOperator.GreaterThan: condition.Operator = OperatorEnum.Greater; break; case AntDesign.TableFilterCompareOperator.GreaterThanOrEquals: condition.Operator = OperatorEnum.GreaterEqual; break; case AntDesign.TableFilterCompareOperator.LessThan: condition.Operator = OperatorEnum.Less; break; case AntDesign.TableFilterCompareOperator.LessThanOrEquals: condition.Operator = OperatorEnum.LessEqual; break; case AntDesign.TableFilterCompareOperator.NotContains: condition.Operator = OperatorEnum.NotContains; break; case AntDesign.TableFilterCompareOperator.NotEquals: condition.Operator = OperatorEnum.NotEqual; break; case AntDesign.TableFilterCompareOperator.StartsWith: condition.Operator = OperatorEnum.StartsWith; break; } switch (f.FilterCondition) { case AntDesign.TableFilterCondition.And: condition.LogicOperate = LogicEnum.And; break; case AntDesign.TableFilterCondition.Or: condition.LogicOperate = LogicEnum.Or; break; default: condition.LogicOperate = LogicEnum.And; break; } query.ConditionTree.Add(condition); } } query.Sorts = new List(); foreach (var sort in queryModel.SortModel) { if (!string.IsNullOrEmpty(sort.Sort)) { query.Sorts.Add(new OrderField() { FieldName = sort.FieldName, Sort = (sort.Sort == "descend" ? 1 : 0) }); } } } else { query.PageIndex = 1; query.PageSize = 1; query.ConditionTree = new List(); query.Sorts = new List(); } var data = await _httpClient.Post>($"PerformanceItem/QueryFilter", query); //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(queryModel)); return data; } public async Task RefreshItem(int Id) { var data = await _httpClient.Get($"PerformanceItem/RefreshFromIPEasyById?itemId={Id}"); return await _httpClient.Get($"PerformanceItem/PerformanceItem?Id={Id}"); } public async Task> CalMyStatistics(int year, int month, int? userid = null) { var data = await _httpClient.Get>($"PerformanceItem/CalMyStatistics?userid={userid}&year={year}&month={month}"); return data; } public async Task> CalItemStatistics(int ItemId) { var data = await _httpClient.Get>($"PerformanceItem/CalItemJX?itemid={ItemId}"); return data; } #region 绩效等级计算 public async Task StatisticsLevelCount(int year, int month) { await _httpClient.Get($"PerformanceItem/StatisticsLevelCount?year={year}&month={month}"); } public async Task CalAgentLevel(int year, int quarter, string GradeCode) { var data = await _httpClient.Get($"PerformanceItem/CalAgentLevel?year={year}&quarter={quarter}&GradeCode={GradeCode}"); return data; } public async Task> getARatios(PerformanceItem item) { var data = await _httpClient.Get>($"PerformanceItem/CalAllocationRatios?itemId={item.Id}"); return data; } public async Task SaveAllocationRatios(List allocationRatios) { await _httpClient.Post($"PerformanceItem/SaveAllocationRatios", allocationRatios); //throw new NotImplementedException(); } #endregion } }