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.CompanyDeviceRelationDAO;
import com.jpsoft.shinestar.modules.base.entity.CompanyDeviceRelation;
import com.jpsoft.shinestar.modules.base.entity.DeviceInfo;
import com.jpsoft.shinestar.modules.base.service.CompanyDeviceRelationService;
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="companyDeviceRelationService")
public class CompanyDeviceRelationServiceImpl implements CompanyDeviceRelationService {
	@Resource(name="companyDeviceRelationDAO")
	private CompanyDeviceRelationDAO companyDeviceRelationDAO;

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

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

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

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

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

	@Override
	public List<DeviceInfo> findDeviceByCompanyId(String companyId) {
		return companyDeviceRelationDAO.findDeviceByCompanyId(companyId);
	}

	@Override
	public CompanyDeviceRelation findByCompanyIdAndDeviceId(String companyId, String deviceId){
		return companyDeviceRelationDAO.findByCompanyIdAndDeviceId(companyId,deviceId);
	}

	@Override
	public List<CompanyDeviceRelation> findByCompanyId(String companyId){
		return companyDeviceRelationDAO.findByCompanyId(companyId);
	}

	@Override
	public List<CompanyDeviceRelation> findByDeviceId(String deviceId){
		return companyDeviceRelationDAO.findByDeviceId(deviceId);
	}

	@Override
	public int deleteByCompanyId(String companyId) {
		return companyDeviceRelationDAO.deleteByCompanyId(companyId);
	}

	@Override
	public int deleteByDeviceId(String deviceId) {
		return companyDeviceRelationDAO.deleteByDeviceId(deviceId);
	}

	@Override
	public int deleteByCompanyIdAndDeviceId(String companyId, String deviceId) {
		return companyDeviceRelationDAO.deleteByCompanyIdAndDeviceId(companyId,deviceId);
	}
}