<?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.dv.mapper.devBrandQuotation.DvBrandQuotationProcessMapper">

    <resultMap type="DvBrandQuotationProcessVo" id="DevBrandQuotationProcessResult">
        <result property="brandQuotationProcessId"    column="brand_quotation_process_id"    />
        <result property="brandQuotationId"    column="brand_quotation_id"    />
        <result property="recordId"    column="record_id"    />
        <result property="workstationId"    column="workstation_id"    />
        <result property="workstationName"    column="workstation_name"    />
        <result property="stdWorkingTime"    column="std_working_time"    />
        <result property="defaultPreTime"    column="default_pre_time"    />
        <result property="defaultSufTime"    column="default_suf_time"    />
        <result property="keyFlag"    column="key_flag"    />
        <result property="isCheck"    column="is_check"    />
        <result property="remark"    column="remark"    />
        <result property="linkType"    column="link_type"    />
        <result property="colorCode"    column="color_code"    />
        <result property="processName"    column="process_name"    />
        <result property="processCode"    column="process_code"    />
        <result property="processId"    column="process_id"    />
        <result property="nextProcessName"    column="next_process_name"    />
        <result property="orderNum"    column="order_num"    />
    </resultMap>

    <sql id="selectDevBrandQuotationProcessVo">
        select pprp.brand_quotation_process_id,
               pprp.brand_quotation_id,
               pprp.record_id,
               pprp.workstation_id,
               pprp.std_working_time,
               pprp.default_pre_time,
               pprp.default_suf_time,
               pprp.key_flag,
               pprp.is_check,
               pprp.remark,
               prp.link_type,
               prp.color_code,
               prp.process_name,
               prp.process_code,
               prp.process_id,
               prp.next_process_name,
               mw.workstation_name,
               prp.order_num

        from dev_brand_quotation_process pprp
                 left join pro_route_process prp on pprp.record_id = prp.record_id
                 left join md_workstation mw on pprp.workstation_id = mw.workstation_id
    </sql>

    <select id="selectDevBrandQuotationProcessList" parameterType="DvBrandQuotationProcess" resultMap="DevBrandQuotationProcessResult">
        <include refid="selectDevBrandQuotationProcessVo"/>
        <where>
            <if test="brandQuotationId != null "> and pprp.brand_quotation_id = #{brandQuotationId}</if>
            <if test="recordId != null "> and  pprp.record_id = #{recordId}</if>
            <if test="workstationId != null "> and pprp.workstation_id = #{workstationId}</if>
            <if test="stdWorkingTime != null "> and pprp.std_working_time = #{stdWorkingTime}</if>
            <if test="defaultPreTime != null "> and pprp.default_pre_time = #{defaultPreTime}</if>
            <if test="defaultSufTime != null "> and pprp.default_suf_time = #{defaultSufTime}</if>
            <if test="keyFlag != null  and keyFlag != ''"> and pprp.key_flag = #{keyFlag}</if>
            <if test="isCheck != null  and isCheck != ''"> and pprp.is_check = #{isCheck}</if>
        </where>
    </select>

    <select id="selectDevBrandQuotationProcessByBrandQuotationProcessId" parameterType="Long" resultMap="DevBrandQuotationProcessResult">
        <include refid="selectDevBrandQuotationProcessVo"/>
        where pprp.brand_quotation_process_id = #{brandQuotationProcessId}
    </select>



    <select id="selectDvBrandQuotationProcessBybrandQuotationId"
            parameterType="Long" resultMap="DevBrandQuotationProcessResult">
        <include refid="selectDevBrandQuotationProcessVo"/>
        where  pprp.brand_quotation_id = #{brandQuotationId}
    </select>


    <insert id="insertDevBrandQuotationProcess" parameterType="DvBrandQuotationProcess" useGeneratedKeys="true" keyProperty="brandQuotationProcessId">
        insert into dev_brand_quotation_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brandQuotationId != null">brand_quotation_id,</if>
            <if test="recordId != null">record_id,</if>
            <if test="workstationId != null">workstation_id,</if>
            <if test="stdWorkingTime != null">std_working_time,</if>
            <if test="defaultPreTime != null">default_pre_time,</if>
            <if test="defaultSufTime != null">default_suf_time,</if>
            <if test="keyFlag != null">key_flag,</if>
            <if test="isCheck != null">is_check,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brandQuotationId != null">#{brandQuotationId},</if>
            <if test="recordId != null">#{recordId},</if>
            <if test="workstationId != null">#{workstationId},</if>
            <if test="stdWorkingTime != null">#{stdWorkingTime},</if>
            <if test="defaultPreTime != null">#{defaultPreTime},</if>
            <if test="defaultSufTime != null">#{defaultSufTime},</if>
            <if test="keyFlag != null">#{keyFlag},</if>
            <if test="isCheck != null">#{isCheck},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateDevBrandQuotationProcess" parameterType="DvBrandQuotationProcess">
        update dev_brand_quotation_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="brandQuotationId != null">brand_quotation_id = #{brandQuotationId},</if>
            <if test="recordId != null">record_id = #{recordId},</if>
            <if test="workstationId != null">workstation_id = #{workstationId},</if>
            <if test="stdWorkingTime != null">std_working_time = #{stdWorkingTime},</if>
            <if test="defaultPreTime != null">default_pre_time = #{defaultPreTime},</if>
            <if test="defaultSufTime != null">default_suf_time = #{defaultSufTime},</if>
            <if test="keyFlag != null">key_flag = #{keyFlag},</if>
            <if test="isCheck != null">is_check = #{isCheck},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where brand_quotation_process_id = #{brandQuotationProcessId}
    </update>

    <delete id="deleteDevBrandQuotationProcessByBrandQuotationProcessId" parameterType="Long">
        delete from dev_brand_quotation_process where brand_quotation_process_id = #{brandQuotationProcessId}
    </delete>

    <delete id="deleteDevBrandQuotationProcessByBrandQuotationProcessIds" parameterType="String">
        delete from dev_brand_quotation_process where brand_quotation_process_id in
        <foreach item="brandQuotationProcessId" collection="array" open="(" separator="," close=")">
            #{brandQuotationProcessId}
        </foreach>
    </delete>
</mapper>
