package com.sv.service.oms;
import com.github.pagehelper.PageHelper;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.service.impl.BaseServiceImpl;

import com.sv.entity.MemberMoneyLog;
import com.sv.mapper.MemberMoneyLogMapper;

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 yechanglin
 * @since 2018-08-08
 */
@Service("MemberMoneyLogServiceOms")
@Transactional(readOnly = true)
public class MemberMoneyLogService extends BaseServiceImpl {

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

	@Resource
	private MemberMoneyLogMapper memberMoneyLogMapper;

	/**
	 * 创建用户金额记录
	 *
	 * @param memberMoneyLog 用户金额记录
	 */
	@Transactional
    public void save(MemberMoneyLog memberMoneyLog) {
		if (memberMoneyLog.getId() != null && memberMoneyLog.getId() > 0) {
			// 更新
			memberMoneyLogMapper.update(memberMoneyLog);
		} else {
			// 新建
			memberMoneyLogMapper.insert(memberMoneyLog);
		}
	}

	/**
	 * 更新用户金额记录
 	 *
	 * @param memberMoneyLog 用户金额记录
	 */
	@Transactional
    public void update(MemberMoneyLog memberMoneyLog) {
		memberMoneyLogMapper.update(memberMoneyLog);
	}

	/**
	 * 删除用户金额记录
	 *
	 * @param id 编号
   	 * @return 删除数量
	 */
	@Transactional
    public Integer delete(Integer id) {
		if (id == null || id <= 0) {
			return 0;
		}
		return memberMoneyLogMapper.delete(id);
	}

	/**
	 * 删除用户金额记录
	 *
	 * @param ids 编号数组
	 * @return 删除数量
	 */

	@Transactional
    public Integer deleteByIds(Integer[] ids) {
		if (ids == null || ids.length == 0) {
			return 0;
		}
		return memberMoneyLogMapper.deleteByIds(ids);
	}

	/**
	 * 查询用户金额记录
	 *
	 * @param id 编号
	 * @return 用户金额记录
	 */
	public MemberMoneyLog findById(Integer id) {
		return memberMoneyLogMapper.findById(id);
	}

	/**
	 * 查询用户金额记录
	 *
	 * @param pagination 分页信息
	 * @return 分页结果
	 */

	public Pagination findPage(Pagination pagination, Integer memberId) {
		PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
		PageHelper.orderBy("id desc");
		pagination.setQueryResult(memberMoneyLogMapper.findAlls(memberId));
		return pagination;
	}

}

