<?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>

    <sql id="Base_Column_List1">
        id
        ,user_id,model_id,
        model_name_en model_name,src_id,col,station_id,device_type,
        col_name_en col_name
    </sql>
    <sql id="Base_Column_List2">
        id
        ,user_id,model_id,
        model_name_fra model_name,src_id,col,station_id,device_type,
        col_name_en col_name
    </sql>
    <sql id="Base_Column_List3">
        id
        ,user_id,model_id,
        model_name_spa model_name,src_id,col,station_id,device_type,
        col_name_en col_name
    </sql>
    <sql id="Base_Column_List4">
        id
        ,user_id,model_id,
        model_name_de model_name,src_id,col,station_id,device_type,
        col_name_en col_name
    </sql>
    <sql id="Base_Column_List5">
        id
        ,user_id,model_id,
        model_name_pl model_name,src_id,col,station_id,device_type,
        col_name_en col_name
    </sql>
    <sql id="Base_Column_List6">
        id
        ,user_id,model_id,
        model_name_ara model_name,src_id,col,station_id,device_type,
        col_name_en col_name
    </sql>


    <insert id="insertBatch">
        INSERT INTO his_curve_relate
        (user_id,model_id,
        model_name,model_name_en,
        model_name_fra,model_name_spa,model_name_de,model_name_pl,model_name_ara,
         src_id,col,station_id,device_type,
        col_name,col_name_en,
        col_name_fra,col_name_spa,col_name_de,col_name_pl, col_name_ara)
        VALUES
        <foreach item="item" collection="list" index="index" separator=",">
            (
            #{item.userId},#{item.modelId},#{item.modelName},#{item.modelNameEn},
            #{item.modelNameFra},#{item.modelNameSpa},#{item.modelNameDe},#{item.modelNamePl},#{item.modelNameAra},
             #{item.srcId},#{item.col} ,#{item.stationId},#{item.deviceType}
            ,#{item.colName},#{item.colNameEn},#{item.colNameFra},#{item.colNameSpa},#{item.colNameDe},#{item.colNamePl},#{item.colNameAra}
            )
        </foreach>

    </insert>

    <select id="selectAll" resultType="com.ho.business.entity.HisCurveRelate">
        select
        <choose>
            <when test="hisCurveRelate.lang != null and hisCurveRelate.lang=='en_US' ">
                <include refid="Base_Column_List1"/>
            </when>
            <when test="hisCurveRelate.lang != null and hisCurveRelate.lang=='fr_FR' ">
                <include refid="Base_Column_List2"/>
            </when>
            <when test="hisCurveRelate.lang != null and hisCurveRelate.lang=='es_ES' ">
                <include refid="Base_Column_List3"/>
            </when>
            <when test="hisCurveRelate.lang != null and hisCurveRelate.lang=='de_DE' ">
                <include refid="Base_Column_List4"/>
            </when>
            <when test="hisCurveRelate.lang != null and hisCurveRelate.lang=='pl_PL' ">
                <include refid="Base_Column_List5"/>
            </when>
            <when test="hisCurveRelate.lang != null and hisCurveRelate.lang=='ar_EG' ">
                <include refid="Base_Column_List6"/>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        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>
