package com.sv.service.api;

import com.github.pagehelper.PageHelper;
import com.sv.entity.Protocol;
import com.sv.mapper.ProtocolMapper;
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-10
 */
@Service("ProtocolServiceApi")
@Transactional(readOnly = true)
public class ProtocolService extends BaseServiceImpl  {

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

	@Resource
	private ProtocolMapper protocolMapper;

	/**
	 * 创建协议
	 *
	 * @param protocol 协议
	 */
	@Transactional
    public void save(Protocol protocol) {
		if (protocol.getId() != null && protocol.getId() > 0) {
			// 更新
			protocolMapper.update(protocol);
		} else {
			// 新建
			protocolMapper.insert(protocol);
		}
	}

	/**
	 * 更新协议
 	 *
	 * @param protocol 协议
	 */
	@Transactional
    public void update(Protocol protocol) {
		protocolMapper.update(protocol);
	}

	/**
	 * 删除协议
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */
	@Transactional
    public Integer delete(Integer id) {
		if (id == null || id <= 0) {
			return 0;
		}
		return protocolMapper.delete(id);
	}

	/**
	 * 删除协议
	 *
	 * @param ids 编号数组
	 * @return 删除数量
	 */
	@Transactional
    public Integer deleteByIds(Integer[] ids) {
		if (ids == null || ids.length == 0) {
			return 0;
		}
		return protocolMapper.deleteByIds(ids);
	}

	/**
	 * 查询协议
	 *
	 * @param id 编号
	 * @return 协议
	 */
	public Protocol findById(Integer id) {
		return protocolMapper.findById(id);
	}

	/**
	 * api 查询协议
	 *
	 */
	public Protocol findAll(){
		return protocolMapper.findAll();
	}

}

