<?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.priceVerification.mapper.QuotHjMapper">

    <resultMap type="QuotHj" id="QuotHjResult">
        <result property="quotHjId"    column="quot_hj_id"    />
        <result property="quotHjCode"    column="quot_hj_code"    />
        <result property="quotHjPricingType"    column="quot_hj_pricing_type"    />
        <result property="quotHjPricingDate"    column="quot_hj_pricing_date"    />
        <result property="quotHjRemark"    column="quot_hj_remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="createName"    column="create_name"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />

        <result property="quotId"    column="quot_id"    />
        <result property="quotCode"    column="quot_code"    />
        <result property="quotHjApprovalStatus"    column="quot_hj_approval_status"    />
        <result property="quotSalesmanName"    column="quot_salesman_name"    />
        <result property="quotCustomerName"    column="quot_customer_name"    />
        <result property="quotProject"    column="quot_project"    />

        <result property="quotJsxzConfirmId"    column="quot_jsxz_confirm_id"    />
        <result property="quotJsxzGroupValues"    column="quot_jsxz_group_values"    />

        <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"    />
    </resultMap>

    <sql id="quotHjJoins">
        left join sys_user u on u.user_name=a.create_by
        left join sys_dept d on u.dept_id = d.dept_id
        left join quot q on q.quot_hj_id = a.quot_hj_id
        left join quot_jsqr j on j.quot_jsqr_id = q.quot_jsxz_confirm_id
    </sql>

    <sql id="selectQuotHjVo">
        select a.quot_hj_id, a.quot_hj_code, a.quot_hj_pricing_type, a.quot_hj_pricing_date, a.quot_hj_remark,
               a.create_by, a.create_time, a.update_by, a.update_time,
               u.nick_name create_name,
               q.quot_hj_approval_status,q.quot_id,q.quot_code,q.quot_salesman_name,
               q.quot_customer_name,q.quot_project,
               q.quot_jsxz_confirm_id,q.quot_jsxz_group_values,
                j.quot_jsqr_tl_approval_status,j.quot_jsqr_tl_remark,
                j.quot_jsqr_dy_approval_status,j.quot_jsqr_dy_remark,
                j.quot_jsqr_zy_approval_status,j.quot_jsqr_zy_remark,
                j.quot_jsqr_qt_approval_status,j.quot_jsqr_qt_remark
        from quot_hj a
        <include refid="quotHjJoins"/>
    </sql>

    <select id="selectQuotHjList" parameterType="QuotHj" resultMap="QuotHjResult">
        <include refid="selectQuotHjVo"/>
        <where>
            <if test="quotHjCode != null  and quotHjCode != ''"> and quot_hj_code like concat('%', #{quotHjCode}, '%')</if>
            <if test="params.beginQuotHjPricingDate != null and params.beginQuotHjPricingDate != '' and params.endQuotHjPricingDate != null and params.endQuotHjPricingDate != ''"> and quot_hj_pricing_date between #{params.beginQuotHjPricingDate} and #{params.endQuotHjPricingDate}</if>
            <!-- 数据范围过滤 -->
            <!--${params.dataScope}-->
        </where>
        order by a.update_time desc
    </select>

    <select id="selectQuotHjByQuotHjId" parameterType="String" resultMap="QuotHjResult">
        <include refid="selectQuotHjVo"/>
        where a.quot_hj_id = #{quotHjId}
    </select>

    <insert id="insertQuotHj" parameterType="QuotHj">
        insert into quot_hj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="quotHjId != null">quot_hj_id,</if>
            <if test="quotHjCode != null">quot_hj_code,</if>
            <if test="quotHjPricingType != null">quot_hj_pricing_type,</if>
            <if test="quotHjPricingDate != null">quot_hj_pricing_date,</if>
            <if test="quotHjRemark != null">quot_hj_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="quotHjId != null">#{quotHjId},</if>
            <if test="quotHjCode != null">#{quotHjCode},</if>
            <if test="quotHjPricingType != null">#{quotHjPricingType},</if>
            <if test="quotHjPricingDate != null">#{quotHjPricingDate},</if>
            <if test="quotHjRemark != null">#{quotHjRemark},</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="updateQuotHj" parameterType="QuotHj">
        update quot_hj
        <trim prefix="SET" suffixOverrides=",">
            <if test="quotHjCode != null">quot_hj_code = #{quotHjCode},</if>
            <if test="quotHjPricingType != null">quot_hj_pricing_type = #{quotHjPricingType},</if>
            <if test="quotHjPricingDate != null">quot_hj_pricing_date = #{quotHjPricingDate},</if>
            <if test="quotHjRemark != null">quot_hj_remark = #{quotHjRemark},</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 quot_hj_id = #{quotHjId}
    </update>

    <delete id="deleteQuotHjByQuotHjId" parameterType="String">
        delete from quot_hj where quot_hj_id = #{quotHjId}
    </delete>

    <delete id="deleteQuotHjByQuotHjIds" parameterType="String">
        delete from quot_hj where quot_hj_id in
        <foreach item="quotHjId" collection="array" open="(" separator="," close=")">
            #{quotHjId}
        </foreach>
    </delete>
</mapper>