zhoushihao
2024-12-30 2e20e85173b764e43a6e4022072bc8fb0cc61330
hangzhoumesParent/moduleService/howllowGlassModule/src/main/java/com/mes/hollow/service/impl/HollowGlassRelationInfoServiceImpl.java
@@ -3,6 +3,7 @@
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mes.common.config.Const;
import com.mes.glassinfo.entity.GlassInfo;
@@ -14,6 +15,7 @@
import com.mes.hollow.entity.dto.HollowBigStorageDTO;
import com.mes.hollow.entity.dto.HollowGlassDetailsDTO;
import com.mes.hollow.entity.dto.LackDetailsDTO;
import com.mes.hollow.entity.vo.HollowBigStorageDetailsQueryVO;
import com.mes.hollow.mapper.HollowGlassRelationInfoMapper;
import com.mes.hollow.service.HollowBigStorageCageDetailsService;
import com.mes.hollow.service.HollowBigStorageCageService;
@@ -63,9 +65,9 @@
                .eq(HollowGlassRelationInfo::getFlowCardId, flowCardId)
                .eq(HollowGlassRelationInfo::getWidth, width)
                .eq(HollowGlassRelationInfo::getHeight, height)
                .eq(HollowGlassRelationInfo::getTotalLayer, totalLayer)
                .eq(HollowGlassRelationInfo::getLayer, layer)
                .isNull(HollowGlassRelationInfo::getTemperingLayoutId)
                .isNull(HollowGlassRelationInfo::getTemperingFeedSequence)
                .eq(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_NEW)
                .orderByAsc(HollowGlassRelationInfo::getHollowSequence)
                .last("limit 1")
        );
@@ -77,47 +79,79 @@
                    .eq(HollowGlassRelationInfo::getFlowCardId, flowCardId)
                    .eq(HollowGlassRelationInfo::getWidth, width)
                    .eq(HollowGlassRelationInfo::getHeight, height)
                    .eq(HollowGlassRelationInfo::getTotalLayer, totalLayer)
                    .eq(HollowGlassRelationInfo::getLayer, layer)
                    .isNull(HollowGlassRelationInfo::getTemperingLayoutId)
                    .isNull(HollowGlassRelationInfo::getTemperingFeedSequence)
                    .eq(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_NEW)
                    .orderByAsc(HollowGlassRelationInfo::getHollowSequence)
                    .last("limit 1")
            );
        }
        HollowBigStorageCageDetails hollowDetails = hollowBigStorageCageDetailsService.getOne(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                .eq(HollowBigStorageCageDetails::getVirtualSlot, relationInfoOne.getVirtualSlot()).in(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL_ZERO)
                .orderByDesc(HollowBigStorageCageDetails::getSequence).last("limit 1"));
        //详情表内获取本组是否已经有玻璃在笼子内(0表示提前占用)
        List<HollowBigStorageCageDetails> hollowDetailsList = hollowBigStorageCageDetailsService.list(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                .eq(HollowBigStorageCageDetails::getFlowCardId, relationInfoOne.getFlowCardId())
                .eq(HollowBigStorageCageDetails::getTotalLayer, totalLayer)
                .eq(HollowBigStorageCageDetails::getLayer, layer)
                .eq(HollowBigStorageCageDetails::getVirtualSlot, relationInfoOne.getVirtualSlot())
                .in(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL_ZERO));
        HollowBigStorageCage storageCage = null;
        if (null == hollowDetails) {
        //如果不存在则选择笼内未用的新格子
        if (CollectionUtil.isEmpty(hollowDetailsList)) {
            storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper<HollowBigStorageCage>()
                    .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth).last("limit 1"));
                    .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth)
                    .le(HollowBigStorageCage::getMinThickness, relationInfoOne.getThickness())
                    .ge(HollowBigStorageCage::getMaxThickness, relationInfoOne.getThickness())
                    .orderByAsc(HollowBigStorageCage::getMaxThickness).last("limit 1"));
            HollowBigStorageDTO storageDTO = new HollowBigStorageDTO();
            BeanUtils.copyProperties(storageCage, storageDTO);
            BeanUtils.copyProperties(relationInfoOne, storageDTO);
            return storageDTO;
        }
        //获取当前组在笼子内的格子号(按照组内序号-1计算 如果没有则新开一格)
        HollowGlassRelationInfo relationInfoBefore = hollowGlassRelationInfoService.getOne(new LambdaQueryWrapper<HollowGlassRelationInfo>()
                .eq(HollowGlassRelationInfo::getFlowCardId, relationInfoOne.getFlowCardId())
                .eq(HollowGlassRelationInfo::getTotalLayer, relationInfoOne.getTotalLayer())
                .eq(HollowGlassRelationInfo::getLayer, relationInfoOne.getLayer())
                .eq(HollowGlassRelationInfo::getVirtualSlot, relationInfoOne.getVirtualSlot())
                .eq(HollowGlassRelationInfo::getSlotSequence, relationInfoOne.getSlotSequence() - 1));
        if (null == relationInfoBefore) {
            //表示序号没有或者  序号为1又不是第一块来的 新开一格
            storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper<HollowBigStorageCage>()
                    .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth).last("limit 1"));
                    .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth)
                    .le(HollowBigStorageCage::getMinThickness, relationInfoOne.getThickness())
                    .ge(HollowBigStorageCage::getMaxThickness, relationInfoOne.getThickness())
                    .orderByAsc(HollowBigStorageCage::getMaxThickness).last("limit 1"));
        } else {
            //获取详情表组内前一片玻璃的笼内详情数据
            HollowBigStorageCageDetails beforeGlass = hollowBigStorageCageDetailsService.getOne(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                    .in(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL_ZERO)
                    .eq(HollowBigStorageCageDetails::getEngineerId, relationInfoBefore.getEngineerId())
                    .eq(HollowBigStorageCageDetails::getTemperingLayoutId, relationInfoBefore.getTemperingLayoutId())
                    .eq(HollowBigStorageCageDetails::getTemperingFeedSequence, relationInfoBefore.getTemperingFeedSequence())
            );
            //改组在笼内有玻璃但是前一块玻璃没有:原因 玻璃破损处理
            if (null == beforeGlass) {
                storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper<HollowBigStorageCage>()
                        .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth).last("limit 1"));
                        .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth)
                        .le(HollowBigStorageCage::getMinThickness, relationInfoOne.getThickness())
                        .ge(HollowBigStorageCage::getMaxThickness, relationInfoOne.getThickness())
                        .orderByAsc(HollowBigStorageCage::getMaxThickness).last("limit 1"));
            } else {
                storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper<HollowBigStorageCage>()
                        .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getSlot, beforeGlass.getSlot()));
                //取出每组玻璃占用笼子的格子并计算格子内的最大组序号,避免玻璃顺序错乱
                List<HollowBigStorageCageDetails> hollowSequenceList = hollowBigStorageCageDetailsService
                        .querySlotMaxSequence(beforeGlass.getFlowCardId(), beforeGlass.getTotalLayer(), beforeGlass.getLayer(), beforeGlass.getVirtualSlot());
                for (HollowBigStorageCageDetails hollowBigStorageCageDetail : hollowSequenceList) {
                    if (relationInfoOne.getSlotSequence() - 1 == hollowBigStorageCageDetail.getSequence()) {
                        storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper<HollowBigStorageCage>()
                                .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getSlot, beforeGlass.getSlot()));
                        break;
                    }
                }
                if (storageCage == null) {
                    storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper<HollowBigStorageCage>()
                            .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth)
                            .le(HollowBigStorageCage::getMinThickness, relationInfoOne.getThickness())
                            .ge(HollowBigStorageCage::getMaxThickness, relationInfoOne.getThickness())
                            .orderByAsc(HollowBigStorageCage::getMaxThickness).last("limit 1"));
                }
            }
        }
        Assert.isTrue(null != storageCage, "没有空余的笼子存放玻璃");
