package com.sv.service.oms;

import com.github.pagehelper.PageHelper;
import com.sv.entity.MemberCard;
import com.sv.mapper.MemberCardMapper;
import com.sv.service.common.MemberCardCommonService;
import com.ydd.framework.core.common.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Service - 用户会员卡
 *
 * @author yechanglin
 * @since 2018-08-02
 */
@Service("MemberCardServiceOmd")
@Transactional(readOnly = true)
public class MemberCardService extends MemberCardCommonService {

	private final Logger logger = LoggerFactory.getLogger(MemberCardService.class);

	@Resource
	private MemberCardMapper memberCardMapper;

	/**
	 * 创建用户会员卡
	 *
	 * @param memberCard 用户会员卡
	 */
	@Transactional
    public void save(MemberCard memberCard) {
		if (memberCard.getId() != null && memberCard.getId() > 0) {
			// 更新
			memberCardMapper.update(memberCard);
		} else {
			// 新建
			memberCardMapper.insert(memberCard);
		}
	}

	/**
	 * 更新用户会员卡
 	 *
	 * @param memberCard 用户会员卡
	 */

	@Transactional
    public void update(MemberCard memberCard) {
		memberCardMapper.update(memberCard);
	}

	/**
	 * 删除用户会员卡
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */

	@Transactional
    public Integer delete(Integer id) {
		if (id == null || id <= 0) {
			return 0;
		}
		return memberCardMapper.delete(id);
	}

	/**
	 * 删除用户会员卡
	 *
	 * @param ids 编号数组
	 * @return 删除数量
	 */

	@Transactional
    public Integer deleteByIds(Integer[] ids) {
		if (ids == null || ids.length == 0) {
			return 0;
		}
		return memberCardMapper.deleteByIds(ids);
	}

	/**
	 * 查询用户会员卡
	 *
	 * @param id 编号
	 * @return 用户会员卡
	 */
	public MemberCard findById(Integer id) {
		return memberCardMapper.findById(id);
	}

	/**
	 * 查询用户会员卡
	 *
	 * @param pagination 分页信息
	 * @return 分页结果
	 */

	public Pagination findPage(Pagination pagination, Integer memberId, Byte status, Byte veneuType,String venueName) {
		PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
		pagination.setQueryResult(memberCardMapper.findAll(memberId, status, veneuType,venueName));
		return pagination;
	}

}

