| | |
| | | package com.mes.job; |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.smallbun.screw.core.util.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.mes.bigstorage.entity.BigStorageCageDetails; |
| | | import com.mes.bigstorage.service.BigStorageCageDetailsService; |
| | | import com.mes.bigstorage.service.BigStorageCageService; |
| | | import com.mes.common.utils.RedisUtil; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import com.mes.tools.WebSocketServer; |
| | | import com.mes.utils.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @Autowired |
| | | private GlassInfoService glassInfoService; |
| | | |
| | | @Value("${mes.scan.ip}") |
| | | private String scanIp; |
| | | |
| | | @Value("${mes.scan.port}") |
| | | private Integer scanPort; |
| | | // @Value("${mes.scan.ip}") |
| | | // private String scanIp; |
| | | // |
| | | // @Value("${mes.scan.port}") |
| | | // private Integer scanPort; |
| | | |
| | | private JSONObject jsonObject = new JSONObject(); |
| | | |
| | |
| | | * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成) |
| | | * fixedDelay : 上一个调用结束后再次调用的延时 |
| | | */ |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void plcStorageCageTask() throws InterruptedException { |
| | | jsonObject = new JSONObject(); |
| | | try { |
| | |
| | | queryDataSource1(); |
| | | //查询使用数据源2查询数据 |
| | | queryDataSource2(); |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("slicecage"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | List<String> messages = webserver.getMessages(); |
| | | if (!messages.isEmpty()) { |
| | | // // 将最后一个消息转换为整数类型的列表 |
| | | webserver.clearMessages(); |
| | | try { |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("slicecage"); |
| | | 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"); |
| | | } |
| | | } else { |
| | | log.info("Home is closed"); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); // 打印堆栈信息,方便定位问题 |
| | | System.out.println("webserver出现异常: " + e.getMessage()); |
| | | // TODO: handle exception |
| | | } |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void temperingIsRun() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //进片任务数据 |
| | |
| | | } |
| | | |
| | | // @Scheduled(fixedDelay = Long.MAX_VALUE) |
| | | public void scanCodeTask() { |
| | | log.info("扫描任务已启动"); |
| | | while (true) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | try (Socket socket = new Socket(scanIp, scanPort); |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) { |
| | | // 接收服务器响应 |
| | | log.info("等待扫码中......"); |
| | | String glassId = in.readLine(); |
| | | log.info("扫描到的玻璃id:{}", glassId); |
| | | List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("slicecage"); |
| | | if (CollectionUtils.isNotEmpty(sendwServer)) { |
| | | //按照玻璃id获取玻璃信息返回给前端界面,具体需要哪些数据待确认 |
| | | GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>() |
| | | .eq(GlassInfo::getGlassId, glassId).last("limit 1")); |
| | | if (null == glassInfo) { |
| | | log.info("按照玻璃id:{},无法找到玻璃信息", glassId); |
| | | } else { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | jsonObject.append("scanGlass", glassInfo); |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception exception) { |
| | | log.info("读取异常,原因为{}", exception.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | // public void scanCodeTask() { |
| | | // log.info("扫描任务已启动"); |
| | | // while (true) { |
| | | // JSONObject jsonObject = new JSONObject(); |
| | | // try (Socket socket = new Socket(scanIp, scanPort); |
| | | // BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) { |
| | | // // 接收服务器响应 |
| | | // log.info("等待扫码中......"); |
| | | // String glassId = in.readLine(); |
| | | // log.info("扫描到的玻璃id:{}", glassId); |
| | | // List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("slicecage"); |
| | | // if (CollectionUtils.isNotEmpty(sendwServer)) { |
| | | // //按照玻璃id获取玻璃信息返回给前端界面,具体需要哪些数据待确认 |
| | | // GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>() |
| | | // .eq(GlassInfo::getGlassId, glassId).last("limit 1")); |
| | | // if (null == glassInfo) { |
| | | // log.info("按照玻璃id:{},无法找到玻璃信息", glassId); |
| | | // } else { |
| | | // for (WebSocketServer webserver : sendwServer) { |
| | | // jsonObject.append("scanGlass", glassInfo); |
| | | // webserver.sendMessage(jsonObject.toString()); |
| | | // } |
| | | // } |
| | | // } |
| | | // } catch (Exception exception) { |
| | | // log.info("读取异常,原因为{}", exception.getMessage()); |
| | | // } |
| | | // } |
| | | // } |
| | | } |