package com.red.circle.order.infra.database.rds.service.count.impl;

import com.google.common.collect.Lists;
import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl;
import com.red.circle.order.infra.database.rds.dao.count.UserFreightRechargeRecordDAO;
import com.red.circle.order.infra.database.rds.entity.count.UserFreightRechargeRecord;
import com.red.circle.order.infra.database.rds.service.count.UserFreightRechargeRecordService;
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户充值记录 服务实现类.
 * </p>
 *
 * @author zongpubin on 2023-11-23 12:31
 */
@RequiredArgsConstructor
@Service
public class UserFreightRechargeRecordServiceImpl extends
    BaseServiceImpl<UserFreightRechargeRecordDAO, UserFreightRechargeRecord> implements
    UserFreightRechargeRecordService {

  private final UserFreightRechargeRecordDAO userFreightRechargeRecordDAO;

  @Override
  public UserFreightRechargeRecord getNowMonthByUserId(Long userId) {
    return query().eq(UserFreightRechargeRecord::getUserId, userId)
        .eq(UserFreightRechargeRecord::getRechargeDate,
            ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt())
        .getOne();
  }

  @Override
  public List<Long> listNowMonthBySysOrigin(String sysOrigin) {
    return Optional.ofNullable(userFreightRechargeRecordDAO.listBySysOrigin(sysOrigin,
        ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt())).orElse(Lists.newArrayList());
  }

  @Override
  public BigDecimal countAmount(Long userId) {
    return userFreightRechargeRecordDAO.countAmount(userId);
  }

}
