ZengTao
2025-10-11 c542e5b9cf09e192d8a13cb955703857e9558ccc
hangzhoumesParent/moduleService/hollowGlassModule/src/main/resources/mapper/HollowBigStorageCageDetailsMapper.xml
@@ -252,4 +252,129 @@
        where state in (100, 102, 103, 104)
        group by flow_card_id, layer
    </select>
    <select id="queryHollowAllFlowCard" resultType="com.mes.hollow.entity.dto.FlowCardGlassInfoDTO">
        WITH hollow_flow_temp AS (
        SELECT DISTINCT flow_card_id
        FROM hollow_big_storage_cage_details
        WHERE state = 100
        <if test="flowCardId != null and flowCardId != ''">
            AND flow_card_id LIKE CONCAT('%', #{flowCardId}, '%')
        </if>
        <if test="filmsId != null and filmsId != ''">
            AND films_id LIKE CONCAT('%', #{filmsId}, '%')
        </if>
        <if test="thickness != 0">
            AND thickness = #{thickness}
        </if>
        ),
        hollow_details_temp AS (
        SELECT
        flow_card_id,
        glass_id,
        virtual_slot,
        sequence,
        layer,
        total_layer,
        hollow_sequence
        FROM hollow_big_storage_cage_details
        WHERE state = 100
        <if test="flowCardId != null and flowCardId != ''">
            AND flow_card_id LIKE CONCAT('%', #{flowCardId}, '%')
        </if>
        <if test="filmsId != null and filmsId != ''">
            AND films_id LIKE CONCAT('%', #{filmsId}, '%')
        </if>
        <if test="thickness != 0">
            AND thickness = #{thickness}
        </if>
        ),
        hollow_through_temp AS (
        SELECT
        flow_card_id,
        MIN(hollow_sequence) as hollow_sequence,
        MAX(total_layer) as total_layer
        FROM hollow_details_temp
        GROUP BY flow_card_id
        ),
        hollow_pair_temp AS (
        SELECT
        t1.flow_card_id,
        COUNT(*) AS pair_count
        FROM hollow_details_temp t1
        INNER JOIN hollow_details_temp t2
        ON t1.flow_card_id = t2.flow_card_id
        AND t1.virtual_slot = t2.virtual_slot
        AND t1.sequence = t2.sequence
        AND t1.layer = 1 AND t2.layer = 2
        WHERE NOT EXISTS (
        SELECT 1
        FROM hollow_through_temp ht
        WHERE ht.flow_card_id = t1.flow_card_id
        AND ht.total_layer = 3
        ) OR EXISTS (
        SELECT 1
        FROM hollow_details_temp t3
        WHERE t3.flow_card_id = t1.flow_card_id
        AND t3.virtual_slot = t1.virtual_slot
        AND t3.sequence = t1.sequence
        AND t3.layer = 3
        )
        GROUP BY t1.flow_card_id
        ),
        glass_info_temp AS (
        SELECT
        gi.id,
        gi.glass_id,
        gi.flow_card_id,
        gi.layer,
        gi.thickness,
        gi.filmsId
        FROM hollow_flow_temp hft
        INNER JOIN glass_info gi ON hft.flow_card_id = gi.flow_card_id
        ),
        damage_ranked AS (
        SELECT
        d.glass_id,
        d.type,
        d.status,
        ROW_NUMBER() OVER(PARTITION BY d.glass_id ORDER BY d.id DESC) as rn
        FROM hollow_flow_temp hft
        INNER JOIN damage d ON hft.flow_card_id = d.process_id
        ),
        damage_latest AS (
        SELECT
        glass_id,
        type,
        status
        FROM damage_ranked
        WHERE rn = 1
        ),
        result_temp AS (
        SELECT
        t.flow_card_id,
        t.layer,
        t.thickness,
        t.filmsId,
        COUNT(DISTINCT t.id) as sum_count,
        COUNT(DISTINCT t1.glass_id) as real_count,
        COUNT(DISTINCT t.id) - COUNT(DISTINCT t1.glass_id) as lack_count,
        COUNT(DISTINCT CASE WHEN t2.type IN (7,8) AND t2.status = 1 THEN t.glass_id END) as damage_count
        FROM glass_info_temp t
        LEFT JOIN hollow_details_temp t1 ON t.glass_id = t1.glass_id
        LEFT JOIN damage_latest t2 ON t.glass_id = t2.glass_id
        GROUP BY t.flow_card_id, t.layer, t.thickness, t.filmsId
        )
        SELECT
        t.*,
        COALESCE(t1.pair_count, 0) as pair_count,
        t2.hollow_sequence,
        t2.total_layer
        FROM result_temp t
        LEFT JOIN hollow_pair_temp t1 ON t.flow_card_id = t1.flow_card_id
        LEFT JOIN hollow_through_temp t2 ON t.flow_card_id = t2.flow_card_id
        ORDER BY t.flow_card_id
    </select>
</mapper>