<?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="net.northking.cctp.device.db.dao.CdMobileBrandDao">


  <resultMap id="DetailMap" type="net.northking.cctp.device.dto.brand.CdMobileBrandDetailDto">
    <!-- 主键id -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
    <!-- 品牌名称 -->
    <result column="brand_name" jdbcType="VARCHAR" property="brandName"/>
    <!-- 中文名称 -->
    <result column="brand_name_cn" jdbcType="VARCHAR" property="brandNameCn"/>
    <!-- 品牌标识 -->
    <result column="brand_icon" jdbcType="VARCHAR" property="brandIcon"/>
    <!-- 创建人 -->
    <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
    <!-- 创建时间 -->
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
    <!-- 更新人 -->
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
    <!-- 更新时间 -->
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
  </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.device.db.entity.CdMobileBrand">
    select
    id
    ,brand_name
    ,brand_name_cn
    ,brand_icon
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND">
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="brandName != null">
        AND LOCATE(#{brandName,jdbcType=VARCHAR},brand_name) > 0
      </if>
      <if test="brandNameCn != null">
        AND LOCATE(#{brandNameCn,jdbcType=VARCHAR},brand_name_cn) > 0
      </if>
      <if test="brandIcon != null">
        AND brand_icon=#{brandIcon,jdbcType=VARCHAR}
      </if>
      <if test="createdBy != null">
        AND created_by=#{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time=#{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="updatedBy != null">
        AND updated_by=#{updatedBy,jdbcType=VARCHAR}
      </if>
      <if test="updatedTime != null">
        AND updated_time=#{updatedTime,jdbcType=TIMESTAMP}
      </if>
    </trim>
    order by created_time desc
  </select>

  <select id="findAllBrand" resultMap="BaseResultMap">
    SELECT
    id
    ,brand_name_cn
    FROM
    <include refid="Table_Name"/>
    order by created_time desc
  </select>

  <select id="checkBrand" resultType="integer" parameterType="net.northking.cctp.device.db.entity.CdMobileBrand">
    SELECT COUNT(*)
    FROM cd_mobile_brand
    WHERE brand_name = #{brandName,jdbcType=VARCHAR}
    <if test="id != null">
      AND id not in (#{id,jdbcType=VARCHAR})
    </if>
  </select>
  <!-- 请在本文件内添加自定义SQL语句 -->
</mapper>