<?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.productionMake.ProProductionMakeMapper">

    <resultMap type="ProProductionMakeVo" id="ProProductionMakeResult">
        <result property="productionMakeId"    column="production_make_id"    />
        <result property="productionMakeCode"    column="production_make_code"    />
        <result property="productionRequestId"    column="production_request_id"    />
        <result property="prototypeMakeCode"    column="prototype_make_code"    />
        <result property="itemId"    column="item_id"    />
        <result property="itemCode"    column="item_code"    />
        <result property="itemName" column="item_name"/>
        <result property="itemNameEn" column="item_name_en"/>
        <result property="productTypeName"    column="product_type_name"    />
        <result property="routeId"    column="route_id"    />
        <result property="routeName"    column="route_name"    />
        <result property="purchaseUnit"    column="purchase_unit"    />
        <result property="unit"    column="unit"    />
        <result property="conversionValue"    column="conversion_value"    />
        <result property="brandId"    column="brand_id"    />
        <result property="brandName"    column="brand_name"    />
        <result property="length"    column="length"    />
        <result property="singleLayerThick"    column="single_layer_thick"    />
        <result property="layerNum"    column="layer_num"    />
        <result property="singleWeight"    column="single_weight"    />
        <result property="width"    column="width"    />
        <result property="height"    column="height"    />
        <result property="printingPaperlenth"    column="printing_paperlenth"    />
        <result property="printPaperwidth"    column="print_paperwidth"    />
        <result property="storePlace"    column="store_place"    />
        <result property="sizeGroupId"    column="size_group_id"    />
        <result property="sizeGroupName"    column="size_group_name"    />
        <result property="sendworkMultiple"    column="sendwork_multiple"    />
        <result property="rowNum"    column="row_num"    />
        <result property="isDisable"    column="is_disable"    />
        <result property="isCreateSpec"    column="is_create_spec"    />
        <result property="isNeedShoeImg"    column="is_need_shoe_img"    />
        <result property="isAddSimple"    column="is_add_simple"    />
        <result property="isUniqueCode"    column="is_unique_code"    />
        <result property="isConsiderColor"    column="is_consider_color"    />
        <result property="productMaterial"    column="product_material"    />
        <result property="identifyingPeople"    column="identifying_people"    />
        <result property="identifyingDate"    column="identifying_date"    />
        <result property="printingFrontcolor"    column="printing_frontcolor"    />
        <result property="printingFrontcolorName"    column="printing_frontcolor_name"    />
        <result property="printingBackcolor"    column="printing_backcolor"    />
        <result property="printingBackcolorName"    column="printing_backcolor_name"    />
        <result property="frontImg"    column="front_img"    />
        <result property="backImg"    column="back_img"    />
        <result property="productionMakeStatus"    column="production_make_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"    />
    </resultMap>

    <sql id="selectProProductionMakeVo">
        select t1.*,
               pr.route_name,
               mi.item_name,
               mi.item_code,
               mi.unit_of_measure as unit,
               mbi.product_english_name as item_name_en,
               mi.item_type_name as product_type_name,
               mb.brand_name,
               msg.size_group_name,
               mc1.color_name as printing_frontcolor_name,
               mc2.color_name as printing_backcolor_name
         from pro_production_make t1
         left join md_item mi on t1.item_id = mi.item_id
         left join md_base_info mbi on mbi.item_id = mi.item_id
         left join pro_route pr on t1.route_id = pr.route_id
         left join md_brand mb on mb.brand_id = t1.brand_id
         left join md_size_group msg on msg.size_group_id = t1.size_group_id
         left join md_color mc1 on mc1.color_id = t1.printing_frontcolor
         left join md_color mc2 on mc2.color_id = t1.printing_backcolor
    </sql>

    <select id="selectProProductionMakeList" parameterType="ProProductionMakeVo" resultMap="ProProductionMakeResult">
        <include refid="selectProProductionMakeVo"/>
        <where>
            <if test="productionMakeCode != null  and productionMakeCode != ''"> and production_make_code = #{productionMakeCode}</if>
            <if test="productionRequestId != null "> and production_request_id = #{productionRequestId}</if>
            <if test="itemId != null "> and item_id = #{itemId}</if>
            <if test="routeId != null "> and route_id = #{routeId}</if>
            <if test="identifyingPeople != null  and identifyingPeople != ''"> and identifying_people = #{identifyingPeople}</if>
            <if test="identifyingDate != null "> and identifying_date = #{identifyingDate}</if>
            <if test="printingFrontcolor != null  and printingFrontcolor != ''"> and printing_frontcolor = #{printingFrontcolor}</if>
            <if test="printingBackcolor != null  and printingBackcolor != ''"> and printing_backcolor = #{printingBackcolor}</if>
            <if test="frontImg != null  and frontImg != ''"> and front_img = #{frontImg}</if>
            <if test="backImg != null  and backImg != ''"> and back_img = #{backImg}</if>
            <if test="productionMakeStatus != null "> and production_make_status = #{productionMakeStatus}</if>
        </where>
    </select>

    <select id="selectProProductionMakeByProductionMakeId" parameterType="Long" resultMap="ProProductionMakeResult">
        <include refid="selectProProductionMakeVo"/>
        where production_make_id = #{productionMakeId}
    </select>

    <insert id="insertProProductionMake" parameterType="ProProductionMakeVo" useGeneratedKeys="true" keyProperty="productionMakeId">
        insert into pro_production_make
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productionMakeCode != null and productionMakeCode != ''">production_make_code,</if>
            <if test="productionRequestId != null">production_request_id,</if>
            <if test="itemId != null">item_id,</if>
            <if test="routeId != null">route_id,</if>
            <if test="identifyingPeople != null">identifying_people,</if>
            <if test="identifyingDate != null">identifying_date,</if>
            <if test="printingFrontcolor != null">printing_frontcolor,</if>
            <if test="printingBackcolor != null">printing_backcolor,</if>
            <if test="frontImg != null">front_img,</if>
            <if test="backImg != null">back_img,</if>
            <if test="productionMakeStatus != null">production_make_status,</if>
            <if test="prototypeMakeCode != null">prototype_make_code,</if>
            <if test="purchaseUnit != null">purchase_unit,</if>
            <if test="conversionValue != null">conversion_value,</if>
            <if test="brandId != null">brand_id,</if>
            <if test="length != null">length,</if>
            <if test="singleLayerThick != null">single_layer_thick,</if>
            <if test="layerNum != null">layer_num,</if>
            <if test="singleWeight != null">single_weight,</if>
            <if test="width != null">width,</if>
            <if test="height != null">height,</if>
            <if test="printingPaperlenth != null">printing_paperlenth,</if>
            <if test="printPaperwidth != null">print_paperwidth,</if>
            <if test="storePlace != null">store_place,</if>
            <if test="sizeGroupId != null">size_group_id,</if>
            <if test="sendworkMultiple != null">sendwork_multiple,</if>
            <if test="rowNum != null">row_num,</if>
            <if test="isDisable != null">is_disable,</if>
            <if test="isCreateSpec != null">is_create_spec,</if>
            <if test="isNeedShoeImg != null">is_need_shoe_img,</if>
            <if test="isAddSimple != null">is_add_simple,</if>
            <if test="isUniqueCode != null">is_unique_code,</if>
            <if test="isConsiderColor != null">is_consider_color,</if>
            <if test="productMaterial != null">product_material,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productionMakeCode != null and productionMakeCode != ''">#{productionMakeCode},</if>
            <if test="productionRequestId != null">#{productionRequestId},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="routeId != null">#{routeId},</if>
            <if test="identifyingPeople != null">#{identifyingPeople},</if>
            <if test="identifyingDate != null">#{identifyingDate},</if>
            <if test="printingFrontcolor != null">#{printingFrontcolor},</if>
            <if test="printingBackcolor != null">#{printingBackcolor},</if>
            <if test="frontImg != null">#{frontImg},</if>
            <if test="backImg != null">#{backImg},</if>
            <if test="productionMakeStatus != null">#{productionMakeStatus},</if>
            <if test="prototypeMakeCode != null">#{prototypeMakeCode},</if>
            <if test="purchaseUnit != null">#{purchaseUnit},</if>
            <if test="conversionValue != null">#{conversionValue},</if>
            <if test="brandId != null">#{brandId},</if>
            <if test="length != null">#{length},</if>
            <if test="singleLayerThick != null">#{singleLayerThick},</if>
            <if test="layerNum != null">#{layerNum},</if>
            <if test="singleWeight != null">#{singleWeight},</if>
            <if test="width != null">#{width},</if>
            <if test="height != null">#{height},</if>
            <if test="printingPaperlenth != null">#{printingPaperlenth},</if>
            <if test="printPaperwidth != null">#{printPaperwidth},</if>
            <if test="storePlace != null">#{storePlace},</if>
            <if test="sizeGroupId != null">#{sizeGroupId},</if>
            <if test="sendworkMultiple != null">#{sendworkMultiple},</if>
            <if test="rowNum != null">#{rowNum},</if>
            <if test="isDisable != null">#{isDisable},</if>
            <if test="isCreateSpec != null">#{isCreateSpec},</if>
            <if test="isNeedShoeImg != null">#{isNeedShoeImg},</if>
            <if test="isAddSimple != null">#{isAddSimple},</if>
            <if test="isUniqueCode != null">#{isUniqueCode},</if>
            <if test="isConsiderColor != null">#{isConsiderColor},</if>
            <if test="productMaterial != null">#{productMaterial},</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>
         </trim>
    </insert>

    <update id="updateProProductionMake" parameterType="ProProductionMakeVo">
        update pro_production_make
        <trim prefix="SET" suffixOverrides=",">
            <if test="productionMakeCode != null and productionMakeCode != ''">production_make_code = #{productionMakeCode},</if>
            <if test="productionRequestId != null">production_request_id = #{productionRequestId},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="routeId != null">route_id = #{routeId},</if>
            <if test="identifyingPeople != null">identifying_people = #{identifyingPeople},</if>
            <if test="identifyingDate != null">identifying_date = #{identifyingDate},</if>
            <if test="printingFrontcolor != null">printing_frontcolor = #{printingFrontcolor},</if>
            <if test="printingBackcolor != null">printing_backcolor = #{printingBackcolor},</if>
            front_img = #{frontImg},
            back_img = #{backImg},
            <if test="productionMakeStatus != null">production_make_status = #{productionMakeStatus},</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>
        </trim>
        where production_make_id = #{productionMakeId}
    </update>

    <delete id="deleteProProductionMakeByProductionMakeId" parameterType="Long">
        delete from pro_production_make where production_make_id = #{productionMakeId}
    </delete>

    <delete id="deleteProProductionMakeByProductionMakeIds" parameterType="String">
        delete from pro_production_make where production_make_id in
        <foreach item="productionMakeId" collection="array" open="(" separator="," close=")">
            #{productionMakeId}
        </foreach>
    </delete>

    <update id="updateProProductionMakeStatus">
        update pro_production_make
        set production_make_status = #{productionMakeStatus}
        where production_make_id = #{productionMakeId}
    </update>
</mapper>
