【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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tellsea

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值