<?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.tofly.xrtygis.mapper.TfKpiManageMapper">

  <resultMap id="tfKpiManageMap" type="com.tofly.xrtygis.entity.TfKpiManage">
                <id property="id" column="ID"/>
<!--                      <result property="kpiStandardId" column="KPI_STANDARD_ID"/>-->
                      <result property="assessPerson" column="ASSESS_PERSON"/>
<!--                      <result property="assessDuty" column="ASSESS_DUTY"/>-->
                      <result property="assessDate" column="ASSESS_DATE"/>
                      <result property="assessArea" column="ASSESS_AREA"/>
<!--                      <result property="assessType" column="ASSESS_TYPE"/>-->
<!--                      <result property="assessContent" column="ASSESS_CONTENT"/>-->
                      <result property="currentKpiValue" column="CURRENT_KPI_VALUE"/>
                      <result property="assessStatus" column="ASSESS_STATUS"/>
                      <result property="assessScore" column="ASSESS_SCORE"/>
                      <result property="remark" column="REMARK"/>
                      <result property="isQualify" column="IS_QUALIFY"/>
                      <result property="createUser" column="CREATE_USER"/>
                      <result property="createTime" column="CREATE_TIME"/>
                      <result property="assessType" column="ASSESS_TYPE"/>
                      <result property="assessStandard" column="ASSESS_STANDARD"/>
                      <result property="assessContent" column="ASSESS_CONTENT"/>
                      <result property="operateDate" column="OPERATE_DATE"/>
                      <result property="areaLevel" column="AREA_LEVEL"/>
                      <association property="assessContentName"  column="ASSESS_CONTENT" select="getAssessContentName" ></association>
                      <association property="assessTypeName" column="ASSESS_TYPE" select="getAssessTypeName"></association>
                      <association property="createUserName"  column="CREATE_USER" select="com.tofly.xrtygis.mapper.IFileMapper.getUserName" ></association>
                      <association property="assessPersonName"  column="ASSESS_PERSON" select="com.tofly.xrtygis.mapper.IFileMapper.getUserName" ></association>
                      <association property="assessStatusName"  column="ASSESS_STATUS" select="getAssessStatusName" ></association>
                      <association property="isQualifyName"  column="IS_QUALIFY" select="getIsQualifyName" ></association>
<!--                      <association property="assessDutyName"  column="ASSESS_DUTY" select="getAssessDutyName" ></association>-->
                      <association property="areaLevelName"  column="ASSESS_AREA" select="getAreaLevelName" ></association>
                      <association property="assessAreaName"  column="ASSESS_AREA" select="getAssessAreaName" ></association>
