package com.neusoft.smart.pos.card.persistent.repository;

import com.neusoft.smart.pos.card.persistent.domain.Card;
import com.neusoft.smart.pos.card.persistent.domain.CardExample;
import com.neusoft.smart.pos.card.persistent.mapper.CardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CardRepository {
	
	@Autowired
	private CardMapper cardMapper;


	public Card getActiveCardByCardNum(String cardNum) {
		CardExample cardExample = new CardExample();
		cardExample.createCriteria().andCardNumEqualTo(cardNum).andIsActiveEqualTo(1);
		return cardMapper.selectByExample(cardExample).stream().findAny().orElse(null);
	}

	public Card get(Integer cardId){
		return cardMapper.selectByPrimaryKey(cardId);
	}
	
	public Integer update(Card card, CardExample cardExample) {
		return cardMapper.updateByExampleSelective(card, cardExample);
	}
	
}
