<?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.hw.system.common.mapper.WfProcessActivityAuthMapper">

    <resultMap type="WfProcessActivityAuth" id="WfProcessActivityAuthResult">
        <result property="processActivityAuthId"    column="process_activity_auth_id"    />
        <result property="processActivityId"    column="process_activity_id"    />
        <result property="authTargetType"    column="auth_target_type"    />
        <result property="authTargetId"    column="auth_target_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="nickName"    column="nick_name"    />
    </resultMap>

    <sql id="selectWfProcessActivityAuthVo">
        select process_activity_auth_id, process_activity_id, auth_target_type, auth_target_id, create_by, create_time, update_by, update_time from wf_process_activity_auth
    </sql>

    <select id="selectWfProcessActivityAuthList" parameterType="WfProcessActivityAuth" resultMap="WfProcessActivityAuthResult">
        <include refid="selectWfProcessActivityAuthVo"/>
        <where>
            <if test="processActivityId != null "> and process_activity_id = #{processActivityId}</if>
            <if test="authTargetType != null  and authTargetType != ''"> and auth_target_type = #{authTargetType}</if>
            <if test="authTargetId != null "> and auth_target_id = #{authTargetId}</if>
        </where>
    </select>

    <select id="selectWfProcessActivityAuthByProcessActivityAuthId" parameterType="Long" resultMap="WfProcessActivityAuthResult">
        <include refid="selectWfProcessActivityAuthVo"/>
        where process_activity_auth_id = #{processActivityAuthId}
    </select>

    <insert id="insertWfProcessActivityAuth" parameterType="WfProcessActivityAuth" useGeneratedKeys="true" keyProperty="processActivityAuthId">
        insert into wf_process_activity_auth
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="processActivityId != null">process_activity_id,</if>
            <if test="authTargetType != null and authTargetType != ''">auth_target_type,</if>
            <if test="authTargetId != null">auth_target_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="processActivityId != null">#{processActivityId},</if>
            <if test="authTargetType != null and authTargetType != ''">#{authTargetType},</if>
            <if test="authTargetId != null">#{authTargetId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateWfProcessActivityAuth" parameterType="WfProcessActivityAuth">
        update wf_process_activity_auth
        <trim prefix="SET" suffixOverrides=",">
            <if test="processActivityId != null">process_activity_id = #{processActivityId},</if>
            <if test="authTargetType != null and authTargetType != ''">auth_target_type = #{authTargetType},</if>
            <if test="authTargetId != null">auth_target_id = #{authTargetId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where process_activity_auth_id = #{processActivityAuthId}
    </update>

    <delete id="deleteWfProcessActivityAuthByProcessActivityAuthId" parameterType="Long">
        delete from wf_process_activity_auth where process_activity_auth_id = #{processActivityAuthId}
    </delete>

    <delete id="deleteWfProcessActivityAuthByProcessActivityAuthIds" parameterType="String">
        delete from wf_process_activity_auth where process_activity_auth_id in
        <foreach item="processActivityAuthId" collection="array" open="(" separator="," close=")">
            #{processActivityAuthId}
        </foreach>
    </delete>
    <select id="selectUserAuth" parameterType="WfProcessActivityAuth" resultMap="WfProcessActivityAuthResult">
         select wfpaa.process_activity_auth_id, wfpaa.process_activity_id,
          wfpaa.auth_target_type, wfpaa.auth_target_id, wfpaa.create_by, wfpaa.create_time,
           wfpaa.update_by, wfpaa.update_time,su.nick_name
         from wf_process_activity_auth wfpaa
         left join sys_user su on wfpaa.auth_target_id = su.user_id
         <where>
             <if test="processActivityId!=null">and wfpaa.process_activity_id = #{processActivityId}</if>
             <if test="authTargetId!=null">and wfpaa.auth_target_id= #{authTargetId}</if>
             <if test="nickName!=null">and su.nick_name like concat('%', #{nickName},'%')</if>
         </where>

    </select>
</mapper>