<!--                      <association property="assessTypeName" column="ASSESS_TYPE" select="getAssessTypeName"></association>-->
<!--                      <association property="tfKpiStandardManage" column="KPI_STANDARD_ID" select="com.tofly.xrtygis.mapper.TfKpiStandardManageMapper.getAssessStandardById"></association>-->
  </resultMap>

    <select id="getAssessTypeName" resultType="string">
        SELECT decode(#{assessType},'1','按季度','2','按年度') as assessTypeName FROM dual
    </select>

    <select id="getAssessContentName" resultType="string">
        SELECT CNAME
        FROM
            TF_YWPN_SYSCHILDCODE_D
        WHERE
            PCID =1001
          AND
            CCODE = #{assessContent}
    </select>

    <select id="getAssessStatusName" resultType="string">
        SELECT decode(#{assessStatus},'1','已考核','2','未考核') as assessStatusName FROM dual
    </select>

    <select id="getIsQualifyName" resultType="string">
        SELECT decode(#{isQualify},'1','不合格','2','合格') as isQualifyName FROM dual
    </select>

<!--    <select id="getAssessDutyName" resultType="string">-->
<!--        SELECT decode(#{assessDuty},'1','巡线人员','2','处漏人员','3','区域运维人员') as assessDutyName FROM dual-->
<!--    </select>-->

    <select id="getAreaLevelName" resultType="string">
        SELECT decode(#{areaLevel},'1','一级分区','2','二级分区','3','三级分区') as areaLevelName FROM dual
    </select>

    <select id="getAssessAreaName" resultType="string">
        select DMA_NAME
        from TF_YWPN_DMAREGION_W
        where DMA_CODE = #{assessArea}
    </select>

  <select id="getKpiManageAreaList" resultType="string">
      SELECT DISTINCT ASSESS_AREA
      FROM
          TF_KPI_MANAGE
      WHERE
          1=1
      <if test="assessDate != null and assessDate != '' ">
          AND ASSESS_DATE in
          <foreach collection="assessDate.split(',')" item="code" open="(" close=")" separator=",">
              #{code}
          </foreach>
      </if>
      <if test="assessPerson != null and assessPerson.trim() != ''">
          and ASSESS_PERSON = #{assessPerson}
      </if>
      <if test="areaLevel != null and areaLevel.trim() != ''">
          and AREA_LEVEL = #{areaLevel}
      </if>
  </select>

<!--      <select id="getAssessTypeName" resultType="string">-->
<!--          SELECT CNAME-->
<!--          FROM-->
<!--              TF_YWPN_SYSCHILDCODE_D-->
<!--          WHERE-->
<!--              PCID =1001-->
<!--            AND-->
<!--              CCODE = #{assessType}-->
<!--      </select>-->

    <select id="getTfKpiManageList" resultMap="tfKpiManageMap">
        SELECT *
        FROM
        TF_KPI_MANAGE
        where
        1=1
        <if test="tfKpiManageDto.assessDate != null and tfKpiManageDto.assessDate != '' ">
            AND ASSESS_DATE in
            <foreach collection="tfKpiManageDto.assessDate.split(',')" item="code" open="(" close=")" separator=",">
                #{code}
            </foreach>
        </if>
        <if test="tfKpiManageDto.assessPerson != null and tfKpiManageDto.assessPerson.trim() != ''">
            and ASSESS_PERSON = #{tfKpiManageDto.assessPerson}
        </if>
        <if test="tfKpiManageDto.areaLevel != null and tfKpiManageDto.areaLevel.trim() != ''">
            and AREA_LEVEL = #{tfKpiManageDto.areaLevel}
        </if>
    </select>

    <select id="getTfKpiManageScoreAll" resultType="integer">
        SELECT SUM (ASSESS_SCORE)
        FROM
        TF_KPI_MANAGE
        where
        1=1
        <if test="thisYearAssessDate != null and thisYearAssessDate.trim() != ''">
            and ASSESS_DATE = #{thisYearAssessDate}
        </if>
<!--        <if test="quarterAssessDate != null and quarterAssessDate.trim() != ''">-->
<!--            and  ASSESS_DATE = #{quarterAssessDate}-->
<!--        </if>-->
        <if test="assessContent != null and assessContent.trim() != ''">
            and ASSESS_CONTENT = #{assessContent}
        </if>
        <if test="assessArea != null and assessArea.trim() != ''">
            and ASSESS_AREA = #{assessArea}
        </if>
        <if test="assessPerson != null and assessPerson.trim() != ''">
            and ASSESS_PERSON = #{assessPerson}
        </if>
        <if test="areaLevel != null and areaLevel.trim() != ''">
            and AREA_LEVEL = #{areaLevel}
        </if>
        <if test="quarterAssessDate != null and quarterAssessDate != '' ">
            AND ASSESS_DATE in
            <foreach collection="quarterAssessDate.split(',')" item="code" open="(" close=")" separator=",">
                #{code}
            </foreach>
        </if>
    </select>

    <select id="getTfKpiManageScoreCount" resultType="integer">
        SELECT COUNT (ASSESS_SCORE)
        FROM
        TF_KPI_MANAGE
        where
        1=1
        <if test="thisYearAssessDate != null and thisYearAssessDate.trim() != ''">
            and ASSESS_DATE = #{thisYearAssessDate}
        </if>
<!--        <if test="quarterAssessDate != null and quarterAssessDate.trim() != ''">-->
<!--            and  ASSESS_DATE = #{quarterAssessDate}-->
<!--        </if>-->
        <if test="assessContent != null and assessContent.trim() != ''">
            and ASSESS_CONTENT = #{assessContent}
        </if>
        <if test="assessArea != null and assessArea.trim() != ''">
            and ASSESS_AREA = #{assessArea}
        </if>
        <if test="assessPerson != null and assessPerson.trim() != ''">
            and ASSESS_PERSON = #{assessPerson}
        </if>
        <if test="areaLevel != null and areaLevel.trim() != ''">
            and AREA_LEVEL = #{areaLevel}
        </if>
        <if test="quarterAssessDate != null and quarterAssessDate != '' ">
            AND ASSESS_DATE in
            <foreach collection="quarterAssessDate.split(',')" item="code" open="(" close=")" separator=",">
                #{code}
            </foreach>
        </if>
    </select>

<!--    <select id="getCensusInfoPage" resultMap="tfKpiManageMap" >-->
<!--        SELECT * FROM-->
<!--        TF_KPI_MANAGE-->
<!--        where-->
<!--        1=1-->
<!--        <if test="tfKpiManageDto.thisYearAssessDate != null and tfKpiManageDto.thisYearAssessDate.trim() != ''">-->
<!--            and to_char(ASSESS_DATE,'yyyy') = #{tfKpiManageDto.thisYearAssessDate}-->
<!--        </if>-->
<!--        <if test="tfKpiManageDto.startAssessDate != null and tfKpiManageDto.startAssessDate.trim() != ''">-->
<!--            and to_char(ASSESS_DATE,'yyyy') >= #{tfKpiManageDto.startAssessDate}-->
<!--        </if>-->
<!--        <if test="tfKpiManageDto.endAssessDate != null and tfKpiManageDto.endAssessDate.trim() != ''">-->
<!--            <![CDATA[ and to_char(ASSESS_DATE,'yyyy') <= #{tfKpiManageDto.endAssessDate}  ]]>-->
<!--        </if>-->
<!--        <if test="tfKpiManageDto.quarterAssessDate != null and tfKpiManageDto.quarterAssessDate.trim() != ''">-->
<!--            and  to_char(ASSESS_DATE,'Q') = #{tfKpiManageDto.quarterAssessDate}-->
<!--        </if>-->
<!--        <if test="tfKpiManageDto.areaLevel != null and tfKpiManageDto.areaLevel.trim() != ''">-->
<!--            and AREA_LEVEL = #{tfKpiManageDto.areaLevel}-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="getCensusInfoByContent" resultType="java.util.Map" >-->
<!--        SELECT ASSESS_CONTENT,-->
<!--               COUNT( ID ),-->
<!--               SUM( CURRENT_KPI_VALUE )-->
<!--        FROM-->
<!--        TF_KPI_MANAGE-->
<!--        where-->
<!--        1=1-->
<!--        <if test="thisYearAssessDate != null and thisYearAssessDate.trim() != ''">-->
<!--            and to_char(ASSESS_DATE,'yyyy') = #{thisYearAssessDate}-->
<!--        </if>-->
<!--        <if test="quarterAssessDate != null and quarterAssessDate.trim() != ''">-->
<!--            and  to_char(ASSESS_DATE,'Q') = #{quarterAssessDate}-->
<!--        </if>-->
<!--        <if test="assessArea != null and assessArea.trim() != ''">-->
<!--            and ASSESS_AREA = #{assessArea}-->
<!--        </if>-->
<!--        GROUP BY ASSESS_AREA-->
<!--    </select>-->


<!--    <select id="getCensusInfoByYear" resultType="java.util.Map" >-->
<!--        SELECT ASSESS_TYPE,-->
<!--               to_char(ASSESS_DATE,'yyyy'),-->
<!--               AVG (ASSESS_SCORE)-->
<!--        FROM-->
<!--        TF_KPI_MANAGE-->
<!--        where-->
<!--        1=1-->
<!--        <if test="startAssessDate != null and startAssessDate.trim() != ''">-->
<!--            and to_char(ASSESS_DATE,'yyyy-MM-dd hh:mm:ss') >= to_char(#{startAssessDate},'yyyy-MM-dd hh:mm:ss')-->
<!--        </if>-->
<!--        <if test="endAssessDate != null and endAssessDate.trim() != ''">-->
<!--            <![CDATA[ and to_char(ASSESS_DATE,'yyyy-MM-dd hh:mm:ss') <= to_char(#{endAssessDate},'yyyy-MM-dd hh:mm:ss')   ]]>-->
<!--        </if>-->
<!--        GROUP BY to_char(ASSESS_DATE,'yyyy')-->
<!--        HAVING IN ASSESS_TYPE-->
<!--    </select>-->

<!--    <select id="getCensusInfoByYearGroupByMonth" resultType="java.util.Map" >-->
<!--        SELECT ASSESS_TYPE,-->
<!--               to_char(ASSESS_DATE,'mm'),-->
<!--               AVG (ASSESS_SCORE)-->
<!--        FROM-->
<!--        TF_KPI_MANAGE-->
<!--        where-->
<!--        1=1-->
<!--        <if test="thisYearAssessDate != null and thisYearAssessDate.trim() != ''">-->
<!--            and to_char(ASSESS_DATE,'yyyy') = to_char(#{thisYearAssessDate},'yyyy')-->
<!--        </if>-->
<!--        GROUP BY to_char(ASSESS_DATE,'mm')-->
<!--        HAVING IN ASSESS_TYPE-->
<!--    </select>-->

<!--    <select id="getCensusInfoByQuarter" resultType="java.util.Map" >-->
<!--        SELECT ASSESS_TYPE,-->
<!--        to_char(ASSESS_DATE,'yyyy-Q'),-->
<!--        AVG (ASSESS_SCORE)-->
<!--        FROM-->
<!--        TF_KPI_MANAGE-->
<!--        where-->
<!--        1=1-->
<!--        <if test="quarterStartAssessDate != null and quarterStartAssessDate.trim() != ''">-->
<!--            and  to_char(ASSESS_DATE,'yyyy-Q') >= to_char(#{quarterStartAssessDate},'yyyy-Q')-->
<!--        </if>-->
<!--        <if test="quarterEndAssessDate != null and quarterEndAssessDate.trim() != ''">-->
<!--            <![CDATA[ and to_char(ASSESS_DATE,'yyyy-Q') <= to_char(#{quarterEndAssessDate},'yyyy-Q')   ]]>-->
<!--        </if>-->
<!--        GROUP BY to_char(ASSESS_DATE,'yyyy-Q')-->
<!--        HAVING IN ASSESS_TYPE-->
<!--    </select>-->

<!--    <select id="getCensusInfoByQuarterGroupByMonth" resultType="java.util.Map" >-->
<!--        SELECT ASSESS_TYPE,-->
<!--               to_char(ASSESS_DATE,'mm'),-->
<!--               AVG (ASSESS_SCORE)-->
<!--        FROM-->
<!--        TF_KPI_MANAGE-->
<!--        where-->
<!--        1=1-->
<!--        <if test="quarterStartAssessDate != null and quarterStartAssessDate.trim() != ''">-->
<!--            and  to_char(ASSESS_DATE,'yyyy-Q') >= to_char(#{quarterStartAssessDate},'yyyy-Q')-->
<!--        </if>-->
<!--        <if test="quarterEndAssessDate != null and quarterEndAssessDate.trim() != ''">-->
<!--            <![CDATA[ and to_char(ASSESS_DATE,'yyyy-Q') <= to_char(#{quarterEndAssessDate},'yyyy-Q')   ]]>-->
<!--        </if>-->
<!--        GROUP BY to_char(ASSESS_DATE,'mm')-->
<!--        HAVING IN ASSESS_TYPE-->
<!--    </select>-->
                                                                                
</mapper>
