严智鑫
2024-09-14 f74b51190a77c560949abd4628c5f33cd7e734ac
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/MarkingTask.java
@@ -1,15 +1,19 @@
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;
@@ -34,9 +38,14 @@
    public static String engineerId = "";
    @Autowired
    TaskingMapper taskingMapper;
    @Autowired
    MachineMapper machineMapper;
    @Autowired
    TaskingService taskingService;
//    @Scheduled(fixedDelay = 1000)
    public void plcMarkingTask() {
    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();
@@ -58,50 +67,39 @@
        }
        if ("1".equals(taskRequestTypeValue)) {
            log.info("2、进片请求,且发送字为0,执行打标任务");
            plcRequest(glassIdeValue, confirmationWrodAddress, currentSlot);
            plcRequest(glassIdeValue, confirmationWrodAddress, currentSlot,machine);
        }else if ("3".equals(taskRequestTypeValue)) {
            log.info("2、完成请求,执行完成任务");
            plcReport(glassIdeValue, confirmationWrodAddress, currentSlot);
            plcReport(glassIdeValue, confirmationWrodAddress, currentSlot,machine);
        }
    }
    public void plcRequest(String glassIdeValue, String confirmationWrodAddress, String currentSlot) {
    public void plcRequest(String glassIdeValue, String confirmationWrodAddress, String currentSlot, Machine machine) {
        //查找打标机任务
        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())){
                //发送任务
        Tasking tasking=taskingService.startMachineTask(machine);
        if(tasking!=null&&"开工".equals(machine.getState())){//有任务
            log.info("发送任务:{}",tasking);
            }else{
                log.info("当前任务状态:{}",tasking.getWorkState());
            }
            log.info("不满足发送条件:{}",tasking);
        }
    }
    public void plcReport(String glassIdeValue, String confirmationWrodAddress, String currentSlot) {
    public void plcReport(String glassIdeValue, String confirmationWrodAddress, String currentSlot, Machine machine) {
        //查找打标机工作的任务
        //查找打标机任务
        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())){
                //发送完成
        int finishCount=taskingService.finishMachineTask(machine);
        if(finishCount>0){//数据已标记完成
            log.info("正常汇报:");
            }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);
        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) {