| | |
| | | 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.common.utils.RedisUtil;
|
| | | import com.mes.downglassinfo.entity.DownGlassInfo;
|
| | | import com.mes.downglassinfo.entity.DownGlassTask;
|
| | | import com.mes.downglassinfo.entity.request.DownGlassInfoRequest;
|
| | | import com.mes.downglassinfo.service.DownGlassInfoService;
|
| | | import com.mes.downglassinfo.service.DownGlassTaskService;
|
| | | 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.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.TaskScheduler;
|
| | | import org.springframework.scheduling.annotation.Async;
|
| | | import org.springframework.scheduling.annotation.Scheduled;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import java.io.BufferedReader;
|
| | | import java.io.InputStreamReader;
|
| | | import java.net.InetSocketAddress;
|
| | | import java.net.Socket;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.*;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | @Slf4j
|
| | |
| | | private DownStorageCageService downStorageCageService;
|
| | | @Autowired
|
| | | private DownGlassInfoService downGlassInfoService;
|
| | | @Autowired
|
| | | private DownGlassTaskService downGlassTaskService;
|
| | | @Autowired
|
| | | private GlassInfoService glassInfoService;
|
| | |
|
| | | @Value("${mes.scan.ip}")
|
| | | private String scanIp;
|
| | |
|
| | | @Value("${mes.scan.port}")
|
| | | private Integer scanPort;
|
| | |
|
| | | @Autowired
|
| | | private RedisUtil redisUtil;
|
| | |
| | | log.info("发送工位玻璃信息");
|
| | | JSONObject jsonObject = new JSONObject();
|
| | |
|
| | | List<DownWorkstation> data = downWorkstationService.getoneDownWorkstations(1, 6);
|
| | | List<DownWorkstation> data = downWorkstationService.list();
|
| | | jsonObject.append("params", data);
|
| | | log.info(jsonObject.toString());
|
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("unloadglass");
|
| | |
| | | autoPrint = redisUtil.getCacheObject("autoPrint");
|
| | | }
|
| | | jsonObject4.append("autoPrint", autoPrint);
|
| | | //人工下片位置最后一片
|
| | | DownGlassTask takeGlass = downGlassTaskService.getOne(
|
| | | new QueryWrapper<DownGlassTask>()
|
| | | .select("Top 1 *")
|
| | | .eq("end_cell", Const.G13_WORK_STATION)
|
| | | .lt("task_status", Const.UNLOAD_GLASS_DOWN)
|
| | | .orderByAsc("id")
|
| | | );
|
| | | if(takeGlass!=null){
|
| | | jsonObject4.append("takeGlass", takeGlass);
|
| | | }
|
| | |
|
| | | ArrayList<WebSocketServer> sendwServer4 = WebSocketServer.sessionMap.get("unloadglass");
|
| | | if (sendwServer4 != null) {
|
| | |
| | | //正在进行的任务
|
| | | List<DownWorkstation> downWorkstation = downWorkstationService.getoneDownWorkstations(1, 6);
|
| | | jsonObject.append("downWorkstation", downWorkstation);
|
| | | List<DownGlassTask> downGlassTask = downGlassTaskService.selectOutTaskCache();
|
| | | jsonObject.append("downGlassTask", downGlassTask);
|
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("unLoadGlassIsRun");
|
| | | if (sendwServer != null) {
|
| | | for (WebSocketServer webserver : sendwServer) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @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("unloadglass");
|
| | | 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());
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|