<?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.gpsboot.mapper.trouble.TroubleMapper">

    <resultMap id="troubleMap" type="com.tofly.pojo.trouble.Trouble">
        <id property="id" column="ID"/>
        <result property="isread" column="ISREAD"/>
        <result property="isSubmit" column="IS_SUBMIT"/>
        <result property="submitTime" column="SUBMIT_TIME"/>
        <result property="submitUser" column="SUBMIT_USER"/>
        <result property="auditResult" column="AUDIT_RESULT"/>
        <result property="auditTime" column="AUDIT_TIME"/>
        <result property="auditUser" column="AUDIT_USER"/>
        <result property="auditNotes" column="AUDIT_NOTES"/>
        <result property="pipeName" column="PIPE_NAME"/>
        <result property="location" column="LOCATION"/>
        <result property="padId" column="PAD_ID"/>
        <result property="typeId" column="TYPE_ID"/>
        <result property="lgtd" column="LGTD"/>
        <result property="lttd" column="LTTD"/>
        <result property="address" column="ADDRESS"/>
        <result property="notes" column="NOTES"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="isbuild" column="ISBUILD"/>
        <result property="buildId" column="BUILD_ID"/>
        <result property="suggest" column="SUGGEST"/>
        <result property="uploadType" column="UPLOAD_TYPE"/>
        <result property="uploadFileids" column="UPLOAD_FILEIDS"/>
        <result property="isrespect" column="ISRESPECT"/>
        <result property="state" column="STATE"/>
        <result property="regionId" column="REGION_ID"/>
        <result property="regionName" column="REGION_NAME"/>
        <result property="toubleRangeId" column="TOUBLE_RANGE_ID"/>
        <association property="locationName" column="LOCATION" select="getLocationName"/>
        <association property="submitUserName" column="SUBMIT_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="auditUserName" column="AUDIT_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="isreadName" column="ISREAD" select="com.tofly.gpsboot.mapper.build.BuildMapper.getIsreadName"/>
        <association property="typeIdName" column="TYPE_ID" select="getTypeIdName"/>
        <association property="auditResultName" column="AUDIT_RESULT" select="com.tofly.gpsboot.mapper.build.BuildMapper.getAuditResultName"/>
        <association property="uploadTypeName" column="UPLOAD_TYPE" select="com.tofly.gpsboot.mapper.build.BuildMapper.getUploadTypeName"/>
        <association property="createUserName" column="CREATE_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="filePathList" column="UPLOAD_FILEIDS" select="getFilePathList"/>
        <association property="ischeackReadName" column="ISCHEACK_READ" select="getIscheackReadName"/>
        <association property="isrespectName" column="ISRESPECT" select="com.tofly.gpsboot.mapper.build.BuildMapper.getIsrespectName"/>
        <association property="stateName" column="STATE" select="getStateName"/>
        <association property="isbuildName" column="ISBUILD" select="getIsbuildName"/>
        <association property="isSubmitName" column="IS_SUBMIT" select="com.tofly.gpsboot.mapper.build.BuildMapper.getIsSubmitName"/>
        <association property="toubleRangeIdName" column="TOUBLE_RANGE_ID" select="getToubleRangeIdName"/>
    </resultMap>
    <select id="getFilePathList" resultType="string" databaseId="oracle">
        select FILE_PATH as filePath
        from TF_YWPN_FILE_W
        <if test="uploadFileids != null and uploadFileids != ''  ">where id in
            <foreach item="nodeCodestr" collection="uploadFileids.split(',')" open="(" separator="," close=")">
                #{nodeCodestr}
            </foreach>
        </if>
        <if test="uploadFileids == null ">
            where id = ''
        </if>

    </select>
    <select id="getLocationName" resultType="string">
        select decode(#{location},'0','管线','1','设施','2','其他') as locationName from dual
    </select>
    <select id="getIsbuildName" resultType="string">
        select decode(#{isbuild},'0','否','1','是') as isbuildName from dual
    </select>
    <select id="getToubleRangeIdName" resultType="string">
        select name toubleRangeIdName
        from TF_YWPN_TOUBLERANGE_D
        where id = #{toubleRangeId}
    </select>
    <select id="getTypeIdName" resultType="string">
        select name typeIdName
        from TF_YWPN_TOUBLETYPE_D
        where id = #{typeId}
    </select>
    <select id="getStateName" resultType="string">
        select decode(#{state},'0','无需处理','1','巡查','2','已消除','3','消除申请','4','已上报') as stateName from dual
    </select>

</mapper>
