wu
2025-10-27 112ff5924fd5f6114c1562af60ca16e6eba6f7fb
hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/resources/mapper/BigStorageCageDetailsMapper.xml
@@ -301,4 +301,85 @@
        group by bsc.device_id, bsc.slot
        order by bsc.device_id, bsc.slot
    </select>
    <select id="queryNeedDispatch" resultType="com.mes.bigstorage.entity.BigStorageCageDetails">
        SELECT * FROM big_storage_cage_details WHERE STATE = 100 AND SLOT = (SELECT SLOT FROM big_storage_cage_details WHERE STATE = 100 AND sequence = 1 order by slot desc LIMIT 1) ORDER BY tempering_feed_sequence
    </select>
    <select id="queryNeedDispatchSlotBySequence" resultType="com.mes.bigstorage.entity.dto.BigStorageSlotDTO">
        with glass_temp as (
        select t.* ,t1.virtual_slot,t1.slot_sequence from big_storage_cage_details t inner join
        big_storage_glass_relation_info t1 on t.engineer_id = t1.engineer_id
        and t.tempering_layout_id = t1.tempering_layout_id
        and t.tempering_feed_sequence = t1.tempering_feed_sequence where t.state = 100
        ),slot_max_temp as (
        select ROW_NUMBER()over(PARTITION by engineer_id, tempering_layout_id, virtual_slot order by slot_sequence desc)
        as rn,t.* from glass_temp t where t.device_id in (5,6)
        ) ,slot_max_message as (select * from slot_max_temp where rn =1)
        ,slot_min_temp as (
        select ROW_NUMBER()over(PARTITION by engineer_id, tempering_layout_id, virtual_slot order by slot_sequence) as
        rn,t.* from glass_temp t where t.device_id in (5,6)
        ) ,slot_min_message as (select * from slot_min_temp where rn =1)
        ,result as (
        select t.slot as target_slot ,t1.slot as start_slot from slot_max_message t inner join slot_min_message t1 on
        t.engineer_id = t1.engineer_id and t.tempering_layout_id = t1.tempering_layout_id and t.virtual_slot =
        t1.virtual_slot and t.tempering_layout_id = t1.tempering_layout_id and t.tempering_feed_sequence =
        t1.tempering_feed_sequence -1
        )select * from result limit 1
    </select>
    <select id="queryTemperingGlassCountSummary" resultMap="temperingGlassCount">
        with glass_info_temp as (
        select engineer_id, tempering_layout_id, count(*) as total_count
        from glass_info
        group by engineer_id, tempering_layout_id
        ),
        big_details_temp as (
        select engineer_id, tempering_layout_id, count(*) as real_count, films_id, thickness
        from big_storage_cage_details
        where state = 100
        <if test="isTempering == 0">
            and tempering_layout_id = 0
        </if>
        <if test="isTempering == 1">
            and tempering_layout_id != 0
        </if>
        group by engineer_id, tempering_layout_id, films_id, thickness
        ),
        damage_temp as (
        select engineer_id, tempering_layout_id, count(*) as damage_count
        from damage
        where type in(8,9) and STATUS = 1
        group by engineer_id, tempering_layout_id
        ),
        result as (
        select t.engineer_id,
        t.tempering_layout_id,
        t.films_id,
        t.thickness,
        total_count,
        real_count,
        ifnull(damage_count, 0) as damage_count,
        case when total_count - real_count - ifnull(damage_count, 0) &lt; 0 then 0 else
        total_count - real_count - ifnull(damage_count, 0) end as lack_count
        from big_details_temp t
        inner join glass_info_temp t1 on t.engineer_id = t1.engineer_id and
        t.tempering_layout_id = t1.tempering_layout_id
        left join damage_temp t2
        on t.engineer_id = t2.engineer_id and t.tempering_layout_id = t2.tempering_layout_id
        ),
        -- 二次汇总层
        secondary_summary as (
        select
        engineer_id,
        films_id,
        thickness,
        count(distinct tempering_layout_id) as total_count, -- 计算totalCount的累计数(去重计数)
        sum(total_count) as real_count -- 计算realCount的总和
        from result
        group by engineer_id, films_id, thickness
        )
        select *
        from secondary_summary
        order by engineer_id, films_id, thickness
    </select>
</mapper>