fire_point/src/main/java/com/xkrs/dao/FirePointDao.java
2021-12-14 14:55:56 +08:00

114 lines
4.0 KiB
Java

package com.xkrs.dao;
import com.xkrs.model.entity.FirePointEntity;
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 org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* @author XinYi Song
*/
@Component
public interface FirePointDao extends JpaRepository<FirePointEntity,Long>, JpaSpecificationExecutor<FirePointEntity> {
/**
* 查询今天的火点信息
* @param addTime
* @param address
* @return
*/
@Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and fire_point_address like CONCAT('%',:address,'%')",nativeQuery = true)
List<FirePointEntity> selectTodayFirePoint(String addTime,String address);
/**
*查询山东省今天火点信息
* @param addTime
* @param address
* @return
*/
@Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and fire_point_address like CONCAT('%',:address,'%') and land_type != '耕地'",nativeQuery = true)
List<FirePointEntity> selectTodayFirePointShandong(String addTime,String address);
/**
* 区县条件查询今天火点信息
* @param addTime
* @param countyCode
* @return
*/
@Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and county_code = :countyCode",nativeQuery = true)
List<FirePointEntity> selectTodayFirePointOne(String addTime,String countyCode);
/**
* 查询山东省县的今天火点信息
* @param addTime
* @param countyCode
* @return
*/
@Query(value = "select * from fire_point where add_time like CONCAT('%',:addTime,'%') and county_code = :countyCode and land_type != '耕地'",nativeQuery = true)
List<FirePointEntity> selectTodayFirePointOneShandong(String addTime,String countyCode);
/**
* 根据火点编码查询火点信息
* @param fireCode
* @return
*/
FirePointEntity findByFireCode(String fireCode);
/**
* 根据火点编码修改火点状态
* @param fireCode
* @param fireType
*/
@Modifying(clearAutomatically=true)
@Query(value = "update fire_point set fire_type = ?2 where fire_code = ?1",nativeQuery = true)
void updateFireTypeByFireCode(String fireCode,String fireType);
/**
* 查询时间段内各植被类型的火点数量
* @param startTime
* @param endTime
* @return
*/
@Query(value = "select la.land_name landname,count(fp.id) as num from land la left join fire_point fp " +
"on fp.land_type = la.land_name AND fp.add_time BETWEEN ?1 AND ?2 " +
"group by la.land_name",nativeQuery = true)
List<Map<String,Object>> selectNumByLandType(String startTime,String endTime);
/**
* 查询时间段内各地区的火点数量
* @param startTime
* @param endTime
* @return
*/
@Query(value = "select ci.city_name cityname,count(fp.id) from city ci left join fire_point fp " +
"on fp.county_code like concat('%',ci.city_code,'%') AND fp.add_time BETWEEN ?1 AND ?2 " +
"group by ci.city_name",nativeQuery = true)
List<Map<String,Object>> selectNumByArea(String startTime,String endTime);
/**
* 查询水体类型的id
* @return
*/
@Query(value = "select id from fire_point where land_type = '水体'",nativeQuery = true)
List<Integer> selectId();
/**
* 批量删除水体
* @param id
*/
@Modifying(clearAutomatically=true)
void deleteByIdIn(List<Integer> id);
/**
* 查询北京的火点
* @return
*/
@Query(value = "select * from fire_point fp where fp.fire_point_address like concat('%','北京市','%') and fp.add_time BETWEEN '2021-10-19' AND '2021-11-20'",nativeQuery = true)
List<FirePointEntity> selectBeijing();
}