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.ElectricClientInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.ElectricClientInfo;
import com.jpsoft.shinestar.modules.base.service.ElectricClientInfoService;
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="electricClientInfoService")
public class ElectricClientInfoServiceImpl implements ElectricClientInfoService {
	@Resource(name="electricClientInfoDAO")
	private ElectricClientInfoDAO electricClientInfoDAO;

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

	@Override
	public ElectricClientInfo getRoomMessage(String id){
		return electricClientInfoDAO.getRoomMessage(id);
	}

	@Override
	public int getCountByCNo(String customerNo,String excludeId){
		return electricClientInfoDAO.getCountByCNo(customerNo,excludeId);
	}

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

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

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

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

	@Override
	public ElectricClientInfo findOneByRoomId(String roomId) {
		return electricClientInfoDAO.findOneByRoomId(roomId);
	}
}