<?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.plan.PlanmouthMapper">

    <resultMap id="planmouthMap" type="com.tofly.pojo.plan.Planmouth">
        <id property="id" column="ID"/>
        <result property="year" column="YEAR"/>
        <result property="mouth" column="MOUTH"/>
        <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="planContent" column="PLAN_CONTENT"/>
        <result property="maintenanceFlag" column="MAINTENANCE_FLAG"/>
        <association property="planNum" column="ID" select="getPlanNum"/>
        <association property="executePlanNum" column="ID" select="getExecutePlanNum"/>
        <association property="executeNotPlanNum" column="ID" select="getExecuteNotPlanNum"/>
        <association property="planStateName" column="PLAN_STATE"
                     select="com.tofly.gpsboot.mapper.comm.AuditMapper.getAuditStateName"/>
        <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="maintenanceFlagName" column="MAINTENANCE_FLAG"
                     select="com.tofly.gpsboot.mapper.plan.PlanMapper.getMaintenanceFlagName"/>
        <collection property="auditVoList" column="ID"
                    select="com.tofly.gpsboot.mapper.comm.AuditMapper.getAuditMonthlyPlanInfo"/>
    </resultMap>


    <select id="getPlanNum" resultType="java.lang.Integer">
        SELECT count(1)
        FROM TF_YWPN_PLAN_W
        WHERE MOUTH_ID = #{id}
    </select>

    <select id="getExecutePlanNum" resultType="java.lang.Integer">
        SELECT count(1) as
        FROM TF_YWPN_PLAN_W
        WHERE MOUTH_ID = #{id}
          AND PLAN_STATE not in ('0'
            , '1'
            , '2')
    </select>

    <select id="getExecuteNotPlanNum" resultType="java.lang.Integer">
        SELECT count(1) as
        FROM TF_YWPN_PLAN_W
        WHERE MOUTH_ID = #{id}
          AND PLAN_STATE in ('0'
            , '1'
            , '2')
    </select>


    <select id="getIssubmitName" resultType="string">
        SELECT CNAME
        FROM TF_YWPN_SYSCHILDCODE_D
        WHERE PCID = 50800
          AND CCODE = #{issubmit}
    </select>

</mapper>
