You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

295 lines
11 KiB

<?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.youlai.boot.mini.mapper.MiniStrayAnimalMapper">
<insert id="insertStrayAnimal" parameterType="com.youlai.boot.mini.model.entity.MiniStrayAnimal" useGeneratedKeys="true" keyProperty="id">
INSERT INTO mini_stray_animal
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="uuid != null">uuid,</if>
<if test="miniUserId != null">mini_user_id,</if>
<if test="animalType != null">animal_type,</if>
<if test="color != null">color,</if>
<if test="size != null">size,</if>
<if test="status != null">status,</if>
<if test="adoptedBy != null">adopted_by,</if>
<if test="adoptedAt != null">adopted_at,</if>
<if test="auditStatus != null">audit_status,</if>
<if test="province != null">province,</if>
<if test="city != null">city,</if>
<if test="district != null">district,</if>
<if test="address != null">address,</if>
<if test="gdLocationPoint != null">gd_location_point,</if>
<if test="wgs84LocationPoint != null">wgs84_location_point,</if>
<if test="wgs84Geohash != null">wgs84_geohash,</if>
<if test="createTime != null">create_time,</if>
<if test="createTimestamp != null">create_timestamp,</if>
<if test="createBy != null">create_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="updateTimestamp != null">update_timestamp,</if>
<if test="updateBy != null">update_by,</if>
<if test="deleted != null">is_deleted,</if>
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="uuid != null">#{uuid},</if>
<if test="miniUserId != null">#{miniUserId},</if>
<if test="animalType != null">#{animalType},</if>
<if test="color != null">#{color},</if>
<if test="size != null">#{size},</if>
<if test="status != null">#{status},</if>
<if test="adoptedBy != null">#{adoptedBy},</if>
<if test="adoptedAt != null">#{adoptedAt},</if>
<if test="auditStatus != null">#{auditStatus},</if>
<if test="province != null">#{province},</if>
<if test="city != null">#{city},</if>
<if test="district != null">#{district},</if>
<if test="address != null">#{address},</if>
<if test="gdLocationPoint != null">
ST_GeomFromWKB(#{gdLocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326, 'axis-order=long-lat'),
</if>
<if test="wgs84LocationPoint != null">
ST_GeomFromWKB(#{wgs84LocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326, 'axis-order=long-lat'),
</if>
<if test="wgs84Geohash != null">#{wgs84Geohash},</if>
<if test="createTime != null">#{createTime},</if>
<if test="createTimestamp != null">#{createTimestamp},</if>
<if test="createBy != null">#{createBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="updateTimestamp != null">#{updateTimestamp},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="deleted != null">#{deleted},</if>
</trim>
</insert>
<update id="updateStrayAnimal" parameterType="com.youlai.boot.mini.model.entity.MiniStrayAnimal">
UPDATE mini_stray_animal
<set>
<if test="uuid != null">uuid = #{uuid},</if>
<if test="miniUserId != null">mini_user_id = #{miniUserId},</if>
<if test="animalType != null">animal_type = #{animalType},</if>
<if test="color != null">color = #{color},</if>
<if test="size != null">size = #{size},</if>
<if test="status != null">status = #{status},</if>
<if test="adoptedBy != null">adopted_by = #{adoptedBy},</if>
<if test="adoptedAt != null">adopted_at = #{adoptedAt},</if>
<if test="auditStatus != null">audit_status = #{auditStatus},</if>
<if test="province != null">province = #{province},</if>
<if test="city != null">city = #{city},</if>
<if test="district != null">district = #{district},</if>
<if test="address != null">address = #{address},</if>
<if test="gdLocationPoint != null">
gd_location_point =
ST_GeomFromWKB(#{gdLocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326, 'axis-order=long-lat'),
</if>
<if test="wgs84LocationPoint != null">
wgs84_location_point =
ST_GeomFromWKB(#{wgs84LocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326, 'axis-order=long-lat'),
</if>
<if test="wgs84Geohash != null">wgs84_geohash = #{wgs84Geohash},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="updateTimestamp != null">update_timestamp = #{updateTimestamp},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
</set>
WHERE id = #{id}
</update>
<select id="getAnimalPage" resultType="com.youlai.boot.mini.model.vo.StrayAnimalShortVO" databaseId="mysql">
WITH first_image AS (
SELECT
m.note_id,
m.source_url,
ROW_NUMBER() OVER (
PARTITION BY m.note_id
ORDER BY m.id ASC
) AS rn
FROM mini_stray_animal_note_media m
WHERE m.media_type = 'image'
AND m.is_deleted = 0
)
SELECT
u.uuid AS authorUuid,
u.nickname AS authorName,
u.avatar AS authorAvatar,
a.uuid AS animalUuid,
n.uuid AS animalNoteUuid,
a.animal_type,
fi.source_url AS firstImageUrl,
n.title,
n.content,
n.visibility,
n.view_count,
n.like_count,
n.comment_count,
n.collect_count,
<if test="queryParams.miniUserId != null">
-- 当前用户是否点赞
EXISTS (
SELECT 1
FROM mini_stray_animal_note_like l
WHERE l.note_id = n.id
AND l.mini_user_id = #{queryParams.miniUserId}
AND l.is_deleted = 0
) AS isLiked,
-- 当前用户是否收藏
EXISTS (
SELECT 1
FROM mini_stray_animal_note_collect c
WHERE c.note_id = n.id
AND c.mini_user_id = #{queryParams.miniUserId}
AND c.is_deleted = 0
) AS isCollected,
</if>
a.audit_status
FROM
mini_stray_animal a
INNER JOIN sys_user u ON a.mini_user_id = u.id
LEFT JOIN mini_stray_animal_note n ON n.stray_animal_id = a.id
LEFT JOIN first_image fi ON fi.note_id = n.id AND fi.rn = 1
<where>
n.is_deleted = 0 AND a.is_deleted = 0
<!-- 指定用户 -->
AND n.mini_user_id = #{queryParams.creatorId}
<!-- 动物类型 -->
<if test="queryParams.animalType != null and queryParams.animalType != ''">
AND a.animal_type = #{queryParams.animalType}
</if>
<!-- 时间范围 -->
<if test="queryParams.createStartTimestamp != null">
AND a.create_timestamp >= #{queryParams.createStartTimestamp}
</if>
<if test="queryParams.createEndTimestamp != null">
AND #{queryParams.createEndTimestamp} >= a.create_timestamp
</if>
</where>
ORDER BY a.id DESC
</select>
<select id="getStrayAnimalDetails" resultType="com.youlai.boot.mini.model.vo.StrayAnimalDetailsVO">
SELECT
su.uuid AS authorUuid,
su.nickname AS authorName,
su.avatar AS authorAvatar,
a.uuid AS animalUuid,
a.animal_type,
a.color,
a.size,
a.status,
a.audit_status,
n.uuid animalNoteUuid,
n.title,
n.content,
n.visibility,
n.view_count,
n.like_count,
n.comment_count,
n.collect_count,
<if test="miniUserId != null">
-- 当前用户是否点赞
EXISTS (
SELECT 1
FROM mini_stray_animal_note_like l
WHERE l.note_id = n.id
AND l.mini_user_id = #{miniUserId}
AND l.is_deleted = 0
) AS isLiked,
-- 当前用户是否收藏
EXISTS (
SELECT 1
FROM mini_stray_animal_note_collect c
WHERE c.note_id = n.id
AND c.mini_user_id = #{miniUserId}
AND c.is_deleted = 0
) AS isCollected,
</if>
a.province,
a.city,
a.district,
ST_Longitude(a.gd_location_point) AS lng,
ST_Latitude(a.gd_location_point) AS lat,
a.address
FROM
mini_stray_animal a
LEFT JOIN mini_stray_animal_note n ON a.id = n.stray_animal_id
LEFT JOIN sys_user su ON su.id = a.mini_user_id AND su.is_deleted = 0
WHERE a.uuid = #{animalUuid}
</select>
<select id="listByMapBounds" resultType="com.youlai.boot.mini.model.vo.StrayAnimalNearbyVO">
SELECT
uuid animalUuid,
animal_type,
color,
size,
ST_Longitude(gd_location_point) AS lng,
ST_Latitude(gd_location_point) AS lat
FROM
mini_stray_animal
WHERE is_deleted = 0
AND MBRContains(
ST_GeomFromText(
CONCAT(
'Polygon((',
#{southWestLat}, ' ', #{southWestLng}, ',',
#{southWestLat}, ' ', #{northEastLng}, ',',
#{northEastLat}, ' ', #{northEastLng}, ',',
#{northEastLat}, ' ', #{southWestLng}, ',',
#{southWestLat}, ' ', #{southWestLng},
'))'
), 4326
),
wgs84_location_point
)
<if test="animalType != null and animalType !=''">
AND animal_type = #{animalType}
</if>
</select>
</mapper>