严智鑫
2024-12-11 044c32c15ee9ccac6f3b60eb6745025e2f4480f2
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
package com.mes.job;
 
import cn.hutool.json.JSONObject;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.common.S7object;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.LineConfiguration;
import com.mes.md.entity.Machine;
import com.mes.md.entity.PrimitiveTask;
import com.mes.md.entity.Tasking;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.mapper.TaskingMapper;
import com.mes.md.service.PrimitiveTaskService;
import com.mes.md.service.TaskingService;
import com.mes.tools.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCManualReporting {
 
    PlcParameterObject plcParameterObject =null;
    @Autowired
    TaskingService taskingService;
    @Autowired
    TaskingMapper taskingMapper;
    @Autowired
    MachineMapper machineMapper;
    @Autowired
    PrimitiveTaskService primitiveTaskService;
 
    @Scheduled(fixedDelay = 500)
    public void manualReporting() {
        JSONObject jsonObject = new JSONObject();
        Machine machine=machineMapper.selectById(24L);
        List<Tasking> taskingList=taskingMapper.selectJoinList(Tasking.class,new MPJLambdaWrapper<Tasking>()
                .selectAll(Tasking.class)
                .innerJoin(LineConfiguration.class,LineConfiguration::getId,Tasking::getLineConfigurationId)
                .innerJoin(Machine.class,Machine::getId,LineConfiguration::getMachineId)
                .eq(LineConfiguration::getMachineId,machine.getId())
                .eq(Tasking::getGlassState,"正常")
                .eq(Tasking::getState,"线上")
                .ne(Tasking::getWorkState,"完工")
                .orderByDesc(Tasking::getOperationRecordTime));
 
        //List<PrimitiveTask> taskingList = primitiveTaskService.selectPrimitiveTask(new PrimitiveTask());
        jsonObject.append("taskingList", taskingList);
        jsonObject.append("machine", machine);
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("manualReporting");
        if (sendwServer != null) {
            for (WebSocketServer webserver : sendwServer) {
                if (webserver != null) {
                    try {
                        webserver.sendMessage(jsonObject.toString());
                        List<String> messages = webserver.getMessages();
                        if (!messages.isEmpty()) {
                            // // 将最后一个消息转换为整数类型的列表
                            webserver.clearMessages();
                        }
                    }catch (Exception e) {
 
                    }
                } else {
                    log.info("Home is closed");
                }
            }
 
        }
    }
 
}