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.CameraCompanyDAO;
import com.jpsoft.shinestar.modules.base.entity.CameraCompany;
import com.jpsoft.shinestar.modules.base.service.CameraCompanyService;
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="cameraCompanyService")
public class CameraCompanyServiceImpl implements CameraCompanyService {
	@Resource(name="cameraCompanyDAO")
	private CameraCompanyDAO cameraCompanyDAO;

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

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

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

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

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

	@Override
	public  List<CameraCompany> findByClassId(String classId){
		return cameraCompanyDAO.findByClassId(classId);
	}

	@Override
	public List<CameraCompany> findByCameraId(String cameraId){
		return cameraCompanyDAO.findByCameraId(cameraId);
	}

	@Override
	public List<CameraCompany> findByCameraIdAndClassId(String cameraId,String classId){
		return cameraCompanyDAO.findByCameraIdAndClassId(cameraId,classId);
	}
		
	@Override
	public Page<CameraCompany> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
        Page<CameraCompany> page = PageHelper.startPage(1,10).doSelectPage(()->{
            cameraCompanyDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public boolean existByKey(String cameraId, String classId) {
		return cameraCompanyDAO.existByKey(cameraId,classId)>0;
	}

	@Override
	public int deleteByKey(String cameraId, String classId) {
		return cameraCompanyDAO.deleteByKey(cameraId,classId);
	}
}