package com.sv.service.oms;

import com.github.pagehelper.PageHelper;
import com.sv.entity.Recharge;
import com.sv.mapper.RechargeMapper;
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-15
 */
@Service("RechargeServiceOms")
@Transactional(readOnly = true)
public class RechargeService extends BaseServiceImpl {

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

	@Resource
	private RechargeMapper rechargeMapper;

	/**
	 * 创建快速充值配置信息
	 *
	 * @param recharge 快速充值配置信息
	 */
	@Transactional
    public void save(Recharge recharge) {
		if (recharge.getId() != null && recharge.getId() > 0) {
			// 更新
			rechargeMapper.update(recharge);
		} else {
			// 新建
			rechargeMapper.insert(recharge);
		}
	}

	/**
	 * 更新快速充值配置信息
 	 *
	 * @param recharge 快速充值配置信息
	 */
	@Transactional
    public void update(Recharge recharge) {
		rechargeMapper.update(recharge);
	}

	/**
	 * 删除快速充值配置信息
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */
	@Transactional
    public Integer delete(Integer id) {
		if (id == null || id <= 0) {
			return 0;
		}
		return rechargeMapper.delete(id);
	}

	/**
	 * 删除快速充值配置信息
	 *
	 * @param ids 编号数组
	 * @return 删除数量
	 */
	@Transactional
    public Integer deleteByIds(Integer[] ids) {
		if (ids == null || ids.length == 0) {
			return 0;
		}
		return rechargeMapper.deleteByIds(ids);
	}

	/**
	 * 查询快速充值配置信息
	 *
	 * @param id 编号
	 * @return 快速充值配置信息
	 */
	public Recharge findById(Integer id) {
		return rechargeMapper.findById(id);
	}

	/**
	 * 查询快速充值配置信息
	 *
	 * @param pagination 分页信息
	 * @return 分页结果
	 */
	public Pagination findPage(Pagination pagination) {
		PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
		PageHelper.orderBy("id desc");
		pagination.setQueryResult(rechargeMapper.findAll());
		return pagination;
	}

}

