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

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.base.dao.AddressDeviceDAO;
import com.jpsoft.shinestar.modules.base.entity.AddressDevice;
import com.jpsoft.shinestar.modules.base.service.AddressDeviceService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="addressDeviceService")
public class AddressDeviceServiceImpl implements AddressDeviceService {
	@Resource(name="addressDeviceDAO")
	private AddressDeviceDAO addressDeviceDAO;

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

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

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

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

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

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