@ -877,59 +877,21 @@
where site = #{site} and part_no = #{partNo} and eng_chg_level = #{engChgLevel} and bom_type = #{bomType} and alternative_no = #{alternativeNo} and by_prod_line_item_no = #{byProdLineItemNo} and component_line_item_no = #{componentLineItemNo}
where site = #{site} and part_no = #{partNo} and eng_chg_level = #{engChgLevel} and bom_type = #{bomType} and alternative_no = #{alternativeNo} and by_prod_line_item_no = #{byProdLineItemNo} and component_line_item_no = #{componentLineItemNo}
</update>
</update>
<!-- 多层级 BOM 展开:IFS CONNECT BY 语义;子装配解析在 DefaultChildBom(非递归)中完成。递归成员仅 INNER JOIN,避免 SQL Server 对递归 CTE 的限制(禁止派生表/子查询/外连接/OPTION) 。 -->
<!-- 多层级 BOM 展开:IFS CONNECT BY 语义。直接在递归成员中 JOIN 有效版本,避免使用 ROW_NUMBER() 导致全表扫描 。 -->
<select id= "queryBomMultiLevelStructureList" parameterType= "BomDetailEntity" resultType= "BomMultiLevelStructureData" >
<select id= "queryBomMultiLevelStructureList" parameterType= "BomDetailEntity" resultType= "BomMultiLevelStructureData" >
WITH DefaultChildBom AS (
SELECT pick.site, pick.part_no, pick.bom_type, pick.eng_chg_level, pick.alternative_no
FROM (
SELECT bd.site,
bd.part_no,
bd.bom_type,
bd.eng_chg_level,
bd.alternative_no,
ROW_NUMBER() OVER (
PARTITION BY bd.site, bd.part_no, bd.bom_type
ORDER BY bh.eff_phase_in_date DESC, bh.create_date DESC
) AS rn
FROM plm_bom_detail bd
INNER JOIN plm_bom_header bh ON bd.site = bh.site AND bd.part_no = bh.part_no
AND bd.bom_type = bh.bom_type AND bd.eng_chg_level = bh.eng_chg_level
INNER JOIN part_revision pr ON pr.site = bh.site AND pr.part_no = bh.part_no AND pr.eng_chg_level = bh.eng_chg_level
WHERE bd.alternative_no = '*'
AND pr.eff_phase_out_date IS NULL
AND ISNULL(bd.status, '') <![CDATA[<>]]> 'Obsolete'
) pick
WHERE pick.rn = 1
),
ExplodedBom AS (
WITH ExplodedBom AS (
SELECT
SELECT
1 AS structure_level,
1 AS structure_level,
CAST(RIGHT(REPLICATE('0', 8) + CAST(a.line_sequence AS VARCHAR(8)), 8) AS VARCHAR(8000)) AS sort_key,
CAST(RIGHT(REPLICATE('0', 8) + CAST(a.line_sequence AS VARCHAR(8)), 8) AS VARCHAR(8000)) AS sort_key,
a.site,
a.site,
a.part_no,
a.part_no,
dbo.get_part_name(a.site, a.part_no) AS partDesc,
a.bom_type,
a.bom_type,
a.eng_chg_level,
a.eng_chg_level,
a.alternative_no,
a.alternative_no,
b.alternative_description,
a.component_part,
a.component_part,
dbo.get_part_name(a.site, a.component_part) AS componentPartDesc,
a.qty_per_assembly,
a.qty_per_assembly,
a.print_unit,
dbo.get_um_name(a.print_unit) AS printUnitName,
c.product_group_id4,
dbo.get_product_group_name(c.site, c.product_group_id4, '4') AS productGroupName4,
c.min_order_qty,
c.mul_order_qty,
c.planning_method,
c.cum_lead_time,
c.unprotected_lead_time,
dbo.get_cum_lead_time(a.site, a.component_part) AS componentCumLeadTime,
dbo.get_unprotected_lead_time(a.site, a.component_part) AS componentUnprotectedLeadTime
a.print_unit
FROM plm_bom_component AS a
FROM plm_bom_component AS a
LEFT JOIN plm_bom_detail AS b ON a.site = b.site AND a.part_no = b.part_no AND a.bom_type = b.bom_type
AND a.eng_chg_level = b.eng_chg_level AND a.alternative_no = b.alternative_no
LEFT JOIN part AS c ON a.site = c.site AND a.part_no = c.part_no
WHERE a.site = #{site}
WHERE a.site = #{site}
AND a.part_no = #{partNo}
AND a.part_no = #{partNo}
AND a.bom_type = #{bomType}
AND a.bom_type = #{bomType}
@ -944,60 +906,54 @@
CAST(p.sort_key + '.' + RIGHT(REPLICATE('0', 8) + CAST(a.line_sequence AS VARCHAR(8)), 8) AS VARCHAR(8000)),
CAST(p.sort_key + '.' + RIGHT(REPLICATE('0', 8) + CAST(a.line_sequence AS VARCHAR(8)), 8) AS VARCHAR(8000)),
a.site,
a.site,
a.part_no,
a.part_no,
dbo.get_part_name(a.site, a.part_no) AS partDesc,
a.bom_type,
a.bom_type,
a.eng_chg_level,
a.eng_chg_level,
a.alternative_no,
a.alternative_no,
b.alternative_description,
a.component_part,
a.component_part,
dbo.get_part_name(a.site, a.component_part) AS componentPartDesc,
a.qty_per_assembly,
a.qty_per_assembly,
a.print_unit,
dbo.get_um_name(a.print_unit) AS printUnitName,
c.product_group_id4,
dbo.get_product_group_name(c.site, c.product_group_id4, '4') AS productGroupName4,
c.min_order_qty,
c.mul_order_qty,
c.planning_method,
c.cum_lead_time,
c.unprotected_lead_time,
dbo.get_cum_lead_time(a.site, a.component_part) AS componentCumLeadTime,
dbo.get_unprotected_lead_time(a.site, a.component_part) AS componentUnprotectedLeadTime
a.print_unit
FROM ExplodedBom AS p
FROM ExplodedBom AS p
INNER JOIN DefaultChildBom AS cb ON cb.site = p.site AND cb.part_no = p.component_part AND cb.bom_type = p.bom_type
INNER JOIN plm_bom_detail AS cb ON cb.site = p.site AND cb.part_no = p.component_part AND cb.bom_type = p.bom_type
AND cb.alternative_no = '*' AND ISNULL(cb.status, '') <![CDATA[<>]]> 'Obsolete'
INNER JOIN part_revision AS cpr ON cpr.site = cb.site AND cpr.part_no = cb.part_no AND cpr.eng_chg_level = cb.eng_chg_level
AND cpr.eff_phase_out_date IS NULL
INNER JOIN plm_bom_component AS a ON a.site = cb.site AND a.part_no = cb.part_no
INNER JOIN plm_bom_component AS a ON a.site = cb.site AND a.part_no = cb.part_no
AND a.bom_type = cb.bom_type AND a.eng_chg_level = cb.eng_chg_level AND a.alternative_no = cb.alternative_no
AND a.bom_type = cb.bom_type AND a.eng_chg_level = cb.eng_chg_level AND a.alternative_no = cb.alternative_no
INNER JOIN plm_bom_detail AS b ON a.site = b.site AND a.part_no = b.part_no AND a.bom_type = b.bom_type
AND a.eng_chg_level = b.eng_chg_level AND a.alternative_no = b.alternative_no
INNER JOIN part AS c ON a.site = c.site AND a.part_no = c.part_no
WHERE p.structure_level < 100
WHERE p.structure_level < 100
AND a.qty_per_assembly > = 0
AND a.qty_per_assembly > = 0
)
)
SELECT
SELECT
structure_level,
site,
part_no,
partDesc,
bom_type,
eng_chg_level,
alternative_no,
alternative_description,
component_part,
componentPartDesc,
qty_per_assembly,
print_unit,
printUnitName,
product_group_id4,
productGroupName4,
min_order_qty,
mul_order_qty,
planning_method,
cum_lead_time,
unprotected_lead_time,
componentCumLeadTime,
componentUnprotectedLeadTime
FROM ExplodedBom
ORDER BY sort_key
eb.structure_level,
eb.site,
eb.part_no,
dbo.get_part_name(eb.site, eb.part_no) AS partDesc,
eb.bom_type,
eb.eng_chg_level,
eb.alternative_no,
b.alternative_description,
eb.component_part,
dbo.get_part_name(eb.site, eb.component_part) AS componentPartDesc,
eb.qty_per_assembly,
eb.print_unit,
dbo.get_um_name(eb.print_unit) AS printUnitName,
c.product_group_id4,
dbo.get_product_group_name(c.site, c.product_group_id4, '4') AS productGroupName4,
c.min_order_qty,
c.mul_order_qty,
c.planning_method,
c.cum_lead_time,
c.unprotected_lead_time,
dbo.get_cum_lead_time(eb.site, eb.component_part) AS componentCumLeadTime,
dbo.get_unprotected_lead_time(eb.site, eb.component_part) AS componentUnprotectedLeadTime
FROM (
SELECT *, ROW_NUMBER() OVER(PARTITION BY sort_key ORDER BY eng_chg_level DESC) as rn
FROM ExplodedBom
) eb
LEFT JOIN plm_bom_detail AS b ON eb.site = b.site AND eb.part_no = b.part_no AND eb.bom_type = b.bom_type
AND eb.eng_chg_level = b.eng_chg_level AND eb.alternative_no = b.alternative_no
LEFT JOIN part AS c ON eb.site = c.site AND eb.part_no = c.part_no
WHERE eb.rn = 1
ORDER BY eb.sort_key
</select>
</select>
<!-- 新增BOM子明细表内容 -->
<!-- 新增BOM子明细表内容 -->