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

import com.neusoft.smart.pos.member.persistent.domain.MemberCard;
import com.neusoft.smart.pos.member.persistent.domain.MemberCardExample;
import com.neusoft.smart.pos.member.persistent.mapper.MemberCardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MemberCardRepository {
	
	@Autowired
	private MemberCardMapper memberCardMapper;


	public MemberCard getActiveCardByCardNum(String cardNum) {
		MemberCardExample memberCardExample = new MemberCardExample();
		memberCardExample.createCriteria().andCardNumEqualTo(cardNum).andIsActiveEqualTo(1);
		return memberCardMapper.selectByExample(memberCardExample).stream().findAny().orElse(null);
	}
	
	public MemberCard get(Integer cardId){
		return memberCardMapper.selectByPrimaryKey(cardId);
	}
	
	public Integer update(MemberCard memberCard, MemberCardExample memberCardExample) {
		return memberCardMapper.updateByExampleSelective(memberCard, memberCardExample);
	}
	
}
