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