Files
tool-tech/tool-tech-admin/src/main/resources/mapper/ToolRelationMapper.xml
2024-09-08 20:34:39 +08:00

101 lines
4.1 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.rzdata.web.mapper.ToolRelationMapper">
<resultMap type="ToolRelation" id="ToolRelationResult">
<result property="id" column="id" />
<result property="resourceId" column="resource_id" />
<result property="targetId" column="target_id" />
<result property="toolCode" column="tool_code" />
<result property="toolName" column="tool_name" />
</resultMap>
<sql id="selectToolRelationVo">
select id, resource_id, target_id from t_tool_relation
</sql>
<select id="selectToolRelationList" parameterType="ToolRelation" resultMap="ToolRelationResult">
<include refid="selectToolRelationVo"/>
<where>
<if test="resourceId != null and resourceId != ''"> and resource_id = #{resourceId}</if>
<if test="targetId != null and targetId != ''"> and target_id = #{targetId}</if>
</where>
</select>
<select id="selectRelationToolList" parameterType="ToolRelation" resultMap="ToolRelationResult">
select
tr.id, tr.resource_id, tr.target_id,tl.tool_code,tl.tool_name
from t_tool_relation tr
left join t_tool tl on tr.target_id = tl.tool_id
<where>
<if test="resourceId != null and resourceId != ''"> and tr.resource_id = #{resourceId}</if>
<if test="targetId != null and targetId != ''"> and tr.target_id = #{targetId}</if>
<if test="resourceIds != null and resourceIds.size() > 0">
and tr.resource_id in
<foreach item="id" index="index" collection="resourceIds" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
</select>
<select id="selectToolRelationById" parameterType="String" resultMap="ToolRelationResult">
<include refid="selectToolRelationVo"/>
where id = #{id}
</select>
<insert id="insertToolRelation" parameterType="ToolRelation">
insert into t_tool_relation
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="resourceId != null">resource_id,</if>
<if test="targetId != null">target_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="resourceId != null">#{resourceId},</if>
<if test="targetId != null">#{targetId},</if>
</trim>
</insert>
<update id="updateToolRelation" parameterType="ToolRelation">
update t_tool_relation
<trim prefix="SET" suffixOverrides=",">
<if test="resourceId != null">resource_id = #{resourceId},</if>
<if test="targetId != null">target_id = #{targetId},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteToolRelationById" parameterType="String">
delete from t_tool_relation where id = #{id}
</delete>
<delete id="deleteResourceAndTarget" parameterType="String">
delete from t_tool_relation where resource_id = #{resourceId} and target_id = #{targetId}
</delete>
<delete id="deleteTargetAndResource" parameterType="String">
delete from t_tool_relation where target_id = #{targetId} and resource_id = #{resourceId}
</delete>
<delete id="deleteToolRelationByIds" parameterType="String">
delete from t_tool_relation where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<!-- 批量插入 -->
<insert id="batchInsert" parameterType="java.util.List">
insert into t_tool_relation (id, resource_id, target_id)
values
<foreach item="item" index="index" collection="toolRelationList" open="(" separator="),(" close=")">
#{item.id}, #{item.resourceId}, #{item.targetId}
</foreach>
</insert>
</mapper>