153 lines
5.3 KiB
XML
153 lines
5.3 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||
|
||
<mapper namespace="com.central.order.mapper.TourismMapper">
|
||
|
||
<select id="findList" resultType="com.central.order.model.Tourism">
|
||
SELECT *
|
||
FROM tourisms t
|
||
<where>
|
||
<if test="p.tenantIds != null and p.tenantIds.size > 0">
|
||
AND t.tenant_id IN
|
||
<foreach collection="p.tenantIds" item="tid" open="(" separator="," close=")">
|
||
#{tid}
|
||
</foreach>
|
||
</if>
|
||
<if test="(p.tenantIds == null or p.tenantIds.size == 0) and p.tenantId != null and p.tenantId != ''">
|
||
AND t.tenant_id = #{p.tenantId}
|
||
</if>
|
||
<if test="p.tourismName != null and p.tourismName != ''">
|
||
AND t.tourism_name LIKE CONCAT('%', #{p.tourismName}, '%')
|
||
</if>
|
||
</where>
|
||
ORDER BY t.id DESC
|
||
</select>
|
||
|
||
<resultMap id="TourismResultMap" type="com.central.order.model.Tourism">
|
||
</resultMap>
|
||
<select id="getTourismById" resultMap="TourismResultMap">
|
||
SELECT * FROM tourisms WHERE id = #{id}
|
||
</select>
|
||
|
||
<insert id="insertTourism">
|
||
INSERT INTO tourisms (tourism_no, tourism_name, tourism_address,tourism_phone)
|
||
VALUES (#{tourismNo}, #{tourismName}, #{tourismAddress},#{tourismPhone})
|
||
</insert>
|
||
|
||
<!-- 获取景区设备列表 -->
|
||
<select id="getDevicesByTourismId" resultType="java.util.Map">
|
||
SELECT DISTINCT
|
||
q.device_sn as deviceSn,
|
||
q.name as qrcodeName,
|
||
q.code_id as qrcodeId,
|
||
q.price as qrcodePrice,
|
||
q.status as qrcodeStatus,
|
||
q.create_time as qrcodeCreateTime,
|
||
t.tourism_name as tourismName,
|
||
t.tourism_address as tourismAddress
|
||
FROM qrcodes q
|
||
LEFT JOIN tourisms t ON q.tourism_id = t.id
|
||
WHERE q.tourism_id = #{tourismId}
|
||
AND q.is_del = 0
|
||
AND t.is_del = 0
|
||
ORDER BY q.create_time DESC
|
||
</select>
|
||
|
||
<!-- 查询附近景区列表 -->
|
||
<select id="findNearbyTourisms" resultType="com.central.order.model.TourismWithDistance">
|
||
<![CDATA[
|
||
SELECT
|
||
*,
|
||
(
|
||
6371 * acos(
|
||
cos(radians(#{latitude})) *
|
||
cos(radians(latitude)) *
|
||
cos(radians(longitude) - radians(#{longitude})) +
|
||
sin(radians(#{latitude})) *
|
||
sin(radians(latitude))
|
||
)
|
||
) AS distance
|
||
FROM tourisms
|
||
WHERE is_del = 0
|
||
AND status = 1
|
||
AND longitude IS NOT NULL
|
||
AND latitude IS NOT NULL
|
||
]]>
|
||
<choose>
|
||
<when test="showInHomepage != null">
|
||
<if test="showInHomepage == 1">
|
||
AND (show_in_homepage = 1 OR show_in_homepage IS NULL)
|
||
</if>
|
||
<if test="showInHomepage == 0">
|
||
AND show_in_homepage = 0
|
||
</if>
|
||
</when>
|
||
<otherwise>
|
||
AND (show_in_homepage = 1 OR show_in_homepage IS NULL)
|
||
</otherwise>
|
||
</choose>
|
||
<![CDATA[
|
||
HAVING distance <= #{radius}
|
||
ORDER BY distance ASC
|
||
]]>
|
||
<if test="limit != null and limit > 0">
|
||
LIMIT #{limit}
|
||
</if>
|
||
</select>
|
||
|
||
<!-- 根据经纬度范围查询景区 -->
|
||
<select id="findTourismsByBounds" resultType="com.central.order.model.Tourism">
|
||
SELECT * FROM tourisms
|
||
WHERE is_del = 0
|
||
AND status = 1
|
||
AND longitude BETWEEN #{minLongitude} AND #{maxLongitude}
|
||
AND latitude BETWEEN #{minLatitude} AND #{maxLatitude}
|
||
ORDER BY create_time DESC
|
||
</select>
|
||
|
||
<!-- 根据租户ID集合查询景区ID集合 -->
|
||
<select id="findTourismIdsByTenantIds" resultType="java.lang.Long">
|
||
SELECT id FROM tourisms
|
||
WHERE is_del = 0
|
||
<if test="tenantIds != null and tenantIds.size > 0">
|
||
AND tenant_id IN
|
||
<foreach collection="tenantIds" item="tid" open="(" separator="," close=")">
|
||
#{tid}
|
||
</foreach>
|
||
</if>
|
||
ORDER BY id DESC
|
||
</select>
|
||
|
||
<!-- 基于二维码表按租户反查景区ID(容错方案) -->
|
||
<select id="findTourismIdsByTenantIdsFromQrcodes" resultType="java.lang.Long">
|
||
SELECT DISTINCT q.tourism_id
|
||
FROM qrcodes q
|
||
WHERE q.is_del = 0
|
||
AND q.tourism_id IS NOT NULL
|
||
<if test="tenantIds != null and tenantIds.size > 0">
|
||
AND q.tenant_id IN
|
||
<foreach collection="tenantIds" item="tid" open="(" separator="," close=")">
|
||
#{tid}
|
||
</foreach>
|
||
</if>
|
||
ORDER BY q.tourism_id DESC
|
||
</select>
|
||
|
||
<!-- 全部景区ID(webApp全库统计使用) -->
|
||
<select id="findAllTourismIds" resultType="java.lang.Long">
|
||
SELECT id FROM tourisms WHERE is_del = 0 ORDER BY id DESC
|
||
</select>
|
||
|
||
|
||
<!-- 根据单个租户ID查询景区ID集合 -->
|
||
<select id="findTourismIdsByTenantId" resultType="java.lang.Long">
|
||
SELECT id FROM tourisms
|
||
WHERE is_del = 0
|
||
<if test="tenantId != null and tenantId != ''">
|
||
AND tenant_id = #{tenantId}
|
||
</if>
|
||
ORDER BY id DESC
|
||
</select>
|
||
|
||
</mapper>
|