/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.base.dao.device;

import com.yihu.jw.entity.care.device.Device;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface DeviceDao extends PagingAndSortingRepository<Device, Long> {

	@Query("select a from Device a where a.categoryCode = ?1 and a.del = '1'")
	List<Device> findByCategoryCode(String categoryCode);

	@Query("select a from Device a where a.del = '1'")
	List<Device> findAll();

	@Query("select count(1) from Device a where a.del = '1' and a.categoryCode=?1 ")
	Integer findTotalByCategoryCode(String categoryCode);

	@Query("select count(1) from Device a where a.del = '1' and a.name=?1 ")
	Integer findTotalByName(String name);

	@Query("select count(1) from Device a where a.del = '1' and a.categoryCode=?1 and a.name=?2 ")
	Integer findTotalByCategoryCodeAndName(String categoryCode,String name);

	@Query("select count(1) from Device a where a.del = '1' and a.model=?1")
	Integer findTotalByModel(String model);

	@Query("select count(1) from Device a where a.del = '1' and a.categoryCode=?1 and a.name=?2 and a.model=?3 ")
	Integer findTotalByCodeNameModel(String categoryCode,String name,String model);

	@Query("select a from Device a where a.del = '1' and a.model=?1")
	Device findByModel(String model);
}
