<?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.ToubleclearMapper">

    <resultMap id="toubleclearMap" type="com.tofly.pojo.trouble.Toubleclear">
        <id property="id" column="ID"/>
        <result property="auditTime" column="AUDIT_TIME"/>
        <result property="auditUser" column="AUDIT_USER"/>
        <result property="auditNotes" column="AUDIT_NOTES"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="isSubmit" column="IS_SUBMIT"/>
        <result property="toubleId" column="TOUBLE_ID"/>
        <result property="notes" column="NOTES"/>
        <result property="clearFileids" column="CLEAR_FILEIDS"/>
        <result property="isread" column="ISREAD"/>
        <result property="state" column="STATE"/>
        <result property="submitTime" column="SUBMIT_TIME"/>
        <result property="submitUser" column="SUBMIT_USER"/>
        <result property="auditResult" column="AUDIT_RESULT"/>
        <association property="troubleNote" column="TOUBLE_ID" select="getTroubleNote"/>
        <association property="troubleLevel" column="TOUBLE_ID" select="getTroubleLevel"/>
    </resultMap>

    <select id="getTroubleNote" resultType="java.lang.String">
        select notes as troubleNote
        from TF_YWPN_TROUBLE_W
        where id = #{toubleId}
    </select>

    <select id="getTroubleLevel" resultType="java.lang.String">
        select t1.NAME as troubleLevel
        from TF_YWPN_TOUBLERANGE_D t1
        left join TF_YWPN_TROUBLE_W t2 on t1.ID = t2.TOUBLE_RANGE_ID
        where t2.id = #{toubleId}
    </select>

    <update id="clearTroubleUserTaskPlan">
        update TF_XRTY_NEW_UDB.TF_YWPN_USERTASK_W
        set ishandle = '1'
        where table_id in(
            select PLAN_ID
            from TF_YWPN_TROUBLE_W t1 left join TF_YWPN_TOUBLEPLAN_W t2 on t1.id = t2.TROUBLE_ID
            where t1.id = #{toubleId}
        )
          and tkty = '4'
          and tknm = '隐患任务'
    </update>


</mapper>
