<?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.casic.missiles.mapper.system.FlowDefMapper">

    <select id="selectDeployListPage" resultType="com.casic.missiles.dto.system.FlowProcDefDTO"
            parameterType="com.baomidou.mybatisplus.extension.plugins.pagination.Page">
        SELECT
        rp.id_ as id,
        rd.id_ as deploymentId,
        rd.name_ as name,
        rd.category_ as category,
        rp.key_ as flowKey,
        rp.version_ as version,
        rp.suspension_state_ as suspensionState,
        rd.tenant_id_ as directorId,
        rd.deploy_time_ as deploymentTime,
        sff.form_id as formId,
        sff.form_name as formName,
        sff.form_desc as formDesc,
        su.name as directorName
        FROM ACT_RE_PROCDEF rp
        LEFT JOIN ACT_RE_DEPLOYMENT rd ON rp.deployment_id_ = rd.id_
        <!--    同一流程定义多个版本取版本号最大的，由于版本号可能重复，使用部署id最大代替，0112前端获取数据不全，注释可以    -->
<!--        INNER JOIN (SELECT max(arp.deployment_id_) AS deployment_id_ FROM ACT_RE_PROCDEF arp GROUP BY arp.key_) c ON rp.deployment_id_ = c.deployment_id_-->
        LEFT JOIN system_flow_form sff ON sff.deploy_id = rd.id_
        LEFT JOIN sys_user su ON su.id = rd.tenant_id_
        WHERE sff.is_del = 0
        <if test="request.id != null and request.id !=''">
            and rp.id_ like concat('%',#{request.id},'%')
        </if>
        <if test="request.name != null and request.name !=''">
            and rd.name_ like concat('%',#{request.name},'%')
        </if>
        <if test="request.formId != null and request.formId !=''">
            and sff.form_id = #{request.formId}
        </if>
        <if test="request.category != null and request.category !=''">
            and rd.category_ like concat('%',#{request.category},'%')
        </if>
        <if test="request.suspensionState != null">
            and rp.suspension_state_ = #{request.suspensionState}
        </if>
<!--        <if test="request.directorId != null">-->
<!--            and rd.tenant_id_ = #{request.directorId}-->
<!--        </if>-->
        <if test="request.directorName != null">
            and su.name like concat('%',#{request.directorName},'%')
        </if>
        <if test="request.deploymentStartTime != null and request.deploymentStartTime !=''">
            and rd.deploy_time_ &gt;= #{request.deploymentStartTime}
        </if>
        <if test="request.deploymentEndTime != null and request.deploymentEndTime !=''">
            and rd.deploy_time_ &lt;= #{request.deploymentEndTime}
        </if>
        order by rd.deploy_time_ desc
    </select>

    <select id="selectDeployList" resultType="com.casic.missiles.dto.system.FlowProcDefDTO">
        SELECT
        rp.id_ as id,
        rd.id_ as deploymentId,
        rd.name_ as name,
        rd.category_ as category,
        rp.key_ as flowKey,
        rp.version_ as version,
        rp.suspension_state_ as suspensionState,
        rd.tenant_id_ as directorId,
        rd.deploy_time_  as deploymentTime,
        sff.form_id as formId,
        sff.form_name as formName,
        sff.form_desc as formDesc,
        su.name as directorName
        FROM ACT_RE_PROCDEF rp
        LEFT JOIN ACT_RE_DEPLOYMENT rd ON rp.deployment_id_ = rd.id_
        <!--    同一流程定义多个版本取版本号最大的，由于版本号可能重复，使用部署id最大代替，0112前端获取数据不全，注释可以    -->
        <!--        INNER JOIN (SELECT max(arp.deployment_id_) AS deployment_id_ FROM ACT_RE_PROCDEF arp GROUP BY arp.key_) c ON rp.deployment_id_ = c.deployment_id_-->
        LEFT JOIN system_flow_form sff ON sff.deploy_id = rd.id_
        LEFT JOIN sys_user su ON su.id = rd.tenant_id_
        WHERE sff.is_del = 0
        <if test="request.id != null and request.id !=''">
            and rp.id_ like concat('%',#{request.id},'%')
        </if>
        <if test="request.name != null and request.name !=''">
            and rd.name_ like concat('%',#{request.name},'%')
        </if>
        <if test="request.formId != null and request.formId !=''">
            and sff.form_id = #{request.formId}
        </if>
        <if test="request.category != null and request.category !=''">
            and rd.category_ like concat('%',#{request.category},'%')
        </if>
        <if test="request.suspensionState != null">
            and rp.suspension_state_ = #{request.suspensionState}
        </if>
        <if test="request.directorName != null">
            and su.name like concat('%',#{request.directorName},'%')
        </if>
        <if test="request.deploymentStartTime != null and request.deploymentStartTime !=''">
            and rd.deploy_time_ &gt;= #{request.deploymentStartTime}
        </if>
        <if test="request.deploymentEndTime != null and request.deploymentEndTime !=''">
            and rd.deploy_time_ &lt;= #{request.deploymentEndTime}
        </if>
        order by rd.deploy_time_ desc
    </select>

    <select id="selectListByIds" resultType="com.casic.missiles.dto.system.FlowProcDefDTO">
        SELECT
        rp.id_ as id,
        rd.id_ as deploymentId,
        rd.name_ as name,
        rd.category_ as category,
        rp.key_ as flowKey,
        rp.version_ as version,
        rp.suspension_state_ as suspensionState,
        rd.tenant_id_ as directorId,
        rd.deploy_time_  as deploymentTime,
        sff.form_id as formId,
        sff.form_name as formName,
        sff.form_desc as formDesc,
        su.name as directorName
        FROM ACT_RE_PROCDEF rp
        LEFT JOIN ACT_RE_DEPLOYMENT rd ON rp.deployment_id_ = rd.id_
        <!--    同一流程定义多个版本取版本号最大的，由于版本号可能重复，使用部署id最大代替，0112前端获取数据不全，注释可以    -->
        <!--        INNER JOIN (SELECT max(arp.deployment_id_) AS deployment_id_ FROM ACT_RE_PROCDEF arp GROUP BY arp.key_) c ON rp.deployment_id_ = c.deployment_id_-->
        LEFT JOIN system_flow_form sff ON sff.deploy_id = rd.id_
        LEFT JOIN sys_user su ON su.id = rd.tenant_id_
        WHERE sff.is_del = 0
        and rp.id_ in
        <foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        order by rd.deploy_time_ desc
    </select>
</mapper>
