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

    <resultMap id="repairplanyearMap" type="com.tofly.pojo.maintain.Repairplanyear">
        <id property="id" column="ID"/>
        <result property="year" column="YEAR"/>
        <result property="issubmit" column="ISSUBMIT"/>
        <result property="submitTime" column="SUBMIT_TIME"/>
        <result property="submitUser" column="SUBMIT_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="planState" column="PLAN_STATE"/>
        <result property="note" column="NOTE"/>
        <association property="issubmitName" column="ISSUBMIT" select="getIssubmitName"/>
        <association property="submitUserName" column="SUBMIT_USER"
                     select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="planStateName" column="PLAN_STATE" select="getPlanStateName"/>
        <association property="details" column="id" select="getDetails"/>
        <association property="auditVoList" column="id" select="getAuditVoList"/>
    </resultMap>

    <resultMap id="yeardetailMap" type="com.tofly.pojo.maintain.Repairplanyeardetail">
        <id property="id" column="ID"/>
        <result property="yearId" column="YEAR_ID"/>
        <result property="year" column="YEAR"/>
        <result property="month" column="MONTH"/>
        <result property="planContent" column="PLAN_CONTENT"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="typeId" column="TYPE_ID"/>
        <result property="typeName" column="TYPE_NAME"/>
        <result property="unit" column="UNIT"/>
<!--        <association property="typeName" column="TYPE_ID" select="com.tofly.gpsboot.mapper.maintain.RepairplanyeardetailMapper.getTypeName"/>-->
        <association property="createUserName" column="CREATE_USER"
                     select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
    </resultMap>
    <select id="getDetails" resultMap="yeardetailMap">
        select * from TF_YWPN_REPAIRPLANYEARDETAIL_W where year_Id = #{id}
    </select>

    <select id="getPlanStateName" resultType="string">
        select decode(#{planState},'0','待审核','1','审批通过','2','审批拒绝') as planStateName from dual
    </select>

    <select id="getIssubmitName" resultType="string">
        select decode(#{issubmit},'0','未上报','1','已上报') as issubmitName from dual
    </select>


    <resultMap id="auditMap" 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="getAuditStateName" resultType="string">
        select decode(#{auditState},'0','未审核','1','通过','2','未通过','3','不可审批') as auditStateName from dual
    </select>


    <select id="getAuditVoList" resultMap="auditMap">
        select  * from  TF_YMPN_AUDIT_W where audit_type = '08' and Audit_Plan_Id = #{id}
    </select>
</mapper>
