CalendarScheduleInfo.py 2.3 KB

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