Files

117 lines
3.6 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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.cbsd.universaltestsoftware_client.mapper.InstructMapper">
<!-- 查找前一个兄弟 -->
<select id="findPrevSibling" resultType="com.cbsd.universaltestsoftware_client.entity.Instruct">
SELECT *
FROM instruct
WHERE sort &lt; #{sort}
AND invocation_id = #{invocationId}
AND parent_encoding= #{parentEncoding}
ORDER BY sort DESC
LIMIT 1
</select>
<!-- 查找后一个兄弟 -->
<select id="findNextSibling" resultType="com.cbsd.universaltestsoftware_client.entity.Instruct">
SELECT *
FROM instruct
WHERE sort > #{sort}
AND invocation_id = #{invocationId}
AND parent_encoding= #{parentEncoding}
ORDER BY sort ASC
LIMIT 1
</select>
<!-- 更新指令(至少更新 sort -->
<update id="updateSort">
UPDATE instruct
SET sort = #{sort}
WHERE instruct_id = #{instructId}
</update>
<!-- 全局重排 -->
<update id="reorderGlobalSortContinuous">
UPDATE instruct t
JOIN (
SELECT instruct_id,
(@rn := @rn + 1) AS rn
FROM (SELECT * FROM instruct WHERE invocation_id = #{invocationId} ORDER BY sort) tmp,
(SELECT @rn := 0) init
) r ON t.instruct_id = r.instruct_id
SET t.sort = r.rn
WHERE t.invocation_id = #{invocationId}
</update>
<!-- 根据 ids + invocationId 查询 -->
<select id="selectByIdsAndInvocation" resultType="com.cbsd.universaltestsoftware_client.entity.Instruct">
SELECT * FROM instruct
WHERE instruct_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND invocation_id = #{invocationId}
</select>
<!-- 置零 sort -->
<update id="setSortZeroByIds">
UPDATE instruct
SET sort = 0
WHERE instruct_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<!-- 整棵子树(多个前缀) -->
<select id="listByInvocationAndEncodingPrefix" resultType="com.cbsd.universaltestsoftware_client.entity.Instruct">
SELECT * FROM instruct
WHERE invocation_id = #{invocationId}
<foreach collection="encodings" item="enc" open="AND (" close=")" separator="OR">
encoding LIKE CONCAT(#{enc},'%')
</foreach>
ORDER BY encoding
</select>
<select id="listByParentEncodingAndInvocation"
resultType="com.cbsd.universaltestsoftware_client.entity.Instruct">
SELECT * FROM instruct
WHERE invocation_id = #{invocationId}
AND parent_encoding = #{parentCode}
ORDER BY sort
</select>
<update id="shiftSortAfter">
UPDATE instruct
SET sort = sort + 1
WHERE invocation_id = #{invocationId}
AND sort >= #{sort} and instruct_id !=#{instructId}
</update>
<update id="minusSort">
UPDATE instruct
SET sort = sort - 1
WHERE invocation_id = #{invocationId}
AND sort &gt;= #{oldSort}
AND sort &lt;= #{newSort}
AND instruct_id != #{instructId}
</update>
<update id="plusSort">
UPDATE instruct
SET sort = sort + 1
WHERE invocation_id = #{invocationId}
AND sort &gt;= #{newSort}
AND sort &lt;= #{oldSort}
AND instruct_id != #{instructId}
</update>
</mapper>