wangfei
2025-05-14 f6195615cfceedfa1add7ffb762f76c1757545b9
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.common.config.Const;
import com.mes.order.entity.dto.OrderDTO;
import com.mes.order.service.OrdersService;
import com.mes.rawglassdetails.entity.RawGlassStorageDetails;
import com.mes.rawglassdetails.service.RawGlassStorageDetailsService;
import com.mes.rawglassstation.entity.RawGlassStorageStation;
import com.mes.rawglassstation.service.RawGlassStorageStationService;
import com.mes.rawglasstask.entity.RawGlassStorageTask;
import com.mes.rawglasstask.service.RawGlassStorageTaskService;
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.List;
 
/**
 * @author wangfei
 */
@Slf4j
@Component
public class RawGlassPushMessage {
 
    @Resource
    private RawGlassStorageStationService rawGlassStorageStationService;
 
    @Resource
    private RawGlassStorageTaskService rawGlassStorageTaskService;
 
    @Resource
    private RawGlassStorageDetailsService rawGlassStorageDetailsService;
 
    @Resource
    private OrdersService ordersService;
 
    @Scheduled(fixedDelay = 2000)
    public void sendRawGlassMessage() {
        log.info("发送任务信息和架子信息");
        JSONObject jsonObject = new JSONObject();
        List<RawGlassStorageDetails> rawStationDetailsList =
                rawGlassStorageStationService.listRawGlassDetails();
        List<RawGlassStorageTask> tasks = rawGlassStorageTaskService.listRawGlassTask();
        jsonObject.append("rawStationDetailsList", rawStationDetailsList);
        jsonObject.append("tasks", tasks);
        List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("rawGlass");
        if (CollectionUtil.isNotEmpty(sendwServer)) {
            sendwServer.stream().forEach(e -> {
                e.sendMessage(String.valueOf(jsonObject));
            });
        }
    }
 
    @Scheduled(fixedDelay = 1000)
    public void largenScreen() {
        log.info("发送任务信息和架子信息");
        JSONObject jsonObject = new JSONObject();
        MPJLambdaWrapper<RawGlassStorageDetails> wrapper = new MPJLambdaWrapper<>();
        wrapper.select(RawGlassStorageStation::getSlot)
                .select("ifnull(remain_quantity, 0) as remain_quantity")
                .rightJoin(RawGlassStorageStation.class, on -> on.eq(RawGlassStorageStation::getSlot, RawGlassStorageDetails::getSlot)
                        .eq(RawGlassStorageDetails::getState, Const.RAW_GLASS_STATE_IN))
                .orderByAsc(RawGlassStorageStation::getSlot);
        List<RawGlassStorageDetails> rawGlassStorageDetailList = rawGlassStorageDetailsService.list(wrapper);
        jsonObject.append("rawGlassStorageDetailList", rawGlassStorageDetailList);
 
        List<OrderDTO> orderDTOS = ordersService.selectOrderPercent();
        jsonObject.append("orderDTOS", orderDTOS);
 
        List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("largenScreen");
        if (CollectionUtil.isNotEmpty(sendwServer)) {
            sendwServer.stream().forEach(e -> {
                e.sendMessage(String.valueOf(jsonObject));
            });
        }
    }
}