<?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.usky.fire.mapper.MhPostInspectMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.fire.domain.MhPostInspect">
        <id column="id" property="id"/>
        <result column="inspect_code" property="inspectCode"/>
        <result column="inspect_time" property="inspectTime"/>
        <result column="reply_time" property="replyTime"/>
        <result column="spent_time" property="spentTime"/>
        <result column="inspect_status" property="inspectStatus"/>
        <result column="company_id" property="companyId"/>
        <result column="company_code" property="companyCode"/>
        <result column="creator" property="creator"/>
        <result column="create_time" property="createTime"/>
        <result column="update_person" property="updatePerson"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>
    <select id="inspectStatistics" resultType="com.usky.fire.domain.BaseCompanyPerson">
        SELECT
        company_id,
        COUNT(*) AS inspect_count,
        SUM(inspect_status) AS answer_count,
        MAX(inspect_time) AS inspect_time
        FROM
        mh_post_inspect
        <where>
            <if test="companyIdList != null and companyIdList.size() > 0">
                AND company_id in
                <foreach item="item" collection="companyIdList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY
        company_id
        ORDER BY
        inspect_time DESC
    </select>

    <select id="mhPostInspectStatistics" resultType="java.lang.Integer">
        SELECT
        ${find}
        FROM
        mh_post_inspect
        <where>
            <if test="companyIdList != null and companyIdList.size() > 0">
                AND company_id in
                <foreach item="item" collection="companyIdList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="inspectStatus != null">
                AND inspect_status = #{inspectStatus}
            </if>
            <if test="startTime != null and startTime !='' and endTime != null and endTime !=''">
                AND inspect_time BETWEEN #{startTime} and #{endTime}
            </if>
            <if test="companyId != null and companyId!= 0">
                AND company_id = #{companyId}
            </if>
        </where>
    </select>

</mapper>
