Browse Source

2026-08-31

代办中心显示总良率
master
fengyuan_yang 3 weeks ago
parent
commit
899432f64f
  1. 113
      src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java

113
src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java

@ -3923,6 +3923,7 @@ public class ScheduleServiceImpl implements ScheduleService {
List<Map<String, Object>> 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<String, Object> 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<Map<String, Object>> list) {
if (CollectionUtils.isEmpty(list)) {
return;
}
Map<String, String> rateCache = new HashMap<>();
for (Map<String, Object> 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<String, Object> row,
String site,
String buNo,
String infoCode) {
if (!StringUtils.hasText(site) || !StringUtils.hasText(buNo) || !StringUtils.hasText(infoCode)) {
return "";
}
List<ScheduleTodoDetailRecordEntity> 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<ShiftChangeProductionReportEntity> 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<ScheduleTodoDetailRecordEntity> triggerList) {
if (CollectionUtils.isEmpty(triggerList)) {
return "";
}
List<ScheduleTodoDetailRecordEntity> 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<String, Object> buildTodoCenterQuery(Map<String, Object> inData, boolean includePaging) {
Map<String, Object> query = new HashMap<>();
query.put("site", trimToEmpty(inData == null ? null : inData.get("site")));

Loading…
Cancel
Save