严智鑫
2024-12-03 d1ee3f0300368709a246c37bf5e525f69eb1dbf7
job漏提交文件
10个文件已添加
1227 ■■■■■ 已修改文件
JiuMuMesParent/JsonFile/PlcCacheGlass.json 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/MarkingTask.java 184 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCCleaning.java 88 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCEdging.java 336 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCFlipSlice.java 182 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCManualReporting.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCMechanicalArm.java 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCScanQRVerify.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCScanQRWorks.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCScanQrCodesReport.java 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JiuMuMesParent/JsonFile/PlcCacheGlass.json
New file
@@ -0,0 +1,64 @@
{
   "plcAddressBegin":"DB11.0",
   "plcAddressLenght":"80",
   "dataType":"word",
   "parameteInfor":[
      {
         "codeId": "A06_request_word",
         "addressIndex":"0",
         "addressLenght":"2",
         "ratio":"1",
         "unit":"m/min"
      },
      {
          "codeId": "A05_scanning_ID",
          "addressIndex":"2",
          "addressLenght":"30",
          "ratio":"1",
          "unit":""
       },
       {
          "codeId": "Current_slot",
          "addressIndex":"36",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       },
        {
          "codeId": "MES_confirmation_word",
          "addressIndex":"38",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       },
       {
          "codeId": "A08_glass_status",
          "addressIndex":"68",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       },
       {
          "codeId": "A10_glass_status",
          "addressIndex":"70",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       },
       {
          "codeId": "A09_prohibit_film_production",
          "addressIndex":"72",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       }
       ,
       {
          "codeId": "A10_prohibit_film_production",
          "addressIndex":"74",
          "addressLenght":"2",
          "ratio":"1",
          "unit":""
       }
   ]
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/MarkingTask.java
New file
@@ -0,0 +1,184 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.github.s7connector.api.DaveArea;
import com.github.s7connector.api.S7Connector;
import com.github.s7connector.api.factory.S7ConnectorFactory;
import com.github.s7connector.impl.serializer.converter.StringConverter;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.mes.common.S7object;
import com.mes.common.S7objectFlipSlice;
import com.mes.common.S7objectMachine;
import com.mes.common.S7objectMarking;
import com.mes.device.PlcParameterInfo;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.Machine;
import com.mes.md.entity.Tasking;
import com.mes.md.mapper.GlassInfoMapper;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.mapper.TaskingMapper;
import com.mes.md.service.TaskingService;
import com.mes.service.ModbusTcp;
import com.mes.service.PlcAgreement;
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 sun.nio.cs.ext.GBK;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * 自动打标机
 * @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;
    @Autowired
    private GlassInfoMapper glassInfoMapper;
    public S7objectMachine s7objectMachine;
    public List<Map> sendRecords = new ArrayList<>();
    //@Scheduled(fixedDelay = 1000)
    public void plcMarkingTask() {
        Long machineId=12L;
        Machine machine=machineMapper.selectById(machineId);
        if (s7objectMachine==null){
            s7objectMachine=new S7objectMachine(machine.getIp(),machine.getPort(),"PlcMarking", EPlcType.S1500);
            s7objectMachine.start();
        }
        //PlcParameterObject plcParameterObject = S7objectMarking.getinstance().PlcMesObject;
        PlcParameterObject plcParameterObject = s7objectMachine.PlcMesObject;
        PlcParameterInfo plcRequest =plcParameterObject.getPlcParameter("plcRequest");//请求字
        PlcParameterInfo plcRequestID =plcParameterObject.getPlcParameter("plcRequestID");//请求ID
        PlcParameterInfo mesSend =plcParameterObject.getPlcParameter("mesSend");//发送字
        PlcParameterInfo isMark =plcParameterObject.getPlcParameter("isMark");//发送ID【0 不打标,1标准模式,2定制模式】
        PlcParameterInfo drawingMark =plcParameterObject.getPlcParameter("drawingMark");//打标图纸地址
        PlcParameterInfo lengthOutOfService =plcParameterObject.getPlcParameter("length(OutOfService)");//长
        PlcParameterInfo widthOutOfService =plcParameterObject.getPlcParameter("width(OutOfService)");//宽
        PlcParameterInfo markingMode =plcParameterObject.getPlcParameter("markingMode");//
        PlcParameterInfo plcReport =plcParameterObject.getPlcParameter("plcReport");//汇报字
        PlcParameterInfo plcReportID =plcParameterObject.getPlcParameter("plcReportID");//汇报ID
        PlcParameterInfo mesConfirm =plcParameterObject.getPlcParameter("mesConfirm");//确认字
        PlcParameterInfo mesConfirmID =plcParameterObject.getPlcParameter("mesConfirmID");//确认ID
        if (machine.getIsLog()>0){
            s7objectMachine.consoleLogInfo();
        }
        if ("0".equals(plcRequest.getValue())&&"1".equals(mesSend.getValue())) {
            //发送字置0
            log.info("1.发送字置零,清除上次发送的数据{},{},{},{},{}"
                    ,markingMode.getValue()
                    ,isMark.getValue()
                    ,lengthOutOfService.getValue()
                    ,widthOutOfService.getValue()
                    ,mesSend.getValue());
            //S7objectMarking.getinstance().plccontrol.writeString(drawingMark.getAddress(),"");
            s7objectMachine.plccontrol.writeWord(markingMode.getAddress(), 0);
            s7objectMachine.plccontrol.writeWord(lengthOutOfService.getAddress(), 0);
            s7objectMachine.plccontrol.writeWord(widthOutOfService.getAddress(), 0);
            s7objectMachine.plccontrol.writeWord(isMark.getAddress(), 0);
            s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 0);
            return;
        }
        if ("0".equals(plcReport.getValue())&&"1".equals(mesConfirm.getValue())) {
            log.info("2.确认字置零");
            //发送字置0
            s7objectMachine.plccontrol.writeWord(mesConfirm.getAddress(), 0);
            return;
        }
        if("1".equals(plcReport.getValue())&&"0".equals(mesConfirm.getValue())){
            int finishCount=taskingService.finishMachineTask(machine);
            log.info("3、任务完成");
            if(finishCount>0){//有任务
                s7objectMachine.plccontrol.writeWord(mesConfirm.getAddress(), 1);
                return;
            }
            return;
        }
        List<Tasking> taskingCount=taskingService.findMachineWorkStateTask(machine,"正在工作");
        if("1".equals(plcRequest.getValue())&&"0".equals(mesSend.getValue())&& !plcRequestID.getValue().isEmpty()
                &&"开工".equals(machine.getState())
                &&taskingCount.size()<machine.getMaxTaskCount()){
            Tasking tasking=taskingService.startMachineTask(machine);
            if(tasking!=null){
                //模式:1定制  0 批量      是否打标:0不打标   1打标
                int isMark_=(tasking.getDrawingMarking()==null||tasking.getDrawingMarking().isEmpty())?0:1;
                int isMarkingMode_="定制".equals(tasking.getTaskType()) ?1:0;
                log.info("4、发送数据:{},{},{},{},{},{}"
                        ,tasking.getProgramId()
                        ,tasking.getLength().intValue(),tasking.getWidth().intValue(),isMark_,isMarkingMode_,1);
                if(isMark_==1){
                    s7objectMachine.plccontrol.writeString(drawingMark.getAddress(), tasking.getProgramId());
                }
                //S7objectMarking.getinstance().plccontrol.writeUInt32 (mesSendID.getAddress(), 2);
                s7objectMachine.plccontrol.writeWord(lengthOutOfService.getAddress(), tasking.getLength().intValue());
                s7objectMachine.plccontrol.writeWord(widthOutOfService.getAddress(), tasking.getWidth().intValue());
                s7objectMachine.plccontrol.writeWord(isMark.getAddress(), isMark_);
                s7objectMachine.plccontrol.writeWord(markingMode.getAddress(), isMarkingMode_);
                s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 1);
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String sendRecord=df.format(new Date())+"  "+
                        tasking.getScanId()+"-"+
                        tasking.getProgramId()+"-"+
                        tasking.getLength()+"-"+
                        tasking.getWidth()+"-"+
                        isMark_+"-"+
                        isMarkingMode_;
                if (sendRecords.size()>7){
                    sendRecords.remove(0);
                }
                Map sendContentMap=new HashMap();
                sendContentMap.put("sendContent",sendRecord);
                sendRecords.add(sendContentMap);
                return;
            }
        }
        //log.info("无可执行的条件");
    }
    @Scheduled(fixedDelay = 1000)
    public void markingTasks() {
        JSONObject jsonObject = new JSONObject();
        Machine machine=machineMapper.selectById(12L);
        List<Tasking> taskingList=taskingService.findMachineTask(machine);
        jsonObject.append("taskingList", taskingList);
        jsonObject.append("machine", machine);
        jsonObject.append("sendRecords", sendRecords);
        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");
                }
            }
        }
    }
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCCleaning.java
New file
@@ -0,0 +1,88 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.mes.common.S7object;
import com.mes.common.S7objectCleaning;
import com.mes.common.S7objectMachine;
import com.mes.common.S7objectMarking;
import com.mes.device.PlcParameterInfo;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.Machine;
import com.mes.md.entity.Tasking;
import com.mes.md.mapper.MachineMapper;
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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCCleaning {
    PlcParameterObject plcParameterObject =null;
    @Autowired
    TaskingService taskingService;
    @Autowired
    MachineMapper machineMapper;
    public S7objectMachine s7objectMachine;
    //@Scheduled(fixedDelay = 500)
    public void cleaning() {
        //磨边线速度  10.36.164.200
        Long machineId=8L;
        Machine machine=machineMapper.selectById(machineId);
        if (s7objectMachine==null){
            s7objectMachine=new S7objectMachine(machine.getIp(),machine.getPort(),"PlcCleaning", EPlcType.S200_SMART);
            s7objectMachine.start();
        }
        PlcParameterObject plcParameterObject = s7objectMachine.PlcMesObject;
        PlcParameterInfo edgSpeed =plcParameterObject.getPlcParameter("edgSpeed");//磨边机速度
        PlcParameterInfo thinness =plcParameterObject.getPlcParameter("thinness");//厚度
        if (machine.getIsLog()>0){
            s7objectMachine.consoleLogInfo();
        }
        int edgSpeedInt=PLCEdging.edgSpeed;
        int edgThinnessInt=PLCEdging.thinness;
        if(!(edgSpeedInt+"").equals(edgSpeed.getValue())||!(edgThinnessInt+"").equals(thinness.getValue())){
            //给清洗机器发送磨边机速度
            S7objectCleaning.getinstance().plccontrol.writeWord(edgSpeed.getAddress(), edgSpeedInt);
            S7objectCleaning.getinstance().plccontrol.writeWord(thinness.getAddress(), edgThinnessInt);
        }
    }
    //@Scheduled(fixedDelay = 1000)
    public void cleaningTask() {
        //获取报警状态
        JSONObject jsonObject = new JSONObject();
        Machine machine=machineMapper.selectById(7L);
        List<Tasking> taskingList=taskingService.findMachineTask(machine);
        jsonObject.append("taskingList", taskingList);
        jsonObject.append("machine", machine);
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("cleaning");
        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");
                }
            }
        }
    }
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCEdging.java
New file
@@ -0,0 +1,336 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mes.common.S7object;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.LineConfiguration;
import com.mes.md.entity.Machine;
import com.mes.md.entity.PrimitiveTask;
import com.mes.md.entity.Tasking;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.mapper.TaskingMapper;
import com.mes.md.service.*;
import com.mes.service.ModbusTcp;
import com.mes.service.PlcAgreement;
import com.mes.service.PlcParameter;
import com.mes.tools.WebSocketServer;
import com.mes.utils.HexUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCEdging {
    @Autowired
    TaskingMapper taskingMapper;
    @Autowired
    MachineMapper machineMapper;
    @Autowired
    TaskingService taskingService;
    @Autowired
    ProjectService projectService;
    @Autowired
    PrimitiveTaskService primitiveTaskService;
    @Autowired
    KBBTJPDrawingBPService kBBTJPDrawingBPService;
    @Autowired
    LineConfigurationService lineConfigurationService;
    public static int thinness = 40;
    public static int edgSpeed = 40;
    public static Long machineId1 = 5L;
    public static Long machineId2 = 6L;
    public List<Map> sendRecords = new ArrayList<>();
    //@Scheduled(fixedDelay = 1000)
    public void plcEdging() {
        Machine machine=machineMapper.selectById(machineId2);
        ModbusTcp modbusTcp1 =new ModbusTcp(machine.getIp(),machine.getPort(),"PlcEdging");
        try {
            modbusTcp1.connect();
            PlcAgreement plcAgreement=modbusTcp1.getPlcAgreement("PlcEdging");
            if(!modbusTcp1.read(plcAgreement)){
                log.info("通讯读取新数据失败");
                modbusTcp1.close();
                return;
            }
            PlcParameter inputOrOut2 =plcAgreement.getPlcParameter("inputOrOut2");
            edgSpeed=inputOrOut2.getValueInt();
            PlcParameter plcRequest =plcAgreement.getPlcParameter("plcRequest");//请求字
            PlcParameter mesSend =plcAgreement.getPlcParameter("mesSend");//发送字
            PlcParameter plcReport =plcAgreement.getPlcParameter("plcReport");//汇报字
            PlcParameter plcReportID =plcAgreement.getPlcParameter("plcReportID");//汇报ID
            PlcParameter plcReport2 =plcAgreement.getPlcParameter("plcReport2");//手动汇报字
            PlcParameter plcReportID2 =plcAgreement.getPlcParameter("plcReportID2");//手动汇报ID
            PlcParameter mesConfirm =plcAgreement.getPlcParameter("mesConfirm");//确认字
            PlcParameter mesConfirmID =plcAgreement.getPlcParameter("mesConfirmID");//确认ID
            PlcParameter mesConfirm2 =plcAgreement.getPlcParameter("mesConfirm2");//手动确认字
            PlcParameter mesConfirmID2 =plcAgreement.getPlcParameter("mesConfirmID2");//手动确认ID
            if (machine.getIsLog()>0){
                modbusTcp1.consoleLogInfo(plcAgreement);
            }
            if (0==plcRequest.getValueInt()&&1==mesSend.getValueInt()) {
                log.info("1.发送字置零");
                //发送字置0
                String send= HexUtil.intTo2ByteHex(0);
                modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesSend.getAddressStart()/2));
                log.info("发送字 清空成功;内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesSend.getAddressStart()));
                modbusTcp1.close();
                return;
            }
            if (0==plcReport.getValueInt()&&0!=mesConfirm.getValueInt()) {
                log.info("2.确认字置零");
                //发送字置0
                String send=HexUtil.intTo2ByteHex(0);
                modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesConfirm.getAddressStart()/2));
                log.info("任务完成 清空成功;内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesConfirm.getAddressStart()));
                modbusTcp1.close();
                return;
            }
            if (0==plcReport2.getValueInt()&&0!=mesConfirm2.getValueInt()) {
                log.info("2.确认字置零");
                //发送字置0
                String send=HexUtil.intTo2ByteHex(0);
                modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()/2));
                log.info("任务完成 清空成功;内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()));
                modbusTcp1.close();
                return;
            }
            if(1==plcReport.getValueInt()&&0==mesConfirm.getValueInt()){
                int finishCount=taskingService.finishMachineTask(machine);
                log.info("3、任务完成");
                if(finishCount>0) {//有任务
                    String send = HexUtil.intTo2ByteHex(1);
                    modbusTcp1.writeString(send, HexUtil.intTo2ByteHex(mesConfirm.getAddressStart() / 2));
                    log.info("任务完成 成功 内容:{},发送起始地址:{}", send, HexUtil.intTo2ByteHex(mesConfirm.getAddressStart()));
                    modbusTcp1.close();
                    return;
                }
                String send = HexUtil.intTo2ByteHex(1);
                modbusTcp1.writeString(send, HexUtil.intTo2ByteHex(mesConfirm.getAddressStart() / 2));
                log.info("任务完成 异常成功 内容:{},发送起始地址:{}", send, HexUtil.intTo2ByteHex(mesConfirm.getAddressStart()));
                modbusTcp1.close();
                return;
            }
            if(4==plcReport2.getValueInt()&&0==mesConfirm2.getValueInt()){
                int finishCount=taskingService.glassDownLineOne(machine);
                if(finishCount>0){//有任务
                    log.info("4、人工拿走");
                    String send=HexUtil.intTo2ByteHex(4);
                    modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()/2));
                    log.info("人工拿走发送报文内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()));
                    modbusTcp1.close();
                    return;
                }
                String send=HexUtil.intTo2ByteHex(4);
                modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()/2));
                log.info("人工拿走异常 发送报文内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()));
                modbusTcp1.close();
                return;
            }
            if(2==plcReport2.getValueInt()&&0==mesConfirm2.getValueInt()){
                int finishCount=taskingService.loseMachineTask(machine);
                if(finishCount>0){//有任务
                    log.info("2、重发");
                    String send=HexUtil.intTo2ByteHex(2);
                    modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()/2));
                    log.info("重发发送报文内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()));
                    modbusTcp1.close();
                    return;
                }else{
                    log.info("2、异常重发");
                    String send=HexUtil.intTo2ByteHex(2);
                    modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()/2));
                    log.info("异常重发发送报文内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()));
                    modbusTcp1.close();
                    return;
                }
            }
            if(3==plcReport2.getValueInt()&&0==mesConfirm2.getValueInt()){
                int finishCount=taskingService.finishMachineTask(machine);
                if(finishCount>0){//有任务
                    log.info("3、设备上人工点破损");
                    String send=HexUtil.intTo2ByteHex(3);
                    modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()/2));
                    log.info("人工点破损发送报文内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()));
                    modbusTcp1.close();
                    return;
                }else{
                    //是否自动清除破损
                    log.info("3、无效破损 (没有找到此ID的玻璃)");
                    String send=HexUtil.intTo2ByteHex(3);
                    modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()/2));
                    log.info("发送报文内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesConfirm2.getAddressStart()));
                    modbusTcp1.close();
                    return;
                }
            }
            List<Tasking> taskingCount=taskingService.findMachineWorkStateTask(machine,"正在工作");
            if((1==plcRequest.getValueInt()&&0==mesSend.getValueInt())
                    &&"开工".equals(machine.getState())
                    &&taskingCount.size()<machine.getMaxTaskCount()){
                Machine loadMachine=machineMapper.selectById(2L);
                Tasking tasking;
                String scan_id="";
                if(loadMachine.getMode()==1){
                    //标准模式  找已领取未完成的第一条任务
                    LineConfiguration lineConfiguration=lineConfigurationService.machineLineConfiguration(machine);
                    List<PrimitiveTask> findPrimitiveTasking=primitiveTaskService.findPrimitiveTasking(machine,lineConfiguration.getLineId());
                    //添加数据:
                    for(PrimitiveTask primitiveTask:findPrimitiveTasking){
                        List<Tasking> taskingTopList=taskingMapper.selectList(new QueryWrapper<Tasking>().lambda()
                                .eq(Tasking::getScanId,primitiveTask.getScanId())
                        );
                        //任务数>已上数量
                        if(taskingTopList.size()<primitiveTask.getTaskQuantity()){
                            Tasking taskingAdd=primitiveTaskService.convertListTasking(primitiveTask,lineConfiguration.getId());
                            Integer taskSequence=1;
                            if (machine.getTodayCount()>0&&machine.getTodayCount()<5000){
                                taskSequence=machine.getTodayCount()+1;
                            }else{
                                taskSequence=1;
                            }
                            machine.setTodayCount(taskSequence);
                            taskingAdd.setTaskSequence(taskSequence);
                            machineMapper.updateById(machine);
                            taskingMapper.insert(taskingAdd);
                        }
                        break;
                    }
                    tasking=taskingService.startMachineTask(machine);
                }else{
                    //定制模式
                    String PlcRequestID_=clientTCPSocket();
                    //String PlcRequestID_=",,46607221";
                    if (PlcRequestID_==null||PlcRequestID_.lastIndexOf(",")<0){
                        modbusTcp1.close();
                        errorMachine(machine,("扫不到码:"+PlcRequestID_));
                        return;
                    }
                    scan_id= PlcRequestID_.substring(PlcRequestID_.lastIndexOf(",")+1);
                    tasking=taskingService.startMachineTask(machine,scan_id);
                }
                if(tasking!=null){
                    log.info("4、发送任务  任务数据:{}, 设备状态:{}, ",machine,tasking);
                    String send=
                            HexUtil.intTo2ByteHex(1)+
                                    HexUtil.intTo2ByteHex(tasking.getGlassId().intValue())+
                                    HexUtil.intTo2ByteHex(((Double)(tasking.getLength()*10)).intValue())+
                                    HexUtil.intTo2ByteHex(((Double)(tasking.getWidth()*10)).intValue())+
                                    HexUtil.intTo2ByteHex(((Double)(tasking.getThickness()*10)).intValue());
                    modbusTcp1.writeString(send,HexUtil.intTo2ByteHex(mesSend.getAddressStart()/2));
                    log.info("发送任务发送报文内容:{},发送起始地址:{}",send,HexUtil.intTo2ByteHex(mesSend.getAddressStart()));
                    modbusTcp1.close();
                    errorMachine(machine,"");
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String sendRecord=df.format(new Date())+"  "+
                            tasking.getGlassId()+"-"+
                            tasking.getWidth()+"-"+
                            tasking.getLength()+"-"+
                            tasking.getThickness();
                    if (sendRecords.size()>7){
                        sendRecords.remove(0);
                    }
                    Map sendContentMap=new HashMap();
                    sendContentMap.put("sendContent",sendRecord);
                    sendRecords.add(sendContentMap);
                    return;
                }else if(!scan_id.isEmpty()){
                    taskingService.scanMachineAdd(machine,scan_id);
                    modbusTcp1.close();
                    return;
                }
            }
            //}
        } catch (Exception e) {
            log.info("交互逻辑错误");
        }
        modbusTcp1.close();
        //log.info("无可执行的条件");
    }
    public void errorMachine(Machine machine,String error) {
        if (!error.equals(machine.getRemark())){
            machine.setRemark(error);
            machineMapper.updateById(machine);
        }
    }
    public String clientTCPSocket() {
        try {
            Machine machine=machineMapper.selectById(4L);
            Socket clientSocket = new Socket(machine.getIp(), machine.getPort());
            try {
                // 创建输入流和输出流
                InputStream inputStream = clientSocket.getInputStream();
                OutputStream outputStream = clientSocket.getOutputStream();
                // 发送启动命令
                String message = "start";
                outputStream.write(message.getBytes());
                // 读取服务器响应的数据
                byte[] buffer = new byte[1024];
                int bytesRead = inputStream.read(buffer);
                String receivedMessage = new String(buffer, 0, bytesRead);
                System.out.println("收到扫码枪返回内容:" + receivedMessage);
                // 关闭连接
                String message2 = "stop";
                outputStream.write(message2.getBytes());
                clientSocket.close();
                return receivedMessage;
            } catch (Exception e) {
                e.printStackTrace();
            }
            clientSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    @Scheduled(fixedDelay = 1000)
    public void EdgingTasks() {
        JSONObject jsonObject = new JSONObject();
        Machine machine=machineMapper.selectById(6L);
        List<Tasking> taskingList=taskingService.findMachineTask(machine);
        jsonObject.append("taskingList", taskingList);
        jsonObject.append("machine", machine);
        jsonObject.append("sendRecords", sendRecords);
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("edgingTask");
        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");
                }
            }
        }
    }
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCFlipSlice.java
New file
@@ -0,0 +1,182 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.mes.common.S7object;
import com.mes.common.S7objectFlipSlice;
import com.mes.common.S7objectMachine;
import com.mes.common.S7objectMarking;
import com.mes.device.PlcParameterInfo;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.Machine;
import com.mes.md.entity.Tasking;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.service.ProjectService;
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 java.text.SimpleDateFormat;
import java.util.*;
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCFlipSlice {
    @Autowired
    TaskingService taskingService;
    @Autowired
    MachineMapper machineMapper;
    public S7objectMachine s7objectMachine;
    @Autowired
    ProjectService projectService;
    public List<Map> sendRecords = new ArrayList<>();
    //@Scheduled(fixedDelay = 1000)
    public void plcFlipSlice() {
        Long machineId=26L;
        Machine machine=machineMapper.selectById(machineId);
        if (s7objectMachine==null){
            s7objectMachine=new S7objectMachine(machine.getIp(),machine.getPort(),"PlcFlipSlice", EPlcType.S1200);
            s7objectMachine.start();
        }
        PlcParameterObject plcParameterObject = s7objectMachine.PlcMesObject;
        PlcParameterInfo plcRequest =plcParameterObject.getPlcParameter("plcRequest");//请求字
        PlcParameterInfo plcRequestID =plcParameterObject.getPlcParameter("plcRequestID");//请求ID
        PlcParameterInfo plcRequestType =plcParameterObject.getPlcParameter("plcRequestType");//PLC请求
        PlcParameterInfo mesSend =plcParameterObject.getPlcParameter("mesSend");//发送字
        PlcParameterInfo mesSendId =plcParameterObject.getPlcParameter("mesSendID");//发送ID
        PlcParameterInfo length =plcParameterObject.getPlcParameter("length");//长
        PlcParameterInfo width =plcParameterObject.getPlcParameter("width");//宽
        PlcParameterInfo mesSendType =plcParameterObject.getPlcParameter("mesSendType");//  扫码1   不扫码2
        String scan_id="";
        if (machine.getIsLog()>0){
            s7objectMachine.consoleLogInfo();
        }
        if ("0".equals(plcRequest.getValue())&&!"0".equals(mesSend.getValue())) {
            //发送字置0
            int finishCount=taskingService.finishMachineTask(machine);
            log.info("1.发送字置零,清除上次发送的数据{},{},{},{},{}"
                    ,finishCount
                    ,length.getValue()
                    ,width.getValue()
                    ,mesSendId.getValue()
                    ,mesSend.getValue());
            s7objectMachine.plccontrol.writeWord(length.getAddress(), 0);
            s7objectMachine.plccontrol.writeWord(width.getAddress(), 0);
            s7objectMachine.plccontrol.writeWord(mesSendId.getAddress(), 0);
            s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 0);
            return;
        }
        List<Tasking> taskingCount=taskingService.findMachineWorkStateTask(machine,"正在工作");
        if(("1".equals(plcRequest.getValue())&&"0".equals(mesSend.getValue())&& !plcRequestID.getValue().isEmpty()
                &&"开工".equals(machine.getState())
                &&taskingCount.size()<machine.getMaxTaskCount())){
            Tasking tasking;
            if(machine.getMode()==1){
                //标准模式
                tasking=taskingService.startMachineTask(machine);
            }else{
                //定制模式
                String PlcRequestID_=plcRequestID.getValue();
                scan_id= PlcRequestID_.substring(PlcRequestID_.lastIndexOf(",")+1);
                tasking=taskingService.startScanIdMachineTask(machine,scan_id);//不管顺序,直接找从磨边机扫码后到翻片台的数据
            }
            if(tasking!=null){
                log.info("4、发送数据:{},{},{},{},{}"
                        ,tasking.getGlassId(),tasking.getProgramId()
                        ,tasking.getLength().intValue(),tasking.getWidth().intValue(),1);
                s7objectMachine.plccontrol.writeWord(length.getAddress(), tasking.getLength().intValue());
                s7objectMachine.plccontrol.writeWord(width.getAddress(), tasking.getWidth().intValue());
                s7objectMachine.plccontrol.writeString(mesSendId.getAddress(), tasking.getGlassId().toString());
                s7objectMachine.plccontrol.writeWord(mesSend.getAddress(), 1);
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String sendRecord=df.format(new Date())+"  "+
                        tasking.getGlassId()+"-"+
                        tasking.getLength()+"-"+
                        tasking.getWidth();
                if (sendRecords.size()>7){
                    sendRecords.remove(0);
                }
                Map sendContentMap=new HashMap();
                sendContentMap.put("sendContent",sendRecord);
                sendRecords.add(sendContentMap);
                nullMachine(machine);
                return;
            }else if(!scan_id.isEmpty()){
                taskingService.scanMachineAdd(machine,scan_id);
            }
        }
    }
    public void nullMachine(Machine machine) {
        if (!"".equals(machine.getRemark())){
            machine.setRemark("");
            machineMapper.updateById(machine);
        }
    }
    @Scheduled(fixedDelay = 1000)
    public void flipSliceTask() {
        //获取报警状态
        JSONObject jsonObject = new JSONObject();
        Machine machine=machineMapper.selectById(26L);
        List<Tasking> taskingList=taskingService.findMachineTask(machine);
        jsonObject.append("taskingList", taskingList);
        jsonObject.append("machine", machine);
        jsonObject.append("sendRecords", sendRecords);
        ArrayList<WebSocketServer> sendServer = WebSocketServer.sessionMap.get("flipSlice");
        if (sendServer != null) {
            for (WebSocketServer webserver : sendServer) {
                if (webserver != null) {
                    webserver.sendMessage(jsonObject.toString());
                    List<String> messages = webserver.getMessages();
                    if (!messages.isEmpty()) {
                        // // 将最后一个消息转换为整数类型的列表
                        webserver.clearMessages();
                    }
                } else {
                    log.info("Home is closed");
                }
            }
        }
    }
    @Scheduled(fixedDelay = 1000)
    public void downLineTask() {
        //线下任务
        JSONObject jsonObject = new JSONObject();
        List<Tasking> downLineTask=taskingService.findDownLineTask();
        jsonObject.append("downLineTask", downLineTask);
        ArrayList<WebSocketServer> sendServer = WebSocketServer.sessionMap.get("downLineTask");
        if (sendServer != null) {
            for (WebSocketServer webserver : sendServer) {
                if (webserver != null) {
                    webserver.sendMessage(jsonObject.toString());
                    List<String> messages = webserver.getMessages();
                    if (!messages.isEmpty()) {
                        // // 将最后一个消息转换为整数类型的列表
                        webserver.clearMessages();
                    }
                } else {
                    log.info("Home is closed");
                }
            }
        }
    }
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCManualReporting.java
New file
@@ -0,0 +1,59 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.mes.common.S7object;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.PrimitiveTask;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.service.PrimitiveTaskService;
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 java.util.ArrayList;
import java.util.List;
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCManualReporting {
    PlcParameterObject plcParameterObject =null;
    @Autowired
    TaskingService taskingService;
    @Autowired
    MachineMapper machineMapper;
    @Autowired
    PrimitiveTaskService primitiveTaskService;
    //@Scheduled(fixedDelay = 500)
    //@Scheduled(fixedDelay = 1000)
    public void manualReporting() {
        JSONObject jsonObject = new JSONObject();
        List<PrimitiveTask> taskingList = primitiveTaskService.selectPrimitiveTask(new PrimitiveTask());
        jsonObject.append("taskingList", taskingList);
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("manualReporting");
        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");
                }
            }
        }
    }
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCMechanicalArm.java
New file
@@ -0,0 +1,80 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.mes.common.S7object;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.Machine;
import com.mes.md.entity.Tasking;
import com.mes.md.mapper.MachineMapper;
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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCMechanicalArm {
    PlcParameterObject plcParameterObject =null;
    @Autowired
    TaskingService taskingService;
    @Autowired
    MachineMapper machineMapper;
//    @Scheduled(fixedDelay = 500)
    public void plcEdging() {
        //机械臂请求信号
        String request = plcParameterObject.getPlcParameter("request").getValue();
        if (!Objects.equals(request, "")){
            //当机械臂请求信号为1的时候,//判断当前任务是定制还是标准
            String status = plcParameterObject.getPlcParameter("Status").getValue();
                boolean tasking = taskingService.insertTasking(status);
                if(tasking){
                    S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("overGlass").getAddress(), Integer.parseInt("1"));
                    //发送上片完毕
                }
        }
    }
    //@Scheduled(fixedDelay = 1000)
    public void mechanicalAmWeb() {
        //获取当前任务表最新的一块任务状态
        //获取报警状态
        JSONObject jsonObject = new JSONObject();
//        String warning = plcParameterObject.getPlcParameter("warning").getValue();
//        if (!Objects.equals(warning, "0")) {
//            //log.info("报警信息:"+warning);
//            jsonObject.append("warning", warning);
//        }
        Machine machine=machineMapper.selectById(1L);
        List<Tasking> taskingList=taskingService.findMachineTask(machine);
        jsonObject.append("taskingList", taskingList);
        jsonObject.append("machine", machine);
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("mechanicalArm");
        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");
                }
            }
        }
    }
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCScanQRVerify.java
New file
@@ -0,0 +1,77 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.mes.common.S7object;
import com.mes.device.PlcParameterObject;
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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCScanQRVerify {
    PlcParameterObject plcParameterObject =null;
    @Autowired
    TaskingService taskingService;
    //@Scheduled(fixedDelay = 500)
    public void plcScanQrVerify() {
        //获取当前任务表最新的一块任务状态
        //扫码确认线程
        String scanId = plcParameterObject.getPlcParameter("scanId").getValue();
        Tasking tasking =new Tasking();
        tasking.setScanId(scanId);
        if(!Objects.equals(scanId, "")){
            //更新任务表状态
           boolean result = taskingService.updateTaskingState(tasking);
           if (result){
               //添加成功时发送过片信号
               S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("scan").getAddress(), Integer.parseInt("1"));
           }
        }else {
            //扫码失败时发送警告,二维码消失
            S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("deficiency").getAddress(), Integer.parseInt("1"));
            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("ScanQrVerify");
        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");
                }
            }
        }
    }
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCScanQRWorks.java
New file
@@ -0,0 +1,79 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.mes.common.S7object;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.Tasking;
import com.mes.md.service.PrimitiveTaskService;
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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PLCScanQRWorks {
    PlcParameterObject plcParameterObject =null;
    @Autowired
    TaskingService taskingService;
    @Autowired
    PrimitiveTaskService primitiveTaskService;
    //@Scheduled(fixedDelay = 500)
    public void plcScanQrVerify() {
        //根据扫描到的定制二维码将状态更新到数据库中
        //扫码报工线程
        String scanId = plcParameterObject.getPlcParameter("scanId").getValue();
        Tasking tasking =new Tasking();
        if(!Objects.equals(scanId, "")){
            //更新任务表状态
           boolean result = primitiveTaskService.updateReportCount(scanId);
           if (result){
               //添加成功时发送过片信号
               S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("scan").getAddress(), Integer.parseInt("1"));
           }
        }else {
            //扫码失败时发送警告,二维码消失
            S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("deficiency").getAddress(), Integer.parseInt("1"));
            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("ScanQrVerify");
        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");
                }
            }
        }
    }
}
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/PLCScanQrCodesReport.java
New file
@@ -0,0 +1,78 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.mes.common.S7object;
import com.mes.md.entity.Machine;
import com.mes.md.entity.Tasking;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.service.PrimitiveTaskService;
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 PLCScanQrCodesReport {
    PlcParameterObject plcParameterObject =null;
    @Autowired
    TaskingService taskingService;
    @Autowired
    MachineMapper machineMapper;
    @Autowired
    PrimitiveTaskService primitiveTaskService;
    //@Scheduled(fixedDelay = 500)
    public void pLCScanQR() {
        //获取当前任务表最新的一块任务状态
        //扫码线程
        String scanId = plcParameterObject.getPlcParameter("scanId").getValue();
        if(!Objects.equals(scanId, "")){
           boolean result = primitiveTaskService.updateReportCount(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() {
        //获取当前任务表最新的一块任务状态
        JSONObject jsonObject = new JSONObject();
        //获取报警状态
        Machine machine=machineMapper.selectById(23L);
        List<Tasking> taskingList=taskingService.findMachineTask(machine);
        jsonObject.append("taskingList", taskingList);
        jsonObject.append("machine", machine);
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("scanQrCodesReport");
        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");
                }
            }
        }
    }
}