package com.sv.service.api;

import com.github.pagehelper.PageHelper;
import com.sv.entity.VenueLessonImage;
import com.sv.mapper.VenueLessonImageMapper;
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-06
 */
@Service
@Transactional(readOnly = true)
public class VenueLessonImageService extends BaseServiceImpl {

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

	@Resource
	private VenueLessonImageMapper venueLessonImageMapper;

	/**
	 * 创建场馆课程图片
	 *
	 * @param venueLessonImage 场馆课程图片
	 */
	@Transactional
    public void save(VenueLessonImage venueLessonImage) {
		if (venueLessonImage.getId() != null && venueLessonImage.getId() > 0) {
			// 更新
			venueLessonImageMapper.update(venueLessonImage);
		} else {
			// 新建
			venueLessonImageMapper.insert(venueLessonImage);
		}
	}

	/**
	 * 更新场馆课程图片
 	 *
	 * @param venueLessonImage 场馆课程图片
	 */
	@Transactional
    public void update(VenueLessonImage venueLessonImage) {
		venueLessonImageMapper.update(venueLessonImage);
	}

	/**
	 * 删除场馆课程图片
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */
	@Transactional
    public Integer delete(Integer id) {
		if (id == null || id <= 0) {
			return 0;
		}
		return venueLessonImageMapper.delete(id);
	}

	/**
	 * 删除场馆课程图片
	 *
	 * @param ids 编号数组
	 * @return 删除数量
	 */
	@Transactional
    public Integer deleteByIds(Integer[] ids) {
		if (ids == null || ids.length == 0) {
			return 0;
		}
		return venueLessonImageMapper.deleteByIds(ids);
	}

	/**
	 * 查询场馆课程图片
	 *
	 * @param id 编号
	 * @return 场馆课程图片
	 */
	public VenueLessonImage findById(Integer id) {
		return venueLessonImageMapper.findById(id);
	}

	/**
	 * 查询场馆课程图片
	 *
	 * @param pagination 分页信息
	 * @return 分页结果
	 */
	public Pagination findPage(Pagination pagination) {
		PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
		PageHelper.orderBy("id desc");
		pagination.setQueryResult(venueLessonImageMapper.findAll());
		return pagination;
	}

}

