package com.mes.hollow.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.Assert; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mes.common.config.Const; import com.mes.glassinfo.entity.GlassInfo; import com.mes.glassinfo.service.GlassInfoService; import com.mes.hollow.entity.HollowBigStorageCage; import com.mes.hollow.entity.HollowBigStorageCageDetails; import com.mes.hollow.entity.HollowGlassRelationInfo; import com.mes.hollow.entity.dto.FlowCardGlassInfoDTO; 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.mapper.HollowGlassRelationInfoMapper; import com.mes.hollow.service.HollowBigStorageCageDetailsService; import com.mes.hollow.service.HollowBigStorageCageService; import com.mes.hollow.service.HollowGlassRelationInfoService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * (HollowGlassRelationInfo)表服务实现类 * * @author makejava * @since 2024-11-23 15:59:30 */ @Service @Slf4j public class HollowGlassRelationInfoServiceImpl extends ServiceImpl implements HollowGlassRelationInfoService { @Resource GlassInfoService glassInfoService; @Resource HollowBigStorageCageService hollowBigStorageCageService; @Resource HollowGlassRelationInfoService hollowGlassRelationInfoService; @Resource HollowBigStorageCageDetailsService hollowBigStorageCageDetailsService; @Value("${mes.slotWidth}") private Integer slotWidth; @Value("${mes.glassGap}") private Integer glassGap; @Value("${mes.outCarMaxSize}") private Integer outCarMaxSize; @Override public HollowBigStorageDTO queryHollowTargetSlot(String flowCardId, double width, double height, int totalLayer, int layer) { //按照玻璃信息获取关系表中对应的大理片笼格子号 HollowGlassRelationInfo relationInfoOne = hollowGlassRelationInfoService.getOne(new LambdaQueryWrapper() .eq(HollowGlassRelationInfo::getFlowCardId, flowCardId) .eq(HollowGlassRelationInfo::getWidth, width) .eq(HollowGlassRelationInfo::getHeight, height) .eq(HollowGlassRelationInfo::getLayer, layer) .isNull(HollowGlassRelationInfo::getTemperingLayoutId) .isNull(HollowGlassRelationInfo::getTemperingFeedSequence) .orderByAsc(HollowGlassRelationInfo::getHollowSequence) .last("limit 1") ); if (relationInfoOne == null) { //理片笼关系表中没有对应的数据,查看理片笼虚拟位置表是否有本工程下的所有玻璃虚拟信息 //虚拟位置表没有本工程下的所有玻璃虚拟信息,按照玻璃id生成本工程下所有玻璃的虚拟信息 generateHollowGlassInfo(flowCardId, totalLayer, layer); relationInfoOne = this.getOne(new LambdaQueryWrapper() .eq(HollowGlassRelationInfo::getFlowCardId, flowCardId) .eq(HollowGlassRelationInfo::getWidth, width) .eq(HollowGlassRelationInfo::getHeight, height) .eq(HollowGlassRelationInfo::getLayer, layer) .isNull(HollowGlassRelationInfo::getTemperingLayoutId) .isNull(HollowGlassRelationInfo::getTemperingFeedSequence) .orderByAsc(HollowGlassRelationInfo::getHollowSequence) .last("limit 1") ); } HollowBigStorageCageDetails hollowDetails = hollowBigStorageCageDetailsService.getOne(new LambdaQueryWrapper() .eq(HollowBigStorageCageDetails::getSlot, relationInfoOne.getVirtualSlot()).in(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL_ZERO) .orderByDesc(HollowBigStorageCageDetails::getSequence).last("limit 1")); HollowBigStorageCage storageCage = null; if (null == hollowDetails) { storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper() .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth).last("limit 1")); HollowBigStorageDTO storageDTO = new HollowBigStorageDTO(); BeanUtils.copyProperties(storageCage, storageDTO); BeanUtils.copyProperties(relationInfoOne, storageDTO); return storageDTO; } HollowGlassRelationInfo relationInfoBefore = hollowGlassRelationInfoService.getOne(new LambdaQueryWrapper() .eq(HollowGlassRelationInfo::getEngineerId, relationInfoOne.getEngineerId()) .eq(HollowGlassRelationInfo::getTemperingLayoutId, relationInfoOne.getTemperingLayoutId()) .eq(HollowGlassRelationInfo::getVirtualSlot, relationInfoOne.getVirtualSlot()) .eq(HollowGlassRelationInfo::getSlotSequence, relationInfoOne.getSlotSequence() - 1)); if (null == relationInfoBefore) { //表示序号没有或者 序号为1又不是第一块来的 新开一格 storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper() .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth).last("limit 1")); } else { HollowBigStorageCageDetails beforeGlass = hollowBigStorageCageDetailsService.getOne(new LambdaQueryWrapper() .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() .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth).last("limit 1")); } else { storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper() .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getSlot, beforeGlass.getSlot())); } } Assert.isTrue(null != storageCage, "没有空余的笼子存放玻璃"); HollowBigStorageDTO storageDTO = new HollowBigStorageDTO(); BeanUtils.copyProperties(storageCage, storageDTO); BeanUtils.copyProperties(relationInfoOne, storageDTO); return storageDTO; } @Override public void generateHollowGlassInfo(String flowCardId, int totalLayer, int layer) { GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper().eq(GlassInfo::getFlowCardId, flowCardId) .eq(GlassInfo::getLayer, layer).last("limit 1")); if (null == glassInfo) { log.info("当前流程卡信息为导入mes系统流程卡:{},层数{}", flowCardId, layer); return; } //按照流程卡获取本流程卡最后一层或第一次的玻璃数据 List glassDetailsDTOS = this.baseMapper.queryFlowCardIdMaxLayerGlassInfo(flowCardId, totalLayer); if (CollectionUtil.isEmpty(glassDetailsDTOS)) { log.info("当前流程卡最外层数据未找到,请在erp确认数据无误,流程卡:{},总层数{}", flowCardId, totalLayer); return; } if (totalLayer != layer) { glassDetailsDTOS = this.baseMapper.queryFlowCardIdLayerGlassInfo(flowCardId, totalLayer, layer); } if (CollectionUtil.isEmpty(glassDetailsDTOS)) { log.info("当前流程卡最外层数据未找到,请在erp确认数据无误,流程卡:{},总层数{},层数{}", flowCardId, totalLayer, layer); return; } ArrayList tempGlassList = new ArrayList<>(); int hollowSequence = 1; for (HollowGlassDetailsDTO item : glassDetailsDTOS) { for (int i = 0; i < item.getQuantity(); i++) { HollowGlassDetailsDTO dto = new HollowGlassDetailsDTO(); BeanUtils.copyProperties(item, dto); dto.setHollowSequence(hollowSequence++); tempGlassList.add(dto); } } //方式一:将玻璃按流程卡、尺寸、版图、版序 依次生成虚拟格子信息,格子一直往后累加 // flowCardIdMap.forEach((e, v) -> { // int remainWidth = slotWidth; // int slotNumber = 1; // for (GlassInfo item : v) { // int maxLength = (int) Math.max(item.getWidth(), item.getHeight()); // if (remainWidth > maxLength) { // remainWidth = remainWidth - maxLength - glassGap; // } else { // slotNumber = slotNumber + 1; // remainWidth = slotWidth - maxLength - glassGap; // } // HollowGlassInfo hollow = new HollowGlassInfo(); // BeanUtils.copyProperties(item, hollow); // hollow.setSlot(slotNumber); // hollowGlassInfoList.add(hollow); // } // }); // this.saveBatch(hollowGlassInfoList); //获取中空大理片笼的所有空闲格子 // List hollowSlotList = HollowBigStorageCageService.list(new LambdaQueryWrapper() // .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth)); //方式二:将玻璃按流程卡、尺寸、版图、版序 ,优先将格子全部补全后 依次计算后面的格子号 List relationInfoList = new ArrayList(); List> tempHollowList = new ArrayList<>(); int slotNumber = 1; for (HollowGlassDetailsDTO item : tempGlassList) { boolean flag = false; for (List temp : tempHollowList) { int sum = 0; for (HollowGlassRelationInfo i : temp) { sum = sum + (int) Math.max(i.getHeight(), i.getWidth()) + glassGap; } if (sum + (int) Math.max(item.getHeight(), item.getWidth()) <= slotWidth && temp.size() < outCarMaxSize) { HollowGlassRelationInfo hollow = new HollowGlassRelationInfo(); BeanUtils.copyProperties(item, hollow); hollow.setSlotSequence(temp.size() + 1); hollow.setTotalLayer(totalLayer); hollow.setVirtualSlot(temp.get(0).getVirtualSlot()); hollow.setFilmsId(glassInfo.getFilmsid()); hollow.setThickness(glassInfo.getThickness()); temp.add(hollow); flag = true; break; } } if (!flag) { List newList = new ArrayList<>(); HollowGlassRelationInfo hollow = new HollowGlassRelationInfo(); BeanUtils.copyProperties(item, hollow); hollow.setSlotSequence(1); hollow.setTotalLayer(totalLayer); hollow.setVirtualSlot(slotNumber++); hollow.setFilmsId(glassInfo.getFilmsid()); hollow.setThickness(glassInfo.getThickness()); newList.add(hollow); tempHollowList.add(newList); } } for (List item : tempHollowList) { relationInfoList.addAll(item); } log.info("分配完毕"); this.saveBatch(relationInfoList); } @Override public Map> queryHollowAllFlowCard() { List detailsList = hollowBigStorageCageDetailsService.list(new LambdaQueryWrapper() .eq(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN)); if (CollectionUtil.isEmpty(detailsList)) { log.info("笼内无玻璃"); return new HashMap<>(); } Map> listMap = detailsList.stream().collect(Collectors.groupingBy(HollowBigStorageCageDetails::getFlowCardId)); List dtos = new ArrayList<>(); listMap.forEach((e, v) -> { HollowBigStorageCageDetails cageDetails = v.get(0); dtos.addAll(hollowBigStorageCageDetailsService.hollowIsAll(e, cageDetails.getTotalLayer(), Boolean.FALSE)); }); return dtos.stream().collect(Collectors.groupingBy(FlowCardGlassInfoDTO::getFlowCardId)); } @Override public List queryLackByFlowCard(String flowCardId, int layer) { return this.baseMapper.queryLackByFlowCard(flowCardId, layer); // return this.list(new LambdaQueryWrapper() // .eq(HollowGlassRelationInfo::getFlowCardId,flowCardId) // .eq(HollowGlassRelationInfo::getLayer,layer) // .isNull(HollowGlassRelationInfo::getTemperingLayoutId) // .isNull(HollowGlassRelationInfo::getTemperingFeedSequence) // ); } }