<?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.productionRequest.ProProductionRequestMapper">

    <resultMap type="ProProductionRequest" id="ProProductionRequestResult">
        <result property="productionRequestId"    column="production_request_id"    />
        <result property="productionRequestCode"    column="production_request_code"    />
        <result property="routeId"    column="route_id"    />
        <result property="itemId"    column="item_id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="warehouse"    column="warehouse"    />
        <result property="sizeGroup"    column="size_group"    />
        <result property="isNeedShoeImg"    column="is_need_shoe_img"    />
        <result property="isNeedPrototype"    column="is_need_prototype"    />
        <result property="isUniqueCode"    column="is_unique_code"    />
        <result property="isConsiderColor"    column="is_consider_color"    />
        <result property="isDisabled"    column="is_disabled"    />
        <result property="shoeImg"    column="shoe_img"    />
        <result property="prototype"    column="prototype"    />
        <result property="productionRequestStatus"    column="production_request_status"    />
        <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"    />
        <result property="routeName"    column="route_name"    />
        <result property="itemName"    column="item_name"    />
        <result property="factoryName"    column="factory_name"    />
        <result property="length"    column="length"    />
        <result property="width"    column="width"    />
        <result property="height"    column="height"    />
        <result property="thick"    column="thick"    />
        <result property="weight"    column="weight"    />
        <result property="angleType"    column="angle_type"    />
        <result property="isAllotype"    column="is_allotype"    />
        <result property="isRightAngle"    column="is_right_angle"    />
        <result property="fillet"    column="fillet"    />
        <result property="angle"    column="angle"    />
        <result property="aperture"    column="aperture"    />
        <result property="singleLayerThick"    column="single_layer_thick"    />
        <result property="singleWeight"    column="single_weight"    />
        <result property="layerNum"    column="layer_num"    />
        <result property="isMould"    column="is_mould"    />
        <result property="isCoding"    column="is_coding"    />
        <result property="certification"    column="certification"    />
        <result property="shape"    column="shape"    />
        <result property="shapeSize"    column="shape_size"    />
    </resultMap>

    <sql id="selectProProductionRequestVo">
        select production_request_id, production_request_code, route_id, item_id, factory_id, warehouse, size_group, is_need_shoe_img, is_need_prototype, is_unique_code, is_consider_color, is_disabled, shoe_img, prototype, production_request_status, remark, create_by, create_time, update_by, update_time,
            length, width, height, thick, weight, angle_type,is_allotype,is_right_angle,fillet, angle, aperture, single_layer_thick, single_weight, layer_num, is_mould, is_coding, certification, shape, shape_size
        from pro_production_request
    </sql>

    <sql id="selectProProductionRequestVoJoin">
        select t1.*,
               t2.item_name,t3.route_name,t4.factory_name
        from pro_production_request t1
                left join md_item t2 on t1.item_id = t2.item_id
                left join pro_route t3 on t1.route_id = t3.route_id
                left join md_factory t4 on t1.factory_id = t4.factory_id

    </sql>

    <select id="selectProProductionRequestList" parameterType="ProProductionRequest" resultMap="ProProductionRequestResult">
        <include refid="selectProProductionRequestVo"/>
        <where>
            <if test="productionRequestCode != null  and productionRequestCode != ''"> and production_request_code = #{productionRequestCode}</if>
            <if test="routeId != null "> and route_id = #{routeId}</if>
            <if test="itemId != null "> and item_id = #{itemId}</if>
            <if test="factoryId != null "> and factory_id = #{factoryId}</if>
            <if test="warehouse != null  and warehouse != ''"> and warehouse = #{warehouse}</if>
            <if test="sizeGroup != null  and sizeGroup != ''"> and size_group = #{sizeGroup}</if>
            <if test="isNeedShoeImg != null "> and is_need_shoe_img = #{isNeedShoeImg}</if>
            <if test="isNeedPrototype != null "> and is_need_prototype = #{isNeedPrototype}</if>
            <if test="isUniqueCode != null "> and is_unique_code = #{isUniqueCode}</if>
            <if test="isConsiderColor != null "> and is_consider_color = #{isConsiderColor}</if>
            <if test="isDisabled != null "> and is_disabled = #{isDisabled}</if>
            <if test="shoeImg != null  and shoeImg != ''"> and shoe_img = #{shoeImg}</if>
            <if test="prototype != null  and prototype != ''"> and prototype = #{prototype}</if>
            <if test="productionRequestStatus != null "> and production_request_status = #{productionRequestStatus}</if>
        </where>
    </select>

    <select id="selectProProductionRequestListJoin" parameterType="ProProductionRequest" resultMap="ProProductionRequestResult">
        <include refid="selectProProductionRequestVoJoin"/>
        <where>
            <if test="productionRequestCode != null  and productionRequestCode != ''"> and production_request_code = #{productionRequestCode}</if>
            <if test="routeId != null "> and route_id = #{routeId}</if>
            <if test="itemId != null "> and item_id = #{itemId}</if>
            <if test="factoryId != null "> and factory_id = #{factoryId}</if>
            <if test="warehouse != null  and warehouse != ''"> and warehouse = #{warehouse}</if>
            <if test="sizeGroup != null  and sizeGroup != ''"> and size_group = #{sizeGroup}</if>
            <if test="isNeedShoeImg != null "> and is_need_shoe_img = #{isNeedShoeImg}</if>
            <if test="isNeedPrototype != null "> and is_need_prototype = #{isNeedPrototype}</if>
            <if test="isUniqueCode != null "> and is_unique_code = #{isUniqueCode}</if>
            <if test="isConsiderColor != null "> and is_consider_color = #{isConsiderColor}</if>
            <if test="isDisabled != null "> and is_disabled = #{isDisabled}</if>
            <if test="shoeImg != null  and shoeImg != ''"> and shoe_img = #{shoeImg}</if>
            <if test="prototype != null  and prototype != ''"> and prototype = #{prototype}</if>
            <if test="productionRequestStatus != null "> and production_request_status = #{productionRequestStatus}</if>
        </where>
    </select>

    <select id="selectProProductionRequestByProductionRequestId" parameterType="Long" resultMap="ProProductionRequestResult">
        <include refid="selectProProductionRequestVoJoin"/>
        where production_request_id = #{productionRequestId}
    </select>

    <insert id="insertProProductionRequest" parameterType="ProProductionRequest" useGeneratedKeys="true" keyProperty="productionRequestId">
        insert into pro_production_request
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productionRequestCode != null">production_request_code,</if>
            <if test="routeId != null">route_id,</if>
            <if test="itemId != null">item_id,</if>
            <if test="factoryId != null">factory_id,</if>
            <if test="warehouse != null">warehouse,</if>
            <if test="sizeGroup != null">size_group,</if>
            <if test="isNeedShoeImg != null">is_need_shoe_img,</if>
            <if test="isNeedPrototype != null">is_need_prototype,</if>
            <if test="isUniqueCode != null">is_unique_code,</if>
            <if test="isConsiderColor != null">is_consider_color,</if>
            <if test="isDisabled != null">is_disabled,</if>
            <if test="shoeImg != null">shoe_img,</if>
            <if test="prototype != null">prototype,</if>
            <if test="productionRequestStatus != null">production_request_status,</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>
            <if test="length != null">length,</if>
            <if test="width != null">width,</if>
            <if test="height != null">height,</if>
            <if test="thick != null">thick,</if>
            <if test="weight != null">weight,</if>
            <if test="angleType != null">angle_type,</if>
            <if test="isAllotype != null">is_allotype,</if>
            <if test="isRightAngle != null">is_right_angle,</if>
            <if test="fillet != null">fillet,</if>
            <if test="angle != null">angle,</if>
            <if test="aperture != null">aperture,</if>
            <if test="singleLayerThick != null">single_layer_thick,</if>
            <if test="singleWeight != null">single_weight,</if>
            <if test="layerNum != null">layer_num,</if>
            <if test="isMould != null">is_mould,</if>
            <if test="isCoding != null">is_coding,</if>
            <if test="certification != null">certification,</if>
            <if test="shape != null">shape,</if>
            <if test="shapeSize != null">shape_size,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productionRequestCode != null">#{productionRequestCode},</if>
            <if test="routeId != null">#{routeId},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="factoryId != null">#{factoryId},</if>
            <if test="warehouse != null">#{warehouse},</if>
            <if test="sizeGroup != null">#{sizeGroup},</if>
            <if test="isNeedShoeImg != null">#{isNeedShoeImg},</if>
            <if test="isNeedPrototype != null">#{isNeedPrototype},</if>
            <if test="isUniqueCode != null">#{isUniqueCode},</if>
            <if test="isConsiderColor != null">#{isConsiderColor},</if>
            <if test="isDisabled != null">#{isDisabled},</if>
            <if test="shoeImg != null">#{shoeImg},</if>
            <if test="prototype != null">#{prototype},</if>
            <if test="productionRequestStatus != null">#{productionRequestStatus},</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>
            <if test="length != null">#{length},</if>
            <if test="width != null">#{width},</if>
            <if test="height != null">#{height},</if>
            <if test="thick != null">#{thick},</if>
            <if test="weight != null">#{weight},</if>
            <if test="angleType != null">#{angleType},</if>
            <if test="isAllotype != null">#{isAllotype},</if>
            <if test="isRightAngle != null">#{isRightAngle},</if>
            <if test="fillet != null">#{fillet},</if>
            <if test="angle != null">#{angle},</if>
            <if test="aperture != null">#{aperture},</if>
            <if test="singleLayerThick != null">#{singleLayerThick},</if>
            <if test="singleWeight != null">#{singleWeight},</if>
            <if test="layerNum != null">#{layerNum},</if>
            <if test="isMould != null">#{isMould},</if>
            <if test="isCoding != null">#{isCoding},</if>
            <if test="certification != null">#{certification},</if>
            <if test="shape != null">#{shape},</if>
            <if test="shapeSize != null">#{shapeSize},</if>
        </trim>
    </insert>

    <update id="updateProProductionRequest" parameterType="ProProductionRequest">
        update pro_production_request
        <trim prefix="SET" suffixOverrides=",">
            <if test="productionRequestCode != null">production_request_code = #{productionRequestCode},</if>
            <if test="routeId != null">route_id = #{routeId},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="factoryId != null">factory_id = #{factoryId},</if>
            <if test="warehouse != null">warehouse = #{warehouse},</if>
            <if test="sizeGroup != null">size_group = #{sizeGroup},</if>
            <if test="isNeedShoeImg != null">is_need_shoe_img = #{isNeedShoeImg},</if>
            <if test="isNeedPrototype != null">is_need_prototype = #{isNeedPrototype},</if>
            <if test="isUniqueCode != null">is_unique_code = #{isUniqueCode},</if>
            <if test="isConsiderColor != null">is_consider_color = #{isConsiderColor},</if>
            <if test="isDisabled != null">is_disabled = #{isDisabled},</if>
            shoe_img = #{shoeImg},
            <if test="prototype != null">prototype = #{prototype},</if>
            <if test="productionRequestStatus != null">production_request_status = #{productionRequestStatus},</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>
            <if test="length != null">length = #{length},</if>
            <if test="width != null">width = #{width},</if>
            <if test="height != null">height = #{height},</if>
            <if test="thick != null">thick = #{thick},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="angleType != null">angle_type = #{angleType},</if>
            <if test="isAllotype != null">is_allotype = #{isAllotype},</if>
            <if test="isRightAngle != null">is_right_angle = #{isRightAngle},</if>
            <if test="fillet != null">fillet = #{fillet},</if>
            <if test="angle != null">angle = #{angle},</if>
            <if test="aperture != null">aperture = #{aperture},</if>
            <if test="singleLayerThick != null">single_layer_thick = #{singleLayerThick},</if>
            <if test="singleWeight != null">single_weight = #{singleWeight},</if>
            <if test="layerNum != null">layer_num = #{layerNum},</if>
            <if test="isMould != null">is_mould = #{isMould},</if>
            <if test="isCoding != null">is_coding = #{isCoding},</if>
            <if test="certification != null">certification = #{certification},</if>
            <if test="shape != null">shape = #{shape},</if>
            <if test="shapeSize != null">shape_size = #{shapeSize},</if>
        </trim>
        where production_request_id = #{productionRequestId}
    </update>

    <delete id="deleteProProductionRequestByProductionRequestId" parameterType="Long">
        delete from pro_production_request where production_request_id = #{productionRequestId}
    </delete>

    <delete id="deleteProProductionRequestByProductionRequestIds" parameterType="String">
        delete from pro_production_request where production_request_id in
        <foreach item="productionRequestId" collection="array" open="(" separator="," close=")">
            #{productionRequestId}
        </foreach>
    </delete>

    <update id="updateProProductionRequestStatus">
        update pro_production_request
        set production_request_status = #{productionRequestStatus}
        where production_request_id = #{productionRequestId}
    </update>
</mapper>
