AppealTypeService.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.Text.Json;
  9. using System.Threading.Tasks;
  10. using wispro.sp.entity;
  11. using wispro.sp.share;
  12. using wispro.sp.web.Auth;
  13. using wispro.sp.web.Models;
  14. namespace wispro.sp.web.Services
  15. {
  16. public class AppealTypeService
  17. {
  18. private readonly HttpClient _httpClient;
  19. private readonly JwtAuthenticationStateProvider _jwt;
  20. private List<AppealType> AppealTypes;
  21. public AppealTypeService(HttpClient httpClient, AuthenticationStateProvider jwt)
  22. {
  23. _httpClient = httpClient;
  24. _jwt = (JwtAuthenticationStateProvider)jwt;
  25. }
  26. public async Task<AppealRecord> getAppealRecord(int appealRecordId)
  27. {
  28. var data = await _httpClient.GetFromJsonAsync<AppealRecord>($"http://localhost:39476/api/Appeal/GetAppealRecord?Id={appealRecordId}");
  29. return data;
  30. }
  31. public async Task<List<InputFieldValue>> GetInputFieldValues(int id, int state)
  32. {
  33. var data = await _httpClient.GetFromJsonAsync<List<InputFieldValue>>($"http://localhost:39476/api/Appeal/GetInputFieldValues?Id={id}&state={state}");
  34. return data;
  35. }
  36. public async Task<List<AppealType>> GetItems()
  37. {
  38. if (AppealTypes == null)
  39. {
  40. AppealTypes = await _httpClient.GetFromJsonAsync<List<AppealType>>($"http://localhost:39476/api/Appeal/GetAppealTypes");
  41. }
  42. return AppealTypes;
  43. }
  44. public List<AppealType> GetItems(PerformanceItem item)
  45. {
  46. List<AppealType> retList = new List<AppealType>();
  47. foreach (var at in AppealTypes)
  48. {
  49. if (!string.IsNullOrWhiteSpace(at.CanDoExpress))
  50. {
  51. var interpreter = new Interpreter();
  52. //Console.WriteLine(at.CanDoExpress);
  53. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(at.CanDoExpress, "p");
  54. bool result = func.Invoke(item);
  55. if (result)
  56. {
  57. retList.Add(at);
  58. }
  59. }
  60. else
  61. {
  62. retList.Add(at);
  63. }
  64. }
  65. return retList;
  66. }
  67. public async Task<List<AppealRecord>> GetUserAppeals(int? userid)
  68. {
  69. var data = await _httpClient.GetFromJsonAsync<List<AppealRecord>>($"http://localhost:39476/api/Appeal/GetAppealRecords?userId={userid}");
  70. return data;
  71. }
  72. public async Task<AppealType> GetItem(int appealTypeId)
  73. {
  74. if (AppealTypes == null)
  75. {
  76. AppealTypes = await _httpClient.GetFromJsonAsync<List<AppealType>>($"http://localhost:39476/api/Appeal/GetAppealTypes");
  77. }
  78. var retData = AppealTypes.Where<AppealType>(ap => ap.Id == appealTypeId).FirstOrDefault();
  79. return retData;
  80. }
  81. public async Task<List<InputField>> GetInputFields(int appealTypeId,int State)
  82. {
  83. Console.WriteLine($"begin GetInputFields: appealTypeId={appealTypeId};State={State}");
  84. var data = await _httpClient.GetFromJsonAsync<List<InputField>>($"http://localhost:39476/api/Appeal/GetInputField?appealTypeId={appealTypeId}&state={State}");
  85. return data;
  86. }
  87. public async Task<List<AttachFile>> GetAppealRecordAttachFiles(int appealRecordId)
  88. {
  89. var data = await _httpClient.GetFromJsonAsync<List<AttachFile>>($"http://localhost:39476/api/Appeal/GetAppealRecordAttachFiles?appealRecordId={appealRecordId}");
  90. return data;
  91. }
  92. public async Task CreateAppeal(CreateAppealModel model)
  93. {
  94. List<AttachFile> attachFiles = new List<AttachFile>();
  95. foreach (var file in model.FileList)
  96. {
  97. AttachFile atfile = new AttachFile();
  98. var result = file.GetResponse<List<AttachFile>>();
  99. atfile.Id = result[0].Id;
  100. attachFiles.Add(atfile);
  101. }
  102. string strUrl = $"http://localhost:39476/api/Appeal/CreateAppeal?ItemId={model.Item.Id}&typeid={model.AppealType.Id}&reviewerId={model.AppealRecord.ReviewerId}";
  103. AppealObject appealObject = new AppealObject();
  104. appealObject.attachFiles = attachFiles;
  105. appealObject.inputFieldValues = model.inputFieldValues;
  106. foreach(var fValue in appealObject.inputFieldValues)
  107. {
  108. fValue.InputField = null;
  109. }
  110. var data = await _httpClient.PostAsJsonAsync<AppealObject>(strUrl, appealObject);
  111. Console.WriteLine(JsonSerializer.Serialize(data));
  112. }
  113. public async Task ReviewerAppeal(ReviewerAppealModel model)
  114. {
  115. string strUrl = $"http://localhost:39476/api/Appeal/ReviewerAppeal?appealRecordId={model.AppealRecord.Id}";
  116. AppealObject appealObject = new AppealObject();
  117. appealObject.inputFieldValues = model.inputFieldValues;
  118. foreach (var fValue in appealObject.inputFieldValues)
  119. {
  120. fValue.InputField = null;
  121. }
  122. var data = await _httpClient.PostAsJsonAsync<AppealObject>(strUrl, appealObject);
  123. if (!data.IsSuccessStatusCode)
  124. {
  125. string strContent = await data.Content.ReadAsStringAsync();
  126. throw new Exception(strContent);
  127. }
  128. }
  129. }
  130. }