<?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. -->
<!--  文件内容由代码生成器产生，请不要手动修改！ -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2022-09-22 16:18:45  -->
<mapper namespace="net.northking.cctp.device.db.dao.CdDeviceTokenDao">
  <resultMap id="BaseResultMap" type="net.northking.cctp.device.db.entity.CdDeviceToken">
      <!-- 主键id(设备id) -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                      <!-- 令牌 -->
    <result column="token" jdbcType="VARCHAR" property="token"/>
        <!-- 使用类型(1-远程 2-调试 3-计划) -->
    <result column="usage_type" jdbcType="VARCHAR" property="usageType"/>
        <!-- 设备类型(1-移动 2-PC) -->
    <result column="device_type" jdbcType="VARCHAR" property="deviceType"/>
        <!-- 开始时间 -->
    <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
        <!-- 最大到期时间 -->
    <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime"/>

    <result column="user_by" jdbcType="VARCHAR" property="userBy"/>

    <result column="user_id" jdbcType="VARCHAR" property="userId"/>
    </resultMap>

  <sql id="Base_Column_List">
    id
    ,token
    ,usage_type
    ,device_type
    ,start_time
    ,expired_time
    ,user_by
    ,user_id
  </sql>

  <sql id="Table_Name">
    ${defaultSchema}.cd_device_token
  </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.device.db.entity.CdDeviceToken">
    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="token != null">
          AND token=#{token,jdbcType=VARCHAR}
        </if>
              <if test="usageType != null">
          AND usage_type=#{usageType,jdbcType=VARCHAR}
        </if>
              <if test="deviceType != null">
          AND device_type=#{deviceType,jdbcType=VARCHAR}
        </if>
              <if test="startTime != null">
          AND start_time=#{startTime,jdbcType=TIMESTAMP}
        </if>
              <if test="expiredTime != null">
          AND expired_time=#{expiredTime,jdbcType=TIMESTAMP}
        </if>
              <if test="userBy != null">
          AND user_by=#{userBy,jdbcType=VARCHAR}
        </if>
              <if test="userId != null">
          AND user_id=#{userId,jdbcType=VARCHAR}
        </if>
          </trim>
  </delete>

  <insert id="insert" parameterType="net.northking.cctp.device.db.entity.CdDeviceToken">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="token != null">
        token,
      </if>
      <if test="usageType != null">
        usage_type,
      </if>
      <if test="deviceType != null">
        device_type,
      </if>
      <if test="startTime != null">
        start_time,
      </if>
      <if test="expiredTime != null">
        expired_time,
      </if>
      <if test="userBy != null">
        user_by,
      </if>
      <if test="userId != null">
        user_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
          #{id, jdbcType=VARCHAR},
      </if>
      <if test="token != null">
          #{token, jdbcType=VARCHAR},
      </if>
      <if test="usageType != null">
          #{usageType, jdbcType=VARCHAR},
      </if>
      <if test="deviceType != null">
          #{deviceType, jdbcType=VARCHAR},
      </if>
      <if test="startTime != null">
          #{startTime, jdbcType=TIMESTAMP},
      </if>
      <if test="expiredTime != null">
          #{expiredTime, jdbcType=TIMESTAMP},
      </if>
      <if test="userBy != null">
        #{userBy, jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        #{userId, jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    id,
    token,
    usage_type,
    device_type,
    start_time,
    expired_time,
    user_by,
    user_id,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.id, jdbcType=VARCHAR},
    #{item.token, jdbcType=VARCHAR},
    #{item.usageType, jdbcType=VARCHAR},
    #{item.deviceType, jdbcType=VARCHAR},
    #{item.startTime, jdbcType=TIMESTAMP},
    #{item.expiredTime, jdbcType=TIMESTAMP},
    #{item.userBy, jdbcType=VARCHAR},
    #{item.userId, jdbcType=VARCHAR},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.device.db.entity.CdDeviceToken">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="token != null">
        token = #{token, jdbcType=VARCHAR},
      </if>
      <if test="usageType != null">
        usage_type = #{usageType, jdbcType=VARCHAR},
      </if>
      <if test="deviceType != null">
        device_type = #{deviceType, jdbcType=VARCHAR},
      </if>
      <if test="startTime != null">
        start_time = #{startTime, jdbcType=TIMESTAMP},
      </if>
      <if test="expiredTime != null">
        expired_time = #{expiredTime, jdbcType=TIMESTAMP},
      </if>
      <if test="userBy != null">
        user_by = #{userBy, jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        user_id = #{userId, jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.device.db.entity.CdDeviceToken">
    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="token != null">
        AND token = #{token,jdbcType=VARCHAR}
      </if>
      <if test="usageType != null">
        AND usage_type = #{usageType,jdbcType=VARCHAR}
      </if>
      <if test="deviceType != null">
        AND device_type = #{deviceType,jdbcType=VARCHAR}
      </if>
      <if test="startTime != null">
        AND start_time = #{startTime,jdbcType=TIMESTAMP}
      </if>
      <if test="expiredTime != null">
        AND expired_time = #{expiredTime,jdbcType=TIMESTAMP}
      </if>
      <if test="userBy != null">
        AND user_by = #{userBy,jdbcType=VARCHAR}
      </if>
      <if test="userId != null">
        AND user_id = #{userId,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

  <select id="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.device.db.entity.CdDeviceToken">
    select count(*) from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id=#{id,jdbcType=VARCHAR}
      </if>
      <if test="token != null">
        AND token=#{token,jdbcType=VARCHAR}
      </if>
      <if test="usageType != null">
        AND usage_type=#{usageType,jdbcType=VARCHAR}
      </if>
      <if test="deviceType != null">
        AND device_type=#{deviceType,jdbcType=VARCHAR}
      </if>
      <if test="startTime != null">
        AND start_time=#{startTime,jdbcType=TIMESTAMP}
      </if>
      <if test="expiredTime != null">
        AND expired_time=#{expiredTime,jdbcType=TIMESTAMP}
      </if>
      <if test="userBy != null">
        AND user_by = #{userBy,jdbcType=VARCHAR}
      </if>
      <if test="userId != null">
        AND user_id = #{userId,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

</mapper>