PerformanceItemServices.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using AntDesign.TableModels;
  2. using Microsoft.AspNetCore.Components.Authorization;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.Http;
  7. using System.Net.Http.Json;
  8. using System.Threading.Tasks;
  9. using wispro.sp.entity;
  10. using wispro.sp.share;
  11. using wispro.sp.web.Auth;
  12. namespace wispro.sp.web.Services
  13. {
  14. public class PerformanceItemServices
  15. {
  16. private readonly IHttpService _httpClient;
  17. private readonly JwtAuthenticationStateProvider _jwt;
  18. public PerformanceItemServices(IHttpService httpClient, AuthenticationStateProvider jwt)
  19. {
  20. _httpClient = httpClient;
  21. _jwt = (JwtAuthenticationStateProvider)jwt;
  22. }
  23. public async Task<ListApiResponse<PerformanceItem>> GetItems(int _pageIndex,int _pageSize)
  24. {
  25. ListApiResponse<PerformanceItem> data = await _httpClient.Get<ListApiResponse<PerformanceItem>>($"PerformanceItem/Query?pageIndex={_pageIndex}&pageSize={_pageSize}");
  26. return data;
  27. }
  28. public async Task<ApiSaveResponse> SaveFieldChange(int id,string Field,string value)
  29. {
  30. ApiSaveResponse data = await _httpClient.Get<ApiSaveResponse>($"PerformanceItem/UpdateFieldValue?id={id}&field={Field}&value={value}");
  31. return data;
  32. }
  33. public async Task<PerformanceItem> GetPerformancItem(int Id)
  34. {
  35. PerformanceItem data = await _httpClient.Get<PerformanceItem>($"PerformanceItem/Get?Id={Id}");
  36. return data;
  37. }
  38. public async Task<ListApiResponse<PerformanceItem>> GetMyList(int userid,jxType type,int pageIndex=1,int pageSize=5)
  39. {
  40. ListApiResponse<PerformanceItem> data = await _httpClient.Get<ListApiResponse<PerformanceItem>>($"PerformanceItem/GetMyList?userid={userid}&Type={Convert.ToInt32(type)}&pageIndex={pageIndex}&pageSize={pageSize}");
  41. return data;
  42. }
  43. public async Task<ListApiResponse<PerformanceItem>> Query(int userid, jxType type, QueryModel<PerformanceItem> queryModel)
  44. {
  45. QueryFilter query = new QueryFilter();
  46. query.userId = userid;
  47. query.jxType = type;
  48. query.PageIndex = queryModel.PageIndex;
  49. query.PageSize = queryModel.PageSize;
  50. query.ConditionTree = new List<FieldCondition>();
  51. foreach(var filter in queryModel.FilterModel)
  52. {
  53. foreach(var f in filter.Filters)
  54. {
  55. FieldCondition condition = new FieldCondition() { FieldName = filter.FieldName};
  56. condition.Value = f.Value.ToString();
  57. condition.ValueType = typeof(PerformanceItem).GetProperty(filter.FieldName).PropertyType.ToString();
  58. switch (f.FilterCompareOperator)
  59. {
  60. case AntDesign.TableFilterCompareOperator.Contains:
  61. condition.Operator = OperatorEnum.Contains;
  62. break;
  63. case AntDesign.TableFilterCompareOperator.EndsWith:
  64. condition.Operator = OperatorEnum.EndWith;
  65. break;
  66. case AntDesign.TableFilterCompareOperator.Equals:
  67. condition.Operator = OperatorEnum.EndWith;
  68. break;
  69. case AntDesign.TableFilterCompareOperator.GreaterThan:
  70. condition.Operator = OperatorEnum.Greater ;
  71. break;
  72. case AntDesign.TableFilterCompareOperator.GreaterThanOrEquals:
  73. condition.Operator = OperatorEnum.GreaterEqual;
  74. break;
  75. case AntDesign.TableFilterCompareOperator.LessThan:
  76. condition.Operator = OperatorEnum.Less;
  77. break;
  78. case AntDesign.TableFilterCompareOperator.LessThanOrEquals:
  79. condition.Operator = OperatorEnum.LessEqual;
  80. break;
  81. case AntDesign.TableFilterCompareOperator.NotContains:
  82. condition.Operator = OperatorEnum.NotContains;
  83. break;
  84. case AntDesign.TableFilterCompareOperator.NotEquals:
  85. condition.Operator = OperatorEnum.NotEqual;
  86. break;
  87. case AntDesign.TableFilterCompareOperator.StartsWith:
  88. condition.Operator = OperatorEnum.StartsWith;
  89. break;
  90. }
  91. switch (f.FilterCondition)
  92. {
  93. case AntDesign.TableFilterCondition.And:
  94. condition.LogicOperate = LogicEnum.And;
  95. break;
  96. case AntDesign.TableFilterCondition.Or:
  97. condition.LogicOperate = LogicEnum.Or;
  98. break;
  99. default:
  100. condition.LogicOperate = LogicEnum.And;
  101. break;
  102. }
  103. query.ConditionTree.Add(condition);
  104. }
  105. }
  106. query.Sorts =new List<OrderField>();
  107. foreach(var sort in queryModel.SortModel)
  108. {
  109. if (!string.IsNullOrEmpty(sort.Sort))
  110. {
  111. query.Sorts.Add(new OrderField() { FieldName = sort.FieldName, Sort = (sort.Sort == "descend" ? 1 : 0) });
  112. }
  113. }
  114. var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter",query);
  115. //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(queryModel));
  116. return data;
  117. }
  118. public async Task<List<StaffStatistics>> CalMyStatistics(int year, int month, int? userid = null)
  119. {
  120. var data = await _httpClient.Get<List<StaffStatistics>>($"PerformanceItem/CalMyStatistics?userid={userid}&year={year}&month={month}");
  121. return data;
  122. }
  123. public async Task<PerformanceItem> GetProjectInfo(string caseNo)
  124. {
  125. var data = await _httpClient.Get<PerformanceItem>($"PerformanctItem/GetCaseInfo?CaseNo={caseNo}");
  126. return data;
  127. }
  128. public async Task<ApiSaveResponse> AddProjectPerformanctItem(ProjectPointRecord projectPoint)
  129. {
  130. var data = await _httpClient.Post<ApiSaveResponse>($"PerformanceItem/AddProjectPerformance",projectPoint);
  131. return data;
  132. }
  133. }
  134. }