You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

323 lines
15 KiB

<?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.xujie.modules.supplier.mapper.PriceSheetReportMapper">
<select id="countPriceList" resultType="long">
SELECT COUNT(1)
FROM SupplierforPart sp
INNER JOIN part p
ON p.site = sp.site
AND p.part_no = sp.part_no
LEFT JOIN srm_supplier s
ON s.site = sp.site
AND s.supplier_no = sp.supplier_no
WHERE sp.site = #{query.site}
AND p.item IS NOT NULL
AND LTRIM(RTRIM(p.item)) &lt;&gt; ''
<if test="query.item != null and query.item != ''">
AND p.item LIKE CONCAT('%', #{query.item}, '%')
</if>
<if test="query.sku != null and query.sku != ''">
AND p.sku LIKE CONCAT('%', #{query.sku}, '%')
</if>
<if test="query.shortNpc != null and query.shortNpc != ''">
AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
</if>
<if test="query.category != null and query.category != ''">
AND p.category LIKE CONCAT('%', #{query.category}, '%')
</if>
</select>
<!--
价格表查询:QTY/PO 读 minOrderQty,MOQ/COLOR 读 minColorQty,QTY/CARTON 读 minCartonQty。
site 必须来自请求。空数量按 0 返回,避免前端显示空白。
-->
<select id="listPriceList" resultType="com.xujie.modules.supplier.data.PriceSheetReportPriceVo">
SELECT
p.item AS rawCode,
p.sku AS sku,
s.c_short_npc AS supplier,
ISNULL(sp.minOrderQty, 0) AS qtyPo,
ISNULL(sp.minColorQty, 0) AS moqColor,
ISNULL(sp.minCartonQty, 0) AS qtyCarton,
CONVERT(VARCHAR(10), current_price.priceDate, 23) AS startDate,
current_price.tierQty1 AS tierQty1,
current_price.tierQty2 AS tierQty2,
current_price.tierQty3 AS tierQty3,
current_price.tierQty4 AS tierQty4,
current_price.tierQty5 AS tierQty5,
current_price.tierQty6 AS tierQty6,
current_price.tierQty7 AS tierQty7,
current_price.tierQty8 AS tierQty8,
current_price.priceTier1 AS priceTier1,
current_price.priceTier2 AS priceTier2,
current_price.priceTier3 AS priceTier3,
current_price.priceTier4 AS priceTier4,
current_price.priceTier5 AS priceTier5,
current_price.priceTier6 AS priceTier6,
current_price.priceTier7 AS priceTier7,
current_price.priceTier8 AS priceTier8,
fsc.propertyValue AS fsc,
fsc_claim.propertyValue AS fscClaim,
aware_dpp.propertyValue AS awareDpp,
coo.propertyValue AS coo,
COALESCE(sku_lead.production_lead_time, s.production_lead_time) AS leadTime
FROM SupplierforPart sp
INNER JOIN part p
ON p.site = sp.site
AND p.part_no = sp.part_no
LEFT JOIN srm_supplier s
ON s.site = sp.site
AND s.supplier_no = sp.supplier_no
LEFT JOIN SupplierforSku sku_lead
ON sku_lead.supplier_no = sp.supplier_no
AND sku_lead.sku = p.sku
AND NULLIF(LTRIM(RTRIM(p.sku)), '') IS NOT NULL
LEFT JOIN
(
SELECT
ranked.site,
ranked.supplier_code,
ranked.part_no,
MAX(CASE WHEN ranked.tierRank = 1 THEN ranked.price_date END) AS priceDate,
MAX(CASE WHEN ranked.tierRank = 1 THEN ranked.qty_end END) AS tierQty1,
MAX(CASE WHEN ranked.tierRank = 2 THEN ranked.qty_end END) AS tierQty2,
MAX(CASE WHEN ranked.tierRank = 3 THEN ranked.qty_end END) AS tierQty3,
MAX(CASE WHEN ranked.tierRank = 4 THEN ranked.qty_end END) AS tierQty4,
MAX(CASE WHEN ranked.tierRank = 5 THEN ranked.qty_end END) AS tierQty5,
MAX(CASE WHEN ranked.tierRank = 6 THEN ranked.qty_end END) AS tierQty6,
MAX(CASE WHEN ranked.tierRank = 7 THEN ranked.qty_end END) AS tierQty7,
MAX(CASE WHEN ranked.tierRank = 8 THEN ranked.qty_end END) AS tierQty8,
MAX(CASE WHEN ranked.tierRank = 1 THEN ranked.unit_price END) AS priceTier1,
MAX(CASE WHEN ranked.tierRank = 2 THEN ranked.unit_price END) AS priceTier2,
MAX(CASE WHEN ranked.tierRank = 3 THEN ranked.unit_price END) AS priceTier3,
MAX(CASE WHEN ranked.tierRank = 4 THEN ranked.unit_price END) AS priceTier4,
MAX(CASE WHEN ranked.tierRank = 5 THEN ranked.unit_price END) AS priceTier5,
MAX(CASE WHEN ranked.tierRank = 6 THEN ranked.unit_price END) AS priceTier6,
MAX(CASE WHEN ranked.tierRank = 7 THEN ranked.unit_price END) AS priceTier7,
MAX(CASE WHEN ranked.tierRank = 8 THEN ranked.unit_price END) AS priceTier8
FROM
(
SELECT
price.site,
price.supplier_code,
price.part_no,
price.qty_end,
price.unit_price,
price.price_date,
ROW_NUMBER() OVER
(
PARTITION BY price.site, price.supplier_code, price.part_no
ORDER BY price.qty_start, price.qty_end, price.id
) AS tierRank
FROM sp_current_tier_price price
WHERE price.site = #{query.site}
) ranked
WHERE ranked.tierRank &lt;= 8
GROUP BY ranked.site, ranked.supplier_code, ranked.part_no
) current_price
ON current_price.site = sp.site
AND current_price.supplier_code = sp.supplier_no
AND current_price.part_no = sp.part_no
<!-- 物料附加属性:FSC / FSC claim / AWARE DPP / COO。Lead free Pellet(T0016) 已从价格单查询与导出移除,不再关联。 -->
LEFT JOIN
(
SELECT Site, PartNo,
MAX(TextValue) AS propertyValue
FROM PartSubPropertiesValue
WHERE PropertiesItemNo = 'T0011' AND RecordType = 'P'
GROUP BY Site, PartNo
) fsc ON fsc.Site = sp.site AND fsc.PartNo = sp.part_no
LEFT JOIN
(
SELECT Site, PartNo,
MAX(TextValue) AS propertyValue
FROM PartSubPropertiesValue
WHERE PropertiesItemNo = 'T0012' AND RecordType = 'P'
GROUP BY Site, PartNo
) fsc_claim ON fsc_claim.Site = sp.site AND fsc_claim.PartNo = sp.part_no
LEFT JOIN
(
SELECT Site, PartNo,
MAX(TextValue) AS propertyValue
FROM PartSubPropertiesValue
WHERE PropertiesItemNo = 'T0052' AND RecordType = 'P'
GROUP BY Site, PartNo
) aware_dpp ON aware_dpp.Site = sp.site AND aware_dpp.PartNo = sp.part_no
LEFT JOIN
(
SELECT Site, PartNo,
MAX(TextValue) AS propertyValue
FROM PartSubPropertiesValue
WHERE PropertiesItemNo = 'T0042' AND RecordType = 'P'
GROUP BY Site, PartNo
) coo ON coo.Site = sp.site AND coo.PartNo = sp.part_no
WHERE sp.site = #{query.site}
AND p.item IS NOT NULL
AND LTRIM(RTRIM(p.item)) &lt;&gt; ''
<if test="query.item != null and query.item != ''">
AND p.item LIKE CONCAT('%', #{query.item}, '%')
</if>
<if test="query.sku != null and query.sku != ''">
AND p.sku LIKE CONCAT('%', #{query.sku}, '%')
</if>
<if test="query.shortNpc != null and query.shortNpc != ''">
AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
</if>
<if test="query.category != null and query.category != ''">
AND p.category LIKE CONCAT('%', #{query.category}, '%')
</if>
ORDER BY p.item, s.c_short_npc, sp.part_no, sp.supplier_no
<if test="offset != null and limit != null">
OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY
</if>
</select>
<!--
handling charge 只展示配置了最低出货金额的供应商。
min_ship_account 已改为 varchar 字典值:null 或空白视为未配置,页签查询与导出共用本条件。
-->
<sql id="HandlingChargeHasMinShipAccount">
AND NULLIF(LTRIM(RTRIM(s.min_ship_account)), '') IS NOT NULL
</sql>
<select id="countHandlingCharges" resultType="long">
SELECT COUNT(1)
FROM srm_supplier s
WHERE s.site = #{query.site}
<include refid="HandlingChargeHasMinShipAccount"/>
<if test="query.shortNpc != null and query.shortNpc != ''">
AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
</if>
AND EXISTS (
SELECT 1
FROM SupplierforPart filter_relation
INNER JOIN part filter_part
ON filter_part.site = filter_relation.site
AND filter_part.part_no = filter_relation.part_no
WHERE filter_relation.site = s.site
AND filter_relation.supplier_no = s.supplier_no
AND filter_part.item IS NOT NULL
AND LTRIM(RTRIM(filter_part.item)) &lt;&gt; ''
<if test="query.item != null and query.item != ''">
AND filter_part.item LIKE CONCAT('%', #{query.item}, '%')
</if>
<if test="query.sku != null and query.sku != ''">
AND filter_part.sku LIKE CONCAT('%', #{query.sku}, '%')
</if>
<if test="query.category != null and query.category != ''">
AND filter_part.category LIKE CONCAT('%', #{query.category}, '%')
</if>
)
</select>
<select id="listHandlingCharges"
resultType="com.xujie.modules.supplier.data.PriceSheetReportHandlingChargeVo">
SELECT
s.c_short_npc AS supplier,
s.min_ship_account AS minShipAccount,
s.handling_charge AS handlingChargeAmount
FROM srm_supplier s
WHERE s.site = #{query.site}
<include refid="HandlingChargeHasMinShipAccount"/>
<if test="query.shortNpc != null and query.shortNpc != ''">
AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
</if>
AND EXISTS (
SELECT 1
FROM SupplierforPart filter_relation
INNER JOIN part filter_part
ON filter_part.site = filter_relation.site
AND filter_part.part_no = filter_relation.part_no
WHERE filter_relation.site = s.site
AND filter_relation.supplier_no = s.supplier_no
AND filter_part.item IS NOT NULL
AND LTRIM(RTRIM(filter_part.item)) &lt;&gt; ''
<if test="query.item != null and query.item != ''">
AND filter_part.item LIKE CONCAT('%', #{query.item}, '%')
</if>
<if test="query.sku != null and query.sku != ''">
AND filter_part.sku LIKE CONCAT('%', #{query.sku}, '%')
</if>
<if test="query.category != null and query.category != ''">
AND filter_part.category LIKE CONCAT('%', #{query.category}, '%')
</if>
)
ORDER BY s.c_short_npc, s.supplier_no
<if test="offset != null and limit != null">
OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY
</if>
</select>
<select id="countPaymentTerms" resultType="long">
SELECT COUNT(1)
FROM srm_supplier s
WHERE s.site = #{query.site}
<if test="query.shortNpc != null and query.shortNpc != ''">
AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
</if>
AND EXISTS (
SELECT 1
FROM SupplierforPart filter_relation
INNER JOIN part filter_part
ON filter_part.site = filter_relation.site
AND filter_part.part_no = filter_relation.part_no
WHERE filter_relation.site = s.site
AND filter_relation.supplier_no = s.supplier_no
AND filter_part.item IS NOT NULL
AND LTRIM(RTRIM(filter_part.item)) &lt;&gt; ''
<if test="query.item != null and query.item != ''">
AND filter_part.item LIKE CONCAT('%', #{query.item}, '%')
</if>
<if test="query.sku != null and query.sku != ''">
AND filter_part.sku LIKE CONCAT('%', #{query.sku}, '%')
</if>
<if test="query.category != null and query.category != ''">
AND filter_part.category LIKE CONCAT('%', #{query.category}, '%')
</if>
)
</select>
<select id="listPaymentTerms"
resultType="com.xujie.modules.supplier.data.PriceSheetReportPaymentTermVo">
SELECT
ROW_NUMBER() OVER (ORDER BY s.c_short_npc, s.supplier_no) AS rowNo,
s.c_short_npc AS supplier,
payment_term.payment_term AS paymentTerms,
CAST(NULL AS VARCHAR(1)) AS telexReleaseStatus
FROM srm_supplier s
LEFT JOIN PaymentTerm payment_term
ON payment_term.site = s.site
AND payment_term.payment_term_id = s.PaymentTerm
WHERE s.site = #{query.site}
<if test="query.shortNpc != null and query.shortNpc != ''">
AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
</if>
AND EXISTS (
SELECT 1
FROM SupplierforPart filter_relation
INNER JOIN part filter_part
ON filter_part.site = filter_relation.site
AND filter_part.part_no = filter_relation.part_no
WHERE filter_relation.site = s.site
AND filter_relation.supplier_no = s.supplier_no
AND filter_part.item IS NOT NULL
AND LTRIM(RTRIM(filter_part.item)) &lt;&gt; ''
<if test="query.item != null and query.item != ''">
AND filter_part.item LIKE CONCAT('%', #{query.item}, '%')
</if>
<if test="query.sku != null and query.sku != ''">
AND filter_part.sku LIKE CONCAT('%', #{query.sku}, '%')
</if>
<if test="query.category != null and query.category != ''">
AND filter_part.category LIKE CONCAT('%', #{query.category}, '%')
</if>
)
ORDER BY s.c_short_npc, s.supplier_no
<if test="offset != null and limit != null">
OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY
</if>
</select>
</mapper>