package com.sv.service.api;

import com.github.pagehelper.PageHelper;
import com.sv.entity.VenueImage;
import com.sv.mapper.VenueImageMapper;
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 zuojie.Liang
 * @since 2018-08-02
 */
@Service("VenueImageServiceApi")
@Transactional(readOnly = true)
public class VenueImageService extends BaseServiceImpl {

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

	@Resource
	private VenueImageMapper venueImageMapper;

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

	/**
	 * 更新场馆图片
 	 *
	 * @param venueImage 场馆图片
	 */
	@Transactional
    public void update(VenueImage venueImage) {
		venueImageMapper.update(venueImage);
	}

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

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

	/**
	 * 查询场馆图片
	 *
	 * @param id 编号
	 * @return 场馆图片
	 */
	public VenueImage findById(Integer id) {
		return venueImageMapper.findById(id);
	}

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

    public void deleteByVenueId(Integer id) {
		venueImageMapper.deleteByVenueId(id);
    }
}

