| | |
| | | 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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
| | | import com.mes.common.config.Const;
|
| | |
| | | import com.mes.downstorage.service.DownStorageCageService;
|
| | | import com.mes.downworkstation.entity.DownWorkstation;
|
| | | import com.mes.downworkstation.service.DownWorkstationService;
|
| | | import com.mes.glassinfo.entity.GlassInfo;
|
| | | import com.mes.glassinfo.service.GlassInfoService;
|
| | | import com.mes.tools.DateUtil;
|
| | | import com.mes.tools.SocketUtil;
|
| | | 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.beans.factory.annotation.Value;
|
| | | import org.springframework.scheduling.annotation.Scheduled;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | 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 DownGlassTaskService downGlassTaskService;
|
| | | @Autowired
|
| | | SocketUtil socketUtil;
|
| | | private GlassInfoService glassInfoService;
|
| | |
|
| | | @Value("${mes.scan.ip}")
|
| | | private String scanIp;
|
| | |
|
| | | @Value("${mes.scan.port}")
|
| | | private Integer scanPort;
|
| | |
|
| | | @Autowired
|
| | | private RedisUtil redisUtil;
|
| | |
|
| | |
| | | @Scheduled(fixedDelay = Long.MAX_VALUE)
|
| | | public void scanCodeTask() {
|
| | | while (true) {
|
| | | try {
|
| | | if (socketUtil.openSocket()) {
|
| | | String data = socketUtil.receiveData();
|
| | | if (StringUtils.isNotBlank(data)) {
|
| | | log.info("扫描数据:" + data);
|
| | | //发送扫描数据
|
| | | //todo:按照玻璃id获取玻璃信息返回给前端界面,具体需要哪些数据待确认
|
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("scanCode");
|
| | | if (sendwServer != null) {
|
| | | for (WebSocketServer webserver : sendwServer) {
|
| | | if (webserver != null && webserver.session.isOpen()) {
|
| | | webserver.sendMessage(data);
|
| | | }
|
| | | }
|
| | | try (Socket socket = new Socket(scanIp, scanPort);
|
| | | BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
|
| | | // 接收服务器响应
|
| | | String response;
|
| | | while ((response = in.readLine()) != null) {
|
| | | List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("scanCode");
|
| | | if (CollectionUtils.isNotEmpty(sendwServer)) {
|
| | | //按照玻璃id获取玻璃信息返回给前端界面,具体需要哪些数据待确认
|
| | | GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>()
|
| | | .eq(GlassInfo::getGlassId, response).last("limit 1"));
|
| | | if (null == glassInfo) {
|
| | | log.info("按照玻璃id:{},无法找到玻璃信息", response);
|
| | | } else {
|
| | | sendwServer.get(0).sendMessage(glassInfo.toString());
|
| | | }
|
| | | }
|
| | | } else {
|
| | | log.info("socket连接失败");
|
| | | }
|
| | | } catch (Exception e) {
|
| | | log.info("socke执行过程中发生异常");
|
| | | } catch (Exception exception) {
|
| | | log.info("读取异常,原因为{}", exception.getMessage());
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|