DividendLogRepository.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\repositories\dividend;
  3. use app\common\dao\dividend\DividendLogDao;
  4. use app\common\repositories\BaseRepository;
  5. use app\entity\data\dividend\DividendLogEntity;
  6. class DividendLogRepository extends BaseRepository
  7. {
  8. protected $dao;
  9. /**
  10. * DividendLogRepository constructor.
  11. * @param DividendLogDao $dao
  12. */
  13. public function __construct(DividendLogDao $dao)
  14. {
  15. $this->dao = $dao;
  16. }
  17. /**
  18. * @param int $id
  19. * @return DividendLogEntity
  20. */
  21. public function getDividendLogEntityById(int $id): DividendLogEntity
  22. {
  23. $entityList = $this->getDividendLogEntityListByIdList([$id]);
  24. $entity = array_shift($entityList);
  25. if ($entity instanceof DividendLogEntity) {
  26. return $entity;
  27. } else {
  28. /** @var DividendLogEntity */
  29. return DividendLogEntity::newInstance();
  30. }
  31. }
  32. /**
  33. * @param array $idList
  34. * @return DividendLogEntity[]
  35. */
  36. public function getDividendLogEntityListByIdList(array $idList): array
  37. {
  38. return $this->dao->getDividendLogEntityListByIdList($idList);
  39. }
  40. public function create($data)
  41. {
  42. return $this->dao->create($data);
  43. }
  44. /**
  45. * @param DividendLogEntity $dividendLogEntity
  46. * @return DividendLogEntity
  47. */
  48. public function createByEntity(DividendLogEntity $dividendLogEntity): DividendLogEntity
  49. {
  50. $result = $this->create($dividendLogEntity->toUnderlineArray())->toArray();
  51. /** @var DividendLogEntity $entity */
  52. $entity = DividendLogEntity::newInstance($result);
  53. return $entity;
  54. }
  55. }