<?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-29 09:58:35  -->
<mapper namespace="net.northking.cctp.device.db.dao.CdDeviceTenantDao">
  <resultMap id="BaseResultMap" type="net.northking.cctp.device.db.entity.CdDeviceTenant">
      <!-- 主键id(device_id) -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                  <!-- 租户id -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!-- 到期时间 -->
    <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime"/>
        <!-- 回收方式(1-自动回收 2-手动回收) -->
    <result column="recycle_type" jdbcType="VARCHAR" property="recycleType"/>
    </resultMap>

  <sql id="Base_Column_List">
    id
    ,tenant_id
    ,expired_time
    ,recycle_type
  </sql>

  <sql id="Table_Name">
    ${defaultSchema}.cd_device_tenant
  </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.CdDeviceTenant">
    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="tenantId != null">
          AND tenant_id=#{tenantId,jdbcType=VARCHAR}
        </if>
              <if test="expiredTime != null">
          AND expired_time=#{expiredTime,jdbcType=TIMESTAMP}
        </if>
              <if test="recycleType != null">
          AND recycle_type=#{recycleType,jdbcType=VARCHAR}
        </if>
          </trim>
  </delete>

  <insert id="insert" parameterType="net.northking.cctp.device.db.entity.CdDeviceTenant">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="tenantId != null">
        tenant_id,
      </if>
      <if test="expiredTime != null">
        expired_time,
      </if>
      <if test="recycleType != null">
        recycle_type,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
          #{id, jdbcType=VARCHAR},
      </if>
      <if test="tenantId != null">
          #{tenantId, jdbcType=VARCHAR},
      </if>
      <if test="expiredTime != null">
          #{expiredTime, jdbcType=TIMESTAMP},
      </if>
      <if test="recycleType != null">
          #{recycleType, jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    id,
    tenant_id,
    expired_time,
    recycle_type,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.id, jdbcType=VARCHAR},
    #{item.tenantId, jdbcType=VARCHAR},
    #{item.expiredTime, jdbcType=TIMESTAMP},
    #{item.recycleType, jdbcType=VARCHAR},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.device.db.entity.CdDeviceTenant">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="tenantId != null">
        tenant_id = #{tenantId, jdbcType=VARCHAR},
      </if>
      <if test="expiredTime != null">
        expired_time = #{expiredTime, jdbcType=TIMESTAMP},
      </if>
      <if test="recycleType != null">
        recycle_type = #{recycleType, jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.device.db.entity.CdDeviceTenant">
    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="tenantId != null">
        AND tenant_id = #{tenantId,jdbcType=VARCHAR}
      </if>
      <if test="expiredTime != null">
        AND expired_time = #{expiredTime,jdbcType=TIMESTAMP}
      </if>
      <if test="recycleType != null">
        AND recycle_type = #{recycleType,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

  <select id="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.device.db.entity.CdDeviceTenant">
    select count(*) from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id=#{id,jdbcType=VARCHAR}
      </if>
      <if test="tenantId != null">
        AND tenant_id=#{tenantId,jdbcType=VARCHAR}
      </if>
      <if test="expiredTime != null">
        AND expired_time=#{expiredTime,jdbcType=TIMESTAMP}
      </if>
      <if test="recycleType != null">
        AND recycle_type=#{recycleType,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

</mapper>