<?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.xrtymis.mapper.LeakInfoMapper">

    <resultMap id="leakInfoMap" type="com.tofly.xrtymis.entity.LeakInfo">
        <id property="id" column="ID"/>
        <result property="leakName" column="LEAK_NAME"/>
        <result property="dmaId" column="DMA_ID"/>
        <result property="leakSource" column="LEAK_SOURCE"/>
        <result property="disposeState" column="DISPOSE_STATE"/>
        <result property="disposeSuggest" column="DISPOSE_SUGGEST"/>
        <result property="gdinfoId" column="GDINFO_ID"/>
        <result property="estimatedWaterLoss" column="ESTIMATED_WATER_LOSS"/>
        <result property="isReal" column="IS_REAL"/>
        <association property="dmaName" column="DMA_ID" select="getDmaName"/>
        <association property="leakSourceName" column="LEAK_SOURCE" select="getLeakSourceName"/>
        <association property="disposeStateName" column="DISPOSE_STATE" select="getLeakSourceName"/>
    </resultMap>

    <select id="getDmaName" resultType="string">
        select DMA_NAME  from TF_YWPN_DMAREGION_W where ID = #{dmaId}
    </select>

    <select id="getLeakSourceName" resultType="string">
        SELECT CNAME
        FROM
            TF_YWPN_SYSCHILDCODE_D
        WHERE
            PCID =52800
          AND
            CCODE = #{leakSource}
    </select>

    <select id="getLeakInfo" resultMap="leakInfoMap">
        select ID,LEAK_NAME,DMA_ID,LEAK_SOURCE,DISPOSE_STATE,DISPOSE_SUGGEST,GDINFO_ID,ESTIMATED_WATER_LOSS,IS_REAL from TF_YWPN_LEAK_INFO_W
        where GDINFO_ID = #{id}
    </select>

    <update id="updatePublicLeakInfo">
        UPDATE  TF_PUBLIC_LEAKAGE_INFO
        set ESTIMATE_LEAKAGE_WATER = #{water},VERIFY_STATUS = #{isReal}
        where ORDER_ID = #{orderId}
    </update>


    <update id="updatePublicRewardWaterVolume">
        UPDATE  TF_PUBLIC_LEAKAGE_INFO
        set REWARD_WATER_VOLUME = #{rewardWaterVolume}
        where REWARD_WATER_ID = #{orderId}
    </update>

    <update id="updateYxState">
        UPDATE  TF_PUBLIC_LEAKAGE_INFO
        set YX_SYN_STATE = '1'
        where REWARD_WATER_ID = #{orderId}
    </update>

    <select id="getPublicRewardWaterVolumeOpenId" resultType="com.tofly.xrtymis.custom.vo.PublicRewardWaterVo">
        select OPEN_ID openId, REWARD_WATER_VOLUME rewardWaterVolume
        FROM TF_PUBLIC_LEAKAGE_INFO
        WHERE REWARD_WATER_ID = #{orderId}
    </select>
</mapper>
