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<HollowGlassOutRelationInfo> taskList = hollowGlassOutRelationInfoService.list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
|
.in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE));
|
if (CollectionUtil.isEmpty(taskList)){
|
return;
|
}
|
JSONObject jsonObject = new JSONObject();
|
List<String> flowCardIdList = taskList.stream().map(HollowGlassOutRelationInfo::getFlowCardId).collect(Collectors.toList());
|
List<HollowGlassQueueInfo> list = hollowGlassQueueInfoService.list(new LambdaQueryWrapper<HollowGlassQueueInfo>().in(HollowGlassQueueInfo::getFlowCardId, flowCardIdList));
|
Map<Integer, List<HollowGlassQueueInfo>> 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<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("HollowGlass");
|
if (CollectionUtil.isNotEmpty(sendwServer)) {
|
WebSocketServer socketServer = sendwServer.get(0);
|
if (socketServer != null && socketServer.session.isOpen()) {
|
socketServer.sendMessage(jsonObject.toString());
|
}
|
}
|
}
|
}
|