AppealTypeService.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. Console.WriteLine(at.CanDoExpress);
  41. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(at.CanDoExpress, "p");
  42. bool result = func.Invoke(item);
  43. if (result)
  44. {
  45. retList.Add(at);
  46. }
  47. }
  48. else
  49. {
  50. retList.Add(at);
  51. }
  52. }
  53. return retList;
  54. }
  55. public async Task<AppealType> GetItem(int appealTypeId)
  56. {
  57. if (AppealTypes == null)
  58. {
  59. AppealTypes = await _httpClient.GetFromJsonAsync<List<AppealType>>($"http://localhost:39476/api/Appeal/GetAppealTypes");
  60. }
  61. var retData = AppealTypes.Where<AppealType>(ap => ap.Id == appealTypeId).FirstOrDefault();
  62. return retData;
  63. }
  64. public async Task<List<InputField>> GetInputFields(int appealTypeId,int State)
  65. {
  66. var data = await _httpClient.GetFromJsonAsync<List<InputField>>($"http://localhost:39476/api/Appeal/GetInputField?appealTypeId={appealTypeId}&state={State}");
  67. return data;
  68. }
  69. }
  70. }