<?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.project.invoice.mapper.TInvoiceTagMapper">

    <resultMap type="TInvoiceTag" id="TInvoiceTagResult">
        <result property="id"    column="id"    />
        <result property="tag"    column="tag"    />
        <result property="sort"    column="sort"    />
        <result property="type"    column="type"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTInvoiceTagVo">
        select d.id, d.tag, d.sort, d.type, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_invoice_tag d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTInvoiceTagList" parameterType="TInvoiceTag" resultMap="TInvoiceTagResult">
        <include refid="selectTInvoiceTagVo"/>
        <where>
            <if test="tag != null  and tag != ''"> and tag = #{tag}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.sort desc
    </select>

    <select id="selectTInvoiceTagById" parameterType="Long" resultMap="TInvoiceTagResult">
        <include refid="selectTInvoiceTagVo"/>
        where id = #{id}
    </select>

    <insert id="insertTInvoiceTag" parameterType="TInvoiceTag">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_invoice_tag.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_invoice_tag
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="tag != null">tag,</if>
            <if test="sort != null">sort,</if>
            <if test="type != null">type,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="tag != null">#{tag},</if>
            <if test="sort != null">#{sort},</if>
            <if test="type != null">#{type},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTInvoiceTag" parameterType="TInvoiceTag">
        update t_invoice_tag
        <trim prefix="SET" suffixOverrides=",">
            <if test="tag != null">tag = #{tag},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="type != null">type = #{type},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTInvoiceTagById" parameterType="Long">
        update t_invoice_tag set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTInvoiceTagByIds" parameterType="String">
        update t_invoice_tag set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
