wu
2024-09-14 65ce957a82e047fe8327bcc1a290234da1d3ca29
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
package com.mes.job;
 
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.Machine;
import com.mes.md.entity.Tasking;
import com.mes.md.entity.WorkTaskDetail;
import com.mes.md.mapper.GlassInfoMapper;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.mapper.TaskingMapper;
import com.mes.md.mapper.WorkTaskDetailMapper;
import com.mes.md.service.TaskingService;
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;
    @Autowired
    MachineMapper machineMapper;
    @Autowired
    TaskingService taskingService;
 
//    @Scheduled(fixedDelay = 1000)
    public void plcMarkingTask(Long machineId) {
        Machine machine=machineMapper.selectById(machineId);
        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,machine);
        }else if ("3".equals(taskRequestTypeValue)) {
            log.info("2、完成请求,执行完成任务");
            plcReport(glassIdeValue, confirmationWrodAddress, currentSlot,machine);
        }
    }
    public void plcRequest(String glassIdeValue, String confirmationWrodAddress, String currentSlot, Machine machine) {
        //查找打标机任务
        Tasking tasking=taskingService.startMachineTask(machine);
        if(tasking!=null&&"开工".equals(machine.getState())){//有任务
            log.info("发送任务:{}",tasking);
        }else{
            log.info("不满足发送条件:{}",tasking);
        }
 
    }
    public void plcReport(String glassIdeValue, String confirmationWrodAddress, String currentSlot, Machine machine) {
        //查找打标机工作的任务
        //查找打标机任务
        int finishCount=taskingService.finishMachineTask(machine);
        if(finishCount>0){//数据已标记完成
            log.info("正常汇报:");
 
        }else{
            log.info("当前无共工作的任务,无效汇报完成!");
        }
    }
    //@Scheduled(fixedDelay = 1000)
    public void markingTasks() {
        JSONObject jsonObject = new JSONObject();
        Machine machine=machineMapper.selectById(11L);
        List<Tasking> taskingList=taskingService.findMachineTask(machine);
        jsonObject.append("taskingList", taskingList);
 
        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");
                }
            }
        }
    }
 
}