<?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.maintain.RepairrecordMapper">

    <resultMap id="repairrecordMap" type="com.tofly.pojo.maintain.Repairrecord">
        <id property="id" column="ID"/>
        <result property="lgtd" column="LGTD"/>
        <result property="lttd" column="LTTD"/>
        <result property="repairUserid" column="REPAIR_USERID"/>
        <result property="network" column="NETWORK"/>
        <result property="address" column="ADDRESS"/>
        <result property="bore" column="BORE"/>
        <result property="notes" column="NOTES"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="fileIdsOne" column="FILE_IDS_ONE"/>
        <result property="fileIdsTow" column="FILE_IDS_TOW"/>
        <result property="fileIdsThree" column="FILE_IDS_THREE"/>
        <result property="flag" column="FLAG"/>
        <result property="state" column="STATE"/>
        <result property="repairDevice" column="REPAIR_DEVICE"/>
        <result property="repairLayer" column="REPAIR_LAYER"/>
        <result property="regionCode" column="REGION_CODE"/>
        <result property="regionName" column="REGION_NAME"/>
        <result property="repairType" column="REPAIR_TYPE"/>
    </resultMap>


    <resultMap id="repairOrderRecordInfoVoMap" type="com.tofly.pojo.maintain.vo.datail.RepairOrderRecordInfoVo">
        <result property="respUser" column="RESP_USER"/>
        <result property="teamUser" column="TEAM_USER"/>
        <result property="address" column="ADDRESS"/>
        <result property="bore" column="BORE"/>
        <result property="notes" column="NOTES"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="fileIdsOne" column="FILE_IDS_ONE"/>
        <result property="fileIdsTow" column="FILE_IDS_TOW"/>
        <result property="fileIdsThree" column="FILE_IDS_THREE"/>
        <result property="flag" column="FLAG"/>
        <result property="repairDevice" column="REPAIR_DEVICE"/>
        <result property="regionName" column="REGION_NAME"/>
        <result property="repairType" column="REPAIR_TYPE"/>
        <result property="recordId" column="RECORD_ID"/>
        <result property="x" column="X"/>
        <result property="y" column="Y"/>
        <result property="createTimeStr" column="CREATE_TIME_STR"/>
        <result property="repairLayer" column="REPAIR_LAYER"/>
        <association property="respUserName" column="RESP_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="teamUserName" column="TEAM_USER" select="com.tofly.gpsboot.mapper.maintain.RepairuserMapper.getTeamUserName"/>
        <association property="flagName" column="FLAG" select="getFlagName"/>
        <association property="repairTypeName" column="REPAIR_TYPE" select="getTypeName"/>
        <collection property="fileIdsOneList" column="FILE_IDS_ONE" select="getFileIdsOneList"/>
        <collection property="fileIdsTowList" column="FILE_IDS_TOW" select="getFileIdsTowList"/>
        <collection property="fileIdsThreeList" column="FILE_IDS_THREE" select="getFileIdsThreeList"/>
    </resultMap>

    <select id="getRepairRecordInfo" resultMap="repairOrderRecordInfoVoMap">
        SELECT
            t2.RESP_USER,
            t2.TEAM_USER,
            t3.CREATE_TIME,
            t3.REGION_NAME,
            t3.ADDRESS,
            t3.NOTES,
            t3.FILE_IDS_ONE,
            t3.FILE_IDS_TOW,
            t3.FILE_IDS_THREE,
            t3.FLAG,
            t3.REPAIR_DEVICE,
            t3.REPAIR_TYPE,
            t3.BORE,
            t3.ID as RECORD_ID,
            t3.LGTD X,
            t3.LTTD Y,
            date_format(t3.CREATE_TIME, '%Y-%m-%d %H:%i:%s') as CREATE_TIME_STR,
            t3.REPAIR_LAYER
        FROM
            TF_YWPN_REPAIRORDER_W t1
                LEFT JOIN TF_YWPN_REPAIRUSER_W t2 ON t1. ID = t2.REPAIR_ID
                LEFT JOIN TF_YWPN_REPAIRRECORD_W t3 ON t2.ID = t3.REPAIR_USERID
        WHERE t1.ID = #{id}
        ORDER BY t3.CREATE_TIME DESC
    </select>


    <select id="getFlagName" resultType="java.lang.String">
        select (case #{flag}
                    when '0' then '驳回'
                    when '1' then '正常'
                    else '' end )
                   as flagName from dual
    </select>
    <select id="getTypeName" resultType="java.lang.String">
        select name as repairTypeName from TF_YWPN_REPAIRTYPE_D where id = #{repairType}
    </select>


    <select id="getFileIdsOneList" resultType="java.lang.String"  >
        select FILE_PATH as filePath
        from TF_YWPN_FILE_W
        <if test="fileIdsOne != null and fileIdsOne != ''  ">where id in
            <foreach item="nodeCodestr" collection="fileIdsOne.split(',')" open="(" separator="," close=")">
                #{nodeCodestr}
            </foreach>
        </if>
        <if test="fileIdsOne == null ">
            where id = ''
        </if>

    </select>

    <select id="getFileIdsTowList" resultType="java.lang.String"  >
        select FILE_PATH as filePath
        from TF_YWPN_FILE_W
        <if test="fileIdsTow != null and fileIdsTow != ''  ">where id in
            <foreach item="nodeCodestr" collection="fileIdsTow.split(',')" open="(" separator="," close=")">
                #{nodeCodestr}
            </foreach>
        </if>
        <if test="fileIdsTow == null ">
            where id = ''
        </if>

    </select>

    <select id="getFileIdsThreeList" resultType="java.lang.String"  >
        select FILE_PATH as filePath
        from TF_YWPN_FILE_W
        <if test="fileIdsThree != null and fileIdsThree != ''  ">where id in
            <foreach item="nodeCodestr" collection="fileIdsThree.split(',')" open="(" separator="," close=")">
                #{nodeCodestr}
            </foreach>
        </if>
        <if test="fileIdsThree == null ">
            where id = ''
        </if>

    </select>

</mapper>
