package com.mes.job; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.mes.common.config.Const; import com.mes.hollow.entity.HollowGlassOutRelationInfo; import com.mes.hollow.service.HollowGlassOutRelationInfoService; import com.mes.hollowqueue.entity.HollowGlassQueueInfo; import com.mes.hollowqueue.service.HollowGlassQueueInfoService; import com.mes.tools.WebSocketServer; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @Author : zhoush * @Date: 2024/12/4 9:41 * @Description: */ @Component @Slf4j public class PushMessageToIndex { @Resource HollowGlassQueueInfoService hollowGlassQueueInfoService; @Resource HollowGlassOutRelationInfoService hollowGlassOutRelationInfoService; @Scheduled(fixedDelay = 1000) public void hollowGlassTask() { List taskList = hollowGlassOutRelationInfoService.list(new LambdaQueryWrapper() .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE)); if (CollectionUtil.isEmpty(taskList)) { return; } JSONObject jsonObject = new JSONObject(); List flowCardIdList = taskList.stream().map(HollowGlassOutRelationInfo::getFlowCardId).collect(Collectors.toList()); List list = hollowGlassQueueInfoService.list(new LambdaQueryWrapper().in(HollowGlassQueueInfo::getFlowCardId, flowCardIdList)); Map> listMap = list.stream().collect(Collectors.groupingBy(HollowGlassQueueInfo::getCell)); jsonObject.append("930", listMap.get(930)); jsonObject.append("931", listMap.get(931)); jsonObject.append("932", listMap.get(932)); List sendwServer = WebSocketServer.sessionMap.get("HollowGlass"); if (CollectionUtil.isNotEmpty(sendwServer)) { for (WebSocketServer socketServer : sendwServer) { if (socketServer != null && socketServer.session.isOpen()) { socketServer.sendMessage(jsonObject.toString()); } } } } }