From e782b38bd2fbe97b140b6bdd450d2c3d299f4b0b Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期四, 04 九月 2025 13:55:42 +0800
Subject: [PATCH] 1、中空查询任务时增加耗时日志,排查查询慢的原因

---
 hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/hollow/service/impl/HollowGlassRelationInfoServiceImpl.java |  133 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 102 insertions(+), 31 deletions(-)

diff --git a/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/hollow/service/impl/HollowGlassRelationInfoServiceImpl.java b/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/hollow/service/impl/HollowGlassRelationInfoServiceImpl.java
index 5b12e1a..bc1dae1 100644
--- a/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/hollow/service/impl/HollowGlassRelationInfoServiceImpl.java
+++ b/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/hollow/service/impl/HollowGlassRelationInfoServiceImpl.java
@@ -7,16 +7,15 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.mes.common.config.Const;
 import com.mes.common.config.ConstSysConfig;
+import com.mes.damage.entity.request.DamageRequest;
+import com.mes.damage.service.DamageService;
 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.HollowGlassOutRelationInfo;
 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.entity.dto.*;
 import com.mes.hollow.entity.vo.HollowAllFlowCardVO;
 import com.mes.hollow.entity.vo.HollowBigStorageDetailsQueryVO;
 import com.mes.hollow.mapper.HollowGlassRelationInfoMapper;
@@ -30,10 +29,11 @@
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import java.math.BigInteger;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -58,6 +58,8 @@
     HollowBigStorageCageDetailsService hollowBigStorageCageDetailsService;
     @Resource
     SysConfigService sysConfigService;
+    @Resource
+    DamageService damageService;
 //    @Value("${mes.slotWidth}")
 //    private Integer slotWidth;
 //    @Value("${mes.glassGap}")
@@ -67,12 +69,12 @@
 //    private Integer outCarMaxSize;
 
     @Override
