<?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.ProScheduleSetupRuleValMapper">
    
    <resultMap type="ProScheduleSetupRuleVal" id="ProScheduleSetupRuleValResult">
        <result property="ruleValId"    column="rule_val_id"    />
        <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="workorderId"    column="workorder_id"    />
        <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="selectProScheduleSetupRuleValVo">
        select rule_val_id, item_type_id, item_type_name, process_id, process_name, workorder_id, 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_val
    </sql>

    <select id="selectProScheduleSetupRuleValList" parameterType="ProScheduleSetupRuleVal" resultMap="ProScheduleSetupRuleValResult">
        <include refid="selectProScheduleSetupRuleValVo"/>
        <where>  
            <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="workorderId != null "> and workorder_id = #{workorderId}</if>
            <if test="tool != null  and tool != ''"> and tool = #{tool}</if>
            <if test="mould != null  and mould != ''"> and mould = #{mould}</if>
            <if test="plate != null  and plate != ''"> and plate = #{plate}</if>
            <if test="materialRecoil != null  and materialRecoil != ''"> and material_recoil = #{materialRecoil}</if>
            <if test="sheetLength != null  and sheetLength != ''"> and sheet_length = #{sheetLength}</if>
            <if test="sheetWidth != null  and sheetWidth != ''"> and sheet_width = #{sheetWidth}</if>
            <if test="productStandard != null  and productStandard != ''"> and product_standard = #{productStandard}</if>
            <if test="proConColor != null  and proConColor != ''"> and pro_con_color = #{proConColor}</if>
            <if test="inlay != null  and inlay != ''"> and inlay = #{inlay}</if>
            <if test="routeCode != null  and routeCode != ''"> and route_code = #{routeCode}</if>
            <if test="productWidth != null  and productWidth != ''"> and product_width = #{productWidth}</if>
        </where>
    </select>
    
    <select id="selectProScheduleSetupRuleValByRuleValId" parameterType="Long" resultMap="ProScheduleSetupRuleValResult">
        <include refid="selectProScheduleSetupRuleValVo"/>
        where rule_val_id = #{ruleValId}
    </select>
        
    <insert id="insertProScheduleSetupRuleVal" parameterType="ProScheduleSetupRuleVal">
        insert into pro_schedule_setup_rule_val
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <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="workorderId != null">workorder_id,</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="itemTypeId != null">#{itemTypeId},</if>
            <if test="itemTypeName != null">#{itemTypeName},</if>
            <if test="processId != null">#{processId},</if>
            <if test="processName != null">#{processName},</if>
            <if test="workorderId != null">#{workorderId},</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="updateProScheduleSetupRuleVal" parameterType="ProScheduleSetupRuleVal">
        update pro_schedule_setup_rule_val
        <trim prefix="SET" suffixOverrides=",">
            <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="workorderId != null">workorder_id = #{workorderId},</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_val_id = #{ruleValId}
    </update>

    <delete id="deleteProScheduleSetupRuleValByRuleValId" parameterType="Long">
        delete from pro_schedule_setup_rule_val where rule_val_id = #{ruleValId}
    </delete>

    <delete id="deleteProScheduleSetupRuleValByRuleValIds" parameterType="String">
        delete from pro_schedule_setup_rule_val where rule_val_id in 
        <foreach item="ruleValId" collection="array" open="(" separator="," close=")">
            #{ruleValId}
        </foreach>
    </delete>
</mapper>