package com.sv.service.oms;
import com.github.pagehelper.PageHelper;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.entity.enums.StatusEnum;
import com.ydd.framework.core.service.impl.BaseServiceImpl;

import com.sv.entity.GiftMemberCard;
import com.sv.mapper.GiftMemberCardMapper;

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-17
 */
@Service
@Transactional(readOnly = true)
public class GiftMemberCardService extends BaseServiceImpl  {

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

	@Resource
	private GiftMemberCardMapper giftMemberCardMapper;

	/**
	 * 创建送会员卡记录
	 *
	 * @param giftMemberCard 送会员卡记录
	 */

	@Transactional
    public void save(GiftMemberCard giftMemberCard) {
		if (giftMemberCard.getId() != null && giftMemberCard.getId() > 0) {
			// 更新
			giftMemberCardMapper.update(giftMemberCard);
		} else {
			// 新建
			giftMemberCardMapper.insert(giftMemberCard);
		}
	}

	/**
	 * 更新送会员卡记录
 	 *
	 * @param giftMemberCard 送会员卡记录
	 */

	@Transactional
    public void update(GiftMemberCard giftMemberCard) {
		giftMemberCardMapper.update(giftMemberCard);
	}

	/**
	 * 删除送会员卡记录
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */

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

	/**
	 * 删除送会员卡记录
	 *
	 * @param ids 编号数组
	 * @return 删除数量
	 */

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

	/**
	 * 查询送会员卡记录
	 *
	 * @param id 编号
	 * @return 送会员卡记录
	 */
	public GiftMemberCard findById(Integer id) {
		return giftMemberCardMapper.findById(id);
	}

	/**
	 * 查询送会员卡记录
	 *
	 * @param pagination 分页信息
	 * @return 分页结果
	 */

	public Pagination findPage(Pagination pagination, String name) {
		PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
		PageHelper.orderBy("id desc");
		pagination.setQueryResult(giftMemberCardMapper.findAll(name));
		return pagination;
	}

	/**
	 * 更新状态
	 *
	 * @param ids 编号
	 * @param status 状态
	 * @return 更新数量
	 */

	@Transactional
	public Integer updateStatus(Integer[] ids, Byte status) {
		if (ids == null) {
			return 0;
		}
		if (status == null) {
			status = StatusEnum.DISABLE.value;
		}

		return giftMemberCardMapper.updateStatus(ids, status);
	}

}

