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");
|
}
|
}
|
}
|
}
|
|
}
|