根据动态条件

@Query(nativeQuery = true, value = "select A.* " +
            "from epidemic_case_info A where A.delete_flag = '0' " +
            "and (case " +
            "when right(:distCode, 4) = '0000' then A.dist_code like concat(substring(:distCode, 1, 2 ), '%')  " +
            "when right(:distCode, 2) = '00' then A.dist_code like concat(substring(:distCode, 1, 4 ), '%') " +
            "else A.dist_code = :distCode end) " +
            "and A.report_time >= :startDate and A.report_time <= :endDate " +
            "and (case when :name is not null and :name != '' then A.name = :name else 1 = 1 end) ")
    List<EpidemicCaseInfoPO> caseArea(@Param("distCode") String distCode, @Param("startDate") String startDate,
                                      @Param("endDate") String endDate, @Param("name") String name);

根据经纬度距离查询

@Query(nativeQuery = true, value = "" +
            "select * from (select round(ST_Distance" +
            "(ST_Transform(ST_SetSRID(ST_MakePoint(:longitude,:latitude),4326),3857)" +
            ", ST_Transform(ST_SetSRID(ST_MakePoint(longitude\\:\\:float,latitude\\:\\:float),4326),3857))\\:\\:numeric, 2) as distance" +
            ",t.* from task_emer.task_storehouse_info t " +
            "where t.longitude is not null and t.longitude != '' and t.latitude is not null and t.latitude != ''" +
            " AND case when :storehouseName is not null and :storehouseName != '' then t.name like concat('%', :storehouseName, '%') else 1 = 1 end " +
            " AND case when :type is not null and :type != '' then t.type = :type else 1 = 1 end " +
            ") x where x.distance < :range " +
            "ORDER BY x.distance ")
    List<TaskStorehouseInfoPO> findTaskStorehouseByRange(@Param("longitude") float longitude, @Param("latitude") float latitude,
                                                         @Param("range") float range, @Param("storehouseName") String storehouseName,
                                                         @Param("type") String type);