You've already forked FrameTour-BE
refactor(mapper):优化查询逻辑并处理空列表情况
- 将 filterExistingRelations 查询中的 if 判断替换为 choose-when 结构 - 在 otherwise 分支中添加空结果集查询,避免空列表时 SQL 异常- 统一 filterValidSourceRelations 查询结构,增强代码一致性 -修正 foreach 标签中 UNION ALL 前后的空格问题,确保 SQL 语法正确- 提升 XML 映射文件的可读性和健壮性
This commit is contained in:
@@ -17,7 +17,8 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
<select id="filterExistingRelations" resultType="com.ycwl.basic.model.pc.source.entity.MemberSourceEntity">
|
<select id="filterExistingRelations" resultType="com.ycwl.basic.model.pc.source.entity.MemberSourceEntity">
|
||||||
<if test="list != null and list.size() > 0">
|
<choose>
|
||||||
|
<when test="list != null and list.size() > 0">
|
||||||
SELECT
|
SELECT
|
||||||
r.memberId as memberId,
|
r.memberId as memberId,
|
||||||
r.sourceId as sourceId,
|
r.sourceId as sourceId,
|
||||||
@@ -49,13 +50,28 @@
|
|||||||
AND ms.type = r.type
|
AND ms.type = r.type
|
||||||
AND ms.face_id = r.faceId
|
AND ms.face_id = r.faceId
|
||||||
)
|
)
|
||||||
</if>
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
SELECT
|
||||||
|
NULL as memberId,
|
||||||
|
NULL as sourceId,
|
||||||
|
NULL as type,
|
||||||
|
NULL as faceId,
|
||||||
|
NULL as scenicId,
|
||||||
|
NULL as isBuy,
|
||||||
|
NULL as orderId,
|
||||||
|
NULL as isFree,
|
||||||
|
NULL as id
|
||||||
|
WHERE 1 = 0
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
</select>
|
</select>
|
||||||
<select id="sourceExists" resultType="boolean">
|
<select id="sourceExists" resultType="boolean">
|
||||||
SELECT COUNT(1) > 0 FROM source WHERE id = #{sourceId}
|
SELECT COUNT(1) > 0 FROM source WHERE id = #{sourceId}
|
||||||
</select>
|
</select>
|
||||||
<select id="filterValidSourceRelations" resultType="com.ycwl.basic.model.pc.source.entity.MemberSourceEntity">
|
<select id="filterValidSourceRelations" resultType="com.ycwl.basic.model.pc.source.entity.MemberSourceEntity">
|
||||||
<if test="list != null and list.size() > 0">
|
<choose>
|
||||||
|
<when test="list != null and list.size() > 0">
|
||||||
SELECT
|
SELECT
|
||||||
r.memberId as memberId,
|
r.memberId as memberId,
|
||||||
r.sourceId as sourceId,
|
r.sourceId as sourceId,
|
||||||
@@ -67,7 +83,7 @@
|
|||||||
r.isFree as isFree,
|
r.isFree as isFree,
|
||||||
r.id as id
|
r.id as id
|
||||||
FROM (
|
FROM (
|
||||||
<foreach collection="list" item="item" separator="UNION ALL ">
|
<foreach collection="list" item="item" separator=" UNION ALL ">
|
||||||
SELECT
|
SELECT
|
||||||
#{item.memberId} as memberId,
|
#{item.memberId} as memberId,
|
||||||
#{item.sourceId} as sourceId,
|
#{item.sourceId} as sourceId,
|
||||||
@@ -83,7 +99,21 @@
|
|||||||
WHERE EXISTS (
|
WHERE EXISTS (
|
||||||
SELECT 1 FROM source s WHERE s.id = r.sourceId
|
SELECT 1 FROM source s WHERE s.id = r.sourceId
|
||||||
)
|
)
|
||||||
</if>
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
SELECT
|
||||||
|
NULL as memberId,
|
||||||
|
NULL as sourceId,
|
||||||
|
NULL as type,
|
||||||
|
NULL as faceId,
|
||||||
|
NULL as scenicId,
|
||||||
|
NULL as isBuy,
|
||||||
|
NULL as orderId,
|
||||||
|
NULL as isFree,
|
||||||
|
NULL as id
|
||||||
|
WHERE 1 = 0
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
</select>
|
</select>
|
||||||
<insert id="addSourceWatermark">
|
<insert id="addSourceWatermark">
|
||||||
insert source_watermark(source_id, face_id, watermark_type, watermark_url)
|
insert source_watermark(source_id, face_id, watermark_type, watermark_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user