【Spring Data JPA】根据动态查询条件、根据经纬度距离查询

根据动态条件

    @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);

相关推荐

  1. mysql 根据经纬度计算距离

    2024-01-16 11:16:03       6 阅读
  2. JPA + ES 动态条件查询

    2024-01-16 11:16:03       30 阅读
  3. 数据库查询--条件查询

    2024-01-16 11:16:03       11 阅读
  4. php根据用户地址获取经纬度

    2024-01-16 11:16:03       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-16 11:16:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-16 11:16:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-16 11:16:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-16 11:16:03       18 阅读

热门阅读

  1. C语言作用域和存储期简单介绍

    2024-01-16 11:16:03       35 阅读
  2. 在Dynamics 365中通过代码为用户添加角色

    2024-01-16 11:16:03       33 阅读
  3. PXC集群(MySQL8.0版本)

    2024-01-16 11:16:03       29 阅读
  4. oracle分区

    2024-01-16 11:16:03       23 阅读
  5. 前端面试题-webpack

    2024-01-16 11:16:03       37 阅读
  6. Spark-RDD的依赖

    2024-01-16 11:16:03       31 阅读
  7. 安装 Git

    2024-01-16 11:16:03       32 阅读
  8. Unity3D 服务器逻辑和传输如何分层/解耦详解

    2024-01-16 11:16:03       34 阅读
  9. Wargames与bash知识18

    2024-01-16 11:16:03       27 阅读