| | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | try { |
| | | waitingGlass = selectWaitingGlassByOpc(); |
| | | if (CollectionUtil.isNotEmpty(waitingGlass)) { |
| | | jsonObject.append("waitingGlass", waitingGlass); |
| | | jsonObject.append("waitingGlass", markSequence(waitingGlass)); |
| | | } |
| | | } catch (Exception e) { |
| | | log.info("钢化前获取异常:{}", e.getMessage()); |
| | |
| | | if (i != 0) { |
| | | jsonName = jsonName + i; |
| | | } |
| | | jsonObject.append(jsonName, temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>() |
| | | List<TemperingGlassInfo> intoGlassList = temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>() |
| | | .eq(TemperingGlassInfo::getEngineerId, intoGlass.get(i).getEngineerId()) |
| | | .eq(TemperingGlassInfo::getTemperingLayoutId, intoGlass.get(i).getTemperingLayoutId()))); |
| | | .eq(TemperingGlassInfo::getTemperingLayoutId, intoGlass.get(i).getTemperingLayoutId())); |
| | | jsonObject.append(jsonName, markSequence(intoGlassList)); |
| | | } |
| | | |
| | | } |
| | |
| | | //出炉后的玻璃 |
| | | List<TemperingGlassInfo> outGlass = temperingGlassInfoService.selectOutGlass(); |
| | | if (CollectionUtil.isNotEmpty(outGlass)) { |
| | | jsonObject.append("outGlass", outGlass); |
| | | jsonObject.append("outGlass", markSequence(outGlass)); |
| | | } |
| | | } catch (Exception e) { |
| | | log.info("钢化前获取异常:{}", e.getMessage()); |
| | |
| | | return tempList; |
| | | } |
| | | } |
| | | |
| | | |
| | | public List<TemperingGlassInfo> markSequence(List<TemperingGlassInfo> tempGlass) { |
| | | |
| | | // 1. 步骤1:定义分组键提取规则(明确类型,避免泛型推导混乱) |
| | | // 组合键:flowCardId + "_" + layer(保证flowCardId+layer唯一) |
| | | Function<TemperingGlassInfo, String> keyExtractor = info -> |
| | | info.getFlowCardId() + "_" + (info.getLayer() == null ? "" : info.getLayer()); |
| | | |
| | | // 2. 步骤2:按组合键分组(完全依赖编译器自动推导泛型,无显式指定) |
| | | // 使用LinkedHashMap保证分组顺序与原始数据一致 |
| | | Map<String, List<TemperingGlassInfo>> groupMap = tempGlass.stream() |
| | | .collect(Collectors.groupingBy( |
| | | keyExtractor, // 分组键 |
| | | LinkedHashMap::new, // 外层Map实现(有序) |
| | | Collectors.toList() // 内层List收集器 |
| | | )); |
| | | |
| | | // 3. 步骤3:为每个分组内的元素标记sequence(从1开始) |
| | | groupMap.forEach((key, glassList) -> { |
| | | // 遍历分组内的列表,按顺序赋值sequence |
| | | for (int i = 0; i < glassList.size(); i++) { |
| | | glassList.get(i).setSequence(i + 1); // sequence从1开始 |
| | | } |
| | | }); |
| | | |
| | | // 5. 返回标记后的完整列表(原列表已通过引用修改) |
| | | return tempGlass; |
| | | } |
| | | } |