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.CameraInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.CameraInfo;
import com.jpsoft.shinestar.modules.base.service.CameraInfoService;
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="cameraInfoService")
public class CameraInfoServiceImpl implements CameraInfoService {
	@Resource(name="cameraInfoDAO")
	private CameraInfoDAO cameraInfoDAO;

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

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

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

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

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

	@Override
	public List<CameraInfo> findBySchoolId(String classId){
		return cameraInfoDAO.findBySchoolId(classId);
	}
		
	@Override
	public Page<CameraInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<CameraInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            cameraInfoDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public List<CameraInfo> search(Map<String, Object> searchParams,List<Sort> sortList) {

		return cameraInfoDAO.search(searchParams,sortList);
	}
	@Override
	public List<CameraInfo> findByPersonId(Long classId) {
		return cameraInfoDAO.findByPersonId(classId);
	}
}