<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.pj.dao.ibatis.PjEvaluateStatDaoImpl">
    <!-- 获取统计列表 -->
    <select id="getPjStatList" parameterType="paramDto" resultMap="PjEvaluateStatEntity-Map">
        select
        <!-- 获取分组字段 -->
        <if test="groupList != null and !groupList.isEmpty()">
            <foreach collection="groupList" open="" close="" index="index" item="item">
                ${item},
            </foreach>
        </if>
        a.siteCode,
        a.siteName,
        <!-- 评价数量-->
        sum(IFNULL(a.pjCount,0)) pjCount

        from mortals_xhx_pj_evaluate_stat as a
        <trim suffixOverrides="where" suffix="">
            where
            <trim prefixOverrides="and" prefix="">
                <include refid="_condition_"/>
                <include refid="_condition_two_"/>
            </trim>
        </trim>
        <include refid="_group_by_"/>
        <include refid="_orderCols_"/>
    </select>


    <!-- 条件映射 -->
    <sql id="_condition_two_">
        <if test="condition != null and !condition.isEmpty()">
            <!-- 条件映射-普通条件 -->
            <include refid="_condition_param_two_">
                <property name="_conditionParam_" value="condition"/>
                <property name="_conditionType_" value="and"/>
            </include>
          </if>
    </sql>

    <sql id="_condition_param_two_">
        <bind name="conditionParamRef" value="${_conditionParam_}"/>
        <if test="conditionParamRef.containsKey('timeStart') and conditionParamRef.timeStart != null and conditionParamRef.timeStart!=''">
            ${_conditionType_} STR_TO_DATE(CONCAT(`year`,'-',`month`,'-',`day`),'%Y-%m-%d')<![CDATA[ >= ]]>STR_TO_DATE(#{${_conditionParam_}.timeStart},'%Y-%m-%d')
        </if>
        <if test="conditionParamRef.containsKey('timeEnd') and conditionParamRef.timeEnd != null and conditionParamRef.timeEnd!=''">
            ${_conditionType_}  STR_TO_DATE(CONCAT(`year`,'-',`month`,'-',`day`),'%Y-%m-%d')<![CDATA[ <= ]]>STR_TO_DATE(#{${_conditionParam_}.timeEnd},'%Y-%m-%d')
        </if>
    </sql>
</mapper>