<?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.prototypeRequest.ProPrototypeRequestMapper">

    <resultMap type="ProPrototypeRequestVo" id="ProPrototypeRequestResult">
        <result property="prototypeRequestId" column="prototype_request_id"/>
        <result property="prototypeRequestCode" column="prototype_request_code"/>
        <result property="itemId" column="item_id"/>
        <result property="itemName" column="item_name"/>
        <result property="routeId" column="route_id"/>
        <result property="routeName" column="route_name"/>
        <result property="abbreviation" column="abbreviation"/>
        <result property="enName" column="en_name"/>
        <result property="num" column="num"/>
        <result property="type" column="type"/>
        <result property="modality" column="modality"/>
        <result property="surfaceTreatment" column="surface_treatment"/>
        <result property="ngReason" column="ng_reason"/>
        <result property="plannedFinishDate" column="planned_finish_date"/>
        <result property="plannedLayoutDate" column="planned_layout_date"/>
        <result property="prototypeRequestStatus" column="prototype_request_status"/>
        <result property="testStandard" column="test_standard"/>
        <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="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"    />
        <result property="frontImg"    column="front_img"    />
        <result property="backImg"    column="back_img"    />
        <result property="frontColorId" column="front_color_id"/>
        <result property="oppositeColorId" column="opposite_color_id"/>
        <result property="frontColorName" column="front_color_name"/>
        <result property="oppositeColorName" column="opposite_color_name"/>
    </resultMap>

    <sql id="selectProPrototypeRequestVo">
        select ppr.prototype_request_id,
               ppr.prototype_request_code,
               ppr.item_id,
               mi.item_name,
               ppr.route_id,
               pr.route_name,
               ppr.abbreviation,
               ppr.en_name,
               ppr.num,
               ppr.type,
               ppr.modality,
               ppr.surface_treatment,
               ppr.ng_reason,
               ppr.planned_finish_date,
               ppr.planned_layout_date,
               ppr.prototype_request_status,
               ppr.test_standard,
               ppr.remark,
               ppr.create_by,
               ppr.create_time,
               ppr.update_by,
               ppr.update_time,
               ppr.length,
               ppr.width,
               ppr.height,
               ppr.thick,
               ppr.weight,
               ppr.angle_type,
               ppr.is_allotype,
               ppr.is_right_angle,
               ppr.fillet,
               ppr.angle,
               ppr.aperture,
               ppr.single_layer_thick,
               ppr.single_weight,
               ppr.layer_num,
               ppr.is_mould,
               ppr.is_coding,
               ppr.certification,
               ppr.shape,
               ppr.shape_size,
               ppr.front_img,
               ppr.back_img,
               ppr.front_color_id,
               ppr.opposite_color_id,
               mc1.color_name as front_color_name,
               mc2.color_name as opposite_color_name
        from pro_prototype_request ppr
                 left join md_item mi on ppr.item_id = mi.item_id
                 left join pro_route pr on ppr.route_id = pr.route_id
                 left join md_color mc1 on ppr.front_color_id = mc1.color_id
                 left join md_color mc2 on ppr.opposite_color_id = mc2.color_id

    </sql>

    <select id="selectProPrototypeRequestList" parameterType="ProPrototypeRequest"
            resultMap="ProPrototypeRequestResult">
        <include refid="selectProPrototypeRequestVo"/>
        <where>
            <if test="prototypeRequestCode != null  and prototypeRequestCode != ''">and ppr.prototype_request_code =
                #{prototypeRequestCode}
            </if>
            <if test="itemId != null ">and ppr.item_id = #{itemId}</if>
            <if test="itemName != null ">and mi.item_name = #{itemName}</if>
            <if test="routeId != null ">and ppr.route_id = #{routeId}</if>
            <if test="routeName != null ">and pr.route_name = #{routeName}</if>
            <if test="itemName != null  and itemName != ''">and ppr.abbreviation like concat('%', #{itemName}, '%')</if>
            <if test="itemName != null  and itemName != ''">and ppr.en_name like concat('%', #{itemName}, '%')</if>
            <if test="num != null ">and ppr.num = #{num}</if>
            <if test="type != null  and type != ''">and ppr.type = #{type}</if>
            <if test="modality != null  and modality != ''">and ppr.modality = #{modality}</if>
            <if test="surfaceTreatment != null  and surfaceTreatment != ''">and ppr.surface_treatment =
                #{surfaceTreatment}
            </if>
            <if test="ngReason != null  and ngReason != ''">and ppr.ng_reason = #{ngReason}</if>
            <if test="plannedFinishDate != null ">and ppr.planned_finish_date = #{plannedFinishDate}</if>
            <if test="plannedLayoutDate != null ">and ppr.planned_layout_date = #{plannedLayoutDate}</if>
            <if test="prototypeRequestStatus != null ">and ppr.prototype_request_status =
                #{prototypeRequestStatus}
            </if>
            <if test="testStandard != null  and testStandard != ''">and ppr.test_standard = #{testStandard}</if>
        </where>
    </select>

    <select id="selectProPrototypeRequestByPrototypeRequestId" parameterType="Long"
            resultMap="ProPrototypeRequestResult">
        <include refid="selectProPrototypeRequestVo"/>
        where ppr.prototype_request_id = #{prototypeRequestId}
    </select>

    <insert id="insertProPrototypeRequest" parameterType="ProPrototypeRequest" useGeneratedKeys="true"
            keyProperty="prototypeRequestId">
        insert into pro_prototype_request
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prototypeRequestCode != null">prototype_request_code,</if>
            <if test="itemId != null">item_id,</if>
            <if test="routeId != null">route_id,</if>
            <if test="abbreviation != null">abbreviation,</if>
            <if test="enName != null">en_name,</if>
            <if test="num != null">num,</if>
            <if test="type != null">type,</if>
            <if test="modality != null">modality,</if>
            <if test="surfaceTreatment != null">surface_treatment,</if>
            <if test="ngReason != null">ng_reason,</if>
            <if test="plannedFinishDate != null">planned_finish_date,</if>
            <if test="plannedLayoutDate != null">planned_layout_date,</if>
            <if test="prototypeRequestStatus != null">prototype_request_status,</if>
            <if test="testStandard != null">test_standard,</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>
            <if test="frontImg != null">front_img,</if>
            <if test="backImg != null">back_img,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="prototypeRequestCode != null">#{prototypeRequestCode},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="routeId != null">#{routeId},</if>
            <if test="abbreviation != null">#{abbreviation},</if>
            <if test="enName != null">#{enName},</if>
            <if test="num != null">#{num},</if>
            <if test="type != null">#{type},</if>
            <if test="modality != null">#{modality},</if>
            <if test="surfaceTreatment != null">#{surfaceTreatment},</if>
            <if test="ngReason != null">#{ngReason},</if>
            <if test="plannedFinishDate != null">#{plannedFinishDate},</if>
            <if test="plannedLayoutDate != null">#{plannedLayoutDate},</if>
            <if test="prototypeRequestStatus != null">#{prototypeRequestStatus},</if>
            <if test="testStandard != null">#{testStandard},</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>
            <if test="frontImg != null">#{frontImg},</if>
            <if test="backImg != null">#{backImg},</if>
        </trim>
    </insert>

    <update id="updateProPrototypeRequest" parameterType="ProPrototypeRequest">
        update pro_prototype_request
        <trim prefix="SET" suffixOverrides=",">
            <if test="prototypeRequestCode != null">prototype_request_code = #{prototypeRequestCode},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="routeId != null">route_id = #{routeId},</if>
            <if test="abbreviation != null">abbreviation = #{abbreviation},</if>
            <if test="enName != null">en_name = #{enName},</if>
            <if test="num != null">num = #{num},</if>
            <if test="type != null">type = #{type},</if>
            <if test="modality != null">modality = #{modality},</if>
            <if test="surfaceTreatment != null">surface_treatment = #{surfaceTreatment},</if>
            <if test="ngReason != null">ng_reason = #{ngReason},</if>
            <if test="plannedFinishDate != null">planned_finish_date = #{plannedFinishDate},</if>
            <if test="plannedLayoutDate != null">planned_layout_date = #{plannedLayoutDate},</if>
            <if test="prototypeRequestStatus != null">prototype_request_status = #{prototypeRequestStatus},</if>
            <if test="testStandard != null">test_standard = #{testStandard},</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>
#             update_time = sysdate();
            <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>
            <if test="frontImg != null">front_img = #{frontImg},</if>
            <if test="backImg != null">back_img = #{backImg},</if>
        </trim>
        where prototype_request_id = #{prototypeRequestId}
    </update>
    <update id="updateProPrototypeRequestStatus">
        update pro_prototype_request
        set prototype_request_status = #{prototypeRequestStatus}
        where prototype_request_id = #{prototypeRequestId}
    </update>

    <delete id="deleteProPrototypeRequestByPrototypeRequestId" parameterType="Long">
        delete
        from pro_prototype_request
        where prototype_request_id = #{prototypeRequestId}
    </delete>

    <delete id="deleteProPrototypeRequestByPrototypeRequestIds" parameterType="String">
        delete from pro_prototype_request where prototype_request_id in
        <foreach item="prototypeRequestId" collection="array" open="(" separator="," close=")">
            #{prototypeRequestId}
        </foreach>
    </delete>
</mapper>
