<?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.ruoyi.quot.mapper.QuotMapper">

    <resultMap type="Quot" id="QuotResult">
        <result property="quotId"    column="quot_id"    />
        <result property="quotCode"    column="quot_code"    />
        <result property="quotJswCode"    column="quot_jsw_code"    />
        <result property="quotSalesmanCode"    column="quot_salesman_code"    />
        <result property="quotSalesmanBm"    column="quot_salesman_bm"    />
        <result property="quotSalesmanName"    column="quot_salesman_name"    />
        <result property="quotCustomerBm"    column="quot_customer_bm"    />
        <result property="quotCustomerName"    column="quot_customer_name"    />
        <result property="quotSalesmanDeptId"    column="quot_salesman_dept_id"    />
        <result property="quotSalesmanDeptName"    column="quot_salesman_dept_name"    />
        <result property="quotAddress"    column="quot_address"    />
        <result property="quotContacts"    column="quot_contacts"    />
        <result property="quotPhone"    column="quot_phone"    />
        <result property="quotInquiryDate"    column="quot_inquiry_date"    />
        <result property="quotProject"    column="quot_project"    />
        <result property="quotQuotationDate"    column="quot_quotation_date"    />
        <result property="quotQuotationFrom"    column="quot_quotation_from"    />
        <result property="quotQuotationRequire"    column="quot_quotation_require"    />
        <result property="quotFeedbackExplanation"    column="quot_feedback_explanation"    />
        <result property="quotQuantity"    column="quot_quantity"    />
        <result property="quotTotalPrice"    column="quot_total_price"    />
        <result property="quotCheckUserName"    column="quot_check_user_name"    />
        <result property="quotCheckUserNickname"    column="quot_check_user_nickname"    />
        <result property="quotApprovalStatus"    column="quot_approval_status"    />
        <result property="quotMaterialsCount"    column="quot_materials_count"    />
        <result property="quotLvPrice"    column="quot_lv_price"    />
        <result property="quotTongPrice"    column="quot_tong_price"    />
        <result property="quotMatpriceDiff"    column="quot_matprice_diff"    />
        <result property="quotPrint"    column="quot_print"    />
        <result property="quotPrintUserName"    column="quot_print_user_name"    />
        <result property="createBy"    column="create_by"    />
        <result property="createName"     column="create_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />

        <result property="quotJsxzStandard"    column="quot_jsxz_standard"    />
        <result property="quotJsxzApprovalStatus"    column="quot_jsxz_approval_status"    />
        <result property="quotJsxzChapter"    column="quot_jsxz_chapter"    />
        <result property="quotJsxzTechnicalRequirement"    column="quot_jsxz_technical_requirement"    />
        <result property="quotJsxzGroupValues"    column="quot_jsxz_group_values"    />
        <result property="quotJsxzConfirmId"    column="quot_jsxz_confirm_id"    />
        <result property="quotJsxzConfirmCode"    column="quot_jsxz_confirm_code"    />

        <result property="quotJsqrTlApprovalStatus"    column="quot_jsqr_tl_approval_status"    />
        <result property="quotJsqrTlRemark"    column="quot_jsqr_tl_remark"    />
        <result property="quotJsqrDyApprovalStatus"    column="quot_jsqr_dy_approval_status"    />
        <result property="quotJsqrDyRemark"    column="quot_jsqr_dy_remark"    />
        <result property="quotJsqrZyApprovalStatus"    column="quot_jsqr_zy_approval_status"    />
        <result property="quotJsqrZyRemark"    column="quot_jsqr_zy_remark"    />
        <result property="quotJsqrQtApprovalStatus"    column="quot_jsqr_qt_approval_status"    />
        <result property="quotJsqrQtRemark"    column="quot_jsqr_qt_remark"    />

        <result property="quotHjId"    column="quot_hj_id"    />
        <result property="quotHjCode"    column="quot_hj_code"    />
        <result property="quotHjApprovalStatus"    column="quot_hj_approval_status"    />
        <result property="quotHjPricingDate"    column="quot_hj_pricing_date"    />
        <result property="quotHjRemark"    column="quot_hj_remark"    />

        <result property="quotJswApprovalStatus"    column="quot_jsw_approval_status"    />
        <result property="quotOAApprovalStatus"    column="quot_oa_approval_status"    />
        <result property="quotOAApprovalStatusRemark"    column="quot_oa_approval_remark"    />

    </resultMap>

    <resultMap id="QuotQuotMaterialResult" type="Quot" extends="QuotResult">
        <collection property="quotMaterialList" notNullColumn="sub_mat_id" javaType="java.util.List" resultMap="QuotMaterialResult" />
    </resultMap>

    <resultMap type="QuotMaterial" id="QuotMaterialResult">
        <result property="matId"    column="sub_mat_id"    />
        <result property="matXingh"    column="sub_mat_xingh"    />
        <result property="matGuig"    column="sub_mat_guig"    />
        <result property="matDiany"    column="sub_mat_diany"    />
        <result property="matStandard"    column="sub_mat_standard"    />
        <result property="matDanw"    column="sub_mat_danw"    />
        <result property="matSl"    column="sub_mat_sl"    />
        <result property="matRemark"    column="sub_mat_remark"    />

        <result property="matMatprice"    column="sub_mat_matprice"    />
        <result property="matPrice"    column="sub_mat_price"    />
        <result property="matQuotPrice"    column="sub_mat_quot_price"    />
        <result property="matQuotTp"    column="sub_mat_quot_tp"  />
        <result property="matQuotAllPrice"    column="sub_mat_quot_allPrice"    />
        <result property="matMatpriceDiff"    column="sub_mat_matprice_diff"    />
        <result property="xh"    column="sub_xh"    />
        <result property="index"    column="sub_number"    />

        <result property="quotId"    column="sub_quot_id"    />
    </resultMap>

    <sql id="quotJoins">
        left join sys_user u on u.user_name=a.create_by
        left join sys_user u2 on u2.user_name=a.quot_check_user_name
        left join sys_user u3 on u3.user_name=a.quot_print_user_name
        left join sys_dept d on u.dept_id = d.dept_id
        left join quot_jsqr q on q.quot_jsqr_id = a.quot_jsxz_confirm_id
        left join quot_hj h on h.quot_hj_id = a.quot_hj_id
    </sql>

    <sql id="selectQuotVo">
        select a.quot_id, a.quot_code,a.quot_jsw_code, a.quot_salesman_code, a.quot_salesman_bm, a.quot_salesman_name, a.quot_customer_bm,
               a.quot_customer_name,a.quot_salesman_dept_id, a.quot_salesman_dept_name, a.quot_address, a.quot_contacts,
               a.quot_phone, a.quot_inquiry_date, a.quot_project, a.quot_quotation_date, a.quot_quotation_from,
               a.quot_quotation_require, a.quot_feedback_explanation, a.quot_quantity, a.quot_total_price,
               a.quot_check_user_name, u2.nick_name quot_check_user_nickname, a.quot_approval_status,a.quot_materials_count,
               a.quot_lv_price,a.quot_tong_price,a.quot_matprice_diff,a.quot_print,u3.nick_name quot_print_user_name,
               a.create_by, a.create_time, a.update_by, a.update_time, u.nick_name create_name,

                a.quot_jsxz_standard,a.quot_jsxz_approval_status,a.quot_jsxz_chapter,
                a.quot_jsxz_technical_requirement,a.quot_jsxz_group_values,a.quot_jsxz_confirm_id,
                q.quot_jsqr_code quot_jsxz_confirm_code,
                q.quot_jsqr_tl_approval_status,q.quot_jsqr_tl_remark,
                q.quot_jsqr_dy_approval_status,q.quot_jsqr_dy_remark,
                q.quot_jsqr_zy_approval_status,q.quot_jsqr_zy_remark,
                q.quot_jsqr_qt_approval_status,q.quot_jsqr_qt_remark,

               a.quot_hj_id,a.quot_hj_approval_status,
               h.quot_hj_code,h.quot_hj_pricing_date,
               h.quot_hj_remark,

               a.quot_jsw_approval_status,a.quot_oa_approval_status,a.quot_oa_approval_remark

        from quot a
        <include refid="quotJoins"/>
    </sql>

    <select id="selectQuotList" parameterType="Quot" resultMap="QuotResult">
        <include refid="selectQuotVo"/>
        <where>
            <if test="quotCode != null  and quotCode != ''"> and quot_code like concat('%', #{quotCode}, '%')</if>
            <if test="quotCustomerName != null  and quotCustomerName != ''"> and quot_customer_name like concat('%', #{quotCustomerName}, '%')</if>
            <if test="quotProject != null  and quotProject != ''"> and quot_project like concat('%', #{quotProject}, '%')</if>
            <if test="quotSalesmanName != null  and quotSalesmanName != ''"> and quot_salesman_name like concat('%', #{quotSalesmanName}, '%')</if>
            <if test="quotPrint != null  and quotPrint != ''"> and quot_print = #{quotPrint}</if>
            <if test="quotApprovalStatus != null  and quotApprovalStatus != ''"> and quot_approval_status = #{quotApprovalStatus}</if>
            <!-- 数据范围过滤 -->
            ${params.dataScope}
        </where>
        order by a.quot_inquiry_date desc
    </select>

    <select id="selectQuotListCount" resultType="String">
        select count(1) from quot where quot_approval_status in ('1','2') and CONVERT(DATE, quot_inquiry_date) = CONVERT(DATE, GETDATE())
    </select>

    <select id="selectQuotByQuotId" parameterType="String" resultMap="QuotQuotMaterialResult">
        select a.quot_id, a.quot_code,a.quot_jsw_code, a.quot_salesman_code, a.quot_salesman_bm, a.quot_salesman_name, a.quot_customer_bm,a.quot_customer_name,
               a.quot_salesman_dept_id, a.quot_salesman_dept_name, a.quot_address, a.quot_contacts, a.quot_phone, a.quot_inquiry_date,
               a.quot_project, a.quot_quotation_date, a.quot_quotation_from, a.quot_quotation_require, a.quot_feedback_explanation,
               a.quot_quantity, a.quot_total_price, a.quot_check_user_name, u2.nick_name quot_check_user_nickname, a.quot_approval_status,
                a.quot_materials_count,a.quot_lv_price,a.quot_tong_price,a.quot_matprice_diff,a.quot_print,u3.nick_name quot_print_user_name,
               a.create_by, a.create_time, a.update_by, a.update_time,

                a.quot_jsxz_standard,a.quot_jsxz_approval_status,a.quot_jsxz_chapter,
                a.quot_jsxz_technical_requirement,a.quot_jsxz_group_values,a.quot_jsxz_confirm_id,
                q.quot_jsqr_code quot_jsxz_confirm_code,
                q.quot_jsqr_tl_approval_status,q.quot_jsqr_tl_remark,
                q.quot_jsqr_dy_approval_status,q.quot_jsqr_dy_remark,
                q.quot_jsqr_zy_approval_status,q.quot_jsqr_zy_remark,
                q.quot_jsqr_qt_approval_status,q.quot_jsqr_qt_remark,

                a.quot_hj_id,a.quot_hj_approval_status,
                h.quot_hj_code,h.quot_hj_pricing_date,
                h.quot_hj_remark,

                a.quot_jsw_approval_status,a.quot_oa_approval_status,a.quot_oa_approval_remark,

                b.mat_id as sub_mat_id, b.mat_xingh as sub_mat_xingh, b.mat_guig as sub_mat_guig,
                b.mat_diany as sub_mat_diany, b.mat_standard as sub_mat_standard, b.mat_danw as sub_mat_danw, b.mat_sl as sub_mat_sl,
                b.mat_remark as sub_mat_remark,
                b.mat_matprice as sub_mat_matprice,
                b.mat_price as sub_mat_price,
                b.mat_quot_price as sub_mat_quot_price,

                b.mat_quot_tp as sub_mat_quot_tp,
                b.mat_quot_allPrice as sub_mat_quot_allPrice,
                b.mat_matprice_diff as sub_mat_matprice_diff,

                b.xh as sub_xh,
                b.number as sub_number,

                b.quot_id as sub_quot_id
        from quot a
        left join quot_material b on b.quot_id = a.quot_id
        <include refid="quotJoins"/>
        where a.quot_id = #{quotId}
        order by b.number
    </select>

    <select id="selectQuotByQuotCode">
        select quot_id from quot where quot_code = #{quotCode}
    </select>


    <select id="checkExistQuot" parameterType="String" resultType="String">
        select count(1) from quot where quot_salesman_code != #{quotSalesmanCode}
        and quot_customer_bm = #{quotCustomerBm} and quot_project = #{quotProject}
        and quot_approval_status in ('1','2')
    </select>

    <insert id="insertQuot" parameterType="Quot">
        insert into quot
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="quotId != null and quotId != ''">quot_id,</if>
            <if test="quotCode != null and quotCode != ''">quot_code,</if>
            <if test="quotJswCode != null and quotJswCode != ''">quot_jsw_code,</if>
            <if test="quotSalesmanCode != null and quotSalesmanCode != ''">quot_salesman_code,</if>
            <if test="quotSalesmanBm != null and quotSalesmanBm != ''">quot_salesman_bm,</if>
            <if test="quotSalesmanName != null and quotSalesmanName != ''">quot_salesman_name,</if>
            <if test="quotCustomerBm != null and quotCustomerBm != ''">quot_customer_bm,</if>
            <if test="quotCustomerName != null and quotCustomerName != ''">quot_customer_name,</if>
            <if test="quotSalesmanDeptId != null and quotSalesmanDeptId != ''">quot_salesman_dept_id,</if>
            <if test="quotSalesmanDeptName != null and quotSalesmanDeptName != ''">quot_salesman_dept_name,</if>
            <if test="quotAddress != null and quotAddress != ''">quot_address,</if>
            <if test="quotContacts != null and quotContacts != ''">quot_contacts,</if>
            <if test="quotPhone != null and quotPhone != ''">quot_phone,</if>
            <if test="quotInquiryDate != null">quot_inquiry_date,</if>
            <if test="quotProject != null and quotProject != ''">quot_project,</if>
            <if test="quotQuotationDate != null">quot_quotation_date,</if>
            <if test="quotQuotationFrom != null and quotQuotationFrom != ''">quot_quotation_from,</if>
            <if test="quotQuotationRequire != null and quotQuotationRequire != ''">quot_quotation_require,</if>
            <if test="quotFeedbackExplanation != null and quotFeedbackExplanation != ''">quot_feedback_explanation,</if>
            <if test="quotQuantity != null and quotQuantity != ''">quot_quantity,</if>
            <if test="quotTotalPrice != null and quotTotalPrice != ''">quot_total_price,</if>
            <if test="quotCheckUserName != null and quotCheckUserName != ''">quot_check_user_name,</if>
            <if test="quotApprovalStatus != null and quotApprovalStatus != ''">quot_approval_status,</if>
            <if test="quotMaterialsCount != null and quotMaterialsCount != ''">quot_materials_count,</if>
            <if test="quotLvPrice != null and quotLvPrice != ''">quot_lv_price,</if>
            <if test="quotTongPrice != null and quotTongPrice != ''">quot_tong_price,</if>
            <if test="quotMatpriceDiff != null and quotMatpriceDiff != ''">quot_matprice_diff,</if>
            <if test="quotPrint != null and quotPrint != ''">quot_print,</if>
            <if test="quotPrintUserName != null and quotPrintUserName != ''">quot_print_user_name,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="updateTime != null">update_time,</if>

            <if test="quotJsxzStandard != null and quotJsxzStandard != ''">quot_jsxz_standard,</if>
            <if test="quotJsxzApprovalStatus != null and quotJsxzApprovalStatus != ''">quot_jsxz_approval_status,</if>
            <if test="quotJsxzChapter != null and quotJsxzChapter != ''">quot_jsxz_chapter,</if>
            <if test="quotJsxzTechnicalRequirement != null and quotJsxzTechnicalRequirement != ''">quot_jsxz_technical_requirement,</if>
            <if test="quotJsxzGroupValues != null and quotJsxzGroupValues != ''">quot_jsxz_group_values,</if>
            <if test="quotJsxzConfirmId != null and quotJsxzConfirmId != ''">quot_jsxz_confirm_id,</if>

            <if test="quotHjId != null and quotHjId != ''">quot_hj_id,</if>
            <if test="quotHjApprovalStatus != null and quotHjApprovalStatus != ''">quot_hj_approval_status,</if>

            <if test="quotJswApprovalStatus != null and quotJswApprovalStatus != ''">quot_jsw_approval_status,</if>
            <if test="quotOAApprovalStatus != null and quotOAApprovalStatus != ''">quot_oa_approval_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="quotId != null and quotId != ''">#{quotId},</if>
            <if test="quotCode != null and quotCode != ''">#{quotCode},</if>
            <if test="quotJswCode != null and quotJswCode != ''">#{quotJswCode},</if>
            <if test="quotSalesmanCode != null and quotSalesmanCode != ''">#{quotSalesmanCode},</if>
            <if test="quotSalesmanBm != null and quotSalesmanBm != ''">#{quotSalesmanBm},</if>
            <if test="quotSalesmanName != null and quotSalesmanName != ''">#{quotSalesmanName},</if>
            <if test="quotCustomerBm != null and quotCustomerBm != ''">#{quotCustomerBm},</if>
            <if test="quotCustomerName != null and quotCustomerName != ''">#{quotCustomerName},</if>
            <if test="quotSalesmanDeptId != null and quotSalesmanDeptId != ''">#{quotSalesmanDeptId},</if>
            <if test="quotSalesmanDeptName != null and quotSalesmanDeptName != ''">#{quotSalesmanDeptName},</if>
            <if test="quotAddress != null and quotAddress != ''">#{quotAddress},</if>
            <if test="quotContacts != null and quotContacts != ''">#{quotContacts},</if>
            <if test="quotPhone != null and quotPhone != ''">#{quotPhone},</if>
            <if test="quotInquiryDate != null">#{quotInquiryDate},</if>
            <if test="quotProject != null and quotProject != ''">#{quotProject},</if>
            <if test="quotQuotationDate != null">#{quotQuotationDate},</if>
            <if test="quotQuotationFrom != null and quotQuotationFrom != ''">#{quotQuotationFrom},</if>
            <if test="quotQuotationRequire != null and quotQuotationRequire != ''">#{quotQuotationRequire},</if>
            <if test="quotFeedbackExplanation != null and quotFeedbackExplanation != ''">#{quotFeedbackExplanation},</if>
            <if test="quotQuantity != null and quotQuantity != ''">#{quotQuantity},</if>
            <if test="quotTotalPrice != null and quotTotalPrice != ''">#{quotTotalPrice},</if>
            <if test="quotCheckUserName != null and quotCheckUserName != ''">#{quotCheckUserName},</if>
            <if test="quotApprovalStatus != null and quotApprovalStatus != ''">#{quotApprovalStatus},</if>
            <if test="quotMaterialsCount != null and quotMaterialsCount != ''">#{quotMaterialsCount},</if>
            <if test="quotLvPrice != null and quotLvPrice != ''">#{quotLvPrice},</if>
            <if test="quotTongPrice != null and quotTongPrice != ''">#{quotTongPrice},</if>
            <if test="quotMatpriceDiff != null and quotMatpriceDiff != ''">#{quotMatpriceDiff},</if>
            <if test="quotPrint != null and quotPrint != ''">#{quotPrint},</if>
            <if test="quotPrintUserName != null and quotPrintUserName != ''">#{quotPrintUserName},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>

            <if test="quotJsxzStandard != null and quotJsxzStandard != ''">#{quotJsxzStandard},</if>
            <if test="quotJsxzApprovalStatus != null and quotJsxzApprovalStatus != ''">#{quotJsxzApprovalStatus},</if>
            <if test="quotJsxzChapter != null and quotJsxzChapter != ''">#{quotJsxzChapter},</if>
            <if test="quotJsxzTechnicalRequirement != null and quotJsxzTechnicalRequirement != ''">#{quotJsxzTechnicalRequirement},</if>
            <if test="quotJsxzGroupValues != null and quotJsxzGroupValues != ''">#{quotJsxzGroupValues},</if>
            <if test="quotJsxzConfirmId != null and quotJsxzConfirmId != ''">#{quotJsxzConfirmId},</if>

            <if test="quotHjId != null and quotHjId != ''">#{quotHjId},</if>
            <if test="quotHjApprovalStatus != null and quotHjApprovalStatus != ''">#{quotHjApprovalStatus},</if>

            <if test="quotJswApprovalStatus != null and quotJswApprovalStatus != ''">#{quotJswApprovalStatus},</if>
            <if test="quotOAApprovalStatus != null and quotOAApprovalStatus != ''">#{quotOAApprovalStatus},</if>
         </trim>
    </insert>


    <select id="selectOAUserByUserName" resultType="SysOaQuot">
        select top 1 id as userId,departmentid as departmentId from HrmResource where loginid = #{loginid}
    </select>
    <insert id="insertSysOAQuot" parameterType="SysOaQuot">
        insert into sys_oa_quot
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null and userId != ''">user_id,</if>
            <if test="departmentId != null and departmentId != ''">department_id,</if>
            <if test="submissionTime != null and submissionTime != ''">submission_time,</if>
            <if test="quotId != null and quotId != ''">quot_id,</if>
            <if test="quotCode != null and quotCode != ''">quot_code,</if>
            <if test="quotSalesmanName != null and quotSalesmanName != ''">quot_salesman_name,</if>
            <if test="quotCustomerName != null and quotCustomerName != ''">quot_customer_name,</if>
            <if test="quotAddress != null and quotAddress != ''">quot_address,</if>
            <if test="quotPhone != null and quotPhone != ''">quot_phone,</if>
            <if test="quotInquiryDate != null">quot_inquiry_date,</if>
            <if test="quotProject != null and quotProject != ''">quot_project,</if>
            <if test="quotQuotationRequire != null and quotQuotationRequire != ''">quot_quotation_require,</if>
            <if test="quotLvPrice != null and quotLvPrice != ''">quot_lv_price,</if>
            <if test="quotTongPrice != null and quotTongPrice != ''">quot_tong_price,</if>
            <if test="quotMatpriceDiff != null and quotMatpriceDiff != ''">quot_matprice_diff,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isFinish != null and isFinish != ''">isFinish,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null and userId != ''">#{userId},</if>
            <if test="departmentId != null and departmentId != ''">#{departmentId},</if>
            <if test="submissionTime != null and submissionTime != ''">#{submissionTime},</if>
            <if test="quotId != null and quotId != ''">#{quotId},</if>
            <if test="quotCode != null and quotCode != ''">#{quotCode},</if>
            <if test="quotSalesmanName != null and quotSalesmanName != ''">#{quotSalesmanName},</if>
            <if test="quotCustomerName != null and quotCustomerName != ''">#{quotCustomerName},</if>
            <if test="quotAddress != null and quotAddress != ''">#{quotAddress},</if>
            <if test="quotPhone != null and quotPhone != ''">#{quotPhone},</if>
            <if test="quotInquiryDate != null">#{quotInquiryDate},</if>
            <if test="quotProject != null and quotProject != ''">#{quotProject},</if>
            <if test="quotQuotationRequire != null and quotQuotationRequire != ''">#{quotQuotationRequire},</if>
            <if test="quotLvPrice != null and quotLvPrice != ''">#{quotLvPrice},</if>
            <if test="quotTongPrice != null and quotTongPrice != ''">#{quotTongPrice},</if>
            <if test="quotMatpriceDiff != null and quotMatpriceDiff != ''">#{quotMatpriceDiff},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isFinish != null and isFinish != ''">#{isFinish},</if>
        </trim>
    </insert>

    <update id="updateQuot" parameterType="Quot">
        update quot
        <trim prefix="SET" suffixOverrides=",">
            <if test="quotCode != null and quotCode != ''">quot_code = #{quotCode},</if>
            <if test="quotJswCode != null and quotJswCode != ''">quot_jsw_code = #{quotJswCode},</if>
            <if test="quotSalesmanCode != null and quotSalesmanCode != ''">quot_salesman_code = #{quotSalesmanCode},</if>
            <if test="quotSalesmanBm != null and quotSalesmanBm != ''">quot_salesman_bm = #{quotSalesmanBm},</if>
            <if test="quotSalesmanName != null and quotSalesmanName != ''">quot_salesman_name = #{quotSalesmanName},</if>
            <if test="quotCustomerBm != null and quotCustomerBm != ''">quot_customer_bm = #{quotCustomerBm},</if>
            <if test="quotCustomerName != null and quotCustomerName != ''">quot_customer_name = #{quotCustomerName},</if>
            <if test="quotSalesmanDeptId != null and quotSalesmanDeptId != ''">quot_salesman_dept_id = #{quotSalesmanDeptId},</if>
            <if test="quotSalesmanDeptName != null and quotSalesmanDeptName != ''">quot_salesman_dept_name = #{quotSalesmanDeptName},</if>
            <if test="quotAddress != null and quotAddress != ''">quot_address = #{quotAddress},</if>
            <if test="quotContacts != null and quotContacts != ''">quot_contacts = #{quotContacts},</if>
            <if test="quotPhone != null and quotPhone != ''">quot_phone = #{quotPhone},</if>
            <if test="quotInquiryDate != null">quot_inquiry_date = #{quotInquiryDate},</if>
            <if test="quotProject != null and quotProject != ''">quot_project = #{quotProject},</if>
            <if test="quotQuotationDate != null">quot_quotation_date = #{quotQuotationDate},</if>
            <if test="quotQuotationFrom != null and quotQuotationFrom != ''">quot_quotation_from = #{quotQuotationFrom},</if>
            <if test="quotQuotationRequire != null and quotQuotationRequire != ''">quot_quotation_require = #{quotQuotationRequire},</if>
            <if test="quotFeedbackExplanation != null and quotFeedbackExplanation != ''">quot_feedback_explanation = #{quotFeedbackExplanation},</if>
            <if test="quotQuantity != null and quotQuantity != ''">quot_quantity = #{quotQuantity},</if>
            <if test="quotTotalPrice != null and quotTotalPrice != ''">quot_total_price = #{quotTotalPrice},</if>
            <if test="quotCheckUserName != null and quotCheckUserName != ''">quot_check_user_name = #{quotCheckUserName},</if>
            <if test="quotApprovalStatus != null and quotApprovalStatus != ''">quot_approval_status = #{quotApprovalStatus},</if>
            <if test="quotMaterialsCount != null and quotMaterialsCount != ''">quot_materials_count = #{quotMaterialsCount},</if>
            <if test="quotLvPrice != null and quotLvPrice != ''">quot_lv_price = #{quotLvPrice},</if>
            <if test="quotTongPrice != null and quotTongPrice != ''">quot_tong_price = #{quotTongPrice},</if>
            <if test="quotMatpriceDiff != null and quotMatpriceDiff != ''">quot_matprice_diff = #{quotMatpriceDiff},</if>
            <if test="quotPrint != null and quotPrint != ''">quot_print = #{quotPrint},</if>
            <if test="quotPrintUserName != null and quotPrintUserName != ''">quot_print_user_name = #{quotPrintUserName},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>

            <if test="quotJsxzStandard != null and quotJsxzStandard != ''">quot_jsxz_standard = #{quotJsxzStandard},</if>
            <if test="quotJsxzApprovalStatus != null and quotJsxzApprovalStatus != ''">quot_jsxz_approval_status = #{quotJsxzApprovalStatus},</if>
            <if test="quotJsxzChapter != null and quotJsxzChapter != ''">quot_jsxz_chapter = #{quotJsxzChapter},</if>
            <if test="quotJsxzTechnicalRequirement != null and quotJsxzTechnicalRequirement != ''">quot_jsxz_technical_requirement = #{quotJsxzTechnicalRequirement},</if>
            <if test="quotJsxzGroupValues != null and quotJsxzGroupValues != ''">quot_jsxz_group_values = #{quotJsxzGroupValues},</if>
            <if test="quotJsxzConfirmId != null and quotJsxzConfirmId != ''">quot_jsxz_confirm_id = #{quotJsxzConfirmId},</if>

            <if test="quotHjId != null and quotHjId != ''">quot_hj_id = #{quotHjId},</if>
            <if test="quotHjApprovalStatus != null and quotHjApprovalStatus != ''">quot_hj_approval_status = #{quotHjApprovalStatus},</if>

            <if test="quotJswApprovalStatus != null and quotJswApprovalStatus != ''">quot_jsw_approval_status = #{quotJswApprovalStatus},</if>
            <if test="quotOAApprovalStatus != null and quotOAApprovalStatus != ''">quot_oa_approval_status = #{quotOAApprovalStatus},</if>
            </trim>
        where quot_id = #{quotId}
    </update>

    <delete id="deleteQuotByQuotId" parameterType="String">
        delete from quot where quot_id = #{quotId}
    </delete>

    <delete id="deleteQuotByQuotIds" parameterType="String">
        delete from quot where quot_id in
        <foreach item="quotId" collection="array" open="(" separator="," close=")">
            #{quotId}
        </foreach>
    </delete>

    <delete id="deleteQuotMaterialByQuotIds" parameterType="String">
        delete from quot_material where quot_id in
        <foreach item="quotId" collection="array" open="(" separator="," close=")">
            #{quotId}
        </foreach>
    </delete>

    <delete id="deleteQuotMaterialByQuotId" parameterType="String">
        delete from quot_material where quot_id = #{quotId}
    </delete>

    <insert id="batchQuotMaterial">
        insert into quot_material( mat_id, mat_xingh, mat_guig, mat_diany,mat_standard, mat_danw, mat_sl,mat_remark, quot_id,xh,number,mat_matprice,mat_price,mat_quot_price,mat_quot_tp,mat_quot_allPrice,mat_matprice_diff) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.matId}, #{item.matXingh}, #{item.matGuig}, #{item.matDiany}, #{item.matStandard}, #{item.matDanw}, cast(#{item.matSl,jdbcType=DECIMAL} as decimal(18,3)),#{item.matRemark}, #{item.quotId}, #{item.xh}, #{item.index}, cast(#{item.matMatprice,jdbcType=DECIMAL} as decimal(18,3)), cast(#{item.matPrice,jdbcType=DECIMAL} as decimal(18,3)), cast(#{item.matQuotPrice,jdbcType=DECIMAL} as decimal(18,3)), cast(#{item.matQuotTp,jdbcType=DECIMAL} as decimal(18,3)),cast(#{item.matQuotAllPrice,jdbcType=DECIMAL} as decimal(18,3)), cast(#{item.matMatpriceDiff,jdbcType=DECIMAL} as decimal(18,3)))
        </foreach>
    </insert>

    <insert id="batchSysOaQuotMaterial">
        insert into sys_oa_quot_material( mat_id, mat_xingh, mat_guig, mat_diany,mat_standard, mat_danw, mat_sl,mat_remark, quot_id,xh,number,mat_matprice,mat_price,mat_quot_price,mat_quot_allPrice,mat_matprice_diff) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.matId}, #{item.matXingh}, #{item.matGuig}, #{item.matDiany}, #{item.matStandard}, #{item.matDanw}, cast(#{item.matSl,jdbcType=DECIMAL} as decimal(18,3)),#{item.matRemark}, #{item.quotId}, #{item.xh}, #{item.index}, cast(#{item.matMatprice,jdbcType=DECIMAL} as decimal(18,3)), cast(#{item.matPrice,jdbcType=DECIMAL} as decimal(18,3)), cast(#{item.matQuotPrice,jdbcType=DECIMAL} as decimal(18,3)),cast(#{item.matQuotAllPrice,jdbcType=DECIMAL} as decimal(18,3)), cast(#{item.matMatpriceDiff,jdbcType=DECIMAL} as decimal(18,3)))
        </foreach>
    </insert>

    <select id="selectQuotByQuotJsqrId" parameterType="String" resultMap="QuotQuotMaterialResult">
        select a.quot_id, a.quot_code, a.quot_salesman_bm, a.quot_salesman_name, a.quot_customer_name,
        a.quot_salesman_dept_id, a.quot_salesman_dept_name, a.quot_address, a.quot_phone, a.quot_inquiry_date,
        a.quot_project, a.quot_quotation_date, a.quot_quotation_from, a.quot_quotation_require, a.quot_feedback_explanation,
        a.quot_quantity, a.quot_total_price, a.quot_check_user_name, u2.nick_name quot_check_user_nickname, a.quot_approval_status,
        a.create_by, a.create_time, a.update_by, a.update_time,

        a.quot_jsxz_standard,a.quot_jsxz_approval_status,a.quot_jsxz_chapter,
        a.quot_jsxz_technical_requirement,a.quot_jsxz_group_values,a.quot_jsxz_confirm_id,
        q.quot_jsqr_code quot_jsxz_confirm_code,
        q.quot_jsqr_tl_approval_status,q.quot_jsqr_tl_remark,
        q.quot_jsqr_dy_approval_status,q.quot_jsqr_dy_remark,
        q.quot_jsqr_zy_approval_status,q.quot_jsqr_zy_remark,
        q.quot_jsqr_qt_approval_status,q.quot_jsqr_qt_remark,

        a.quot_hj_id,a.quot_hj_approval_status,
        h.quot_hj_code,h.quot_hj_pricing_date,
        h.quot_hj_remark,

        b.mat_id as sub_mat_id, b.mat_xingh as sub_mat_xingh, b.mat_guig as sub_mat_guig,
        b.mat_diany as sub_mat_diany, b.mat_danw as sub_mat_danw, b.mat_sl as sub_mat_sl,
        b.quot_id as sub_quot_id
        from quot a
        left join quot_material b on b.quot_id = a.quot_id
        <include refid="quotJoins"/>
        where a.quot_jsxz_confirm_id = #{quotJsqrId}
    </select>

    <select id="selectQuotByQuotHjId" parameterType="String" resultMap="QuotQuotMaterialResult">
        select a.quot_id, a.quot_code, a.quot_salesman_bm, a.quot_salesman_name, a.quot_customer_name,
        a.quot_salesman_dept_id, a.quot_salesman_dept_name, a.quot_address, a.quot_phone, a.quot_inquiry_date,
        a.quot_project, a.quot_quotation_date, a.quot_quotation_from, a.quot_quotation_require, a.quot_feedback_explanation,
        a.quot_quantity, a.quot_total_price, a.quot_check_user_name, u2.nick_name quot_check_user_nickname, a.quot_approval_status,
        a.create_by, a.create_time, a.update_by, a.update_time,

        a.quot_jsxz_standard,a.quot_jsxz_approval_status,a.quot_jsxz_chapter,
        a.quot_jsxz_technical_requirement,a.quot_jsxz_group_values,a.quot_jsxz_confirm_id,
        q.quot_jsqr_code quot_jsxz_confirm_code,
        q.quot_jsqr_tl_approval_status,q.quot_jsqr_tl_remark,
        q.quot_jsqr_dy_approval_status,q.quot_jsqr_dy_remark,
        q.quot_jsqr_zy_approval_status,q.quot_jsqr_zy_remark,
        q.quot_jsqr_qt_approval_status,q.quot_jsqr_qt_remark,

        a.quot_hj_id,a.quot_hj_approval_status,
        h.quot_hj_code,h.quot_hj_pricing_date,
        h.quot_hj_remark,

        b.mat_id as sub_mat_id, b.mat_xingh as sub_mat_xingh, b.mat_guig as sub_mat_guig,
        b.mat_diany as sub_mat_diany, b.mat_danw as sub_mat_danw, b.mat_sl as sub_mat_sl,
        b.quot_id as sub_quot_id
        from quot a
        left join quot_material b on b.quot_id = a.quot_id
        <include refid="quotJoins"/>
        where a.quot_hj_id = #{quotHjId}
    </select>

    <select id="getCode" resultType="String" statementType="CALLABLE">
        {call GetSerialNo(#{type,mode=IN,jdbcType=VARCHAR})}
    </select>






    <select id="selectStatisticsQuotList" parameterType="Quot" resultMap="QuotResult">
        <include refid="selectQuotVo"/>
        <where>
            <if test="quotCode != null  and quotCode != ''"> and quot_code like concat('%', #{quotCode}, '%')</if>
            <if test="quotCustomerName != null  and quotCustomerName != ''"> and quot_customer_name like concat('%', #{quotCustomerName}, '%')</if>
            <if test="quotProject != null  and quotProject != ''"> and quot_project like concat('%', #{quotProject}, '%')</if>
            <if test="quotSalesmanName != null  and quotSalesmanName != ''"> and quot_salesman_name like concat('%', #{quotSalesmanName}, '%')</if>
        </where>
        order by a.quot_inquiry_date desc
    </select>
</mapper>