RegionProvider.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using ivf_tl_Entity.ControlEntity;
  2. using ivf_tl_Entity.Entity.balance;
  3. using ivf_tl_Entity.Entity.Result;
  4. using ivf_tl_Entity.Enums;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Xml.Linq;
  13. namespace ivf_tl_Service.HttpProvider
  14. {
  15. public class RegionProvider
  16. {
  17. LogService LogService { get; set; }
  18. HttpServiceCall httpServiceCall1 { get; set; }
  19. public RegionProvider(HttpServiceCall _httpServiceCall, LogService _logService)
  20. {
  21. httpServiceCall1 = _httpServiceCall;
  22. LogService = _logService;
  23. }
  24. private void ExLog(Exception ex, string name)
  25. {
  26. LogService.ExceptionLog(ex, $"RegionProvider.{name}", LogEnum.RunException);
  27. }
  28. private void ErrorLog(string message, LogEnum logType)
  29. {
  30. LogService.TLLog($"RegionProvider.{message}", logType);
  31. }
  32. public ObservableCollection<AddressEntity> GetRegionData()
  33. {
  34. string funcName = "GetRegionData";
  35. try
  36. {
  37. string url = "/api/tl/control/data/getReign";
  38. string json = httpServiceCall1.callWebService(url,true);
  39. if (string.IsNullOrEmpty(json)) return new ObservableCollection<AddressEntity>();
  40. var result = JsonConvert.DeserializeObject<ResultEntity<ObservableCollection<AddressEntity>>>(json);
  41. if (!result.success)
  42. {
  43. ErrorLog($"{funcName}接口返回失败:{json}", LogEnum.RunError);
  44. return new ObservableCollection<AddressEntity>();
  45. }
  46. if(result.data != null) return result.data;
  47. ErrorLog($"{funcName}接口返回成功但是无数据 {json}", LogEnum.RunError);
  48. return new ObservableCollection<AddressEntity>();
  49. }
  50. catch (Exception ex)
  51. {
  52. ExLog(ex, funcName);
  53. return new ObservableCollection<AddressEntity>();
  54. }
  55. }
  56. }
  57. }