<?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.comm.AuditMapper">

    <resultMap id="auditMap" type="com.tofly.pojo.comm.Audit">
        <id property="id" column="ID"/>
        <result property="auditType" column="AUDIT_TYPE"/>
        <result property="auditPlanId" column="AUDIT_PLAN_ID"/>
        <result property="auditState" column="AUDIT_STATE"/>
        <result property="auditTime" column="AUDIT_TIME"/>
        <result property="auditNote" column="AUDIT_NOTE"/>
        <result property="auditUser" column="AUDIT_USER"/>
        <result property="auditLevel" column="AUDIT_LEVEL"/>
        <association property="auditStateName" column="AUDIT_STATE" select="getAuditStateName"/>
        <association property="auditUserName" column="AUDIT_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
    </resultMap>

    <select id="getAuditStateName" resultType="string">
        SELECT CNAME
        FROM
            TF_YWPN_SYSCHILDCODE_D
        WHERE
            PCID =50700
          AND
            CCODE = #{auditState}
    </select>

    <select id="getAuditRepairOrderInfo" resultMap="auditMap">
        SELECT
            *
        FROM
            TF_YMPN_AUDIT_W t1
        WHERE
            t1.AUDIT_TYPE = '10'
            and t1.AUDIT_PLAN_ID = #{id}
        ORDER BY   t1.AUDIT_TIME DESC
    </select>

    <select id="getAuditMonthlyPlanInfo" resultMap="auditMap">
        SELECT
            *
        FROM
            TF_YMPN_AUDIT_W t1
        WHERE
            t1.AUDIT_TYPE = '01'
          and t1.AUDIT_PLAN_ID = #{id}
        ORDER BY   t1.AUDIT_TIME DESC
    </select>


    <resultMap id="auditVoMap" type="com.tofly.pojo.comm.vo.AuditVo">
        <id property="id" column="ID"/>
        <result property="auditType" column="AUDIT_TYPE"/>
        <result property="auditPlanId" column="AUDIT_PLAN_ID"/>
        <result property="auditState" column="AUDIT_STATE"/>
        <result property="auditTime" column="AUDIT_TIME"/>
        <result property="auditNote" column="AUDIT_NOTE"/>
        <result property="auditUser" column="AUDIT_USER"/>
        <result property="auditLevel" column="AUDIT_LEVEL"/>
        <association property="auditStateName" column="AUDIT_STATE" select="getAuditStateName"/>
        <association property="auditUserName" column="AUDIT_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
    </resultMap>

    <select id="getAuditVoList" resultMap="auditVoMap">
        select  * from TF_YMPN_AUDIT_W where AUDIT_TYPE = #{type} and AUDIT_PLAN_ID = #{id}
    </select>

    <select id="getRepairPlanAuditVoList" resultMap="auditVoMap">
        select  * from TF_YMPN_AUDIT_W where AUDIT_TYPE = '11' and AUDIT_PLAN_ID = #{id}
    </select>

    <select id="getPlanYearAuditVoList" resultMap="auditVoMap">
        select  * from TF_YMPN_AUDIT_W where AUDIT_TYPE = '00' and AUDIT_PLAN_ID = #{id}
    </select>

    <select id="getPlanMonthAuditVoList" resultMap="auditVoMap">
        select  * from TF_YMPN_AUDIT_W where AUDIT_TYPE = '01' and AUDIT_PLAN_ID = #{id}
    </select>
</mapper>
