package com.red.circle.console.infra.database.mongo.count.service.impl;

import com.red.circle.console.infra.database.mongo.count.entity.CountUserDailyRechargeRank;
import com.red.circle.console.infra.database.mongo.count.service.CountUserDailyRechargeRankService;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

/**
 * @author pengliang on 2022/11/25
 */
@Service
@AllArgsConstructor
public class CountUserDailyRechargeRankServiceImpl implements CountUserDailyRechargeRankService {

  private final MongoTemplate mongoTemplate;

  @Override
  public void addBatch(List<CountUserDailyRechargeRank> ranks) {
    mongoTemplate.insert(ranks, CountUserDailyRechargeRank.class);
  }

  @Override
  public List<CountUserDailyRechargeRank> list(Integer dateNumber) {
    return mongoTemplate.find(Query.query(Criteria.where("dateNumber").is(dateNumber))
            .with(Sort.by(Sort.Order.desc("quantity")))
        , CountUserDailyRechargeRank.class);
  }
}
