<?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.elephant.framework.galaxy.aroad.module.emergencyplan.mapper.EmergencyPlanMapper">

  <resultMap id="emergencyPlanMap" type="com.elephant.framework.galaxy.aroad.module.emergencyplan.entity.EmergencyPlan">
        <id property="planId" column="plan_id"/>
        <result property="planName" column="plan_name"/>
        <result property="planType" column="plan_type"/>
        <result property="planLevel" column="plan_level"/>
        <result property="planDocName" column="plan_doc_name"/>
        <result property="planDocUrl" column="plan_doc_url"/>
        <result property="planKeyword" column="plan_keyword"/>
        <result property="publishDept" column="publish_dept"/>
        <result property="publishTime" column="publish_time"/>
        <result property="publisher" column="publisher"/>
        <result property="publisherId" column="publisher_id"/>
  </resultMap>

      <resultMap id="emergencyPlanDtoMap" type="com.elephant.framework.galaxy.aroad.module.emergencyplan.dto.EmergencyPlanDto">
            <id property="planId" column="plan_id"/>
            <result property="planName" column="plan_name"/>
            <result property="planType" column="plan_type"/>
            <result property="planLevel" column="plan_level"/>
            <result property="planDocName" column="plan_doc_name"/>
            <result property="planDocUrl" column="plan_doc_url"/>
            <result property="planKeyword" column="plan_keyword"/>
            <result property="publishDept" column="publish_dept"/>
            <result property="publishTime" column="publish_time"/>
            <result property="publisher" column="publisher"/>
            <result property="publisherId" column="publisher_id"/>

            <collection property="planDoc" ofType="com.elephant.framework.galaxy.aroad.response.UpFileResponse">
                  <result property="name" column="plan_doc_name"/>
                  <result property="url" column="plan_doc_url"/>
            </collection>
      </resultMap>


      <select id="getPlanPage" resultMap="emergencyPlanDtoMap">
            select
               plan_id,
               plan_name,
               plan_type,
               plan_level,
               plan_doc_name,
               plan_doc_url,
               plan_keyword,
               publish_dept,
               publish_time,
               publisher,
               publisher_id
            from
               emergency_plan
          <where>
            1 = 1
            <if test="emergencyPlan.planKeyword != null">
                and plan_keyword like concat('%',#{emergencyPlan.planKeyword},'%')
            </if>
            <if test="emergencyPlan.planName != null">
                and plan_name like concat('%',#{emergencyPlan.planName},'%')
            </if>
            <if test="emergencyPlan.publishDept != null">
                and publish_dept like concat('%',#{emergencyPlan.publishDept},'%')
            </if>
          </where>
      </select>
</mapper>
