<?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.dcs.hnyz.mapper.DcsRequestTaskMapper">

    <resultMap type="DcsRequestTask" id="DcsRequestTaskResult">
        <result property="requestId"    column="request_id"    />
        <result property="requestName"    column="request_name"    />
        <result property="requestCode"    column="request_code"    />
        <result property="lineCode"    column="line_code"    />
        <result property="requestType"    column="request_type"    />
        <result property="requestParam"    column="request_param"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectDcsRequestTaskVo">
        select request_id, request_name, request_code, line_code, request_type, request_param, status, del_flag, create_by, update_by, create_time, update_time, remark from dcs_request_task
    </sql>

    <select id="selectDcsRequestTaskList" parameterType="DcsRequestTask" resultMap="DcsRequestTaskResult">
        <include refid="selectDcsRequestTaskVo"/>
        <where>
            <if test="requestName != null  and requestName != ''"> and request_name like concat('%', #{requestName}, '%')</if>
            <if test="requestCode != null  and requestCode != ''"> and request_code = #{requestCode}</if>
            <if test="lineCode != null  and lineCode != ''"> and line_code = #{lineCode}</if>
            <if test="requestType != null  and requestType != ''"> and request_type = #{requestType}</if>
            <if test="requestParam != null  and requestParam != ''"> and request_param = #{requestParam}</if>
            <if test="status != null"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectDcsRequestTaskByRequestId" parameterType="Long" resultMap="DcsRequestTaskResult">
        <include refid="selectDcsRequestTaskVo"/>
        where request_id = #{requestId}
    </select>

    <insert id="insertDcsRequestTask" parameterType="DcsRequestTask" useGeneratedKeys="true" keyProperty="requestId">
        insert into dcs_request_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="requestName != null">request_name,</if>
            <if test="requestCode != null">request_code,</if>
            <if test="lineCode != null">line_code,</if>
            <if test="requestType != null">request_type,</if>
            <if test="requestParam != null">request_param,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="requestName != null">#{requestName},</if>
            <if test="requestCode != null">#{requestCode},</if>
            <if test="lineCode != null">#{lineCode},</if>
            <if test="requestType != null">#{requestType},</if>
            <if test="requestParam != null">#{requestParam},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateDcsRequestTask" parameterType="DcsRequestTask">
        update dcs_request_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="requestName != null">request_name = #{requestName},</if>
            <if test="requestCode != null">request_code = #{requestCode},</if>
            <if test="lineCode != null"> and line_code = #{lineCode},</if>
            <if test="requestType != null">request_type = #{requestType},</if>
            <if test="requestParam != null">request_param = #{requestParam},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where request_id = #{requestId}
    </update>

    <delete id="deleteDcsRequestTaskByRequestId" parameterType="Long">
        delete from dcs_request_task where request_id = #{requestId}
    </delete>

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