<?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">
<!--  Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved. -->
<!--  Mybatis数据库持久层（底层映射文件）：计划批次设备关联表 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2022-12-23 15:34:17  -->
<mapper namespace="net.northking.cctp.executePlan.db.dao.AtuPlanBatchDeviceLinkDao">
  <resultMap id="BaseResultMap" type="net.northking.cctp.executePlan.db.entity.AtuPlanBatchDeviceLink">
      <!-- 主键 -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                      <!-- 批次号 -->
    <result column="batch_id" jdbcType="VARCHAR" property="batchId"/>
        <!-- 设备编号 -->
    <result column="device_id" jdbcType="VARCHAR" property="deviceId"/>
        <!-- 设备类型;1-PC，2-移动端 -->
    <result column="device_type" jdbcType="CHAR" property="deviceType"/>
        <!-- 是否离线;0-否，1-是 -->
    <result column="is_offline" jdbcType="BIT" property="offline"/>
        <!-- 离线时间 -->
    <result column="offline_time" jdbcType="TIMESTAMP" property="offlineTime"/>
    </resultMap>

  <sql id="Base_Column_List">
    id
    ,batch_id
    ,device_id
    ,device_type
    ,is_offline
    ,offline_time
  </sql>

  <sql id="Table_Name">
    ${defaultSchema}.atu_plan_batch_device_link
  </sql>

  <select id="findByPrimaryKey" parameterType="String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=VARCHAR}
  </select>

  <select id="findByPrimaryKeys" parameterType="java.util.List">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id in
    <foreach collection="list" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </select>

  <delete id="deleteByPrimaryKey" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=VARCHAR}
  </delete>

  <delete id="deleteByPrimaryKeys" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where id in
    <foreach collection="list" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </delete>

  <delete id="deleteByExample" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatchDeviceLink">
    delete from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <choose>
        <when test="id != null">
          id = #{id,jdbcType=VARCHAR}
        </when>
      </choose>
              <if test="id != null">
          AND id=#{id,jdbcType=VARCHAR}
        </if>
              <if test="batchId != null">
          AND batch_id=#{batchId,jdbcType=VARCHAR}
        </if>
              <if test="deviceId != null">
          AND device_id=#{deviceId,jdbcType=VARCHAR}
        </if>
              <if test="deviceType != null">
          AND device_type=#{deviceType,jdbcType=CHAR}
        </if>
              <if test="offline != null">
          AND is_offline=#{offline,jdbcType=BIT}
        </if>
              <if test="offlineTime != null">
          AND offline_time=#{offlineTime,jdbcType=TIMESTAMP}
        </if>
          </trim>
  </delete>

  <insert id="insert" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatchDeviceLink">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="batchId != null">
        batch_id,
      </if>
      <if test="deviceId != null">
        device_id,
      </if>
      <if test="deviceType != null">
        device_type,
      </if>
      <if test="offline != null">
        is_offline,
      </if>
      <if test="offlineTime != null">
        offline_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
          #{id, jdbcType=VARCHAR},
      </if>
      <if test="batchId != null">
          #{batchId, jdbcType=VARCHAR},
      </if>
      <if test="deviceId != null">
          #{deviceId, jdbcType=VARCHAR},
      </if>
      <if test="deviceType != null">
          #{deviceType, jdbcType=CHAR},
      </if>
      <if test="offline != null">
          #{offline, jdbcType=BIT},
      </if>
      <if test="offlineTime != null">
          #{offlineTime, jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    id,
    batch_id,
    device_id,
    device_type,
    is_offline,
    offline_time,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.id, jdbcType=VARCHAR},
    #{item.batchId, jdbcType=VARCHAR},
    #{item.deviceId, jdbcType=VARCHAR},
    #{item.deviceType, jdbcType=CHAR},
    #{item.offline, jdbcType=BIT},
    #{item.offlineTime, jdbcType=TIMESTAMP},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatchDeviceLink">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="batchId != null">
        batch_id = #{batchId, jdbcType=VARCHAR},
      </if>
      <if test="deviceId != null">
        device_id = #{deviceId, jdbcType=VARCHAR},
      </if>
      <if test="deviceType != null">
        device_type = #{deviceType, jdbcType=CHAR},
      </if>
      <if test="offline != null">
        is_offline = #{offline, jdbcType=BIT},
      </if>
      <if test="offlineTime != null">
        offline_time = #{offlineTime, jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatchDeviceLink">
    select
    <include refid="Base_Column_List" />
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="batchId != null">
        AND batch_id = #{batchId,jdbcType=VARCHAR}
      </if>
      <if test="deviceId != null">
        AND device_id = #{deviceId,jdbcType=VARCHAR}
      </if>
      <if test="deviceType != null">
        AND device_type = #{deviceType,jdbcType=CHAR}
      </if>
      <if test="offline != null">
        AND is_offline = #{offline,jdbcType=BIT}
      </if>
      <if test="offlineTime != null">
        AND offline_time = #{offlineTime,jdbcType=TIMESTAMP}
      </if>
    </trim>
  </select>

  <select id="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanBatchDeviceLink">
    select count(*) from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id=#{id,jdbcType=VARCHAR}
      </if>
      <if test="batchId != null">
        AND batch_id=#{batchId,jdbcType=VARCHAR}
      </if>
      <if test="deviceId != null">
        AND device_id=#{deviceId,jdbcType=VARCHAR}
      </if>
      <if test="deviceType != null">
        AND device_type=#{deviceType,jdbcType=CHAR}
      </if>
      <if test="offline != null">
        AND is_offline=#{offline,jdbcType=BIT}
      </if>
      <if test="offlineTime != null">
        AND offline_time=#{offlineTime,jdbcType=TIMESTAMP}
      </if>
    </trim>
  </select>

</mapper>