package com.jpsoft.shinestar.modules.base.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.RechargeRecordDAO;
import com.jpsoft.shinestar.modules.base.entity.RechargeRecord;
import com.jpsoft.shinestar.modules.base.service.RechargeRecordService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Transactional
@Component(value="rechargeRecordService")
public class RechargeRecordServiceImpl implements RechargeRecordService {
	@Resource(name="rechargeRecordDAO")
	private RechargeRecordDAO rechargeRecordDAO;

	@Override
	public RechargeRecord get(String id) {
		// TODO Auto-generated method stub
		return rechargeRecordDAO.get(id);
	}

	@Override
	public int insert(RechargeRecord model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());
		
		return rechargeRecordDAO.insert(model);
	}

	@Override
	public int update(RechargeRecord model) {
		// TODO Auto-generated method stub
		return rechargeRecordDAO.update(model);		
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return rechargeRecordDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = rechargeRecordDAO.exist(id);
		
		return count > 0 ? true : false;
	}

	@Override
	public RechargeRecord getBySerialNum(String erialNum){
		return rechargeRecordDAO.getBySerialNum(erialNum);
	}

	@Override
	public List<RechargeRecord> list() {
		// TODO Auto-generated method stub
		return rechargeRecordDAO.list();
	}
		
	@Override
	public Page<RechargeRecord> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
		Page<RechargeRecord> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
			rechargeRecordDAO.search(searchParams,sortList);
		});

		return page;
	}

	@Override
	public Page<RechargeRecord> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
		Page<RechargeRecord> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
			rechargeRecordDAO.search(searchParams,sortList);
		});

		return page;
	}
}