目 录CONTENT

文章目录

经纬度相关查询SQL(MySQL)

BKUN
2022-05-29 / 0 评论 / 1 点赞 / 2,392 阅读 / 1,111 字

MyBatis片段

select
		mer_id,nation_id,province_id,city_id,mer_name,mer_des,business_circle_id,
		mer_type_id,mer_address,mer_lon,mer_lat,mer_phone,mer_price,mer_evaluate,
		mer_service,mer_rank,mer_is_group_buy,mer_discount,mer_is_member,
		mer_is_order,mer_is_take_out,mer_is_car,mer_is_wifi,mer_url,
		mer_all_rating,mer_srating,mer_erating,mer_comment_num,
		mer_begintime,mer_endtime,status,remarks,
		create_by,create_date,update_by,update_date,mer_opening_hours
		<if test="hotelMer.merLon != null  and hotelMer.merLon != ''  and hotelMer.merLat != null  and hotelMer.merLat != ''">
            ,ROUND(
            6378.138 * 2 * ASIN(
            SQRT(
            POW(
            SIN(
            (
            #{hotelMer.merLat} * PI() / 180 - mer_lat * PI() / 180
            ) / 2
            ),
            2
            ) + COS( #{hotelMer.merLat} * PI() / 180) * COS(mer_lat * PI() / 180) * POW(
            SIN(
            (
            #{hotelMer.merLon}  * PI() / 180 - mer_lon * PI() / 180
            ) / 2
            ),
            2
            )
            )
            ) * 1000
            ) AS distance
        </if>
		from hotel_mer where 1=1 
		<if test="hotelMer.merId != null and hotelMer.merId != ''" >
			AND mer_id=#{hotelMer.merId}
		</if>
		<if test="hotelMer.nationId != null and hotelMer.nationId != ''" >
			AND nation_id=#{hotelMer.nationId}
		</if>
		<if test="hotelMer.provinceId != null and hotelMer.provinceId != ''" >
			AND province_id=#{hotelMer.provinceId}
		</if>
		<if test="hotelMer.cityId != null and hotelMer.cityId != ''" >
			AND city_id=#{hotelMer.cityId}
		</if>
		<if test="hotelMer.merName != null and hotelMer.merName != ''" >
			AND mer_name like concat(concat('%',#{hotelMer.merName}),'%')
		</if>
		<if test="hotelMer.merDes != null and hotelMer.merDes != ''" >
			AND mer_des=#{hotelMer.merDes}
		</if>
		<if test="hotelMer.businessCircleId != null and hotelMer.businessCircleId != ''" >
			AND business_circle_id=#{hotelMer.businessCircleId}
		</if>
		<if test="hotelMer.merTypeId != null and hotelMer.merTypeId != ''" >
			AND mer_type_id=#{hotelMer.merTypeId}
		</if>
		<if test="hotelMer.merAddress != null and hotelMer.merAddress != ''" >
			AND mer_address=#{hotelMer.merAddress}
		</if>
		<if test="hotelMer.merOpeningHours != null and hotelMer.merOpeningHours != ''" >
			AND mer_opening_hours=#{hotelMer.merOpeningHours}
		</if>
 		<if test="hotelMer.merLon != null " >
			AND mer_lon=#{hotelMer.merLon}
		</if>
		<if test="hotelMer.merLat != null " >
			AND mer_lat=#{hotelMer.merLat}
		</if> -->
		
		<!-- <if test="hotelMer.merLon != null  and hotelMer.merLon != ''  and hotelMer.merLat != null  and hotelMer.merLat != ''">
			and
			(
			acos(
            sin(( #{hotelMer.merLat} * 3.1415 )/ 180 ) * sin(( mer_lat * 3.1415 )/ 180 ) + cos(( #{hotelMer.merLat} * 3.1415 )/ 180 ) * cos(( mer_lat * 3.1415 )/ 180 ) * cos(( #{hotelMer.merLon} * 3.1415 )/ 180 - ( mer_lon * 3.1415 )/ 180 )
            )* 6370.996
            ) &lt;= 100
         </if>
		
		<if test="hotelMer.merPhone != null and hotelMer.merPhone != ''" >
			AND mer_phone=#{hotelMer.merPhone}
		</if>
		<if test="hotelMer.merPrice != null " >
			AND mer_price=#{hotelMer.merPrice}
		</if>
		<if test="hotelMer.merEvaluate != null and hotelMer.merEvaluate != ''" >
			AND mer_evaluate=#{hotelMer.merEvaluate}
		</if>
		<if test="hotelMer.merService != null and hotelMer.merService != ''" >
			AND mer_service=#{hotelMer.merService}
		</if>
		<if test="hotelMer.merRank != null and hotelMer.merRank != ''" >
			AND mer_rank=#{hotelMer.merRank}
		</if>
		<if test="hotelMer.merIsGroupBuy != null and hotelMer.merIsGroupBuy != ''" >
			AND mer_is_group_buy=#{hotelMer.merIsGroupBuy}
		</if>
		<if test="hotelMer.merDiscount != null and hotelMer.merDiscount != ''" >
			AND mer_discount=#{hotelMer.merDiscount}
		</if>
		<if test="hotelMer.merIsMember != null and hotelMer.merIsMember != ''" >
			AND mer_is_member=#{hotelMer.merIsMember}
		</if>
		<if test="hotelMer.merIsOrder != null and hotelMer.merIsOrder != ''" >
			AND mer_is_order=#{hotelMer.merIsOrder}
		</if>
		<if test="hotelMer.merIsTakeOut != null and hotelMer.merIsTakeOut != ''" >
			AND mer_is_take_out=#{hotelMer.merIsTakeOut}
		</if>
		<if test="hotelMer.merIsCar != null and hotelMer.merIsCar != ''" >
			AND mer_is_car=#{hotelMer.merIsCar}
		</if>
		<if test="hotelMer.merIsWifi != null and hotelMer.merIsWifi != ''" >
			AND mer_is_wifi=#{hotelMer.merIsWifi}
		</if>
		<if test="hotelMer.merUrl != null and hotelMer.merUrl != ''" >
			AND mer_url=#{hotelMer.merUrl}
		</if>
		<if test="hotelMer.merAllRating != null and hotelMer.merAllRating != ''" >
			AND mer_all_rating=#{hotelMer.merAllRating}
		</if>
		<if test="hotelMer.merSrating != null and hotelMer.merSrating != ''" >
			AND mer_srating=#{hotelMer.merSrating}
		</if>
		<if test="hotelMer.merErating != null and hotelMer.merErating != ''" >
			AND mer_erating=#{hotelMer.merErating}
		</if>
		<if test="hotelMer.merCommentNum != null and hotelMer.merCommentNum != ''" >
			AND mer_comment_num=#{hotelMer.merCommentNum}
		</if>
		<if test="hotelMer.merBegintime != null " >
			AND mer_begintime=#{hotelMer.merBegintime}
		</if>
		<if test="hotelMer.merEndtime != null " >
			AND mer_endtime=#{hotelMer.merEndtime}
		</if>
		<if test="hotelMer.status != null and hotelMer.status != ''" >
			AND status=#{hotelMer.status}
		</if>
		<if test="hotelMer.remarks != null and hotelMer.remarks != ''" >
			AND remarks=#{hotelMer.remarks}
		</if>
		<if test="hotelMer.createBy != null and hotelMer.createBy != ''" >
			AND create_by=#{hotelMer.createBy}
		</if>
		<if test="hotelMer.createDate != null " >
			AND create_date=#{hotelMer.createDate}
		</if>
		<if test="hotelMer.updateBy != null and hotelMer.updateBy != ''" >
			AND update_by=#{hotelMer.updateBy}
		</if>
		<if test="hotelMer.updateDate != null " >
			AND update_date=#{hotelMer.updateDate}
		</if>
		<if test='hotelMer.selectFlag != null and hotelMer.selectFlag == "1" and hotelMer.userId != null' >
			AND mer_id in (select mer_id from hotel_user_mer where user_id = #{hotelMer.userId})
		</if>
		<if test='hotelMer.selectFlag != null and hotelMer.selectFlag == "0" and hotelMer.userId != null' >
			AND mer_id not in (select mer_id from hotel_user_mer where user_id = #{hotelMer.userId})
		</if>
	</select>
1

评论区