<?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.web.v1.mapper.DeadDisposalMapper">
    
    <resultMap type="com.ruoyi.web.v1.model.DeadDisposal" id="DeadDisposalResult">
        <result property="id"    column="id"    />
        <result property="dealReason"    column="deal_reason"    />
        <result property="dealWay"    column="deal_way"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectDeadDisposalVo">
        select id, deal_reason, deal_way, create_time, create_by, update_time, update_by, del_flag from dead_disposal
    </sql>

    <select id="selectDeadDisposalList" parameterType="com.ruoyi.web.v1.model.DeadDisposal" resultMap="DeadDisposalResult">
        <include refid="selectDeadDisposalVo"/>
        <where>
            del_flag = '0'
            <if test="dealReason != null  and dealReason != ''"> and deal_reason like concat('%', #{dealReason}, '%')</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectDeadDisposalById" parameterType="Long" resultMap="DeadDisposalResult">
        <include refid="selectDeadDisposalVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="checkDealReasonUnique" parameterType="String" resultMap="DeadDisposalResult">
        select id, deal_reason from dead_disposal where deal_reason = #{dealReason} and del_flag = '0' limit 1
    </select>

    <insert id="insertDeadDisposal" parameterType="com.ruoyi.web.v1.model.DeadDisposal" useGeneratedKeys="true" keyProperty="id">
        insert into dead_disposal
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dealReason != null and dealReason != ''">deal_reason,</if>
            <if test="dealWay != null and dealWay != ''">deal_way,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            del_flag
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dealReason != null and dealReason != ''">#{dealReason},</if>
            <if test="dealWay != null and dealWay != ''">#{dealWay},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            '0'
         </trim>
    </insert>

    <update id="updateDeadDisposal" parameterType="com.ruoyi.web.v1.model.DeadDisposal">
        update dead_disposal
        <trim prefix="SET" suffixOverrides=",">
            <if test="dealReason != null and dealReason != ''">deal_reason = #{dealReason},</if>
            <if test="dealWay != null and dealWay != ''">deal_way = #{dealWay},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeadDisposalById" parameterType="Long">
        update dead_disposal set del_flag = '2' where id = #{id}
    </delete>

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