SmartUrbanRural/src/main/java/com/xkrs/dao/EquipmentDao.java

93 lines
3.6 KiB
Java

package com.xkrs.dao;
import com.xkrs.model.entity.Equipment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Map;
/**
* @Author: XinYi Song
* @Date: 2022/2/8 9:26
*/
public interface EquipmentDao extends JpaRepository<Equipment,Long>, JpaSpecificationExecutor<Equipment> {
/**
* 根据设备编码修改实时视频路径
* @param code
* @param videoPath
*/
@Modifying(clearAutomatically=true)
@Query(value = "update equipment set live_video = ?2 where equipment_code = ?1",nativeQuery = true)
void updateVideo(String code,String videoPath);
/**
* 查询全部设备信息
* @return
*/
@Query(value = "select * from equipment",nativeQuery = true)
List<Equipment> findAllInformation();
/**
* 查询实时视频
* @return
*/
@Query(value = "select equipment_code equipmentcode,live_video livevideo from equipment",nativeQuery = true)
List<Map<String,String>> findVideoPath();
/**
* 获取设备的信息
* @return
*/
@Query(value = "select equipment_code equipmentcode,equipment_name equipmentname,equipment_type equipmenttype," +
"equipment_status equipmentstatus,equipment_longitude equipmentlongitude," +
"equipment_latitude equipmentlatitude,installation_time installationtime,street from equipment",nativeQuery = true)
List<Map<String,String>> findEquipment();
/**
* 根据时间段查询各个街道火情数量
* @param beginTime
* @param endTime
* @return
*/
@Query(value = "select e.street street,count(f.id) AS firenumber from equipment e,fire f where f.alarm_date " +
"BETWEEN ?1 AND ?2 AND e.equipment_code = f.device_code " +
"GROUP BY e.street",nativeQuery = true)
List<Map<String,Object>> selectCountFire(String beginTime, String endTime);
/**
* 查询一个月中每一天各个街道的火情数量
* @param beginTime
* @param endTime
* @return
*/
@Query(value = "select LEFT(f.alarm_date,10) AS data,e.street as street,count(f.id) AS firenumber " +
"from equipment e,fire f where f.alarm_date BETWEEN ?1 AND ?2 " +
"AND e.equipment_code = f.device_code GROUP BY LEFT(f.alarm_date,10),e.street",nativeQuery = true)
List<Map<String,Object>> selectEveryDayCount(String beginTime, String endTime);
/**
* 查询一年中每个月的各个街道的火情数量
* @param beginTime
* @param endTime
* @return
*/
@Query(value = "select LEFT(f.alarm_date,7) AS data,e.street as street,count(f.id) AS firenumber " +
"from equipment e,fire f where f.alarm_date BETWEEN ?1 AND ?2 " +
"AND e.equipment_code = f.device_code GROUP BY LEFT(f.alarm_date,7),e.street",nativeQuery = true)
List<Map<String,Object>> selectEveryMonthCount(String beginTime, String endTime);
/**
* 根据街道查询设备信息
* @param street
* @return
*/
@Query(value = "select equipment_code equipmentcode,equipment_name equipmentname,equipment_type equipmenttype," +
"equipment_status equipmentstatus,equipment_longitude equipmentlongitude," +
"equipment_latitude equipmentlatitude,installation_time installationtime,street from equipment where street = ?",nativeQuery = true)
List<Map<String,Object>> selectEquipmentByStreet(String street);
}