package com.sv.service.oms;

import com.github.pagehelper.PageHelper;
import com.sv.entity.MemberLessonTicket;
import com.sv.mapper.MemberLessonTicketMapper;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.entity.enums.StatusEnum;
import com.ydd.framework.core.service.impl.BaseServiceImpl;
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("MemberLessonTicketServiceOms")
@Transactional(readOnly = true)
public class MemberLessonTicketService extends BaseServiceImpl {

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

	@Resource
	private MemberLessonTicketMapper memberLessonTicketMapper;

	/**
	 * 创建预约场馆课程订单
	 *
	 * @param memberLessonTicket 预约场馆课程订单
	 */

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

	/**
	 * 更新预约场馆课程订单
 	 *
	 * @param memberLessonTicket 预约场馆课程订单
	 */

	@Transactional
    public void update(MemberLessonTicket memberLessonTicket) {
		memberLessonTicketMapper.update(memberLessonTicket);
	}

	/**
	 * 删除预约场馆课程订单
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */

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

	/**
	 * 删除预约场馆课程订单
	 *
	 * @param ids 编号数组
	 * @return 删除数量
	 */

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

	/**
	 * 查询预约场馆课程订单
	 *
	 * @param id 编号
	 * @return 预约场馆课程订单
	 */
	public MemberLessonTicket findById(Integer id) {
		return memberLessonTicketMapper.findById(id);
	}

	/**
	 * 查询预约场馆课程订单
	 *
	 * @param pagination 分页信息
	 * @return 分页结果
	 */

	public Pagination findPage(Pagination pagination, Integer payStatus, String starTime,
							   String endTime, String orderSn, String lessonname, Integer lessonId) {
		PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
		PageHelper.orderBy("id desc");
		pagination.setQueryResult(memberLessonTicketMapper.findAlls(payStatus, starTime, endTime, orderSn, lessonname, lessonId));
		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 memberLessonTicketMapper.updateStatus(ids, status);
	}

}

