<?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.unis.interactiveCommunication.modular.icPublicOpinionCollect.mapper.IcPublicOpinionCollectMapper">


    <select id="selectMyPage"
            resultType="com.unis.interactiveCommunication.modular.icPublicOpinionCollect.vo.IcPublicOpinionCollectVO">

        SELECT
        t1.*,
        t3.department_name,
        ifnull( count( t2.public_opinion_collect_id ), 0 ) viewsNumber,
        ifnull( t4.auditPassStatusNumber, 0 ) auditPassStatusNumber
        FROM
        biz_ic_public_opinion_collect t1
        LEFT JOIN biz_ic_public_opinion_collect_message t2 ON t1.id = t2.public_opinion_collect_id
        LEFT JOIN biz_io_department_function t3 ON t1.io_department_function_id = t3.id
        LEFT JOIN (
        SELECT
        t1.id,
        ifnull( count( t2.audit_status ), 0 ) auditPassStatusNumber
        FROM
        biz_ic_public_opinion_collect t1
        LEFT JOIN biz_ic_public_opinion_collect_message t2 ON t1.id = t2.public_opinion_collect_id
        WHERE
        t2.audit_status = '1'
        GROUP BY
        t1.id
        ) t4 ON t1.id = t4.id

        <where>

            <if test="collectionTitle!=null and collectionTitle!=''">
                and t1.collection_title like concat("%",#{collectionTitle},"%")
            </if>
            <if test="progressStatus!=null ">
                and t1.progress_status=#{progressStatus}
            </if>
        </where>
        group by t1.id
        order by t1.create_time desc

    </select>
</mapper>