SchoolsService.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using TEAMModelOS.Model.Core;
  6. using TEAMModelOS.SDK.Context.Configuration;
  7. using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
  8. using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
  9. using TEAMModelOS.SDK.Extension.HttpClient.Implements;
  10. using TEAMModelOS.SDK.Helper.Common.JsonHelper;
  11. using TEAMModelOS.Service.Core.Interfaces;
  12. namespace TEAMModelOS.Service.Core.Implements
  13. {
  14. public class SchoolsService : ISchoolsService
  15. {
  16. private readonly HttpClientSchool _httpClientSchool;
  17. public SchoolsService(HttpClientSchool httpClientSchool) {
  18. _httpClientSchool = httpClientSchool;
  19. }
  20. public async Task<List<SchoolInfo>> GetSchools(JosnRPCRequest<FindSchoolByCode> getSchool)
  21. {
  22. string schoolString = await RequestSchoolInfo(getSchool);
  23. if (!string.IsNullOrEmpty(schoolString))
  24. {
  25. JosnRPCResponse<List<SchoolInfo>> response = MessagePackHelper.JsonToObject<JosnRPCResponse<List<SchoolInfo>>>(schoolString);
  26. if (response.error == null && response != null)
  27. {
  28. List<SchoolInfo> schoolInfo = response.result;
  29. return schoolInfo;
  30. }
  31. else return null;
  32. }
  33. else return null;
  34. }
  35. private async Task<string> RequestSchoolInfo(JosnRPCRequest<FindSchoolByCode> getSchool) {
  36. string SchoolCodeKey = BaseConfigModel.Configuration["HaBookAuth:SchoolCodeKey"];
  37. Dictionary<string, string> dict = new Dictionary<string, string>
  38. {
  39. { "Authorization", SchoolCodeKey }
  40. };
  41. Dictionary<string, object> codeInfo = new Dictionary<string, object>
  42. {
  43. { "countryId", getSchool.@params.CountryId },
  44. { "provinceId", getSchool.@params.ProvinceId },
  45. { "cityId", getSchool.@params.CityId }
  46. };
  47. Dictionary<string, object> data = new Dictionary<string, object>
  48. {
  49. { "data", codeInfo }
  50. };
  51. JosnRPCRequest<Dictionary<string, object>> request = new JosnRPCRequest<Dictionary<string, object>>
  52. {
  53. @params = data,
  54. method = "SchoolCode"
  55. };
  56. string postData = MessagePackHelper.ObjectToJson(request);
  57. return await _httpClientSchool.HttpPostAsync(BaseConfigModel.Configuration["HaBookAuth:ServiceUrl"], postData);
  58. }
  59. }
  60. }