OrganizationService.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using AntDesign;
  2. using AntDesign.TableModels;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using wispro.sp.entity;
  8. using wispro.sp.share;
  9. namespace wispro.sp.web.Services
  10. {
  11. public class OrganizationService
  12. {
  13. private readonly IHttpService _httpClient;
  14. public OrganizationService(IHttpService httpClient)
  15. {
  16. _httpClient = httpClient;
  17. }
  18. public async Task<Department> SaveDept(Department dept)
  19. {
  20. var data = await _httpClient.Post<Department>($"Organization/SaveDept",dept);
  21. return data;
  22. }
  23. public async Task<List<Department>> GetDepartments()
  24. {
  25. var data = await _httpClient.Get<List<Department>>($"Organization/GetDepartments");
  26. return data;
  27. }
  28. public async Task<List<Position>> getPositions(int? deptId)
  29. {
  30. var ret = await _httpClient.Get<List<Position>>($"Organization/GetPositions?deptId={deptId}");
  31. return ret;
  32. }
  33. public async Task<List<Customer>> GetAllCustomer()
  34. {
  35. var ret = await _httpClient.Get<List<Customer>>($"Organization/GetCustomers");
  36. return ret;
  37. }
  38. public async Task<bool> DeleteDept(int deptId)
  39. {
  40. var ret = await _httpClient.Get<bool>($"Organization/DeleteDept?Id={deptId}");
  41. return ret;
  42. }
  43. public async Task<ListApiResponse<Staff>> GetStaffs(Department dept,int _pageIndex,int _pageSize)
  44. {
  45. if (dept == null || dept.Id <= 0)
  46. {
  47. ListApiResponse<Staff> data = await _httpClient.Get<ListApiResponse<Staff>>($"Staff/Query?pageIndex={_pageIndex}&pageSize={_pageSize}");
  48. return data;
  49. }
  50. else
  51. {
  52. ListApiResponse<Staff> data = await _httpClient.Get<ListApiResponse<Staff>>($"Staff/QueryInDepartment?deptId={dept.Id}&pageIndex={_pageIndex}&pageSize={_pageSize}");
  53. return data;
  54. }
  55. }
  56. string GetRandomuserParams(QueryModel<Staff> queryModel)
  57. {
  58. List<string> query = new List<string>()
  59. {
  60. $"pageSize={queryModel.PageSize}",
  61. $"pageIndex={queryModel.PageIndex}",
  62. };
  63. queryModel.SortModel.ForEach(x =>
  64. {
  65. if (x.Sort != null)
  66. {
  67. query.Add($"sortField={x.FieldName.ToLower()}");
  68. query.Add($"sortOrder={x.Sort}");
  69. }
  70. });
  71. queryModel.FilterModel.ForEach(filter =>
  72. {
  73. filter.SelectedValues.ForEach(value =>
  74. {
  75. query.Add($"{filter.FieldName.ToLower()}={value}");
  76. });
  77. });
  78. return string.Join('&', query);
  79. }
  80. public async Task<ListApiResponse<Staff>> GetStaffs(Department dept, QueryModel<Staff> queryModel)
  81. {
  82. ListApiResponse<Staff> data = await _httpClient.Get<ListApiResponse<Staff>>($"Staff/Query?DeptId={dept.Id}&" + GetRandomuserParams(queryModel));
  83. return data;
  84. }
  85. public async Task<List<wispro.sp.entity.StaffGrade>> GetStaffGrades()
  86. {
  87. var data = await _httpClient.Get<List<wispro.sp.entity.StaffGrade>>($"StaffGrade/GetAll");
  88. return data;
  89. }
  90. public async Task<ApiSaveResponse> SaveUser(Department dept,Position position,Staff staff)
  91. {
  92. SaveUserObject saveUser = new SaveUserObject();
  93. if (dept != null)
  94. {
  95. saveUser.deptId = dept.Id;
  96. }
  97. saveUser.positionId = position.Id;
  98. saveUser.staff = staff;
  99. var data =await _httpClient.Post<ApiSaveResponse>("Staff/SaveUser", saveUser);
  100. return data;
  101. }
  102. public async Task<ApiSaveResponse> SaveCustomer(Customer customer)
  103. {
  104. var data = await _httpClient.Post<ApiSaveResponse>("Organization/SaveCustomer", customer);
  105. return data;
  106. }
  107. public async Task<Customer> GetCustomer(int id)
  108. {
  109. var data = await _httpClient.Get<Customer>($"Organization/GetCustomer?id={id}");
  110. return data;
  111. }
  112. public async Task Init()
  113. {
  114. await _httpClient.Get<ApiSaveResponse>("Staff/Init");
  115. }
  116. public async Task<Position> getPosition(Staff staff, Department editDepartment)
  117. {
  118. try
  119. {
  120. var data = await _httpClient.Get<Position>($"Organization/GetPosition?deptId={editDepartment.Id}&staffId={staff.Id}");
  121. return data;
  122. }
  123. catch
  124. {
  125. return null;
  126. }
  127. }
  128. }
  129. }