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

    <resultMap id="BaseResultMap" type="com.ho.business.entity.HisCurveRelate">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <id property="stationId" column="station_id" jdbcType="INTEGER"/>
        <result property="userId" column="user_id" jdbcType="VARCHAR"/>
        <result property="modelId" column="model_id" jdbcType="VARCHAR"/>
        <result property="modelName" column="model_name" jdbcType="VARCHAR"/>
        <result property="srcId" column="src_id" jdbcType="INTEGER"/>
        <result property="col" column="col" jdbcType="VARCHAR"/>
        <result property="colName" column="col_name" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,user_id,model_id,
        model_name,src_id,col,station_id,device_type,
        col_name
    </sql>


    <insert id="insertBatch">
        INSERT INTO his_curve_relate
        (user_id,model_id,
        model_name,src_id,col,station_id,device_type,
        col_name)
        VALUES
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.userId},#{item.modelId},#{item.modelName},#{item.srcId}
            ,#{item.col} ,#{item.stationId},#{item.deviceType}
            ,#{item.colName}
            )
        </foreach>

    </insert>

    <select id="selectAll" resultType="com.ho.business.entity.HisCurveRelate">
        select
        <include refid="Base_Column_List"/>
        from his_curve_relate
        <where>
            <if test="hisCurveRelate.stationId!=null">
                and station_id = #{hisCurveRelate.stationId}
            </if>
            <if test="hisCurveRelate.userId!=null">
                and user_id = #{hisCurveRelate.userId}
            </if>
            <if test="hisCurveRelate.modelName!=null">
                and model_name like concat('%',#{hisCurveRelate.modelName},'%')
            </if>
        </where>
    </select>

    <delete id="delete">
        delete
        from his_curve_relate
        where model_id = #{modelId}
    </delete>
</mapper>
