2026-05-23 13:49:11 +08:00
|
|
|
|
<?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.system.mapper.bid.BizClientQuoteMapper">
|
|
|
|
|
|
|
2026-06-01 19:05:04 +08:00
|
|
|
|
<!-- ========== 甲方报价主表操作 ========== -->
|
|
|
|
|
|
|
|
|
|
|
|
<sql id="quoteColumns">
|
|
|
|
|
|
quote_id AS quoteId, tenant_id AS tenantId, quote_no AS quoteNo,
|
|
|
|
|
|
client_name AS clientName, rfq_id AS rfqId, rfq_no AS rfqNo, rfq_title AS rfqTitle,
|
|
|
|
|
|
status, validity_date AS validityDate, total_amount AS totalAmount,
|
|
|
|
|
|
currency, remark, create_by AS createBy, create_time AS createTime
|
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
2026-05-23 13:49:11 +08:00
|
|
|
|
<select id="selectClientQuoteList" resultType="com.ruoyi.system.domain.bid.BizClientQuote">
|
2026-06-01 19:05:04 +08:00
|
|
|
|
SELECT <include refid="quoteColumns"/>
|
2026-05-23 13:49:11 +08:00
|
|
|
|
FROM biz_client_quote
|
|
|
|
|
|
<where>
|
|
|
|
|
|
<if test="q.clientName != null and q.clientName != ''">AND client_name LIKE CONCAT('%',#{q.clientName},'%')</if>
|
|
|
|
|
|
<if test="q.status != null and q.status != ''">AND status = #{q.status}</if>
|
2026-06-01 19:05:04 +08:00
|
|
|
|
<if test="q.quoteNo != null and q.quoteNo != ''">AND quote_no LIKE CONCAT('%',#{q.quoteNo},'%')</if>
|
|
|
|
|
|
<if test="q.params.beginTime != null and q.params.beginTime != ''">
|
|
|
|
|
|
AND create_time >= #{q.params.beginTime}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="q.params.endTime != null and q.params.endTime != ''">
|
|
|
|
|
|
AND create_time <= #{q.params.endTime}
|
|
|
|
|
|
</if>
|
2026-05-23 13:49:11 +08:00
|
|
|
|
</where>
|
|
|
|
|
|
ORDER BY create_time DESC
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectClientQuoteById" resultType="com.ruoyi.system.domain.bid.BizClientQuote">
|
2026-06-01 19:05:04 +08:00
|
|
|
|
SELECT <include refid="quoteColumns"/>
|
2026-05-23 13:49:11 +08:00
|
|
|
|
FROM biz_client_quote WHERE quote_id = #{quoteId}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
2026-06-01 19:05:04 +08:00
|
|
|
|
<!-- ========== 甲方报价明细操作 ========== -->
|
|
|
|
|
|
|
|
|
|
|
|
<sql id="itemColumns">
|
|
|
|
|
|
item_id AS itemId, quote_id AS quoteId, material_id AS materialId,
|
|
|
|
|
|
material_name AS materialName, spec, model_no AS modelNo, unit, quantity,
|
|
|
|
|
|
cost_price AS costPrice, unit_price AS unitPrice, total_price AS totalPrice,
|
|
|
|
|
|
delivery_days AS deliveryDays, remark
|
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
2026-05-23 13:49:11 +08:00
|
|
|
|
<select id="selectItemsByQuoteId" resultType="com.ruoyi.system.domain.bid.BizClientQuoteItem">
|
2026-06-01 19:05:04 +08:00
|
|
|
|
SELECT <include refid="itemColumns"/>
|
2026-05-23 13:49:11 +08:00
|
|
|
|
FROM biz_client_quote_item WHERE quote_id = #{quoteId} ORDER BY item_id
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectNextQuoteNo" resultType="String">
|
|
|
|
|
|
SELECT CONCAT('CQ-', DATE_FORMAT(NOW(),'%Y%m'), '-', LPAD(IFNULL(MAX(CAST(SUBSTRING_INDEX(quote_no,'-',-1) AS UNSIGNED)),0)+1,3,'0'))
|
|
|
|
|
|
FROM biz_client_quote WHERE quote_no LIKE CONCAT('CQ-', DATE_FORMAT(NOW(),'%Y%m'), '%')
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<insert id="insertClientQuote" useGeneratedKeys="true" keyProperty="quoteId">
|
|
|
|
|
|
INSERT INTO biz_client_quote (tenant_id,quote_no,client_name,rfq_id,rfq_no,rfq_title,
|
|
|
|
|
|
status,validity_date,total_amount,currency,remark,create_by,create_time)
|
|
|
|
|
|
VALUES (1,#{quoteNo},#{clientName},#{rfqId},#{rfqNo},#{rfqTitle},
|
|
|
|
|
|
#{status},#{validityDate},#{totalAmount},#{currency},#{remark},#{createBy},NOW())
|
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
|
|
<insert id="insertClientQuoteItem" useGeneratedKeys="true" keyProperty="itemId">
|
2026-06-01 19:05:04 +08:00
|
|
|
|
INSERT INTO biz_client_quote_item (quote_id,material_id,material_name,spec,model_no,unit,quantity,
|
2026-05-23 13:49:11 +08:00
|
|
|
|
cost_price,unit_price,total_price,delivery_days,remark)
|
2026-06-01 19:05:04 +08:00
|
|
|
|
VALUES (#{quoteId},#{materialId},#{materialName},#{spec},#{modelNo},#{unit},#{quantity},
|
2026-05-23 13:49:11 +08:00
|
|
|
|
#{costPrice},#{unitPrice},#{totalPrice},#{deliveryDays},#{remark})
|
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
|
|
<update id="updateClientQuote">
|
|
|
|
|
|
UPDATE biz_client_quote SET client_name=#{clientName},status=#{status},
|
|
|
|
|
|
validity_date=#{validityDate},total_amount=#{totalAmount},
|
|
|
|
|
|
currency=#{currency},remark=#{remark},update_time=NOW()
|
|
|
|
|
|
WHERE quote_id=#{quoteId}
|
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
|
|
<delete id="deleteClientQuoteById">DELETE FROM biz_client_quote WHERE quote_id=#{quoteId}</delete>
|
|
|
|
|
|
<delete id="deleteItemsByQuoteId">DELETE FROM biz_client_quote_item WHERE quote_id=#{quoteId}</delete>
|
2026-06-01 19:05:04 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- ========== 甲方报价历史 - 统计查询 ========== -->
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectClientQuoteStatistics" resultType="java.util.Map">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
COUNT(*) AS total_count,
|
|
|
|
|
|
COUNT(DISTINCT client_name) AS client_count,
|
|
|
|
|
|
COALESCE(SUM(total_amount), 0) AS total_amount_sum,
|
|
|
|
|
|
MAX(total_amount) AS max_amount,
|
|
|
|
|
|
AVG(total_amount) AS avg_amount
|
|
|
|
|
|
FROM biz_client_quote
|
|
|
|
|
|
<where>
|
|
|
|
|
|
<if test="q.clientName != null and q.clientName != ''">AND client_name LIKE CONCAT('%',#{q.clientName},'%')</if>
|
|
|
|
|
|
<if test="q.status != null and q.status != ''">AND status = #{q.status}</if>
|
|
|
|
|
|
<if test="q.params.beginTime != null and q.params.beginTime != ''">
|
|
|
|
|
|
AND create_time >= #{q.params.beginTime}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="q.params.endTime != null and q.params.endTime != ''">
|
|
|
|
|
|
AND create_time <= #{q.params.endTime}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
</where>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
2026-06-06 15:20:46 +08:00
|
|
|
|
<!-- ========== 获取去重的客户名称列表(用于自动补全) ========== -->
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectDistinctClientNames" resultType="java.lang.String">
|
|
|
|
|
|
SELECT DISTINCT client_name FROM biz_client_quote
|
|
|
|
|
|
WHERE client_name IS NOT NULL AND client_name != ''
|
|
|
|
|
|
<if test="keyword != null and keyword != ''">AND client_name LIKE CONCAT('%',#{keyword},'%')</if>
|
|
|
|
|
|
ORDER BY client_name
|
|
|
|
|
|
LIMIT 20
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
2026-06-01 19:05:04 +08:00
|
|
|
|
<!-- ========== 按物料ID查询甲方报价历史(使用material_id精确关联) ========== -->
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectClientQuotesByMaterialId" resultType="java.util.Map">
|
|
|
|
|
|
SELECT cqi.item_id AS itemId, cqi.spec, cqi.model_no AS modelNo, cqi.unit, cqi.quantity,
|
|
|
|
|
|
cqi.cost_price AS costPrice, cqi.unit_price AS unitPrice, cqi.total_price AS totalPrice,
|
|
|
|
|
|
cqi.delivery_days AS deliveryDays, cqi.material_id AS materialId,
|
|
|
|
|
|
cqi.material_name AS materialName,
|
|
|
|
|
|
cq.quote_id AS quoteId, cq.quote_no AS quoteNo, cq.client_name AS clientName,
|
|
|
|
|
|
cq.status AS quoteStatus, cq.create_time AS createTime
|
|
|
|
|
|
FROM biz_client_quote_item cqi
|
|
|
|
|
|
JOIN biz_client_quote cq ON cqi.quote_id = cq.quote_id
|
|
|
|
|
|
WHERE cqi.material_id = #{materialId}
|
|
|
|
|
|
ORDER BY cq.create_time DESC
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
2026-06-06 15:20:46 +08:00
|
|
|
|
<!-- ========== 按客户+物料ID查询历史报价(甲方编辑时参考) ========== -->
|
|
|
|
|
|
|
|
|
|
|
|
<!-- materialId为可选,为空时返回该客户所有历史物料 -->
|
|
|
|
|
|
<select id="selectClientQuoteHistory" resultType="java.util.Map">
|
|
|
|
|
|
SELECT cqi.item_id AS itemId, cqi.spec, cqi.unit, cqi.quantity,
|
|
|
|
|
|
cqi.cost_price AS costPrice, cqi.unit_price AS unitPrice, cqi.total_price AS totalPrice,
|
|
|
|
|
|
cqi.delivery_days AS deliveryDays, cqi.material_id AS materialId,
|
|
|
|
|
|
cqi.material_name AS materialName,
|
|
|
|
|
|
cq.quote_id AS quoteId, cq.quote_no AS quoteNo, cq.create_time AS createTime
|
|
|
|
|
|
FROM biz_client_quote_item cqi
|
|
|
|
|
|
JOIN biz_client_quote cq ON cqi.quote_id = cq.quote_id
|
|
|
|
|
|
WHERE cq.client_name LIKE CONCAT('%', #{clientName}, '%')
|
|
|
|
|
|
<if test="materialId != null">AND cqi.material_id = #{materialId}</if>
|
|
|
|
|
|
ORDER BY cq.create_time DESC
|
|
|
|
|
|
LIMIT 20
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
2026-06-01 19:05:04 +08:00
|
|
|
|
<!-- ========== 快速创建 - 复制历史报价单的明细(按报价单ID) ========== -->
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectItemsByQuoteIdForCopy" resultType="com.ruoyi.system.domain.bid.BizClientQuoteItem">
|
|
|
|
|
|
SELECT <include refid="itemColumns"/>
|
|
|
|
|
|
FROM biz_client_quote_item WHERE quote_id = #{quoteId}
|
|
|
|
|
|
ORDER BY item_id
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- ========== 甲方报价历史 - 按日期统计趋势 ========== -->
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectMonthlyTrend" resultType="java.util.Map">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
DATE_FORMAT(create_time, '%Y-%m') AS month,
|
|
|
|
|
|
COUNT(*) AS quote_count,
|
|
|
|
|
|
COALESCE(SUM(total_amount), 0) AS amount_sum
|
|
|
|
|
|
FROM biz_client_quote
|
|
|
|
|
|
WHERE create_time >= DATE_SUB(NOW(), INTERVAL 12 MONTH)
|
|
|
|
|
|
GROUP BY DATE_FORMAT(create_time, '%Y-%m')
|
|
|
|
|
|
ORDER BY month
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
2026-05-23 13:49:11 +08:00
|
|
|
|
</mapper>
|