<?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="cn.fateverse.workflow.mapper.ProcessDataMapper">

    <select id="selectByDeploymentKey" resultType="cn.fateverse.workflow.entity.vo.ProcessDefinitionHistoryVo">
        select wrd.logo, arp.ID_ as process_definition_id, arp.NAME_ as deployment_name, concat('v', arp.VERSION_) as version,arp.KEY_ as deployment_key, wrd.remark, arp.SUSPENSION_STATE_ as state, wrd.deployment_id
        from wk_re_process_data wrd
        inner join act_re_procdef arp on arp.DEPLOYMENT_ID_ = wrd.deployment_id
        where arp.KEY_ = #{processDefinitionKey}
        order by arp.VERSION_ desc
    </select>

    <select id="selectByProcessDefinitionId" resultType="cn.fateverse.workflow.entity.ProcessData">
        select wrd.deployment_id,deployment_name, logo, settings, process_str, form_item_str, remark
        from wk_re_process_data wrd
        left join act_re_procdef arp on arp.DEPLOYMENT_ID_ = wrd.deployment_id
        where arp.ID_ = #{processDefinitionId}
    </select>

    <select id="selectByDeploymentId" resultType="cn.fateverse.workflow.entity.ProcessData">
        select deployment_id, deployment_name, logo, settings, process_str, form_item_str, remark
        from wk_re_process_data where deployment_id = #{deploymentId}
    </select>
    <select id="selectByProcessDefinitionKey" resultType="cn.fateverse.workflow.entity.ProcessData">
        select wrpd.deployment_id, wrpd.deployment_name, wrpd.logo, wrpd.settings, wrpd.process_str, wrpd.form_item_str, wrpd.remark
        from wk_re_process_data wrpd
        left join wk_re_process_business wrpb on wrpd.deployment_id = wrpb.deployment_id
        where wrpb.process_definition_key = #{processDefinitionKey}
    </select>

    <insert id="insert">
        insert into wk_re_process_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deploymentId != null and deploymentId != ''">deployment_id,</if>
            <if test="deploymentName != null and deploymentName != ''">deployment_name,</if>
            <if test="logo != null and logo != ''">logo,</if>
            <if test="settings != null and settings != ''">settings,</if>
            <if test="processStr != null and processStr != ''">process_str,</if>
            <if test="formItemStr != null and formItemStr != ''">form_item_str,</if>
            <if test="remark != null and remark != ''">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deploymentId != null and deploymentId != ''">#{deploymentId},</if>
            <if test="deploymentName != null and deploymentName != ''">#{deploymentName},</if>
            <if test="logo != null and logo != ''">#{logo},</if>
            <if test="settings != null and settings != ''">#{settings},</if>
            <if test="processStr != null and processStr != ''">#{processStr},</if>
            <if test="formItemStr != null and formItemStr != ''">#{formItemStr},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
        </trim>
    </insert>


</mapper>