CityFunction.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. class CityFunction(object):
  6. def __init__(self):
  7. self._city_code = None
  8. self._city_name = None
  9. self._function_type = None
  10. @property
  11. def city_code(self):
  12. return self._city_code
  13. @city_code.setter
  14. def city_code(self, value):
  15. self._city_code = value
  16. @property
  17. def city_name(self):
  18. return self._city_name
  19. @city_name.setter
  20. def city_name(self, value):
  21. self._city_name = value
  22. @property
  23. def function_type(self):
  24. return self._function_type
  25. @function_type.setter
  26. def function_type(self, value):
  27. if isinstance(value, list):
  28. self._function_type = list()
  29. for i in value:
  30. self._function_type.append(i)
  31. def to_alipay_dict(self):
  32. params = dict()
  33. if self.city_code:
  34. if hasattr(self.city_code, 'to_alipay_dict'):
  35. params['city_code'] = self.city_code.to_alipay_dict()
  36. else:
  37. params['city_code'] = self.city_code
  38. if self.city_name:
  39. if hasattr(self.city_name, 'to_alipay_dict'):
  40. params['city_name'] = self.city_name.to_alipay_dict()
  41. else:
  42. params['city_name'] = self.city_name
  43. if self.function_type:
  44. if isinstance(self.function_type, list):
  45. for i in range(0, len(self.function_type)):
  46. element = self.function_type[i]
  47. if hasattr(element, 'to_alipay_dict'):
  48. self.function_type[i] = element.to_alipay_dict()
  49. if hasattr(self.function_type, 'to_alipay_dict'):
  50. params['function_type'] = self.function_type.to_alipay_dict()
  51. else:
  52. params['function_type'] = self.function_type
  53. return params
  54. @staticmethod
  55. def from_alipay_dict(d):
  56. if not d:
  57. return None
  58. o = CityFunction()
  59. if 'city_code' in d:
  60. o.city_code = d['city_code']
  61. if 'city_name' in d:
  62. o.city_name = d['city_name']
  63. if 'function_type' in d:
  64. o.function_type = d['function_type']
  65. return o