<?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.watermeter.mapper.ReadabnormalMapper">

    <resultMap id="readabnormalMap" type="com.tofly.watermeter.entity.Readabnormal">
        <id property="id" column="ID"/>
        <result property="typeCode" column="TYPE_CODE"/>
        <result property="type" column="TYPE"/>
        <result property="ysxzBm" column="YSXZ_BM"/>
        <result property="sbkjBm" column="SBKJ_BM"/>
        <result property="fiducialValue" column="FIDUCIAL_VALUE"/>
        <result property="nosediveValue" column="NOSEDIVE_VALUE"/>
        <result property="ratio" column="RATIO"/>
        <result property="minAverageValue" column="MIN_AVERAGE_VALUE"/>
        <result property="count" column="COUNT"/>
        <result property="firstRead" column="FIRST_READ"/>
        <result property="describe" column="DESCRIBE"/>
        <result property="isYearorchain" column="IS_YEARORCHAIN"/>
        <result property="isUpordown" column="IS_UPORDOWN"/>
        <result property="createDate" column="CREATE_DATE"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="typeName" column="TYPE_NAME"/>
        <result property="modelName" column="MODEL_NAME"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="ysxzName" column="YSXZ_BM"
                     select="getYsxzName"/>
        <association property="firstReadName" column="FIRST_READ" select="getFirstReadName"/>
        <association property="isYearorchainName" column="IS_YEARORCHAIN" select="getIsYearorchainName"/>
        <association property="isUpordownName" column="IS_UPORDOWN" select="getIsUpordownName"/>
    </resultMap>

    <select id="getFirstReadName" resultType="string">
        select decode(#{firstRead},'0','首次抄表水量为0','1','首次非正常方式抄表') from dual
    </select>
    <select id="getIsYearorchainName" resultType="string">
        select decode(#{isYearorchain},'0','同比','1','环比') from dual
    </select>
    <select id="getIsUpordownName" resultType="string">
        select decode(#{isUpordown},'0','升比例','1','降比例') from dual
    </select>
    <select id="getYsxzName" resultType="string">
        select YSXZ_MC from TF_YWPN_QFMIDYSXZBM_E where YSXZ_BM = #{ysxz}
    </select>
    <select id="getCodeById" resultType="string">
        select CNAME
        from TF_YWPN_SYSCHILDCODE_D
        where ID = #{id}
    </select>

</mapper>
