<?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.WfProcessActivityMapper">

    <resultMap type="WfProcessActivity" id="WfProcessActivityResult">
        <result property="processActivityId"    column="process_activity_id"    />
        <result property="wfProcessId"    column="wf_process_id"    />
        <result property="processActivityName"    column="process_activity_name"    />
        <result property="processActivityOrder"    column="process_activity_order"    />
        <result property="wfActivityType"    column="wf_activity_type"    />
        <result property="emailNotice"    column="email_notice"    />
        <result property="wechatOfficalNotice"    column="wechat_offical_notice"    />
        <result property="wecomNotice"    column="wecom_notice"    />
        <result property="smsNotice"    column="sms_notice"    />
        <result property="dingtalkNotice"    column="dingtalk_notice"    />
        <result property="timeLimit"    column="time_limit"    />
        <result property="isAssist"    column="is_assist"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <resultMap id="WfProcessActivityWfProcessActivityAuthResult" type="WfProcessActivity" extends="WfProcessActivityResult">
        <collection property="wfProcessActivityAuthList" notNullColumn="sub_process_activity_auth_id" javaType="java.util.List" resultMap="WfProcessActivityAuthResult" />
    </resultMap>

    <resultMap type="WfProcessActivityAuth" id="WfProcessActivityAuthResult">
        <result property="processActivityAuthId"    column="sub_process_activity_auth_id"    />
        <result property="processActivityId"    column="sub_process_activity_id"    />
        <result property="authTargetType"    column="sub_auth_target_type"    />
        <result property="authTargetId"    column="sub_auth_target_id"    />
        <result property="createBy"    column="sub_create_by"    />
        <result property="createTime"    column="sub_create_time"    />
        <result property="updateBy"    column="sub_update_by"    />
        <result property="updateTime"    column="sub_update_time"    />
    </resultMap>

    <sql id="selectWfProcessActivityVo">
        select process_activity_id, wf_process_id, process_activity_name, process_activity_order, wf_activity_type, email_notice, wechat_offical_notice, wecom_notice, sms_notice, dingtalk_notice, time_limit, is_assist, remark, create_by, create_time, update_by, update_time from wf_process_activity
    </sql>

    <select id="selectWfProcessActivityList" parameterType="WfProcessActivity" resultMap="WfProcessActivityResult">
        <include refid="selectWfProcessActivityVo"/>
        <where>
            <if test="processActivityId != null">and process_activity_id = #{processActivityId}</if>
            <if test="wfProcessId != null "> and wf_process_id = #{wfProcessId}</if>
            <if test="processActivityName != null  and processActivityName != ''"> and process_activity_name like concat('%', #{processActivityName}, '%')</if>
            <if test="processActivityOrder != null "> and process_activity_order = #{processActivityOrder}</if>
            <if test="wfActivityType != null  and wfActivityType != ''"> and wf_activity_type = #{wfActivityType}</if>
            <if test="emailNotice != null  and emailNotice != ''"> and email_notice = #{emailNotice}</if>
            <if test="wechatOfficalNotice != null  and wechatOfficalNotice != ''"> and wechat_offical_notice = #{wechatOfficalNotice}</if>
            <if test="wecomNotice != null  and wecomNotice != ''"> and wecom_notice = #{wecomNotice}</if>
            <if test="smsNotice != null  and smsNotice != ''"> and sms_notice = #{smsNotice}</if>
            <if test="dingtalkNotice != null  and dingtalkNotice != ''"> and dingtalk_notice = #{dingtalkNotice}</if>
            <if test="timeLimit != null "> and time_limit = #{timeLimit}</if>
            <if test="isAssist != null  and isAssist != ''"> and is_assist = #{isAssist}</if>
        </where>
    </select>

    <select id="selectWfProcessActivityByProcessActivityId" parameterType="Long" resultMap="WfProcessActivityWfProcessActivityAuthResult">
        select a.process_activity_id, a.wf_process_id, a.process_activity_name, a.process_activity_order, a.wf_activity_type, a.email_notice, a.wechat_offical_notice, a.wecom_notice, a.sms_notice, a.dingtalk_notice, a.time_limit, a.is_assist, a.remark, a.create_by, a.create_time, a.update_by, a.update_time,
 b.process_activity_auth_id as sub_process_activity_auth_id, b.process_activity_id as sub_process_activity_id, b.auth_target_type as sub_auth_target_type, b.auth_target_id as sub_auth_target_id, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time
        from wf_process_activity a
        left join wf_process_activity_auth b on b.process_activity_id = a.process_activity_id
        where a.process_activity_id = #{processActivityId}
    </select>

    <insert id="insertWfProcessActivity" parameterType="WfProcessActivity" useGeneratedKeys="true" keyProperty="processActivityId">
        insert into wf_process_activity
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wfProcessId != null">wf_process_id,</if>
            <if test="processActivityName != null and processActivityName != ''">process_activity_name,</if>
            <if test="processActivityOrder != null">process_activity_order,</if>
            <if test="wfActivityType != null and wfActivityType != ''">wf_activity_type,</if>
            <if test="emailNotice != null">email_notice,</if>
            <if test="wechatOfficalNotice != null">wechat_offical_notice,</if>
            <if test="wecomNotice != null">wecom_notice,</if>
            <if test="smsNotice != null">sms_notice,</if>
            <if test="dingtalkNotice != null">dingtalk_notice,</if>
            <if test="timeLimit != null">time_limit,</if>
            <if test="isAssist != null">is_assist,</if>
            <if test="remark != null">remark,</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="wfProcessId != null">#{wfProcessId},</if>
            <if test="processActivityName != null and processActivityName != ''">#{processActivityName},</if>
            <if test="processActivityOrder != null">#{processActivityOrder},</if>
            <if test="wfActivityType != null and wfActivityType != ''">#{wfActivityType},</if>
            <if test="emailNotice != null">#{emailNotice},</if>
            <if test="wechatOfficalNotice != null">#{wechatOfficalNotice},</if>
            <if test="wecomNotice != null">#{wecomNotice},</if>
            <if test="smsNotice != null">#{smsNotice},</if>
            <if test="dingtalkNotice != null">#{dingtalkNotice},</if>
            <if test="timeLimit != null">#{timeLimit},</if>
            <if test="isAssist != null">#{isAssist},</if>
            <if test="remark != null">#{remark},</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="updateWfProcessActivity" parameterType="WfProcessActivity">
        update wf_process_activity
        <trim prefix="SET" suffixOverrides=",">
            <if test="wfProcessId != null">wf_process_id = #{wfProcessId},</if>
            <if test="processActivityName != null and processActivityName != ''">process_activity_name = #{processActivityName},</if>
            <if test="processActivityOrder != null">process_activity_order = #{processActivityOrder},</if>
            <if test="wfActivityType != null and wfActivityType != ''">wf_activity_type = #{wfActivityType},</if>
            <if test="emailNotice != null">email_notice = #{emailNotice},</if>
            <if test="wechatOfficalNotice != null">wechat_offical_notice = #{wechatOfficalNotice},</if>
            <if test="wecomNotice != null">wecom_notice = #{wecomNotice},</if>
            <if test="smsNotice != null">sms_notice = #{smsNotice},</if>
            <if test="dingtalkNotice != null">dingtalk_notice = #{dingtalkNotice},</if>
            <if test="timeLimit != null">time_limit = #{timeLimit},</if>
            <if test="isAssist != null">is_assist = #{isAssist},</if>
            <if test="remark != null">remark = #{remark},</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_id = #{processActivityId}
    </update>

    <delete id="deleteWfProcessActivityByProcessActivityId" parameterType="Long">
        delete from wf_process_activity where process_activity_id = #{processActivityId}
    </delete>

    <delete id="deleteWfProcessActivityByProcessActivityIds" parameterType="String">
        delete from wf_process_activity where process_activity_id in
        <foreach item="processActivityId" collection="array" open="(" separator="," close=")">
            #{processActivityId}
        </foreach>
    </delete>

    <delete id="deleteWfProcessActivityAuthByProcessActivityIds" parameterType="String">
        delete from wf_process_activity_auth where process_activity_id in
        <foreach item="processActivityId" collection="array" open="(" separator="," close=")">
            #{processActivityId}
        </foreach>
    </delete>

    <delete id="deleteWfProcessActivityAuthByProcessActivityId" parameterType="Long">
        delete from wf_process_activity_auth where process_activity_id = #{processActivityId}
    </delete>

    <insert id="batchWfProcessActivityAuth">
        insert into wf_process_activity_auth( process_activity_auth_id, process_activity_id, auth_target_type, auth_target_id, create_by, create_time, update_by, update_time) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.processActivityAuthId}, #{item.processActivityId}, #{item.authTargetType}, #{item.authTargetId}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime})
        </foreach>
    </insert>
</mapper>
