<?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.ruoyi.szxc.mapper.SzxcJmTagMapper">

    <resultMap type="SzxcJmTag" id="SzxcJmTagResult">
        <result property="id"    column="id"    />
        <result property="jmId"    column="jm_id"    />
        <result property="tagId"    column="tag_id"    />
        <result property="tagName"    column="tag_name"    />
    </resultMap>

    <sql id="selectSzxcJmTagVo">
        select id, jm_id, tag_id, tag_name from szxc_jm_tag
    </sql>

    <select id="selectSzxcJmTagList" parameterType="SzxcJmTag" resultMap="SzxcJmTagResult">
        <include refid="selectSzxcJmTagVo"/>
        <where>
            <if test="jmId != null "> and jm_id = #{jmId}</if>
            <if test="tagId != null "> and tag_id = #{tagId}</if>
            <if test="tagName != null  and tagName != ''"> and tag_name like concat('%', #{tagName}, '%')</if>
        </where>
    </select>

    <select id="selectSzxcJmTagById" parameterType="Long" resultMap="SzxcJmTagResult">
        <include refid="selectSzxcJmTagVo"/>
        where id = #{id}
    </select>

    <insert id="insertSzxcJmTag" parameterType="SzxcJmTag" useGeneratedKeys="true" keyProperty="id">
        insert into szxc_jm_tag
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="jmId != null">jm_id,</if>
            <if test="tagId != null">tag_id,</if>
            <if test="tagName != null">tag_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="jmId != null">#{jmId},</if>
            <if test="tagId != null">#{tagId},</if>
            <if test="tagName != null">#{tagName},</if>
        </trim>
    </insert>

    <update id="updateSzxcJmTag" parameterType="SzxcJmTag">
        update szxc_jm_tag
        <trim prefix="SET" suffixOverrides=",">
            <if test="jmId != null">jm_id = #{jmId},</if>
            <if test="tagId != null">tag_id = #{tagId},</if>
            <if test="tagName != null">tag_name = #{tagName},</if>
        </trim>
        where id = #{id}
    </update>

    <!--删除所有jmid对应的数据 -->
    <delete id="deleteSzxcJmTagByJmId" parameterType="Long">
        delete from szxc_jm_tag where jm_id = #{jmId}
    </delete>

    <delete id="deleteSzxcJmTagById" parameterType="Long">
        delete from szxc_jm_tag where id = #{id}
    </delete>

    <delete id="deleteSzxcJmTagByIds" parameterType="String">
        delete from szxc_jm_tag where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>