<?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.ho.business.mapper.ModelTypeColMapper">

    <resultMap id="BaseResultMap" type="com.ho.business.entity.ModelTypeCol">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="modelTypeId" column="model_type_id" jdbcType="INTEGER"/>
        <result property="modelType" column="model_type" jdbcType="VARCHAR"/>
        <result property="modelTypeName" column="model_type_name" jdbcType="VARCHAR"/>
        <result property="col" column="col" jdbcType="VARCHAR"/>
        <result property="colName" column="col_name" jdbcType="VARCHAR"/>
        <result property="dataType" column="data_type" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,model_type_id,model_type,
        model_type_name,col,col_name,
        data_type
    </sql>

    <sql id="Base_List">
        id
        ,model_type_id,model_type,
        model_type_name,col,col_name
    </sql>

    <insert id="insert">
        insert into model_type_col
        (id, model_type_id, model_type,
         model_type_name, col, col_name,
         data_type)
        values ( #{id}, #{model_type_id}, #{model_type}
               , #{model_type_name}, #{col}, #{col_name}, #{data_type})
    </insert>

    <insert id="insertSelective">
        insert into model_type_col
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="modelTypeId != null">model_type_id,</if>
            <if test="modelType != null">model_type,</if>
            <if test="modelTypeName != null">model_type_name,</if>
            <if test="col != null">col</if>
            <if test="colName != null">col_name</if>
            <if test="dataType != null">data_type</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="modelTypeId != null">#{modelTypeId},</if>
            <if test="modelType != null">#{modelType},</if>
            <if test="modelTypeName != null">#{modelTypeName},</if>
            <if test="col != null">#{col},</if>
            <if test="colName != null">#{colName},</if>
            <if test="dataType != null">#{dataType},</if>
        </trim>
    </insert>

    <insert id="addBatchModel" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
        insert into model_type_col (<include refid="Base_List"/>)
        values
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.id}, #{item.modelTypeId}, #{item.modelType}
            , #{item.modelTypeName}, #{item.col}, #{item.colName}
            )
        </foreach>

    </insert>


    <update id="updateByPrimaryKeySelective">
        update model_type_col
        <set>
            <if test="modelTypeId != null">
                model_type_id=#{modelTypeId},
            </if>
            <if test="modelType != null">
                model_type=#{modelType},
            </if>

            <if test="modelTypeName != null">
                model_type_name=#{modelTypeName},
            </if>
            <if test="col != null">
                col=#{col},
            </if>
            <if test="colName != null">
                col_name=#{colName},
            </if>
            <if test="dataType != null">
                data_type=#{dataType},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <delete id="deleteByPrimaryKey">
        delete
        from model_type_col
        where id = #{id}
    </delete>

    <select id="selectByTypeId" resultType="com.ho.business.entity.ModelTypeCol">
        select
        <include refid="Base_Column_List"/>
        from model_type_col
        where model_type_id=#{modelTypeId}
    </select>

    <select id="selectByModelType" resultType="com.ho.business.entity.ModelTypeCol">
        select
        <include refid="Base_Column_List"/>
        from model_type_col
        <where>
            <if test="type!=null">
                and model_type = #{type}
            </if>
            <if test="name!=null">
                and (col_name LIKE concat('%',#{name},'%') or col LIKE concat('%',#{name},'%'))
            </if>
        </where>
        ORDER BY id desc
    </select>

    <select id="selectSameModelCol" resultType="com.ho.business.entity.ModelTypeCol">
        select
        <include refid="Base_Column_List"/>
        from model_type_col
        <where>
            <if test="deviceType != null">
                and model_type=#{deviceType}
            </if>
            <if test="list != null and list.size !=0">
                and col in
                <foreach collection="list" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>

    </select>

    <select id="selectByIds" resultType="com.ho.business.entity.ModelTypeCol">
        select
        <include refid="Base_Column_List"/>
        from model_type_col
        <where>
            <if test="ids != null and ids.size !=0">
                and id in
                <foreach collection="ids" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectByCol" resultType="com.ho.business.entity.ModelTypeCol">
        select
        <include refid="Base_Column_List"/>
        from model_type_col
        <where>
            <if test="col != null">
                and col=#{col}
            </if>
        </where>
    </select>

    <select id="selectByColList" resultType="com.ho.business.entity.ModelTypeCol">
        select
        <include refid="Base_Column_List"/>
        from model_type_col
        <where>
            <if test="list != null and list.size !=0">
                and col in
                <foreach collection="list" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    <select id="selectById" resultType="com.ho.business.entity.ModelTypeCol">
        select
        <include refid="Base_Column_List"/>
        from model_type_col
        where id = #{modelColId}
    </select>
    <select id="selectByColValue" resultType="com.ho.business.entity.ModelTypeCol">
        select
        <include refid="Base_Column_List"/>
        from model_type_col
        <where>
            <if test="col != null">
                and col=#{col}
            </if>
            <if test="modelType != null">
                and model_type=#{modelType}
            </if>
        </where>
    </select>
</mapper>
