<?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.testor.workflow.statistics.dao.ZStatisticsDao">

    <select id="statisticsByFormVar" resultType="com.testor.workflow.statistics.model.vo.ZStatisticsVO">
    select count(hv.id_)
        <if test="query.groupByFields!=null">
        ,
            <foreach collection="query.statusList" index="index" item="item" open=" " separator="," close=" ">
                #{item}
            </foreach>
        </if>
    from act_hi_varinst hv, act_hi_procinst hp, act_re_procdef rp
    where hv.proc_inst_id_ = hp.id_ and hp.proc_def_id_ = rp.id_
        <if test="query.procDefId!='' and query.procDefId!=null">
            and rp.id_=#{query.procDefId}
        </if>
        <if test="query.procDefKey!='' and query.procDefKey!=null">
            and r.key_=#{procDefKey}
        </if>
        <if test="query.groupByFields!='' and query.procDefKey!=null">
            and r.key_=#{procDefKey}
        </if>
        <if test="query.groupByFields!=null">
            group by
            <foreach collection="query.statusList" index="index" item="item" open=" " separator="," close=" ">
                #{item}
            </foreach>
        </if>
    </select>
</mapper>