<?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.qmth.sop.business.mapper.TFCustomFlowMapper">

    <select id="findMaxVersion" resultType="com.qmth.sop.business.entity.TFCustomFlow">
        select * from t_f_custom_flow t
        <where>
            <if test="orgId != null and orgId != ''">
                and t.org_id = #{orgId}
            </if>
            <if test="flowName != null and flowName != ''">
                and t.name = #{flowName}
            </if>
            <if test="type != null and type != ''">
                and t.type = #{type}
            </if>
            and t.enable = 1
            and t.publish = 1
        </where>
        order by t.version desc limit 1
    </select>

    <select id="findFlowDeploymentList" resultType="com.qmth.sop.business.entity.TFCustomFlow">
        select t.* from t_f_custom_flow t
                join
            (
                select
                    max(tfcf.id) as id,
                    tfcf.type,
                    tfcf.name
                from
                    t_f_custom_flow tfcf
                where
                    tfcf.enable = 1
                  and tfcf.publish = 1
                group by tfcf.type,tfcf.name) temp on
                temp.id = t.id
            order by t.create_time
    </select>
</mapper>
