严智鑫
2024-09-11 916f102b39d6f2e1ce591fd5cdd4204ee6ec9ab0
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
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.mes.common.S7object;
import com.mes.md.entity.Tasking;
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 com.mes.device.PlcParameterObject;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCScanQR {
 
    PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
    @Autowired
    TaskingService taskingService;
    @Scheduled(fixedDelay = 500)
    public void pLCScanQR() {
        //获取当前任务表最新的一块任务状态
        //扫码线程
        //电气去根据上一个任务传递下来的状态自己判断需不需要扫码,如果需要扫码直接传输扫码id
        String scanId = plcParameterObject.getPlcParameter("scanId").getValue();
        if(!Objects.equals(scanId, "")){
           boolean result = taskingService.insertTaskingPro(scanId);
           if (result){
               //添加成功时发送过片信号
               S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("scan").getAddress(), Integer.parseInt("1"));
           }
            log.info("扫描定制二维码:"+scanId);
        }else {
            log.info("标准模式扫描二维码:无");
        }
 
    }
    @Scheduled(fixedDelay = 1000)
    public void scanQrCode() {
        //获取当前任务表最新的一块任务状态
        //获取报警状态
        String warning = plcParameterObject.getPlcParameter("warning").getValue();
        JSONObject jsonObject = new JSONObject();
        if (!Objects.equals(warning, "0")) {
            //log.info("报警信息:"+warning);
            jsonObject.append("warning", warning);
        }
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("scanQrCode");
        if (sendwServer != null) {
            for (WebSocketServer webserver : sendwServer) {
                if (webserver != null) {
                    webserver.sendMessage(jsonObject.toString());
                    List<String> messages = webserver.getMessages();
                    if (!messages.isEmpty()) {
                        // // 将最后一个消息转换为整数类型的列表
                        webserver.clearMessages();
                    }
                } else {
                    log.info("Home is closed");
                }
            }
 
        }
    }
 
}