<?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.aucma.production.mapper.AndonBoardConfigMapper">

    <resultMap type="AndonBoardConfig" id="AndonBoardConfigResult">
            <result property="boardId"    column="board_id"    />
            <result property="boardCode"    column="board_code"    />
            <result property="boardName"    column="board_name"    />
            <result property="productLineCode"    column="product_line_code"    />
            <result property="stationCode"    column="station_code"    />
            <result property="displayFields"    column="display_fields"    />
            <result property="refreshIntervalSec"    column="refresh_interval_sec"    />
            <result property="isFlag"    column="is_flag"    />
            <result property="remark"    column="remark"    />
            <result property="createBy"    column="create_by"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateBy"    column="update_by"    />
            <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAndonBoardConfigVo">
        select board_id, board_code, board_name, product_line_code, station_code, display_fields, refresh_interval_sec, is_flag, remark, create_by, create_time, update_by, update_time from andon_board_config
    </sql>

    <select id="selectAndonBoardConfigList" parameterType="AndonBoardConfig" resultMap="AndonBoardConfigResult">
        <include refid="selectAndonBoardConfigVo"/>
        <where>
                        <if test="boardCode != null  and boardCode != ''"> and board_code = #{boardCode}</if>
                        <if test="boardName != null  and boardName != ''"> and board_name like concat(concat('%', #{boardName}), '%')</if>
                        <if test="productLineCode != null  and productLineCode != ''"> and product_line_code = #{productLineCode}</if>
                        <if test="stationCode != null  and stationCode != ''"> and station_code = #{stationCode}</if>
                        <if test="displayFields != null  and displayFields != ''"> and display_fields = #{displayFields}</if>
                        <if test="refreshIntervalSec != null "> and refresh_interval_sec = #{refreshIntervalSec}</if>
                        <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectAndonBoardConfigByBoardId" parameterType="Long" resultMap="AndonBoardConfigResult">
            <include refid="selectAndonBoardConfigVo"/>
            where board_id = #{boardId}
    </select>

    <insert id="insertAndonBoardConfig" parameterType="AndonBoardConfig">
            <selectKey keyProperty="boardId" resultType="long" order="BEFORE">
                SELECT ANDON_BOARD_CONFIG_SEQ.NEXTVAL as boardId FROM DUAL
            </selectKey>
        insert into andon_board_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="boardId != null">board_id,</if>
                <if test="boardCode != null and boardCode != ''">board_code,</if>
                <if test="boardName != null and boardName != ''">board_name,</if>
                <if test="productLineCode != null">product_line_code,</if>
                <if test="stationCode != null">station_code,</if>
                <if test="displayFields != null">display_fields,</if>
                <if test="refreshIntervalSec != null">refresh_interval_sec,</if>
                <if test="isFlag != null and isFlag != ''">is_flag,</if>
                <if test="remark != null">remark,</if>
                <if test="createBy != null">create_by,</if>
                <if test="createTime != null">create_time,</if>
                <if test="updateBy != null">update_by,</if>
                <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="boardId != null">#{boardId},</if>
                <if test="boardCode != null and boardCode != ''">#{boardCode},</if>
                <if test="boardName != null and boardName != ''">#{boardName},</if>
                <if test="productLineCode != null">#{productLineCode},</if>
                <if test="stationCode != null">#{stationCode},</if>
                <if test="displayFields != null">#{displayFields},</if>
                <if test="refreshIntervalSec != null">#{refreshIntervalSec},</if>
                <if test="isFlag != null and isFlag != ''">#{isFlag},</if>
                <if test="remark != null">#{remark},</if>
                <if test="createBy != null">#{createBy},</if>
                <if test="createTime != null">#{createTime},</if>
                <if test="updateBy != null">#{updateBy},</if>
                <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateAndonBoardConfig" parameterType="AndonBoardConfig">
        update andon_board_config
        <trim prefix="SET" suffixOverrides=",">
                    <if test="boardCode != null and boardCode != ''">board_code = #{boardCode},</if>
                    <if test="boardName != null and boardName != ''">board_name = #{boardName},</if>
                    <if test="productLineCode != null">product_line_code = #{productLineCode},</if>
                    <if test="stationCode != null">station_code = #{stationCode},</if>
                    <if test="displayFields != null">display_fields = #{displayFields},</if>
                    <if test="refreshIntervalSec != null">refresh_interval_sec = #{refreshIntervalSec},</if>
                    <if test="isFlag != null and isFlag != ''">is_flag = #{isFlag},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where board_id = #{boardId}
    </update>

    <delete id="deleteAndonBoardConfigByBoardId" parameterType="Long">
        delete from andon_board_config where board_id = #{boardId}
    </delete>

    <delete id="deleteAndonBoardConfigByBoardIds" parameterType="String">
        delete from andon_board_config where board_id in
        <foreach item="boardId" collection="array" open="(" separator="," close=")">
            #{boardId}
        </foreach>
    </delete>
</mapper>