From cf33278c73767f72e35a4898c23765f52a3bfd1d Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期二, 03 十二月 2024 09:06:02 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/ywMes'
---
hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/bigstorage/service/impl/BigStorageGlassInfoServiceImpl.java | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 200 insertions(+), 0 deletions(-)
diff --git a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/bigstorage/service/impl/BigStorageGlassInfoServiceImpl.java b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/bigstorage/service/impl/BigStorageGlassInfoServiceImpl.java
new file mode 100644
index 0000000..9586097
--- /dev/null
+++ b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/bigstorage/service/impl/BigStorageGlassInfoServiceImpl.java
@@ -0,0 +1,200 @@
+package com.mes.bigstorage.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.bigstorage.entity.BigStorageCage;
+import com.mes.bigstorage.entity.BigStorageCageDetails;
+import com.mes.bigstorage.entity.BigStorageGlassInfo;
+import com.mes.bigstorage.entity.BigStorageGlassRelationInfo;
+import com.mes.bigstorage.entity.dto.BigStorageDTO;
+import com.mes.bigstorage.mapper.BigStorageGlassInfoMapper;
+import com.mes.bigstorage.service.BigStorageCageDetailsService;
+import com.mes.bigstorage.service.BigStorageCageService;
+import com.mes.bigstorage.service.BigStorageGlassInfoService;
+import com.mes.bigstorage.service.BigStorageGlassRelationInfoService;
+import com.mes.common.config.Const;
+import com.mes.glassinfo.entity.GlassInfo;
+import com.mes.glassinfo.service.GlassInfoService;
+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;
+
+/**
+ * (BigStorageGlassInfo)琛ㄦ湇鍔″疄鐜扮被
+ *
+ * @author makejava
+ * @since 2024-11-24 10:15:35
+ */
+@Service
+@Slf4j
+public class BigStorageGlassInfoServiceImpl extends ServiceImpl<BigStorageGlassInfoMapper, BigStorageGlassInfo> implements BigStorageGlassInfoService {
+ @Resource
+ GlassInfoService glassInfoService;
+ @Resource
+ BigStorageCageService bigStorageCageService;
+ @Resource
+ BigStorageCageDetailsService bigStorageCageDetailsService;
+ @Resource
+ BigStorageGlassRelationInfoService bigStorageGlassRelationInfoService;
+ @Value("${mes.slotWidth}")
+ private Integer slotWidth;
+ @Value("${mes.glassGap}")
+ private Integer glassGap;
+ @Value("${mes.outCarMaxSize}")
+ private Integer outCarMaxSize;
+
+ @Override
+ public BigStorageDTO queryBigStorageTargetSlot(String engineerId, Integer temperingLayoutId, Integer temperingFeedSequence) {
+ //鎸夌収鐜荤拑淇℃伅鑾峰彇鍏崇郴琛ㄦ槸鍚︽湁瀵瑰簲鐨勫叧绯�
+ BigStorageGlassRelationInfo relationInfoOne = bigStorageGlassRelationInfoService.getOne(new LambdaQueryWrapper<BigStorageGlassRelationInfo>()
+ .eq(BigStorageGlassRelationInfo::getEngineerId, engineerId)
+ .eq(BigStorageGlassRelationInfo::getTemperingLayoutId, temperingLayoutId)
+ .eq(BigStorageGlassRelationInfo::getTemperingFeedSequence, temperingFeedSequence)
+ );
+ if (relationInfoOne == null) {
+ //鐞嗙墖绗煎叧绯昏〃涓病鏈夊搴旂殑鏁版嵁锛屾煡鐪嬬悊鐗囩铏氭嫙浣嶇疆琛ㄦ槸鍚︽湁鏈伐绋嬩笅鐨勬墍鏈夌幓鐠冭櫄鎷熶俊鎭�
+ BigStorageGlassInfo bigStorageGlassInfo = this.getOne(new LambdaQueryWrapper<BigStorageGlassInfo>()
+ .eq(BigStorageGlassInfo::getEngineerId, engineerId)
+ .eq(BigStorageGlassInfo::getTemperingLayoutId, temperingLayoutId)
+ .eq(BigStorageGlassInfo::getTemperingFeedSequence, temperingFeedSequence));
+ if (null == bigStorageGlassInfo) {
+ //铏氭嫙浣嶇疆琛ㄦ病鏈夋湰宸ョ▼涓嬬殑鎵�鏈夌幓鐠冭櫄鎷熶俊鎭紝鎸夌収鐜荤拑id鐢熸垚鏈伐绋嬩笅鎵�鏈夌幓鐠冪殑铏氭嫙淇℃伅
+ generateBigStorageGlassInfo(engineerId, temperingLayoutId);
+ bigStorageGlassInfo = this.getOne(new LambdaQueryWrapper<BigStorageGlassInfo>()
+ .eq(BigStorageGlassInfo::getEngineerId, engineerId)
+ .eq(BigStorageGlassInfo::getTemperingLayoutId, temperingLayoutId)
+ .eq(BigStorageGlassInfo::getTemperingFeedSequence, temperingFeedSequence));
+ }
+ //鎸夌収铏氭嫙浣嶇疆鍜屽ぇ鐞嗙墖绗肩幇鏈夊彲鐢ㄦ牸瀛愮敓鎴愬叧绯昏〃
+ bigStorageSlotPair(bigStorageGlassInfo);
+ //鍏崇郴琛ㄨ幏鍙栧疄闄呬綅缃�
+ relationInfoOne = bigStorageGlassRelationInfoService.getOne(new LambdaQueryWrapper<BigStorageGlassRelationInfo>()
+ .eq(BigStorageGlassRelationInfo::getEngineerId, engineerId)
+ .eq(BigStorageGlassRelationInfo::getTemperingLayoutId, temperingLayoutId)
+ .eq(BigStorageGlassRelationInfo::getTemperingFeedSequence, temperingFeedSequence));
+ }
+ BigStorageCageDetails bigStorageCageDetails = bigStorageCageDetailsService.getOne(new LambdaQueryWrapper<BigStorageCageDetails>()
+ .eq(BigStorageCageDetails::getSlot, relationInfoOne.getSlot()).in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL_ZERO)
+ .orderByDesc(BigStorageCageDetails::getSequence).last("limit 1"));
+ if (null == bigStorageCageDetails) {
+ BigStorageDTO storageDTO = new BigStorageDTO();
+ storageDTO.setDeviceId(relationInfoOne.getDeviceId());
+ storageDTO.setSlot(relationInfoOne.getSlot());
+ storageDTO.setSlotSequence(relationInfoOne.getSlotSequence());
+ storageDTO.setWidth(slotWidth);
+ return storageDTO;
+ }
+ BigStorageGlassRelationInfo relationInfoBefore = bigStorageGlassRelationInfoService.getOne(new LambdaQueryWrapper<BigStorageGlassRelationInfo>()
+ .eq(BigStorageGlassRelationInfo::getEngineerId, relationInfoOne.getEngineerId())
+ .eq(BigStorageGlassRelationInfo::getTemperingLayoutId, relationInfoOne.getTemperingLayoutId())
+ .eq(BigStorageGlassRelationInfo::getVirtualSlot, relationInfoOne.getVirtualSlot())
+ .eq(BigStorageGlassRelationInfo::getSlotSequence, relationInfoOne.getSlotSequence() - 1));
+ BigStorageCage storageCage = null;
+ if (null == relationInfoBefore) {
+ //琛ㄧず搴忓彿娌℃湁鎴栬�� 搴忓彿涓�1鍙堜笉鏄涓�鍧楁潵鐨� 鏂板紑涓�鏍�
+ storageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>()
+ .eq(BigStorageCage::getEnableState, Const.SLOT_ON).eq(BigStorageCage::getRemainWidth, slotWidth).orderByAsc(BigStorageCage::getSlot).last("limit 1"));
+ } else {
+ BigStorageCageDetails beforeGlass = bigStorageCageDetailsService.getOne(new LambdaQueryWrapper<BigStorageCageDetails>()
+ .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL_ZERO)
+ .eq(BigStorageCageDetails::getEngineerId, relationInfoBefore.getEngineerId())
+ .eq(BigStorageCageDetails::getTemperingLayoutId, relationInfoBefore.getTemperingLayoutId())
+ .eq(BigStorageCageDetails::getTemperingFeedSequence, relationInfoBefore.getTemperingFeedSequence())
+ );
+ if (null == beforeGlass) {
+ storageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>()
+ .eq(BigStorageCage::getEnableState, Const.SLOT_ON).eq(BigStorageCage::getRemainWidth, slotWidth).orderByAsc(BigStorageCage::getSlot).last("limit 1"));
+ } else {
+ storageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>()
+ .eq(BigStorageCage::getEnableState, Const.SLOT_ON).eq(BigStorageCage::getSlot, beforeGlass.getSlot()));
+ }
+ }
+ Assert.isTrue(null != storageCage, "娌℃湁绌轰綑鐨勭瀛愬瓨鏀剧幓鐠�");
+ BigStorageDTO storageDTO = new BigStorageDTO();
+ storageDTO.setDeviceId(storageCage.getDeviceId());
+ storageDTO.setSlotSequence(relationInfoOne.getSlotSequence());
+ storageDTO.setSlot(storageCage.getSlot());
+ storageDTO.setWidth(storageCage.getRemainWidth());
+ return storageDTO;
+ }
+
+ @Override
+ public void generateBigStorageGlassInfo(String engineerId, int temperingLayoutId) {
+ List<BigStorageGlassInfo> list = this.list(new LambdaQueryWrapper<BigStorageGlassInfo>()
+ .eq(BigStorageGlassInfo::getEngineerId, engineerId).eq(BigStorageGlassInfo::getTemperingLayoutId, temperingLayoutId));
+ if (CollectionUtil.isNotEmpty(list)) {
+ return;
+ }
+// Engineering engineering = engineeringMapper.selectOne(new LambdaQueryWrapper<Engineering>()
+// .eq(Engineering::getEngineerId, glassInfo.getEngineerId()));
+ //鑾峰彇鐜荤拑鐨勫伐绋媔d锛屾寜鐓у伐绋媔d鑾峰彇宸ョ▼涓嬬殑鎵�鏈夌幓鐠冧俊鎭�
+ List<GlassInfo> glassInfoList = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>()
+ .eq(GlassInfo::getEngineerId, engineerId)
+ .orderByAsc(GlassInfo::getTemperingLayoutId).orderByAsc(GlassInfo::getTemperingFeedSequence));
+ Map<Integer, List<GlassInfo>> trmperingIdMap = glassInfoList.stream().collect(Collectors.groupingBy(GlassInfo::getTemperingLayoutId));
+ List<BigStorageGlassInfo> bigStorageGlassInfoList = new ArrayList<>();
+ //鏂瑰紡涓�锛氬皢鐜荤拑鎸夌増鍥俱�佺増搴� 渚濇鐢熸垚铏氭嫙鏍煎瓙淇℃伅锛屾牸瀛愪竴鐩村線鍚庣疮鍔�
+ trmperingIdMap.forEach((e, v) -> {
+ int remainWidth = slotWidth;
+ int slotNumber = 1;
+ int slotSequence = 1;
+ for (GlassInfo item : v) {
+ int maxLength = (int) Math.max(item.getWidth(), item.getHeight());
+ if (remainWidth > maxLength && slotSequence <= outCarMaxSize) {
+ remainWidth = remainWidth - maxLength - glassGap;
+ } else {
+ slotNumber = slotNumber + 1;
+ slotSequence = 1;
+ remainWidth = slotWidth - maxLength - glassGap;
+ }
+ BigStorageGlassInfo bigStorage = new BigStorageGlassInfo();
+ BeanUtils.copyProperties(item, bigStorage);
+ bigStorage.setVirtualSlot(slotNumber);
+ bigStorage.setSlotSequence(slotSequence++);
+ bigStorage.setId(null);
+ bigStorageGlassInfoList.add(bigStorage);
+ }
+ });
+ this.saveBatch(bigStorageGlassInfoList);
+ log.info("鍒嗛厤瀹屾瘯");
+
+ }
+
+ @Override
+ public int bigStorageSlotPair(BigStorageGlassInfo bigStorageGlassInfo) {
+ //鑾峰彇鎵�鏈夌┖闂插彲鐢ㄧ殑鏍煎瓙鍙�
+ BigStorageCage storageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>()
+ .eq(BigStorageCage::getEnableState, Const.SLOT_ON).eq(BigStorageCage::getRemainWidth, slotWidth).orderByAsc(BigStorageCage::getSlot).last("limit 1"));
+ Assert.isTrue(null != storageCage, "娌℃湁绌轰綑鐨勭瀛愬瓨鏀剧幓鐠�");
+ Integer slot = storageCage.getSlot();
+ //鑾峰彇璇ュ伐绋嬪悓涓�娴佺▼鍗″悓涓�杞︾殑鐜荤拑淇℃伅
+ List<BigStorageGlassInfo> bigStorageGlassInfoList = this.list(new LambdaQueryWrapper<BigStorageGlassInfo>()
+ .eq(BigStorageGlassInfo::getEngineerId, bigStorageGlassInfo.getEngineerId())
+ .eq(BigStorageGlassInfo::getTemperingLayoutId, bigStorageGlassInfo.getTemperingLayoutId())
+ .eq(BigStorageGlassInfo::getVirtualSlot, bigStorageGlassInfo.getVirtualSlot()));
+ //璁剧疆鍏崇郴琛ㄧ殑瀹為檯鏍煎瓙鍙�
+ List<BigStorageGlassRelationInfo> relationInfoList = bigStorageGlassInfoList.stream().map(e -> {
+ BigStorageGlassRelationInfo info = new BigStorageGlassRelationInfo();
+ BeanUtils.copyProperties(e, info);
+ info.setSlot(slot);
+ info.setDeviceId(storageCage.getDeviceId());
+ return info;
+ }).collect(Collectors.toList());
+ //淇濆瓨鍏崇郴琛�
+ bigStorageGlassRelationInfoService.saveBatch(relationInfoList);
+ //杩斿洖鏍煎瓙淇℃伅
+ return slot;
+ }
+
+
+}
+
--
Gitblit v1.8.0