<?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.CsDevModelMapper">
  <resultMap id="BaseResultMap" type="com.njcn.csdevice.pojo.po.CsDevModelPO">
    <!--@mbg.generated-->
    <!--@Table cs_dev_model-->
    <result column="id" jdbcType="VARCHAR" property="id" />
    <result column="dev_type" jdbcType="VARCHAR" property="devType" />
    <result column="version_no" jdbcType="VARCHAR" property="versionNo" />
    <result column="version_date" jdbcType="TIMESTAMP" property="versionDate" />
    <result column="file_path" jdbcType="VARCHAR" property="filePath" />
    <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_type, version_no, version_date, file_path, create_by, create_time, update_by, 
    update_time, `status`
  </sql>
    <select id="getPage" resultType="com.njcn.csdevice.pojo.vo.CsDevModelPageVO">
       SELECT a.*
            FROM cs_dev_model a
                    WHERE
                    1 = 1 And a.`status`='1'
            <if test="csDevModelQueryParm.versionStartDate != null and csDevModelQueryParm.versionStartDate != ''">
                AND a.version_date &gt;= #{csDevModelQueryParm.versionStartDate }
            </if>
            <if test="csDevModelQueryParm.versionEndDate != null and csDevModelQueryParm.versionEndDate != ''">
                AND a.version_date &lt;= #{csDevModelQueryParm.versionEndDate }
            </if>

            <if test="csDevModelQueryParm.devName != null and csDevModelQueryParm.devName != ''">
                AND a.dev_type_name = #{csDevModelQueryParm.devName}
            </if>
             <if test="csDevModelQueryParm.name != null and csDevModelQueryParm.name != ''">
                AND a.name LIKE concat('%',#{csDevModelQueryParm.name},'%')
            </if>
       order by a.version_date desc
  </select>
    <select id="queryOne" resultType="com.njcn.csdevice.pojo.vo.CsDevModelPageVO">
   SELECT a.*
        FROM cs_dev_model a
                WHERE
                1 = 1 And a.`status`='1'
<!--        <if test="csDevModelQueryListParm.versionStartDate != null and csDevModelQueryListParm.versionStartDate != ''">-->
<!--            AND a.version_date &gt;= #{csDevModelQueryListParm.versionStartDate }-->
<!--        </if>-->
<!--        <if test="csDevModelQueryListParm.versionEndDate != null and csDevModelQueryListParm.versionEndDate != ''">-->
<!--            AND a.version_date  &lt;= #{csDevModelQueryListParm.versionEndDate }-->
<!--        </if>-->

        <if test="csDevModelQueryListParm.versionDate != null and csDevModelQueryListParm.versionDate != ''">
            AND a.version_date  = #{csDevModelQueryListParm.versionDate }
        </if>

        <if test="csDevModelQueryListParm.versionNo != null and csDevModelQueryListParm.versionNo != ''">
            AND a.version_no = #{csDevModelQueryListParm.versionNo}
        </if>
        <if test="csDevModelQueryListParm.devType != null and csDevModelQueryListParm.devType != ''">
            AND a.dev_type = #{csDevModelQueryListParm.devType}
        </if>
    <if test="csDevModelQueryListParm.devName != null and csDevModelQueryListParm.devName != ''">
        AND a.dev_type_name = #{csDevModelQueryListParm.devName}
    </if>
         <if test="csDevModelQueryListParm.name != null and csDevModelQueryListParm.name != ''">
            AND a.name = #{csDevModelQueryListParm.name}
        </if>

   </select>

    <select id="getDataArrayByModelId" resultType="com.njcn.csdevice.pojo.dto.DataArrayDTO">
        select
            distinct t1.id dataSetId,t1.another_name dataSetName ,t2.name dataArrayName,t2.another_name dataArrayShowName
        from
            cs_dev_model t0
        left join cs_data_set t1 on
            t0.id = t1.pid
        left join cs_data_array t2 on
            t1.id = t2.pid
        where
            t0.id = #{modelId}
    </select>

</mapper>