AppealTypeService.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using DynamicExpresso;
  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 AppealTypeService
  15. {
  16. private readonly HttpClient _httpClient;
  17. private readonly JwtAuthenticationStateProvider _jwt;
  18. private List<AppealType> AppealTypes;
  19. public AppealTypeService(HttpClient httpClient, AuthenticationStateProvider jwt)
  20. {
  21. _httpClient = httpClient;
  22. _jwt = (JwtAuthenticationStateProvider)jwt;
  23. }
  24. public async Task<List<AppealType>> GetItems()
  25. {
  26. if (AppealTypes == null)
  27. {
  28. AppealTypes = await _httpClient.GetFromJsonAsync<List<AppealType>>($"http://localhost:39476/api/Appeal/GetAppealTypes");
  29. }
  30. return AppealTypes;
  31. }
  32. public List<AppealType> GetItems(PerformanceItem item)
  33. {
  34. List<AppealType> retList = new List<AppealType>();
  35. foreach (var at in AppealTypes)
  36. {
  37. if (!string.IsNullOrWhiteSpace(at.CanDoExpress))
  38. {
  39. var interpreter = new Interpreter();
  40. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(at.CanDoExpress, "p");
  41. bool result = func.Invoke(item);
  42. if (result)
  43. {
  44. retList.Add(at);
  45. }
  46. }
  47. else
  48. {
  49. retList.Add(at);
  50. }
  51. }
  52. return retList;
  53. }
  54. public async Task<AppealType> GetItem(int appealTypeId)
  55. {
  56. if (AppealTypes == null)
  57. {
  58. AppealTypes = await _httpClient.GetFromJsonAsync<List<AppealType>>($"http://localhost:39476/api/Appeal/GetAppealTypes");
  59. }
  60. var retData = AppealTypes.Where<AppealType>(ap => ap.Id == appealTypeId).FirstOrDefault();
  61. return retData;
  62. }
  63. public async Task<List<InputField>> GetInputFields(int appealTypeId,int State)
  64. {
  65. var data = await _httpClient.GetFromJsonAsync<List<InputField>>($"http://localhost:39476/api/Appeal/GetInputField?appealTypeId={appealTypeId}&state={State}");
  66. return data;
  67. }
  68. }
  69. }