<?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.CdDeviceModelDao">

  <resultMap id="DetailMap" type="net.northking.cctp.device.dto.model.CdDeviceModelDetailDto">
    <!-- 机型id -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
    <!-- 机型名称 -->
    <result column="model_name" jdbcType="VARCHAR" property="modelName"/>
    <!-- 所属品牌 -->
    <result column="brand_id" jdbcType="VARCHAR" property="brandId"/>
    <!-- 产品名称 -->
    <result column="product_name" jdbcType="VARCHAR" property="productName"/>
    <!-- 屏幕尺寸 -->
    <result column="screen_size" jdbcType="VARCHAR" property="screenSize"/>
    <!-- 分辨率 -->
    <result column="resolution" jdbcType="VARCHAR" property="resolution"/>
    <!-- 类型 -->
    <result column="type" jdbcType="VARCHAR" property="type"/>
    <!-- 机型图片 -->
    <result column="model_img" jdbcType="VARCHAR" property="modelImg"/>
    <!-- 系统版本 -->
    <result column="system_version" jdbcType="VARCHAR" property="systemVersion"/>
    <!-- cpu核心数 -->
    <result column="cpu_core_num" jdbcType="INTEGER" property="cpuCoreNum"/>
    <!-- cpu型号 -->
    <result column="cpu_model" jdbcType="VARCHAR" property="cpuModel"/>
    <!-- cpu品牌 -->
    <result column="cpu_brand" jdbcType="VARCHAR" property="cpuBrand"/>
    <!-- 内存大小 -->
    <result column="ram_size" jdbcType="VARCHAR" property="ramSize"/>
    <!-- 创建人 -->
    <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"/>
    <!-- 品牌名称 -->
    <result column="brand_name" jdbcType="VARCHAR" property="brandName"/>
  </resultMap>

  <select id="pageQuery" resultMap="DetailMap" parameterType="net.northking.cctp.device.dto.model.CdDeviceModelQueryDto">
    SELECT cdm.*,cmb.brand_name_cn as brand_name
    FROM cd_device_model cdm
    LEFT JOIN cd_mobile_brand cmb ON cdm.brand_id = cmb.id
    <trim prefix="WHERE" prefixOverrides="AND">
      <if test="brandName != null">
        AND LOCATE(#{brandName,jdbcType=VARCHAR},cmb.brand_name_cn) > 0
      </if>
      <if test="modelName != null">
        AND LOCATE(#{modelName,jdbcType=VARCHAR},cdm.model_name) > 0
      </if>
      <if test="productName != null">
        AND LOCATE(#{productName,jdbcType=VARCHAR},cdm.product_name) > 0
      </if>
    </trim>
    order by cdm.created_time desc
  </select>

  <select id="checkOnlyModel" resultType="integer" parameterType="net.northking.cctp.device.db.entity.CdDeviceModel">
    SELECT COUNT(*)
    FROM cd_device_model
    WHERE model_name = #{modelName,jdbcType=VARCHAR}
    AND id NOT IN (#{id,jdbcType=VARCHAR})
  </select>

  <select id="getDeviceConditionWithStatus" parameterType="map" resultType="map">
    SELECT
    c.ID AS brandId,
    c.BRAND_NAME_CN AS brandName,
    a.PLATFORM AS platform,
    a.PLATFORM_VERSION AS platformVersion,
    b.RESOLUTION AS resolution
    FROM
    cd_mobile_device AS a inner JOIN cd_device_model AS b ON a.MODEL_ID = b.ID
    inner JOIN cd_mobile_brand AS c ON b.BRAND_ID = c.ID
    WHERE (a.TENANT_ID = #{tenantId,jdbcType=VARCHAR} or a.TENANT_ID = 'system')
    <if test="platform != null and platform != ''">
      AND a.PLATFORM = #{platform,jdbcType=VARCHAR}
    </if>
  </select>
</mapper>