package com.mes.hollow.service.impl;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
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.engineering.entity.Engineering;
|
import com.mes.engineering.mapper.EngineeringMapper;
|
import com.mes.glassinfo.entity.GlassInfo;
|
import com.mes.glassinfo.service.GlassInfoService;
|
import com.mes.hollow.entity.BigStorageCageHollow;
|
import com.mes.hollow.entity.HollowGlassInfo;
|
import com.mes.hollow.entity.HollowGlassRelationInfo;
|
import com.mes.hollow.mapper.HollowGlassInfoMapper;
|
import com.mes.hollow.service.BigStorageCageHollowService;
|
import com.mes.hollow.service.HollowGlassInfoService;
|
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.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* (HollowGlassInfo)表服务实现类
|
*
|
* @author makejava
|
* @since 2024-11-22 17:49:41
|
*/
|
|
@Slf4j
|
@Service
|
public class HollowGlassInfoServiceImpl extends ServiceImpl<HollowGlassInfoMapper, HollowGlassInfo> implements HollowGlassInfoService {
|
|
@Resource
|
GlassInfoService glassInfoService;
|
@Resource
|
EngineeringMapper engineeringMapper;
|
@Resource
|
BigStorageCageHollowService bigStorageCageHollowService;
|
@Resource
|
HollowGlassRelationInfoService hollowGlassRelationInfoService;
|
@Value("${mes.slotWidth}")
|
private Integer slotWidth;
|
@Value("${mes.glassGap}")
|
private Integer glassGap;
|
|
@Override
|
public int queryHollowTargetSlot(String glassId) {
|
//按照玻璃信息获取关系表中对应的大理片笼格子号
|
HollowGlassRelationInfo relationInfoOne = hollowGlassRelationInfoService.getOne(new LambdaQueryWrapper<HollowGlassRelationInfo>().eq(HollowGlassRelationInfo::getGlassId, glassId));
|
if (relationInfoOne != null) {
|
return relationInfoOne.getSlot();
|
}
|
//按照玻璃id获取中空信息表是否数据
|
HollowGlassInfo hollowGlassInfo = this.getOne(new LambdaQueryWrapper<HollowGlassInfo>().eq(HollowGlassInfo::getGlassId, glassId));
|
if (null == hollowGlassInfo) {
|
//按照玻璃id计算对应工程下所有玻璃的格子
|
generateHollowGlassInfo(glassId);
|
hollowGlassInfo = this.getOne(new LambdaQueryWrapper<HollowGlassInfo>().eq(HollowGlassInfo::getGlassId, glassId));
|
}
|
return hollowSlotPair(hollowGlassInfo);
|
}
|
|
@Override
|
public void generateHollowGlassInfo(String glassId) {
|
GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId));
|
List<HollowGlassInfo> list = this.list(new LambdaQueryWrapper<HollowGlassInfo>().eq(HollowGlassInfo::getFlowCardId, glassInfo.getFlowCardId()));
|
if (CollectionUtil.isNotEmpty(list)) {
|
return;
|
}
|
Engineering engineering = engineeringMapper.selectOne(new LambdaQueryWrapper<Engineering>()
|
.eq(Engineering::getEngineerId, glassInfo.getEngineerId()));
|
//获取玻璃的工程id,按照工程id获取工程下的所有玻璃信息
|
List<GlassInfo> glassInfoList = glassInfoService.listBySize(engineering.getEngineerId());
|
Map<String, List<GlassInfo>> flowCardIdMap = glassInfoList.stream().collect(Collectors.groupingBy(GlassInfo::getFlowCardId));
|
List<HollowGlassInfo> hollowGlassInfoList = new ArrayList<>();
|
//方式一:将玻璃按流程卡、尺寸、版图、版序 依次生成虚拟格子信息,格子一直往后累加
|
// 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<BigStorageCageHollow> hollowSlotList = bigStorageCageHollowService.list(new LambdaQueryWrapper<BigStorageCageHollow>()
|
// .eq(BigStorageCageHollow::getEnableState, Const.SLOT_ON).eq(BigStorageCageHollow::getRemainWidth, slotWidth));
|
//方式二:将玻璃按流程卡、尺寸、版图、版序 ,优先将格子全部补全后 依次计算后面的格子号
|
flowCardIdMap.forEach((e, v) -> {
|
List<List<HollowGlassInfo>> tempHollowList = new ArrayList<>();
|
int slotNumber = 1;
|
for (GlassInfo item : v) {
|
boolean flag = false;
|
for (List<HollowGlassInfo> temp : tempHollowList) {
|
int sum = 0;
|
for (HollowGlassInfo i : temp) {
|
sum = sum + (int) Math.max(i.getHeight(), i.getWidth()) + glassGap;
|
}
|
if (sum + (int) Math.max(item.getHeight(), item.getWidth()) <= slotWidth) {
|
HollowGlassInfo hollow = new HollowGlassInfo();
|
BeanUtils.copyProperties(item, hollow);
|
hollow.setSlotSequence(temp.size() + 1);
|
hollow.setVirtualSlot(temp.get(0).getVirtualSlot());
|
temp.add(hollow);
|
flag = true;
|
break;
|
}
|
}
|
if (!flag) {
|
List<HollowGlassInfo> newList = new ArrayList<>();
|
HollowGlassInfo hollow = new HollowGlassInfo();
|
BeanUtils.copyProperties(item, hollow);
|
hollow.setSlotSequence(1);
|
hollow.setVirtualSlot(slotNumber++);
|
newList.add(hollow);
|
tempHollowList.add(newList);
|
}
|
}
|
for (List<HollowGlassInfo> item : tempHollowList) {
|
hollowGlassInfoList.addAll(item);
|
}
|
|
});
|
log.info("分配完毕");
|
this.saveBatch(hollowGlassInfoList);
|
}
|
|
@Override
|
public int hollowSlotPair(HollowGlassInfo hollowGlassInfo) {
|
//获取所有空闲可用的格子号
|
BigStorageCageHollow storageCageHollow = bigStorageCageHollowService.getOne(new LambdaQueryWrapper<BigStorageCageHollow>()
|
.eq(BigStorageCageHollow::getEnableState, Const.SLOT_ON).eq(BigStorageCageHollow::getRemainWidth, slotWidth).last("limit 1"));
|
Integer slot = storageCageHollow.getSlot();
|
//获取该工程同一流程卡同一车的玻璃信息
|
List<HollowGlassInfo> hollowGlassInfoList = this.list(new LambdaQueryWrapper<HollowGlassInfo>().eq(HollowGlassInfo::getFlowCardId, hollowGlassInfo.getFlowCardId())
|
.eq(HollowGlassInfo::getVirtualSlot, hollowGlassInfo.getVirtualSlot()));
|
//设置关系表的实际格子号
|
List<HollowGlassRelationInfo> relationInfoList = hollowGlassInfoList.stream().map(e -> {
|
HollowGlassRelationInfo info = new HollowGlassRelationInfo();
|
BeanUtils.copyProperties(e, info);
|
info.setSlot(slot);
|
return info;
|
}).collect(Collectors.toList());
|
//保存关系表
|
hollowGlassRelationInfoService.saveBatch(relationInfoList);
|
//返回格子信息
|
return slot;
|
}
|
}
|