严智鑫
2024-09-09 9fe6d51a678fdd40026b1b91c72959e271dd065f
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
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.GlassInfo;
import com.mes.md.entity.Tasking;
import com.mes.md.entity.WorkTaskDetail;
import com.mes.md.mapper.GlassInfoMapper;
import com.mes.md.mapper.TaskingMapper;
import com.mes.md.mapper.WorkTaskDetailMapper;
import com.mes.tools.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @Author : yanzhxiin
 * @Date: 2024/8/20 11:19
 * @Description:
 */
@Component
@Slf4j
public class MarkingTask {
 
    public static String engineerId = "";
    @Autowired
    TaskingMapper taskingMapper;
 
//    @Scheduled(fixedDelay = 1000)
    public void plcMarkingTask() {
        PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
        String taskRequestTypeValue = plcParameterObject.getPlcParameter("A06_request_word").getValue();
        String glassIdeValue = plcParameterObject.getPlcParameter("A05_scanning_ID").getValue();
        String confirmationWrodValue = plcParameterObject.getPlcParameter("MES_confirmation_word").getValue();
        String confirmationWrodAddress = plcParameterObject.getPlcParameter("MES_confirmation_word").getAddress();
        String currentSlot = plcParameterObject.getPlcParameter("Current_slot").getValue();
        if ("0".equals(taskRequestTypeValue)) {
            if ("0".equals(confirmationWrodValue)) {
                log.info("2、获取到的请求字为0,且发送字为0,不执行任务");
                return;
            }
            log.info("2、获取到的请求字为0,将发送字改为0");
            S7object.getinstance().plccontrol.writeWord(confirmationWrodAddress, 0);
            return;
        }
        if (!"0".equals(confirmationWrodValue)) {
            log.info("2、获取到的请求字不为0,将发送字不为0,直接结束");
            return;
        }
        if ("1".equals(taskRequestTypeValue)) {
            log.info("2、进片请求,且发送字为0,执行打标任务");
            plcRequest(glassIdeValue, confirmationWrodAddress, currentSlot);
        }else if ("3".equals(taskRequestTypeValue)) {
            log.info("2、完成请求,执行完成任务");
            plcReport(glassIdeValue, confirmationWrodAddress, currentSlot);
        }
    }
    public void plcRequest(String glassIdeValue, String confirmationWrodAddress, String currentSlot) {
        //查找打标机任务
        List<Tasking> taskings=taskingMapper.selectList(new MPJLambdaWrapper<Tasking>()
                .eq(Tasking::getState,"线上")
                .eq(Tasking::getCurrentCraft,"打标"));
        if(!taskings.isEmpty()){//有任务
            Tasking tasking=taskings.get(0);
            if("等待".equals(tasking.getWorkState())){
                //发送任务
            }else{
                log.info("当前任务状态:{}",tasking.getWorkState());
            }
        }
 
    }
    public void plcReport(String glassIdeValue, String confirmationWrodAddress, String currentSlot) {
        //查找打标机工作的任务
        //查找打标机任务
        List<Tasking> taskings=taskingMapper.selectList(new MPJLambdaWrapper<Tasking>()
                .eq(Tasking::getState,"线上")
                .eq(Tasking::getCurrentCraft,"打标"));
        if(!taskings.isEmpty()){//有任务
            Tasking tasking=taskings.get(0);
            if("工作".equals(tasking.getWorkState())){
                //发送完成
 
            }else{
                log.info("当前无共工作的任务,无效汇报完成!");
            }
        }
    }
    //@Scheduled(fixedDelay = 1000)
    public void markingTasks() {
        JSONObject jsonObject = new JSONObject();
        List<Tasking> taskings=taskingMapper.selectList(new MPJLambdaWrapper<Tasking>()
                .eq(Tasking::getState,"线上")
                .eq(Tasking::getCurrentCraft,"打标"));
        jsonObject.append("taskings", taskings);
 
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("marking");
        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");
                }
            }
        }
    }
 
}