package com.sv.service.api;

import com.github.pagehelper.PageHelper;
import com.sv.entity.VenuePrice;
import com.sv.mapper.VenuePriceMapper;
import com.ydd.framework.core.common.Pagination;
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 lihong
 * @since 2018-08-23
 */
@Service("VenuePriceServiceApi")
@Transactional(readOnly = true)
public class VenuePriceService extends BaseServiceImpl  {

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

	@Resource
	private VenuePriceMapper venuePriceMapper;

	/**
	 * 创建场馆对应价格表
	 *
	 * @param venuePrice 场馆对应价格表
	 */
	@Transactional
    public void save(VenuePrice venuePrice) {
		if (venuePrice.getId() != null && venuePrice.getId() > 0) {
			// 更新
			venuePriceMapper.update(venuePrice);
		} else {
			// 新建
			venuePriceMapper.insert(venuePrice);
		}
	}

	/**
	 * 更新场馆对应价格表
 	 *
	 * @param venuePrice 场馆对应价格表
	 */
	@Transactional
    public void update(VenuePrice venuePrice) {
		venuePriceMapper.update(venuePrice);
	}

	/**
	 * 删除场馆对应价格表
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */
	@Transactional
    public Integer delete(Integer id) {
		if (id == null || id <= 0) {
			return 0;
		}
		return venuePriceMapper.delete(id);
	}

	/**
	 * 删除场馆对应价格表
	 *
	 * @param ids 编号数组
	 * @return 删除数量
	 */
	@Transactional
    public Integer deleteByIds(Integer[] ids) {
		if (ids == null || ids.length == 0) {
			return 0;
		}
		return venuePriceMapper.deleteByIds(ids);
	}

	/**
	 * 查询场馆对应价格表
	 *
	 * @param id 编号
	 * @return 场馆对应价格表
	 */
	public VenuePrice findById(Integer id) {
		return venuePriceMapper.findById(id);
	}

	/**
	 * 查询场馆对应价格表
	 *
	 * @param pagination 分页信息
	 * @return 分页结果
	 */
	public Pagination findPage(Pagination pagination) {
		PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
		PageHelper.orderBy("id desc");
		pagination.setQueryResult(venuePriceMapper.findAll());
		return pagination;
	}

	/**
	 * 查询进场时间对应的价格
	 */
	public VenuePrice findPrice(Integer venueId,String time){
		return venuePriceMapper.findPriceByVenueId(venueId,time);
	}
}

