<?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="cn.cecep.talroad.mapper.analysis.BCoDischargePlanInfoMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.analysis.BCoDischargePlanInfo">
    <!--@mbg.generated-->
    <!--@Table b_co_discharge_plan_info-->
    <result column="id" jdbcType="VARCHAR" property="id" />
    <result column="plan_id" jdbcType="INTEGER" property="planId" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="device_id" jdbcType="VARCHAR" property="deviceId" />
    <result column="plan_start_time" jdbcType="TIMESTAMP" property="planStartTime" />
    <result column="plan_end_time" jdbcType="TIMESTAMP" property="planEndTime" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, plan_id, "type", "name", device_id, plan_start_time, plan_end_time, remarks, 
    create_time, update_time
  </sql>
  <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into b_co_discharge_plan_info
    (id, plan_id, "type", "name", device_id, plan_start_time, plan_end_time, remarks, 
      create_time, update_time)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=VARCHAR}, #{item.planId,jdbcType=INTEGER}, #{item.type,jdbcType=VARCHAR}, 
        #{item.name,jdbcType=VARCHAR}, #{item.deviceId,jdbcType=VARCHAR}, #{item.planStartTime,jdbcType=TIMESTAMP}, 
        #{item.planEndTime,jdbcType=TIMESTAMP}, #{item.remarks,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, 
        #{item.updateTime,jdbcType=TIMESTAMP})
    </foreach>
  </insert>

  <select id="selectAllDevice" resultMap="BaseResultMap">
    SELECT
      bdpi.id,
      bdpi.plan_start_time,
      bdpi.plan_end_time,
      bdpi.remarks,
      bd.work_step AS type,
      bd.NAME,
      bd.device_id

    FROM
    bas_device bd
    LEFT JOIN b_co_discharge_plan_info bdpi ON bd.device_id = bdpi.device_id AND bdpi.plan_id=#{planId,jdbcType=INTEGER}
    WHERE
      bd.industry IN ( 'GT', 'JH' )
      AND bd.TYPE IN ( 'GLMQ', 'ZLMQ', 'MQGW' )
      AND bd.factory_id = #{factoryId,jdbcType=VARCHAR}
    ORDER BY bdpi.id
    </select>
</mapper>