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

    <resultMap type="ProWorkOrderArrangeRule" id="ProWorkOrderArrangeRuleResult">
        <result property="arrangeRuleId"    column="arrange_rule_id"    />
        <result property="arrangeRuleCode"    column="arrange_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="routeCode"    column="route_code"    />
        <result property="routeDesc"    column="route_desc"    />
        <result property="brandCode"    column="brand_code"    />
        <result property="itemCode"    column="item_code"    />
        <result property="length"    column="length"    />
        <result property="width"    column="width"    />
        <result property="productMaterial"    column="product_material"    />
        <result property="processCode"    column="process_code"    />
        <result property="spacing"    column="spacing"    />
        <result property="frontImg"    column="front_img"    />
        <result property="toolList"    column="tool_list"    />
        <result property="shape"    column="shape"    />
        <result property="inlay"    column="inlay"    />
        <result property="blownFilmWidth"    column="blown_film_width"    />
        <result property="blownFilmThickness"    column="blown_film_thickness"    />
        <result property="printingWidth"    column="printing_width"    />
        <result property="requestDateInterval"    column="request_date_interval"    />
        <result property="requestDateIntervalMinNum"    column="request_date_interval_min_num"    />
        <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="selectProWorkOrderArrangeRuleVo">
        select arrange_rule_id, arrange_rule_code, item_type_id, item_type_name, process_id, process_name, process_id, process_name, route_code, route_desc, brand_code, item_code, length, width, product_material, process_code, spacing, front_img, tool_list, shape, inlay, blown_film_width, blown_film_thickness, printing_width,
               request_date_interval,request_date_interval_min_num,create_by, create_time, update_by, update_time from pro_work_order_arrange_rule
    </sql>

    <select id="selectProWorkOrderArrangeRuleList" parameterType="ProWorkOrderArrangeRule" resultMap="ProWorkOrderArrangeRuleResult">
        <include refid="selectProWorkOrderArrangeRuleVo"/>
        <where>
            <if test="arrangeRuleCode != null  and arrangeRuleCode != ''"> and arrange_rule_code = #{arrangeRuleCode}</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 processId != ''"> and process_id = #{processId}</if>
            <if test="processName != null  and processName != ''"> and process_name like concat('%', #{processName}, '%')</if>
            <if test="routeCode != null  and routeCode != ''"> and route_code = #{routeCode}</if>
            <if test="routeDesc != null  and routeDesc != ''"> and route_desc = #{routeDesc}</if>
            <if test="brandCode != null  and brandCode != ''"> and brand_code = #{brandCode}</if>
            <if test="itemCode != null  and itemCode != ''"> and item_code = #{itemCode}</if>
            <if test="length != null  and length != ''"> and length = #{length}</if>
            <if test="width != null  and width != ''"> and width = #{width}</if>
            <if test="productMaterial != null  and productMaterial != ''"> and product_material = #{productMaterial}</if>
            <if test="processCode != null  and processCode != ''"> and process_code = #{processCode}</if>
            <if test="spacing != null  and spacing != ''"> and spacing = #{spacing}</if>
            <if test="frontImg != null  and frontImg != ''"> and front_img = #{frontImg}</if>
            <if test="toolList != null  and toolList != ''"> and tool_list = #{toolList}</if>
            <if test="shape != null  and shape != ''"> and shape = #{shape}</if>
            <if test="inlay != null  and inlay != ''"> and inlay = #{inlay}</if>
            <if test="blownFilmWidth != null  and blownFilmWidth != ''"> and blown_film_width = #{blownFilmWidth}</if>
            <if test="blownFilmThickness != null  and blownFilmThickness != ''"> and blown_film_thickness = #{blownFilmThickness}</if>
            <if test="printingWidth != null  and printingWidth != ''"> and printing_width = #{printingWidth}</if>
        </where>
    </select>

    <select id="selectProWorkOrderArrangeRuleByArrangeRuleId" parameterType="Long" resultMap="ProWorkOrderArrangeRuleResult">
        <include refid="selectProWorkOrderArrangeRuleVo"/>
        where arrange_rule_id = #{arrangeRuleId}
    </select>

    <insert id="insertProWorkOrderArrangeRule" parameterType="ProWorkOrderArrangeRule" useGeneratedKeys="true" keyProperty="arrangeRuleId">
        insert into pro_work_order_arrange_rule
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="arrangeRuleCode != null and arrangeRuleCode != ''">arrange_rule_code,</if>
            <if test="itemTypeId != null">item_type_id,</if>
            <if test="itemTypeName != null and itemTypeName != ''">item_type_name,</if>
            <if test="processId != null">process_id,</if>
            <if test="processName != null">process_name,</if>
            <if test="routeCode != null">route_code,</if>
            <if test="routeDesc != null">route_desc,</if>
            <if test="brandCode != null">brand_code,</if>
            <if test="itemCode != null">item_code,</if>
            <if test="length != null">length,</if>
            <if test="width != null">width,</if>
            <if test="productMaterial != null">product_material,</if>
            <if test="processCode != null">process_code,</if>
            <if test="spacing != null">spacing,</if>
            <if test="frontImg != null">front_img,</if>
            <if test="toolList != null">tool_list,</if>
            <if test="shape != null">shape,</if>
            <if test="inlay != null">inlay,</if>
            <if test="blownFilmWidth != null">blown_film_width,</if>
            <if test="blownFilmThickness != null">blown_film_thickness,</if>
            <if test="printingWidth != null">printing_width,</if>
            <if test="requestDateInterval != null">request_date_interval,</if>
            <if test="requestDateIntervalMinNum != null">request_date_interval_min_num,</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="arrangeRuleCode != null and arrangeRuleCode != ''">#{arrangeRuleCode},</if>
            <if test="itemTypeId != null">#{itemTypeId},</if>
            <if test="itemTypeName != null and itemTypeName != ''">#{itemTypeName},</if>
            <if test="processId != null">#{processId},</if>
            <if test="processName != null">#{processName},</if>
            <if test="routeCode != null">#{routeCode},</if>
            <if test="routeDesc != null">#{routeDesc},</if>
            <if test="brandCode != null">#{brandCode},</if>
            <if test="itemCode != null">#{itemCode},</if>
            <if test="length != null">#{length},</if>
            <if test="width != null">#{width},</if>
            <if test="productMaterial != null">#{productMaterial},</if>
            <if test="processCode != null">#{processCode},</if>
            <if test="spacing != null">#{spacing},</if>
            <if test="frontImg != null">#{frontImg},</if>
            <if test="toolList != null">#{toolList},</if>
            <if test="shape != null">#{shape},</if>
            <if test="inlay != null">#{inlay},</if>
            <if test="blownFilmWidth != null">#{blownFilmWidth},</if>
            <if test="blownFilmThickness != null">#{blownFilmThickness},</if>
            <if test="printingWidth != null">#{printingWidth},</if>
            <if test="requestDateInterval != null">#{requestDateInterval},</if>
            <if test="requestDateIntervalMinNum != null">#{requestDateIntervalMinNum},</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="updateProWorkOrderArrangeRule" parameterType="ProWorkOrderArrangeRule">
        update pro_work_order_arrange_rule
        <trim prefix="SET" suffixOverrides=",">
            <if test="arrangeRuleCode != null and arrangeRuleCode != ''">arrange_rule_code = #{arrangeRuleCode},</if>
            <if test="itemTypeId != null">item_type_id = #{itemTypeId},</if>
            <if test="itemTypeName != null and itemTypeName != ''">item_type_name = #{itemTypeName},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="processName != null">process_name = #{processName},</if>
            <if test="routeCode != null">route_code = #{routeCode},</if>
            <if test="routeDesc != null">route_desc = #{routeDesc},</if>
            <if test="brandCode != null">brand_code = #{brandCode},</if>
            <if test="itemCode != null">item_code = #{itemCode},</if>
            <if test="length != null">length = #{length},</if>
            <if test="width != null">width = #{width},</if>
            <if test="productMaterial != null">product_material = #{productMaterial},</if>
            <if test="processCode != null">process_code = #{processCode},</if>
            <if test="spacing != null">spacing = #{spacing},</if>
            <if test="frontImg != null">front_img = #{frontImg},</if>
            <if test="toolList != null">tool_list = #{toolList},</if>
            <if test="shape != null">shape = #{shape},</if>
            <if test="inlay != null">inlay = #{inlay},</if>
            <if test="blownFilmWidth != null">blown_film_width = #{blownFilmWidth},</if>
            <if test="blownFilmThickness != null">blown_film_thickness = #{blownFilmThickness},</if>
            <if test="printingWidth != null">printing_width = #{printingWidth},</if>
            <if test="blownFilmThickness != null">blown_film_thickness = #{blownFilmThickness},</if>
            <if test="printingWidth != null">printing_width = #{printingWidth},</if>
            <if test="requestDateInterval != null">request_date_interval = #{requestDateInterval},</if>
            <if test="requestDateIntervalMinNum != null">request_date_interval_min_num = #{requestDateIntervalMinNum},</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 arrange_rule_id = #{arrangeRuleId}
    </update>

    <delete id="deleteProWorkOrderArrangeRuleByArrangeRuleId" parameterType="Long">
        delete from pro_work_order_arrange_rule where arrange_rule_id = #{arrangeRuleId}
    </delete>

    <delete id="deleteProWorkOrderArrangeRuleByArrangeRuleIds" parameterType="String">
        delete from pro_work_order_arrange_rule where arrange_rule_id in
        <foreach item="arrangeRuleId" collection="array" open="(" separator="," close=")">
            #{arrangeRuleId}
        </foreach>
    </delete>
</mapper>
