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.ElectricMeterInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.ElectricMeterInfo;
import com.jpsoft.shinestar.modules.base.service.ElectricMeterInfoService;
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="electricMeterInfoService")
public class ElectricMeterInfoServiceImpl implements ElectricMeterInfoService {
	@Resource(name="electricMeterInfoDAO")
	private ElectricMeterInfoDAO electricMeterInfoDAO;

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

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

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

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

	@Override
	public int getCountByMNoAndUNo(String meterNo,String unitNo,String excludeId){
		return electricMeterInfoDAO.getCountByMNoAndUNo(meterNo,unitNo,excludeId);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = electricMeterInfoDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<ElectricMeterInfo> list() {
		// TODO Auto-generated method stub
		return electricMeterInfoDAO.list();
	}
		
	@Override
	public Page<ElectricMeterInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
        Page<ElectricMeterInfo> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
            electricMeterInfoDAO.search(searchParams,sortList);
        });
        
        return page;
	}
}