<?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.ticket.mapper.TTicketIdMapper">
    
    <resultMap type="TTicketId" id="TTicketIdResult">
        <result property="id"    column="id"    />
        <result property="ticketId"    column="ticket_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="ticketType"    column="ticket_type"    />
        <result property="ticketFull"    column="ticket_full"    />
        <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="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTicketIdVo">
        select d.id, d.ticket_id, d.dept_id, d.plant_code, d.ticket_type, d.ticket_full, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks ,s.dept_name from t_ticket_id d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTicketIdList" parameterType="TTicketId" resultMap="TTicketIdResult">
        <include refid="selectTTicketIdVo"/>
        <where>  
            <if test="ticketId != null "> and ticket_id = #{ticketId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="plantCode != null "> and plant_code = #{plantCode}</if>
            <if test="ticketType != null "> and ticket_type = #{ticketType}</if>
            <if test="ticketFull != null  and ticketFull != ''"> and ticket_full = #{ticketFull}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTTicketIdById" parameterType="Long" resultMap="TTicketIdResult">
        <include refid="selectTTicketIdVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTTicketId" parameterType="TTicketId">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_ticket_id.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_ticket_id
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="ticketId != null">ticket_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="ticketType != null">ticket_type,</if>
            <if test="ticketFull != null">ticket_full,</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="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="ticketId != null">#{ticketId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="ticketType != null">#{ticketType},</if>
            <if test="ticketFull != null">#{ticketFull},</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="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTTicketId" parameterType="TTicketId">
        update t_ticket_id
        <trim prefix="SET" suffixOverrides=",">
            <if test="ticketId != null">ticket_id = #{ticketId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="ticketType != null">ticket_type = #{ticketType},</if>
            <if test="ticketFull != null">ticket_full = #{ticketFull},</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="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

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

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