package com.zhongshu.card.server.core.dao.payment.impl;

import com.zhongshu.card.server.core.dao.payment.extend.PicDaoExtend;
import com.zhongshu.card.server.core.domain.payment.Pic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

public class PicDaoImpl implements PicDaoExtend {

    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public Pic findByAccesserIdAndDocument_type(String accesserId, String type) {

        Query query = new Query(Criteria.where("document_type").is(type).and("accesserId").is(accesserId));

        List<Pic> pics = mongoTemplate.find(query, Pic.class);
        if (pics.size() == 0) {
            return null;
        }
        return pics.get(0);
    }

    @Override
    public List<Pic> findByEpId(String epId) {
        Query query = new Query(Criteria.where("epId").is(epId));
        return mongoTemplate.find(query, Pic.class);
    }
}