@@ -200,6 +234,7 @@
                    hollow.setVirtualSlot(temp.get(0).getVirtualSlot());
                    hollow.setFilmsId(glassInfo.getFilmsid());
                    hollow.setThickness(glassInfo.getThickness());
                    hollow.setState(Const.HOLLOW_RELATION_NEW);
                    temp.add(hollow);
                    flag = true;
                    break;
@@ -214,6 +249,7 @@
                hollow.setVirtualSlot(slotNumber++);
                hollow.setFilmsId(glassInfo.getFilmsid());
                hollow.setThickness(glassInfo.getThickness());
                hollow.setState(Const.HOLLOW_RELATION_NEW);
                newList.add(hollow);
                tempHollowList.add(newList);
            }
@@ -226,9 +262,12 @@
    }
    @Override
    public Map<String, List<FlowCardGlassInfoDTO>> queryHollowAllFlowCard() {
    public Map<String, List<FlowCardGlassInfoDTO>> queryHollowAllFlowCard(HollowBigStorageDetailsQueryVO query) {
        List<HollowBigStorageCageDetails> detailsList = hollowBigStorageCageDetailsService.list(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                .eq(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN));
                .eq(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN)
                .like(StringUtils.isNotBlank(query.getFilmsId()), HollowBigStorageCageDetails::getFilmsId, query.getFilmsId())
                .like(StringUtils.isNotBlank(query.getFlowCardId()), HollowBigStorageCageDetails::getFlowCardId, query.getFlowCardId())
        );
        if (CollectionUtil.isEmpty(detailsList)) {
            log.info("笼内无玻璃");
            return new HashMap<>();
@@ -243,9 +282,16 @@
    }
    @Override
    public List<LackDetailsDTO> queryLackByFlowCard(String flowCardId, int layer) {
        return this.baseMapper.queryLackByFlowCard(flowCardId, layer);
    public Map<Integer, List<LackDetailsDTO>> queryLackByFlowCard(String flowCardId) {
        List<LackDetailsDTO> lackDetailsList = this.baseMapper.queryLackByFlowCard(flowCardId);
        Map<Integer, List<LackDetailsDTO>> listMap = lackDetailsList.stream().collect(Collectors.groupingBy(LackDetailsDTO::getLayer));
        return listMap;
    }
//    @Override
//    public List<LackDetailsDTO> queryLackByFlowCard(String flowCardId) {
//        List<LackDetailsDTO> lackDetailsList = this.baseMapper.queryLackByFlowCard(flowCardId);
//        return lackDetailsList;
//    }
}