-    public HollowBigStorageDTO queryHollowTargetSlot(String flowCardId, double width, double height, int totalLayer, int layer) {
+    public HollowBigStorageDTO queryHollowTargetSlot(String flowCardId, Integer glassType, double width, double height, int totalLayer, int layer) {
+        log.info("鐜荤拑娴佺▼鍗★細{}锛屽簭鍙凤細{}锛屾�诲眰鏁帮細{}锛屽眰鏁帮細{}", flowCardId, glassType, totalLayer, layer);
         //鎸夌収鐜荤拑淇℃伅鑾峰彇鍏崇郴琛ㄤ腑瀵瑰簲鐨勫ぇ鐞嗙墖绗兼牸瀛愬彿
         HollowGlassRelationInfo relationInfoOne = hollowGlassRelationInfoService.getOne(new LambdaQueryWrapper<HollowGlassRelationInfo>()
                 .eq(HollowGlassRelationInfo::getFlowCardId, flowCardId)
-                .eq(HollowGlassRelationInfo::getWidth, width)
-                .eq(HollowGlassRelationInfo::getHeight, height)
+                .eq(HollowGlassRelationInfo::getOrderSort, glassType)
                 .eq(HollowGlassRelationInfo::getTotalLayer, totalLayer)
                 .eq(HollowGlassRelationInfo::getLayer, layer)
                 .eq(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_NEW)
@@ -94,8 +96,7 @@
             //铏氭嫙浣嶇疆琛ㄦ病鏈夋湰宸ョ▼涓嬬殑鎵�鏈夌幓鐠冭櫄鎷熶俊鎭紝鎸夌収鐜荤拑id鐢熸垚鏈伐绋嬩笅鎵�鏈夌幓鐠冪殑铏氭嫙淇℃伅
             relationInfoOne = this.getOne(new LambdaQueryWrapper<HollowGlassRelationInfo>()
                     .eq(HollowGlassRelationInfo::getFlowCardId, flowCardId)
-                    .eq(HollowGlassRelationInfo::getWidth, width)
-                    .eq(HollowGlassRelationInfo::getHeight, height)
+                    .eq(HollowGlassRelationInfo::getOrderSort, glassType)
                     .eq(HollowGlassRelationInfo::getTotalLayer, totalLayer)
                     .eq(HollowGlassRelationInfo::getLayer, layer)
                     .eq(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_NEW)
@@ -103,6 +104,7 @@
                     .last("limit 1")
             );
         }
+        Assert.isTrue(null != relationInfoOne, "鐩稿叧娴佺▼鍗℃湭鎵惧埌瀵瑰簲鐨勭粍鍙蜂俊鎭紝鐜荤拑娴佺▼鍗★細{}锛屽簭鍙凤細{}锛屾�诲眰鏁帮細{}锛屽眰鏁帮細{}", flowCardId, glassType, totalLayer, layer);
         Integer slotWidth = sysConfigService.queryConfigValue(ConstSysConfig.HOLLOW_SLOT_WIDTH);
         //璇︽儏琛ㄥ唴鑾峰彇鏈粍鏄惁宸茬粡鏈夌幓鐠冨湪绗煎瓙鍐咃紙0琛ㄧず鎻愬墠鍗犵敤锛�
         int taskCount = hollowGlassOutRelationInfoService.count(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
@@ -250,7 +252,8 @@
         //鏂瑰紡浜岋細灏嗙幓鐠冩寜娴佺▼鍗°�佸昂瀵搞�佺増鍥俱�佺増搴� 锛屼紭鍏堝皢鏍煎瓙鍏ㄩ儴琛ュ叏鍚� 渚濇璁$畻鍚庨潰鐨勬牸瀛愬彿
 
         Integer slotWidth = sysConfigService.queryConfigValue(ConstSysConfig.HOLLOW_SLOT_WIDTH);
-        Integer glassGap = sysConfigService.queryConfigValue(ConstSysConfig.HOLLOW_GLASS_GAP);
+//        Integer glassGap = sysConfigService.queryConfigValue(ConstSysConfig.HOLLOW_GLASS_GAP);
+        Integer glassGap = getGlassGapByThickness(glassInfo.getThickness());
         Integer outCarMaxSize = sysConfigService.queryConfigValue(ConstSysConfig.HOLLOW_OUT_CAR_SIZE);
         List<HollowGlassRelationInfo> relationInfoList = new ArrayList();
         List<List<HollowGlassRelationInfo>> tempHollowList = new ArrayList<>();
@@ -299,6 +302,8 @@
 
     @Override
     public List<HollowAllFlowCardVO> queryHollowAllFlowCard(HollowBigStorageDetailsQueryVO query) {
+        Date startDate = new Date();
+        log.info("寮�濮嬫煡璇腑绌烘祦绋嬪崱浠诲姟淇℃伅锛屽紑濮嬫椂闂磠}", startDate);
         List<HollowBigStorageCageDetails> detailsList = hollowBigStorageCageDetailsService.list(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                 .eq(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN)
                 .like(StringUtils.isNotBlank(query.getFilmsId()), HollowBigStorageCageDetails::getFilmsId, query.getFilmsId())
@@ -310,26 +315,41 @@
             log.info("绗煎唴鏃犵幓鐠�");
             return new ArrayList<>();
         }
+        Date middleDate = new Date();
+        log.info("涓┖鐞嗙墖绗艰鎯呮暟鎹凡鏌ヨ瀹屾瘯锛岃�楁椂:{}ms", middleDate.getTime() - startDate.getTime());
         Map<String, List<HollowBigStorageCageDetails>> listMap = detailsList.stream().collect(Collectors.groupingBy(HollowBigStorageCageDetails::getFlowCardId));
         List<HollowAllFlowCardVO> resultList = new ArrayList<>();
+        AtomicInteger pairTotalCount = new AtomicInteger();
         listMap.forEach((e, v) -> {
             HollowAllFlowCardVO hollowAllFlowCardVO = new HollowAllFlowCardVO();
             HollowBigStorageCageDetails cageDetails = v.get(0);
-            hollowAllFlowCardVO.setFlowCardId(e);
-            if (cageDetails.getHollowSequence() == 0) {
-                hollowAllFlowCardVO.setIsThroughSlot(Boolean.TRUE);
-            } else {
-                hollowAllFlowCardVO.setIsThroughSlot(Boolean.FALSE);
-            }
             //鎸夌収娴佺▼鍗¤幏鍙栧搴旂殑浜у搧鍚嶇О
-            String productName = baseMapper.queryProductNameByFlowCardId(cageDetails.getFlowCardId());
-            hollowAllFlowCardVO.setProductName(productName);
-            List<FlowCardGlassInfoDTO> flowCardInfoList = hollowBigStorageCageDetailsService.hollowIsAll(e, cageDetails.getTotalLayer(), Boolean.FALSE);
-            hollowAllFlowCardVO.setFlowCardGlassInfoDTOList(flowCardInfoList);
-            resultList.add(hollowAllFlowCardVO);
+            OrderDetailsDTO orderDetails = baseMapper.queryProductNameByFlowCardId(cageDetails.getFlowCardId(), query.getProductName(), query.getCustomerName());
+            if (null != orderDetails) {
+                BeanUtils.copyProperties(orderDetails, hollowAllFlowCardVO);
+                hollowAllFlowCardVO.setFlowCardId(e);
+                if (cageDetails.getHollowSequence() == 0) {
+                    hollowAllFlowCardVO.setIsThroughSlot(Boolean.TRUE);
+                } else {
+                    hollowAllFlowCardVO.setIsThroughSlot(Boolean.FALSE);
+                }
+                List<FlowCardGlassInfoDTO> flowCardInfoList = hollowBigStorageCageDetailsService.hollowIsAll(e, cageDetails.getTotalLayer(), Boolean.FALSE);
+                log.info("鑾峰彇鍒扮殑娴佺▼鍗′俊鎭负:{}", flowCardInfoList);
+                if (CollectionUtil.isNotEmpty(flowCardInfoList)) {
+                    hollowAllFlowCardVO.setFlowCardGlassInfoDTOList(flowCardInfoList);
+                    pairTotalCount.addAndGet(flowCardInfoList.get(0).getPairCount());
+                }
+                resultList.add(hollowAllFlowCardVO);
+            }
         });
+        Date endDate = new Date();
+        log.info("瀹㈡埛淇℃伅鏁版嵁宸叉煡璇㈠畬姣曪紝鑰楁椂:{}ms锛屾�昏鑰楁椂锛歿}ms", endDate.getTime() - middleDate.getTime(), endDate.getTime() - startDate.getTime());
+        if (CollectionUtil.isEmpty(resultList)) {
+            return new ArrayList<>();
+        }
+        sortFlowCardIdList(resultList);
+        resultList.get(0).setPairTotalCount(pairTotalCount.get());
         return resultList;
-//        return dtos.stream().collect(Collectors.groupingBy(e -> e.getFlowCardId() + ":" + e.getProductName()));
     }
 
     @Override
@@ -390,11 +410,62 @@
     public int queryLayerByFlowCardId(String flowCardId) {
         return baseMapper.queryLayerByFlowCardId(flowCardId);
     }
-    //    @Override
-//    public List<LackDetailsDTO> queryLackByFlowCard(String flowCardId) {
-//        List<LackDetailsDTO> lackDetailsList = this.baseMapper.queryLackByFlowCard(flowCardId);
-//        return lackDetailsList;
-//    }
+
+    @Override
+    public Integer getGlassGapByThickness(Double thickness) {
+        int sysKey = 0;
+        if (thickness >= 12) {
+            sysKey = ConstSysConfig.HOLLOW_GLASS_GAP_12;
+        } else if (thickness == 8) {
+            sysKey = ConstSysConfig.HOLLOW_GLASS_GAP_8;
+        } else if (thickness == 10) {
+            sysKey = ConstSysConfig.HOLLOW_GLASS_GAP_10;
+        } else {
+            sysKey = ConstSysConfig.HOLLOW_GLASS_GAP;
+        }
+        return sysConfigService.queryConfigValue(sysKey);
+    }
+
+    @Override
+    public Boolean hollowBigStorageGlassDamage(DamageRequest request) {
+        List<GlassInfo> glassInfos = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>()
+                .eq(GlassInfo::getFlowCardId, request.getFlowCardId())
+                .eq(GlassInfo::getLayer, request.getLayer())
+                .eq(GlassInfo::getGlassType, request.getGlassType()));
+        for (GlassInfo glassInfo : glassInfos) {
+            //鎺扮墖鎶ョ牬鎹�
+            damageService.autoSubmitReport(glassInfo.getGlassId(), request.getLine(), request.getWorkingProcedure(), request.getRemark(), request.getState());
+        }
+        return Boolean.TRUE;
+    }
+
+    private void sortFlowCardIdList(List<HollowAllFlowCardVO> list) {
+        Pattern pattern = Pattern.compile("^NG(\\d+)([A-Za-z]+)(\\d+)$");
+
+        list.sort((v1, v2) -> {
+            Matcher m1 = pattern.matcher(v1.getFlowCardId());
+            Matcher m2 = pattern.matcher(v2.getFlowCardId());
+
+            if (!m1.find() || !m2.find()) {
+                throw new IllegalArgumentException("鑾峰彇鍒扮殑娴佺▼鍗′笉绗﹀悎鏍¢獙瑙勫垯");
+            }
+
+            // 鎻愬彇閮ㄥ垎
+            BigInteger order1 = new BigInteger(m1.group(1));
+            BigInteger order2 = new BigInteger(m2.group(1));
+            String layer1 = m1.group(2);
+            String layer2 = m2.group(2);
+            BigInteger seq1 = new BigInteger(m1.group(3));
+            BigInteger seq2 = new BigInteger(m2.group(3));
+
+            // 浼樺厛绾ф帓搴�
+            int cmp = order1.compareTo(order2);
+            if (cmp != 0) return cmp;
+            cmp = layer1.compareTo(layer2);
+            if (cmp != 0) return cmp;
+            return seq1.compareTo(seq2);
+        });
+    }
 
 }
 

--
Gitblit v1.8.0