huang
2025-12-01 dad0263459b30dbfa75f06dff062a0c85183517b
mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/GlassInfoServiceImpl.java
@@ -9,6 +9,7 @@
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -124,5 +125,40 @@
            return false;
        }
    }
    @Override
    public List<String> getRecentScannedGlassIds(Integer minutesAgo, Integer maxCount, String workLine) {
        try {
            // 默认查询最近2分钟内的记录,最多返回20条
            int minutes = minutesAgo != null && minutesAgo > 0 ? minutesAgo : 2;
            int limit = maxCount != null && maxCount > 0 ? maxCount : 20;
            Date timeThreshold = new Date(System.currentTimeMillis() - minutes * 60 * 1000L);
            LambdaQueryWrapper<GlassInfo> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(GlassInfo::getStatus, GlassInfo.Status.ACTIVE)
                   .ge(GlassInfo::getCreatedTime, timeThreshold)
                   .orderByDesc(GlassInfo::getCreatedTime)
                   .last("LIMIT " + limit);
            // 如果指定了workLine,则过滤description
            if (workLine != null && !workLine.trim().isEmpty()) {
                wrapper.like(GlassInfo::getDescription, "workLine=" + workLine);
            }
            List<GlassInfo> recentGlasses = baseMapper.selectList(wrapper);
            // 提取玻璃ID列表
            return recentGlasses.stream()
                    .map(GlassInfo::getGlassId)
                    .filter(id -> id != null && !id.trim().isEmpty())
                    .collect(Collectors.toList());
        } catch (Exception e) {
            log.error("查询最近扫码的玻璃ID失败, minutesAgo={}, maxCount={}, workLine={}",
                    minutesAgo, maxCount, workLine, e);
            return Collections.emptyList();
        }
    }
}