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

    <resultMap type="AndonRule" id="AndonRuleResult">
            <result property="ruleId"    column="rule_id"    />
            <result property="ruleName"    column="rule_name"    />
            <result property="callTypeCode"    column="call_type_code"    />
            <result property="productLineCode"    column="product_line_code"    />
            <result property="stationCode"    column="station_code"    />
            <result property="teamCode"    column="team_code"    />
            <result property="sourceType"    column="source_type"    />
            <result property="ackTimeoutMin"    column="ack_timeout_min"    />
            <result property="resolveTimeoutMin"    column="resolve_timeout_min"    />
            <result property="priorityDefault"    column="priority_default"    />
            <result property="notifyRoles"    column="notify_roles"    />
            <result property="notifyUsers"    column="notify_users"    />
            <result property="escalateLevels"    column="escalate_levels"    />
            <result property="effectiveBeginTime"    column="effective_begin_time"    />
            <result property="effectiveEndTime"    column="effective_end_time"    />
            <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="selectAndonRuleVo">
        select rule_id, rule_name, call_type_code, product_line_code, station_code, team_code, source_type, ack_timeout_min, resolve_timeout_min, priority_default, notify_roles, notify_users, escalate_levels, effective_begin_time, effective_end_time, is_flag, remark, create_by, create_time, update_by, update_time from andon_rule
    </sql>

    <select id="selectAndonRuleList" parameterType="AndonRule" resultMap="AndonRuleResult">
        <include refid="selectAndonRuleVo"/>
        <where>
                        <if test="ruleName != null  and ruleName != ''"> and rule_name like concat(concat('%', #{ruleName}), '%')</if>
                        <if test="callTypeCode != null  and callTypeCode != ''"> and call_type_code = #{callTypeCode}</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="teamCode != null  and teamCode != ''"> and team_code = #{teamCode}</if>
                        <if test="sourceType != null  and sourceType != ''"> and source_type = #{sourceType}</if>
                        <if test="ackTimeoutMin != null "> and ack_timeout_min = #{ackTimeoutMin}</if>
                        <if test="resolveTimeoutMin != null "> and resolve_timeout_min = #{resolveTimeoutMin}</if>
                        <if test="priorityDefault != null "> and priority_default = #{priorityDefault}</if>
                        <if test="notifyRoles != null  and notifyRoles != ''"> and notify_roles = #{notifyRoles}</if>
                        <if test="notifyUsers != null  and notifyUsers != ''"> and notify_users = #{notifyUsers}</if>
                        <if test="escalateLevels != null  and escalateLevels != ''"> and escalate_levels = #{escalateLevels}</if>
                        <if test="effectiveBeginTime != null "> and effective_begin_time = #{effectiveBeginTime}</if>
                        <if test="effectiveEndTime != null "> and effective_end_time = #{effectiveEndTime}</if>
                        <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectAndonRuleByRuleId" parameterType="Long" resultMap="AndonRuleResult">
            <include refid="selectAndonRuleVo"/>
            where rule_id = #{ruleId}
    </select>

    <insert id="insertAndonRule" parameterType="AndonRule">
            <selectKey keyProperty="ruleId" resultType="long" order="BEFORE">
                SELECT ANDON_RULE_SEQ.NEXTVAL as ruleId FROM DUAL
            </selectKey>
        insert into andon_rule
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="ruleId != null">rule_id,</if>
                <if test="ruleName != null and ruleName != ''">rule_name,</if>
                <if test="callTypeCode != null and callTypeCode != ''">call_type_code,</if>
                <if test="productLineCode != null">product_line_code,</if>
                <if test="stationCode != null">station_code,</if>
                <if test="teamCode != null">team_code,</if>
                <if test="sourceType != null">source_type,</if>
                <if test="ackTimeoutMin != null">ack_timeout_min,</if>
                <if test="resolveTimeoutMin != null">resolve_timeout_min,</if>
                <if test="priorityDefault != null">priority_default,</if>
                <if test="notifyRoles != null">notify_roles,</if>
                <if test="notifyUsers != null">notify_users,</if>
                <if test="escalateLevels != null">escalate_levels,</if>
                <if test="effectiveBeginTime != null">effective_begin_time,</if>
                <if test="effectiveEndTime != null">effective_end_time,</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="ruleId != null">#{ruleId},</if>
                <if test="ruleName != null and ruleName != ''">#{ruleName},</if>
                <if test="callTypeCode != null and callTypeCode != ''">#{callTypeCode},</if>
                <if test="productLineCode != null">#{productLineCode},</if>
                <if test="stationCode != null">#{stationCode},</if>
                <if test="teamCode != null">#{teamCode},</if>
                <if test="sourceType != null">#{sourceType},</if>
                <if test="ackTimeoutMin != null">#{ackTimeoutMin},</if>
                <if test="resolveTimeoutMin != null">#{resolveTimeoutMin},</if>
                <if test="priorityDefault != null">#{priorityDefault},</if>
                <if test="notifyRoles != null">#{notifyRoles},</if>
                <if test="notifyUsers != null">#{notifyUsers},</if>
                <if test="escalateLevels != null">#{escalateLevels},</if>
                <if test="effectiveBeginTime != null">#{effectiveBeginTime},</if>
                <if test="effectiveEndTime != null">#{effectiveEndTime},</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="updateAndonRule" parameterType="AndonRule">
        update andon_rule
        <trim prefix="SET" suffixOverrides=",">
                    <if test="ruleName != null and ruleName != ''">rule_name = #{ruleName},</if>
                    <if test="callTypeCode != null and callTypeCode != ''">call_type_code = #{callTypeCode},</if>
                    <if test="productLineCode != null">product_line_code = #{productLineCode},</if>
                    <if test="stationCode != null">station_code = #{stationCode},</if>
                    <if test="teamCode != null">team_code = #{teamCode},</if>
                    <if test="sourceType != null">source_type = #{sourceType},</if>
                    <if test="ackTimeoutMin != null">ack_timeout_min = #{ackTimeoutMin},</if>
                    <if test="resolveTimeoutMin != null">resolve_timeout_min = #{resolveTimeoutMin},</if>
                    <if test="priorityDefault != null">priority_default = #{priorityDefault},</if>
                    <if test="notifyRoles != null">notify_roles = #{notifyRoles},</if>
                    <if test="notifyUsers != null">notify_users = #{notifyUsers},</if>
                    <if test="escalateLevels != null">escalate_levels = #{escalateLevels},</if>
                    <if test="effectiveBeginTime != null">effective_begin_time = #{effectiveBeginTime},</if>
                    <if test="effectiveEndTime != null">effective_end_time = #{effectiveEndTime},</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 rule_id = #{ruleId}
    </update>

    <delete id="deleteAndonRuleByRuleId" parameterType="Long">
        delete from andon_rule where rule_id = #{ruleId}
    </delete>

    <delete id="deleteAndonRuleByRuleIds" parameterType="String">
        delete from andon_rule where rule_id in
        <foreach item="ruleId" collection="array" open="(" separator="," close=")">
            #{ruleId}
        </foreach>
    </delete>
</mapper>