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

    <select id="findFlowIdByCrmNo" resultType="java.lang.Long">
        select tffa.flow_id from t_f_flow_approve tffa
             join t_f_custom_flow_entity tfcfe on tfcfe.flow_id = tffa.flow_id
        <where> 1 = 1
            <if test="crmNo != null and crmNo != ''">
                and tfcfe.crm_no = #{crmNo}
            </if>
                and tffa.status not in('FINISH','END')
        </where>
    </select>

    <select id="findFlowPassageSopByCrmNo" resultType="java.lang.Integer">
        select count(1)
        from
            t_f_flow_approve tffa
            join t_f_custom_flow_entity tfcfe on tfcfe.flow_id = tffa.flow_id
            join t_f_custom_flow tfcf on tfcf.id = tfcfe.t_f_custom_flow_id
        where
            1 = 1
          and (tfcf.`type` = 'OFFICE_SOP_FLOW' or tfcf.`type` = 'CLOUD_MARK_SOP_FLOW')
          and tfcfe.crm_no = #{crmNo}
          and tffa.status not in ('FINISH', 'END')
    </select>
</mapper>
