<?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.ktg.iscs.mapper.IsSopUserMapper">
    
    <resultMap type="IsSopUser" id="IsSopUserResult">
        <result property="recordId"    column="record_id"    />
        <result property="sopId"    column="sop_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userType"    column="user_type"    />
        <result property="userRole"    column="user_role"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectIsSopUserVo">
        select record_id, sop_id, user_id, user_name, user_type, user_role, del_flag, create_by, create_time, update_time, update_by, remark from is_sop_user
    </sql>

    <select id="selectIsSopUserList" parameterType="IsSopUser" resultMap="IsSopUserResult">
        <include refid="selectIsSopUserVo"/>
        <where>  
            <if test="sopId != null "> and sop_id = #{sopId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userType != null  and userType != ''"> and user_type = #{userType}</if>
            <if test="userRole != null  and userRole != ''"> and user_role = #{userRole}</if>
        </where>
    </select>
    
    <select id="selectIsSopUserByRecordId" parameterType="Long" resultMap="IsSopUserResult">
        <include refid="selectIsSopUserVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertIsSopUser" parameterType="IsSopUser" useGeneratedKeys="true" keyProperty="recordId">
        insert into is_sop_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sopId != null">sop_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="userType != null">user_type,</if>
            <if test="userRole != null">user_role,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sopId != null">#{sopId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userType != null">#{userType},</if>
            <if test="userRole != null">#{userRole},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateIsSopUser" parameterType="IsSopUser">
        update is_sop_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="sopId != null">sop_id = #{sopId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="userRole != null">user_role = #{userRole},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteIsSopUserByRecordId" parameterType="Long">
        delete from is_sop_user where record_id = #{recordId}
    </delete>

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