package com.sv.service.oms;
import com.github.pagehelper.PageHelper;
import com.sv.mapper.MemberCardOrderMapper;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.service.impl.BaseServiceImpl;

import com.sv.entity.MemberCardOrder;

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-03
 */
@Service("MemberCardOrderServiceOms")
@Transactional(readOnly = true)
public class MemberCardOrderService extends BaseServiceImpl {

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

	@Resource
	private MemberCardOrderMapper memberCardOrderMapper;

	/**
	 * 创建会员卡订单
	 *
	 * @param memberCardOrder 会员卡订单
	 */

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

	/**
	 * 更新会员卡订单
 	 *
	 * @param memberCardOrder 会员卡订单
	 */

	@Transactional
    public void update(MemberCardOrder memberCardOrder) {
		memberCardOrderMapper.update(memberCardOrder);
	}

	/**
	 * 删除会员卡订单
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */

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

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

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

	/**
	 * 查询会员卡订单
	 *
	 * @param id 编号
	 * @return 会员卡订单
	 */
	public MemberCardOrder findById(Integer id) {
		return memberCardOrderMapper.findById(id);
	}

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

	public Pagination findPage(Pagination pagination, Integer payStatus, String starTime,
							   String endTime, String orderSn) {
		PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
		PageHelper.orderBy("id desc");
		pagination.setQueryResult(memberCardOrderMapper.findAlls(payStatus, starTime, endTime, orderSn));
		return pagination;
	}



}

