<?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.ximai.mes.pro.mapper.ProScheduleSetupRuleMapper">
    
    <resultMap type="ProScheduleSetupRule" id="ProScheduleSetupRuleResult">
        <result property="ruleId"    column="rule_id"    />
        <result property="ruleCode"    column="rule_code"    />
        <result property="itemTypeId"    column="item_type_id"    />
        <result property="itemTypeName"    column="item_type_name"    />
        <result property="processId"    column="process_id"    />
        <result property="processName"    column="process_name"    />
        <result property="tool"    column="tool"    />
        <result property="mould"    column="mould"    />
        <result property="plate"    column="plate"    />
        <result property="materialRecoil"    column="material_recoil"    />
        <result property="sheetLength"    column="sheet_length"    />
        <result property="sheetWidth"    column="sheet_width"    />
        <result property="productStandard"    column="product_standard"    />
        <result property="proConColor"    column="pro_con_color"    />
        <result property="inlay"    column="inlay"    />
        <result property="routeCode"    column="route_code"    />
        <result property="productWidth"    column="product_width"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectProScheduleSetupRuleVo">
        select rule_id, rule_code, item_type_id, item_type_name, process_id, process_name, tool, mould, plate, material_recoil, sheet_length, sheet_width, product_standard, pro_con_color, inlay, route_code, product_width, create_by, create_time from pro_schedule_setup_rule
    </sql>

    <select id="selectProScheduleSetupRuleList" parameterType="ProScheduleSetupRule" resultMap="ProScheduleSetupRuleResult">
        <include refid="selectProScheduleSetupRuleVo"/>
        <where>  
            <if test="ruleCode != null  and ruleCode != ''"> and rule_code = #{ruleCode}</if>
            <if test="itemTypeId != null "> and item_type_id = #{itemTypeId}</if>
            <if test="itemTypeName != null  and itemTypeName != ''"> and item_type_name like concat('%', #{itemTypeName}, '%')</if>
            <if test="processId != null "> and process_id = #{processId}</if>
            <if test="processName != null  and processName != ''"> and process_name like concat('%', #{processName}, '%')</if>
            <if test="tool != null "> and tool = #{tool}</if>
            <if test="mould != null "> and mould = #{mould}</if>
            <if test="plate != null "> and plate = #{plate}</if>
            <if test="materialRecoil != null "> and material_recoil = #{materialRecoil}</if>
            <if test="sheetLength != null "> and sheet_length = #{sheetLength}</if>
            <if test="sheetWidth != null "> and sheet_width = #{sheetWidth}</if>
            <if test="productStandard != null "> and product_standard = #{productStandard}</if>
            <if test="proConColor != null "> and pro_con_color = #{proConColor}</if>
            <if test="inlay != null "> and inlay = #{inlay}</if>
            <if test="routeCode != null "> and route_code = #{routeCode}</if>
            <if test="productWidth != null "> and product_width = #{productWidth}</if>
        </where>
    </select>
    
    <select id="selectProScheduleSetupRuleByRuleId" parameterType="Long" resultMap="ProScheduleSetupRuleResult">
        <include refid="selectProScheduleSetupRuleVo"/>
        where rule_id = #{ruleId}
    </select>
        
    <insert id="insertProScheduleSetupRule" parameterType="ProScheduleSetupRule">
        insert into pro_schedule_setup_rule
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ruleId != null">rule_id,</if>
            <if test="ruleCode != null">rule_code,</if>
            <if test="itemTypeId != null">item_type_id,</if>
            <if test="itemTypeName != null">item_type_name,</if>
            <if test="processId != null">process_id,</if>
            <if test="processName != null">process_name,</if>
            <if test="tool != null">tool,</if>
            <if test="mould != null">mould,</if>
            <if test="plate != null">plate,</if>
            <if test="materialRecoil != null">material_recoil,</if>
            <if test="sheetLength != null">sheet_length,</if>
            <if test="sheetWidth != null">sheet_width,</if>
            <if test="productStandard != null">product_standard,</if>
            <if test="proConColor != null">pro_con_color,</if>
            <if test="inlay != null">inlay,</if>
            <if test="routeCode != null">route_code,</if>
            <if test="productWidth != null">product_width,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ruleId != null">#{ruleId},</if>
            <if test="ruleCode != null">#{ruleCode},</if>
            <if test="itemTypeId != null">#{itemTypeId},</if>
            <if test="itemTypeName != null">#{itemTypeName},</if>
            <if test="processId != null">#{processId},</if>
            <if test="processName != null">#{processName},</if>
            <if test="tool != null">#{tool},</if>
            <if test="mould != null">#{mould},</if>
            <if test="plate != null">#{plate},</if>
            <if test="materialRecoil != null">#{materialRecoil},</if>
            <if test="sheetLength != null">#{sheetLength},</if>
            <if test="sheetWidth != null">#{sheetWidth},</if>
            <if test="productStandard != null">#{productStandard},</if>
            <if test="proConColor != null">#{proConColor},</if>
            <if test="inlay != null">#{inlay},</if>
            <if test="routeCode != null">#{routeCode},</if>
            <if test="productWidth != null">#{productWidth},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateProScheduleSetupRule" parameterType="ProScheduleSetupRule">
        update pro_schedule_setup_rule
        <trim prefix="SET" suffixOverrides=",">
            <if test="ruleCode != null">rule_code = #{ruleCode},</if>
            <if test="itemTypeId != null">item_type_id = #{itemTypeId},</if>
            <if test="itemTypeName != null">item_type_name = #{itemTypeName},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="processName != null">process_name = #{processName},</if>
            <if test="tool != null">tool = #{tool},</if>
            <if test="mould != null">mould = #{mould},</if>
            <if test="plate != null">plate = #{plate},</if>
            <if test="materialRecoil != null">material_recoil = #{materialRecoil},</if>
            <if test="sheetLength != null">sheet_length = #{sheetLength},</if>
            <if test="sheetWidth != null">sheet_width = #{sheetWidth},</if>
            <if test="productStandard != null">product_standard = #{productStandard},</if>
            <if test="proConColor != null">pro_con_color = #{proConColor},</if>
            <if test="inlay != null">inlay = #{inlay},</if>
            <if test="routeCode != null">route_code = #{routeCode},</if>
            <if test="productWidth != null">product_width = #{productWidth},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where rule_id = #{ruleId}
    </update>

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

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