wangfei
2024-12-06 111c7929f721f3abd504facda2428c8185b2a402
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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());
                }
        }
    }
}