| | |
| | | import com.mes.s7.entity.S7DataGHTwo; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import com.mes.tools.WebSocketServer; |
| | | import com.mes.tools.WebSocketUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | @Qualifier("s7SerializerGHTwo") |
| | | private S7Serializer s7SerializerGHTwo; |
| | | @Resource |
| | | private WebSocketUtils webSocketUtils; |
| | | |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | |
| | | 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()); |
| | | } |
| | | webSocketUtils.sendToWeb("temperingGlass", jsonObject); |
| | | |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("temperingGlass"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | } else { |
| | | log.info("Home is closed"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | |
| | | //正在进行的任务 |
| | | List<TemperingGlassInfo> temperingTaskType = temperingGlassInfoService.selectTaskType(); |
| | | jsonObject.append("temperingTaskType", temperingTaskType); |
| | | |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("temperingIsRun"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | } else { |
| | | log.info("Home is closed"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | webSocketUtils.sendToWeb("temperingIsRun", jsonObject); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | |
| | | //钢化饼图数据 |
| | | List<PieChartVO> pieChartVOS = temperingGlassInfoService.queryPieChart(); |
| | | jsonObject.append("pieChartVOS", pieChartVOS); |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("largenScreen"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | List<String> messages = webserver.getMessages(); |
| | | if (!messages.isEmpty()) { |
| | | // // 将最后一个消息转换为整数类型的列表 |
| | | webserver.clearMessages(); |
| | | } |
| | | } else { |
| | | log.info("largenScreen is closed"); |
| | | } |
| | | } |
| | | } |
| | | webSocketUtils.sendToWeb("largenScreen", jsonObject); |
| | | } |
| | | |
| | | |
| | |
| | | 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; |
| | | } |
| | | } |