From 899432f64fff1a40d7436706e6cae73f87040e4b Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Mon, 31 Aug 2026 17:19:57 +0800 Subject: [PATCH] =?UTF-8?q?2026-08-31=20=E4=BB=A3=E5=8A=9E=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E6=98=BE=E7=A4=BA=E6=80=BB=E8=89=AF=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ScheduleServiceImpl.java | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java b/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java index 320d4ad..b53651c 100644 --- a/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java +++ b/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java @@ -3923,6 +3923,7 @@ public class ScheduleServiceImpl implements ScheduleService { List> list = new ArrayList<>(); if (totalCount != null && totalCount > 0) { list = scheduleTodoMessageMapper.searchTodoCenterList(query); + fillTodoCenterMinTriggerTotalYieldRate(list); } return new PageUtils(list, totalCount == null ? 0 : totalCount, pageSize, pageNo); } @@ -3978,12 +3979,124 @@ public class ScheduleServiceImpl implements ScheduleService { } Map result = new HashMap<>(); + result.put("minTriggerTotalYieldRate", calculateMinTriggerTotalYieldRate(triggerList)); result.put("triggerList", triggerList == null ? new ArrayList<>() : triggerList); result.put("reportList", reportList == null ? new ArrayList<>() : reportList); result.put("mrbInspectionReport", processExceptionNo); return result; } + private void fillTodoCenterMinTriggerTotalYieldRate(List> list) { + if (CollectionUtils.isEmpty(list)) { + return; + } + Map rateCache = new HashMap<>(); + for (Map row : list) { + if (row == null) { + continue; + } + String site = trimToEmpty(row.get("site")); + String buNo = trimToEmpty(row.get("buNo")); + String infoCode = trimToEmpty(row.get("infoCode")); + String cacheKey = site + "|" + buNo + "|" + infoCode; + String minYieldRate = rateCache.get(cacheKey); + if (minYieldRate == null) { + minYieldRate = resolveTodoMinTriggerTotalYieldRate(row, site, buNo, infoCode); + rateCache.put(cacheKey, minYieldRate); + } + row.put("minTriggerTotalYieldRate", minYieldRate); + } + } + + private String resolveTodoMinTriggerTotalYieldRate(Map row, + String site, + String buNo, + String infoCode) { + if (!StringUtils.hasText(site) || !StringUtils.hasText(buNo) || !StringUtils.hasText(infoCode)) { + return ""; + } + List triggerList = scheduleTodoDetailRecordMapper.selectByInfoCodeAndStage( + site, buNo, infoCode, TODO_DETAIL_STAGE_TRIGGER); + if (CollectionUtils.isEmpty(triggerList)) { + String orderNo = trimToEmpty(row.get("orderNo")); + Integer seqNo = toInteger(row.get("seqNo")); + if (StringUtils.hasText(orderNo) && seqNo != null) { + List cacheList = shiftChangeProductionReportMapper.selectUnprocessedData( + site, orderNo, seqNo); + if (!CollectionUtils.isEmpty(cacheList)) { + triggerList = convertShiftCacheToTodoDetailList(cacheList, infoCode, TODO_DETAIL_STAGE_TRIGGER); + } + } + } + return calculateMinTriggerTotalYieldRate(triggerList); + } + + private String calculateMinTriggerTotalYieldRate(List triggerList) { + if (CollectionUtils.isEmpty(triggerList)) { + return ""; + } + List sortedRows = new ArrayList<>(triggerList); + sortedRows.sort(Comparator + .comparing(ScheduleTodoDetailRecordEntity::getRowBumber, Comparator.nullsLast(Integer::compareTo)) + .thenComparing(ScheduleTodoDetailRecordEntity::getId, Comparator.nullsLast(Long::compareTo))); + + int rollCount = 0; + for (ScheduleTodoDetailRecordEntity row : sortedRows) { + if (row == null || row.getRollCount() == null) { + continue; + } + if (row.getRollCount() > rollCount) { + rollCount = row.getRollCount(); + } + } + if (rollCount <= 0) { + rollCount = 1; + } + + int rowsPerRoll = sortedRows.size() / rollCount; + int remainingRows = sortedRows.size() % rollCount; + int currentIndex = 0; + BigDecimal minYieldRate = null; + for (int i = 0; i < rollCount; i++) { + int currentRollRows = rowsPerRoll + (i < remainingRows ? 1 : 0); + if (currentRollRows <= 0 || currentIndex >= sortedRows.size()) { + continue; + } + int endIndex = Math.min(currentIndex + currentRollRows, sortedRows.size()); + BigDecimal goodQty = BigDecimal.ZERO; + BigDecimal defectQty = BigDecimal.ZERO; + for (int idx = currentIndex; idx < endIndex; idx++) { + ScheduleTodoDetailRecordEntity row = sortedRows.get(idx); + if (row == null) { + continue; + } + goodQty = goodQty.add(row.getGoodQty() == null ? BigDecimal.ZERO : row.getGoodQty()); + defectQty = defectQty.add(row.getDefectQty() == null ? BigDecimal.ZERO : row.getDefectQty()); + } + BigDecimal currentYieldRate = calculateYieldRatePercent(goodQty, defectQty); + if (minYieldRate == null || currentYieldRate.compareTo(minYieldRate) < 0) { + minYieldRate = currentYieldRate; + } + currentIndex = endIndex; + } + + if (minYieldRate == null) { + return ""; + } + return minYieldRate.setScale(2, RoundingMode.HALF_UP).toPlainString() + "%"; + } + + private BigDecimal calculateYieldRatePercent(BigDecimal goodQty, BigDecimal defectQty) { + BigDecimal safeGoodQty = goodQty == null ? BigDecimal.ZERO : goodQty; + BigDecimal safeDefectQty = defectQty == null ? BigDecimal.ZERO : defectQty; + BigDecimal totalQty = safeGoodQty.add(safeDefectQty); + if (totalQty.compareTo(BigDecimal.ZERO) <= 0) { + return BigDecimal.ZERO; + } + return safeGoodQty.multiply(BigDecimal.valueOf(100)) + .divide(totalQty, 6, RoundingMode.HALF_UP); + } + private Map buildTodoCenterQuery(Map inData, boolean includePaging) { Map query = new HashMap<>(); query.put("site", trimToEmpty(inData == null ? null : inData.get("site")));