<?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="com.njcn.csdevice.mapper.CsDevModelRelationMapper">
  <resultMap id="BaseResultMap" type="com.njcn.csdevice.pojo.po.CsDevModelRelationPO">
    <!--@mbg.generated-->
    <!--@Table cs_dev_model_relation-->
    <result column="id" jdbcType="VARCHAR" property="id" />
    <result column="dev_id" jdbcType="VARCHAR" property="devId" />
    <result column="model id" jdbcType="VARCHAR" property="modelId" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="status" jdbcType="BOOLEAN" property="status" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, dev_id, `model id`, create_by, create_time, update_by, update_time, `status`
  </sql>


  <select id="getModelByType" resultType="string">
    select
        t1.id
    from
        cs_dev_model_relation t0
    left join cs_dev_model t1 on
        t0.model_id = t1.id
    where
    t0.status="1" and
        t0.dev_id = #{devId} and t1.`type` = #{type}
  </select>
  <select id="getVersionByDevId" resultType="string">
    select
    t1.version_no
    from
    cs_dev_model_relation t0
    left join cs_dev_model t1 on
    t0.model_id = t1.id
    where
    t0.status="1" and
    t0.dev_id = #{devId}
    order by t1.version_date desc limit 1
  </select>
</mapper>