From aa6f20d98b5d8e18ae56f9562a78d403a5417b48 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期三, 08 一月 2025 16:32:28 +0800 Subject: [PATCH] # --- zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java | 89 ++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 85 insertions(+), 4 deletions(-) diff --git a/zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java b/zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java index 1578c7a..a737504 100644 --- a/zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java +++ b/zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java @@ -1,11 +1,21 @@ package com.zy.acs.fake.service; +import com.zy.acs.fake.config.RedisProperties; import com.zy.acs.fake.domain.DynamicNode; import com.zy.acs.framework.common.Cools; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; +import org.springframework.util.StopWatch; +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; @@ -18,9 +28,73 @@ @Autowired private MapDataDispatcher mapDataDispatcher; + @Autowired + private RedisProperties redisProperties; + + public synchronized void unlockPath0(String agvNo, String codeData) { + try { + + Resource resource = new ClassPathResource("unlock.py"); + File tempScript = null; + + InputStream is = resource.getInputStream(); + tempScript = File.createTempFile("unlock", ".py"); + tempScript.deleteOnExit(); + + Files.copy(is, tempScript.toPath(), StandardCopyOption.REPLACE_EXISTING); + tempScript.setExecutable(true); + + ProcessBuilder processBuilder = new ProcessBuilder( + "python" + , tempScript.getAbsolutePath() + , redisProperties.getHost() + , redisProperties.getPassword() + , String.valueOf(redisProperties.getPort()) + , String.valueOf(redisProperties.getIndex()) + , agvNo + , codeData + ); + + processBuilder.redirectErrorStream(true); + + Process process = processBuilder.start(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + StringBuilder builder = new StringBuilder(); + while ((line = reader.readLine()) != null) { + builder.append(line); + } + + int exitCode = process.waitFor(); + if (exitCode != 0) { + log.error("Python script exited with error code: {}", exitCode); + log.error("python error:{}", builder.toString()); + return; + } + reader.close(); + + if (builder.length() <= 0) { + return; + } + + String result = builder.toString(); + + if (!Cools.isEmpty(result)) { + if (!"1".equals(result)) { + log.error("Fail python"); + } + } + + + } catch (Exception e) { + log.error("MapService.unlockPath", e); + } + } public synchronized void unlockPath(String agvNo, String codeData) { try { + long startTime = System.currentTimeMillis(); if (Cools.isEmpty(agvNo, codeData)) { return; @@ -36,16 +110,21 @@ DynamicNode dynamicNode = dynamicMatrix[codeMatrixIdx[0]][codeMatrixIdx[1]]; - Integer serial = dynamicNode.getSerial(); + long time = dynamicNode.getTime(); List<String> resetCodeList = new ArrayList<>(); for (int i = 0; i < dynamicMatrix.length; i++) { for (int j = 0; j < dynamicMatrix[i].length; j++) { + + if (i == codeMatrixIdx[0] && j == codeMatrixIdx[1]) { continue; } + DynamicNode node = dynamicMatrix[i][j]; - if (node.getVehicle().equals(agvNo) && node.getSerial() < serial) { - resetCodeList.add(codeMatrix[i][j]); + if (node.getVehicle().equals(agvNo)) { + if (node.getSerial() < serial || node.getTime() != time) { + resetCodeList.add(codeMatrix[i][j]); + } } } } @@ -55,8 +134,10 @@ mapDataDispatcher.clearDynamicMatrixByCodeList(lev, resetCodeList); } + log.info("瑙i攣璺緞鍑芥暟鑺辫垂鏃堕棿涓猴細{}姣......", System.currentTimeMillis() - startTime); + } catch (Exception e) { - log.error("TrafficService.unlockPath", e); + log.error("MapService.unlockPath", e); } } -- Gitblit v1.9.1