zhoushihao
2025-10-09 266ca8c80300d479351eed50fee5a30751a22fda
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.mes.job;
 
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mes.common.config.Const;
import com.mes.edgglasstask.entity.EdgGlassTaskInfo;
import com.mes.edgglasstask.service.EdgGlassTaskInfoService;
import com.mes.edgstoragecage.entity.vo.EdgStorageCageVO;
import com.mes.edgstoragecage.service.EdgStorageCageDetailsService;
import com.mes.edgstoragecage.service.EdgStorageCageService;
import com.mes.engineering.entity.Engineering;
import com.mes.engineering.service.EngineeringService;
import com.mes.largenscreen.entity.DailyProductionVO;
import com.mes.largenscreen.entity.DateRequest;
import com.mes.largenscreen.entity.PieChartVO;
import com.mes.largenscreen.entity.RunTime;
import com.mes.largenscreen.service.LargenScreenService;
import com.mes.opctask.entity.EdgStorageDeviceTaskHistory;
import com.mes.opctask.service.EdgStorageDeviceTaskHistoryService;
import com.mes.opctask.service.EdgStorageDeviceTaskService;
import com.mes.tools.WebSocketUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
 
/**
 * @Author : zhoush
 * @Date: 2024/12/4 9:41
 * @Description:
 */
@Component
@Slf4j
public class PushMessageToIndex {
 
    @Resource
    EdgStorageCageDetailsService edgStorageCageDetailsService;
    @Resource
    EdgStorageCageService edgStorageCageService;
    @Resource
    EdgGlassTaskInfoService edgGlassTaskInfoService;
    @Resource
    EdgStorageDeviceTaskService edgStorageDeviceTaskService;
    @Resource
    EdgStorageDeviceTaskHistoryService edgStorageDeviceTaskHistoryService;
    @Resource
    EngineeringService engineeringService;
    @Resource
    LargenScreenService largenScreenService;
 
    @Resource
    private WebSocketUtils webSocketUtils;
 
    @Scheduled(fixedDelay = 1000)
    public void CacheGlassOneTasks() {
        CacheGlassTasksChild("cacheGlassOne", 1);
    }
 
    @Scheduled(fixedDelay = 1000)
    public void CacheGlassTwoTasks() {
        CacheGlassTasksChild("cacheGlassTwo", 2);
    }
 
    private void CacheGlassTasksChild(String webSocketName, int deviceId) {
        JSONObject jsonObject = new JSONObject();
        //卧室缓存笼内信息
        List<EdgStorageCageVO> edgStorageCageVOS = edgStorageCageService.selectEdgStorageCagesByDeviceId(deviceId);
        jsonObject.append("EdgStorageCageinfos", edgStorageCageVOS);
 
        //获取正在整形中的任务
        EdgStorageDeviceTaskHistory taskHistory = edgStorageDeviceTaskHistoryService.getOne(new LambdaQueryWrapper<EdgStorageDeviceTaskHistory>()
                .eq(EdgStorageDeviceTaskHistory::getDeviceId, deviceId)
                .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW)
                .orderByDesc(EdgStorageDeviceTaskHistory::getCreateTime).last("limit 1"));
        jsonObject.append("taskMessage", taskHistory);
        webSocketUtils.sendToWeb(webSocketName, jsonObject);
    }
 
    @Scheduled(fixedDelay = 1000)
    public void currentCutDrawingOneTask() {
        currentCutDrawingTaskChild("currentCutDrawingOne", 1, 5);
    }
 
    @Scheduled(fixedDelay = 1000)
    public void currentCutDrawingTwoTask() {
        currentCutDrawingTaskChild("currentCutDrawingTwo", 2, 6);
    }
 
    public void currentCutDrawingTaskChild(String webSocketName, int deviceId, int stationCell) {
        JSONObject jsonObject = edgStorageCageDetailsService.queryCurrentCutDrawing(deviceId, stationCell);
        webSocketUtils.sendToWeb(webSocketName, jsonObject);
    }
 
    @Scheduled(fixedDelay = 1000)
    public void CacheGlassTaskss() {
        JSONObject jsonObject = new JSONObject();
        //磨边信息
        List<EdgGlassTaskInfo> edgTasks = edgGlassTaskInfoService.selectEdgInfo();
        jsonObject.append("edgTasks", edgTasks);
        webSocketUtils.sendToWeb("edgTasks", jsonObject);
    }
 
    @Scheduled(fixedDelay = 5000)
    public void querySameDayProductionTask() {
        JSONObject jsonObject = new JSONObject();
        List<DailyProductionVO> productionVO = largenScreenService.querySameDayProduction(new DateRequest());
        jsonObject.append("productionVO", productionVO);
        webSocketUtils.sendToWeb("largenScreenProduction", jsonObject);
 
    }
 
    @Scheduled(fixedDelay = 5000)
    public void largenScreen() {
        JSONObject jsonObject = new JSONObject();
        //磨边信息
        Date startOfToday = new Date(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String formatted = sdf.format(startOfToday);
        LocalDate date = LocalDate.parse(formatted); // formatted = "2025-05-23"
        LocalDateTime start = date.atStartOfDay(); // 2025-05-23 00:00:00
        LocalDateTime end = date.plusDays(1).atStartOfDay();
        int edgOneCount = edgGlassTaskInfoService.count(
                new LambdaQueryWrapper<EdgGlassTaskInfo>()
                        .lt(EdgGlassTaskInfo::getState, 2)
                        .eq(EdgGlassTaskInfo::getLine, 1)
                        .between(EdgGlassTaskInfo::getCreateTime, start, end)
        );
        edgOneCount = edgOneCount >= 6 ? 6 : edgOneCount;
        int edgTwoCount = edgGlassTaskInfoService.count(
                new LambdaQueryWrapper<EdgGlassTaskInfo>()
                        .lt(EdgGlassTaskInfo::getState, 2)
                        .eq(EdgGlassTaskInfo::getLine, 2)
                        .between(EdgGlassTaskInfo::getCreateTime, start, end)
        );
        edgTwoCount = edgTwoCount >= 6 ? 6 : edgTwoCount;
        jsonObject.append("edgOneCount", edgOneCount);
        jsonObject.append("edgTwoCount", edgTwoCount);
        List<Engineering> engineeringOne = engineeringService.list(
                new LambdaQueryWrapper<Engineering>()
                        .eq(Engineering::getStationCell, 5)
                        .eq(Engineering::getState, 0)
        );
        List<Engineering> engineeringTow = engineeringService.list(
                new LambdaQueryWrapper<Engineering>()
                        .eq(Engineering::getStationCell, 6)
                        .eq(Engineering::getState, 0)
        );
        jsonObject.append("engineeringOne", engineeringOne);
        jsonObject.append("engineeringTwo", engineeringTow);
        List<PieChartVO> pieChartVOS = edgStorageCageDetailsService.queryPieChart();
        jsonObject.append("pieChartVOS", pieChartVOS);
        List<RunTime> loadRunTimes = edgStorageDeviceTaskHistoryService.queryRunTimes(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        jsonObject.append("loadRunTimes", loadRunTimes);
 
        webSocketUtils.sendToWeb("largenScreen", jsonObject);
 
    }
}